forked from Mirrors/openclonk
Switch shader code to OpenGL 3 style
parent
16d2eb5cb1
commit
aef7538aa1
|
@ -76,14 +76,14 @@ slice(texture+5)
|
||||||
// Query light texture
|
// Query light texture
|
||||||
vec2 lightDirCoord = lightCoord;
|
vec2 lightDirCoord = lightCoord;
|
||||||
|
|
||||||
vec4 lightPx = texture2D(lightTex, lightDirCoord);
|
vec4 lightPx = texture(lightTex, lightDirCoord);
|
||||||
float lightBright = maxLightBrightness * max(0.0, (lightPx.a-lightDarknessLevel)/(1.0-lightDarknessLevel));
|
float lightBright = maxLightBrightness * max(0.0, (lightPx.a-lightDarknessLevel)/(1.0-lightDarknessLevel));
|
||||||
vec3 lightDir = normalize(vec3(vec2(1.0, 1.0) - lightPx.yz * 3.0, lightDepth));
|
vec3 lightDir = normalize(vec3(vec2(1.0, 1.0) - lightPx.yz * 3.0, lightDepth));
|
||||||
|
|
||||||
// Query light color texture (part of the light texture)
|
// Query light color texture (part of the light texture)
|
||||||
vec2 lightColorCoord = lightCoord - vec2(0.0, 0.5); // subtract offset for the color texture
|
vec2 lightColorCoord = lightCoord - vec2(0.0, 0.5); // subtract offset for the color texture
|
||||||
|
|
||||||
vec3 lightColor = texture2D(lightTex, lightColorCoord.st).rgb;
|
vec3 lightColor = texture(lightTex, lightColorCoord.st).rgb;
|
||||||
|
|
||||||
// Normalise light colour
|
// Normalise light colour
|
||||||
#ifdef LIGHT_DEBUG_COLOR
|
#ifdef LIGHT_DEBUG_COLOR
|
||||||
|
@ -93,7 +93,7 @@ slice(texture+5)
|
||||||
|
|
||||||
// Ambient light
|
// Ambient light
|
||||||
// Edxtra .xy since some old intel drivers return a vec3
|
// Edxtra .xy since some old intel drivers return a vec3
|
||||||
float ambient = texture2D(ambientTex, (ambientTransform * vec3(gl_FragCoord.xy, 1.0)).xy).r;
|
float ambient = texture(ambientTex, (ambientTransform * vec3(gl_FragCoord.xy, 1.0)).xy).r;
|
||||||
ambient *= ambientBrightness;
|
ambient *= ambientBrightness;
|
||||||
#ifdef OC_SKY
|
#ifdef OC_SKY
|
||||||
ambient = 0.999; // TODO: = 1.0 causes bugs?
|
ambient = 0.999; // TODO: = 1.0 causes bugs?
|
||||||
|
@ -144,7 +144,7 @@ slice(color+5)
|
||||||
// "spotty" and allow the material to self-illuminate. The light
|
// "spotty" and allow the material to self-illuminate. The light
|
||||||
// brightness overrules everything though (= FoW is last factor).
|
// brightness overrules everything though (= FoW is last factor).
|
||||||
vec3 spotLight = pow(vec3(light,light,light), matSpot);
|
vec3 spotLight = pow(vec3(light,light,light), matSpot);
|
||||||
color.rgb = lightBright * color.rgb * (matEmit + lightColorNorm * spotLight);
|
fragColor.rgb = lightBright * fragColor.rgb * (matEmit + lightColorNorm * spotLight);
|
||||||
#ifdef OC_LANDSCAPE
|
#ifdef OC_LANDSCAPE
|
||||||
vec3 spotLight2 = pow(vec3(light2,light2,light2), matSpot2);
|
vec3 spotLight2 = pow(vec3(light2,light2,light2), matSpot2);
|
||||||
color2.rgb = lightBright * color2.rgb * (matEmit2 + lightColorNorm * spotLight2);
|
color2.rgb = lightBright * color2.rgb * (matEmit2 + lightColorNorm * spotLight2);
|
||||||
|
@ -159,18 +159,18 @@ slice(finish+5)
|
||||||
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;
|
||||||
color =
|
fragColor =
|
||||||
vec4(lightStrength * vec3(1.0-1.5*(max(0.0, lightYDir) + max(0.0,lightXDir)),
|
vec4(lightStrength * vec3(1.0-1.5*(max(0.0, lightYDir) + max(0.0,lightXDir)),
|
||||||
1.0-1.5*(max(0.0, lightYDir) + max(0.0,-lightXDir)),
|
1.0-1.5*(max(0.0, lightYDir) + max(0.0,-lightXDir)),
|
||||||
1.0-1.5*max(0.0, -lightYDir)),
|
1.0-1.5*max(0.0, -lightYDir)),
|
||||||
1.0);
|
1.0);
|
||||||
#else
|
#else
|
||||||
color = vec4(0.0, 0.0, 0.0, 0.0); // invisible
|
fragColor = vec4(0.0, 0.0, 0.0, 0.0); // invisible
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
slice(finish+10) {
|
slice(finish+10) {
|
||||||
color = vec4(pow(color.rgb, gamma), color.a);
|
fragColor = vec4(pow(fragColor.rgb, gamma), fragColor.a);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
|
|
||||||
// Interpolated texture coordinates
|
// Interpolated texture coordinates
|
||||||
varying vec2 landscapeTexCoord;
|
in vec2 landscapeTexCoord;
|
||||||
#ifdef OC_DYNAMIC_LIGHT
|
#ifdef OC_DYNAMIC_LIGHT
|
||||||
varying vec2 lightTexCoord;
|
in vec2 lightTexCoord;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Input textures
|
// Input textures
|
||||||
|
@ -20,6 +20,8 @@ uniform sampler1D matMapTex;
|
||||||
uniform float materialDepth;
|
uniform float materialDepth;
|
||||||
uniform vec2 materialSize;
|
uniform vec2 materialSize;
|
||||||
|
|
||||||
|
out vec4 fragColor;
|
||||||
|
|
||||||
// Expected parameters for the scaler
|
// Expected parameters for the scaler
|
||||||
const vec2 scalerStepX = vec2(1.0 / 8.0, 0.0);
|
const vec2 scalerStepX = vec2(1.0 / 8.0, 0.0);
|
||||||
const vec2 scalerStepY = vec2(0.0, 1.0 / 32.0);
|
const vec2 scalerStepY = vec2(0.0, 1.0 / 32.0);
|
||||||
|
@ -28,7 +30,7 @@ const vec2 scalerPixel = vec2(scalerStepX.x, scalerStepY.y) / 3.0;
|
||||||
|
|
||||||
vec4 queryMatMap(int pix)
|
vec4 queryMatMap(int pix)
|
||||||
{
|
{
|
||||||
return texture1D(matMapTex, float(pix) / 2.0 / 256.0 + 0.5 / 2.0 / 256.0);
|
return texture(matMapTex, float(pix) / 2.0 / 256.0 + 0.5 / 2.0 / 256.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
slice(init)
|
slice(init)
|
||||||
|
@ -67,8 +69,8 @@ slice(coordinate)
|
||||||
slice(texture)
|
slice(texture)
|
||||||
{
|
{
|
||||||
// our pixel color (without/with interpolation)
|
// our pixel color (without/with interpolation)
|
||||||
vec4 landscapePx = texture2D(landscapeTex[0], centerCoo);
|
vec4 landscapePx = texture(landscapeTex[0], centerCoo);
|
||||||
vec4 realLandscapePx = texture2D(landscapeTex[0], texCoo);
|
vec4 realLandscapePx = texture(landscapeTex[0], texCoo);
|
||||||
|
|
||||||
// find scaler coordinate
|
// find scaler coordinate
|
||||||
vec2 scalerCoo = scalerOffset + mod(pixelCoo, vec2(1.0, 1.0)) * scalerPixel;
|
vec2 scalerCoo = scalerOffset + mod(pixelCoo, vec2(1.0, 1.0)) * scalerPixel;
|
||||||
|
@ -77,12 +79,12 @@ slice(texture)
|
||||||
scalerCoo.y += float(iScaler / 8) / 32.0;
|
scalerCoo.y += float(iScaler / 8) / 32.0;
|
||||||
|
|
||||||
// query scaler texture
|
// query scaler texture
|
||||||
vec4 scalerPx = texture2D(scalerTex, scalerCoo);
|
vec4 scalerPx = texture(scalerTex, scalerCoo);
|
||||||
|
|
||||||
// Get "second" landscape pixel
|
// Get "second" landscape pixel
|
||||||
vec2 centerCoo2 = centerCoo + fullStep * floor(vec2(-0.5, -0.5) +
|
vec2 centerCoo2 = centerCoo + fullStep * floor(vec2(-0.5, -0.5) +
|
||||||
scalerPx.gb * 255.0 / 64.0);
|
scalerPx.gb * 255.0 / 64.0);
|
||||||
vec4 landscapePx2 = texture2D(landscapeTex[0], centerCoo2);
|
vec4 landscapePx2 = texture(landscapeTex[0], centerCoo2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,12 +147,11 @@ slice(normal)
|
||||||
}
|
}
|
||||||
|
|
||||||
slice(color) {
|
slice(color) {
|
||||||
#define color gl_FragColor
|
fragColor = materialPx;
|
||||||
color = materialPx;
|
|
||||||
vec4 color2 = materialPx2;
|
vec4 color2 = materialPx2;
|
||||||
}
|
}
|
||||||
|
|
||||||
slice(color+10) {
|
slice(color+10) {
|
||||||
// Mix second color into main color according to scaler
|
// Mix second color into main color according to scaler
|
||||||
color = mix(color2, color, scalerPx.r);
|
fragColor = mix(color2, fragColor, scalerPx.r);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,13 +15,13 @@
|
||||||
|
|
||||||
// Default Vertex Shader for the landscape.
|
// Default Vertex Shader for the landscape.
|
||||||
|
|
||||||
attribute vec2 oc_Position;
|
in vec2 oc_Position;
|
||||||
attribute vec2 oc_LandscapeTexCoord;
|
in vec2 oc_LandscapeTexCoord;
|
||||||
attribute vec2 oc_LightTexCoord;
|
in vec2 oc_LightTexCoord;
|
||||||
|
|
||||||
varying vec2 landscapeTexCoord;
|
out vec2 landscapeTexCoord;
|
||||||
#ifdef OC_DYNAMIC_LIGHT
|
#ifdef OC_DYNAMIC_LIGHT
|
||||||
varying vec2 lightTexCoord;
|
out vec2 lightTexCoord;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uniform mat4 projectionMatrix;
|
uniform mat4 projectionMatrix;
|
||||||
|
|
|
@ -36,12 +36,12 @@
|
||||||
|
|
||||||
#define MAX_BONE_COUNT 80
|
#define MAX_BONE_COUNT 80
|
||||||
|
|
||||||
attribute vec3 oc_Position;
|
in vec3 oc_Position;
|
||||||
attribute vec3 oc_Normal;
|
in vec3 oc_Normal;
|
||||||
attribute vec2 oc_TexCoord;
|
in vec2 oc_TexCoord;
|
||||||
|
|
||||||
varying vec3 vtxNormal;
|
out vec3 vtxNormal;
|
||||||
varying vec2 texcoord;
|
out vec2 texcoord;
|
||||||
|
|
||||||
uniform mat4 projectionMatrix;
|
uniform mat4 projectionMatrix;
|
||||||
uniform mat4 modelviewMatrix;
|
uniform mat4 modelviewMatrix;
|
||||||
|
@ -58,12 +58,12 @@ uniform mat3x4 bones[MAX_BONE_COUNT];
|
||||||
// respectively. (Or we could split it even further.)
|
// respectively. (Or we could split it even further.)
|
||||||
#define BONE_COUNT 8
|
#define BONE_COUNT 8
|
||||||
|
|
||||||
attribute vec4 oc_BoneIndices0;
|
in vec4 oc_BoneIndices0;
|
||||||
attribute vec4 oc_BoneWeights0;
|
in vec4 oc_BoneWeights0;
|
||||||
|
|
||||||
#if BONE_COUNT > 4
|
#if BONE_COUNT > 4
|
||||||
attribute vec4 oc_BoneIndices1;
|
in vec4 oc_BoneIndices1;
|
||||||
attribute vec4 oc_BoneWeights1;
|
in vec4 oc_BoneWeights1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef OC_WA_LOW_MAX_VERTEX_UNIFORM_COMPONENTS
|
#ifndef OC_WA_LOW_MAX_VERTEX_UNIFORM_COMPONENTS
|
||||||
|
|
|
@ -21,18 +21,20 @@ uniform sampler2D overlayTex;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef OC_MESH
|
#ifdef OC_MESH
|
||||||
varying vec3 vtxNormal;
|
in vec3 vtxNormal;
|
||||||
varying vec2 texcoord;
|
in vec2 texcoord;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef OC_MESH
|
#ifndef OC_MESH
|
||||||
varying vec4 vtxColor;
|
in vec4 vtxColor;
|
||||||
#ifdef OC_HAVE_BASE
|
#ifdef OC_HAVE_BASE
|
||||||
uniform sampler2D baseTex;
|
uniform sampler2D baseTex;
|
||||||
varying vec2 texcoord;
|
in vec2 texcoord;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
out vec4 fragColor;
|
||||||
|
|
||||||
slice(material)
|
slice(material)
|
||||||
{
|
{
|
||||||
// Default material properties.
|
// Default material properties.
|
||||||
|
@ -48,28 +50,26 @@ slice(material)
|
||||||
|
|
||||||
slice(texture)
|
slice(texture)
|
||||||
{
|
{
|
||||||
#define color gl_FragColor
|
|
||||||
|
|
||||||
#ifdef OC_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.
|
||||||
color = materialDiffuse;
|
fragColor = materialDiffuse;
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#ifdef OC_HAVE_BASE
|
#ifdef OC_HAVE_BASE
|
||||||
// Texturing: Use color from texture, modulated with vertex color
|
// Texturing: Use color from texture, modulated with vertex color
|
||||||
color = vtxColor * texture2D(baseTex, texcoord);
|
fragColor = vtxColor * texture(baseTex, texcoord);
|
||||||
#ifdef OC_HAVE_OVERLAY
|
#ifdef OC_HAVE_OVERLAY
|
||||||
// Get overlay color from overlay texture
|
// Get overlay color from overlay texture
|
||||||
vec4 overlay = vtxColor * overlayClr * texture2D(overlayTex, texcoord);
|
vec4 overlay = vtxColor * overlayClr * texture(overlayTex, texcoord);
|
||||||
// Mix overlay with texture
|
// Mix overlay with texture
|
||||||
float alpha0 = 1.0 - (1.0 - color.a) * (1.0 - overlay.a);
|
float alpha0 = 1.0 - (1.0 - fragColor.a) * (1.0 - overlay.a);
|
||||||
color = vec4(mix(color.rgb, overlay.rgb, overlay.a / alpha0), alpha0);
|
fragColor = vec4(mix(fragColor.rgb, overlay.rgb, overlay.a / alpha0), alpha0);
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
// No texturing: Just use color assigned to vertex
|
// No texturing: Just use color assigned to vertex
|
||||||
color = vtxColor;
|
fragColor = vtxColor;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ slice(texture+4)
|
||||||
slice(normal)
|
slice(normal)
|
||||||
{
|
{
|
||||||
#ifdef OC_WITH_NORMALMAP
|
#ifdef OC_WITH_NORMALMAP
|
||||||
vec4 normalPx = texture2D(normalTex, texcoord);
|
vec4 normalPx = texture(normalTex, texcoord);
|
||||||
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));
|
||||||
vec3 normal = normalize(normalMatrix * normalPxDir);
|
vec3 normal = normalize(normalMatrix * normalPxDir);
|
||||||
#else
|
#else
|
||||||
|
@ -110,8 +110,8 @@ slice(color)
|
||||||
// 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 OC_CLRMOD_MOD2
|
#ifdef OC_CLRMOD_MOD2
|
||||||
color = vec4(clamp(color.rgb + clrMod.rgb - 0.5, 0.0, 1.0), color.a * clrMod.a);
|
fragColor = vec4(clamp(fragColor.rgb + clrMod.rgb - 0.5, 0.0, 1.0), fragColor.a * clrMod.a);
|
||||||
#else
|
#else
|
||||||
color = color * clrMod;
|
fragColor = fragColor * clrMod;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,17 +18,17 @@
|
||||||
uniform mat4 projectionMatrix;
|
uniform mat4 projectionMatrix;
|
||||||
uniform mat4 modelviewMatrix;
|
uniform mat4 modelviewMatrix;
|
||||||
|
|
||||||
attribute vec2 oc_Position;
|
in vec2 oc_Position;
|
||||||
attribute vec4 oc_Color;
|
in vec4 oc_Color;
|
||||||
|
|
||||||
#ifdef OC_HAVE_BASE
|
#ifdef OC_HAVE_BASE
|
||||||
attribute vec2 oc_TexCoord;
|
in vec2 oc_TexCoord;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
varying vec4 vtxColor;
|
out vec4 vtxColor;
|
||||||
|
|
||||||
#ifdef OC_HAVE_BASE
|
#ifdef OC_HAVE_BASE
|
||||||
varying vec2 texcoord;
|
out vec2 texcoord;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
slice(position)
|
slice(position)
|
||||||
|
|
|
@ -3,17 +3,17 @@ uniform sampler2D normalTex;
|
||||||
uniform mat3 normalMatrix;
|
uniform mat3 normalMatrix;
|
||||||
|
|
||||||
#ifndef OPENCLONK
|
#ifndef OPENCLONK
|
||||||
varying vec2 texcoord;
|
in vec2 texcoord;
|
||||||
|
out vec4 fragColor;
|
||||||
#define slice(x)
|
#define slice(x)
|
||||||
#define color gl_FragColor
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
color = vec4(1.0, 1.0, 1.0, 1.0);
|
fragColor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
slice(texture+1)
|
slice(texture+1)
|
||||||
{
|
{
|
||||||
color = color * texture2D(basemap, texcoord);
|
fragColor = fragColor * texture(basemap, texcoord);
|
||||||
|
|
||||||
#ifndef OPENCLONK
|
#ifndef OPENCLONK
|
||||||
// TODO: Could apply some default lighting here, for viewing the mesh in
|
// TODO: Could apply some default lighting here, for viewing the mesh in
|
||||||
|
@ -27,7 +27,7 @@ slice(normal+1)
|
||||||
// from ObjectShader.glsl. It's probably optimized out,
|
// from ObjectShader.glsl. It's probably optimized out,
|
||||||
// but a more elegant solution would be nice. Also maybe
|
// but a more elegant solution would be nice. Also maybe
|
||||||
// a function in UtilShader.glsl to reduce code duplication.
|
// a function in UtilShader.glsl to reduce code duplication.
|
||||||
vec4 normalPx = texture2D(normalTex, texcoord);
|
vec4 normalPx = texture(normalTex, texcoord);
|
||||||
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));
|
||||||
normal = normalize(normalMatrix * normalPxDir);
|
normal = normalize(normalMatrix * normalPxDir);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
attribute vec3 oc_Position;
|
in vec3 oc_Position;
|
||||||
attribute vec3 oc_Normal;
|
in vec3 oc_Normal;
|
||||||
attribute vec2 oc_TexCoord;
|
in vec2 oc_TexCoord;
|
||||||
|
|
||||||
varying vec3 vtxNormal;
|
out vec3 vtxNormal;
|
||||||
varying vec2 texcoord;
|
out vec2 texcoord;
|
||||||
|
|
||||||
uniform mat4 projectionMatrix;
|
uniform mat4 projectionMatrix;
|
||||||
uniform mat4 modelviewMatrix;
|
uniform mat4 modelviewMatrix;
|
||||||
|
|
|
@ -59,8 +59,8 @@ namespace
|
||||||
////////////////////////////////////////////
|
////////////////////////////////////////////
|
||||||
StdStrBuf Texture2DToCode(int index, bool hasTextureAnimation)
|
StdStrBuf Texture2DToCode(int index, bool hasTextureAnimation)
|
||||||
{
|
{
|
||||||
if (hasTextureAnimation) return FormatString("texture2D(oc_Texture%d, (oc_TextureMatrix%d * vec4(texcoord, 0.0, 1.0)).xy)", index, index);
|
if (hasTextureAnimation) return FormatString("texture(oc_Texture%d, (oc_TextureMatrix%d * vec4(texcoord, 0.0, 1.0)).xy)", index, index);
|
||||||
return FormatString("texture2D(oc_Texture%d, texcoord)", index);
|
return FormatString("texture(oc_Texture%d, texcoord)", index);
|
||||||
}
|
}
|
||||||
|
|
||||||
StdStrBuf TextureUnitSourceToCode(int index, StdMeshMaterialTextureUnit::BlendOpSourceType source, const float manualColor[3], float manualAlpha, bool hasTextureAnimation)
|
StdStrBuf TextureUnitSourceToCode(int index, StdMeshMaterialTextureUnit::BlendOpSourceType source, const float manualColor[3], float manualAlpha, bool hasTextureAnimation)
|
||||||
|
@ -123,17 +123,17 @@ namespace
|
||||||
case StdMeshMaterialPass::DF_AlwaysFail:
|
case StdMeshMaterialPass::DF_AlwaysFail:
|
||||||
return StdStrBuf("discard;");
|
return StdStrBuf("discard;");
|
||||||
case StdMeshMaterialPass::DF_Less:
|
case StdMeshMaterialPass::DF_Less:
|
||||||
return FormatString("if (!(color.a < %f)) discard;", pass.AlphaRejectionValue);
|
return FormatString("if (!(fragColor.a < %f)) discard;", pass.AlphaRejectionValue);
|
||||||
case StdMeshMaterialPass::DF_LessEqual:
|
case StdMeshMaterialPass::DF_LessEqual:
|
||||||
return FormatString("if (!(color.a <= %f)) discard;", pass.AlphaRejectionValue);
|
return FormatString("if (!(fragColor.a <= %f)) discard;", pass.AlphaRejectionValue);
|
||||||
case StdMeshMaterialPass::DF_Equal:
|
case StdMeshMaterialPass::DF_Equal:
|
||||||
return FormatString("if (!(color.a == %f)) discard;", pass.AlphaRejectionValue);
|
return FormatString("if (!(fragColor.a == %f)) discard;", pass.AlphaRejectionValue);
|
||||||
case StdMeshMaterialPass::DF_NotEqual:
|
case StdMeshMaterialPass::DF_NotEqual:
|
||||||
return FormatString("if (!(color.a != %f)) discard;", pass.AlphaRejectionValue);
|
return FormatString("if (!(fragColor.a != %f)) discard;", pass.AlphaRejectionValue);
|
||||||
case StdMeshMaterialPass::DF_Greater:
|
case StdMeshMaterialPass::DF_Greater:
|
||||||
return FormatString("if (!(color.a > %f)) discard;", pass.AlphaRejectionValue);
|
return FormatString("if (!(fragColor.a > %f)) discard;", pass.AlphaRejectionValue);
|
||||||
case StdMeshMaterialPass::DF_GreaterEqual:
|
case StdMeshMaterialPass::DF_GreaterEqual:
|
||||||
return FormatString("if (!(color.a >= %f)) discard;", pass.AlphaRejectionValue);
|
return FormatString("if (!(fragColor.a >= %f)) discard;", pass.AlphaRejectionValue);
|
||||||
default:
|
default:
|
||||||
assert(false);
|
assert(false);
|
||||||
return StdStrBuf();
|
return StdStrBuf();
|
||||||
|
@ -238,10 +238,10 @@ namespace
|
||||||
"\n"
|
"\n"
|
||||||
"slice(texture)\n"
|
"slice(texture)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" vec4 diffuse = color;\n"
|
" vec4 diffuse = fragColor;\n"
|
||||||
" vec4 currentColor = diffuse;\n"
|
" vec4 currentColor = diffuse;\n"
|
||||||
" %s\n"
|
" %s\n"
|
||||||
" color = currentColor;\n"
|
" fragColor = currentColor;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"\n"
|
"\n"
|
||||||
"slice(finish)\n"
|
"slice(finish)\n"
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
#include "C4Surface.h"
|
#include "C4Surface.h"
|
||||||
|
|
||||||
// Shader version
|
// Shader version
|
||||||
const int C4Shader_Version = 130; // GLSL 1.30 / OpenGL 3.0
|
const int C4Shader_Version = 150; // GLSL 1.50 / OpenGL 3.2
|
||||||
|
|
||||||
// Maximum number of texture coordinates
|
// Maximum number of texture coordinates
|
||||||
const int C4Shader_MaxTexCoords = 8;
|
const int C4Shader_MaxTexCoords = 8;
|
||||||
|
|
|
@ -34,9 +34,9 @@ C4Shader *C4FoW::GetFramebufShader()
|
||||||
// this is about how to utilise old frame buffer data in the lights texture.
|
// this is about how to utilise old frame buffer data in the lights texture.
|
||||||
// Or put in other words: This shader is responsible for fading lights out.
|
// Or put in other words: This shader is responsible for fading lights out.
|
||||||
const char* FramebufVertexShader =
|
const char* FramebufVertexShader =
|
||||||
"attribute vec2 oc_Position;\n"
|
"in vec2 oc_Position;\n"
|
||||||
"attribute vec2 oc_TexCoord;\n"
|
"in vec2 oc_TexCoord;\n"
|
||||||
"varying vec2 texcoord;\n"
|
"out vec2 texcoord;\n"
|
||||||
"uniform mat4 projectionMatrix;\n"
|
"uniform mat4 projectionMatrix;\n"
|
||||||
"\n"
|
"\n"
|
||||||
"slice(position)\n"
|
"slice(position)\n"
|
||||||
|
@ -50,12 +50,13 @@ C4Shader *C4FoW::GetFramebufShader()
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
const char* FramebufFragmentShader =
|
const char* FramebufFragmentShader =
|
||||||
"varying vec2 texcoord;\n"
|
"in vec2 texcoord;\n"
|
||||||
"uniform sampler2D tex;\n"
|
"uniform sampler2D tex;\n"
|
||||||
|
"out vec4 fragColor;\n"
|
||||||
"\n"
|
"\n"
|
||||||
"slice(color)\n"
|
"slice(color)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" gl_FragColor = texture2D(tex, texcoord);\n"
|
" fragColor = texture(tex, texcoord);\n"
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
FramebufShader.AddVertexSlices("built-in FoW framebuf shader", FramebufVertexShader);
|
FramebufShader.AddVertexSlices("built-in FoW framebuf shader", FramebufVertexShader);
|
||||||
|
@ -90,9 +91,9 @@ C4Shader *C4FoW::GetRenderShader()
|
||||||
{
|
{
|
||||||
// Create the render shader. Fairly simple pass-through.
|
// Create the render shader. Fairly simple pass-through.
|
||||||
const char* RenderVertexShader =
|
const char* RenderVertexShader =
|
||||||
"attribute vec2 oc_Position;\n"
|
"in vec2 oc_Position;\n"
|
||||||
"attribute vec4 oc_Color;\n"
|
"in vec4 oc_Color;\n"
|
||||||
"varying vec4 vtxColor;\n"
|
"out vec4 vtxColor;\n"
|
||||||
"uniform mat4 projectionMatrix;\n"
|
"uniform mat4 projectionMatrix;\n"
|
||||||
"uniform vec2 vertexOffset;\n"
|
"uniform vec2 vertexOffset;\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
@ -107,11 +108,12 @@ C4Shader *C4FoW::GetRenderShader()
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
const char* RenderFragmentShader =
|
const char* RenderFragmentShader =
|
||||||
"varying vec4 vtxColor;\n"
|
"in vec4 vtxColor;\n"
|
||||||
|
"out vec4 fragColor;\n"
|
||||||
"\n"
|
"\n"
|
||||||
"slice(color)\n"
|
"slice(color)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" gl_FragColor = vtxColor;\n"
|
" fragColor = vtxColor;\n"
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
RenderShader.AddVertexSlices("built-in FoW render shader", RenderVertexShader);
|
RenderShader.AddVertexSlices("built-in FoW render shader", RenderVertexShader);
|
||||||
|
|
Loading…
Reference in New Issue