[quake3-commits] r2372 - in trunk/code/rend2: . glsl

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Wed Dec 5 20:55:45 EST 2012


Author: smiletheory
Date: 2012-12-05 20:55:45 -0500 (Wed, 05 Dec 2012)
New Revision: 2372

Modified:
   trunk/code/rend2/glsl/lightall_fp.glsl
   trunk/code/rend2/glsl/lightall_vp.glsl
   trunk/code/rend2/glsl/shadowmask_fp.glsl
   trunk/code/rend2/glsl/shadowmask_vp.glsl
   trunk/code/rend2/tr_backend.c
Log:
#5812 - Use refdef's coordinates when drawing to screen shadow fbo, and separate depth texture and screen texture coordinates in glsl shaders.

Modified: trunk/code/rend2/glsl/lightall_fp.glsl
===================================================================
--- trunk/code/rend2/glsl/lightall_fp.glsl	2012-12-04 03:05:34 UTC (rev 2371)
+++ trunk/code/rend2/glsl/lightall_fp.glsl	2012-12-06 01:55:45 UTC (rev 2372)
@@ -63,10 +63,6 @@
 varying vec3      var_WorldLight;
 #endif
 
-#if defined(USE_LIGHT_VECTOR) && !defined(USE_FAST_LIGHT) && defined(USE_SHADOWMAP)
-varying vec4   var_ScreenPos;
-#endif
-
 #define EPSILON 0.00000001
 
 #if defined(USE_PARALLAXMAP)
@@ -228,8 +224,7 @@
 	vec3 ambientLight  = u_AmbientLight;
 
   #if defined(USE_SHADOWMAP)
-	//vec2 shadowTex = gl_FragCoord.xy * r_FBufScale;
-	vec2 shadowTex = var_ScreenPos.xy / var_ScreenPos.w;
+	vec2 shadowTex = gl_FragCoord.xy * r_FBufScale;
 	directedLight *= texture2D(u_ShadowMap, shadowTex).r;
   #endif
 #elif defined(USE_LIGHT_VERTEX) && !defined(USE_FAST_LIGHT)

Modified: trunk/code/rend2/glsl/lightall_vp.glsl
===================================================================
--- trunk/code/rend2/glsl/lightall_vp.glsl	2012-12-04 03:05:34 UTC (rev 2371)
+++ trunk/code/rend2/glsl/lightall_vp.glsl	2012-12-06 01:55:45 UTC (rev 2372)
@@ -92,10 +92,6 @@
 varying vec3   var_WorldLight;
 #endif
 
-#if defined(USE_LIGHT_VECTOR) && !defined(USE_FAST_LIGHT) && defined(USE_SHADOWMAP)
-varying vec4   var_ScreenPos;
-#endif
-
 #if defined(USE_TCMOD)
 vec2 ModTexCoords(vec2 st, vec3 position, vec4 texMatrix, vec4 offTurb)
 {
@@ -133,10 +129,6 @@
 
 	gl_Position = u_ModelViewProjectionMatrix * position;
 
-#if defined(USE_LIGHT_VECTOR) && !defined(USE_FAST_LIGHT) && defined(USE_SHADOWMAP)
-	var_ScreenPos = gl_Position + vec2(1.0, 0.0).xxyx * gl_Position.w;
-#endif
-
 #if (defined(USE_LIGHTMAP) || defined(USE_LIGHT_VERTEX)) && !defined(USE_DELUXEMAP) && !defined(USE_FAST_LIGHT)
 	vec3 worldLight = attr_LightDirection;
 #endif

Modified: trunk/code/rend2/glsl/shadowmask_fp.glsl
===================================================================
--- trunk/code/rend2/glsl/shadowmask_fp.glsl	2012-12-04 03:05:34 UTC (rev 2371)
+++ trunk/code/rend2/glsl/shadowmask_fp.glsl	2012-12-06 01:55:45 UTC (rev 2372)
@@ -15,7 +15,7 @@
 uniform vec3   u_ViewOrigin;
 uniform vec4   u_ViewInfo; // zfar / znear, zfar
 
-varying vec2   var_ScreenTex;
+varying vec2   var_DepthTex;
 varying vec3   var_ViewDir;
 
 // Input: It uses texture coords as the random number seed.
@@ -41,7 +41,7 @@
 	float scale = 2.0 / r_shadowMapSize;
 		
 #if defined(USE_SHADOW_FILTER)
-	float r = random(var_ScreenTex.xy);
+	float r = random(var_DepthTex.xy);
 	float sinr = sin(r) * scale;
 	float cosr = cos(r) * scale;
 	mat2 rmat = mat2(cosr, sinr, -sinr, cosr);
@@ -78,7 +78,7 @@
 {
 	float result;
 	
-	float depth = getLinearDepth(u_ScreenDepthMap, var_ScreenTex, u_ViewInfo.x);
+	float depth = getLinearDepth(u_ScreenDepthMap, var_DepthTex, u_ViewInfo.x);
 	float sampleZ = u_ViewInfo.y * depth;
 
 	vec4 biasPos = vec4(u_ViewOrigin + var_ViewDir * depth * 0.99, 1.0);

Modified: trunk/code/rend2/glsl/shadowmask_vp.glsl
===================================================================
--- trunk/code/rend2/glsl/shadowmask_vp.glsl	2012-12-04 03:05:34 UTC (rev 2371)
+++ trunk/code/rend2/glsl/shadowmask_vp.glsl	2012-12-06 01:55:45 UTC (rev 2372)
@@ -6,15 +6,13 @@
 uniform vec3   u_ViewUp;
 uniform vec4   u_ViewInfo; // zfar / znear
 
-varying vec2   var_ScreenTex;
+varying vec2   var_DepthTex;
 varying vec3   var_ViewDir;
 
 void main()
 {
 	gl_Position = attr_Position;
-	//vec2 screenCoords = gl_Position.xy / gl_Position.w;
-	//var_ScreenTex = screenCoords * 0.5 + 0.5;
-	var_ScreenTex = attr_TexCoord0.xy;
-	vec2 screenCoords = attr_TexCoord0.xy * 2.0 - 1.0;
+	vec2 screenCoords = gl_Position.xy / gl_Position.w;
+	var_DepthTex = attr_TexCoord0.xy;
 	var_ViewDir = u_ViewForward + u_ViewLeft * -screenCoords.x + u_ViewUp * screenCoords.y;
 }

Modified: trunk/code/rend2/tr_backend.c
===================================================================
--- trunk/code/rend2/tr_backend.c	2012-12-04 03:05:34 UTC (rev 2371)
+++ trunk/code/rend2/tr_backend.c	2012-12-06 01:55:45 UTC (rev 2372)
@@ -1245,22 +1245,38 @@
 		{
 			vec4_t quadVerts[4];
 			vec2_t texCoords[4];
+			vec4_t box;
 
 			FBO_Bind(tr.screenShadowFbo);
 
-			qglViewport(0, 0, tr.screenShadowFbo->width, tr.screenShadowFbo->height);
-			qglScissor(0, 0, tr.screenShadowFbo->width, tr.screenShadowFbo->height);
+			box[0] = (backEnd.refdef.x     ) * tr.screenShadowFbo->width  / (float)glConfig.vidWidth;
+			box[1] = (backEnd.refdef.y     ) * tr.screenShadowFbo->height / (float)glConfig.vidHeight;
+			box[2] = (backEnd.refdef.width ) * tr.screenShadowFbo->width  / (float)glConfig.vidWidth;
+			box[3] = (backEnd.refdef.height) * tr.screenShadowFbo->height / (float)glConfig.vidHeight;
 
-			VectorSet4(quadVerts[0], -1,  1, 0, 1);
-			VectorSet4(quadVerts[1],  1,  1, 0, 1);
-			VectorSet4(quadVerts[2],  1, -1, 0, 1);
-			VectorSet4(quadVerts[3], -1, -1, 0, 1);
+			qglViewport(box[0], box[1], box[2], box[3]);
+			qglScissor(box[0], box[1], box[2], box[3]);
 
-			texCoords[0][0] = 0; texCoords[0][1] = 1;
-			texCoords[1][0] = 1; texCoords[1][1] = 1;
-			texCoords[2][0] = 1; texCoords[2][1] = 0;
-			texCoords[3][0] = 0; texCoords[3][1] = 0;
+			box[0] = (backEnd.refdef.x                        ) / (float)glConfig.vidWidth;
+			box[1] = (backEnd.refdef.y                        ) / (float)glConfig.vidHeight;
+			box[2] = (backEnd.refdef.x + backEnd.refdef.width ) / (float)glConfig.vidWidth;
+			box[3] = (backEnd.refdef.y + backEnd.refdef.height) / (float)glConfig.vidHeight;
 
+			texCoords[0][0] = box[0]; texCoords[0][1] = box[3];
+			texCoords[1][0] = box[2]; texCoords[1][1] = box[3];
+			texCoords[2][0] = box[2]; texCoords[2][1] = box[1];
+			texCoords[3][0] = box[0]; texCoords[3][1] = box[1];
+
+			box[0] = -1.0f;
+			box[1] = -1.0f;
+			box[2] =  1.0f;
+			box[3] =  1.0f;
+
+			VectorSet4(quadVerts[0], box[0], box[3], 0, 1);
+			VectorSet4(quadVerts[1], box[2], box[3], 0, 1);
+			VectorSet4(quadVerts[2], box[2], box[1], 0, 1);
+			VectorSet4(quadVerts[3], box[0], box[1], 0, 1);
+
 			GL_State( GLS_DEPTHTEST_DISABLE );
 
 			GLSL_BindProgram(&tr.shadowmaskShader);



More information about the quake3-commits mailing list