forked from Mirrors/openclonk
Change slice syntax such that positions appear in parentheses
This allows to ignore slice declarations using `#define slice(x)`, which mill be useful for custom mesh material shaders, allowing to write them such that they can be used standalone in a mesh viewer but also as slices for OpenClonk, in which case lighting and color modulation will be applied automatically.issue1247
parent
4981182cf8
commit
7f1cf15274
|
@ -6,13 +6,13 @@ uniform sampler2D ambientTex;
|
|||
uniform mat3x2 ambientTransform;
|
||||
uniform float ambientBrightness;
|
||||
|
||||
slice texture+6
|
||||
slice(texture+6)
|
||||
{
|
||||
// Ambient light
|
||||
float ambient = texture2D(ambientTex, ambientTransform * vec3(gl_FragCoord.xy, 1.0)).r * ambientBrightness;
|
||||
}
|
||||
|
||||
slice light+1
|
||||
slice(light+1)
|
||||
{
|
||||
// Add ambience to brightness
|
||||
#ifdef LANDSCAPE
|
||||
|
|
|
@ -35,7 +35,7 @@ float queryMatMap(int pix)
|
|||
#endif
|
||||
}
|
||||
|
||||
slice coordinate
|
||||
slice(coordinate)
|
||||
{
|
||||
// full pixel steps in the landscape texture (depends on landscape resolution)
|
||||
vec2 fullStep = vec2(1.0, 1.0) / resolution;
|
||||
|
@ -52,14 +52,14 @@ slice coordinate
|
|||
vec2 materialCoo = texCoo * resolution / materialSize;
|
||||
}
|
||||
|
||||
slice texture
|
||||
slice(texture)
|
||||
{
|
||||
// our pixel color (without/with interpolation)
|
||||
vec4 landscapePx = texture2D(landscapeTex[0], centerCoo);
|
||||
vec4 realLandscapePx = texture2D(landscapeTex[0], texCoo);
|
||||
}
|
||||
|
||||
slice material
|
||||
slice(material)
|
||||
{
|
||||
|
||||
// Get material pixels
|
||||
|
@ -75,7 +75,7 @@ slice material
|
|||
#endif
|
||||
}
|
||||
|
||||
slice normal
|
||||
slice(normal)
|
||||
{
|
||||
// Normal calculation
|
||||
vec3 normal = extend_normal(mix(realLandscapePx.yz, landscapePx.yz, scalerPx.a)
|
||||
|
@ -91,7 +91,7 @@ slice normal
|
|||
|
||||
}
|
||||
|
||||
slice color {
|
||||
slice(color) {
|
||||
#define color gl_FragColor
|
||||
color = materialPx;
|
||||
#ifdef HAVE_2PX
|
||||
|
|
|
@ -13,7 +13,7 @@ uniform sampler2D lightTex;
|
|||
// and therefore will often never arrive at 0 light intensity.
|
||||
const float lightDarknessLevel = 8.0 / 256.0;
|
||||
|
||||
slice texture+5
|
||||
slice(texture+5)
|
||||
{
|
||||
// Query light texture
|
||||
vec4 lightPx = texture2D(lightTex, lightCoord.st);
|
||||
|
@ -21,7 +21,7 @@ slice texture+5
|
|||
vec3 lightDir = extend_normal(vec2(1.0, 1.0) - lightPx.yz * 3.0);
|
||||
}
|
||||
|
||||
slice light
|
||||
slice(light)
|
||||
{
|
||||
// Light direction
|
||||
float light = 2.0 * lightBright * dot(normal, lightDir);
|
||||
|
@ -30,7 +30,7 @@ slice light
|
|||
#endif
|
||||
}
|
||||
|
||||
slice color+5
|
||||
slice(color+5)
|
||||
{
|
||||
// Add light
|
||||
color = vec4(light * color.rgb, color.a);
|
||||
|
@ -39,7 +39,7 @@ slice color+5
|
|||
#endif
|
||||
}
|
||||
|
||||
slice finish+5
|
||||
slice(finish+5)
|
||||
{
|
||||
|
||||
#ifdef LIGHT_DEBUG
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#define HAVE_2PX
|
||||
|
||||
slice texture+5
|
||||
slice(texture+5)
|
||||
{
|
||||
// find scaler coordinate
|
||||
vec2 scalerCoo = scalerOffset + mod(pixelCoo, vec2(1.0, 1.0)) * scalerPixel;
|
||||
|
@ -43,7 +43,7 @@ slice texture+5
|
|||
|
||||
}
|
||||
|
||||
slice color+10 {
|
||||
slice(color+10) {
|
||||
// Mix second color into main color according to scaler
|
||||
color = mix(color2, color, scalerPx.r);
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
uniform vec4 clrMod;
|
||||
|
||||
slice init
|
||||
slice(init)
|
||||
{
|
||||
#define color gl_FragColor
|
||||
vec4 baseColor = gl_Color;
|
||||
color = baseColor;
|
||||
}
|
||||
|
||||
slice color
|
||||
slice(color)
|
||||
{
|
||||
// TODO: Instead of a conditional, we could compute the color as
|
||||
// color = A + B*color + C*clrMod + D*color*clrMod;
|
||||
|
|
|
@ -3,13 +3,13 @@ uniform mat3x2 lightTransform;
|
|||
uniform sampler2D normalTex;
|
||||
#endif
|
||||
|
||||
slice texture+4
|
||||
slice(texture+4)
|
||||
{
|
||||
// prepare texture coordinate for light lookup in LightShader.c
|
||||
vec2 lightCoord = lightTransform * vec3(gl_FragCoord.xy, 1.0);
|
||||
}
|
||||
|
||||
slice normal
|
||||
slice(normal)
|
||||
{
|
||||
#ifdef HAVE_NORMALMAP
|
||||
vec4 normalPx = texture2D(normalTex, texcoord.xy);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
uniform vec4 overlayClr;
|
||||
uniform sampler2D overlayTex;
|
||||
|
||||
slice texture+1
|
||||
slice(texture+1)
|
||||
{
|
||||
// Get overlay color from overlay texture
|
||||
vec4 overlay = baseColor * overlayClr * texture2D(overlayTex, texcoord.xy);
|
||||
|
@ -9,5 +9,3 @@ slice texture+1
|
|||
float alpha0 = 1.0 - (1.0 - color.a) * (1.0 - overlay.a);
|
||||
color = vec4(mix(color.rgb, overlay.rgb, overlay.a / alpha0), alpha0);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
uniform sampler2D baseTex;
|
||||
|
||||
slice texture
|
||||
slice(texture)
|
||||
{
|
||||
color = baseColor * texture2D(baseTex, texcoord.xy);
|
||||
}
|
||||
|
|
|
@ -100,12 +100,19 @@ void C4Shader::AddSlices(const char *szWhat, const char *szText, const char *szS
|
|||
|
||||
// New slice? We need a newline followed by "slice"
|
||||
if (iDepth < 0 && isspace(*pPos)) {
|
||||
if (SEqual2(pPos+1, "slice") && isspace(*(pPos+6))) {
|
||||
if (SEqual2(pPos+1, "slice") && !isalnum(*(pPos+6))) {
|
||||
const char *pSliceEnd = pPos; pPos += 6;
|
||||
while(isspace(*pPos)) pPos++;
|
||||
if(*pPos != '(') { pPos++; continue; }
|
||||
pPos++;
|
||||
|
||||
// Now let's parse the position
|
||||
iPosition = ParsePosition(szWhat, &pPos);
|
||||
if (iPosition != -1) {
|
||||
// Make sure a closing parenthesis
|
||||
while(isspace(*pPos)) pPos++;
|
||||
if(*pPos != ')') { pPos++; continue; }
|
||||
pPos++;
|
||||
|
||||
// Make sure an opening brace follows
|
||||
while(isspace(*pPos)) pPos++;
|
||||
|
|
Loading…
Reference in New Issue