]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
updated default glsl shader
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 17 Mar 2006 06:34:13 +0000 (06:34 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 17 Mar 2006 06:34:13 +0000 (06:34 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6129 d7cf8633-e32d-0410-b094-e92efae38249

gl_rmain.c

index a7dc2c3e0cb5ec48246e620dca1a4c75c114d282..fb0295c14296e7aa7ccdd3273dd26377215e3267 100644 (file)
@@ -428,9 +428,15 @@ static const char *builtinshaderstring =
 "#endif\n"
 "\n"
 "varying vec2 TexCoord;\n"
+"#if !defined(MODE_LIGHTSOURCE) && !defined(MODE_LIGHTDIRECTION)\n"
+"varying vec2 TexCoordLightmap;\n"
+"#endif\n"
 "\n"
-"#ifdef USELIGHTSOURCE\n"
+"#ifdef MODE_LIGHTSOURCE\n"
 "varying myhvec3 CubeVector;\n"
+"#endif\n"
+"\n"
+"#if defined(MODE_LIGHTSOURCE) || defined(MODE_LIGHTDIRECTION)\n"
 "varying vec3 LightVector;\n"
 "#endif\n"
 "\n"
@@ -444,7 +450,7 @@ static const char *builtinshaderstring =
 "// vertex shader specific:\n"
 "#ifdef VERTEX_SHADER\n"
 "\n"
-"#ifdef USELIGHTSOURCE\n"
+"#ifdef MODE_LIGHTSOURCE\n"
 "uniform vec3 LightPosition;\n"
 "#endif\n"
 "\n"
@@ -452,14 +458,22 @@ static const char *builtinshaderstring =
 "uniform vec3 EyePosition;\n"
 "#endif\n"
 "\n"
+"#ifdef MODE_LIGHTDIRECTION\n"
+"uniform myhvec3 LightDir;\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"
 "      // copy the surface texcoord\n"
 "      TexCoord = vec2(gl_TextureMatrix[0] * gl_MultiTexCoord0);\n"
+"#if !defined(MODE_LIGHTSOURCE) && !defined(MODE_LIGHTDIRECTION)\n"
+"      TexCoordLightmap = vec2(gl_MultiTexCoord4);\n"
+"#endif\n"
+"      gl_FrontColor = gl_Color;\n"
 "\n"
-"#ifdef USELIGHTSOURCE\n"
+"#ifdef MODE_LIGHTSOURCE\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"
@@ -473,6 +487,12 @@ static const char *builtinshaderstring =
 "      LightVector.z = dot(lightminusvertex, gl_MultiTexCoord3.xyz);\n"
 "#endif\n"
 "\n"
+"#ifdef MODE_LIGHTDIRECTION\n"
+"      LightVector.x = dot(LightDir, gl_MultiTexCoord1.xyz);\n"
+"      LightVector.y = dot(LightDir, gl_MultiTexCoord2.xyz);\n"
+"      LightVector.z = dot(LightDir, gl_MultiTexCoord3.xyz);\n"
+"#endif\n"
+"\n"
 "#if defined(USESPECULAR) || defined(USEFOG) || defined(USEOFFSETMAPPING)\n"
 "      // transform unnormalized eye direction into tangent space\n"
 "      vec3 eyeminusvertex = EyePosition - gl_Vertex.xyz;\n"
@@ -500,12 +520,29 @@ static const char *builtinshaderstring =
 "uniform myhalf OffsetMapping_Bias;\n"
 "#endif\n"
 "\n"
-"#if defined(USELIGHTSOURCE) || defined(USEDELUXEMAPPING)\n"
+"#if defined(MODE_LIGHTSOURCE) || defined(MODE_LIGHTDIRECTIONMAP) || defined(MODE_LIGHTDIRECTION) || defined(USEOFFSETMAPPING)\n"
 "uniform sampler2D Texture_Normal;\n"
 "#endif\n"
 "\n"
+"#ifdef MODE_LIGHTDIRECTION\n"
+"uniform myhvec3 AmbientColor;\n"
+"uniform myhvec3 DiffuseColor;\n"
+"uniform myhvec3 SpecularColor;\n"
+"#endif\n"
+"\n"
 "uniform sampler2D Texture_Color;\n"
 "\n"
+"#if !defined(MODE_LIGHTSOURCE) && !defined(MODE_LIGHTDIRECTION)\n"
+"uniform sampler2D Texture_Lightmap;\n"
+"#endif\n"
+"#ifdef MODE_LIGHTDIRECTIONMAP\n"
+"uniform sampler2D Texture_Deluxemap;\n"
+"#endif\n"
+"\n"
+"#ifdef USEGLOW\n"
+"uniform sampler2D Texture_Glow;\n"
+"#endif\n"
+"\n"
 "#ifdef USECOLORMAPPING\n"
 "uniform sampler2D Texture_Pants;\n"
 "uniform sampler2D Texture_Shirt;\n"
@@ -526,10 +563,34 @@ static const char *builtinshaderstring =
 "#endif\n"
 "\n"
 "#ifdef USEFOG\n"
+"uniform myhvec3 FogColor;\n"
 "uniform myhalf FogRangeRecip;\n"
 "uniform sampler2D Texture_FogMask;\n"
 "#endif\n"
 "\n"
+"#ifdef USEEASTEREGG\n"
+"void main(void)\n"
+"{\n"
+"      gl_FragColor = myhvec4(0, 0, 0, 1);;\n"
+"      int i;\n"
+"      float o;\n"
+"      vec2 p = vec2(CubeVector.x * 16.0, CubeVector.y * 16.0);\n"
+"      vec2 c = vec2(CubeVector.x * 16.0, CubeVector.y * 16.0);\n"
+"      for (i = 0;i < 1000 && dot(p,p) < 4.0;i = i + 1)\n"
+"      {\n"
+"              o = p.x * p.x - p.y * p.y;\n"
+"              p.y = 2.0 * p.x * p.y;\n"
+"              p.x = o;\n"
+"              p += c;\n"
+"      }\n"
+"      o = float(i) * 0.314;\n"
+"      if (i < 1000)\n"
+"              gl_FragColor = vec4(cos(o), sin(o), sin(o * 0.2), 1);\n"
+"}\n"
+"#else // USEEASTEREGG\n"
+"\n"
+"\n"
+"\n"
 "void main(void)\n"
 "{\n"
 "      // apply offsetmapping\n"
@@ -551,7 +612,7 @@ static const char *builtinshaderstring =
 "\n"
 "\n"
 "\n"
-"#ifdef USELIGHTSOURCE\n"
+"#ifdef MODE_LIGHTSOURCE\n"
 "      // light source\n"
 "\n"
 "      // get the surface normal and light normal\n"
@@ -590,8 +651,30 @@ static const char *builtinshaderstring =
 "\n"
 "\n"
 "\n"
+"#elif defined(MODE_LIGHTDIRECTION)\n"
+"      // directional model lighting\n"
+"\n"
+"      // get the surface normal and light normal\n"
+"#ifdef SURFACENORMALIZE\n"
+"      myhvec3 surfacenormal = normalize(myhvec3(texture2D(Texture_Normal, TexCoord)) - 0.5);\n"
 "#else\n"
-"#ifdef USEDELUXEMAPPING\n"
+"      myhvec3 surfacenormal = -1.0 + 2.0 * myhvec3(texture2D(Texture_Normal, TexCoord));\n"
+"#endif\n"
+"      myhvec3 diffusenormal = myhvec3(normalize(LightVector));\n"
+"\n"
+"\n"
+"      // calculate directional shading\n"
+"      color.rgb *= AmbientColor + DiffuseColor * max(dot(surfacenormal, diffusenormal), 0.0);\n"
+"      //color.rgb *= AmbientColor + DiffuseColor * max(dot(surfacenormal, diffusenormal), 0.0);\n"
+"#ifdef USESPECULAR\n"
+"      myhvec3 specularnormal = myhvec3(normalize(diffusenormal + myhvec3(normalize(EyeVector))));\n"
+"      color.rgb += myhvec3(texture2D(Texture_Gloss, TexCoord)) * SpecularColor * pow(max(dot(surfacenormal, specularnormal), 0.0), SpecularPower);\n"
+"#endif\n"
+"\n"
+"\n"
+"\n"
+"\n"
+"#elif defined(MODE_LIGHTDIRECTIONMAP)\n"
 "      // deluxemap lightmapping\n"
 "\n"
 "      // get the surface normal and light normal\n"
@@ -604,35 +687,36 @@ static const char *builtinshaderstring =
 "#endif\n"
 "\n"
 "      // calculate directional shading\n"
-"      color.rgb *= (AmbientScale + DiffuseScale * max(dot(surfacenormal, diffusenormal), 0.0));\n"
+"      myhvec3 tempcolor = color.rgb * (DiffuseScale * max(dot(surfacenormal, diffusenormal), 0.0)));\n"
 "#ifdef USESPECULAR\n"
 "      myhvec3 specularnormal = myhvec3(normalize(diffusenormal + myhvec3(normalize(EyeVector))));\n"
-"      color.rgb += myhvec3(texture2D(Texture_Gloss, TexCoord)) * SpecularScale * pow(max(dot(surfacenormal, specularnormal), 0.0), SpecularPower);\n"
+"      tempcolor += myhvec3(texture2D(Texture_Gloss, TexCoord)) * SpecularScale * pow(max(dot(surfacenormal, specularnormal), 0.0), SpecularPower);\n"
 "#endif\n"
 "\n"
 "      // apply lightmap color\n"
-"      color.rgb *= myhvec3(texture2D(Texture_Lightmap, TexCoordLightmap));\n"
+"      color.rgb = tempcolor * myhvec3(texture2D(Texture_Lightmap, TexCoordLightmap)) + color.rgb * myhvec3(AmbientScale);\n"
 "\n"
 "\n"
 "\n"
 "\n"
-"#else\n"
+"#else // MODE none (lightmap)\n"
 "      // apply lightmap color\n"
-"      color.rgb *= myhvec3(texture2D(Texture_Lightmap, TexCoordLightmap)) * DiffuseScale;\n"
-"#endif\n"
-"#endif\n"
-"\n"
-"\n"
+"      color.rgb *= myhvec3(texture2D(Texture_Lightmap, TexCoordLightmap)) * DiffuseScale + myhvec3(AmbientScale);\n"
+"#endif // MODE\n"
 "\n"
+"#ifdef USEGLOW\n"
+"      color.rgb += myhvec3(texture2D(Texture_Glow, TexCoord));\n"
+"#endif\n"
 "\n"
 "#ifdef USEFOG\n"
 "      // apply fog\n"
-"      myhalf fog = texture2D(Texture_FogMask, myhvec2(length(EyeVector)*FogRangeRecip, 0)).x;\n"
-"      color.rgb = color.rgb * (1 - fog) + FogColor * fog;\n"
+"      myhalf fog = texture2D(Texture_FogMask, myhvec2(length(EyeVector)*FogRangeRecip, 0.0)).x;\n"
+"      color.rgb = color.rgb * fog + FogColor * (1.0 - fog);\n"
 "#endif\n"
 "\n"
-"      gl_FragColor = color;\n"
+"      gl_FragColor = color * gl_Color;\n"
 "}\n"
+"#endif // !USEEASTEREGG\n"
 "\n"
 "#endif\n"
 ;