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
|
||||
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));
|
||||
vec3 lightDir = normalize(vec3(vec2(1.0, 1.0) - lightPx.yz * 3.0, lightDepth));
|
||||
|
||||
// Query light color texture (part of the light 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
|
||||
#ifdef LIGHT_DEBUG_COLOR
|
||||
|
@ -93,7 +93,7 @@ slice(texture+5)
|
|||
|
||||
// Ambient light
|
||||
// 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;
|
||||
#ifdef OC_SKY
|
||||
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
|
||||
// brightness overrules everything though (= FoW is last factor).
|
||||
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
|
||||
vec3 spotLight2 = pow(vec3(light2,light2,light2), matSpot2);
|
||||
color2.rgb = lightBright * color2.rgb * (matEmit2 + lightColorNorm * spotLight2);
|
||||
|
@ -159,18 +159,18 @@ slice(finish+5)
|
|||
float lightYDir = lightPx.b - 1.0/3.0;
|
||||
float lightXDir = lightPx.g - 1.0/3.0;
|
||||
float lightStrength = lightPx.a;
|
||||
color =
|
||||
fragColor =
|
||||
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)),
|
||||
1.0);
|
||||
#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
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
varying vec2 landscapeTexCoord;
|
||||
in vec2 landscapeTexCoord;
|
||||
#ifdef OC_DYNAMIC_LIGHT
|
||||
varying vec2 lightTexCoord;
|
||||
in vec2 lightTexCoord;
|
||||
#endif
|
||||
|
||||
// Input textures
|
||||
|
@ -20,6 +20,8 @@ uniform sampler1D matMapTex;
|
|||
uniform float materialDepth;
|
||||
uniform vec2 materialSize;
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
// Expected parameters for the scaler
|
||||
const vec2 scalerStepX = vec2(1.0 / 8.0, 0.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)
|
||||
{
|
||||
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)
|
||||
|
@ -67,8 +69,8 @@ slice(coordinate)
|
|||
slice(texture)
|
||||
{
|
||||
// our pixel color (without/with interpolation)
|
||||
vec4 landscapePx = texture2D(landscapeTex[0], centerCoo);
|
||||
vec4 realLandscapePx = texture2D(landscapeTex[0], texCoo);
|
||||
vec4 landscapePx = texture(landscapeTex[0], centerCoo);
|
||||
vec4 realLandscapePx = texture(landscapeTex[0], texCoo);
|
||||
|
||||
// find scaler coordinate
|
||||
vec2 scalerCoo = scalerOffset + mod(pixelCoo, vec2(1.0, 1.0)) * scalerPixel;
|
||||
|
@ -77,12 +79,12 @@ slice(texture)
|
|||
scalerCoo.y += float(iScaler / 8) / 32.0;
|
||||
|
||||
// query scaler texture
|
||||
vec4 scalerPx = texture2D(scalerTex, scalerCoo);
|
||||
vec4 scalerPx = texture(scalerTex, scalerCoo);
|
||||
|
||||
// Get "second" landscape pixel
|
||||
vec2 centerCoo2 = centerCoo + fullStep * floor(vec2(-0.5, -0.5) +
|
||||
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) {
|
||||
#define color gl_FragColor
|
||||
color = materialPx;
|
||||
fragColor = materialPx;
|
||||
vec4 color2 = materialPx2;
|
||||
}
|
||||
|
||||
slice(color+10) {
|
||||
// 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.
|
||||
|
||||
attribute vec2 oc_Position;
|
||||
attribute vec2 oc_LandscapeTexCoord;
|
||||
attribute vec2 oc_LightTexCoord;
|
||||
in vec2 oc_Position;
|
||||
in vec2 oc_LandscapeTexCoord;
|
||||
in vec2 oc_LightTexCoord;
|
||||
|
||||
varying vec2 landscapeTexCoord;
|
||||
out vec2 landscapeTexCoord;
|
||||
#ifdef OC_DYNAMIC_LIGHT
|
||||
varying vec2 lightTexCoord;
|
||||
out vec2 lightTexCoord;
|
||||
#endif
|
||||
|
||||
uniform mat4 projectionMatrix;
|
||||
|
|
|
@ -36,12 +36,12 @@
|
|||
|
||||
#define MAX_BONE_COUNT 80
|
||||
|
||||
attribute vec3 oc_Position;
|
||||
attribute vec3 oc_Normal;
|
||||
attribute vec2 oc_TexCoord;
|
||||
in vec3 oc_Position;
|
||||
in vec3 oc_Normal;
|
||||
in vec2 oc_TexCoord;
|
||||
|
||||
varying vec3 vtxNormal;
|
||||
varying vec2 texcoord;
|
||||
out vec3 vtxNormal;
|
||||
out vec2 texcoord;
|
||||
|
||||
uniform mat4 projectionMatrix;
|
||||
uniform mat4 modelviewMatrix;
|
||||
|
@ -58,12 +58,12 @@ uniform mat3x4 bones[MAX_BONE_COUNT];
|
|||
// respectively. (Or we could split it even further.)
|
||||
#define BONE_COUNT 8
|
||||
|
||||
attribute vec4 oc_BoneIndices0;
|
||||
attribute vec4 oc_BoneWeights0;
|
||||
in vec4 oc_BoneIndices0;
|
||||
in vec4 oc_BoneWeights0;
|
||||
|
||||
#if BONE_COUNT > 4
|
||||
attribute vec4 oc_BoneIndices1;
|
||||
attribute vec4 oc_BoneWeights1;
|
||||
in vec4 oc_BoneIndices1;
|
||||
in vec4 oc_BoneWeights1;
|
||||
#endif
|
||||
|
||||
#ifndef OC_WA_LOW_MAX_VERTEX_UNIFORM_COMPONENTS
|
||||
|
|
|
@ -21,18 +21,20 @@ uniform sampler2D overlayTex;
|
|||
#endif
|
||||
|
||||
#ifdef OC_MESH
|
||||
varying vec3 vtxNormal;
|
||||
varying vec2 texcoord;
|
||||
in vec3 vtxNormal;
|
||||
in vec2 texcoord;
|
||||
#endif
|
||||
|
||||
#ifndef OC_MESH
|
||||
varying vec4 vtxColor;
|
||||
in vec4 vtxColor;
|
||||
#ifdef OC_HAVE_BASE
|
||||
uniform sampler2D baseTex;
|
||||
varying vec2 texcoord;
|
||||
in vec2 texcoord;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
slice(material)
|
||||
{
|
||||
// Default material properties.
|
||||
|
@ -48,28 +50,26 @@ slice(material)
|
|||
|
||||
slice(texture)
|
||||
{
|
||||
#define color gl_FragColor
|
||||
|
||||
#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.
|
||||
color = materialDiffuse;
|
||||
fragColor = materialDiffuse;
|
||||
#else
|
||||
|
||||
#ifdef OC_HAVE_BASE
|
||||
// Texturing: Use color from texture, modulated with vertex color
|
||||
color = vtxColor * texture2D(baseTex, texcoord);
|
||||
fragColor = vtxColor * texture(baseTex, texcoord);
|
||||
#ifdef OC_HAVE_OVERLAY
|
||||
// Get overlay color from overlay texture
|
||||
vec4 overlay = vtxColor * overlayClr * texture2D(overlayTex, texcoord);
|
||||
vec4 overlay = vtxColor * overlayClr * texture(overlayTex, texcoord);
|
||||
// Mix overlay with texture
|
||||
float alpha0 = 1.0 - (1.0 - color.a) * (1.0 - overlay.a);
|
||||
color = vec4(mix(color.rgb, overlay.rgb, overlay.a / alpha0), alpha0);
|
||||
float alpha0 = 1.0 - (1.0 - fragColor.a) * (1.0 - overlay.a);
|
||||
fragColor = vec4(mix(fragColor.rgb, overlay.rgb, overlay.a / alpha0), alpha0);
|
||||
#endif
|
||||
#else
|
||||
// No texturing: Just use color assigned to vertex
|
||||
color = vtxColor;
|
||||
fragColor = vtxColor;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ slice(texture+4)
|
|||
slice(normal)
|
||||
{
|
||||
#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 normal = normalize(normalMatrix * normalPxDir);
|
||||
#else
|
||||
|
@ -110,8 +110,8 @@ slice(color)
|
|||
// out = (color, clrmod, 1) * (A,B,C,D,E,F,0,0,G) * (color, clrmod, 1)
|
||||
|
||||
#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
|
||||
color = color * clrMod;
|
||||
fragColor = fragColor * clrMod;
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -18,17 +18,17 @@
|
|||
uniform mat4 projectionMatrix;
|
||||
uniform mat4 modelviewMatrix;
|
||||
|
||||
attribute vec2 oc_Position;
|
||||
attribute vec4 oc_Color;
|
||||
in vec2 oc_Position;
|
||||
in vec4 oc_Color;
|
||||
|
||||
#ifdef OC_HAVE_BASE
|
||||
attribute vec2 oc_TexCoord;
|
||||
in vec2 oc_TexCoord;
|
||||
#endif
|
||||
|
||||
varying vec4 vtxColor;
|
||||
out vec4 vtxColor;
|
||||
|
||||
#ifdef OC_HAVE_BASE
|
||||
varying vec2 texcoord;
|
||||
out vec2 texcoord;
|
||||
#endif
|
||||
|
||||
slice(position)
|
||||
|
|
|
@ -3,17 +3,17 @@ uniform sampler2D normalTex;
|
|||
uniform mat3 normalMatrix;
|
||||
|
||||
#ifndef OPENCLONK
|
||||
varying vec2 texcoord;
|
||||
in vec2 texcoord;
|
||||
out vec4 fragColor;
|
||||
#define slice(x)
|
||||
#define color gl_FragColor
|
||||
void main()
|
||||
{
|
||||
color = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
fragColor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
#endif
|
||||
|
||||
slice(texture+1)
|
||||
{
|
||||
color = color * texture2D(basemap, texcoord);
|
||||
fragColor = fragColor * texture(basemap, texcoord);
|
||||
|
||||
#ifndef OPENCLONK
|
||||
// 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,
|
||||
// but a more elegant solution would be nice. Also maybe
|
||||
// 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));
|
||||
normal = normalize(normalMatrix * normalPxDir);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
attribute vec3 oc_Position;
|
||||
attribute vec3 oc_Normal;
|
||||
attribute vec2 oc_TexCoord;
|
||||
in vec3 oc_Position;
|
||||
in vec3 oc_Normal;
|
||||
in vec2 oc_TexCoord;
|
||||
|
||||
varying vec3 vtxNormal;
|
||||
varying vec2 texcoord;
|
||||
out vec3 vtxNormal;
|
||||
out vec2 texcoord;
|
||||
|
||||
uniform mat4 projectionMatrix;
|
||||
uniform mat4 modelviewMatrix;
|
||||
|
|
|
@ -59,8 +59,8 @@ namespace
|
|||
////////////////////////////////////////////
|
||||
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);
|
||||
return FormatString("texture2D(oc_Texture%d, texcoord)", index);
|
||||
if (hasTextureAnimation) return FormatString("texture(oc_Texture%d, (oc_TextureMatrix%d * vec4(texcoord, 0.0, 1.0)).xy)", index, index);
|
||||
return FormatString("texture(oc_Texture%d, texcoord)", index);
|
||||
}
|
||||
|
||||
StdStrBuf TextureUnitSourceToCode(int index, StdMeshMaterialTextureUnit::BlendOpSourceType source, const float manualColor[3], float manualAlpha, bool hasTextureAnimation)
|
||||
|
@ -123,17 +123,17 @@ namespace
|
|||
case StdMeshMaterialPass::DF_AlwaysFail:
|
||||
return StdStrBuf("discard;");
|
||||
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:
|
||||
return FormatString("if (!(color.a <= %f)) discard;", pass.AlphaRejectionValue);
|
||||
return FormatString("if (!(fragColor.a <= %f)) discard;", pass.AlphaRejectionValue);
|
||||
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:
|
||||
return FormatString("if (!(color.a != %f)) discard;", pass.AlphaRejectionValue);
|
||||
return FormatString("if (!(fragColor.a != %f)) discard;", pass.AlphaRejectionValue);
|
||||
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:
|
||||
return FormatString("if (!(color.a >= %f)) discard;", pass.AlphaRejectionValue);
|
||||
return FormatString("if (!(fragColor.a >= %f)) discard;", pass.AlphaRejectionValue);
|
||||
default:
|
||||
assert(false);
|
||||
return StdStrBuf();
|
||||
|
@ -238,10 +238,10 @@ namespace
|
|||
"\n"
|
||||
"slice(texture)\n"
|
||||
"{\n"
|
||||
" vec4 diffuse = color;\n"
|
||||
" vec4 diffuse = fragColor;\n"
|
||||
" vec4 currentColor = diffuse;\n"
|
||||
" %s\n"
|
||||
" color = currentColor;\n"
|
||||
" fragColor = currentColor;\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"slice(finish)\n"
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include "C4Surface.h"
|
||||
|
||||
// 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
|
||||
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.
|
||||
// Or put in other words: This shader is responsible for fading lights out.
|
||||
const char* FramebufVertexShader =
|
||||
"attribute vec2 oc_Position;\n"
|
||||
"attribute vec2 oc_TexCoord;\n"
|
||||
"varying vec2 texcoord;\n"
|
||||
"in vec2 oc_Position;\n"
|
||||
"in vec2 oc_TexCoord;\n"
|
||||
"out vec2 texcoord;\n"
|
||||
"uniform mat4 projectionMatrix;\n"
|
||||
"\n"
|
||||
"slice(position)\n"
|
||||
|
@ -50,12 +50,13 @@ C4Shader *C4FoW::GetFramebufShader()
|
|||
"}";
|
||||
|
||||
const char* FramebufFragmentShader =
|
||||
"varying vec2 texcoord;\n"
|
||||
"in vec2 texcoord;\n"
|
||||
"uniform sampler2D tex;\n"
|
||||
"out vec4 fragColor;\n"
|
||||
"\n"
|
||||
"slice(color)\n"
|
||||
"{\n"
|
||||
" gl_FragColor = texture2D(tex, texcoord);\n"
|
||||
" fragColor = texture(tex, texcoord);\n"
|
||||
"}";
|
||||
|
||||
FramebufShader.AddVertexSlices("built-in FoW framebuf shader", FramebufVertexShader);
|
||||
|
@ -90,9 +91,9 @@ C4Shader *C4FoW::GetRenderShader()
|
|||
{
|
||||
// Create the render shader. Fairly simple pass-through.
|
||||
const char* RenderVertexShader =
|
||||
"attribute vec2 oc_Position;\n"
|
||||
"attribute vec4 oc_Color;\n"
|
||||
"varying vec4 vtxColor;\n"
|
||||
"in vec2 oc_Position;\n"
|
||||
"in vec4 oc_Color;\n"
|
||||
"out vec4 vtxColor;\n"
|
||||
"uniform mat4 projectionMatrix;\n"
|
||||
"uniform vec2 vertexOffset;\n"
|
||||
"\n"
|
||||
|
@ -107,11 +108,12 @@ C4Shader *C4FoW::GetRenderShader()
|
|||
"}";
|
||||
|
||||
const char* RenderFragmentShader =
|
||||
"varying vec4 vtxColor;\n"
|
||||
"in vec4 vtxColor;\n"
|
||||
"out vec4 fragColor;\n"
|
||||
"\n"
|
||||
"slice(color)\n"
|
||||
"{\n"
|
||||
" gl_FragColor = vtxColor;\n"
|
||||
" fragColor = vtxColor;\n"
|
||||
"}";
|
||||
|
||||
RenderShader.AddVertexSlices("built-in FoW render shader", RenderVertexShader);
|
||||
|
|
Loading…
Reference in New Issue