mirror of
https://github.com/ioquake/ioq3.git
synced 2025-02-22 19:41:32 +00:00
OpenGL2: Small glsl shader optimizations, fixes, and cleanup.
This commit is contained in:
parent
efe8437cde
commit
623d107f42
15 changed files with 255 additions and 244 deletions
|
@ -1,4 +1,4 @@
|
||||||
attribute vec4 attr_Position;
|
attribute vec3 attr_Position;
|
||||||
attribute vec4 attr_TexCoord0;
|
attribute vec4 attr_TexCoord0;
|
||||||
|
|
||||||
uniform mat4 u_ModelViewProjectionMatrix;
|
uniform mat4 u_ModelViewProjectionMatrix;
|
||||||
|
@ -8,6 +8,6 @@ varying vec2 var_TexCoords;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = u_ModelViewProjectionMatrix * attr_Position;
|
gl_Position = u_ModelViewProjectionMatrix * vec4(attr_Position, 1.0);
|
||||||
var_TexCoords = attr_TexCoord0.st;
|
var_TexCoords = attr_TexCoord0.st;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
attribute vec4 attr_Position;
|
attribute vec3 attr_Position;
|
||||||
attribute vec4 attr_TexCoord0;
|
attribute vec4 attr_TexCoord0;
|
||||||
|
|
||||||
uniform mat4 u_ModelViewProjectionMatrix;
|
uniform mat4 u_ModelViewProjectionMatrix;
|
||||||
|
@ -8,6 +8,6 @@ varying vec2 var_TexCoords;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = u_ModelViewProjectionMatrix * attr_Position;
|
gl_Position = u_ModelViewProjectionMatrix * vec4(attr_Position, 1.0);
|
||||||
var_TexCoords = attr_TexCoord0.st;
|
var_TexCoords = attr_TexCoord0.st;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
attribute vec4 attr_Position;
|
attribute vec3 attr_Position;
|
||||||
attribute vec4 attr_TexCoord0;
|
attribute vec4 attr_TexCoord0;
|
||||||
attribute vec3 attr_Normal;
|
attribute vec3 attr_Normal;
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)
|
||||||
}
|
}
|
||||||
else if (u_DeformGen == DGEN_WAVE_SQUARE)
|
else if (u_DeformGen == DGEN_WAVE_SQUARE)
|
||||||
{
|
{
|
||||||
func = sign(sin(value * 2.0 * M_PI));
|
func = sign(0.5 - fract(value));
|
||||||
}
|
}
|
||||||
else if (u_DeformGen == DGEN_WAVE_TRIANGLE)
|
else if (u_DeformGen == DGEN_WAVE_TRIANGLE)
|
||||||
{
|
{
|
||||||
|
@ -62,7 +62,7 @@ vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)
|
||||||
{
|
{
|
||||||
func = (1.0 - fract(value));
|
func = (1.0 - fract(value));
|
||||||
}
|
}
|
||||||
else if (u_DeformGen == DGEN_BULGE)
|
else // if (u_DeformGen == DGEN_BULGE)
|
||||||
{
|
{
|
||||||
func = sin(value);
|
func = sin(value);
|
||||||
}
|
}
|
||||||
|
@ -73,16 +73,16 @@ vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 position = attr_Position;
|
vec3 position = attr_Position;
|
||||||
vec3 normal = attr_Normal;
|
vec3 normal = attr_Normal * 2.0 - vec3(1.0);
|
||||||
|
|
||||||
#if defined(USE_DEFORM_VERTEXES)
|
#if defined(USE_DEFORM_VERTEXES)
|
||||||
position.xyz = DeformPosition(position.xyz, normal, attr_TexCoord0.st);
|
position = DeformPosition(position, normal, attr_TexCoord0.st);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
gl_Position = u_ModelViewProjectionMatrix * position;
|
gl_Position = u_ModelViewProjectionMatrix * vec4(position, 1.0);
|
||||||
|
|
||||||
vec3 dist = u_DlightInfo.xyz - position.xyz;
|
vec3 dist = u_DlightInfo.xyz - position;
|
||||||
|
|
||||||
var_Tex1 = dist.xy * u_DlightInfo.a + vec2(0.5);
|
var_Tex1 = dist.xy * u_DlightInfo.a + vec2(0.5);
|
||||||
float dlightmod = step(0.0, dot(dist, normal));
|
float dlightmod = step(0.0, dot(dist, normal));
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
attribute vec4 attr_Position;
|
attribute vec3 attr_Position;
|
||||||
attribute vec4 attr_TexCoord0;
|
attribute vec4 attr_TexCoord0;
|
||||||
|
|
||||||
uniform mat4 u_ModelViewProjectionMatrix;
|
uniform mat4 u_ModelViewProjectionMatrix;
|
||||||
|
@ -8,6 +8,6 @@ varying vec2 var_TexCoords;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = u_ModelViewProjectionMatrix * attr_Position;
|
gl_Position = u_ModelViewProjectionMatrix * vec4(attr_Position, 1.0);
|
||||||
var_TexCoords = attr_TexCoord0.st;
|
var_TexCoords = attr_TexCoord0.st;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,5 +5,5 @@ varying float var_Scale;
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_FragColor = u_Color;
|
gl_FragColor = u_Color;
|
||||||
gl_FragColor.a *= sqrt(clamp(var_Scale, 0.0, 1.0));
|
gl_FragColor.a = sqrt(clamp(var_Scale, 0.0, 1.0));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,27 +1,30 @@
|
||||||
attribute vec4 attr_Position;
|
attribute vec3 attr_Position;
|
||||||
attribute vec3 attr_Normal;
|
attribute vec3 attr_Normal;
|
||||||
|
|
||||||
attribute vec4 attr_TexCoord0;
|
attribute vec4 attr_TexCoord0;
|
||||||
|
|
||||||
//#if defined(USE_VERTEX_ANIMATION)
|
#if defined(USE_VERTEX_ANIMATION)
|
||||||
attribute vec4 attr_Position2;
|
attribute vec3 attr_Position2;
|
||||||
attribute vec3 attr_Normal2;
|
attribute vec3 attr_Normal2;
|
||||||
//#endif
|
#endif
|
||||||
|
|
||||||
uniform vec4 u_FogDistance;
|
uniform vec4 u_FogDistance;
|
||||||
uniform vec4 u_FogDepth;
|
uniform vec4 u_FogDepth;
|
||||||
uniform float u_FogEyeT;
|
uniform float u_FogEyeT;
|
||||||
|
|
||||||
//#if defined(USE_DEFORM_VERTEXES)
|
#if defined(USE_DEFORM_VERTEXES)
|
||||||
uniform int u_DeformGen;
|
uniform int u_DeformGen;
|
||||||
uniform float u_DeformParams[5];
|
uniform float u_DeformParams[5];
|
||||||
//#endif
|
#endif
|
||||||
|
|
||||||
uniform float u_Time;
|
uniform float u_Time;
|
||||||
uniform mat4 u_ModelViewProjectionMatrix;
|
uniform mat4 u_ModelViewProjectionMatrix;
|
||||||
|
|
||||||
//#if defined(USE_VERTEX_ANIMATION)
|
#if defined(USE_VERTEX_ANIMATION)
|
||||||
uniform float u_VertexLerp;
|
uniform float u_VertexLerp;
|
||||||
//#endif
|
#endif
|
||||||
|
|
||||||
|
uniform vec4 u_Color;
|
||||||
|
|
||||||
varying float var_Scale;
|
varying float var_Scale;
|
||||||
|
|
||||||
|
@ -57,7 +60,7 @@ vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)
|
||||||
}
|
}
|
||||||
else if (u_DeformGen == DGEN_WAVE_SQUARE)
|
else if (u_DeformGen == DGEN_WAVE_SQUARE)
|
||||||
{
|
{
|
||||||
func = sign(sin(value * 2.0 * M_PI));
|
func = sign(0.5 - fract(value));
|
||||||
}
|
}
|
||||||
else if (u_DeformGen == DGEN_WAVE_TRIANGLE)
|
else if (u_DeformGen == DGEN_WAVE_TRIANGLE)
|
||||||
{
|
{
|
||||||
|
@ -71,7 +74,7 @@ vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)
|
||||||
{
|
{
|
||||||
func = (1.0 - fract(value));
|
func = (1.0 - fract(value));
|
||||||
}
|
}
|
||||||
else if (u_DeformGen == DGEN_BULGE)
|
else // if (u_DeformGen == DGEN_BULGE)
|
||||||
{
|
{
|
||||||
func = sin(value);
|
func = sin(value);
|
||||||
}
|
}
|
||||||
|
@ -80,15 +83,15 @@ vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
float CalcFog(vec4 position)
|
float CalcFog(vec3 position)
|
||||||
{
|
{
|
||||||
float s = dot(position, u_FogDistance) * 8.0;
|
float s = dot(vec4(position, 1.0), u_FogDistance) * 8.0;
|
||||||
float t = dot(position, u_FogDepth);
|
float t = dot(vec4(position, 1.0), u_FogDepth);
|
||||||
|
|
||||||
float eyeOutside = step(0.0, -u_FogEyeT);
|
float eyeOutside = float(u_FogEyeT < 0.0);
|
||||||
float fogged = step(eyeOutside, t);
|
float fogged = float(t >= eyeOutside);
|
||||||
|
|
||||||
t = max(t, 1e-6);
|
t += 1e-6;
|
||||||
t *= fogged / (t - u_FogEyeT * eyeOutside);
|
t *= fogged / (t - u_FogEyeT * eyeOutside);
|
||||||
|
|
||||||
return s * t;
|
return s * t;
|
||||||
|
@ -97,18 +100,19 @@ float CalcFog(vec4 position)
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
#if defined(USE_VERTEX_ANIMATION)
|
#if defined(USE_VERTEX_ANIMATION)
|
||||||
vec4 position = mix(attr_Position, attr_Position2, u_VertexLerp);
|
vec3 position = mix(attr_Position, attr_Position2, u_VertexLerp);
|
||||||
vec3 normal = normalize(mix(attr_Normal, attr_Normal2, u_VertexLerp));
|
vec3 normal = mix(attr_Normal, attr_Normal2, u_VertexLerp);
|
||||||
|
normal = normalize(normal - vec3(0.5));
|
||||||
#else
|
#else
|
||||||
vec4 position = attr_Position;
|
vec3 position = attr_Position;
|
||||||
vec3 normal = attr_Normal;
|
vec3 normal = attr_Normal * 2.0 - vec3(1.0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USE_DEFORM_VERTEXES)
|
#if defined(USE_DEFORM_VERTEXES)
|
||||||
position.xyz = DeformPosition(position.xyz, normal, attr_TexCoord0.st);
|
position.xyz = DeformPosition(position.xyz, normal, attr_TexCoord0.st);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
gl_Position = u_ModelViewProjectionMatrix * position;
|
gl_Position = u_ModelViewProjectionMatrix * vec4(position, 1.0);
|
||||||
|
|
||||||
var_Scale = CalcFog(position);
|
var_Scale = CalcFog(position) * u_Color.a * u_Color.a;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,8 @@ void main()
|
||||||
{
|
{
|
||||||
color = color2;
|
color = color2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//color = color * (u_Texture1Env.xxxx + color2 * u_Texture1Env.z) + color2 * u_Texture1Env.y;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
gl_FragColor = color * var_Color;
|
gl_FragColor = color * var_Color;
|
||||||
|
|
|
@ -89,11 +89,11 @@ vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)
|
||||||
}
|
}
|
||||||
else if (u_DeformGen == DGEN_WAVE_SQUARE)
|
else if (u_DeformGen == DGEN_WAVE_SQUARE)
|
||||||
{
|
{
|
||||||
func = sign(sin(value * 2.0 * M_PI));
|
func = sign(fract(0.5 - value));
|
||||||
}
|
}
|
||||||
else if (u_DeformGen == DGEN_WAVE_TRIANGLE)
|
else if (u_DeformGen == DGEN_WAVE_TRIANGLE)
|
||||||
{
|
{
|
||||||
func = 1.0 - abs(4.0 * fract(value + 0.25) - 2.0);
|
func = abs(fract(value + 0.75) - 0.5) * 4.0 - 1.0;
|
||||||
}
|
}
|
||||||
else if (u_DeformGen == DGEN_WAVE_SAWTOOTH)
|
else if (u_DeformGen == DGEN_WAVE_SAWTOOTH)
|
||||||
{
|
{
|
||||||
|
@ -103,7 +103,7 @@ vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)
|
||||||
{
|
{
|
||||||
func = (1.0 - fract(value));
|
func = (1.0 - fract(value));
|
||||||
}
|
}
|
||||||
else if (u_DeformGen == DGEN_BULGE)
|
else // if (u_DeformGen == DGEN_BULGE)
|
||||||
{
|
{
|
||||||
func = sin(value);
|
func = sin(value);
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,9 @@ vec2 GenTexCoords(int TCGen, vec3 position, vec3 normal, vec3 TCGenVector0, vec3
|
||||||
else if (TCGen == TCGEN_ENVIRONMENT_MAPPED)
|
else if (TCGen == TCGEN_ENVIRONMENT_MAPPED)
|
||||||
{
|
{
|
||||||
vec3 viewer = normalize(u_LocalViewOrigin - position);
|
vec3 viewer = normalize(u_LocalViewOrigin - position);
|
||||||
tex = -reflect(viewer, normal).yz * vec2(0.5, -0.5) + 0.5;
|
vec2 ref = reflect(viewer, normal).yz;
|
||||||
|
tex.s = ref.x * -0.5 + 0.5;
|
||||||
|
tex.t = ref.y * 0.5 + 0.5;
|
||||||
}
|
}
|
||||||
else if (TCGen == TCGEN_VECTOR)
|
else if (TCGen == TCGEN_VECTOR)
|
||||||
{
|
{
|
||||||
|
@ -139,13 +141,14 @@ vec2 GenTexCoords(int TCGen, vec3 position, vec3 normal, vec3 TCGenVector0, vec3
|
||||||
vec2 ModTexCoords(vec2 st, vec3 position, vec4 texMatrix, vec4 offTurb)
|
vec2 ModTexCoords(vec2 st, vec3 position, vec4 texMatrix, vec4 offTurb)
|
||||||
{
|
{
|
||||||
float amplitude = offTurb.z;
|
float amplitude = offTurb.z;
|
||||||
float phase = offTurb.w;
|
float phase = offTurb.w * 2.0 * M_PI;
|
||||||
vec2 st2 = vec2(dot(st, texMatrix.xz), dot(st, texMatrix.yw)) + offTurb.xy;
|
vec2 st2;
|
||||||
|
st2.x = st.x * texMatrix.x + (st.y * texMatrix.z + offTurb.x);
|
||||||
|
st2.y = st.x * texMatrix.y + (st.y * texMatrix.w + offTurb.y);
|
||||||
|
|
||||||
vec3 offsetPos = position / 1024.0;
|
vec2 offsetPos = vec2(position.x + position.z, position.y);
|
||||||
offsetPos.x += offsetPos.z;
|
|
||||||
|
|
||||||
vec2 texOffset = sin((offsetPos.xy + vec2(phase)) * 2.0 * M_PI);
|
vec2 texOffset = sin(offsetPos * (2.0 * M_PI / 1024.0) + vec2(phase));
|
||||||
|
|
||||||
return st2 + texOffset * amplitude;
|
return st2 + texOffset * amplitude;
|
||||||
}
|
}
|
||||||
|
@ -186,13 +189,13 @@ vec4 CalcColor(vec3 position, vec3 normal)
|
||||||
#if defined(USE_FOG)
|
#if defined(USE_FOG)
|
||||||
float CalcFog(vec3 position)
|
float CalcFog(vec3 position)
|
||||||
{
|
{
|
||||||
float s = (dot(position, u_FogDistance.xyz) + u_FogDistance.w) * 8.0;
|
float s = dot(vec4(position, 1.0), u_FogDistance) * 8.0;
|
||||||
float t = dot(position, u_FogDepth.xyz) + u_FogDepth.w;
|
float t = dot(vec4(position, 1.0), u_FogDepth);
|
||||||
|
|
||||||
float eyeOutside = step(0.0, -u_FogEyeT);
|
float eyeOutside = float(u_FogEyeT < 0.0);
|
||||||
float fogged = step(eyeOutside, t);
|
float fogged = float(t < eyeOutside);
|
||||||
|
|
||||||
t = max(t, 1e-6);
|
t += 1e-6;
|
||||||
t *= fogged / (t - u_FogEyeT * eyeOutside);
|
t *= fogged / (t - u_FogEyeT * eyeOutside);
|
||||||
|
|
||||||
return s * t;
|
return s * t;
|
||||||
|
@ -203,7 +206,8 @@ void main()
|
||||||
{
|
{
|
||||||
#if defined(USE_VERTEX_ANIMATION)
|
#if defined(USE_VERTEX_ANIMATION)
|
||||||
vec3 position = mix(attr_Position, attr_Position2, u_VertexLerp);
|
vec3 position = mix(attr_Position, attr_Position2, u_VertexLerp);
|
||||||
vec3 normal = normalize(mix(attr_Normal, attr_Normal2, u_VertexLerp) * 2.0 - vec3(1.0));
|
vec3 normal = mix(attr_Normal, attr_Normal2, u_VertexLerp);
|
||||||
|
normal = normalize(normal - vec3(0.5));
|
||||||
#else
|
#else
|
||||||
vec3 position = attr_Position;
|
vec3 position = attr_Position;
|
||||||
vec3 normal = attr_Normal * 2.0 - vec3(1.0);
|
vec3 normal = attr_Normal * 2.0 - vec3(1.0);
|
||||||
|
|
|
@ -176,12 +176,31 @@ vec3 EnvironmentBRDF(float gloss, float NE, vec3 specular)
|
||||||
|
|
||||||
float CalcBlinn(float NH, float shininess)
|
float CalcBlinn(float NH, float shininess)
|
||||||
{
|
{
|
||||||
|
#if defined(USE_BLINN) || defined(USE_BLINN_FRESNEL)
|
||||||
|
// Normalized Blinn-Phong
|
||||||
|
float norm = shininess * 0.125 + 1.0;
|
||||||
|
#elif defined(USE_MCAULEY)
|
||||||
|
// Cook-Torrance as done by Stephen McAuley
|
||||||
|
// http://blog.selfshadow.com/publications/s2012-shading-course/mcauley/s2012_pbs_farcry3_notes_v2.pdf
|
||||||
|
float norm = shininess * 0.25 + 0.125;
|
||||||
|
#elif defined(USE_GOTANDA)
|
||||||
|
// Neumann-Neumann as done by Yoshiharu Gotanda
|
||||||
|
// http://research.tri-ace.com/Data/s2012_beyond_CourseNotes.pdf
|
||||||
|
float norm = shininess * 0.124858 + 0.269182;
|
||||||
|
#elif defined(USE_LAZAROV)
|
||||||
|
// Cook-Torrance as done by Dimitar Lazarov
|
||||||
|
// http://blog.selfshadow.com/publications/s2013-shading-course/lazarov/s2013_pbs_black_ops_2_notes.pdf
|
||||||
|
float norm = shininess * 0.125 + 0.25;
|
||||||
|
#else
|
||||||
|
float norm = 1.0;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
// from http://seblagarde.wordpress.com/2012/06/03/spherical-gaussien-approximation-for-blinn-phong-phong-and-fresnel/
|
// from http://seblagarde.wordpress.com/2012/06/03/spherical-gaussien-approximation-for-blinn-phong-phong-and-fresnel/
|
||||||
float a = shininess + 0.775;
|
float a = shininess + 0.775;
|
||||||
return exp(a * NH - a);
|
return norm * exp(a * NH - a);
|
||||||
#else
|
#else
|
||||||
return pow(NH, shininess);
|
return norm * pow(NH, shininess);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,22 +234,23 @@ float CalcFresnel(float EH)
|
||||||
|
|
||||||
float CalcVisibility(float NH, float NL, float NE, float EH, float gloss)
|
float CalcVisibility(float NH, float NL, float NE, float EH, float gloss)
|
||||||
{
|
{
|
||||||
#if 1
|
#if defined(USE_GOTANDA)
|
||||||
// From http://blog.selfshadow.com/publications/s2013-shading-course/lazarov/s2013_pbs_black_ops_2_notes.pdf
|
// Neumann-Neumann as done by Yoshiharu Gotanda
|
||||||
|
// http://research.tri-ace.com/Data/s2012_beyond_CourseNotes.pdf
|
||||||
|
return 1.0 / max(max(NL, NE), EPSILON);
|
||||||
|
#elif defined(USE_LAZAROV)
|
||||||
|
// Cook-Torrance as done by Dimitar Lazarov
|
||||||
|
// http://blog.selfshadow.com/publications/s2013-shading-course/lazarov/s2013_pbs_black_ops_2_notes.pdf
|
||||||
float k = min(1.0, gloss + 0.545);
|
float k = min(1.0, gloss + 0.545);
|
||||||
return 1.0 / (k * EH * EH + (1.0 - k));
|
return 1.0 / (k * (EH * EH - 1.0) + 1.0);
|
||||||
#elif 0
|
#elif defined(USE_GGX)
|
||||||
float roughness = exp2(gloss * -6.5);
|
float roughness = exp2(gloss * -6.5);
|
||||||
|
|
||||||
#if defined(USE_GGX)
|
|
||||||
// From http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf
|
|
||||||
float k = roughness + 1.0;
|
|
||||||
k *= k * 0.125;
|
|
||||||
#else
|
|
||||||
float k = roughness;
|
|
||||||
#endif
|
|
||||||
// Modified from http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf
|
// Modified from http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf
|
||||||
// NL, NE in numerator factored out from cook-torrance
|
// NL, NE in numerator factored out from cook-torrance
|
||||||
|
float k = roughness + 1.0;
|
||||||
|
k *= k * 0.125;
|
||||||
|
|
||||||
float k2 = 1.0 - k;
|
float k2 = 1.0 - k;
|
||||||
|
|
||||||
float invGeo1 = NL * k2 + k;
|
float invGeo1 = NL * k2 + k;
|
||||||
|
@ -238,55 +258,36 @@ float CalcVisibility(float NH, float NL, float NE, float EH, float gloss)
|
||||||
|
|
||||||
return 1.0 / (invGeo1 * invGeo2);
|
return 1.0 / (invGeo1 * invGeo2);
|
||||||
#else
|
#else
|
||||||
float geo = 2.0 * NH * min(NE, NL);
|
return 1.0;
|
||||||
geo /= max(EH, geo);
|
|
||||||
|
|
||||||
return geo;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
vec3 CalcSpecular(vec3 specular, float NH, float NL, float NE, float EH, float gloss, float shininess)
|
vec3 CalcSpecular(vec3 specular, float NH, float NL, float NE, float EH, float gloss, float shininess)
|
||||||
{
|
{
|
||||||
float blinn = CalcBlinn(NH, shininess);
|
#if defined(USE_GGX)
|
||||||
vec3 fSpecular = mix(specular, vec3(1.0), CalcFresnel(EH));
|
float distrib = CalcGGX(NH, gloss);
|
||||||
float vis = CalcVisibility(NH, NL, NE, EH, gloss);
|
#else
|
||||||
|
float distrib = CalcBlinn(NH, shininess);
|
||||||
#if defined(USE_BLINN)
|
|
||||||
// Normalized Blinn-Phong
|
|
||||||
return specular * blinn * (shininess * 0.125 + 1.0);
|
|
||||||
#elif defined(USE_BLINN_FRESNEL)
|
|
||||||
// Normalized Blinn-Phong with Fresnel
|
|
||||||
return fSpecular * blinn * (shininess * 0.125 + 1.0);
|
|
||||||
#elif defined(USE_MCAULEY)
|
|
||||||
// Cook-Torrance as done by Stephen McAuley
|
|
||||||
// http://blog.selfshadow.com/publications/s2012-shading-course/mcauley/s2012_pbs_farcry3_notes_v2.pdf
|
|
||||||
return fSpecular * blinn * (shininess * 0.25 + 0.125);
|
|
||||||
#elif defined(USE_GOTANDA)
|
|
||||||
// Neumann-Neumann as done by Yoshiharu Gotanda
|
|
||||||
// http://research.tri-ace.com/Data/s2012_beyond_CourseNotes.pdf
|
|
||||||
return fSpecular * blinn * (shininess * 0.124858 + 0.269182) / max(max(NL, NE), EPSILON);
|
|
||||||
#elif defined(USE_LAZAROV)
|
|
||||||
// Cook-Torrance as done by Dimitar Lazarov
|
|
||||||
// http://blog.selfshadow.com/publications/s2013-shading-course/lazarov/s2013_pbs_black_ops_2_notes.pdf
|
|
||||||
return fSpecular * blinn * (shininess * 0.125 + 0.25) * vis;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return vec3(0.0);
|
#if defined(USE_BLINN)
|
||||||
|
vec3 fSpecular = specular;
|
||||||
|
#else
|
||||||
|
vec3 fSpecular = mix(specular, vec3(1.0), CalcFresnel(EH));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
float vis = CalcVisibility(NH, NL, NE, EH, gloss);
|
||||||
|
|
||||||
|
return fSpecular * (distrib * vis);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float CalcLightAttenuation(vec3 dir, float sqrRadius)
|
float CalcLightAttenuation(float point, float normDist)
|
||||||
{
|
{
|
||||||
// point light at >0 radius, directional otherwise
|
// zero light at 1.0, approximating q3 style
|
||||||
float point = float(sqrRadius > 0.0);
|
|
||||||
|
|
||||||
// inverse square light
|
|
||||||
float attenuation = sqrRadius / dot(dir, dir);
|
|
||||||
|
|
||||||
// zero light at radius, approximating q3 style
|
|
||||||
// also don't attenuate directional light
|
// also don't attenuate directional light
|
||||||
attenuation = (0.5 * attenuation - 1.5) * point + 1.0;
|
float attenuation = (0.5 * normDist - 1.5) * point + 1.0;
|
||||||
|
|
||||||
// clamp attenuation
|
// clamp attenuation
|
||||||
#if defined(NO_LIGHT_CLAMP)
|
#if defined(NO_LIGHT_CLAMP)
|
||||||
|
@ -323,37 +324,32 @@ void main()
|
||||||
vec3 L, N, E, H;
|
vec3 L, N, E, H;
|
||||||
float NL, NH, NE, EH;
|
float NL, NH, NE, EH;
|
||||||
|
|
||||||
#if (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)) || defined(USE_PARALLAXMAP)
|
#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||||
#if defined(USE_VERT_TANGENT_SPACE)
|
#if defined(USE_VERT_TANGENT_SPACE)
|
||||||
mat3 tangentToWorld = mat3(var_Tangent.xyz, var_Bitangent.xyz, var_Normal.xyz);
|
mat3 tangentToWorld = mat3(var_Tangent.xyz, var_Bitangent.xyz, var_Normal.xyz);
|
||||||
|
E = vec3(var_Normal.w, var_Tangent.w, var_Bitangent.w);
|
||||||
#else
|
#else
|
||||||
mat3 tangentToWorld = cotangent_frame(var_Normal, -var_ViewDir, var_TexCoords.xy);
|
mat3 tangentToWorld = cotangent_frame(var_Normal, -var_ViewDir, var_TexCoords.xy);
|
||||||
#endif
|
E = var_ViewDir;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USE_DELUXEMAP)
|
E = normalize(E);
|
||||||
L = texture2D(u_DeluxeMap, var_TexCoords.zw).xyz - vec3(0.5);
|
|
||||||
L = L * u_EnableTextures.y + var_LightDir.xyz;
|
|
||||||
#elif defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
|
||||||
L = var_LightDir.xyz;
|
L = var_LightDir.xyz;
|
||||||
|
#if defined(USE_DELUXEMAP)
|
||||||
|
L += (texture2D(u_DeluxeMap, var_TexCoords.zw).xyz - vec3(0.5)) * u_EnableTextures.y;
|
||||||
#endif
|
#endif
|
||||||
|
float sqrLightDist = dot(L, L);
|
||||||
#if (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)) || defined(USE_PARALLAXMAP)
|
|
||||||
#if defined(USE_VERT_TANGENT_SPACE)
|
|
||||||
E = normalize(vec3(var_Normal.w, var_Tangent.w, var_Bitangent.w));
|
|
||||||
#else
|
|
||||||
E = normalize(var_ViewDir);
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USE_LIGHTMAP)
|
#if defined(USE_LIGHTMAP)
|
||||||
vec4 lightSample = texture2D(u_LightMap, var_TexCoords.zw).rgba;
|
vec4 lightSample = texture2D(u_LightMap, var_TexCoords.zw);
|
||||||
#if defined(RGBM_LIGHTMAP)
|
|
||||||
lightSample.rgb *= 32.0 * lightSample.a;
|
|
||||||
#endif
|
|
||||||
vec3 lightColor = lightSample.rgb;
|
vec3 lightColor = lightSample.rgb;
|
||||||
|
#if defined(RGBM_LIGHTMAP)
|
||||||
|
lightColor *= 32.0 * lightSample.a;
|
||||||
|
#endif
|
||||||
#elif defined(USE_LIGHT_VECTOR) && !defined(USE_FAST_LIGHT)
|
#elif defined(USE_LIGHT_VECTOR) && !defined(USE_FAST_LIGHT)
|
||||||
vec3 lightColor = u_DirectedLight * CalcLightAttenuation(L, var_LightDir.w);
|
vec3 lightColor = u_DirectedLight * CalcLightAttenuation(float(var_LightDir.w > 0.0), var_LightDir.w / sqrLightDist);
|
||||||
vec3 ambientColor = u_AmbientLight;
|
vec3 ambientColor = u_AmbientLight;
|
||||||
#elif defined(USE_LIGHT_VERTEX) && !defined(USE_FAST_LIGHT)
|
#elif defined(USE_LIGHT_VERTEX) && !defined(USE_FAST_LIGHT)
|
||||||
vec3 lightColor = var_LightColor;
|
vec3 lightColor = var_LightColor;
|
||||||
|
@ -383,20 +379,21 @@ void main()
|
||||||
N.xy = texture2D(u_NormalMap, texCoords).rg - vec2(0.5);
|
N.xy = texture2D(u_NormalMap, texCoords).rg - vec2(0.5);
|
||||||
#endif
|
#endif
|
||||||
N.xy *= u_EnableTextures.x;
|
N.xy *= u_EnableTextures.x;
|
||||||
N.z = sqrt(0.25 - dot(N.xy, N.xy));
|
N.z = sqrt((0.25 - N.x * N.x) - N.y * N.y);
|
||||||
N = normalize(tangentToWorld * N);
|
N = tangentToWorld * N;
|
||||||
#else
|
#else
|
||||||
N = normalize(var_Normal.xyz);
|
N = var_Normal.xyz;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
L = normalize(L);
|
N = normalize(N);
|
||||||
|
L /= sqrt(sqrLightDist);
|
||||||
|
|
||||||
#if defined(USE_SHADOWMAP)
|
#if defined(USE_SHADOWMAP)
|
||||||
vec2 shadowTex = gl_FragCoord.xy * r_FBufScale;
|
vec2 shadowTex = gl_FragCoord.xy * r_FBufScale;
|
||||||
float shadowValue = texture2D(u_ShadowMap, shadowTex).r;
|
float shadowValue = texture2D(u_ShadowMap, shadowTex).r;
|
||||||
|
|
||||||
// surfaces not facing the light are always shadowed
|
// surfaces not facing the light are always shadowed
|
||||||
shadowValue *= step(0.0, dot(var_Normal.xyz, var_PrimaryLightDir.xyz));
|
shadowValue *= float(dot(var_Normal.xyz, var_PrimaryLightDir.xyz) > 0.0);
|
||||||
|
|
||||||
#if defined(SHADOWMAP_MODULATE)
|
#if defined(SHADOWMAP_MODULATE)
|
||||||
//vec3 shadowColor = min(u_PrimaryLightAmbient, lightColor);
|
//vec3 shadowColor = min(u_PrimaryLightAmbient, lightColor);
|
||||||
|
@ -428,14 +425,12 @@ void main()
|
||||||
NL = clamp(dot(N, L), 0.0, 1.0);
|
NL = clamp(dot(N, L), 0.0, 1.0);
|
||||||
NE = clamp(dot(N, E), 0.0, 1.0);
|
NE = clamp(dot(N, E), 0.0, 1.0);
|
||||||
|
|
||||||
|
vec4 specular = vec4(1.0);
|
||||||
#if defined(USE_SPECULARMAP)
|
#if defined(USE_SPECULARMAP)
|
||||||
vec4 specular = texture2D(u_SpecularMap, texCoords);
|
specular += texture2D(u_SpecularMap, texCoords) * u_EnableTextures.z - u_EnableTextures.zzzz;
|
||||||
specular = (specular - vec4(1.0)) * u_EnableTextures.z + vec4(1.0);
|
|
||||||
#if defined(USE_GAMMA2_TEXTURES)
|
#if defined(USE_GAMMA2_TEXTURES)
|
||||||
specular.rgb *= specular.rgb;
|
specular.rgb *= specular.rgb;
|
||||||
#endif
|
#endif
|
||||||
#else
|
|
||||||
vec4 specular = vec4(1.0);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
specular *= u_MaterialInfo.xxxy;
|
specular *= u_MaterialInfo.xxxy;
|
||||||
|
@ -447,14 +442,13 @@ void main()
|
||||||
// diffuse is actually base color, and red of specular is metallicness
|
// diffuse is actually base color, and red of specular is metallicness
|
||||||
float metallic = specular.r;
|
float metallic = specular.r;
|
||||||
|
|
||||||
specular.rgb = vec3(0.04) + 0.96 * diffuse.rgb * metallic;
|
specular.rgb = (0.96 * metallic) * diffuse.rgb + vec3(0.04);
|
||||||
diffuse.rgb *= 1.0 - metallic;
|
diffuse.rgb *= 1.0 - metallic;
|
||||||
#else
|
#else
|
||||||
// adjust diffuse by specular reflectance, to maintain energy conservation
|
// adjust diffuse by specular reflectance, to maintain energy conservation
|
||||||
diffuse.rgb *= vec3(1.0) - specular.rgb;
|
diffuse.rgb *= vec3(1.0) - specular.rgb;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
reflectance = CalcDiffuse(diffuse.rgb, N, L, E, NE, NL, shininess);
|
reflectance = CalcDiffuse(diffuse.rgb, N, L, E, NE, NL, shininess);
|
||||||
|
|
||||||
#if defined(r_deluxeSpecular) || defined(USE_LIGHT_VECTOR)
|
#if defined(r_deluxeSpecular) || defined(USE_LIGHT_VECTOR)
|
||||||
|
@ -501,23 +495,34 @@ void main()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USE_PRIMARY_LIGHT)
|
#if defined(USE_PRIMARY_LIGHT)
|
||||||
L = var_PrimaryLightDir.xyz; //normalize(var_PrimaryLightDir.xyz);
|
vec3 L2, H2;
|
||||||
NL = clamp(dot(N, L), 0.0, 1.0);
|
float NL2, EH2, NH2;
|
||||||
|
|
||||||
H = normalize(L + E);
|
L2 = var_PrimaryLightDir.xyz;
|
||||||
EH = clamp(dot(E, H), 0.0, 1.0);
|
|
||||||
NH = clamp(dot(N, H), 0.0, 1.0);
|
|
||||||
|
|
||||||
reflectance = CalcDiffuse(diffuse.rgb, N, L, E, NE, NL, shininess);
|
// enable when point lights are supported as primary lights
|
||||||
reflectance += CalcSpecular(specular.rgb, NH, NL, NE, EH, gloss, shininess);
|
//sqrLightDist = dot(L2, L2);
|
||||||
|
//L2 /= sqrt(sqrLightDist);
|
||||||
|
|
||||||
lightColor = u_PrimaryLightColor; // * CalcLightAttenuation(L, u_PrimaryLightDir.w);
|
NL2 = clamp(dot(N, L2), 0.0, 1.0);
|
||||||
|
|
||||||
|
H2 = normalize(L2 + E);
|
||||||
|
EH2 = clamp(dot(E, H2), 0.0, 1.0);
|
||||||
|
NH2 = clamp(dot(N, H2), 0.0, 1.0);
|
||||||
|
|
||||||
|
reflectance = CalcDiffuse(diffuse.rgb, N, L2, E, NE, NL2, shininess);
|
||||||
|
reflectance += CalcSpecular(specular.rgb, NH2, NL2, NE, EH2, gloss, shininess);
|
||||||
|
|
||||||
|
lightColor = u_PrimaryLightColor;
|
||||||
|
|
||||||
|
// enable when point lights are supported as primary lights
|
||||||
|
//lightColor *= CalcLightAttenuation(float(u_PrimaryLightDir.w > 0.0), u_PrimaryLightDir.w / sqrLightDist);
|
||||||
|
|
||||||
#if defined(USE_SHADOWMAP)
|
#if defined(USE_SHADOWMAP)
|
||||||
lightColor *= shadowValue;
|
lightColor *= shadowValue;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
gl_FragColor.rgb += lightColor * reflectance * NL;
|
gl_FragColor.rgb += lightColor * reflectance * NL2;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
gl_FragColor.a = diffuse.a;
|
gl_FragColor.a = diffuse.a;
|
||||||
|
|
|
@ -14,8 +14,7 @@ attribute vec4 attr_Tangent;
|
||||||
attribute vec3 attr_Position2;
|
attribute vec3 attr_Position2;
|
||||||
attribute vec3 attr_Normal2;
|
attribute vec3 attr_Normal2;
|
||||||
#if defined(USE_VERT_TANGENT_SPACE)
|
#if defined(USE_VERT_TANGENT_SPACE)
|
||||||
attribute vec3 attr_Tangent2;
|
attribute vec4 attr_Tangent2;
|
||||||
attribute vec3 attr_Bitangent2;
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -108,7 +107,9 @@ vec2 GenTexCoords(int TCGen, vec3 position, vec3 normal, vec3 TCGenVector0, vec3
|
||||||
else if (TCGen == TCGEN_ENVIRONMENT_MAPPED)
|
else if (TCGen == TCGEN_ENVIRONMENT_MAPPED)
|
||||||
{
|
{
|
||||||
vec3 viewer = normalize(u_LocalViewOrigin - position);
|
vec3 viewer = normalize(u_LocalViewOrigin - position);
|
||||||
tex = -reflect(viewer, normal).yz * vec2(0.5, -0.5) + 0.5;
|
vec2 ref = reflect(viewer, normal).yz;
|
||||||
|
tex.s = ref.x * -0.5 + 0.5;
|
||||||
|
tex.t = ref.y * 0.5 + 0.5;
|
||||||
}
|
}
|
||||||
else if (TCGen == TCGEN_VECTOR)
|
else if (TCGen == TCGEN_VECTOR)
|
||||||
{
|
{
|
||||||
|
@ -123,30 +124,25 @@ vec2 GenTexCoords(int TCGen, vec3 position, vec3 normal, vec3 TCGenVector0, vec3
|
||||||
vec2 ModTexCoords(vec2 st, vec3 position, vec4 texMatrix, vec4 offTurb)
|
vec2 ModTexCoords(vec2 st, vec3 position, vec4 texMatrix, vec4 offTurb)
|
||||||
{
|
{
|
||||||
float amplitude = offTurb.z;
|
float amplitude = offTurb.z;
|
||||||
float phase = offTurb.w;
|
float phase = offTurb.w * 2.0 * M_PI;
|
||||||
vec2 st2 = vec2(dot(st, texMatrix.xz), dot(st, texMatrix.yw)) + offTurb.xy;
|
vec2 st2;
|
||||||
|
st2.x = st.x * texMatrix.x + (st.y * texMatrix.z + offTurb.x);
|
||||||
|
st2.y = st.x * texMatrix.y + (st.y * texMatrix.w + offTurb.y);
|
||||||
|
|
||||||
vec3 offsetPos = position / 1024.0;
|
vec2 offsetPos = vec2(position.x + position.z, position.y);
|
||||||
offsetPos.x += offsetPos.z;
|
|
||||||
|
|
||||||
vec2 texOffset = sin((offsetPos.xy + vec2(phase)) * 2.0 * M_PI);
|
vec2 texOffset = sin(offsetPos * (2.0 * M_PI / 1024.0) + vec2(phase));
|
||||||
|
|
||||||
return st2 + texOffset * amplitude;
|
return st2 + texOffset * amplitude;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
float CalcLightAttenuation(vec3 dir, float sqrRadius)
|
float CalcLightAttenuation(float point, float normDist)
|
||||||
{
|
{
|
||||||
// point light at >0 radius, directional otherwise
|
// zero light at 1.0, approximating q3 style
|
||||||
float point = float(sqrRadius > 0.0);
|
|
||||||
|
|
||||||
// inverse square light
|
|
||||||
float attenuation = sqrRadius / dot(dir, dir);
|
|
||||||
|
|
||||||
// zero light at radius, approximating q3 style
|
|
||||||
// also don't attenuate directional light
|
// also don't attenuate directional light
|
||||||
attenuation = (0.5 * attenuation - 1.5) * point + 1.0;
|
float attenuation = (0.5 * normDist - 1.5) * point + 1.0;
|
||||||
|
|
||||||
// clamp attenuation
|
// clamp attenuation
|
||||||
#if defined(NO_LIGHT_CLAMP)
|
#if defined(NO_LIGHT_CLAMP)
|
||||||
|
@ -163,21 +159,21 @@ void main()
|
||||||
{
|
{
|
||||||
#if defined(USE_VERTEX_ANIMATION)
|
#if defined(USE_VERTEX_ANIMATION)
|
||||||
vec3 position = mix(attr_Position, attr_Position2, u_VertexLerp);
|
vec3 position = mix(attr_Position, attr_Position2, u_VertexLerp);
|
||||||
vec3 normal = normalize(mix(attr_Normal, attr_Normal2, u_VertexLerp) * 2.0 - vec3(1.0));
|
vec3 normal = mix(attr_Normal, attr_Normal2, u_VertexLerp);
|
||||||
#if defined(USE_VERT_TANGENT_SPACE) && defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
#if defined(USE_VERT_TANGENT_SPACE) && defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||||
vec3 tangent = normalize(mix(attr_Tangent.xyz, attr_Tangent2.xyz, u_VertexLerp) * 2.0 - vec3(1.0));
|
vec3 tangent = mix(attr_Tangent.xyz, attr_Tangent2.xyz, u_VertexLerp);
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
vec3 position = attr_Position;
|
vec3 position = attr_Position;
|
||||||
vec3 normal = attr_Normal * 2.0 - vec3(1.0);
|
vec3 normal = attr_Normal;
|
||||||
#if defined(USE_VERT_TANGENT_SPACE) && defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
#if defined(USE_VERT_TANGENT_SPACE) && defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||||
vec3 tangent = attr_Tangent.xyz * 2.0 - vec3(1.0);
|
vec3 tangent = attr_Tangent.xyz;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
normal = normal * 2.0 - vec3(1.0);
|
||||||
#if defined(USE_VERT_TANGENT_SPACE) && defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
#if defined(USE_VERT_TANGENT_SPACE) && defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||||
vec3 bitangent = cross(normal, tangent);
|
tangent = tangent * 2.0 - vec3(1.0);
|
||||||
bitangent *= attr_Tangent.w * 2.0 - 1.0;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USE_TCGEN)
|
#if defined(USE_TCGEN)
|
||||||
|
@ -197,15 +193,18 @@ void main()
|
||||||
#if defined(USE_MODELMATRIX)
|
#if defined(USE_MODELMATRIX)
|
||||||
position = (u_ModelMatrix * vec4(position, 1.0)).xyz;
|
position = (u_ModelMatrix * vec4(position, 1.0)).xyz;
|
||||||
normal = (u_ModelMatrix * vec4(normal, 0.0)).xyz;
|
normal = (u_ModelMatrix * vec4(normal, 0.0)).xyz;
|
||||||
#if defined(USE_VERT_TANGENT_SPACE)
|
#if defined(USE_VERT_TANGENT_SPACE) && defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||||
tangent = (u_ModelMatrix * vec4(tangent, 0.0)).xyz;
|
tangent = (u_ModelMatrix * vec4(tangent, 0.0)).xyz;
|
||||||
bitangent = (u_ModelMatrix * vec4(bitangent, 0.0)).xyz;
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(USE_VERT_TANGENT_SPACE) && defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||||
|
vec3 bitangent = cross(normal, tangent) * (attr_Tangent.w * 2.0 - 1.0);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(USE_LIGHT_VECTOR)
|
#if defined(USE_LIGHT_VECTOR)
|
||||||
vec3 L = u_LightOrigin.xyz - (position * u_LightOrigin.w);
|
vec3 L = u_LightOrigin.xyz - (position * u_LightOrigin.w);
|
||||||
#elif defined(USE_LIGHT)
|
#elif defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||||
vec3 L = attr_LightDirection * 2.0 - vec3(1.0);
|
vec3 L = attr_LightDirection * 2.0 - vec3(1.0);
|
||||||
#if defined(USE_MODELMATRIX)
|
#if defined(USE_MODELMATRIX)
|
||||||
L = (u_ModelMatrix * vec4(L, 0.0)).xyz;
|
L = (u_ModelMatrix * vec4(L, 0.0)).xyz;
|
||||||
|
@ -223,10 +222,11 @@ void main()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USE_LIGHT_VECTOR) && defined(USE_FAST_LIGHT)
|
#if defined(USE_LIGHT_VECTOR) && defined(USE_FAST_LIGHT)
|
||||||
float attenuation = CalcLightAttenuation(L, u_LightRadius * u_LightRadius);
|
float sqrLightDist = dot(L, L);
|
||||||
float NL = clamp(dot(normal, normalize(L)), 0.0, 1.0);
|
float attenuation = CalcLightAttenuation(u_LightOrigin.w, u_LightRadius * u_LightRadius / sqrLightDist);
|
||||||
|
float NL = clamp(dot(normalize(normal), L) / sqrt(sqrLightDist), 0.0, 1.0);
|
||||||
|
|
||||||
var_Color.rgb *= u_DirectedLight * attenuation * NL + u_AmbientLight;
|
var_Color.rgb *= u_DirectedLight * (attenuation * NL) + u_AmbientLight;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USE_PRIMARY_LIGHT) || defined(USE_SHADOWMAP)
|
#if defined(USE_PRIMARY_LIGHT) || defined(USE_SHADOWMAP)
|
||||||
|
@ -241,15 +241,12 @@ void main()
|
||||||
var_LightDir = vec4(L, 0.0);
|
var_LightDir = vec4(L, 0.0);
|
||||||
#endif
|
#endif
|
||||||
#if defined(USE_DELUXEMAP)
|
#if defined(USE_DELUXEMAP)
|
||||||
var_LightDir *= 1.0 - u_EnableTextures.y;
|
var_LightDir -= u_EnableTextures.y * var_LightDir;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||||
vec3 viewDir = u_ViewOrigin - position;
|
vec3 viewDir = u_ViewOrigin - position;
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
|
||||||
#if defined(USE_VERT_TANGENT_SPACE)
|
#if defined(USE_VERT_TANGENT_SPACE)
|
||||||
// store view direction in tangent space to save on varyings
|
// store view direction in tangent space to save on varyings
|
||||||
var_Normal = vec4(normal, viewDir.x);
|
var_Normal = vec4(normal, viewDir.x);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
attribute vec4 attr_Position;
|
attribute vec3 attr_Position;
|
||||||
attribute vec3 attr_Normal;
|
attribute vec3 attr_Normal;
|
||||||
|
|
||||||
uniform mat4 u_ModelViewProjectionMatrix;
|
uniform mat4 u_ModelViewProjectionMatrix;
|
||||||
|
@ -8,10 +8,8 @@ varying vec3 var_Normal;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 position = attr_Position;
|
gl_Position = u_ModelViewProjectionMatrix * vec4(attr_Position, 1.0);
|
||||||
|
|
||||||
gl_Position = u_ModelViewProjectionMatrix * position;
|
var_Position = attr_Position;
|
||||||
|
var_Normal = attr_Normal * 2.0 - vec3(1.0);
|
||||||
var_Position = position.xyz;
|
|
||||||
var_Normal = attr_Normal;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
attribute vec4 attr_Position;
|
attribute vec3 attr_Position;
|
||||||
attribute vec3 attr_Normal;
|
attribute vec3 attr_Normal;
|
||||||
attribute vec4 attr_TexCoord0;
|
attribute vec4 attr_TexCoord0;
|
||||||
|
|
||||||
//#if defined(USE_VERTEX_ANIMATION)
|
//#if defined(USE_VERTEX_ANIMATION)
|
||||||
attribute vec4 attr_Position2;
|
attribute vec3 attr_Position2;
|
||||||
attribute vec3 attr_Normal2;
|
attribute vec3 attr_Normal2;
|
||||||
//#endif
|
//#endif
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)
|
||||||
}
|
}
|
||||||
else if (u_DeformGen == DGEN_WAVE_SQUARE)
|
else if (u_DeformGen == DGEN_WAVE_SQUARE)
|
||||||
{
|
{
|
||||||
func = sign(sin(value * 2.0 * M_PI));
|
func = sign(0.5 - fract(value));
|
||||||
}
|
}
|
||||||
else if (u_DeformGen == DGEN_WAVE_TRIANGLE)
|
else if (u_DeformGen == DGEN_WAVE_TRIANGLE)
|
||||||
{
|
{
|
||||||
|
@ -68,7 +68,7 @@ vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)
|
||||||
{
|
{
|
||||||
func = (1.0 - fract(value));
|
func = (1.0 - fract(value));
|
||||||
}
|
}
|
||||||
else if (u_DeformGen == DGEN_BULGE)
|
else // if (u_DeformGen == DGEN_BULGE)
|
||||||
{
|
{
|
||||||
func = sin(value);
|
func = sin(value);
|
||||||
}
|
}
|
||||||
|
@ -78,12 +78,13 @@ vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 position = mix(attr_Position, attr_Position2, u_VertexLerp);
|
vec3 position = mix(attr_Position, attr_Position2, u_VertexLerp);
|
||||||
vec3 normal = normalize(mix(attr_Normal, attr_Normal2, u_VertexLerp));
|
vec3 normal = mix(attr_Normal, attr_Normal2, u_VertexLerp);
|
||||||
|
normal = normalize(normal - vec3(0.5));
|
||||||
|
|
||||||
position.xyz = DeformPosition(position.xyz, normal, attr_TexCoord0.st);
|
position = DeformPosition(position, normal, attr_TexCoord0.st);
|
||||||
|
|
||||||
gl_Position = u_ModelViewProjectionMatrix * position;
|
gl_Position = u_ModelViewProjectionMatrix * vec4(position, 1.0);
|
||||||
|
|
||||||
var_Position = (u_ModelMatrix * position).xyz;
|
var_Position = (u_ModelMatrix * vec4(position, 1.0)).xyz;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#version 120
|
#version 120
|
||||||
|
|
||||||
attribute vec4 attr_Position;
|
attribute vec3 attr_Position;
|
||||||
attribute vec4 attr_TexCoord0;
|
attribute vec4 attr_TexCoord0;
|
||||||
|
|
||||||
uniform mat4 u_ModelViewProjectionMatrix;
|
uniform mat4 u_ModelViewProjectionMatrix;
|
||||||
|
@ -10,6 +10,6 @@ varying vec2 var_Tex1;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = u_ModelViewProjectionMatrix * attr_Position;
|
gl_Position = u_ModelViewProjectionMatrix * vec4(attr_Position, 1.0);
|
||||||
var_Tex1 = attr_TexCoord0.st;
|
var_Tex1 = attr_TexCoord0.st;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
attribute vec4 attr_Position;
|
attribute vec3 attr_Position;
|
||||||
attribute vec4 attr_TexCoord0;
|
attribute vec4 attr_TexCoord0;
|
||||||
|
|
||||||
uniform mat4 u_ModelViewProjectionMatrix;
|
uniform mat4 u_ModelViewProjectionMatrix;
|
||||||
|
@ -8,6 +8,6 @@ varying vec2 var_TexCoords;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = u_ModelViewProjectionMatrix * attr_Position;
|
gl_Position = u_ModelViewProjectionMatrix * vec4(attr_Position, 1.0);
|
||||||
var_TexCoords = attr_TexCoord0.st;
|
var_TexCoords = attr_TexCoord0.st;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue