[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54645] branches/ge_harmony/source/blender /gpu/shaders/gpu_shader_light_frag.glsl: Orthographic projections now work with inferred lighting again, however they still suffer from a bug where Blender' s panel layout can cause offsets in the lighting.

Daniel Stokes kupomail at gmail.com
Tue Feb 19 01:34:39 CET 2013


Revision: 54645
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54645
Author:   kupoman
Date:     2013-02-19 00:34:38 +0000 (Tue, 19 Feb 2013)
Log Message:
-----------
Orthographic projections now work with inferred lighting again, however they still suffer from a bug where Blender's panel layout can cause offsets in the lighting. This should not be a problem in the Blenderplayer since it uses the full window.

Modified Paths:
--------------
    branches/ge_harmony/source/blender/gpu/shaders/gpu_shader_light_frag.glsl

Modified: branches/ge_harmony/source/blender/gpu/shaders/gpu_shader_light_frag.glsl
===================================================================
--- branches/ge_harmony/source/blender/gpu/shaders/gpu_shader_light_frag.glsl	2013-02-19 00:06:46 UTC (rev 54644)
+++ branches/ge_harmony/source/blender/gpu/shaders/gpu_shader_light_frag.glsl	2013-02-19 00:34:38 UTC (rev 54645)
@@ -49,33 +49,37 @@
 uniform sampler2D bgl_PrepassTarget1;
 uniform sampler2D bgl_DepthTexture;
 
-// uniform mat4 inv_proj_matrix;
+uniform mat4 inv_proj_matrix;
 uniform vec4 bgl_Bounds;
 
 void main()
 {
 	vec3 L;
 	float attenuation = 1.0;
-	
+
 	vec2 texcoord = gl_FragCoord.xy/bgl_Bounds.xy;
 	vec4 gbuffer = texture2D(bgl_PrepassTarget0, texcoord);
 	vec4 mbuffer = texture2D(bgl_PrepassTarget1, texcoord);
 
 	vec3 N = gbuffer.rgb * 2.0 - vec3(1.0, 1.0, 1.0);
-	
+
+
+	vec3 V;
 	float depth = texture2D(bgl_DepthTexture, texcoord).r;
-	vec3 viewray = vec3(varposition.xy/varposition.z, 1.0);
-	depth = bgl_Bounds.w / (depth - bgl_Bounds.z);
-	vec3 V = viewray * -depth;
-	
-	// vec3 V;
-	// vec4 proj;
-	// proj.xy = texcoord;
-	// proj.z = depth;
-	// proj.xyz = proj.xyz * 2.0 - vec3(1.0, 1.0, 1.0);
-	// proj.w = 1.0;
-	// proj = inv_proj_matrix * proj;
-	// V.xyz = proj.xyz/proj.w;
+	if (gl_ProjectionMatrix[3][3] == 0.0) {
+		vec3 viewray = vec3(varposition.xy/varposition.z, 1.0);
+		depth = bgl_Bounds.w / (depth - bgl_Bounds.z);
+		V = viewray * -depth;
+	}
+	else {
+		vec4 proj;
+		proj.xy = texcoord;
+		proj.z = depth;
+		proj.xyz = proj.xyz * 2.0 - vec3(1.0, 1.0, 1.0);
+		proj.w = 1.0;
+		proj = inv_proj_matrix * proj;
+		V.xyz = proj.xyz/proj.w;
+	}
 
 	vec3 view = (gl_ProjectionMatrix[3][3] == 0.0)? normalize(-V): vec3(0.0, 0.0, -1.0);
 	
@@ -85,7 +89,7 @@
 	else {
 		L = bgl_Light.position - V;
 		float dist = length(L);
-		
+
 		if (bgl_Light.falloff == INVLINEAR)
 			attenuation = bgl_Light.dist/(bgl_Light.dist + dist);
 		else if (bgl_Light.falloff == INVSQUARE)
@@ -95,25 +99,25 @@
 			attenuation = bgl_Light.dist/(bgl_Light.dist + bgl_Light.att[0]*dist);
 			attenuation *= distkw/(distkw + bgl_Light.att[1]*dist*dist);
 		}
-		
+
 		attenuation *= max((bgl_Light.dist - dist), 0.0)/bgl_Light.dist;
 	}
 	L = normalize(L);
-	
+
 	if (bgl_Light.type == SPOT) {
 		float inpr;
 		lamp_visibility_spot_circle(bgl_Light.vector, L, inpr);
 		lamp_visibility_spot(bgl_Light.spotsize, bgl_Light.spotblend, inpr, attenuation, attenuation);
 	}
-	
+
 	attenuation = (attenuation < 0.001) ? 0.0 : attenuation;
-	
+
 #ifdef ALL_SHADERS
 	int matid = int(gbuffer.a)*65535;
 	int diff_shader = matid / 16;
 	int spec_shader = matid - (diff_shader*16);
 #endif
-	
+
 	// Diffuse term
 	float diff_term = 0.0;
 #ifdef ALL_SHADERS
@@ -138,7 +142,7 @@
 	else
 		diff_term = lambert;
 #endif
-	
+
 	// Specular term
 	float hardness = exp(LN_511 * mbuffer.b);
 #ifdef ALL_SHADERS
@@ -165,7 +169,7 @@
 	else
 		shade_phong_spec(N, L, view, 1.0, hardness);
 #endif
-	
+
 	// Factor in light properties
 	vec3 diff = bgl_Light.color * bgl_Light.energy * diff_term * attenuation;
 	float spec = length(bgl_Light.energy) * spec_term * attenuation;




More information about the Bf-blender-cvs mailing list