forked from Mirrors/openclonk
Prefix most shader defines with "OC_"
parent
d98134332c
commit
f3da8525d0
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
// Ambient light calculation
|
// Ambient light calculation
|
||||||
|
|
||||||
#ifdef HAVE_LIGHT
|
#ifdef OC_DYNAMIC_LIGHT
|
||||||
uniform sampler2D ambientTex;
|
uniform sampler2D ambientTex;
|
||||||
|
|
||||||
uniform mat3x2 ambientTransform;
|
uniform mat3x2 ambientTransform;
|
||||||
|
@ -12,7 +12,7 @@ uniform float ambientBrightness;
|
||||||
|
|
||||||
slice(texture+6)
|
slice(texture+6)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_LIGHT
|
#ifdef OC_DYNAMIC_LIGHT
|
||||||
// Ambient light
|
// Ambient light
|
||||||
// Extra .xy since some old intel drivers return a vec3
|
// Extra .xy since some old intel drivers return a vec3
|
||||||
float ambient = texture2D(ambientTex, (ambientTransform * vec3(gl_FragCoord.xy, 1.0)).xy).r * ambientBrightness;
|
float ambient = texture2D(ambientTex, (ambientTransform * vec3(gl_FragCoord.xy, 1.0)).xy).r * ambientBrightness;
|
||||||
|
@ -25,11 +25,11 @@ slice(texture+6)
|
||||||
slice(light+1)
|
slice(light+1)
|
||||||
{
|
{
|
||||||
// Add ambience to brightness
|
// Add ambience to brightness
|
||||||
#ifdef LANDSCAPE
|
#ifdef OC_LANDSCAPE
|
||||||
// For landscape, ambient brightness is coming from top
|
// For landscape, ambient brightness is coming from top
|
||||||
vec3 ambientDir = vec3(0.0, -1.0, 0.0);
|
vec3 ambientDir = vec3(0.0, -1.0, 0.0);
|
||||||
light = mix(light, 1.0 + 1.0 * dot(normal, ambientDir), ambient);
|
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);
|
light2 = mix(light2, 1.0 + 1.0 * dot(normal2, ambientDir), ambient);
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -74,7 +74,7 @@ slice(material)
|
||||||
vec4 normalPx = texture3D(materialTex, vec3(materialCoo, materialIx+0.5));
|
vec4 normalPx = texture3D(materialTex, vec3(materialCoo, materialIx+0.5));
|
||||||
|
|
||||||
// Same for second pixel, but we'll simply use the first normal
|
// 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));
|
float materialIx2 = queryMatMap(f2i(landscapePx2.r));
|
||||||
vec4 materialPx2 = texture3D(materialTex, vec3(materialCoo, materialIx2));
|
vec4 materialPx2 = texture3D(materialTex, vec3(materialCoo, materialIx2));
|
||||||
vec4 normalPx2 = texture3D(materialTex, vec3(materialCoo, materialIx2+0.5));
|
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);
|
vec3 textureNormal = normalPx.xyz - vec3(0.5,0.5,0.5);
|
||||||
normal = normal + textureNormal * normalMapStrength;
|
normal = normal + textureNormal * normalMapStrength;
|
||||||
|
|
||||||
#ifdef HAVE_2PX
|
#ifdef OC_HAVE_2PX
|
||||||
vec3 normal2 = extend_normal(landscapePx2.yz - vec2(0.5, 0.5));
|
vec3 normal2 = extend_normal(landscapePx2.yz - vec2(0.5, 0.5));
|
||||||
vec3 textureNormal2 = normalPx2.xyz - vec3(0.5,0.5,0.5);
|
vec3 textureNormal2 = normalPx2.xyz - vec3(0.5,0.5,0.5);
|
||||||
normal2 = normal2 + textureNormal2 * normalMapStrength;
|
normal2 = normal2 + textureNormal2 * normalMapStrength;
|
||||||
|
@ -100,7 +100,7 @@ slice(normal)
|
||||||
slice(color) {
|
slice(color) {
|
||||||
#define color gl_FragColor
|
#define color gl_FragColor
|
||||||
color = materialPx;
|
color = materialPx;
|
||||||
#ifdef HAVE_2PX
|
#ifdef OC_HAVE_2PX
|
||||||
vec4 color2 = materialPx2;
|
vec4 color2 = materialPx2;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
// Base light calculations
|
// Base light calculations
|
||||||
|
|
||||||
#ifdef HAVE_LIGHT
|
#ifdef OC_DYNAMIC_LIGHT
|
||||||
uniform sampler2D lightTex;
|
uniform sampler2D lightTex;
|
||||||
#endif
|
#endif
|
||||||
uniform float cullMode; // 0 if backface culling is enabled, 1 if it is disabled
|
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)
|
slice(texture+5)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_LIGHT
|
#ifdef OC_DYNAMIC_LIGHT
|
||||||
|
|
||||||
// Query light texture
|
// Query light texture
|
||||||
vec2 lightDirCoord = lightCoord.st;
|
vec2 lightDirCoord = lightCoord.st;
|
||||||
|
@ -57,7 +57,7 @@ slice(texture+5)
|
||||||
slice(light)
|
slice(light)
|
||||||
{
|
{
|
||||||
float light = 2.0 * lightBright * max(max(dot(normal, lightDir), 0.0), cullMode * max(dot(-normal, lightDir), 0.0));
|
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));
|
float light2 = 2.0 * lightBright * max(max(dot(normal2, lightDir), 0.0), cullMode * max(dot(-normal2, lightDir), 0.0));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ slice(color+5)
|
||||||
|
|
||||||
// Add light
|
// Add light
|
||||||
color.rgb = light * color.rgb * lightColor.rgb;
|
color.rgb = light * color.rgb * lightColor.rgb;
|
||||||
#ifdef HAVE_2PX
|
#ifdef OC_HAVE_2PX
|
||||||
color2.rgb = light2 * color2.rgb * lightColor.rgb;
|
color2.rgb = light2 * color2.rgb * lightColor.rgb;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ slice(finish+5)
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef LIGHT_DEBUG
|
#ifdef LIGHT_DEBUG
|
||||||
#ifdef HAVE_LIGHT
|
#ifdef OC_DYNAMIC_LIGHT
|
||||||
float lightYDir = lightPx.b - 1.0/3.0;
|
float lightYDir = lightPx.b - 1.0/3.0;
|
||||||
float lightXDir = lightPx.g - 1.0/3.0;
|
float lightXDir = lightPx.g - 1.0/3.0;
|
||||||
float lightStrength = lightPx.a;
|
float lightStrength = lightPx.a;
|
||||||
|
|
|
@ -4,7 +4,7 @@ slice(init)
|
||||||
{
|
{
|
||||||
#define color gl_FragColor
|
#define color gl_FragColor
|
||||||
|
|
||||||
#ifdef MESH
|
#ifdef OC_MESH
|
||||||
// TODO: Add emission part of the material. Note we cannot just
|
// TODO: Add emission part of the material. Note we cannot just
|
||||||
// add this to the color, but it would need to be handled separately,
|
// add this to the color, but it would need to be handled separately,
|
||||||
// such that it is independent from the incident light direction.
|
// such that it is independent from the incident light direction.
|
||||||
|
@ -27,7 +27,7 @@ slice(color)
|
||||||
// Could also try some sort of 3x3 matrix:
|
// Could also try some sort of 3x3 matrix:
|
||||||
// out = (color, clrmod, 1) * (A,B,C,D,E,F,0,0,G) * (color, clrmod, 1)
|
// 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);
|
color = clamp(color + clrMod - 0.5, 0.0, 1.0);
|
||||||
#else
|
#else
|
||||||
color = color * clrMod;
|
color = color * clrMod;
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
uniform mat3x2 lightTransform;
|
uniform mat3x2 lightTransform;
|
||||||
#ifdef HAVE_NORMALMAP
|
#ifdef OC_WITH_NORMALMAP
|
||||||
uniform sampler2D normalTex;
|
uniform sampler2D normalTex;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MESH
|
#ifdef OC_MESH
|
||||||
varying vec3 normalDir;
|
varying vec3 normalDir;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
slice(texture+4)
|
slice(texture+4)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_LIGHT
|
#ifdef OC_DYNAMIC_LIGHT
|
||||||
// prepare texture coordinate for light lookup in LightShader.c
|
// prepare texture coordinate for light lookup in LightShader.c
|
||||||
// Extra .xy since some old intel drivers return a vec3
|
// Extra .xy since some old intel drivers return a vec3
|
||||||
vec2 lightCoord = (lightTransform * vec3(gl_FragCoord.xy, 1.0)).xy;
|
vec2 lightCoord = (lightTransform * vec3(gl_FragCoord.xy, 1.0)).xy;
|
||||||
|
@ -18,23 +18,12 @@ slice(texture+4)
|
||||||
|
|
||||||
slice(normal)
|
slice(normal)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_NORMALMAP
|
#ifdef OC_WITH_NORMALMAP
|
||||||
vec4 normalPx = texture2D(normalTex, texcoord.xy);
|
vec4 normalPx = texture2D(normalTex, texcoord.xy);
|
||||||
vec3 normalPxDir = 2.0 * (normalPx.xyz - vec3(0.5, 0.5, 0.5));
|
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);
|
vec3 normal = normalize(gl_NormalMatrix * normalPxDir);
|
||||||
#endif
|
|
||||||
#else
|
#else
|
||||||
#ifdef MESH
|
#ifdef OC_MESH
|
||||||
vec3 normal = normalDir; // Normal matrix is already applied in vertex shader
|
vec3 normal = normalDir; // Normal matrix is already applied in vertex shader
|
||||||
#else
|
#else
|
||||||
vec3 normal = vec3(0.0, 0.0, 1.0);
|
vec3 normal = vec3(0.0, 0.0, 1.0);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
#define HAVE_2PX
|
#define OC_HAVE_2PX
|
||||||
|
|
||||||
slice(texture+5)
|
slice(texture+5)
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,7 +13,7 @@ void main()
|
||||||
slice(init+1)
|
slice(init+1)
|
||||||
{
|
{
|
||||||
// This picks up the normal map lookup in ObjectLightShader.c:
|
// This picks up the normal map lookup in ObjectLightShader.c:
|
||||||
#define HAVE_NORMALMAP
|
#define OC_WITH_NORMALMAP
|
||||||
|
|
||||||
color = color * texture2D(basemap, texcoord);
|
color = color * texture2D(basemap, texcoord);
|
||||||
|
|
||||||
|
|
|
@ -599,9 +599,9 @@ bool CStdGL::CreateSpriteShader(C4Shader& shader, const char* name, int ssc, C4G
|
||||||
|
|
||||||
// Then load slices for fragment shader
|
// Then load slices for fragment shader
|
||||||
shader.AddFragmentSlice(-1, "#define OPENCLONK");
|
shader.AddFragmentSlice(-1, "#define OPENCLONK");
|
||||||
if (ssc & C4SSC_MOD2) shader.AddFragmentSlice(-1, "#define CLRMOD_MOD2");
|
if (ssc & C4SSC_MOD2) shader.AddFragmentSlice(-1, "#define OC_CLRMOD_MOD2");
|
||||||
if (ssc & C4SSC_NORMAL) shader.AddFragmentSlice(-1, "#define HAVE_NORMALMAP");
|
if (ssc & C4SSC_NORMAL) shader.AddFragmentSlice(-1, "#define OC_WITH_NORMALMAP");
|
||||||
if (ssc & C4SSC_LIGHT) shader.AddFragmentSlice(-1, "#define HAVE_LIGHT");
|
if (ssc & C4SSC_LIGHT) shader.AddFragmentSlice(-1, "#define OC_DYNAMIC_LIGHT");
|
||||||
shader.LoadSlices(pGroups, "UtilShader.glsl");
|
shader.LoadSlices(pGroups, "UtilShader.glsl");
|
||||||
shader.LoadSlices(pGroups, "ObjectBaseShader.glsl");
|
shader.LoadSlices(pGroups, "ObjectBaseShader.glsl");
|
||||||
|
|
||||||
|
|
|
@ -537,8 +537,9 @@ bool C4LandscapeRenderGL::LoadShader(C4GroupSet *pGroups, C4Shader& shader, cons
|
||||||
if(ssc & C4SSC_LIGHT) hLightTexCoord = shader.AddTexCoord("lightCoord");
|
if(ssc & C4SSC_LIGHT) hLightTexCoord = shader.AddTexCoord("lightCoord");
|
||||||
|
|
||||||
// Then load slices for fragment shader
|
// Then load slices for fragment shader
|
||||||
shader.AddFragmentSlice(-1, "#define LANDSCAPE");
|
shader.AddFragmentSlice(-1, "#define OPENCLONK");
|
||||||
if(ssc & C4SSC_LIGHT) shader.AddFragmentSlice(-1, "#define HAVE_LIGHT"); // sample light from light texture
|
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, "UtilShader.glsl");
|
||||||
shader.LoadSlices(pGroups, "LandscapeShader.glsl");
|
shader.LoadSlices(pGroups, "LandscapeShader.glsl");
|
||||||
|
|
|
@ -854,7 +854,7 @@ bool StdMeshMaterialProgram::AddParameterNames(const StdMeshMaterialShaderParame
|
||||||
bool StdMeshMaterialProgram::CompileShader(StdMeshMaterialLoader& loader, C4Shader& shader, int ssc)
|
bool StdMeshMaterialProgram::CompileShader(StdMeshMaterialLoader& loader, C4Shader& shader, int ssc)
|
||||||
{
|
{
|
||||||
// Add standard slices
|
// Add standard slices
|
||||||
shader.AddFragmentSlice(-1, "#define MESH");
|
shader.AddFragmentSlice(-1, "#define OC_MESH");
|
||||||
loader.AddShaderSlices(shader, ssc);
|
loader.AddShaderSlices(shader, ssc);
|
||||||
// Add our slices
|
// Add our slices
|
||||||
shader.AddVertexSlice(-1, "varying vec2 texcoord;");
|
shader.AddVertexSlice(-1, "varying vec2 texcoord;");
|
||||||
|
|
|
@ -64,8 +64,8 @@ public:
|
||||||
shader.AddFragmentSlice(-1, "#define OPENCLONK");
|
shader.AddFragmentSlice(-1, "#define OPENCLONK");
|
||||||
shader.AddVertexSlice(-1, "#define OPENCLONK");
|
shader.AddVertexSlice(-1, "#define OPENCLONK");
|
||||||
|
|
||||||
if (ssc & C4SSC_MOD2) shader.AddFragmentSlice(-1, "#define CLRMOD_MOD2");
|
if (ssc & C4SSC_MOD2) shader.AddFragmentSlice(-1, "#define OC_CLRMOD_MOD2");
|
||||||
if (ssc & C4SSC_LIGHT) shader.AddFragmentSlice(-1, "#define HAVE_LIGHT");
|
if (ssc & C4SSC_LIGHT) shader.AddFragmentSlice(-1, "#define OC_DYNAMIC_LIGHT");
|
||||||
|
|
||||||
shader.LoadSlices(&::GraphicsResource.Files, "UtilShader.glsl");
|
shader.LoadSlices(&::GraphicsResource.Files, "UtilShader.glsl");
|
||||||
shader.LoadSlices(&::GraphicsResource.Files, "ObjectBaseShader.glsl");
|
shader.LoadSlices(&::GraphicsResource.Files, "ObjectBaseShader.glsl");
|
||||||
|
@ -73,7 +73,7 @@ public:
|
||||||
shader.LoadSlices(&::GraphicsResource.Files, "GammaShader.glsl");
|
shader.LoadSlices(&::GraphicsResource.Files, "GammaShader.glsl");
|
||||||
|
|
||||||
// Note that these shader slices are always loaded, even if lighting
|
// 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
|
// is not defined. This avoids completely flat shading for meshes
|
||||||
// that are shown as picture graphics for example.
|
// that are shown as picture graphics for example.
|
||||||
shader.LoadSlices(&::GraphicsResource.Files, "ObjectLightShader.glsl");
|
shader.LoadSlices(&::GraphicsResource.Files, "ObjectLightShader.glsl");
|
||||||
|
|
Loading…
Reference in New Issue