From 9ee9172d8494e36c272e72d3301966673b01d37e Mon Sep 17 00:00:00 2001 From: havoc Date: Sat, 3 Jul 2010 10:33:30 +0000 Subject: [PATCH] updated glsl and cg (now also directly compiled as hlsl) shaders - integrated the r_bloom_colorsubtract behavior into the shader rather than relying on fixed function blending in an extra pass, this should be a little faster... git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10268 d7cf8633-e32d-0410-b094-e92efae38249 --- gl_rmain.c | 707 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 442 insertions(+), 265 deletions(-) diff --git a/gl_rmain.c b/gl_rmain.c index dec15bbc..71662b10 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -573,6 +573,55 @@ static void R_BuildFogHeightTexture(void) //======================================================================================================================================================= static const char *builtinshaderstring = +"/* The engine may define the following macros:\n" +"#define VERTEX_SHADER\n" +"#define GEOMETRY_SHADER\n" +"#define FRAGMENT_SHADER\n" +"#define MODE_GENERIC\n" +"#define MODE_POSTPROCESS\n" +"#define MODE_DEPTH_OR_SHADOW\n" +"#define MODE_FLATCOLOR\n" +"#define MODE_VERTEXCOLOR\n" +"#define MODE_LIGHTMAP\n" +"#define MODE_LIGHTDIRECTIONMAP_MODELSPACE\n" +"#define MODE_LIGHTDIRECTIONMAP_TANGENTSPACE\n" +"#define MODE_LIGHTDIRECTION\n" +"#define MODE_LIGHTSOURCE\n" +"#define MODE_REFRACTION\n" +"#define MODE_WATER\n" +"#define MODE_SHOWDEPTH\n" +"#define MODE_DEFERREDGEOMETRY\n" +"#define MODE_DEFERREDLIGHTSOURCE\n" +"#define USEDIFFUSE\n" +"#define USEVERTEXTEXTUREBLEND\n" +"#define USEVIEWTINT\n" +"#define USECOLORMAPPING\n" +"#define USESATURATION\n" +"#define USEFOGINSIDE\n" +"#define USEFOGOUTSIDE\n" +"#define USEFOGHEIGHTTEXTURE\n" +"#define USEGAMMARAMPS\n" +"#define USECUBEFILTER\n" +"#define USEGLOW\n" +"#define USEBLOOM\n" +"#define USESPECULAR\n" +"#define USEPOSTPROCESSING\n" +"#define USEEXACTSPECULARMATH\n" +"#define USEREFLECTION\n" +"#define USEOFFSETMAPPING\n" +"#define USEOFFSETMAPPING_RELIEFMAPPING\n" +"#define USESHADOWMAPRECT\n" +"#define USESHADOWMAPCUBE\n" +"#define USESHADOWMAP2D\n" +"#define USESHADOWMAPPCF 1\n" +"#define USESHADOWMAPPCF 2\n" +"#define USESHADOWSAMPLER\n" +"#define USESHADOWMAPVSDCT\n" +"#define USESHADOWMAPORTHO\n" +"#define USEDEFERREDLIGHTMAP\n" +"#define USEALPHAKILL\n" +"#define USEREFLECTCUBE\n" +"*/\n" "// ambient+diffuse+specular+normalmap+attenuation+cubemap+fog shader\n" "// written by Forest 'LordHavoc' Hale\n" "// shadowmapping enhancements by Lee 'eihrul' Salzman\n" @@ -679,6 +728,7 @@ static const char *builtinshaderstring = "uniform sampler2D Texture_First;\n" "#ifdef USEBLOOM\n" "uniform sampler2D Texture_Second;\n" +"uniform vec4 BloomColorSubtract;\n" "#endif\n" "#ifdef USEGAMMARAMPS\n" "uniform sampler2D Texture_GammaRamps;\n" @@ -700,7 +750,7 @@ static const char *builtinshaderstring = "{\n" " gl_FragColor = texture2D(Texture_First, TexCoord1);\n" "#ifdef USEBLOOM\n" -" gl_FragColor += texture2D(Texture_Second, TexCoord2);\n" +" gl_FragColor += max(vec4(0,0,0,0), texture2D(Texture_Second, TexCoord2) - BloomColorSubtract);\n" "#endif\n" "#ifdef USEVIEWTINT\n" " gl_FragColor = mix(gl_FragColor, ViewTintColor, ViewTintColor.a);\n" @@ -1895,19 +1945,42 @@ const char *builtincgshaderstring = "#endif\n" "\n" "#ifdef FRAGMENT_SHADER\n" +"#ifdef HLSL\n" +"//#undef USESHADOWMAPPCF\n" +"//#define texDepth2D(tex,texcoord) tex2D(tex,texcoord).r\n" +"#define texDepth2D(tex,texcoord) dot(tex2D(tex,texcoord).rgb, float3(1.0, 255.0/65536.0, 255.0/16777216.0))\n" +"#else\n" "#define texDepth2D(tex,texcoord) tex2D(tex,texcoord).r\n" "#endif\n" +"#endif\n" "\n" "#ifdef MODE_DEPTH_OR_SHADOW\n" "#ifdef VERTEX_SHADER\n" "void main\n" "(\n" "float4 gl_Vertex : POSITION,\n" -"uniform float4x4 ModelViewProjectionMatrix,\n" -"out float4 gl_Position : POSITION\n" +"uniform float4x4 ModelViewProjectionMatrix : register(c8),\n" +"out float4 gl_Position : POSITION,\n" +"out float Depth : TEXCOORD0\n" ")\n" "{\n" " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n" +" Depth = gl_Position.z;\n" +"}\n" +"#endif\n" +"\n" +"#ifdef FRAGMENT_SHADER\n" +"void main\n" +"(\n" +"float Depth : TEXCOORD0,\n" +"out float4 gl_FragColor : COLOR\n" +")\n" +"{\n" +"// float3 temp = float3(Depth,Depth*(65536.0/255.0),Depth*(16777216.0/255.0));\n" +" float3 temp = float3(Depth,Depth*256.0,Depth*65536.0);\n" +" temp.yz -= floor(temp.yz);\n" +" gl_FragColor = float4(temp,0);\n" +"// gl_FragColor = float4(Depth,0,0,0);\n" "}\n" "#endif\n" "#else // !MODE_DEPTH_ORSHADOW\n" @@ -1920,7 +1993,7 @@ const char *builtincgshaderstring = "void main\n" "(\n" "float4 gl_Vertex : POSITION,\n" -"uniform float4x4 ModelViewProjectionMatrix,\n" +"uniform float4x4 ModelViewProjectionMatrix : register(c8),\n" "out float4 gl_Position : POSITION,\n" "out float4 gl_FrontColor : COLOR0\n" ")\n" @@ -1951,9 +2024,9 @@ const char *builtincgshaderstring = "void main\n" "(\n" "float4 gl_Vertex : POSITION,\n" -"uniform float4x4 ModelViewProjectionMatrix,\n" +"uniform float4x4 ModelViewProjectionMatrix : register(c8),\n" "float4 gl_MultiTexCoord0 : TEXCOORD0,\n" -"float4 gl_MultiTexCoord1 : TEXCOORD4,\n" +"float4 gl_MultiTexCoord4 : TEXCOORD4,\n" "out float4 gl_Position : POSITION,\n" "out float2 TexCoord1 : TEXCOORD0,\n" "out float2 TexCoord2 : TEXCOORD1\n" @@ -1962,7 +2035,7 @@ const char *builtincgshaderstring = " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n" " TexCoord1 = gl_MultiTexCoord0.xy;\n" "#ifdef USEBLOOM\n" -" TexCoord2 = gl_MultiTexCoord1.xy;\n" +" TexCoord2 = gl_MultiTexCoord4.xy;\n" "#endif\n" "}\n" "#endif\n" @@ -1972,31 +2045,32 @@ const char *builtincgshaderstring = "(\n" "float2 TexCoord1 : TEXCOORD0,\n" "float2 TexCoord2 : TEXCOORD1,\n" -"uniform sampler2D Texture_First,\n" +"uniform sampler Texture_First : register(s0),\n" "#ifdef USEBLOOM\n" -"uniform sampler2D Texture_Second,\n" +"uniform sampler Texture_Second : register(s1),\n" "#endif\n" "#ifdef USEGAMMARAMPS\n" -"uniform sampler2D Texture_GammaRamps,\n" +"uniform sampler Texture_GammaRamps : register(s2),\n" "#endif\n" "#ifdef USESATURATION\n" -"uniform float Saturation,\n" +"uniform float Saturation : register(c30),\n" "#endif\n" "#ifdef USEVIEWTINT\n" -"uniform float4 ViewTintColor,\n" -"#endif\n" -"uniform float4 UserVec1,\n" -"uniform float4 UserVec2,\n" -"uniform float4 UserVec3,\n" -"uniform float4 UserVec4,\n" -"uniform float ClientTime,\n" -"uniform float2 PixelSize,\n" +"uniform float4 ViewTintColor : register(c41),\n" +"#endif\n" +"uniform float4 UserVec1 : register(c37),\n" +"uniform float4 UserVec2 : register(c38),\n" +"uniform float4 UserVec3 : register(c39),\n" +"uniform float4 UserVec4 : register(c40),\n" +"uniform float ClientTime : register(c2),\n" +"uniform float2 PixelSize : register(c25),\n" +"uniform float4 BloomColorSubtract : register(c43),\n" "out float4 gl_FragColor : COLOR\n" ")\n" "{\n" " gl_FragColor = tex2D(Texture_First, TexCoord1);\n" "#ifdef USEBLOOM\n" -" gl_FragColor += tex2D(Texture_Second, TexCoord2);\n" +" gl_FragColor += max(float4(0,0,0,0), tex2D(Texture_Second, TexCoord2) - BloomColorSubtract);\n" "#endif\n" "#ifdef USEVIEWTINT\n" " gl_FragColor = lerp(gl_FragColor, ViewTintColor, ViewTintColor.a);\n" @@ -2005,12 +2079,42 @@ const char *builtincgshaderstring = "#ifdef USEPOSTPROCESSING\n" "// do r_glsl_dumpshader, edit glsl/default.glsl, and replace this by your own postprocessing if you want\n" "// this code does a blur with the radius specified in the first component of r_glsl_postprocess_uservec1 and blends it using the second component\n" +" float sobel = 1.0;\n" +" // float2 ts = textureSize(Texture_First, 0);\n" +" // float2 px = float2(1/ts.x, 1/ts.y);\n" +" float2 px = PixelSize;\n" +" float3 x1 = tex2D(Texture_First, TexCoord1 + float2(-px.x, px.y)).rgb;\n" +" float3 x2 = tex2D(Texture_First, TexCoord1 + float2(-px.x, 0.0)).rgb;\n" +" float3 x3 = tex2D(Texture_First, TexCoord1 + float2(-px.x,-px.y)).rgb;\n" +" float3 x4 = tex2D(Texture_First, TexCoord1 + float2( px.x, px.y)).rgb;\n" +" float3 x5 = tex2D(Texture_First, TexCoord1 + float2( px.x, 0.0)).rgb;\n" +" float3 x6 = tex2D(Texture_First, TexCoord1 + float2( px.x,-px.y)).rgb;\n" +" float3 y1 = tex2D(Texture_First, TexCoord1 + float2( px.x,-px.y)).rgb;\n" +" float3 y2 = tex2D(Texture_First, TexCoord1 + float2( 0.0,-px.y)).rgb;\n" +" float3 y3 = tex2D(Texture_First, TexCoord1 + float2(-px.x,-px.y)).rgb;\n" +" float3 y4 = tex2D(Texture_First, TexCoord1 + float2( px.x, px.y)).rgb;\n" +" float3 y5 = tex2D(Texture_First, TexCoord1 + float2( 0.0, px.y)).rgb;\n" +" float3 y6 = tex2D(Texture_First, TexCoord1 + float2(-px.x, px.y)).rgb;\n" +" float px1 = -1.0 * dot(float3(0.3, 0.59, 0.11), x1);\n" +" float px2 = -2.0 * dot(float3(0.3, 0.59, 0.11), x2);\n" +" float px3 = -1.0 * dot(float3(0.3, 0.59, 0.11), x3);\n" +" float px4 = 1.0 * dot(float3(0.3, 0.59, 0.11), x4);\n" +" float px5 = 2.0 * dot(float3(0.3, 0.59, 0.11), x5);\n" +" float px6 = 1.0 * dot(float3(0.3, 0.59, 0.11), x6);\n" +" float py1 = -1.0 * dot(float3(0.3, 0.59, 0.11), y1);\n" +" float py2 = -2.0 * dot(float3(0.3, 0.59, 0.11), y2);\n" +" float py3 = -1.0 * dot(float3(0.3, 0.59, 0.11), y3);\n" +" float py4 = 1.0 * dot(float3(0.3, 0.59, 0.11), y4);\n" +" float py5 = 2.0 * dot(float3(0.3, 0.59, 0.11), y5);\n" +" float py6 = 1.0 * dot(float3(0.3, 0.59, 0.11), y6);\n" +" sobel = 0.25 * abs(px1 + px2 + px3 + px4 + px5 + px6) + 0.25 * abs(py1 + py2 + py3 + py4 + py5 + py6);\n" " gl_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2(-0.987688, -0.156434)) * UserVec1.y;\n" " gl_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2(-0.156434, -0.891007)) * UserVec1.y;\n" " gl_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2( 0.891007, -0.453990)) * UserVec1.y;\n" " gl_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2( 0.707107, 0.707107)) * UserVec1.y;\n" " gl_FragColor += tex2D(Texture_First, TexCoord1 + PixelSize*UserVec1.x*float2(-0.453990, 0.891007)) * UserVec1.y;\n" -" gl_FragColor /= (1 + 5 * UserVec1.y);\n" +" gl_FragColor /= (1.0 + 5.0 * UserVec1.y);\n" +" gl_FragColor.rgb = gl_FragColor.rgb * (1.0 + UserVec2.x) + float3(1,1,1)*max(0.0, sobel - UserVec2.z)*UserVec2.y;\n" "#endif\n" "\n" "#ifdef USESATURATION\n" @@ -2037,7 +2141,7 @@ const char *builtincgshaderstring = "void main\n" "(\n" "float4 gl_Vertex : POSITION,\n" -"uniform float4x4 ModelViewProjectionMatrix,\n" +"uniform float4x4 ModelViewProjectionMatrix : register(c8),\n" "float4 gl_Color : COLOR0,\n" "float4 gl_MultiTexCoord0 : TEXCOORD0,\n" "float4 gl_MultiTexCoord1 : TEXCOORD1,\n" @@ -2047,7 +2151,11 @@ const char *builtincgshaderstring = "out float2 TexCoord2 : TEXCOORD1\n" ")\n" "{\n" -" gl_FrontColor = gl_Color;\n" +"#ifdef HLSL\n" +" gl_FrontColor = gl_Color.bgra; // NOTE: D3DCOLOR is backwards\n" +"#else\n" +" gl_FrontColor = gl_Color; // Cg is forward\n" +"#endif\n" "#ifdef USEDIFFUSE\n" " TexCoord1 = gl_MultiTexCoord0.xy;\n" "#endif\n" @@ -2062,14 +2170,14 @@ const char *builtincgshaderstring = "\n" "void main\n" "(\n" -"float4 gl_FrontColor : COLOR,\n" +"float4 gl_FrontColor : COLOR0,\n" "float2 TexCoord1 : TEXCOORD0,\n" "float2 TexCoord2 : TEXCOORD1,\n" "#ifdef USEDIFFUSE\n" -"uniform sampler2D Texture_First,\n" +"uniform sampler Texture_First : register(s0),\n" "#endif\n" "#ifdef USESPECULAR\n" -"uniform sampler2D Texture_Second,\n" +"uniform sampler Texture_Second : register(s1),\n" "#endif\n" "out float4 gl_FragColor : COLOR\n" ")\n" @@ -2103,7 +2211,7 @@ const char *builtincgshaderstring = "void main\n" "(\n" "float4 gl_Vertex : POSITION,\n" -"uniform float4x4 ModelViewProjectionMatrix,\n" +"uniform float4x4 ModelViewProjectionMatrix : register(c8),\n" "float4 gl_MultiTexCoord0 : TEXCOORD0,\n" "out float4 gl_Position : POSITION,\n" "out float2 TexCoord : TEXCOORD0\n" @@ -2119,8 +2227,8 @@ const char *builtincgshaderstring = "void main\n" "(\n" "float2 TexCoord : TEXCOORD0,\n" -"uniform sampler2D Texture_First,\n" -"uniform float4 BloomBlur_Parameters,\n" +"uniform sampler Texture_First : register(s0),\n" +"uniform float4 BloomBlur_Parameters : register(c1),\n" "out float4 gl_FragColor : COLOR\n" ")\n" "{\n" @@ -2142,17 +2250,17 @@ const char *builtincgshaderstring = "void main\n" "(\n" "float4 gl_Vertex : POSITION,\n" -"uniform float4x4 ModelViewProjectionMatrix,\n" +"uniform float4x4 ModelViewProjectionMatrix : register(c8),\n" "float4 gl_MultiTexCoord0 : TEXCOORD0,\n" -"uniform float4x4 TexMatrix,\n" -"uniform float3 EyePosition,\n" +"uniform float4x4 TexMatrix : register(c0),\n" +"uniform float3 EyePosition : register(c24),\n" "out float4 gl_Position : POSITION,\n" "out float2 TexCoord : TEXCOORD0,\n" "out float3 EyeVector : TEXCOORD1,\n" "out float4 ModelViewProjectionPosition : TEXCOORD2\n" ")\n" "{\n" -" TexCoord = float2(mul(TexMatrix, gl_MultiTexCoord0));\n" +" TexCoord = mul(TexMatrix, gl_MultiTexCoord0).xy;\n" " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n" " ModelViewProjectionPosition = gl_Position;\n" "}\n" @@ -2164,20 +2272,20 @@ const char *builtincgshaderstring = "float2 TexCoord : TEXCOORD0,\n" "float3 EyeVector : TEXCOORD1,\n" "float4 ModelViewProjectionPosition : TEXCOORD2,\n" -"uniform sampler2D Texture_Normal,\n" -"uniform sampler2D Texture_Refraction,\n" -"uniform sampler2D Texture_Reflection,\n" -"uniform float4 DistortScaleRefractReflect,\n" -"uniform float4 ScreenScaleRefractReflect,\n" -"uniform float4 ScreenCenterRefractReflect,\n" -"uniform float4 RefractColor,\n" +"uniform sampler Texture_Normal : register(s0),\n" +"uniform sampler Texture_Refraction : register(s3),\n" +"uniform sampler Texture_Reflection : register(s7),\n" +"uniform float4 DistortScaleRefractReflect : register(c14),\n" +"uniform float4 ScreenScaleRefractReflect : register(c32),\n" +"uniform float4 ScreenCenterRefractReflect : register(c31),\n" +"uniform float4 RefractColor : register(c29),\n" "out float4 gl_FragColor : COLOR\n" ")\n" "{\n" " float2 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect.xy * (1.0 / ModelViewProjectionPosition.w);\n" -" //float2 ScreenTexCoord = (ModelViewProjectionPosition.xy + normalize(float3(tex2D(Texture_Normal, TexCoord)) - float3(0.5)).xy * DistortScaleRefractReflect.xy * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect.xy;\n" +" //float2 ScreenTexCoord = (ModelViewProjectionPosition.xy + normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xy * DistortScaleRefractReflect.xy * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect.xy;\n" " float2 SafeScreenTexCoord = ModelViewProjectionPosition.xy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect.xy;\n" -" float2 ScreenTexCoord = SafeScreenTexCoord + float2(normalize(float3(tex2D(Texture_Normal, TexCoord)) - float3(0.5))).xy * DistortScaleRefractReflect.xy;\n" +" float2 ScreenTexCoord = SafeScreenTexCoord + float2(normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5))).xy * DistortScaleRefractReflect.xy;\n" " // FIXME temporary hack to detect the case that the reflection\n" " // gets blackened at edges due to leaving the area that contains actual\n" " // content.\n" @@ -2202,17 +2310,20 @@ const char *builtincgshaderstring = "void main\n" "(\n" "float4 gl_Vertex : POSITION,\n" -"uniform float4x4 ModelViewProjectionMatrix,\n" +"uniform float4x4 ModelViewProjectionMatrix : register(c8),\n" "float4 gl_MultiTexCoord0 : TEXCOORD0,\n" -"uniform float4x4 TexMatrix,\n" -"uniform float3 EyePosition,\n" +"float4 gl_MultiTexCoord1 : TEXCOORD1,\n" +"float4 gl_MultiTexCoord2 : TEXCOORD2,\n" +"float4 gl_MultiTexCoord3 : TEXCOORD3,\n" +"uniform float4x4 TexMatrix : register(c0),\n" +"uniform float3 EyePosition : register(c24),\n" "out float4 gl_Position : POSITION,\n" "out float2 TexCoord : TEXCOORD0,\n" "out float3 EyeVector : TEXCOORD1,\n" "out float4 ModelViewProjectionPosition : TEXCOORD2\n" ")\n" "{\n" -" TexCoord = float2(mul(TexMatrix, gl_MultiTexCoord0));\n" +" TexCoord = mul(TexMatrix, gl_MultiTexCoord0).xy;\n" " float3 EyeVectorModelSpace = EyePosition - gl_Vertex.xyz;\n" " EyeVector.x = dot(EyeVectorModelSpace, gl_MultiTexCoord1.xyz);\n" " EyeVector.y = dot(EyeVectorModelSpace, gl_MultiTexCoord2.xyz);\n" @@ -2228,23 +2339,24 @@ const char *builtincgshaderstring = "float2 TexCoord : TEXCOORD0,\n" "float3 EyeVector : TEXCOORD1,\n" "float4 ModelViewProjectionPosition : TEXCOORD2,\n" -"uniform sampler2D Texture_Normal,\n" -"uniform sampler2D Texture_Refraction,\n" -"uniform sampler2D Texture_Reflection,\n" -"uniform float4 DistortScaleRefractReflect,\n" -"uniform float4 ScreenScaleRefractReflect,\n" -"uniform float4 ScreenCenterRefractReflect,\n" -"uniform float4 RefractColor,\n" -"uniform float4 ReflectColor,\n" -"uniform float ReflectFactor,\n" -"uniform float ReflectOffset,\n" +"uniform sampler Texture_Normal : register(s0),\n" +"uniform sampler Texture_Refraction : register(s3),\n" +"uniform sampler Texture_Reflection : register(s7),\n" +"uniform float4 DistortScaleRefractReflect : register(c14),\n" +"uniform float4 ScreenScaleRefractReflect : register(c32),\n" +"uniform float4 ScreenCenterRefractReflect : register(c31),\n" +"uniform float4 RefractColor : register(c29),\n" +"uniform float4 ReflectColor : register(c26),\n" +"uniform float ReflectFactor : register(c27),\n" +"uniform float ReflectOffset : register(c28),\n" "out float4 gl_FragColor : COLOR\n" ")\n" "{\n" " float4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n" -" //float4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(float3(tex2D(Texture_Normal, TexCoord)) - float3(0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n" +" //float4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n" " float4 SafeScreenTexCoord = ModelViewProjectionPosition.xyxy * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n" -" float4 ScreenTexCoord = SafeScreenTexCoord + float2(normalize(float3(tex2D(Texture_Normal, TexCoord)) - float3(0.5))).xyxy * DistortScaleRefractReflect;\n" +" //SafeScreenTexCoord = gl_FragCoord.xyxy * float4(1.0 / 1920.0, 1.0 / 1200.0, 1.0 / 1920.0, 1.0 / 1200.0);\n" +" float4 ScreenTexCoord = SafeScreenTexCoord + float2(normalize(tex2D(Texture_Normal, TexCoord).rgb - float3(0.5,0.5,0.5))).xyxy * DistortScaleRefractReflect;\n" " // FIXME temporary hack to detect the case that the reflection\n" " // gets blackened at edges due to leaving the area that contains actual\n" " // content.\n" @@ -2275,7 +2387,7 @@ const char *builtincgshaderstring = "#ifdef FRAGMENT_SHADER\n" "\n" "#ifdef USEFOG\n" -"float3 FogVertex(float3 surfacecolor, float3 FogColor, float3 EyeVectorModelSpace, float FogPlaneVertexDist, float FogRangeRecip, float FogPlaneViewDist, float FogHeightFade, sampler2D Texture_FogMask, sampler2D Texture_FogHeightTexture)\n" +"float3 FogVertex(float3 surfacecolor, float3 FogColor, float3 EyeVectorModelSpace, float FogPlaneVertexDist, float FogRangeRecip, float FogPlaneViewDist, float FogHeightFade, sampler Texture_FogMask, sampler Texture_FogHeightTexture)\n" "{\n" " float fogfrac;\n" "#ifdef USEFOGHEIGHTTEXTURE\n" @@ -2294,7 +2406,7 @@ const char *builtincgshaderstring = "#endif\n" "\n" "#ifdef USEOFFSETMAPPING\n" -"float2 OffsetMapping(float2 TexCoord, float OffsetMapping_Scale, float3 EyeVector, sampler2D Texture_Normal)\n" +"float2 OffsetMapping(float2 TexCoord, float OffsetMapping_Scale, float3 EyeVector, sampler Texture_Normal)\n" "{\n" "#ifdef USEOFFSETMAPPING_RELIEFMAPPING\n" " // 14 sample relief mapping: linear search and then binary search\n" @@ -2359,8 +2471,12 @@ const char *builtincgshaderstring = " float4 proj = float4(dir, 2.5);\n" " if (adir.x > ma) { ma = adir.x; proj = float4(dir.zyx, 0.5); }\n" " if (adir.y > ma) { ma = adir.y; proj = float4(dir.xzy, 1.5); }\n" +"#ifdef HLSL\n" +" return float3(proj.xy * ShadowMap_Parameters.x / ma + float2(0.5,0.5) + float2(proj.z < 0.0 ? 1.5 : 0.5, proj.w) * ShadowMap_Parameters.z, ma + 64 * ShadowMap_Parameters.w);\n" +"#else\n" " float2 aparams = ShadowMap_Parameters.xy / ma;\n" " return float3(proj.xy * aparams.x + float2(proj.z < 0.0 ? 1.5 : 0.5, proj.w) * ShadowMap_Parameters.z, aparams.y + ShadowMap_Parameters.w);\n" +"#endif\n" "}\n" "# endif\n" "# endif\n" @@ -2369,8 +2485,8 @@ const char *builtincgshaderstring = "#ifdef USESHADOWMAPCUBE\n" "float4 GetShadowMapTCCube(float3 dir, float4 ShadowMap_Parameters)\n" "{\n" -" float3 adir = abs(dir);\n" -" return float4(dir, ShadowMap_Parameters.w + ShadowMap_Parameters.y / max(max(adir.x, adir.y), adir.z));\n" +" float3 adir = abs(dir);\n" +" return float4(dir, ShadowMap_Parameters.w + ShadowMap_Parameters.y / max(max(adir.x, adir.y), adir.z));\n" "}\n" "#endif\n" "\n" @@ -2391,9 +2507,9 @@ const char *builtincgshaderstring = "\n" "# ifdef USESHADOWMAPPCF\n" "# define texval(x, y) shadow2DRect(Texture_ShadowMapRect, shadowmaptc + float3(x, y, 0.0)).r\n" -" f = dot(float4(0.25), float4(texval(-0.4, 1.0), texval(-1.0, -0.4), texval(0.4, -1.0), texval(1.0, 0.4)));\n" +" f = dot(float4(0.25,0.25,0.25,0.25), float4(texval(-0.4, 1.0), texval(-1.0, -0.4), texval(0.4, -1.0), texval(1.0, 0.4)));\n" "# else\n" -" f = shadow2DRect(Texture_ShadowMapRect, shadowmaptc).r;\n" +" f = shadow2DRect(Texture_ShadowMapRect, shadowmaptc).r;\n" "# endif\n" "\n" "# else\n" @@ -2401,24 +2517,24 @@ const char *builtincgshaderstring = "# ifdef USESHADOWMAPPCF\n" "# if USESHADOWMAPPCF > 1\n" "# define texval(x, y) texRECT(Texture_ShadowMapRect, center + float2(x, y)).r\n" -" float2 center = shadowmaptc.xy - 0.5, offset = frac(center);\n" -" float4 row1 = step(shadowmaptc.z, float4(texval(-1.0, -1.0), texval( 0.0, -1.0), texval( 1.0, -1.0), texval( 2.0, -1.0)));\n" -" float4 row2 = step(shadowmaptc.z, float4(texval(-1.0, 0.0), texval( 0.0, 0.0), texval( 1.0, 0.0), texval( 2.0, 0.0)));\n" -" float4 row3 = step(shadowmaptc.z, float4(texval(-1.0, 1.0), texval( 0.0, 1.0), texval( 1.0, 1.0), texval( 2.0, 1.0)));\n" -" float4 row4 = step(shadowmaptc.z, float4(texval(-1.0, 2.0), texval( 0.0, 2.0), texval( 1.0, 2.0), texval( 2.0, 2.0)));\n" -" float4 cols = row2 + row3 + lerp(row1, row4, offset.y);\n" -" f = dot(lerp(cols.xyz, cols.yzw, offset.x), float3(1.0/9.0));\n" +" float2 center = shadowmaptc.xy - 0.5, offset = frac(center);\n" +" float4 row1 = step(shadowmaptc.z, float4(texval(-1.0, -1.0), texval( 0.0, -1.0), texval( 1.0, -1.0), texval( 2.0, -1.0)));\n" +" float4 row2 = step(shadowmaptc.z, float4(texval(-1.0, 0.0), texval( 0.0, 0.0), texval( 1.0, 0.0), texval( 2.0, 0.0)));\n" +" float4 row3 = step(shadowmaptc.z, float4(texval(-1.0, 1.0), texval( 0.0, 1.0), texval( 1.0, 1.0), texval( 2.0, 1.0)));\n" +" float4 row4 = step(shadowmaptc.z, float4(texval(-1.0, 2.0), texval( 0.0, 2.0), texval( 1.0, 2.0), texval( 2.0, 2.0)));\n" +" float4 cols = row2 + row3 + lerp(row1, row4, offset.y);\n" +" f = dot(lerp(cols.xyz, cols.yzw, offset.x), float3(1.0/9.0));\n" "# else\n" "# define texval(x, y) texRECT(Texture_ShadowMapRect, shadowmaptc.xy + float2(x, y)).r\n" -" float2 offset = frac(shadowmaptc.xy);\n" -" float3 row1 = step(shadowmaptc.z, float3(texval(-1.0, -1.0), texval( 0.0, -1.0), texval( 1.0, -1.0)));\n" -" float3 row2 = step(shadowmaptc.z, float3(texval(-1.0, 0.0), texval( 0.0, 0.0), texval( 1.0, 0.0)));\n" -" float3 row3 = step(shadowmaptc.z, float3(texval(-1.0, 1.0), texval( 0.0, 1.0), texval( 1.0, 1.0)));\n" -" float3 cols = row2 + lerp(row1, row3, offset.y);\n" -" f = dot(lerp(cols.xy, cols.yz, offset.x), float2(0.25));\n" +" float2 offset = frac(shadowmaptc.xy);\n" +" float3 row1 = step(shadowmaptc.z, float3(texval(-1.0, -1.0), texval( 0.0, -1.0), texval( 1.0, -1.0)));\n" +" float3 row2 = step(shadowmaptc.z, float3(texval(-1.0, 0.0), texval( 0.0, 0.0), texval( 1.0, 0.0)));\n" +" float3 row3 = step(shadowmaptc.z, float3(texval(-1.0, 1.0), texval( 0.0, 1.0), texval( 1.0, 1.0)));\n" +" float3 cols = row2 + lerp(row1, row3, offset.y);\n" +" f = dot(lerp(cols.xy, cols.yz, offset.x), float2(0.25,0.25));\n" "# endif\n" "# else\n" -" f = step(shadowmaptc.z, texRECT(Texture_ShadowMapRect, shadowmaptc.xy).r);\n" +" f = step(shadowmaptc.z, texRECT(Texture_ShadowMapRect, shadowmaptc.xy).r);\n" "# endif\n" "\n" "# endif\n" @@ -2432,9 +2548,9 @@ const char *builtincgshaderstring = "\n" "# ifdef USESHADOWMAP2D\n" "#ifdef USESHADOWMAPVSDCT\n" -"float ShadowMapCompare(float3 dir, sampler2D Texture_ShadowMap2D, float4 ShadowMap_Parameters, float2 ShadowMap_TextureScale, samplerCUBE Texture_CubeProjection)\n" +"float ShadowMapCompare(float3 dir, sampler Texture_ShadowMap2D, float4 ShadowMap_Parameters, float2 ShadowMap_TextureScale, samplerCUBE Texture_CubeProjection)\n" "#else\n" -"float ShadowMapCompare(float3 dir, sampler2D Texture_ShadowMap2D, float4 ShadowMap_Parameters, float2 ShadowMap_TextureScale)\n" +"float ShadowMapCompare(float3 dir, sampler Texture_ShadowMap2D, float4 ShadowMap_Parameters, float2 ShadowMap_TextureScale)\n" "#endif\n" "{\n" "#ifdef USESHADOWMAPVSDCT\n" @@ -2442,55 +2558,80 @@ const char *builtincgshaderstring = "#else\n" " float3 shadowmaptc = GetShadowMapTC2D(dir, ShadowMap_Parameters);\n" "#endif\n" -" float f;\n" +" float f;\n" "\n" "# ifdef USESHADOWSAMPLER\n" "# ifdef USESHADOWMAPPCF\n" -"# define texval(x, y) shadow2D(Texture_ShadowMap2D, float3(center + float2(x, y)*ShadowMap_TextureScale, shadowmaptc.z)).r \n" -" float2 center = shadowmaptc.xy*ShadowMap_TextureScale;\n" -" f = dot(float4(0.25), float4(texval(-0.4, 1.0), texval(-1.0, -0.4), texval(0.4, -1.0), texval(1.0, 0.4)));\n" +"# define texval(x, y) tex2Dproj(Texture_ShadowMap2D, float4(center + float2(x, y)*ShadowMap_TextureScale, shadowmaptc.z, 1.0)).r \n" +" float2 center = shadowmaptc.xy*ShadowMap_TextureScale;\n" +" f = dot(float4(0.25,0.25,0.25,0.25), float4(texval(-0.4, 1.0), texval(-1.0, -0.4), texval(0.4, -1.0), texval(1.0, 0.4)));\n" "# else\n" -" f = shadow2D(Texture_ShadowMap2D, float3(shadowmaptc.xy*ShadowMap_TextureScale, shadowmaptc.z)).r;\n" +" f = tex2Dproj(Texture_ShadowMap2D, float4(shadowmaptc.xy*ShadowMap_TextureScale, shadowmaptc.z, 1.0)).r;\n" "# endif\n" "# else\n" "# ifdef USESHADOWMAPPCF\n" "# if defined(GL_ARB_texture_gather) || defined(GL_AMD_texture_texture4)\n" "# ifdef GL_ARB_texture_gather\n" -"# define texval(x, y) textureGatherOffset(Texture_ShadowMap2D, center, ivec(x, y))\n" +"# define texval(x, y) textureGatherOffset(Texture_ShadowMap2D, center, int2(x, y))\n" +"# else\n" +"# define texval(x, y) texture4(Texture_ShadowMap2D, center + float2(x, y)*ShadowMap_TextureScale)\n" +"# endif\n" +" float2 offset = frac(shadowmaptc.xy - 0.5), center = (shadowmaptc.xy - offset)*ShadowMap_TextureScale;\n" +"# if USESHADOWMAPPCF > 1\n" +" float4 group1 = step(shadowmaptc.z, texval(-2.0, -2.0));\n" +" float4 group2 = step(shadowmaptc.z, texval( 0.0, -2.0));\n" +" float4 group3 = step(shadowmaptc.z, texval( 2.0, -2.0));\n" +" float4 group4 = step(shadowmaptc.z, texval(-2.0, 0.0));\n" +" float4 group5 = step(shadowmaptc.z, texval( 0.0, 0.0));\n" +" float4 group6 = step(shadowmaptc.z, texval( 2.0, 0.0));\n" +" float4 group7 = step(shadowmaptc.z, texval(-2.0, 2.0));\n" +" float4 group8 = step(shadowmaptc.z, texval( 0.0, 2.0));\n" +" float4 group9 = step(shadowmaptc.z, texval( 2.0, 2.0));\n" +" float4 locols = float4(group1.ab, group3.ab);\n" +" float4 hicols = float4(group7.rg, group9.rg);\n" +" locols.yz += group2.ab;\n" +" hicols.yz += group8.rg;\n" +" float4 midcols = float4(group1.rg, group3.rg) + float4(group7.ab, group9.ab) +\n" +" float4(group4.rg, group6.rg) + float4(group4.ab, group6.ab) +\n" +" lerp(locols, hicols, offset.y);\n" +" float4 cols = group5 + float4(group2.rg, group8.ab);\n" +" cols.xyz += lerp(midcols.xyz, midcols.yzw, offset.x);\n" +" f = dot(cols, float4(1.0/25.0));\n" "# else\n" -"# define texval(x, y) texture4(Texture_ShadowMap2D, center + float2(x,y)*ShadowMap_TextureScale)\n" +" float4 group1 = step(shadowmaptc.z, texval(-1.0, -1.0));\n" +" float4 group2 = step(shadowmaptc.z, texval( 1.0, -1.0));\n" +" float4 group3 = step(shadowmaptc.z, texval(-1.0, 1.0));\n" +" float4 group4 = step(shadowmaptc.z, texval( 1.0, 1.0));\n" +" float4 cols = float4(group1.rg, group2.rg) + float4(group3.ab, group4.ab) +\n" +" lerp(float4(group1.ab, group2.ab), float4(group3.rg, group4.rg), offset.y);\n" +" f = dot(lerp(cols.xyz, cols.yzw, offset.x), float3(1.0/9.0));\n" "# endif\n" -" float2 center = shadowmaptc.xy - 0.5, offset = frac(center);\n" -" center *= ShadowMap_TextureScale;\n" -" float4 group1 = step(shadowmaptc.z, texval(-1.0, -1.0));\n" -" float4 group2 = step(shadowmaptc.z, texval( 1.0, -1.0));\n" -" float4 group3 = step(shadowmaptc.z, texval(-1.0, 1.0));\n" -" float4 group4 = step(shadowmaptc.z, texval( 1.0, 1.0));\n" -" float4 cols = float4(group1.rg, group2.rg) + float4(group3.ab, group4.ab) +\n" -" lerp(float4(group1.ab, group2.ab), float4(group3.rg, group4.rg), offset.y);\n" -" f = dot(lerp(cols.xyz, cols.yzw, offset.x), float3(1.0/9.0));\n" "# else\n" -"# define texval(x, y) texDepth2D(Texture_ShadowMap2D, center + float2(x, y)*ShadowMap_TextureScale) \n" +"# ifdef GL_EXT_gpu_shader4\n" +"# define texval(x, y) tex2DOffset(Texture_ShadowMap2D, center, int2(x, y)).r\n" +"# else\n" +"# define texval(x, y) texDepth2D(Texture_ShadowMap2D, center + float2(x, y)*ShadowMap_TextureScale).r \n" +"# endif\n" "# if USESHADOWMAPPCF > 1\n" -" float2 center = shadowmaptc.xy - 0.5, offset = frac(center);\n" -" center *= ShadowMap_TextureScale;\n" -" float4 row1 = step(shadowmaptc.z, float4(texval(-1.0, -1.0), texval( 0.0, -1.0), texval( 1.0, -1.0), texval( 2.0, -1.0)));\n" -" float4 row2 = step(shadowmaptc.z, float4(texval(-1.0, 0.0), texval( 0.0, 0.0), texval( 1.0, 0.0), texval( 2.0, 0.0)));\n" -" float4 row3 = step(shadowmaptc.z, float4(texval(-1.0, 1.0), texval( 0.0, 1.0), texval( 1.0, 1.0), texval( 2.0, 1.0)));\n" -" float4 row4 = step(shadowmaptc.z, float4(texval(-1.0, 2.0), texval( 0.0, 2.0), texval( 1.0, 2.0), texval( 2.0, 2.0)));\n" -" float4 cols = row2 + row3 + lerp(row1, row4, offset.y);\n" -" f = dot(lerp(cols.xyz, cols.yzw, offset.x), float3(1.0/9.0));\n" +" float2 center = shadowmaptc.xy - 0.5, offset = frac(center);\n" +" center *= ShadowMap_TextureScale;\n" +" float4 row1 = step(shadowmaptc.z, float4(texval(-1.0, -1.0), texval( 0.0, -1.0), texval( 1.0, -1.0), texval( 2.0, -1.0)));\n" +" float4 row2 = step(shadowmaptc.z, float4(texval(-1.0, 0.0), texval( 0.0, 0.0), texval( 1.0, 0.0), texval( 2.0, 0.0)));\n" +" float4 row3 = step(shadowmaptc.z, float4(texval(-1.0, 1.0), texval( 0.0, 1.0), texval( 1.0, 1.0), texval( 2.0, 1.0)));\n" +" float4 row4 = step(shadowmaptc.z, float4(texval(-1.0, 2.0), texval( 0.0, 2.0), texval( 1.0, 2.0), texval( 2.0, 2.0)));\n" +" float4 cols = row2 + row3 + lerp(row1, row4, offset.y);\n" +" f = dot(lerp(cols.xyz, cols.yzw, offset.x), float3(1.0/9.0));\n" "# else\n" -" float2 center = shadowmaptc.xy*ShadowMap_TextureScale, offset = frac(shadowmaptc.xy);\n" -" float3 row1 = step(shadowmaptc.z, float3(texval(-1.0, -1.0), texval( 0.0, -1.0), texval( 1.0, -1.0)));\n" -" float3 row2 = step(shadowmaptc.z, float3(texval(-1.0, 0.0), texval( 0.0, 0.0), texval( 1.0, 0.0)));\n" -" float3 row3 = step(shadowmaptc.z, float3(texval(-1.0, 1.0), texval( 0.0, 1.0), texval( 1.0, 1.0)));\n" -" float3 cols = row2 + lerp(row1, row3, offset.y);\n" -" f = dot(lerp(cols.xy, cols.yz, offset.x), float2(0.25));\n" +" float2 center = shadowmaptc.xy*ShadowMap_TextureScale, offset = frac(shadowmaptc.xy);\n" +" float3 row1 = step(shadowmaptc.z, float3(texval(-1.0, -1.0), texval( 0.0, -1.0), texval( 1.0, -1.0)));\n" +" float3 row2 = step(shadowmaptc.z, float3(texval(-1.0, 0.0), texval( 0.0, 0.0), texval( 1.0, 0.0)));\n" +" float3 row3 = step(shadowmaptc.z, float3(texval(-1.0, 1.0), texval( 0.0, 1.0), texval( 1.0, 1.0)));\n" +" float3 cols = row2 + lerp(row1, row3, offset.y);\n" +" f = dot(lerp(cols.xy, cols.yz, offset.x), float2(0.25,0.25));\n" "# endif\n" "# endif\n" "# else\n" -" f = step(shadowmaptc.z, tex2D(Texture_ShadowMap2D, shadowmaptc.xy*ShadowMap_TextureScale).r);\n" +" f = step(shadowmaptc.z, tex2D(Texture_ShadowMap2D, shadowmaptc.xy*ShadowMap_TextureScale).r);\n" "# endif\n" "# endif\n" "# ifdef USESHADOWMAPORTHO\n" @@ -2504,18 +2645,18 @@ const char *builtincgshaderstring = "# ifdef USESHADOWMAPCUBE\n" "float ShadowMapCompare(float3 dir, samplerCUBE Texture_ShadowMapCube, float4 ShadowMap_Parameters)\n" "{\n" -" // apply depth texture cubemap as light filter\n" -" float4 shadowmaptc = GetShadowMapTCCube(dir, ShadowMap_Parameters);\n" -" float f;\n" +" // apply depth texture cubemap as light filter\n" +" float4 shadowmaptc = GetShadowMapTCCube(dir, ShadowMap_Parameters);\n" +" float f;\n" "# ifdef USESHADOWSAMPLER\n" -" f = shadowCube(Texture_ShadowMapCube, shadowmaptc).r;\n" +" f = shadowCube(Texture_ShadowMapCube, shadowmaptc).r;\n" "# else\n" -" f = step(shadowmaptc.w, texCUBE(Texture_ShadowMapCube, shadowmaptc.xyz).r);\n" +" f = step(shadowmaptc.w, texCUBE(Texture_ShadowMapCube, shadowmaptc.xyz).r);\n" "# endif\n" -" return f;\n" +" return f;\n" "}\n" "# endif\n" -"#endif // !defined(MODE_LIGHTSOURCE) && !defined(MODE_DEFERREDLIGHTSOURCE)\n" +"#endif // !defined(MODE_LIGHTSOURCE) && !defined(MODE_DEFERREDLIGHTSOURCE) && !defined(USESHADOWMAPORTHO)\n" "#endif // FRAGMENT_SHADER\n" "\n" "\n" @@ -2526,7 +2667,7 @@ const char *builtincgshaderstring = "void main\n" "(\n" "float4 gl_Vertex : POSITION,\n" -"uniform float4x4 ModelViewProjectionMatrix,\n" +"uniform float4x4 ModelViewProjectionMatrix : register(c8),\n" "#ifdef USEVERTEXTEXTUREBLEND\n" "float4 gl_Color : COLOR0,\n" "#endif\n" @@ -2534,13 +2675,13 @@ const char *builtincgshaderstring = "float4 gl_MultiTexCoord1 : TEXCOORD1,\n" "float4 gl_MultiTexCoord2 : TEXCOORD2,\n" "float4 gl_MultiTexCoord3 : TEXCOORD3,\n" -"uniform float4x4 TexMatrix,\n" +"uniform float4x4 TexMatrix : register(c0),\n" "#ifdef USEVERTEXTEXTUREBLEND\n" -"uniform float4x4 BackgroundTexMatrix,\n" +"uniform float4x4 BackgroundTexMatrix : register(c4),\n" "#endif\n" -"uniform float4x4 ModelViewMatrix,\n" +"uniform float4x4 ModelViewMatrix : register(c12),\n" "#ifdef USEOFFSETMAPPING\n" -"uniform float3 EyePosition,\n" +"uniform float3 EyePosition : register(c24),\n" "#endif\n" "out float4 gl_Position : POSITION,\n" "out float4 gl_FrontColor : COLOR,\n" @@ -2555,7 +2696,11 @@ const char *builtincgshaderstring = "{\n" " TexCoordBoth = mul(TexMatrix, gl_MultiTexCoord0);\n" "#ifdef USEVERTEXTEXTUREBLEND\n" -" gl_FrontColor = gl_Color;\n" +"#ifdef HLSL\n" +" gl_FrontColor = gl_Color.bgra; // NOTE: D3DCOLOR is backwards\n" +"#else\n" +" gl_FrontColor = gl_Color; // Cg is forward\n" +"#endif\n" " TexCoordBoth.zw = float2(Backgroundmul(TexMatrix, gl_MultiTexCoord0));\n" "#endif\n" "\n" @@ -2582,19 +2727,19 @@ const char *builtincgshaderstring = "float3 VectorS : TEXCOORD5, // direction of S texcoord (sometimes crudely called tangent)\n" "float3 VectorT : TEXCOORD6, // direction of T texcoord (sometimes crudely called binormal)\n" "float3 VectorR : TEXCOORD7, // direction of R texcoord (surface normal)\n" -"uniform sampler2D Texture_Normal,\n" +"uniform sampler Texture_Normal : register(s0),\n" "#ifdef USEALPHAKILL\n" -"uniform sampler2D Texture_Color,\n" +"uniform sampler Texture_Color : register(s1),\n" "#endif\n" -"uniform sampler2D Texture_Gloss,\n" +"uniform sampler Texture_Gloss : register(s2),\n" "#ifdef USEVERTEXTEXTUREBLEND\n" -"uniform sampler2D Texture_SecondaryNormal,\n" -"uniform sampler2D Texture_SecondaryGloss,\n" +"uniform sampler Texture_SecondaryNormal : register(s4),\n" +"uniform sampler Texture_SecondaryGloss : register(s6),\n" "#endif\n" "#ifdef USEOFFSETMAPPING\n" -"uniform float OffsetMapping_Scale,\n" +"uniform float OffsetMapping_Scale : register(c24),\n" "#endif\n" -"uniform half SpecularPower,\n" +"uniform half SpecularPower : register(c36),\n" "out float4 gl_FragColor : COLOR\n" ")\n" "{\n" @@ -2618,14 +2763,14 @@ const char *builtincgshaderstring = "#endif\n" "\n" "#ifdef USEVERTEXTEXTUREBLEND\n" -" float3 surfacenormal = lerp(float3(tex2D(Texture_SecondaryNormal, TexCoord2)), float3(tex2D(Texture_Normal, TexCoord)), terrainblend) - float3(0.5, 0.5, 0.5);\n" -" float a = lerp(tex2D(Texture_SecondaryGloss, TexCoord2), tex2D(Texture_Gloss, TexCoord).a, terrainblend);\n" +" float3 surfacenormal = lerp(tex2D(Texture_SecondaryNormal, TexCoord2).rgb, tex2D(Texture_Normal, TexCoord).rgb, terrainblend) - float3(0.5, 0.5, 0.5);\n" +" float a = lerp(tex2D(Texture_SecondaryGloss, TexCoord2).a, tex2D(Texture_Gloss, TexCoord).a, terrainblend);\n" "#else\n" -" float3 surfacenormal = float3(tex2D(Texture_Normal, TexCoord)) - float3(0.5, 0.5, 0.5);\n" +" float3 surfacenormal = tex2D(Texture_Normal, TexCoord).rgb - float3(0.5, 0.5, 0.5);\n" " float a = tex2D(Texture_Gloss, TexCoord).a;\n" "#endif\n" "\n" -" gl_FragColor = float4(normalize(surfacenormal.x * VectorS + surfacenormal.y * VectorT + surfacenormal.z * VectorR) * 0.5 + float3(0.5, 0.5, 0.5), 1);\n" +" gl_FragColor = float4(normalize(surfacenormal.x * VectorS + surfacenormal.y * VectorT + surfacenormal.z * VectorR) * 0.5 + float3(0.5, 0.5, 0.5), a);\n" "}\n" "#endif // FRAGMENT_SHADER\n" "#else // !MODE_DEFERREDGEOMETRY\n" @@ -2638,8 +2783,8 @@ const char *builtincgshaderstring = "void main\n" "(\n" "float4 gl_Vertex : POSITION,\n" -"uniform float4x4 ModelViewProjectionMatrix,\n" -"uniform float4x4 ModelViewMatrix,\n" +"uniform float4x4 ModelViewProjectionMatrix : register(c8),\n" +"uniform float4x4 ModelViewMatrix : register(c12),\n" "out float4 gl_Position : POSITION,\n" "out float4 ModelViewPosition : TEXCOORD0\n" ")\n" @@ -2652,57 +2797,61 @@ const char *builtincgshaderstring = "#ifdef FRAGMENT_SHADER\n" "void main\n" "(\n" +"#ifdef HLSL\n" +"float2 Pixel : VPOS,\n" +"#else\n" "float2 Pixel : WPOS,\n" +"#endif\n" "float4 ModelViewPosition : TEXCOORD0,\n" -"uniform float4x4 ViewToLight,\n" -"uniform float2 ScreenToDepth, // ScreenToDepth = float2(Far / (Far - Near), Far * Near / (Near - Far));\n" -"uniform float3 LightPosition,\n" -"uniform half2 PixelToScreenTexCoord,\n" -"uniform half3 DeferredColor_Ambient,\n" -"uniform half3 DeferredColor_Diffuse,\n" +"uniform float4x4 ViewToLight : register(c44),\n" +"uniform float2 ScreenToDepth : register(c33), // ScreenToDepth = float2(Far / (Far - Near), Far * Near / (Near - Far));\n" +"uniform float3 LightPosition : register(c23),\n" +"uniform half2 PixelToScreenTexCoord : register(c42),\n" +"uniform half3 DeferredColor_Ambient : register(c9),\n" +"uniform half3 DeferredColor_Diffuse : register(c10),\n" "#ifdef USESPECULAR\n" -"uniform half3 DeferredColor_Specular,\n" -"uniform half SpecularPower,\n" +"uniform half3 DeferredColor_Specular : register(c11),\n" +"uniform half SpecularPower : register(c36),\n" "#endif\n" -"uniform sampler2D Texture_Attenuation,\n" -"uniform sampler2D Texture_ScreenDepth,\n" -"uniform sampler2D Texture_ScreenNormalMap,\n" +"uniform sampler Texture_Attenuation : register(s9),\n" +"uniform sampler Texture_ScreenDepth : register(s13),\n" +"uniform sampler Texture_ScreenNormalMap : register(s14),\n" "\n" "#ifdef USECUBEFILTER\n" -"uniform samplerCUBE Texture_Cube,\n" +"uniform samplerCUBE Texture_Cube : register(s10),\n" "#endif\n" "\n" "#ifdef USESHADOWMAPRECT\n" "# ifdef USESHADOWSAMPLER\n" -"uniform samplerRECTShadow Texture_ShadowMapRect,\n" +"uniform samplerRECTShadow Texture_ShadowMapRect : register(s11),\n" "# else\n" -"uniform samplerRECT Texture_ShadowMapRect,\n" +"uniform samplerRECT Texture_ShadowMapRect : register(s11),\n" "# endif\n" "#endif\n" "\n" "#ifdef USESHADOWMAP2D\n" "# ifdef USESHADOWSAMPLER\n" -"uniform sampler2DShadow Texture_ShadowMap2D,\n" +"uniform sampler Texture_ShadowMap2D : register(s11),\n" "# else\n" -"uniform sampler2D Texture_ShadowMap2D,\n" +"uniform sampler Texture_ShadowMap2D : register(s11),\n" "# endif\n" "#endif\n" "\n" "#ifdef USESHADOWMAPVSDCT\n" -"uniform samplerCUBE Texture_CubeProjection,\n" +"uniform samplerCUBE Texture_CubeProjection : register(s12),\n" "#endif\n" "\n" "#ifdef USESHADOWMAPCUBE\n" "# ifdef USESHADOWSAMPLER\n" -"uniform samplerCUBEShadow Texture_ShadowMapCube,\n" +"uniform samplerCUBEShadow Texture_ShadowMapCube : register(s11),\n" "# else\n" -"uniform samplerCUBE Texture_ShadowMapCube,\n" +"uniform samplerCUBE Texture_ShadowMapCube : register(s11),\n" "# endif\n" "#endif\n" "\n" "#if defined(USESHADOWMAPRECT) || defined(USESHADOWMAP2D) || defined(USESHADOWMAPCUBE)\n" -"uniform float2 ShadowMap_TextureScale,\n" -"uniform float4 ShadowMap_Parameters,\n" +"uniform float2 ShadowMap_TextureScale : register(c35),\n" +"uniform float4 ShadowMap_Parameters : register(c34),\n" "#endif\n" "\n" "out float4 gl_FragData0 : COLOR0,\n" @@ -2716,14 +2865,14 @@ const char *builtincgshaderstring = " position.z = ScreenToDepth.y / (texDepth2D(Texture_ScreenDepth, ScreenTexCoord) + ScreenToDepth.x);\n" " position.xy = ModelViewPosition.xy * (position.z / ModelViewPosition.z);\n" " // decode viewspace pixel normal\n" -" half4 normalmap = tex2D(Texture_ScreenNormalMap, ScreenTexCoord);\n" -" half3 surfacenormal = normalize(normalmap.rgb - half3(0.5,0.5,0.5));\n" +" half4 normalmap = half4(tex2D(Texture_ScreenNormalMap, ScreenTexCoord));\n" +" half3 surfacenormal = half3(normalize(normalmap.rgb - half3(0.5,0.5,0.5)));\n" " // surfacenormal = pixel normal in viewspace\n" " // LightVector = pixel to light in viewspace\n" " // CubeVector = position in lightspace\n" " // eyevector = pixel to view in viewspace\n" -" float3 CubeVector = float3(mul(ViewToLight, float4(position,1)));\n" -" half fade = half(tex2D(Texture_Attenuation, float2(length(CubeVector), 0.0)));\n" +" float3 CubeVector = mul(ViewToLight, float4(position,1)).xyz;\n" +" half fade = half(tex2D(Texture_Attenuation, float2(length(CubeVector), 0.0)).r);\n" "#ifdef USEDIFFUSE\n" " // calculate diffuse shading\n" " half3 lightnormal = half3(normalize(LightPosition - position));\n" @@ -2735,7 +2884,7 @@ const char *builtincgshaderstring = "# ifdef USEEXACTSPECULARMATH\n" " half specular = pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(eyevector)))*-1.0, 0.0)), SpecularPower * normalmap.a);\n" "# else\n" -" half3 specularnormal = normalize(lightnormal + half3(normalize(eyevector)));\n" +" half3 specularnormal = half3(normalize(lightnormal + half3(normalize(eyevector))));\n" " half specular = pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), SpecularPower * normalmap.a);\n" "# endif\n" "#endif\n" @@ -2785,7 +2934,7 @@ const char *builtincgshaderstring = "void main\n" "(\n" "float4 gl_Vertex : POSITION,\n" -"uniform float4x4 ModelViewProjectionMatrix,\n" +"uniform float4x4 ModelViewProjectionMatrix : register(c8),\n" "#if defined(USEVERTEXTEXTUREBLEND) || defined(MODE_VERTEXCOLOR)\n" "float4 gl_Color : COLOR0,\n" "#endif\n" @@ -2795,26 +2944,26 @@ const char *builtincgshaderstring = "float4 gl_MultiTexCoord3 : TEXCOORD3,\n" "float4 gl_MultiTexCoord4 : TEXCOORD4,\n" "\n" -"uniform float3 EyePosition,\n" -"uniform float4x4 TexMatrix,\n" +"uniform float3 EyePosition : register(c24),\n" +"uniform float4x4 TexMatrix : register(c0),\n" "#ifdef USEVERTEXTEXTUREBLEND\n" -"uniform float4x4 BackgroundTexMatrix,\n" +"uniform float4x4 BackgroundTexMatrix : register(c4),\n" "#endif\n" "#ifdef MODE_LIGHTSOURCE\n" -"uniform float4x4 ModelToLight,\n" +"uniform float4x4 ModelToLight : register(c20),\n" "#endif\n" "#ifdef MODE_LIGHTSOURCE\n" -"uniform float3 LightPosition,\n" +"uniform float3 LightPosition : register(c27),\n" "#endif\n" "#ifdef MODE_LIGHTDIRECTION\n" -"uniform float3 LightDir,\n" +"uniform float3 LightDir : register(c26),\n" "#endif\n" -"uniform float4 FogPlane,\n" +"uniform float4 FogPlane : register(c25),\n" "#ifdef MODE_DEFERREDLIGHTSOURCE\n" -"uniform float3 LightPosition,\n" +"uniform float3 LightPosition : register(c27),\n" "#endif\n" "#ifdef USESHADOWMAPORTHO\n" -"uniform float4x4 ShadowMapMatrix,\n" +"uniform float4x4 ShadowMapMatrix : register(c16),\n" "#endif\n" "\n" "out float4 gl_FrontColor : COLOR,\n" @@ -2849,7 +2998,11 @@ const char *builtincgshaderstring = ")\n" "{\n" "#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND)\n" -" gl_FrontColor = gl_Color;\n" +"#ifdef HLSL\n" +" gl_FrontColor = gl_Color.bgra; // NOTE: D3DCOLOR is backwards\n" +"#else\n" +" gl_FrontColor = gl_Color; // Cg is forward\n" +"#endif\n" "#endif\n" " // copy the surface texcoord\n" " TexCoordBoth = mul(TexMatrix, gl_MultiTexCoord0);\n" @@ -2857,13 +3010,13 @@ const char *builtincgshaderstring = " TexCoordBoth.zw = mul(BackgroundTexMatrix, gl_MultiTexCoord0).xy;\n" "#endif\n" "#ifdef USELIGHTMAP\n" -" TexCoordLightmap = float2(gl_MultiTexCoord4);\n" +" TexCoordLightmap = gl_MultiTexCoord4.xy;\n" "#endif\n" "\n" "#ifdef MODE_LIGHTSOURCE\n" " // transform vertex position into light attenuation/cubemap space\n" " // (-1 to +1 across the light box)\n" -" CubeVector = float3(mul(ModelToLight, gl_Vertex));\n" +" CubeVector = mul(ModelToLight, gl_Vertex).xyz;\n" "\n" "# ifdef USEDIFFUSE\n" " // transform unnormalized light direction into tangent space\n" @@ -2905,7 +3058,7 @@ const char *builtincgshaderstring = " gl_Position = mul(ModelViewProjectionMatrix, gl_Vertex);\n" "\n" "#ifdef USESHADOWMAPORTHO\n" -" ShadowMapTC = float3(mul(ShadowMapMatrix, gl_Position));\n" +" ShadowMapTC = mul(ShadowMapMatrix, gl_Position).xyz;\n" "#endif\n" "\n" "#ifdef USEREFLECTION\n" @@ -2921,8 +3074,12 @@ const char *builtincgshaderstring = "void main\n" "(\n" "#ifdef USEDEFERREDLIGHTMAP\n" +"#ifdef HLSL\n" +"float2 Pixel : VPOS,\n" +"#else\n" "float2 Pixel : WPOS,\n" "#endif\n" +"#endif\n" "float4 gl_FrontColor : COLOR,\n" "float4 TexCoordBoth : TEXCOORD0,\n" "#ifdef USELIGHTMAP\n" @@ -2955,135 +3112,135 @@ const char *builtincgshaderstring = "float3 ShadowMapTC : TEXCOORD3, // CONFLICTS WITH USEREFLECTION!\n" "#endif\n" "\n" -"uniform sampler2D Texture_Normal,\n" -"uniform sampler2D Texture_Color,\n" +"uniform sampler Texture_Normal : register(s0),\n" +"uniform sampler Texture_Color : register(s1),\n" "#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n" -"uniform sampler2D Texture_Gloss,\n" +"uniform sampler Texture_Gloss : register(s2),\n" "#endif\n" "#ifdef USEGLOW\n" -"uniform sampler2D Texture_Glow,\n" +"uniform sampler Texture_Glow : register(s3),\n" "#endif\n" "#ifdef USEVERTEXTEXTUREBLEND\n" -"uniform sampler2D Texture_SecondaryNormal,\n" -"uniform sampler2D Texture_SecondaryColor,\n" +"uniform sampler Texture_SecondaryNormal : register(s4),\n" +"uniform sampler Texture_SecondaryColor : register(s5),\n" "#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n" -"uniform sampler2D Texture_SecondaryGloss,\n" +"uniform sampler Texture_SecondaryGloss : register(s6),\n" "#endif\n" "#ifdef USEGLOW\n" -"uniform sampler2D Texture_SecondaryGlow,\n" +"uniform sampler Texture_SecondaryGlow : register(s7),\n" "#endif\n" "#endif\n" "#ifdef USECOLORMAPPING\n" -"uniform sampler2D Texture_Pants,\n" -"uniform sampler2D Texture_Shirt,\n" +"uniform sampler Texture_Pants : register(s4),\n" +"uniform sampler Texture_Shirt : register(s7),\n" "#endif\n" "#ifdef USEFOG\n" -"uniform sampler2D Texture_FogHeightTexture,\n" -"uniform sampler2D Texture_FogMask,\n" +"uniform sampler Texture_FogHeightTexture : register(s14),\n" +"uniform sampler Texture_FogMask : register(s8),\n" "#endif\n" "#ifdef USELIGHTMAP\n" -"uniform sampler2D Texture_Lightmap,\n" +"uniform sampler Texture_Lightmap : register(s9),\n" "#endif\n" "#if defined(MODE_LIGHTDIRECTIONMAP_MODELSPACE) || defined(MODE_LIGHTDIRECTIONMAP_TANGENTSPACE)\n" -"uniform sampler2D Texture_Deluxemap,\n" +"uniform sampler Texture_Deluxemap : register(s10),\n" "#endif\n" "#ifdef USEREFLECTION\n" -"uniform sampler2D Texture_Reflection,\n" +"uniform sampler Texture_Reflection : register(s7),\n" "#endif\n" "\n" "#ifdef MODE_DEFERREDLIGHTSOURCE\n" -"uniform sampler2D Texture_ScreenDepth,\n" -"uniform sampler2D Texture_ScreenNormalMap,\n" +"uniform sampler Texture_ScreenDepth : register(s13),\n" +"uniform sampler Texture_ScreenNormalMap : register(s14),\n" "#endif\n" "#ifdef USEDEFERREDLIGHTMAP\n" -"uniform sampler2D Texture_ScreenDiffuse,\n" -"uniform sampler2D Texture_ScreenSpecular,\n" +"uniform sampler Texture_ScreenDiffuse : register(s11),\n" +"uniform sampler Texture_ScreenSpecular : register(s12),\n" "#endif\n" "\n" "#ifdef USECOLORMAPPING\n" -"uniform half3 Color_Pants,\n" -"uniform half3 Color_Shirt,\n" +"uniform half3 Color_Pants : register(c7),\n" +"uniform half3 Color_Shirt : register(c8),\n" "#endif\n" "#ifdef USEFOG\n" -"uniform float3 FogColor,\n" -"uniform float FogRangeRecip,\n" -"uniform float FogPlaneViewDist,\n" -"uniform float FogHeightFade,\n" +"uniform float3 FogColor : register(c16),\n" +"uniform float FogRangeRecip : register(c20),\n" +"uniform float FogPlaneViewDist : register(c19),\n" +"uniform float FogHeightFade : register(c17),\n" "#endif\n" "\n" "#ifdef USEOFFSETMAPPING\n" -"uniform float OffsetMapping_Scale,\n" +"uniform float OffsetMapping_Scale : register(c24),\n" "#endif\n" "\n" "#ifdef USEDEFERREDLIGHTMAP\n" -"uniform half2 PixelToScreenTexCoord,\n" -"uniform half3 DeferredMod_Diffuse,\n" -"uniform half3 DeferredMod_Specular,\n" -"#endif\n" -"uniform half3 Color_Ambient,\n" -"uniform half3 Color_Diffuse,\n" -"uniform half3 Color_Specular,\n" -"uniform half SpecularPower,\n" +"uniform half2 PixelToScreenTexCoord : register(c42),\n" +"uniform half3 DeferredMod_Diffuse : register(c12),\n" +"uniform half3 DeferredMod_Specular : register(c13),\n" +"#endif\n" +"uniform half3 Color_Ambient : register(c3),\n" +"uniform half3 Color_Diffuse : register(c4),\n" +"uniform half3 Color_Specular : register(c5),\n" +"uniform half SpecularPower : register(c36),\n" "#ifdef USEGLOW\n" -"uniform half3 Color_Glow,\n" +"uniform half3 Color_Glow : register(c6),\n" "#endif\n" -"uniform half Alpha,\n" +"uniform half Alpha : register(c0),\n" "#ifdef USEREFLECTION\n" -"uniform float4 DistortScaleRefractReflect,\n" -"uniform float4 ScreenScaleRefractReflect,\n" -"uniform float4 ScreenCenterRefractReflect,\n" -"uniform half4 ReflectColor,\n" +"uniform float4 DistortScaleRefractReflect : register(c14),\n" +"uniform float4 ScreenScaleRefractReflect : register(c32),\n" +"uniform float4 ScreenCenterRefractReflect : register(c31),\n" +"uniform half4 ReflectColor : register(c26),\n" "#endif\n" "#ifdef USEREFLECTCUBE\n" -"uniform float4x4 ModelToReflectCube,\n" -"uniform sampler2D Texture_ReflectMask,\n" -"uniform samplerCUBE Texture_ReflectCube,\n" +"uniform float4x4 ModelToReflectCube : register(c48),\n" +"uniform sampler Texture_ReflectMask : register(s5),\n" +"uniform samplerCUBE Texture_ReflectCube : register(s6),\n" "#endif\n" "#ifdef MODE_LIGHTDIRECTION\n" -"uniform half3 LightColor,\n" +"uniform half3 LightColor : register(c21),\n" "#endif\n" "#ifdef MODE_LIGHTSOURCE\n" -"uniform half3 LightColor,\n" +"uniform half3 LightColor : register(c21),\n" "#endif\n" "\n" "#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE)\n" -"uniform sampler2D Texture_Attenuation,\n" -"uniform samplerCUBE Texture_Cube,\n" +"uniform sampler Texture_Attenuation : register(s9),\n" +"uniform samplerCUBE Texture_Cube : register(s10),\n" "#endif\n" "\n" "#if defined(MODE_LIGHTSOURCE) || defined(MODE_DEFERREDLIGHTSOURCE) || defined(USESHADOWMAPORTHO)\n" "\n" "#ifdef USESHADOWMAPRECT\n" "# ifdef USESHADOWSAMPLER\n" -"uniform samplerRECTShadow Texture_ShadowMapRect,\n" +"uniform samplerRECTShadow Texture_ShadowMapRect : register(s11),\n" "# else\n" -"uniform samplerRECT Texture_ShadowMapRect,\n" +"uniform samplerRECT Texture_ShadowMapRect : register(s11),\n" "# endif\n" "#endif\n" "\n" "#ifdef USESHADOWMAP2D\n" "# ifdef USESHADOWSAMPLER\n" -"uniform sampler2DShadow Texture_ShadowMap2D,\n" +"uniform sampler Texture_ShadowMap2D : register(s11),\n" "# else\n" -"uniform sampler2D Texture_ShadowMap2D,\n" +"uniform sampler Texture_ShadowMap2D : register(s11),\n" "# endif\n" "#endif\n" "\n" "#ifdef USESHADOWMAPVSDCT\n" -"uniform samplerCUBE Texture_CubeProjection,\n" +"uniform samplerCUBE Texture_CubeProjection : register(s12),\n" "#endif\n" "\n" "#ifdef USESHADOWMAPCUBE\n" "# ifdef USESHADOWSAMPLER\n" -"uniform samplerCUBEShadow Texture_ShadowMapCube,\n" +"uniform samplerCUBEShadow Texture_ShadowMapCube : register(s11),\n" "# else\n" -"uniform samplerCUBE Texture_ShadowMapCube,\n" +"uniform samplerCUBE Texture_ShadowMapCube : register(s11),\n" "# endif\n" "#endif\n" "\n" "#if defined(USESHADOWMAPRECT) || defined(USESHADOWMAP2D) || defined(USESHADOWMAPCUBE)\n" -"uniform float2 ShadowMap_TextureScale,\n" -"uniform float4 ShadowMap_Parameters,\n" +"uniform float2 ShadowMap_TextureScale : register(c35),\n" +"uniform float4 ShadowMap_Parameters : register(c34),\n" "#endif\n" "#endif // !defined(MODE_LIGHTSOURCE) && !defined(MODE_DEFERREDLIGHTSOURCE) && !defined(USESHADOWMAPORTHO)\n" "\n" @@ -3108,29 +3265,29 @@ const char *builtincgshaderstring = "#endif\n" " color.a *= Alpha;\n" "#ifdef USECOLORMAPPING\n" -" color.rgb += half3(tex2D(Texture_Pants, TexCoord)) * Color_Pants + half3(tex2D(Texture_Shirt, TexCoord)) * Color_Shirt;\n" +" color.rgb += half3(tex2D(Texture_Pants, TexCoord).rgb) * Color_Pants + half3(tex2D(Texture_Shirt, TexCoord).rgb) * Color_Shirt;\n" "#endif\n" "#ifdef USEVERTEXTEXTUREBLEND\n" -" float terrainblend = clamp(half(gl_FrontColor.a) * color.a * 2.0 - 0.5, half(0.0), half(1.0));\n" +" half terrainblend = clamp(half(gl_FrontColor.a) * color.a * 2.0 - 0.5, half(0.0), half(1.0));\n" " //half terrainblend = min(half(gl_FrontColor.a) * color.a * 2.0, half(1.0));\n" " //half terrainblend = half(gl_FrontColor.a) * color.a > 0.5;\n" -" color.rgb = half3(lerp(float3(tex2D(Texture_SecondaryColor, TexCoord2)), float3(color.rgb), terrainblend));\n" +" color.rgb = half3(lerp(tex2D(Texture_SecondaryColor, TexCoord2).rgb, float3(color.rgb), terrainblend));\n" " color.a = 1.0;\n" -" //color = lerp(half4(1, 0, 0, 1), color, terrainblend);\n" +" //color = half4(lerp(float4(1, 0, 0, 1), color, terrainblend));\n" "#endif\n" "\n" " // get the surface normal\n" "#ifdef USEVERTEXTEXTUREBLEND\n" -" half3 surfacenormal = normalize(half3(lerp(float3(tex2D(Texture_SecondaryNormal, TexCoord2)), float3(tex2D(Texture_Normal, TexCoord)), terrainblend)) - half3(0.5, 0.5, 0.5));\n" +" half3 surfacenormal = normalize(half3(lerp(tex2D(Texture_SecondaryNormal, TexCoord2).rgb, tex2D(Texture_Normal, TexCoord).rgb, terrainblend)) - half3(0.5, 0.5, 0.5));\n" "#else\n" -" half3 surfacenormal = normalize(half3(tex2D(Texture_Normal, TexCoord)) - half3(0.5, 0.5, 0.5));\n" +" half3 surfacenormal = half3(normalize(half3(tex2D(Texture_Normal, TexCoord).rgb) - half3(0.5, 0.5, 0.5)));\n" "#endif\n" "\n" " // get the material colors\n" " half3 diffusetex = color.rgb;\n" "#if defined(USESPECULAR) || defined(USEDEFERREDLIGHTMAP)\n" "# ifdef USEVERTEXTEXTUREBLEND\n" -" half4 glosstex = half4(lerp(float4(tex2D(Texture_SecondaryGloss, TexCoord2)), float4(tex2D(Texture_Gloss, TexCoord)), terrainblend));\n" +" half4 glosstex = half4(lerp(tex2D(Texture_SecondaryGloss, TexCoord2), tex2D(Texture_Gloss, TexCoord), terrainblend));\n" "# else\n" " half4 glosstex = half4(tex2D(Texture_Gloss, TexCoord));\n" "# endif\n" @@ -3139,8 +3296,8 @@ const char *builtincgshaderstring = "#ifdef USEREFLECTCUBE\n" " float3 TangentReflectVector = reflect(-EyeVector, surfacenormal);\n" " float3 ModelReflectVector = TangentReflectVector.x * VectorS + TangentReflectVector.y * VectorT + TangentReflectVector.z * VectorR;\n" -" float3 ReflectCubeTexCoord = float3(mul(ModelToReflectCube, float4(ModelReflectVector, 0)));\n" -" diffusetex += half3(tex2D(Texture_ReflectMask, TexCoord)) * half3(texCUBE(Texture_ReflectCube, ReflectCubeTexCoord));\n" +" float3 ReflectCubeTexCoord = mul(ModelToReflectCube, float4(ModelReflectVector, 0)).xyz;\n" +" diffusetex += half3(tex2D(Texture_ReflectMask, TexCoord).rgb) * half3(texCUBE(Texture_ReflectCube, ReflectCubeTexCoord).rgb);\n" "#endif\n" "\n" "\n" @@ -3154,10 +3311,10 @@ const char *builtincgshaderstring = " color.rgb = diffusetex * (Color_Ambient + diffuse * Color_Diffuse);\n" "#ifdef USESPECULAR\n" "#ifdef USEEXACTSPECULARMATH\n" -" half specular = pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), SpecularPower * glosstex.a);\n" +" half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), SpecularPower * glosstex.a));\n" "#else\n" -" half3 specularnormal = normalize(lightnormal + half3(normalize(EyeVector)));\n" -" half specular = pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), SpecularPower * glosstex.a);\n" +" half3 specularnormal = half3(normalize(lightnormal + half3(normalize(EyeVector))));\n" +" half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), SpecularPower * glosstex.a));\n" "#endif\n" " color.rgb += glosstex.rgb * (specular * Color_Specular);\n" "#endif\n" @@ -3165,9 +3322,9 @@ const char *builtincgshaderstring = " color.rgb = diffusetex * Color_Ambient;\n" "#endif\n" " color.rgb *= LightColor;\n" -" color.rgb *= half(tex2D(Texture_Attenuation, float2(length(CubeVector), 0.0)));\n" +" color.rgb *= half(tex2D(Texture_Attenuation, float2(length(CubeVector), 0.0)).r);\n" "#if defined(USESHADOWMAPRECT) || defined(USESHADOWMAPCUBE) || defined(USESHADOWMAP2D)\n" -" color.rgb *= ShadowMapCompare(CubeVector,\n" +" color.rgb *= half(ShadowMapCompare(CubeVector,\n" "# if defined(USESHADOWMAP2D)\n" "Texture_ShadowMap2D, ShadowMap_Parameters, ShadowMap_TextureScale\n" "# endif\n" @@ -3181,12 +3338,32 @@ const char *builtincgshaderstring = "#ifdef USESHADOWMAPVSDCT\n" ", Texture_CubeProjection\n" "#endif\n" -" );\n" +" ));\n" "\n" "#endif\n" "# ifdef USECUBEFILTER\n" -" color.rgb *= half3(texCUBE(Texture_Cube, CubeVector));\n" +" color.rgb *= half3(texCUBE(Texture_Cube, CubeVector).rgb);\n" "# endif\n" +"\n" +"#ifdef USESHADOWMAP2D\n" +"#ifdef USESHADOWMAPVSDCT\n" +"// color.rgb = half3(tex2D(Texture_ShadowMap2D, float2(0.1,0.1)).rgb);\n" +"// color.rgb = half3(tex2D(Texture_ShadowMap2D, GetShadowMapTC2D(CubeVector, ShadowMap_Parameters, Texture_CubeProjection).xy * ShadowMap_TextureScale).rgb);\n" +"// color.rgb = half3(GetShadowMapTC2D(CubeVector, ShadowMap_Parameters, Texture_CubeProjection).xyz * float3(ShadowMap_TextureScale,1.0));\n" +"// color.r = half(texDepth2D(Texture_ShadowMap2D, GetShadowMapTC2D(CubeVector, ShadowMap_Parameters, Texture_CubeProjection).xy * ShadowMap_TextureScale));\n" +"#else\n" +"// float3 shadowmaptc = GetShadowMapTC2D(CubeVector, ShadowMap_Parameters);\n" +"// color.rgb = half3(tex2D(Texture_ShadowMap2D, float2(0.1,0.1)).rgb);\n" +"// color.rgb = half3(tex2D(Texture_ShadowMap2D, GetShadowMapTC2D(CubeVector, ShadowMap_Parameters).xy * ShadowMap_TextureScale).rgb);\n" +"// color.rgb = half3(GetShadowMapTC2D(CubeVector, ShadowMap_Parameters).xyz * float3(ShadowMap_TextureScale,1.0));\n" +"// color.r = half(texDepth2D(Texture_ShadowMap2D, GetShadowMapTC2D(CubeVector, ShadowMap_Parameters).xy * ShadowMap_TextureScale));\n" +"// color.r = half(shadowmaptc.z - texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale));\n" +"// color.r = half(texDepth2D(Texture_ShadowMap2D, shadowmaptc.xy * ShadowMap_TextureScale));\n" +"// color.r = half(shadowmaptc.z);\n" +"#endif\n" +"// color.r = 1;\n" +"#endif\n" +"// color.rgb = half3(1,1,1);\n" "#endif // MODE_LIGHTSOURCE\n" "\n" "\n" @@ -3202,8 +3379,8 @@ const char *builtincgshaderstring = "#ifdef MODE_LIGHTDIRECTIONMAP_MODELSPACE\n" "#define SHADING\n" " // deluxemap lightmapping using light vectors in modelspace (q3map2 -light -deluxe)\n" -" half3 lightnormal_modelspace = half3(tex2D(Texture_Deluxemap, TexCoordLightmap)) * 2.0 + half3(-1.0, -1.0, -1.0);\n" -" half3 lightcolor = half3(tex2D(Texture_Lightmap, TexCoordLightmap));\n" +" half3 lightnormal_modelspace = half3(tex2D(Texture_Deluxemap, TexCoordLightmap).rgb) * 2.0 + half3(-1.0, -1.0, -1.0);\n" +" half3 lightcolor = half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb);\n" " // convert modelspace light vector to tangentspace\n" " half3 lightnormal;\n" " lightnormal.x = dot(lightnormal_modelspace, half3(VectorS));\n" @@ -3223,15 +3400,15 @@ const char *builtincgshaderstring = "#ifdef MODE_LIGHTDIRECTIONMAP_TANGENTSPACE\n" "#define SHADING\n" " // deluxemap lightmapping using light vectors in tangentspace (hmap2 -light)\n" -" half3 lightnormal = half3(tex2D(Texture_Deluxemap, TexCoordLightmap)) * 2.0 + half3(-1.0, -1.0, -1.0);\n" -" half3 lightcolor = half3(tex2D(Texture_Lightmap, TexCoordLightmap));\n" +" half3 lightnormal = half3(tex2D(Texture_Deluxemap, TexCoordLightmap).rgb) * 2.0 + half3(-1.0, -1.0, -1.0);\n" +" half3 lightcolor = half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb);\n" "#endif\n" "\n" "\n" "\n" "\n" "#ifdef MODE_LIGHTMAP\n" -" color.rgb = diffusetex * (Color_Ambient + half3(tex2D(Texture_Lightmap, TexCoordLightmap)) * Color_Diffuse);\n" +" color.rgb = diffusetex * (Color_Ambient + half3(tex2D(Texture_Lightmap, TexCoordLightmap).rgb) * Color_Diffuse);\n" "#endif // MODE_LIGHTMAP\n" "#ifdef MODE_VERTEXCOLOR\n" " color.rgb = diffusetex * (Color_Ambient + half3(gl_FrontColor.rgb) * Color_Diffuse);\n" @@ -3248,10 +3425,10 @@ const char *builtincgshaderstring = " half diffuse = half(max(float(dot(surfacenormal, lightnormal)), 0.0));\n" "# ifdef USESPECULAR\n" "# ifdef USEEXACTSPECULARMATH\n" -" half specular = pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), SpecularPower * glosstex.a);\n" +" half specular = half(pow(half(max(float(dot(reflect(lightnormal, surfacenormal), normalize(EyeVector)))*-1.0, 0.0)), SpecularPower * glosstex.a));\n" "# else\n" -" half3 specularnormal = normalize(lightnormal + half3(normalize(EyeVector)));\n" -" half specular = pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), SpecularPower * glosstex.a);\n" +" half3 specularnormal = half3(normalize(lightnormal + half3(normalize(EyeVector))));\n" +" half specular = half(pow(half(max(float(dot(surfacenormal, specularnormal)), 0.0)), SpecularPower * glosstex.a));\n" "# endif\n" " color.rgb = diffusetex * Color_Ambient + (diffusetex * Color_Diffuse * diffuse + glosstex.rgb * Color_Specular * specular) * lightcolor;\n" "# else\n" @@ -3275,15 +3452,15 @@ const char *builtincgshaderstring = "\n" "#ifdef USEDEFERREDLIGHTMAP\n" " float2 ScreenTexCoord = Pixel * PixelToScreenTexCoord;\n" -" color.rgb += diffusetex * half3(tex2D(Texture_ScreenDiffuse, ScreenTexCoord)) * DeferredMod_Diffuse;\n" -" color.rgb += glosstex.rgb * half3(tex2D(Texture_ScreenSpecular, ScreenTexCoord)) * DeferredMod_Specular;\n" +" color.rgb += diffusetex * half3(tex2D(Texture_ScreenDiffuse, ScreenTexCoord).rgb) * DeferredMod_Diffuse;\n" +" color.rgb += glosstex.rgb * half3(tex2D(Texture_ScreenSpecular, ScreenTexCoord).rgb) * DeferredMod_Specular;\n" "#endif\n" "\n" "#ifdef USEGLOW\n" "#ifdef USEVERTEXTEXTUREBLEND\n" -" color.rgb += lerp(half3(tex2D(Texture_SecondaryGlow, TexCoord2)), half3(tex2D(Texture_Glow, TexCoord)), terrainblend) * Color_Glow;\n" +" color.rgb += half3(lerp(tex2D(Texture_SecondaryGlow, TexCoord2).rgb, tex2D(Texture_Glow, TexCoord).rgb, terrainblend)) * Color_Glow;\n" "#else\n" -" color.rgb += half3(tex2D(Texture_Glow, TexCoord)) * Color_Glow;\n" +" color.rgb += half3(tex2D(Texture_Glow, TexCoord).rgb) * Color_Glow;\n" "#endif\n" "#endif\n" "\n" @@ -3294,9 +3471,9 @@ const char *builtincgshaderstring = " // reflection must come last because it already contains exactly the correct fog (the reflection render preserves camera distance from the plane, it only flips the side) and ContrastBoost/SceneBrightness\n" "#ifdef USEREFLECTION\n" " float4 ScreenScaleRefractReflectIW = ScreenScaleRefractReflect * (1.0 / ModelViewProjectionPosition.w);\n" -" //float4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(half3(tex2D(Texture_Normal, TexCoord)) - half3(0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n" +" //float4 ScreenTexCoord = (ModelViewProjectionPosition.xyxy + normalize(half3(tex2D(Texture_Normal, TexCoord).rgb) - half3(0.5,0.5,0.5)).xyxy * DistortScaleRefractReflect * 100) * ScreenScaleRefractReflectIW + ScreenCenterRefractReflect;\n" " float2 SafeScreenTexCoord = ModelViewProjectionPosition.xy * ScreenScaleRefractReflectIW.zw + ScreenCenterRefractReflect.zw;\n" -" float2 ScreenTexCoord = SafeScreenTexCoord + float3(normalize(half3(tex2D(Texture_Normal, TexCoord)) - half3(0.5))).xy * DistortScaleRefractReflect.zw;\n" +" float2 ScreenTexCoord = SafeScreenTexCoord + float3(normalize(half3(tex2D(Texture_Normal, TexCoord).rgb) - half3(0.5,0.5,0.5))).xy * DistortScaleRefractReflect.zw;\n" " // FIXME temporary hack to detect the case that the reflection\n" " // gets blackened at edges due to leaving the area that contains actual\n" " // content.\n" @@ -3307,7 +3484,7 @@ const char *builtincgshaderstring = " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(-0.01, 0.01)).rgb) / 0.05);\n" " f *= min(1.0, length(tex2D(Texture_Reflection, ScreenTexCoord + float2(-0.01, -0.01)).rgb) / 0.05);\n" " ScreenTexCoord = lerp(SafeScreenTexCoord, ScreenTexCoord, f);\n" -" color.rgb = lerp(color.rgb, half3(tex2D(Texture_Reflection, ScreenTexCoord)) * ReflectColor.rgb, ReflectColor.a);\n" +" color.rgb = lerp(color.rgb, half3(tex2D(Texture_Reflection, ScreenTexCoord).rgb) * ReflectColor.rgb, ReflectColor.a);\n" "#endif\n" "\n" " gl_FragColor = float4(color);\n" -- 2.39.2