From f3da8525d06f6d008a3019432ad0aa014b785e95 Mon Sep 17 00:00:00 2001 From: Armin Burgmeier Date: Thu, 10 Sep 2015 19:44:23 -0400 Subject: [PATCH] Prefix most shader defines with "OC_" --- planet/Graphics.ocg/AmbientShader.glsl | 8 ++++---- planet/Graphics.ocg/LandscapeShader.glsl | 6 +++--- planet/Graphics.ocg/LightShader.glsl | 10 +++++----- planet/Graphics.ocg/ObjectBaseShader.glsl | 4 ++-- planet/Graphics.ocg/ObjectLightShader.glsl | 21 +++++---------------- planet/Graphics.ocg/ScalerShader.glsl | 2 +- planet/Objects.ocd/normal_map_fragment.glsl | 2 +- src/graphics/C4DrawGL.cpp | 6 +++--- src/landscape/C4LandscapeRender.cpp | 5 +++-- src/lib/StdMeshMaterial.cpp | 2 +- src/object/C4Def.cpp | 6 +++--- 11 files changed, 31 insertions(+), 41 deletions(-) diff --git a/planet/Graphics.ocg/AmbientShader.glsl b/planet/Graphics.ocg/AmbientShader.glsl index 3fe12fc1b..5d4d99462 100644 --- a/planet/Graphics.ocg/AmbientShader.glsl +++ b/planet/Graphics.ocg/AmbientShader.glsl @@ -1,7 +1,7 @@ // Ambient light calculation -#ifdef HAVE_LIGHT +#ifdef OC_DYNAMIC_LIGHT uniform sampler2D ambientTex; uniform mat3x2 ambientTransform; @@ -12,7 +12,7 @@ uniform float ambientBrightness; slice(texture+6) { -#ifdef HAVE_LIGHT +#ifdef OC_DYNAMIC_LIGHT // Ambient light // Extra .xy since some old intel drivers return a vec3 float ambient = texture2D(ambientTex, (ambientTransform * vec3(gl_FragCoord.xy, 1.0)).xy).r * ambientBrightness; @@ -25,11 +25,11 @@ slice(texture+6) slice(light+1) { // Add ambience to brightness -#ifdef LANDSCAPE +#ifdef OC_LANDSCAPE // For landscape, ambient brightness is coming from top vec3 ambientDir = vec3(0.0, -1.0, 0.0); light = mix(light, 1.0 + 1.0 * dot(normal, ambientDir), ambient); -#ifdef HAVE_2PX +#ifdef OC_HAVE_2PX light2 = mix(light2, 1.0 + 1.0 * dot(normal2, ambientDir), ambient); #endif #else diff --git a/planet/Graphics.ocg/LandscapeShader.glsl b/planet/Graphics.ocg/LandscapeShader.glsl index ea370d74a..5bd380513 100644 --- a/planet/Graphics.ocg/LandscapeShader.glsl +++ b/planet/Graphics.ocg/LandscapeShader.glsl @@ -74,7 +74,7 @@ slice(material) vec4 normalPx = texture3D(materialTex, vec3(materialCoo, materialIx+0.5)); // Same for second pixel, but we'll simply use the first normal -#ifdef HAVE_2PX +#ifdef OC_HAVE_2PX float materialIx2 = queryMatMap(f2i(landscapePx2.r)); vec4 materialPx2 = texture3D(materialTex, vec3(materialCoo, materialIx2)); vec4 normalPx2 = texture3D(materialTex, vec3(materialCoo, materialIx2+0.5)); @@ -89,7 +89,7 @@ slice(normal) vec3 textureNormal = normalPx.xyz - vec3(0.5,0.5,0.5); normal = normal + textureNormal * normalMapStrength; -#ifdef HAVE_2PX +#ifdef OC_HAVE_2PX vec3 normal2 = extend_normal(landscapePx2.yz - vec2(0.5, 0.5)); vec3 textureNormal2 = normalPx2.xyz - vec3(0.5,0.5,0.5); normal2 = normal2 + textureNormal2 * normalMapStrength; @@ -100,7 +100,7 @@ slice(normal) slice(color) { #define color gl_FragColor color = materialPx; -#ifdef HAVE_2PX +#ifdef OC_HAVE_2PX vec4 color2 = materialPx2; #endif } diff --git a/planet/Graphics.ocg/LightShader.glsl b/planet/Graphics.ocg/LightShader.glsl index 985e8a527..c8f15128e 100644 --- a/planet/Graphics.ocg/LightShader.glsl +++ b/planet/Graphics.ocg/LightShader.glsl @@ -1,7 +1,7 @@ // Base light calculations -#ifdef HAVE_LIGHT +#ifdef OC_DYNAMIC_LIGHT uniform sampler2D lightTex; #endif uniform float cullMode; // 0 if backface culling is enabled, 1 if it is disabled @@ -25,7 +25,7 @@ const float lightDarknessLevel = 8.0 / 256.0; slice(texture+5) { -#ifdef HAVE_LIGHT +#ifdef OC_DYNAMIC_LIGHT // Query light texture vec2 lightDirCoord = lightCoord.st; @@ -57,7 +57,7 @@ slice(texture+5) slice(light) { float light = 2.0 * lightBright * max(max(dot(normal, lightDir), 0.0), cullMode * max(dot(-normal, lightDir), 0.0)); -#ifdef HAVE_2PX +#ifdef OC_HAVE_2PX float light2 = 2.0 * lightBright * max(max(dot(normal2, lightDir), 0.0), cullMode * max(dot(-normal2, lightDir), 0.0)); #endif } @@ -73,7 +73,7 @@ slice(color+5) // Add light color.rgb = light * color.rgb * lightColor.rgb; -#ifdef HAVE_2PX +#ifdef OC_HAVE_2PX color2.rgb = light2 * color2.rgb * lightColor.rgb; #endif } @@ -82,7 +82,7 @@ slice(finish+5) { #ifdef LIGHT_DEBUG -#ifdef HAVE_LIGHT +#ifdef OC_DYNAMIC_LIGHT float lightYDir = lightPx.b - 1.0/3.0; float lightXDir = lightPx.g - 1.0/3.0; float lightStrength = lightPx.a; diff --git a/planet/Graphics.ocg/ObjectBaseShader.glsl b/planet/Graphics.ocg/ObjectBaseShader.glsl index cf9b7b376..46d62bb0f 100644 --- a/planet/Graphics.ocg/ObjectBaseShader.glsl +++ b/planet/Graphics.ocg/ObjectBaseShader.glsl @@ -4,7 +4,7 @@ slice(init) { #define color gl_FragColor -#ifdef MESH +#ifdef OC_MESH // TODO: Add emission part of the material. Note we cannot just // add this to the color, but it would need to be handled separately, // such that it is independent from the incident light direction. @@ -27,7 +27,7 @@ slice(color) // Could also try some sort of 3x3 matrix: // out = (color, clrmod, 1) * (A,B,C,D,E,F,0,0,G) * (color, clrmod, 1) -#ifdef CLRMOD_MOD2 +#ifdef OC_CLRMOD_MOD2 color = clamp(color + clrMod - 0.5, 0.0, 1.0); #else color = color * clrMod; diff --git a/planet/Graphics.ocg/ObjectLightShader.glsl b/planet/Graphics.ocg/ObjectLightShader.glsl index 5487a0668..9052ec387 100644 --- a/planet/Graphics.ocg/ObjectLightShader.glsl +++ b/planet/Graphics.ocg/ObjectLightShader.glsl @@ -1,15 +1,15 @@ uniform mat3x2 lightTransform; -#ifdef HAVE_NORMALMAP +#ifdef OC_WITH_NORMALMAP uniform sampler2D normalTex; #endif -#ifdef MESH +#ifdef OC_MESH varying vec3 normalDir; #endif slice(texture+4) { -#ifdef HAVE_LIGHT +#ifdef OC_DYNAMIC_LIGHT // prepare texture coordinate for light lookup in LightShader.c // Extra .xy since some old intel drivers return a vec3 vec2 lightCoord = (lightTransform * vec3(gl_FragCoord.xy, 1.0)).xy; @@ -18,23 +18,12 @@ slice(texture+4) slice(normal) { -#ifdef HAVE_NORMALMAP +#ifdef OC_WITH_NORMALMAP vec4 normalPx = texture2D(normalTex, texcoord.xy); vec3 normalPxDir = 2.0 * (normalPx.xyz - vec3(0.5, 0.5, 0.5)); -#ifdef MESH - // For meshes, the normal matrix is typically provided in Clonk - // coordinates, but the normal matrix incorporates a component that - // transforms from Ogre to Clonk coordinates. Therefore, we need to - // reverse that transformation for meshes. - // TODO: This could be optimized since the matrix is so simple that - // we don't need to do a full matrix multiplication. - mat3 c2o = mat3(0.0, 1.0, 0.0, 0.0, 0.0, -1.0, 1.0, 0.0, 0.0); - vec3 normal = normalize(c2o * gl_NormalMatrix * normalPxDir); -#else vec3 normal = normalize(gl_NormalMatrix * normalPxDir); -#endif #else -#ifdef MESH +#ifdef OC_MESH vec3 normal = normalDir; // Normal matrix is already applied in vertex shader #else vec3 normal = vec3(0.0, 0.0, 1.0); diff --git a/planet/Graphics.ocg/ScalerShader.glsl b/planet/Graphics.ocg/ScalerShader.glsl index a338e3886..cb02877b8 100644 --- a/planet/Graphics.ocg/ScalerShader.glsl +++ b/planet/Graphics.ocg/ScalerShader.glsl @@ -1,5 +1,5 @@ -#define HAVE_2PX +#define OC_HAVE_2PX slice(texture+5) { diff --git a/planet/Objects.ocd/normal_map_fragment.glsl b/planet/Objects.ocd/normal_map_fragment.glsl index a540e497a..d0446b542 100644 --- a/planet/Objects.ocd/normal_map_fragment.glsl +++ b/planet/Objects.ocd/normal_map_fragment.glsl @@ -13,7 +13,7 @@ void main() slice(init+1) { // This picks up the normal map lookup in ObjectLightShader.c: -#define HAVE_NORMALMAP +#define OC_WITH_NORMALMAP color = color * texture2D(basemap, texcoord); diff --git a/src/graphics/C4DrawGL.cpp b/src/graphics/C4DrawGL.cpp index d3beca553..0c67bfd35 100644 --- a/src/graphics/C4DrawGL.cpp +++ b/src/graphics/C4DrawGL.cpp @@ -599,9 +599,9 @@ bool CStdGL::CreateSpriteShader(C4Shader& shader, const char* name, int ssc, C4G // Then load slices for fragment shader shader.AddFragmentSlice(-1, "#define OPENCLONK"); - if (ssc & C4SSC_MOD2) shader.AddFragmentSlice(-1, "#define CLRMOD_MOD2"); - if (ssc & C4SSC_NORMAL) shader.AddFragmentSlice(-1, "#define HAVE_NORMALMAP"); - if (ssc & C4SSC_LIGHT) shader.AddFragmentSlice(-1, "#define HAVE_LIGHT"); + if (ssc & C4SSC_MOD2) shader.AddFragmentSlice(-1, "#define OC_CLRMOD_MOD2"); + if (ssc & C4SSC_NORMAL) shader.AddFragmentSlice(-1, "#define OC_WITH_NORMALMAP"); + if (ssc & C4SSC_LIGHT) shader.AddFragmentSlice(-1, "#define OC_DYNAMIC_LIGHT"); shader.LoadSlices(pGroups, "UtilShader.glsl"); shader.LoadSlices(pGroups, "ObjectBaseShader.glsl"); diff --git a/src/landscape/C4LandscapeRender.cpp b/src/landscape/C4LandscapeRender.cpp index 2dccdc311..def1eb2be 100644 --- a/src/landscape/C4LandscapeRender.cpp +++ b/src/landscape/C4LandscapeRender.cpp @@ -537,8 +537,9 @@ bool C4LandscapeRenderGL::LoadShader(C4GroupSet *pGroups, C4Shader& shader, cons if(ssc & C4SSC_LIGHT) hLightTexCoord = shader.AddTexCoord("lightCoord"); // Then load slices for fragment shader - shader.AddFragmentSlice(-1, "#define LANDSCAPE"); - if(ssc & C4SSC_LIGHT) shader.AddFragmentSlice(-1, "#define HAVE_LIGHT"); // sample light from light texture + shader.AddFragmentSlice(-1, "#define OPENCLONK"); + shader.AddFragmentSlice(-1, "#define OC_LANDSCAPE"); + if(ssc & C4SSC_LIGHT) shader.AddFragmentSlice(-1, "#define OC_DYNAMIC_LIGHT"); // sample light from light texture shader.LoadSlices(pGroups, "UtilShader.glsl"); shader.LoadSlices(pGroups, "LandscapeShader.glsl"); diff --git a/src/lib/StdMeshMaterial.cpp b/src/lib/StdMeshMaterial.cpp index b6ddbfd79..725d952f3 100644 --- a/src/lib/StdMeshMaterial.cpp +++ b/src/lib/StdMeshMaterial.cpp @@ -854,7 +854,7 @@ bool StdMeshMaterialProgram::AddParameterNames(const StdMeshMaterialShaderParame bool StdMeshMaterialProgram::CompileShader(StdMeshMaterialLoader& loader, C4Shader& shader, int ssc) { // Add standard slices - shader.AddFragmentSlice(-1, "#define MESH"); + shader.AddFragmentSlice(-1, "#define OC_MESH"); loader.AddShaderSlices(shader, ssc); // Add our slices shader.AddVertexSlice(-1, "varying vec2 texcoord;"); diff --git a/src/object/C4Def.cpp b/src/object/C4Def.cpp index f097fab79..968377282 100644 --- a/src/object/C4Def.cpp +++ b/src/object/C4Def.cpp @@ -64,8 +64,8 @@ public: shader.AddFragmentSlice(-1, "#define OPENCLONK"); shader.AddVertexSlice(-1, "#define OPENCLONK"); - if (ssc & C4SSC_MOD2) shader.AddFragmentSlice(-1, "#define CLRMOD_MOD2"); - if (ssc & C4SSC_LIGHT) shader.AddFragmentSlice(-1, "#define HAVE_LIGHT"); + if (ssc & C4SSC_MOD2) shader.AddFragmentSlice(-1, "#define OC_CLRMOD_MOD2"); + if (ssc & C4SSC_LIGHT) shader.AddFragmentSlice(-1, "#define OC_DYNAMIC_LIGHT"); shader.LoadSlices(&::GraphicsResource.Files, "UtilShader.glsl"); shader.LoadSlices(&::GraphicsResource.Files, "ObjectBaseShader.glsl"); @@ -73,7 +73,7 @@ public: shader.LoadSlices(&::GraphicsResource.Files, "GammaShader.glsl"); // Note that these shader slices are always loaded, even if lighting - // is disabled. The shaders then assume a default light if HAVE_LIGHT + // is disabled. The shaders then assume a default light if OC_DYNAMIC_LIGHT // is not defined. This avoids completely flat shading for meshes // that are shown as picture graphics for example. shader.LoadSlices(&::GraphicsResource.Files, "ObjectLightShader.glsl");