diff options
| author | SmileTheory <SmileTheory@gmail.com> | 2013-03-14 23:11:27 -0700 | 
|---|---|---|
| committer | Tim Angus <tim@ngus.net> | 2013-03-19 16:41:20 +0000 | 
| commit | d848901749d5d3a73a7111bdbdd34b6c7ef85f67 (patch) | |
| tree | 7b61938c4dd884848d9849219c78216fb15cdd66 /src/renderergl2/glsl | |
| parent | ee7ec241bf5fec5dcb97414e255573df52f42b0a (diff) | |
Support more tcgens in lightall shader.
Diffstat (limited to 'src/renderergl2/glsl')
| -rw-r--r-- | src/renderergl2/glsl/lightall_vp.glsl | 40 | 
1 files changed, 29 insertions, 11 deletions
diff --git a/src/renderergl2/glsl/lightall_vp.glsl b/src/renderergl2/glsl/lightall_vp.glsl index 05a41f4d..4604b6ed 100644 --- a/src/renderergl2/glsl/lightall_vp.glsl +++ b/src/renderergl2/glsl/lightall_vp.glsl @@ -1,5 +1,5 @@  attribute vec4 attr_TexCoord0; -#if defined(USE_LIGHTMAP) +#if defined(USE_LIGHTMAP) || defined(USE_TCGEN)  attribute vec4 attr_TexCoord1;  #endif  attribute vec4 attr_Color; @@ -31,6 +31,8 @@ uniform vec3   u_ViewOrigin;  #if defined(USE_TCGEN)  uniform int    u_TCGen0; +uniform vec3   u_TCGen0Vector0; +uniform vec3   u_TCGen0Vector1;  #endif  #if defined(USE_TCMOD) @@ -92,6 +94,29 @@ varying vec3   var_VertLight;  varying vec3   var_WorldLight;  #endif +#if defined(USE_TCGEN) +vec2 GenTexCoords(int TCGen, vec3 position, vec3 normal, vec3 TCGenVector0, vec3 TCGenVector1) +{ +	vec2 tex = attr_TexCoord0.st; + +	if (TCGen == TCGEN_LIGHTMAP) +	{ +		tex = attr_TexCoord1.st; +	} +	else if (TCGen == TCGEN_ENVIRONMENT_MAPPED) +	{ +		vec3 viewer = normalize(u_ViewOrigin - position); +		tex = -reflect(viewer, normal).yz * vec2(0.5, -0.5) + 0.5; +	} +	else if (TCGen == TCGEN_VECTOR) +	{ +		tex = vec2(dot(position, TCGenVector0), dot(position, TCGenVector1)); +	} +	 +	return tex; +} +#endif +  #if defined(USE_TCMOD)  vec2 ModTexCoords(vec2 st, vec3 position, vec4 texMatrix, vec4 offTurb)  { @@ -158,18 +183,11 @@ void main()  	var_SampleToView = SampleToView;  #endif -	vec2 tex; -  #if defined(USE_TCGEN) -	if (u_TCGen0 == TCGEN_ENVIRONMENT_MAPPED) -	{ -		tex = -reflect(normalize(SampleToView), normal).yz * vec2(0.5, -0.5) + 0.5; -	} -	else +	vec2 tex = GenTexCoords(u_TCGen0, position.xyz, normal, u_TCGen0Vector0, u_TCGen0Vector1); +#else +	vec2 tex = attr_TexCoord0.st;  #endif -	{ -		tex = attr_TexCoord0.st; -	}  #if defined(USE_TCMOD)  	var_DiffuseTex = ModTexCoords(tex, position.xyz, u_DiffuseTexMatrix, u_DiffuseTexOffTurb);  | 
