From f98cbc791d54e09d692c76871b48e4944c8819f6 Mon Sep 17 00:00:00 2001
From: Rudolf Polzer <divverent@xonotic.org>
Date: Mon, 28 Jan 2013 16:34:53 +0100
Subject: [PATCH] some more hlsl fixes

---
 gl_rmain.c    | 15 +++++++++++----
 shader_hlsl.h |  8 ++++----
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/gl_rmain.c b/gl_rmain.c
index 0322fdd6..c7b64f15 100644
--- a/gl_rmain.c
+++ b/gl_rmain.c
@@ -868,7 +868,6 @@ typedef struct r_glsl_permutation_s
 	int loc_BounceGridMatrix;
 	int loc_BounceGridIntensity;
 	int loc_BitValue;
-	int loc_Rand1f;
 	int loc_Rand2f;
 }
 r_glsl_permutation_t;
@@ -1220,7 +1219,6 @@ static void R_GLSL_CompilePermutation(r_glsl_permutation_t *p, unsigned int mode
 		p->loc_BounceGridMatrix           = qglGetUniformLocation(p->program, "BounceGridMatrix");
 		p->loc_BounceGridIntensity        = qglGetUniformLocation(p->program, "BounceGridIntensity");
 		p->loc_BitValue                   = qglGetUniformLocation(p->program, "BitValue");
-		p->loc_Rand1f                     = qglGetUniformLocation(p->program, "Rand1f");
 		p->loc_Rand2f                     = qglGetUniformLocation(p->program, "Rand2f");
 		// initialize the samplers to refer to the texture units we use
 		p->tex_Texture_First = -1;
@@ -1341,7 +1339,6 @@ static void R_SetupShader_SetPermutationGLSL(unsigned int mode, unsigned int per
 	if (r_glsl_permutation->loc_ModelViewProjectionMatrix >= 0) qglUniformMatrix4fv(r_glsl_permutation->loc_ModelViewProjectionMatrix, 1, false, gl_modelviewprojection16f);
 	if (r_glsl_permutation->loc_ModelViewMatrix >= 0) qglUniformMatrix4fv(r_glsl_permutation->loc_ModelViewMatrix, 1, false, gl_modelview16f);
 	if (r_glsl_permutation->loc_ClientTime >= 0) qglUniform1f(r_glsl_permutation->loc_ClientTime, cl.time);
-	if (r_glsl_permutation->loc_Rand1f     >= 0) qglUniform1f(r_glsl_permutation->loc_Rand1f, lhrandom(-1.0,1.0));
 	if (r_glsl_permutation->loc_Rand2f     >= 0) qglUniform2f(r_glsl_permutation->loc_Rand2f, lhrandom(-1.0,1.0), lhrandom(-1.0,1.0));
 	if (r_glsl_permutation->loc_BitValue   >= 0){
 		switch(r_viewfbo.integer){
@@ -1444,7 +1441,9 @@ typedef enum D3DPSREGISTER_e
 	D3DPSREGISTER_NormalmapScrollBlend = 52,
 	D3DPSREGISTER_OffsetMapping_LodDistance = 53,
 	D3DPSREGISTER_OffsetMapping_Bias = 54,
-	// next at 54
+	D3DPSREGISTER_OffsetMapping_BitValue = 55,
+	D3DPSREGISTER_OffsetMapping_Rand2f = 56,
+	// next at 57
 }
 D3DPSREGISTER_t;
 
@@ -1850,6 +1849,14 @@ void R_SetupShader_SetPermutationHLSL(unsigned int mode, unsigned int permutatio
 	hlslVSSetParameter16f(D3DVSREGISTER_ModelViewProjectionMatrix, gl_modelviewprojection16f);
 	hlslVSSetParameter16f(D3DVSREGISTER_ModelViewMatrix, gl_modelview16f);
 	hlslPSSetParameter1f(D3DPSREGISTER_ClientTime, cl.time);
+	hlslPSSetParameter2f(D3DPSREGISTER_Rand2f, lhrandom(-1.0,1.0), lhrandom(-1.0,1.0));
+	switch(r_viewfbo.integer){
+		case 0:
+		case 1:  hlslPSSetParameter1f(D3DPSREGISTER_BitValue, pow(2, -8))); break;
+		case 2:  hlslPSSetParameter1f(D3DPSREGISTER_BitValue, pow(2,-10)); break;
+		case 3:
+		default: hlslPSSetParameter1f(D3DPSREGISTER_BitValue, pow(2,-23));
+	};
 }
 #endif
 
diff --git a/shader_hlsl.h b/shader_hlsl.h
index 8a994b73..a8a42637 100644
--- a/shader_hlsl.h
+++ b/shader_hlsl.h
@@ -365,9 +365,9 @@
 "		uniform sampler Texture_First  : register(s0),\n"
 "		uniform sampler Texture_Second : register(s1),\n"
 "		uniform sampler Texture_Dither : register(s2),\n"
-"		uniform half   BitValue : register(c0),\n"
-"		uniform half      Alpha : register(c1),\n"
-"		uniform float2   Rand2f : register(c2),\n"
+"		uniform half   BitValue : register(c55),\n"
+"		uniform float2   Rand2f : register(c56),\n"
+"		uniform half      Alpha : register(c0),\n"
 "		out float4 dp_FragColor : COLOR\n"
 "		)\n"
 "		{\n"
@@ -375,7 +375,7 @@
 "			float2 tc = TexCoord;\n"
 "			float3 tex1 = tex2D(Texture_First,  tc).rgb;\n"
 "			float3 tex1 = tex2D(Texture_Second, tc).rgb;\n"
-"			float3 tex3 = tex2D(Texture_Dither, tc).rgb;\n"
+"			float3 tex3 = tex2D(Texture_Dither, tc*8.0+Rand2f).rgb;\n"
 "			dp_FragColor = (Alpha)*tex1 + (1.0-Alpha)*tex2 + (tex3-0.5)*BitValue;\n"
 "		}\n"
 "	#endif\n"
-- 
2.39.5