diff --git a/planet/Graphics.ocg/AmbientShader.glsl b/planet/Graphics.ocg/AmbientShader.glsl index 94af7c69b..1370cb368 100644 --- a/planet/Graphics.ocg/AmbientShader.glsl +++ b/planet/Graphics.ocg/AmbientShader.glsl @@ -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 diff --git a/planet/Graphics.ocg/LandscapeShader.glsl b/planet/Graphics.ocg/LandscapeShader.glsl index 513f71465..720443a70 100644 --- a/planet/Graphics.ocg/LandscapeShader.glsl +++ b/planet/Graphics.ocg/LandscapeShader.glsl @@ -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 diff --git a/planet/Graphics.ocg/LightShader.glsl b/planet/Graphics.ocg/LightShader.glsl index 5541aee74..f0baaee6f 100644 --- a/planet/Graphics.ocg/LightShader.glsl +++ b/planet/Graphics.ocg/LightShader.glsl @@ -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 diff --git a/planet/Graphics.ocg/ScalerShader.glsl b/planet/Graphics.ocg/ScalerShader.glsl index 6c54103ec..a338e3886 100644 --- a/planet/Graphics.ocg/ScalerShader.glsl +++ b/planet/Graphics.ocg/ScalerShader.glsl @@ -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); } diff --git a/planet/Graphics.ocg/SpriteBaseShader.glsl b/planet/Graphics.ocg/SpriteBaseShader.glsl index 0250c9bd0..7c9d34df8 100644 --- a/planet/Graphics.ocg/SpriteBaseShader.glsl +++ b/planet/Graphics.ocg/SpriteBaseShader.glsl @@ -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; diff --git a/planet/Graphics.ocg/SpriteLightShader.glsl b/planet/Graphics.ocg/SpriteLightShader.glsl index 1af93c80e..11df39c13 100644 --- a/planet/Graphics.ocg/SpriteLightShader.glsl +++ b/planet/Graphics.ocg/SpriteLightShader.glsl @@ -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); diff --git a/planet/Graphics.ocg/SpriteOverlayShader.glsl b/planet/Graphics.ocg/SpriteOverlayShader.glsl index e337254ed..4d10f1cec 100644 --- a/planet/Graphics.ocg/SpriteOverlayShader.glsl +++ b/planet/Graphics.ocg/SpriteOverlayShader.glsl @@ -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); } - - diff --git a/planet/Graphics.ocg/SpriteTextureShader.glsl b/planet/Graphics.ocg/SpriteTextureShader.glsl index e1e8009a6..13b916c2b 100644 --- a/planet/Graphics.ocg/SpriteTextureShader.glsl +++ b/planet/Graphics.ocg/SpriteTextureShader.glsl @@ -1,6 +1,6 @@ uniform sampler2D baseTex; -slice texture +slice(texture) { color = baseColor * texture2D(baseTex, texcoord.xy); } diff --git a/src/graphics/C4Shader.cpp b/src/graphics/C4Shader.cpp index 0e393d2bd..f9b5096e1 100644 --- a/src/graphics/C4Shader.cpp +++ b/src/graphics/C4Shader.cpp @@ -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++;