From: havoc Date: Tue, 25 Jan 2005 23:59:23 +0000 (+0000) Subject: fixed the embedded fragment and vertex shaders (somehow mispasted fragment shader... X-Git-Tag: xonotic-v0.1.0preview~5184 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=1a47fd0750ef498ccc09b0d8548788e5e09487ed;p=xonotic%2Fdarkplaces.git fixed the embedded fragment and vertex shaders (somehow mispasted fragment shader into both, and the fragment shader was the old NVIDIA-only one) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4965 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/r_shadow.c b/r_shadow.c index dc53d7fe..0341dac0 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -251,90 +251,47 @@ const char *builtinshader_light_vert = "// ambient+diffuse+specular+normalmap+attenuation+cubemap+fog shader\n" "// written by Forest 'LordHavoc' Hale\n" "\n" -"uniform vec3 LightColor;\n" -"\n" -"#ifdef USEOFFSETMAPPING\n" -"uniform float OffsetMapping_Scale;\n" -"uniform float OffsetMapping_Bias;\n" -"#endif\n" -"#ifdef USESPECULAR\n" -"uniform float SpecularPower;\n" -"#endif\n" -"#ifdef USEFOG\n" -"uniform float FogRangeRecip;\n" -"#endif\n" -"uniform float AmbientScale;\n" -"uniform float DiffuseScale;\n" -"#ifdef USESPECULAR\n" -"uniform float SpecularScale;\n" -"#endif\n" -"\n" -"uniform sampler2D Texture_Normal;\n" -"uniform sampler2D Texture_Color;\n" -"#ifdef USESPECULAR\n" -"uniform sampler2D Texture_Gloss;\n" -"#endif\n" -"#ifdef USECUBEFILTER\n" -"uniform samplerCube Texture_Cube;\n" -"#endif\n" -"#ifdef USEFOG\n" -"uniform sampler2D Texture_FogMask;\n" -"#endif\n" +"uniform vec3 LightPosition;\n" "\n" "varying vec2 TexCoord;\n" "varying vec3 CubeVector;\n" "varying vec3 LightVector;\n" +"\n" "#if defined(USESPECULAR) || defined(USEFOG) || defined(USEOFFSETMAPPING)\n" +"uniform vec3 EyePosition;\n" "varying vec3 EyeVector;\n" "#endif\n" "\n" +"// TODO: get rid of tangentt (texcoord2) and use a crossproduct to regenerate it from tangents (texcoord1) and normal (texcoord3)\n" +"\n" "void main(void)\n" "{\n" -" // attenuation\n" -" //\n" -" // the attenuation is (1-(x*x+y*y+z*z)) which gives a large bright\n" -" // center and sharp falloff at the edge, this is about the most efficient\n" -" // we can get away with as far as providing illumination.\n" -" //\n" -" // pow(1-(x*x+y*y+z*z), 4) is far more realistic but needs large lights to\n" -" // provide significant illumination, large = slow = pain.\n" -" float colorscale = clamp(1.0 - dot(CubeVector, CubeVector), 0.0, 1.0);\n" +" // copy the surface texcoord\n" +" TexCoord = gl_MultiTexCoord0.st;\n" "\n" -"#ifdef USEFOG\n" -" // apply fog\n" -" colorscale *= texture2D(Texture_FogMask, vec2(length(EyeVector)*FogRangeRecip, 0)).x;\n" -"#endif\n" +" // transform vertex position into light attenuation/cubemap space\n" +" // (-1 to +1 across the light box)\n" +" CubeVector = vec3(gl_TextureMatrix[3] * gl_Vertex);\n" "\n" -"#ifdef USEOFFSETMAPPING\n" -" vec2 OffsetVector = normalize(EyeVector).xy * vec2(-1, 1);\n" -" vec2 TexCoordOffset = TexCoord + OffsetVector * (OffsetMapping_Bias + OffsetMapping_Scale * texture2D(Texture_Normal, TexCoord).w);\n" -" TexCoordOffset += OffsetVector * (OffsetMapping_Bias + OffsetMapping_Scale * texture2D(Texture_Normal, TexCoordOffset).w);\n" -" TexCoordOffset += OffsetVector * (OffsetMapping_Bias + OffsetMapping_Scale * texture2D(Texture_Normal, TexCoordOffset).w);\n" -" TexCoordOffset += OffsetVector * (OffsetMapping_Bias + OffsetMapping_Scale * texture2D(Texture_Normal, TexCoordOffset).w);\n" -"#define TexCoord TexCoordOffset\n" -"#endif\n" -"\n" -" // get the texels - with a blendmap we'd need to blend multiple here\n" -" vec3 surfacenormal = -1.0 + 2.0 * vec3(texture2D(Texture_Normal, TexCoord));\n" -" vec3 colortexel = vec3(texture2D(Texture_Color, TexCoord));\n" -"#ifdef USESPECULAR\n" -" vec3 glosstexel = vec3(texture2D(Texture_Gloss, TexCoord));\n" -"#endif\n" -"\n" -" // calculate shading\n" -" vec3 diffusenormal = normalize(LightVector);\n" -" vec3 color = colortexel * (AmbientScale + DiffuseScale * clamp(dot(surfacenormal, diffusenormal), 0.0, 1.0));\n" -"#ifdef USESPECULAR\n" -" color += glosstexel * (SpecularScale * pow(clamp(dot(surfacenormal, normalize(diffusenormal + normalize(EyeVector))), 0.0, 1.0), SpecularPower));\n" -"#endif\n" +" // transform unnormalized light direction into tangent space\n" +" // (we use unnormalized to ensure that it interpolates correctly and then\n" +" // normalize it per pixel)\n" +" vec3 lightminusvertex = LightPosition - gl_Vertex.xyz;\n" +" LightVector.x = dot(lightminusvertex, gl_MultiTexCoord1.xyz);\n" +" LightVector.y = dot(lightminusvertex, gl_MultiTexCoord2.xyz);\n" +" LightVector.z = -dot(lightminusvertex, gl_MultiTexCoord3.xyz);\n" "\n" -"#ifdef USECUBEFILTER\n" -" // apply light cubemap filter\n" -" color *= vec3(textureCube(Texture_Cube, CubeVector));\n" +"#if defined(USESPECULAR) || defined(USEFOG) || defined(USEOFFSETMAPPING)\n" +" // transform unnormalized eye direction into tangent space\n" +" vec3 eyeminusvertex = EyePosition - gl_Vertex.xyz;\n" +" EyeVector.x = dot(eyeminusvertex, gl_MultiTexCoord1.xyz);\n" +" EyeVector.y = dot(eyeminusvertex, gl_MultiTexCoord2.xyz);\n" +" EyeVector.z = -dot(eyeminusvertex, gl_MultiTexCoord3.xyz);\n" "#endif\n" "\n" -" // calculate fragment color\n" -" gl_FragColor = vec4(LightColor * color * colorscale, 1);\n" +" // transform vertex to camera space, using ftransform to match non-VS\n" +" // rendering\n" +" gl_Position = ftransform();\n" "}\n" ; @@ -398,19 +355,15 @@ const char *builtinshader_light_frag = "\n" "#ifdef USEOFFSETMAPPING\n" " vec2 OffsetVector = normalize(EyeVector).xy * vec2(-1, 1);\n" -" TexCoord += OffsetVector * (texture2D(Texture_Normal, TexCoord).w * OffsetMapping_Scale + OffsetMapping_Bias);\n" -" TexCoord += OffsetVector * (texture2D(Texture_Normal, TexCoord).w * OffsetMapping_Scale + OffsetMapping_Bias);\n" -" TexCoord += OffsetVector * (texture2D(Texture_Normal, TexCoord).w * OffsetMapping_Scale + OffsetMapping_Bias);\n" -" TexCoord += OffsetVector * (texture2D(Texture_Normal, TexCoord).w * OffsetMapping_Scale + OffsetMapping_Bias);\n" -"#endif\n" -"\n" -"#ifdef USECUBEFILTER\n" -" // apply light cubemap filter\n" -" LightColor *= vec3(textureCube(Texture_Cube, CubeVector));\n" +" vec2 TexCoordOffset = TexCoord + OffsetVector * (OffsetMapping_Bias + OffsetMapping_Scale * texture2D(Texture_Normal, TexCoord).w);\n" +" TexCoordOffset += OffsetVector * (OffsetMapping_Bias + OffsetMapping_Scale * texture2D(Texture_Normal, TexCoordOffset).w);\n" +" TexCoordOffset += OffsetVector * (OffsetMapping_Bias + OffsetMapping_Scale * texture2D(Texture_Normal, TexCoordOffset).w);\n" +" TexCoordOffset += OffsetVector * (OffsetMapping_Bias + OffsetMapping_Scale * texture2D(Texture_Normal, TexCoordOffset).w);\n" +"#define TexCoord TexCoordOffset\n" "#endif\n" "\n" " // get the texels - with a blendmap we'd need to blend multiple here\n" -" vec3 surfacenormal = vec3(texture2D(Texture_Normal, TexCoord)) * 2.0 - 1.0;\n" +" vec3 surfacenormal = -1.0 + 2.0 * vec3(texture2D(Texture_Normal, TexCoord));\n" " vec3 colortexel = vec3(texture2D(Texture_Color, TexCoord));\n" "#ifdef USESPECULAR\n" " vec3 glosstexel = vec3(texture2D(Texture_Gloss, TexCoord));\n" @@ -423,6 +376,11 @@ const char *builtinshader_light_frag = " color += glosstexel * (SpecularScale * pow(clamp(dot(surfacenormal, normalize(diffusenormal + normalize(EyeVector))), 0.0, 1.0), SpecularPower));\n" "#endif\n" "\n" +"#ifdef USECUBEFILTER\n" +" // apply light cubemap filter\n" +" color *= vec3(textureCube(Texture_Cube, CubeVector));\n" +"#endif\n" +"\n" " // calculate fragment color\n" " gl_FragColor = vec4(LightColor * color * colorscale, 1);\n" "}\n"