Oops, fix line endings in new files in previous commit

This commit is contained in:
James Canete 2012-12-04 03:05:34 +00:00
parent edb414b34a
commit 736e1d5170
28 changed files with 1957 additions and 1957 deletions

View file

@ -1,70 +1,70 @@
uniform sampler2D u_TextureMap; uniform sampler2D u_TextureMap;
uniform vec4 u_Color; uniform vec4 u_Color;
uniform vec2 u_InvTexRes; uniform vec2 u_InvTexRes;
varying vec2 var_TexCoords; varying vec2 var_TexCoords;
void main() void main()
{ {
vec4 color; vec4 color;
vec2 tc; vec2 tc;
#if 0 #if 0
float c[7] = float[7](1.0, 0.9659258263, 0.8660254038, 0.7071067812, 0.5, 0.2588190451, 0.0); float c[7] = float[7](1.0, 0.9659258263, 0.8660254038, 0.7071067812, 0.5, 0.2588190451, 0.0);
tc = var_TexCoords + u_InvTexRes * vec2( c[0], c[6]); color = texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( c[0], c[6]); color = texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( c[1], c[5]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( c[1], c[5]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( c[2], c[4]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( c[2], c[4]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( c[3], c[3]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( c[3], c[3]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( c[4], c[2]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( c[4], c[2]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( c[5], c[1]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( c[5], c[1]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( c[6], c[0]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( c[6], c[0]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( c[1], -c[5]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( c[1], -c[5]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( c[2], -c[4]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( c[2], -c[4]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( c[3], -c[3]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( c[3], -c[3]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( c[4], -c[2]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( c[4], -c[2]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( c[5], -c[1]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( c[5], -c[1]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( c[6], -c[0]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( c[6], -c[0]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( -c[0], c[6]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( -c[0], c[6]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( -c[1], c[5]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( -c[1], c[5]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( -c[2], c[4]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( -c[2], c[4]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( -c[3], c[3]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( -c[3], c[3]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( -c[4], c[2]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( -c[4], c[2]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( -c[5], c[1]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( -c[5], c[1]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( -c[1], -c[5]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( -c[1], -c[5]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( -c[2], -c[4]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( -c[2], -c[4]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( -c[3], -c[3]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( -c[3], -c[3]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( -c[4], -c[2]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( -c[4], -c[2]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( -c[5], -c[1]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( -c[5], -c[1]); color += texture2D(u_TextureMap, tc);
gl_FragColor = color * 0.04166667 * u_Color; gl_FragColor = color * 0.04166667 * u_Color;
#endif #endif
float c[5] = float[5](1.0, 0.9238795325, 0.7071067812, 0.3826834324, 0.0); float c[5] = float[5](1.0, 0.9238795325, 0.7071067812, 0.3826834324, 0.0);
tc = var_TexCoords + u_InvTexRes * vec2( c[0], c[4]); color = texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( c[0], c[4]); color = texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( c[1], c[3]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( c[1], c[3]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( c[2], c[2]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( c[2], c[2]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( c[3], c[1]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( c[3], c[1]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( c[4], c[0]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( c[4], c[0]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( c[1], -c[3]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( c[1], -c[3]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( c[2], -c[2]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( c[2], -c[2]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( c[3], -c[1]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( c[3], -c[1]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( c[4], -c[0]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( c[4], -c[0]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( -c[0], c[4]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( -c[0], c[4]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( -c[1], c[3]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( -c[1], c[3]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( -c[2], c[2]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( -c[2], c[2]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( -c[3], c[1]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( -c[3], c[1]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( -c[1], -c[3]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( -c[1], -c[3]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( -c[2], -c[2]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( -c[2], -c[2]); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( -c[3], -c[1]); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( -c[3], -c[1]); color += texture2D(u_TextureMap, tc);
gl_FragColor = color * 0.0625 * u_Color; gl_FragColor = color * 0.0625 * u_Color;
} }

View file

@ -1,13 +1,13 @@
attribute vec4 attr_Position; attribute vec4 attr_Position;
attribute vec4 attr_TexCoord0; attribute vec4 attr_TexCoord0;
uniform mat4 u_ModelViewProjectionMatrix; uniform mat4 u_ModelViewProjectionMatrix;
varying vec2 var_TexCoords; varying vec2 var_TexCoords;
void main() void main()
{ {
gl_Position = u_ModelViewProjectionMatrix * attr_Position; gl_Position = u_ModelViewProjectionMatrix * attr_Position;
var_TexCoords = attr_TexCoord0.st; var_TexCoords = attr_TexCoord0.st;
} }

View file

@ -1,55 +1,55 @@
uniform sampler2D u_TextureMap; uniform sampler2D u_TextureMap;
uniform vec4 u_Color; uniform vec4 u_Color;
uniform vec2 u_InvTexRes; uniform vec2 u_InvTexRes;
varying vec2 var_TexCoords; varying vec2 var_TexCoords;
const vec3 LUMINANCE_VECTOR = vec3(0.2125, 0.7154, 0.0721); //vec3(0.299, 0.587, 0.114); const vec3 LUMINANCE_VECTOR = vec3(0.2125, 0.7154, 0.0721); //vec3(0.299, 0.587, 0.114);
vec3 GetValues(vec2 offset, vec3 current) vec3 GetValues(vec2 offset, vec3 current)
{ {
vec3 minAvgMax; vec3 minAvgMax;
vec2 tc = var_TexCoords + u_InvTexRes * offset; minAvgMax = texture2D(u_TextureMap, tc).rgb; vec2 tc = var_TexCoords + u_InvTexRes * offset; minAvgMax = texture2D(u_TextureMap, tc).rgb;
#ifdef FIRST_PASS #ifdef FIRST_PASS
float lumi = max(dot(LUMINANCE_VECTOR, minAvgMax), 0.000001); float lumi = max(dot(LUMINANCE_VECTOR, minAvgMax), 0.000001);
float loglumi = clamp(log2(lumi), -10.0, 10.0); float loglumi = clamp(log2(lumi), -10.0, 10.0);
minAvgMax = vec3(loglumi * 0.05 + 0.5); minAvgMax = vec3(loglumi * 0.05 + 0.5);
#endif #endif
return vec3(min(current.x, minAvgMax.x), current.y + minAvgMax.y, max(current.z, minAvgMax.z)); return vec3(min(current.x, minAvgMax.x), current.y + minAvgMax.y, max(current.z, minAvgMax.z));
} }
void main() void main()
{ {
vec3 current = vec3(1.0, 0.0, 0.0); vec3 current = vec3(1.0, 0.0, 0.0);
#ifdef FIRST_PASS #ifdef FIRST_PASS
current = GetValues(vec2( 0.0, 0.0), current); current = GetValues(vec2( 0.0, 0.0), current);
#else #else
current = GetValues(vec2(-1.5, -1.5), current); current = GetValues(vec2(-1.5, -1.5), current);
current = GetValues(vec2(-0.5, -1.5), current); current = GetValues(vec2(-0.5, -1.5), current);
current = GetValues(vec2( 0.5, -1.5), current); current = GetValues(vec2( 0.5, -1.5), current);
current = GetValues(vec2( 1.5, -1.5), current); current = GetValues(vec2( 1.5, -1.5), current);
current = GetValues(vec2(-1.5, -0.5), current); current = GetValues(vec2(-1.5, -0.5), current);
current = GetValues(vec2(-0.5, -0.5), current); current = GetValues(vec2(-0.5, -0.5), current);
current = GetValues(vec2( 0.5, -0.5), current); current = GetValues(vec2( 0.5, -0.5), current);
current = GetValues(vec2( 1.5, -0.5), current); current = GetValues(vec2( 1.5, -0.5), current);
current = GetValues(vec2(-1.5, 0.5), current); current = GetValues(vec2(-1.5, 0.5), current);
current = GetValues(vec2(-0.5, 0.5), current); current = GetValues(vec2(-0.5, 0.5), current);
current = GetValues(vec2( 0.5, 0.5), current); current = GetValues(vec2( 0.5, 0.5), current);
current = GetValues(vec2( 1.5, 0.5), current); current = GetValues(vec2( 1.5, 0.5), current);
current = GetValues(vec2(-1.5, 1.5), current); current = GetValues(vec2(-1.5, 1.5), current);
current = GetValues(vec2(-0.5, 1.5), current); current = GetValues(vec2(-0.5, 1.5), current);
current = GetValues(vec2( 0.5, 1.5), current); current = GetValues(vec2( 0.5, 1.5), current);
current = GetValues(vec2( 1.5, 1.5), current); current = GetValues(vec2( 1.5, 1.5), current);
current.y *= 0.0625; current.y *= 0.0625;
#endif #endif
gl_FragColor = vec4(current, 1.0f); gl_FragColor = vec4(current, 1.0f);
} }

View file

@ -1,13 +1,13 @@
attribute vec4 attr_Position; attribute vec4 attr_Position;
attribute vec4 attr_TexCoord0; attribute vec4 attr_TexCoord0;
uniform mat4 u_ModelViewProjectionMatrix; uniform mat4 u_ModelViewProjectionMatrix;
varying vec2 var_TexCoords; varying vec2 var_TexCoords;
void main() void main()
{ {
gl_Position = u_ModelViewProjectionMatrix * attr_Position; gl_Position = u_ModelViewProjectionMatrix * attr_Position;
var_TexCoords = attr_TexCoord0.st; var_TexCoords = attr_TexCoord0.st;
} }

View file

@ -1,58 +1,58 @@
uniform sampler2D u_ScreenImageMap; uniform sampler2D u_ScreenImageMap;
uniform sampler2D u_ScreenDepthMap; uniform sampler2D u_ScreenDepthMap;
uniform vec4 u_ViewInfo; // zfar / znear, zfar uniform vec4 u_ViewInfo; // zfar / znear, zfar
varying vec2 var_ScreenTex; varying vec2 var_ScreenTex;
//float gauss[5] = float[5](0.30, 0.23, 0.097, 0.024, 0.0033); //float gauss[5] = float[5](0.30, 0.23, 0.097, 0.024, 0.0033);
float gauss[4] = float[4](0.40, 0.24, 0.054, 0.0044); float gauss[4] = float[4](0.40, 0.24, 0.054, 0.0044);
//float gauss[3] = float[3](0.60, 0.19, 0.0066); //float gauss[3] = float[3](0.60, 0.19, 0.0066);
#define GAUSS_SIZE 4 #define GAUSS_SIZE 4
float getLinearDepth(sampler2D depthMap, const vec2 tex, const float zFarDivZNear) float getLinearDepth(sampler2D depthMap, const vec2 tex, const float zFarDivZNear)
{ {
float sampleZDivW = texture2D(depthMap, tex).r; float sampleZDivW = texture2D(depthMap, tex).r;
return 1.0 / mix(zFarDivZNear, 1.0, sampleZDivW); return 1.0 / mix(zFarDivZNear, 1.0, sampleZDivW);
} }
vec4 depthGaussian1D(sampler2D imageMap, sampler2D depthMap, vec2 tex, float zFarDivZNear, float zFar) vec4 depthGaussian1D(sampler2D imageMap, sampler2D depthMap, vec2 tex, float zFarDivZNear, float zFar)
{ {
float scale = 1.0 / 256.0; float scale = 1.0 / 256.0;
#if defined(USE_HORIZONTAL_BLUR) #if defined(USE_HORIZONTAL_BLUR)
vec2 direction = vec2(1.0, 0.0) * scale; vec2 direction = vec2(1.0, 0.0) * scale;
#else // if defined(USE_VERTICAL_BLUR) #else // if defined(USE_VERTICAL_BLUR)
vec2 direction = vec2(0.0, 1.0) * scale; vec2 direction = vec2(0.0, 1.0) * scale;
#endif #endif
float depthCenter = zFar * getLinearDepth(depthMap, tex, zFarDivZNear); float depthCenter = zFar * getLinearDepth(depthMap, tex, zFarDivZNear);
vec2 centerSlope = vec2(dFdx(depthCenter), dFdy(depthCenter)) / vec2(dFdx(tex.x), dFdy(tex.y)); vec2 centerSlope = vec2(dFdx(depthCenter), dFdy(depthCenter)) / vec2(dFdx(tex.x), dFdy(tex.y));
vec4 result = texture2D(imageMap, tex) * gauss[0]; vec4 result = texture2D(imageMap, tex) * gauss[0];
float total = gauss[0]; float total = gauss[0];
int i, j; int i, j;
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
{ {
for (j = 1; j < GAUSS_SIZE; j++) for (j = 1; j < GAUSS_SIZE; j++)
{ {
vec2 offset = direction * j; vec2 offset = direction * j;
float depthSample = zFar * getLinearDepth(depthMap, tex + offset, zFarDivZNear); float depthSample = zFar * getLinearDepth(depthMap, tex + offset, zFarDivZNear);
float depthExpected = depthCenter + dot(centerSlope, offset); float depthExpected = depthCenter + dot(centerSlope, offset);
if(abs(depthSample - depthExpected) < 5.0) if(abs(depthSample - depthExpected) < 5.0)
{ {
result += texture2D(imageMap, tex + offset) * gauss[j]; result += texture2D(imageMap, tex + offset) * gauss[j];
total += gauss[j]; total += gauss[j];
} }
} }
direction = -direction; direction = -direction;
} }
return result / total; return result / total;
} }
void main() void main()
{ {
gl_FragColor = depthGaussian1D(u_ScreenImageMap, u_ScreenDepthMap, var_ScreenTex, u_ViewInfo.x, u_ViewInfo.y); gl_FragColor = depthGaussian1D(u_ScreenImageMap, u_ScreenDepthMap, var_ScreenTex, u_ViewInfo.x, u_ViewInfo.y);
} }

View file

@ -1,12 +1,12 @@
attribute vec4 attr_Position; attribute vec4 attr_Position;
attribute vec4 attr_TexCoord0; attribute vec4 attr_TexCoord0;
varying vec2 var_ScreenTex; varying vec2 var_ScreenTex;
void main() void main()
{ {
gl_Position = attr_Position; gl_Position = attr_Position;
var_ScreenTex = attr_TexCoord0.xy; var_ScreenTex = attr_TexCoord0.xy;
//vec2 screenCoords = gl_Position.xy / gl_Position.w; //vec2 screenCoords = gl_Position.xy / gl_Position.w;
//var_ScreenTex = screenCoords * 0.5 + 0.5; //var_ScreenTex = screenCoords * 0.5 + 0.5;
} }

View file

@ -1,12 +1,12 @@
uniform sampler2D u_DiffuseMap; uniform sampler2D u_DiffuseMap;
varying vec2 var_Tex1; varying vec2 var_Tex1;
varying vec4 var_Color; varying vec4 var_Color;
void main() void main()
{ {
vec4 color = texture2D(u_DiffuseMap, var_Tex1); vec4 color = texture2D(u_DiffuseMap, var_Tex1);
gl_FragColor = color * var_Color; gl_FragColor = color * var_Color;
} }

View file

@ -1,92 +1,92 @@
attribute vec4 attr_Position; attribute vec4 attr_Position;
attribute vec4 attr_TexCoord0; attribute vec4 attr_TexCoord0;
attribute vec3 attr_Normal; attribute vec3 attr_Normal;
uniform vec4 u_DlightInfo; uniform vec4 u_DlightInfo;
#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];
uniform float u_Time; uniform float u_Time;
#endif #endif
uniform vec4 u_Color; uniform vec4 u_Color;
uniform mat4 u_ModelViewProjectionMatrix; uniform mat4 u_ModelViewProjectionMatrix;
varying vec2 var_Tex1; varying vec2 var_Tex1;
varying vec4 var_Color; varying vec4 var_Color;
#if defined(USE_DEFORM_VERTEXES) #if defined(USE_DEFORM_VERTEXES)
vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st) vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)
{ {
if (u_DeformGen == 0) if (u_DeformGen == 0)
{ {
return pos; return pos;
} }
float base = u_DeformParams[0]; float base = u_DeformParams[0];
float amplitude = u_DeformParams[1]; float amplitude = u_DeformParams[1];
float phase = u_DeformParams[2]; float phase = u_DeformParams[2];
float frequency = u_DeformParams[3]; float frequency = u_DeformParams[3];
float spread = u_DeformParams[4]; float spread = u_DeformParams[4];
if (u_DeformGen == DGEN_BULGE) if (u_DeformGen == DGEN_BULGE)
{ {
phase *= M_PI * 0.25 * st.x; phase *= M_PI * 0.25 * st.x;
} }
else // if (u_DeformGen <= DGEN_WAVE_INVERSE_SAWTOOTH) else // if (u_DeformGen <= DGEN_WAVE_INVERSE_SAWTOOTH)
{ {
phase += dot(pos.xyz, vec3(spread)); phase += dot(pos.xyz, vec3(spread));
} }
float value = phase + (u_Time * frequency); float value = phase + (u_Time * frequency);
float func; float func;
if (u_DeformGen == DGEN_WAVE_SIN) if (u_DeformGen == DGEN_WAVE_SIN)
{ {
func = sin(value * 2.0 * M_PI); func = sin(value * 2.0 * M_PI);
} }
else if (u_DeformGen == DGEN_WAVE_SQUARE) else if (u_DeformGen == DGEN_WAVE_SQUARE)
{ {
func = sign(sin(value * 2.0 * M_PI)); func = sign(sin(value * 2.0 * M_PI));
} }
else if (u_DeformGen == DGEN_WAVE_TRIANGLE) else if (u_DeformGen == DGEN_WAVE_TRIANGLE)
{ {
func = abs(fract(value + 0.75) - 0.5) * 4.0 - 1.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)
{ {
func = fract(value); func = fract(value);
} }
else if (u_DeformGen == DGEN_WAVE_INVERSE_SAWTOOTH) else if (u_DeformGen == DGEN_WAVE_INVERSE_SAWTOOTH)
{ {
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);
} }
return pos + normal * (base + func * amplitude); return pos + normal * (base + func * amplitude);
} }
#endif #endif
void main() void main()
{ {
vec4 position = attr_Position; vec4 position = attr_Position;
vec3 normal = attr_Normal; vec3 normal = attr_Normal;
#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 * position;
vec3 dist = u_DlightInfo.xyz - position.xyz; vec3 dist = u_DlightInfo.xyz - position.xyz;
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));
dlightmod *= clamp(2.0 * (1.0 - abs(dist.z) * u_DlightInfo.a), 0.0, 1.0); dlightmod *= clamp(2.0 * (1.0 - abs(dist.z) * u_DlightInfo.a), 0.0, 1.0);
var_Color = u_Color * dlightmod; var_Color = u_Color * dlightmod;
} }

View file

@ -1,34 +1,34 @@
uniform sampler2D u_TextureMap; uniform sampler2D u_TextureMap;
uniform vec2 u_InvTexRes; uniform vec2 u_InvTexRes;
varying vec2 var_TexCoords; varying vec2 var_TexCoords;
void main() void main()
{ {
vec4 color; vec4 color;
vec2 tc; vec2 tc;
tc = var_TexCoords + u_InvTexRes * vec2(-1.5, -1.5); color = texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2(-1.5, -1.5); color = texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2(-0.5, -1.5); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2(-0.5, -1.5); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( 0.5, -1.5); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( 0.5, -1.5); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( 1.5, -1.5); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( 1.5, -1.5); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2(-1.5, -0.5); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2(-1.5, -0.5); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2(-0.5, -0.5); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2(-0.5, -0.5); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( 0.5, -0.5); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( 0.5, -0.5); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( 1.5, -0.5); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( 1.5, -0.5); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2(-1.5, 0.5); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2(-1.5, 0.5); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2(-0.5, 0.5); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2(-0.5, 0.5); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( 0.5, 0.5); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( 0.5, 0.5); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( 1.5, 0.5); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( 1.5, 0.5); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2(-1.5, 1.5); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2(-1.5, 1.5); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2(-0.5, 1.5); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2(-0.5, 1.5); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( 0.5, 1.5); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( 0.5, 1.5); color += texture2D(u_TextureMap, tc);
tc = var_TexCoords + u_InvTexRes * vec2( 1.5, 1.5); color += texture2D(u_TextureMap, tc); tc = var_TexCoords + u_InvTexRes * vec2( 1.5, 1.5); color += texture2D(u_TextureMap, tc);
color *= 0.0625; color *= 0.0625;
gl_FragColor = color; gl_FragColor = color;
} }

View file

@ -1,13 +1,13 @@
attribute vec4 attr_Position; attribute vec4 attr_Position;
attribute vec4 attr_TexCoord0; attribute vec4 attr_TexCoord0;
uniform mat4 u_ModelViewProjectionMatrix; uniform mat4 u_ModelViewProjectionMatrix;
varying vec2 var_TexCoords; varying vec2 var_TexCoords;
void main() void main()
{ {
gl_Position = u_ModelViewProjectionMatrix * attr_Position; gl_Position = u_ModelViewProjectionMatrix * attr_Position;
var_TexCoords = attr_TexCoord0.st; var_TexCoords = attr_TexCoord0.st;
} }

View file

@ -1,9 +1,9 @@
uniform vec4 u_Color; uniform vec4 u_Color;
varying float var_Scale; 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));
} }

View file

@ -1,117 +1,117 @@
attribute vec4 attr_Position; attribute vec4 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 vec4 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
varying float var_Scale; varying float var_Scale;
#if defined(USE_DEFORM_VERTEXES) #if defined(USE_DEFORM_VERTEXES)
vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st) vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)
{ {
if (u_DeformGen == 0) if (u_DeformGen == 0)
{ {
return pos; return pos;
} }
float base = u_DeformParams[0]; float base = u_DeformParams[0];
float amplitude = u_DeformParams[1]; float amplitude = u_DeformParams[1];
float phase = u_DeformParams[2]; float phase = u_DeformParams[2];
float frequency = u_DeformParams[3]; float frequency = u_DeformParams[3];
float spread = u_DeformParams[4]; float spread = u_DeformParams[4];
if (u_DeformGen == DGEN_BULGE) if (u_DeformGen == DGEN_BULGE)
{ {
phase *= M_PI * 0.25 * st.x; phase *= M_PI * 0.25 * st.x;
} }
else // if (u_DeformGen <= DGEN_WAVE_INVERSE_SAWTOOTH) else // if (u_DeformGen <= DGEN_WAVE_INVERSE_SAWTOOTH)
{ {
phase += dot(pos.xyz, vec3(spread)); phase += dot(pos.xyz, vec3(spread));
} }
float value = phase + (u_Time * frequency); float value = phase + (u_Time * frequency);
float func; float func;
if (u_DeformGen == DGEN_WAVE_SIN) if (u_DeformGen == DGEN_WAVE_SIN)
{ {
func = sin(value * 2.0 * M_PI); func = sin(value * 2.0 * M_PI);
} }
else if (u_DeformGen == DGEN_WAVE_SQUARE) else if (u_DeformGen == DGEN_WAVE_SQUARE)
{ {
func = sign(sin(value * 2.0 * M_PI)); func = sign(sin(value * 2.0 * M_PI));
} }
else if (u_DeformGen == DGEN_WAVE_TRIANGLE) else if (u_DeformGen == DGEN_WAVE_TRIANGLE)
{ {
func = abs(fract(value + 0.75) - 0.5) * 4.0 - 1.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)
{ {
func = fract(value); func = fract(value);
} }
else if (u_DeformGen == DGEN_WAVE_INVERSE_SAWTOOTH) else if (u_DeformGen == DGEN_WAVE_INVERSE_SAWTOOTH)
{ {
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);
} }
return pos + normal * (base + func * amplitude); return pos + normal * (base + func * amplitude);
} }
#endif #endif
float CalcFog(vec4 position) float CalcFog(vec4 position)
{ {
float s = dot(position, u_FogDistance) * 8.0; float s = dot(position, u_FogDistance) * 8.0;
float t = dot(position, u_FogDepth); float t = dot(position, u_FogDepth);
if (t < 1.0) if (t < 1.0)
{ {
t = step(step(0.0, -u_FogEyeT), t); t = step(step(0.0, -u_FogEyeT), t);
} }
else else
{ {
t /= t - min(u_FogEyeT, 0.0); t /= t - min(u_FogEyeT, 0.0);
} }
return s * t; return s * t;
} }
void main() void main()
{ {
#if defined(USE_VERTEX_ANIMATION) #if defined(USE_VERTEX_ANIMATION)
vec4 position = mix(attr_Position, attr_Position2, u_VertexLerp); vec4 position = mix(attr_Position, attr_Position2, u_VertexLerp);
vec3 normal = normalize(mix(attr_Normal, attr_Normal2, u_VertexLerp)); vec3 normal = normalize(mix(attr_Normal, attr_Normal2, u_VertexLerp));
#else #else
vec4 position = attr_Position; vec4 position = attr_Position;
vec3 normal = attr_Normal; vec3 normal = attr_Normal;
#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 * position;
var_Scale = CalcFog(position); var_Scale = CalcFog(position);
} }

View file

@ -1,43 +1,43 @@
uniform sampler2D u_DiffuseMap; uniform sampler2D u_DiffuseMap;
#if defined(USE_LIGHTMAP) #if defined(USE_LIGHTMAP)
uniform sampler2D u_LightMap; uniform sampler2D u_LightMap;
uniform int u_Texture1Env; uniform int u_Texture1Env;
#endif #endif
varying vec2 var_DiffuseTex; varying vec2 var_DiffuseTex;
#if defined(USE_LIGHTMAP) #if defined(USE_LIGHTMAP)
varying vec2 var_LightTex; varying vec2 var_LightTex;
#endif #endif
varying vec4 var_Color; varying vec4 var_Color;
void main() void main()
{ {
vec4 color = texture2D(u_DiffuseMap, var_DiffuseTex); vec4 color = texture2D(u_DiffuseMap, var_DiffuseTex);
#if defined(USE_LIGHTMAP) #if defined(USE_LIGHTMAP)
vec4 color2 = texture2D(u_LightMap, var_LightTex); vec4 color2 = texture2D(u_LightMap, var_LightTex);
#if defined(RGBE_LIGHTMAP) #if defined(RGBE_LIGHTMAP)
color2.rgb *= exp2(color2.a * 255.0 - 128.0); color2.rgb *= exp2(color2.a * 255.0 - 128.0);
color2.a = 1.0; color2.a = 1.0;
#endif #endif
if (u_Texture1Env == TEXENV_MODULATE) if (u_Texture1Env == TEXENV_MODULATE)
{ {
color *= color2; color *= color2;
} }
else if (u_Texture1Env == TEXENV_ADD) else if (u_Texture1Env == TEXENV_ADD)
{ {
color += color2; color += color2;
} }
else if (u_Texture1Env == TEXENV_REPLACE) else if (u_Texture1Env == TEXENV_REPLACE)
{ {
color = color2; color = color2;
} }
#endif #endif
gl_FragColor = color * var_Color; gl_FragColor = color * var_Color;
} }

View file

@ -1,251 +1,251 @@
attribute vec4 attr_Position; attribute vec4 attr_Position;
attribute vec3 attr_Normal; attribute vec3 attr_Normal;
#if defined(USE_VERTEX_ANIMATION) #if defined(USE_VERTEX_ANIMATION)
attribute vec4 attr_Position2; attribute vec4 attr_Position2;
attribute vec3 attr_Normal2; attribute vec3 attr_Normal2;
#endif #endif
attribute vec4 attr_Color; attribute vec4 attr_Color;
attribute vec4 attr_TexCoord0; attribute vec4 attr_TexCoord0;
#if defined(USE_LIGHTMAP) || defined(USE_TCGEN) #if defined(USE_LIGHTMAP) || defined(USE_TCGEN)
attribute vec4 attr_TexCoord1; attribute vec4 attr_TexCoord1;
#endif #endif
uniform vec4 u_DiffuseTexMatrix; uniform vec4 u_DiffuseTexMatrix;
uniform vec4 u_DiffuseTexOffTurb; uniform vec4 u_DiffuseTexOffTurb;
#if defined(USE_TCGEN) || defined(USE_RGBAGEN) #if defined(USE_TCGEN) || defined(USE_RGBAGEN)
uniform vec3 u_ViewOrigin; uniform vec3 u_ViewOrigin;
#endif #endif
#if defined(USE_TCGEN) #if defined(USE_TCGEN)
uniform int u_TCGen0; uniform int u_TCGen0;
uniform vec3 u_TCGen0Vector0; uniform vec3 u_TCGen0Vector0;
uniform vec3 u_TCGen0Vector1; uniform vec3 u_TCGen0Vector1;
#endif #endif
#if defined(USE_FOG) #if defined(USE_FOG)
uniform vec4 u_FogDistance; uniform vec4 u_FogDistance;
uniform vec4 u_FogDepth; uniform vec4 u_FogDepth;
uniform float u_FogEyeT; uniform float u_FogEyeT;
uniform vec4 u_FogColorMask; uniform vec4 u_FogColorMask;
#endif #endif
#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];
uniform float u_Time; uniform float u_Time;
#endif #endif
uniform mat4 u_ModelViewProjectionMatrix; uniform mat4 u_ModelViewProjectionMatrix;
uniform vec4 u_BaseColor; uniform vec4 u_BaseColor;
uniform vec4 u_VertColor; uniform vec4 u_VertColor;
#if defined(USE_RGBAGEN) #if defined(USE_RGBAGEN)
uniform int u_ColorGen; uniform int u_ColorGen;
uniform int u_AlphaGen; uniform int u_AlphaGen;
uniform vec3 u_AmbientLight; uniform vec3 u_AmbientLight;
uniform vec3 u_DirectedLight; uniform vec3 u_DirectedLight;
uniform vec4 u_LightOrigin; uniform vec4 u_LightOrigin;
uniform float u_PortalRange; uniform float u_PortalRange;
#endif #endif
#if defined(USE_VERTEX_ANIMATION) #if defined(USE_VERTEX_ANIMATION)
uniform float u_VertexLerp; uniform float u_VertexLerp;
#endif #endif
varying vec2 var_DiffuseTex; varying vec2 var_DiffuseTex;
#if defined(USE_LIGHTMAP) #if defined(USE_LIGHTMAP)
varying vec2 var_LightTex; varying vec2 var_LightTex;
#endif #endif
varying vec4 var_Color; varying vec4 var_Color;
#if defined(USE_DEFORM_VERTEXES) #if defined(USE_DEFORM_VERTEXES)
vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st) vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)
{ {
float base = u_DeformParams[0]; float base = u_DeformParams[0];
float amplitude = u_DeformParams[1]; float amplitude = u_DeformParams[1];
float phase = u_DeformParams[2]; float phase = u_DeformParams[2];
float frequency = u_DeformParams[3]; float frequency = u_DeformParams[3];
float spread = u_DeformParams[4]; float spread = u_DeformParams[4];
if (u_DeformGen == DGEN_BULGE) if (u_DeformGen == DGEN_BULGE)
{ {
phase *= M_PI * 0.25 * st.x; phase *= M_PI * 0.25 * st.x;
} }
else // if (u_DeformGen <= DGEN_WAVE_INVERSE_SAWTOOTH) else // if (u_DeformGen <= DGEN_WAVE_INVERSE_SAWTOOTH)
{ {
phase += dot(pos.xyz, vec3(spread)); phase += dot(pos.xyz, vec3(spread));
} }
float value = phase + (u_Time * frequency); float value = phase + (u_Time * frequency);
float func; float func;
if (u_DeformGen == DGEN_WAVE_SIN) if (u_DeformGen == DGEN_WAVE_SIN)
{ {
func = sin(value * 2.0 * M_PI); func = sin(value * 2.0 * M_PI);
} }
else if (u_DeformGen == DGEN_WAVE_SQUARE) else if (u_DeformGen == DGEN_WAVE_SQUARE)
{ {
func = sign(sin(value * 2.0 * M_PI)); func = sign(sin(value * 2.0 * M_PI));
} }
else if (u_DeformGen == DGEN_WAVE_TRIANGLE) else if (u_DeformGen == DGEN_WAVE_TRIANGLE)
{ {
func = abs(fract(value + 0.75) - 0.5) * 4.0 - 1.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)
{ {
func = fract(value); func = fract(value);
} }
else if (u_DeformGen == DGEN_WAVE_INVERSE_SAWTOOTH) else if (u_DeformGen == DGEN_WAVE_INVERSE_SAWTOOTH)
{ {
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);
} }
return pos + normal * (base + func * amplitude); return pos + normal * (base + func * amplitude);
} }
#endif #endif
#if defined(USE_TCGEN) #if defined(USE_TCGEN)
vec2 GenTexCoords(int TCGen, vec3 position, vec3 normal, vec3 TCGenVector0, vec3 TCGenVector1) vec2 GenTexCoords(int TCGen, vec3 position, vec3 normal, vec3 TCGenVector0, vec3 TCGenVector1)
{ {
vec2 tex = attr_TexCoord0.st; vec2 tex = attr_TexCoord0.st;
if (TCGen == TCGEN_LIGHTMAP) if (TCGen == TCGEN_LIGHTMAP)
{ {
tex = attr_TexCoord1.st; tex = attr_TexCoord1.st;
} }
else if (TCGen == TCGEN_ENVIRONMENT_MAPPED) else if (TCGen == TCGEN_ENVIRONMENT_MAPPED)
{ {
vec3 viewer = normalize(u_ViewOrigin - position); vec3 viewer = normalize(u_ViewOrigin - position);
tex = -reflect(viewer, normal).yz * vec2(0.5, -0.5) + 0.5; tex = -reflect(viewer, normal).yz * vec2(0.5, -0.5) + 0.5;
} }
else if (TCGen == TCGEN_VECTOR) else if (TCGen == TCGEN_VECTOR)
{ {
tex = vec2(dot(position, TCGenVector0), dot(position, TCGenVector1)); tex = vec2(dot(position, TCGenVector0), dot(position, TCGenVector1));
} }
return tex; return tex;
} }
#endif #endif
#if defined(USE_TCMOD) #if defined(USE_TCMOD)
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;
vec2 st2 = vec2(dot(st, texMatrix.xz), dot(st, texMatrix.yw)) + offTurb.xy; vec2 st2 = vec2(dot(st, texMatrix.xz), dot(st, texMatrix.yw)) + offTurb.xy;
vec3 offsetPos = position / 1024.0; vec3 offsetPos = position / 1024.0;
offsetPos.x += offsetPos.z; offsetPos.x += offsetPos.z;
vec2 texOffset = sin((offsetPos.xy + vec2(phase)) * 2.0 * M_PI); vec2 texOffset = sin((offsetPos.xy + vec2(phase)) * 2.0 * M_PI);
return st2 + texOffset * amplitude; return st2 + texOffset * amplitude;
} }
#endif #endif
#if defined(USE_RGBAGEN) #if defined(USE_RGBAGEN)
vec4 CalcColor(vec3 position, vec3 normal) vec4 CalcColor(vec3 position, vec3 normal)
{ {
vec4 color = u_VertColor * attr_Color + u_BaseColor; vec4 color = u_VertColor * attr_Color + u_BaseColor;
if (u_ColorGen == CGEN_LIGHTING_DIFFUSE) if (u_ColorGen == CGEN_LIGHTING_DIFFUSE)
{ {
float incoming = clamp(dot(normal, u_LightOrigin.xyz), 0.0, 1.0); float incoming = clamp(dot(normal, u_LightOrigin.xyz), 0.0, 1.0);
color.rgb = clamp(u_DirectedLight * incoming + u_AmbientLight, 0.0, 1.0); color.rgb = clamp(u_DirectedLight * incoming + u_AmbientLight, 0.0, 1.0);
} }
vec3 toView = u_ViewOrigin - position; vec3 toView = u_ViewOrigin - position;
vec3 viewer = normalize(u_ViewOrigin - position); vec3 viewer = normalize(u_ViewOrigin - position);
if (u_AlphaGen == AGEN_LIGHTING_SPECULAR) if (u_AlphaGen == AGEN_LIGHTING_SPECULAR)
{ {
vec3 lightDir = normalize(vec3(-960.0, -1980.0, 96.0) - position.xyz); vec3 lightDir = normalize(vec3(-960.0, -1980.0, 96.0) - position.xyz);
vec3 halfangle = normalize(lightDir + viewer); vec3 halfangle = normalize(lightDir + viewer);
color.a = pow(max(dot(normal, halfangle), 0.0), 8.0); color.a = pow(max(dot(normal, halfangle), 0.0), 8.0);
} }
else if (u_AlphaGen == AGEN_PORTAL) else if (u_AlphaGen == AGEN_PORTAL)
{ {
float alpha = length(toView) / u_PortalRange; float alpha = length(toView) / u_PortalRange;
color.a = clamp(alpha, 0.0, 1.0); color.a = clamp(alpha, 0.0, 1.0);
} }
else if (u_AlphaGen == AGEN_FRESNEL) else if (u_AlphaGen == AGEN_FRESNEL)
{ {
color.a = 0.10 + 0.90 * pow(1.0 - dot(normal, viewer), 5); color.a = 0.10 + 0.90 * pow(1.0 - dot(normal, viewer), 5);
} }
return color; return color;
} }
#endif #endif
#if defined(USE_FOG) #if defined(USE_FOG)
float CalcFog(vec4 position) float CalcFog(vec4 position)
{ {
float s = dot(position, u_FogDistance) * 8.0; float s = dot(position, u_FogDistance) * 8.0;
float t = dot(position, u_FogDepth); float t = dot(position, u_FogDepth);
if (t < 1.0) if (t < 1.0)
{ {
t = step(step(0.0, -u_FogEyeT), t); t = step(step(0.0, -u_FogEyeT), t);
} }
else else
{ {
t /= t - min(u_FogEyeT, 0.0); t /= t - min(u_FogEyeT, 0.0);
} }
return s * t; return s * t;
} }
#endif #endif
void main() void main()
{ {
#if defined(USE_VERTEX_ANIMATION) #if defined(USE_VERTEX_ANIMATION)
vec4 position = mix(attr_Position, attr_Position2, u_VertexLerp); vec4 position = mix(attr_Position, attr_Position2, u_VertexLerp);
vec3 normal = normalize(mix(attr_Normal, attr_Normal2, u_VertexLerp)); vec3 normal = normalize(mix(attr_Normal, attr_Normal2, u_VertexLerp));
#else #else
vec4 position = attr_Position; vec4 position = attr_Position;
vec3 normal = attr_Normal; vec3 normal = attr_Normal;
#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 * position;
#if defined(USE_TCGEN) #if defined(USE_TCGEN)
vec2 tex = GenTexCoords(u_TCGen0, position.xyz, normal, u_TCGen0Vector0, u_TCGen0Vector1); vec2 tex = GenTexCoords(u_TCGen0, position.xyz, normal, u_TCGen0Vector0, u_TCGen0Vector1);
#else #else
vec2 tex = attr_TexCoord0.st; vec2 tex = attr_TexCoord0.st;
#endif #endif
#if defined(USE_TCMOD) #if defined(USE_TCMOD)
var_DiffuseTex = ModTexCoords(tex, position.xyz, u_DiffuseTexMatrix, u_DiffuseTexOffTurb); var_DiffuseTex = ModTexCoords(tex, position.xyz, u_DiffuseTexMatrix, u_DiffuseTexOffTurb);
#else #else
var_DiffuseTex = tex; var_DiffuseTex = tex;
#endif #endif
#if defined(USE_LIGHTMAP) #if defined(USE_LIGHTMAP)
var_LightTex = attr_TexCoord1.st; var_LightTex = attr_TexCoord1.st;
#endif #endif
#if defined(USE_RGBAGEN) #if defined(USE_RGBAGEN)
var_Color = CalcColor(position.xyz, normal); var_Color = CalcColor(position.xyz, normal);
#else #else
var_Color = u_VertColor * attr_Color + u_BaseColor; var_Color = u_VertColor * attr_Color + u_BaseColor;
#endif #endif
#if defined(USE_FOG) #if defined(USE_FOG)
var_Color *= vec4(1.0) - u_FogColorMask * sqrt(clamp(CalcFog(position), 0.0, 1.0)); var_Color *= vec4(1.0) - u_FogColorMask * sqrt(clamp(CalcFog(position), 0.0, 1.0));
#endif #endif
} }

View file

@ -1,360 +1,360 @@
uniform sampler2D u_DiffuseMap; uniform sampler2D u_DiffuseMap;
#if defined(USE_LIGHTMAP) #if defined(USE_LIGHTMAP)
uniform sampler2D u_LightMap; uniform sampler2D u_LightMap;
#endif #endif
#if defined(USE_NORMALMAP) #if defined(USE_NORMALMAP)
uniform sampler2D u_NormalMap; uniform sampler2D u_NormalMap;
#endif #endif
#if defined(USE_DELUXEMAP) #if defined(USE_DELUXEMAP)
uniform sampler2D u_DeluxeMap; uniform sampler2D u_DeluxeMap;
#endif #endif
#if defined(USE_SPECULARMAP) #if defined(USE_SPECULARMAP)
uniform sampler2D u_SpecularMap; uniform sampler2D u_SpecularMap;
#endif #endif
#if defined(USE_SHADOWMAP) #if defined(USE_SHADOWMAP)
uniform sampler2D u_ShadowMap; uniform sampler2D u_ShadowMap;
#endif #endif
uniform vec3 u_ViewOrigin; uniform vec3 u_ViewOrigin;
#if defined(USE_TCGEN) #if defined(USE_TCGEN)
uniform int u_TCGen0; uniform int u_TCGen0;
#endif #endif
#if defined(USE_LIGHT_VECTOR) #if defined(USE_LIGHT_VECTOR)
uniform vec3 u_DirectedLight; uniform vec3 u_DirectedLight;
uniform vec3 u_AmbientLight; uniform vec3 u_AmbientLight;
uniform float u_LightRadius; uniform float u_LightRadius;
#endif #endif
#if defined(USE_LIGHT) #if defined(USE_LIGHT)
uniform vec2 u_MaterialInfo; uniform vec2 u_MaterialInfo;
#endif #endif
varying vec2 var_DiffuseTex; varying vec2 var_DiffuseTex;
#if defined(USE_LIGHTMAP) #if defined(USE_LIGHTMAP)
varying vec2 var_LightTex; varying vec2 var_LightTex;
#endif #endif
varying vec4 var_Color; varying vec4 var_Color;
#if defined(USE_NORMALMAP) && !defined(USE_VERT_TANGENT_SPACE) #if defined(USE_NORMALMAP) && !defined(USE_VERT_TANGENT_SPACE)
varying vec3 var_Position; varying vec3 var_Position;
#endif #endif
varying vec3 var_SampleToView; varying vec3 var_SampleToView;
#if !defined(USE_FAST_LIGHT) #if !defined(USE_FAST_LIGHT)
varying vec3 var_Normal; varying vec3 var_Normal;
#endif #endif
#if defined(USE_VERT_TANGENT_SPACE) #if defined(USE_VERT_TANGENT_SPACE)
varying vec3 var_Tangent; varying vec3 var_Tangent;
varying vec3 var_Bitangent; varying vec3 var_Bitangent;
#endif #endif
varying vec3 var_VertLight; varying vec3 var_VertLight;
#if defined(USE_LIGHT) && !defined(USE_DELUXEMAP) #if defined(USE_LIGHT) && !defined(USE_DELUXEMAP)
varying vec3 var_WorldLight; varying vec3 var_WorldLight;
#endif #endif
#if defined(USE_LIGHT_VECTOR) && !defined(USE_FAST_LIGHT) && defined(USE_SHADOWMAP) #if defined(USE_LIGHT_VECTOR) && !defined(USE_FAST_LIGHT) && defined(USE_SHADOWMAP)
varying vec4 var_ScreenPos; varying vec4 var_ScreenPos;
#endif #endif
#define EPSILON 0.00000001 #define EPSILON 0.00000001
#if defined(USE_PARALLAXMAP) #if defined(USE_PARALLAXMAP)
float SampleHeight(sampler2D normalMap, vec2 t) float SampleHeight(sampler2D normalMap, vec2 t)
{ {
#if defined(SWIZZLE_NORMALMAP) #if defined(SWIZZLE_NORMALMAP)
return texture2D(normalMap, t).r; return texture2D(normalMap, t).r;
#else #else
return texture2D(normalMap, t).a; return texture2D(normalMap, t).a;
#endif #endif
} }
float RayIntersectDisplaceMap(vec2 dp, vec2 ds, sampler2D normalMap) float RayIntersectDisplaceMap(vec2 dp, vec2 ds, sampler2D normalMap)
{ {
const int linearSearchSteps = 16; const int linearSearchSteps = 16;
const int binarySearchSteps = 6; const int binarySearchSteps = 6;
float depthStep = 1.0 / float(linearSearchSteps); float depthStep = 1.0 / float(linearSearchSteps);
// current size of search window // current size of search window
float size = depthStep; float size = depthStep;
// current depth position // current depth position
float depth = 0.0; float depth = 0.0;
// best match found (starts with last position 1.0) // best match found (starts with last position 1.0)
float bestDepth = 1.0; float bestDepth = 1.0;
// search front to back for first point inside object // search front to back for first point inside object
for(int i = 0; i < linearSearchSteps - 1; ++i) for(int i = 0; i < linearSearchSteps - 1; ++i)
{ {
depth += size; depth += size;
float t = 1.0 - SampleHeight(normalMap, dp + ds * depth); float t = 1.0 - SampleHeight(normalMap, dp + ds * depth);
if(bestDepth > 0.996) // if no depth found yet if(bestDepth > 0.996) // if no depth found yet
if(depth >= t) if(depth >= t)
bestDepth = depth; // store best depth bestDepth = depth; // store best depth
} }
depth = bestDepth; depth = bestDepth;
// recurse around first point (depth) for closest match // recurse around first point (depth) for closest match
for(int i = 0; i < binarySearchSteps; ++i) for(int i = 0; i < binarySearchSteps; ++i)
{ {
size *= 0.5; size *= 0.5;
float t = 1.0 - SampleHeight(normalMap, dp + ds * depth); float t = 1.0 - SampleHeight(normalMap, dp + ds * depth);
if(depth >= t) if(depth >= t)
{ {
bestDepth = depth; bestDepth = depth;
depth -= 2.0 * size; depth -= 2.0 * size;
} }
depth += size; depth += size;
} }
return bestDepth; return bestDepth;
} }
#endif #endif
float CalcDiffuse(vec3 N, vec3 L, vec3 E, float NE, float NL, float fzero, float shininess) float CalcDiffuse(vec3 N, vec3 L, vec3 E, float NE, float NL, float fzero, float shininess)
{ {
#if defined(USE_OREN_NAYAR) || defined(USE_TRIACE_OREN_NAYAR) #if defined(USE_OREN_NAYAR) || defined(USE_TRIACE_OREN_NAYAR)
float gamma = dot(E, L) - NE * NL; float gamma = dot(E, L) - NE * NL;
float B = 2.22222 + 0.1 * shininess; float B = 2.22222 + 0.1 * shininess;
#if defined(USE_OREN_NAYAR) #if defined(USE_OREN_NAYAR)
float A = 1.0 - 1.0 / (2.0 + 0.33 * shininess); float A = 1.0 - 1.0 / (2.0 + 0.33 * shininess);
gamma = clamp(gamma, 0.0, 1.0); gamma = clamp(gamma, 0.0, 1.0);
#endif #endif
#if defined(USE_TRIACE_OREN_NAYAR) #if defined(USE_TRIACE_OREN_NAYAR)
float A = 1.0 - 1.0 / (2.0 + 0.65 * shininess); float A = 1.0 - 1.0 / (2.0 + 0.65 * shininess);
if (gamma >= 0.0) if (gamma >= 0.0)
#endif #endif
{ {
B *= max(max(NL, NE), EPSILON); B *= max(max(NL, NE), EPSILON);
} }
return (A + gamma / B) * (1.0 - fzero); return (A + gamma / B) * (1.0 - fzero);
#else #else
return 1.0 - fzero; return 1.0 - fzero;
#endif #endif
} }
#if defined(USE_SPECULARMAP) #if defined(USE_SPECULARMAP)
float CalcSpecular(float NH, float NL, float NE, float EH, float fzero, float shininess) float CalcSpecular(float NH, float NL, float NE, float EH, float fzero, float shininess)
{ {
#if defined(USE_BLINN) || defined(USE_TRIACE) || defined(USE_TORRANCE_SPARROW) #if defined(USE_BLINN) || defined(USE_TRIACE) || defined(USE_TORRANCE_SPARROW)
float blinn = pow(NH, shininess); float blinn = pow(NH, shininess);
#endif #endif
#if defined(USE_BLINN) #if defined(USE_BLINN)
return blinn; return blinn;
#endif #endif
#if defined(USE_COOK_TORRANCE) || defined (USE_TRIACE) || defined (USE_TORRANCE_SPARROW) #if defined(USE_COOK_TORRANCE) || defined (USE_TRIACE) || defined (USE_TORRANCE_SPARROW)
float fresnel = fzero + (1.0 - fzero) * pow(1.0 - EH, 5); float fresnel = fzero + (1.0 - fzero) * pow(1.0 - EH, 5);
#endif #endif
#if defined(USE_COOK_TORRANCE) || defined(USE_TORRANCE_SPARROW) #if defined(USE_COOK_TORRANCE) || defined(USE_TORRANCE_SPARROW)
float geo = 2.0 * NH * min(NE, NL); float geo = 2.0 * NH * min(NE, NL);
geo /= max(EH, geo); geo /= max(EH, geo);
#endif #endif
#if defined(USE_COOK_TORRANCE) #if defined(USE_COOK_TORRANCE)
float m_sq = 2.0 / max(shininess, EPSILON); float m_sq = 2.0 / max(shininess, EPSILON);
float NH_sq = NH * NH; float NH_sq = NH * NH;
float m_NH_sq = m_sq * NH_sq; float m_NH_sq = m_sq * NH_sq;
float beckmann = exp((NH_sq - 1.0) / max(m_NH_sq, EPSILON)) / max(4.0 * m_NH_sq * NH_sq, EPSILON); float beckmann = exp((NH_sq - 1.0) / max(m_NH_sq, EPSILON)) / max(4.0 * m_NH_sq * NH_sq, EPSILON);
return fresnel * geo * beckmann / max(NE, EPSILON); return fresnel * geo * beckmann / max(NE, EPSILON);
#endif #endif
#if defined(USE_TRIACE) #if defined(USE_TRIACE)
float scale = 0.1248582 * shininess + 0.2691817; float scale = 0.1248582 * shininess + 0.2691817;
return fresnel * scale * blinn / max(max(NL, NE), EPSILON); return fresnel * scale * blinn / max(max(NL, NE), EPSILON);
#endif #endif
#if defined(USE_TORRANCE_SPARROW) #if defined(USE_TORRANCE_SPARROW)
float scale = 0.125 * shininess + 1.0; float scale = 0.125 * shininess + 1.0;
return fresnel * geo * scale * blinn / max(NE, EPSILON); return fresnel * geo * scale * blinn / max(NE, EPSILON);
#endif #endif
} }
#endif #endif
void main() void main()
{ {
#if !defined(USE_FAST_LIGHT) && (defined(USE_LIGHT) || defined(USE_NORMALMAP)) #if !defined(USE_FAST_LIGHT) && (defined(USE_LIGHT) || defined(USE_NORMALMAP))
vec3 surfNormal = normalize(var_Normal); vec3 surfNormal = normalize(var_Normal);
#endif #endif
#if defined(USE_DELUXEMAP) #if defined(USE_DELUXEMAP)
vec3 worldLight = 2.0 * texture2D(u_DeluxeMap, var_LightTex).xyz - vec3(1.0); vec3 worldLight = 2.0 * texture2D(u_DeluxeMap, var_LightTex).xyz - vec3(1.0);
//worldLight += var_WorldLight * 0.0001; //worldLight += var_WorldLight * 0.0001;
#elif defined(USE_LIGHT) #elif defined(USE_LIGHT)
vec3 worldLight = var_WorldLight; vec3 worldLight = var_WorldLight;
#endif #endif
#if defined(USE_LIGHTMAP) #if defined(USE_LIGHTMAP)
vec4 lightSample = texture2D(u_LightMap, var_LightTex).rgba; vec4 lightSample = texture2D(u_LightMap, var_LightTex).rgba;
#if defined(RGBE_LIGHTMAP) #if defined(RGBE_LIGHTMAP)
lightSample.rgb *= exp2(lightSample.a * 255.0 - 128.0); lightSample.rgb *= exp2(lightSample.a * 255.0 - 128.0);
#endif #endif
vec3 directedLight = lightSample.rgb; vec3 directedLight = lightSample.rgb;
#elif defined(USE_LIGHT_VECTOR) && !defined(USE_FAST_LIGHT) #elif defined(USE_LIGHT_VECTOR) && !defined(USE_FAST_LIGHT)
#if defined(USE_INVSQRLIGHT) #if defined(USE_INVSQRLIGHT)
float intensity = 1.0 / dot(worldLight, worldLight); float intensity = 1.0 / dot(worldLight, worldLight);
#else #else
float intensity = clamp((1.0 - dot(worldLight, worldLight) / (u_LightRadius * u_LightRadius)) * 1.07, 0.0, 1.0); float intensity = clamp((1.0 - dot(worldLight, worldLight) / (u_LightRadius * u_LightRadius)) * 1.07, 0.0, 1.0);
#endif #endif
vec3 directedLight = u_DirectedLight * intensity; vec3 directedLight = u_DirectedLight * intensity;
vec3 ambientLight = u_AmbientLight; vec3 ambientLight = u_AmbientLight;
#if defined(USE_SHADOWMAP) #if defined(USE_SHADOWMAP)
//vec2 shadowTex = gl_FragCoord.xy * r_FBufScale; //vec2 shadowTex = gl_FragCoord.xy * r_FBufScale;
vec2 shadowTex = var_ScreenPos.xy / var_ScreenPos.w; vec2 shadowTex = var_ScreenPos.xy / var_ScreenPos.w;
directedLight *= texture2D(u_ShadowMap, shadowTex).r; directedLight *= texture2D(u_ShadowMap, shadowTex).r;
#endif #endif
#elif defined(USE_LIGHT_VERTEX) && !defined(USE_FAST_LIGHT) #elif defined(USE_LIGHT_VERTEX) && !defined(USE_FAST_LIGHT)
vec3 directedLight = var_VertLight; vec3 directedLight = var_VertLight;
#endif #endif
#if defined(USE_TCGEN) || defined(USE_NORMALMAP) || (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)) #if defined(USE_TCGEN) || defined(USE_NORMALMAP) || (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT))
vec3 SampleToView = normalize(var_SampleToView); vec3 SampleToView = normalize(var_SampleToView);
#endif #endif
vec2 tex = var_DiffuseTex; vec2 tex = var_DiffuseTex;
float ambientDiff = 1.0; float ambientDiff = 1.0;
#if defined(USE_NORMALMAP) #if defined(USE_NORMALMAP)
#if defined(USE_VERT_TANGENT_SPACE) #if defined(USE_VERT_TANGENT_SPACE)
vec3 tangent = var_Tangent; vec3 tangent = var_Tangent;
vec3 bitangent = var_Bitangent; vec3 bitangent = var_Bitangent;
#else #else
vec3 q0 = dFdx(var_Position); vec3 q0 = dFdx(var_Position);
vec3 q1 = dFdy(var_Position); vec3 q1 = dFdy(var_Position);
vec2 st0 = dFdx(tex); vec2 st0 = dFdx(tex);
vec2 st1 = dFdy(tex); vec2 st1 = dFdy(tex);
float dir = sign(st1.t * st0.s - st0.t * st1.s); float dir = sign(st1.t * st0.s - st0.t * st1.s);
vec3 tangent = normalize( q0 * st1.t - q1 * st0.t) * dir; vec3 tangent = normalize( q0 * st1.t - q1 * st0.t) * dir;
vec3 bitangent = -normalize( q0 * st1.s - q1 * st0.s) * dir; vec3 bitangent = -normalize( q0 * st1.s - q1 * st0.s) * dir;
#endif #endif
mat3 tangentToWorld = mat3(tangent, bitangent, var_Normal); mat3 tangentToWorld = mat3(tangent, bitangent, var_Normal);
#if defined(USE_PARALLAXMAP) #if defined(USE_PARALLAXMAP)
vec3 offsetDir = normalize(SampleToView * tangentToWorld); vec3 offsetDir = normalize(SampleToView * tangentToWorld);
#if 0 #if 0
float height = SampleHeight(u_NormalMap, tex); float height = SampleHeight(u_NormalMap, tex);
float pdist = 0.05 * height - (0.05 / 2.0); float pdist = 0.05 * height - (0.05 / 2.0);
#else #else
offsetDir.xy *= -0.05 / offsetDir.z; offsetDir.xy *= -0.05 / offsetDir.z;
float pdist = RayIntersectDisplaceMap(tex, offsetDir.xy, u_NormalMap); float pdist = RayIntersectDisplaceMap(tex, offsetDir.xy, u_NormalMap);
#endif #endif
tex += offsetDir.xy * pdist; tex += offsetDir.xy * pdist;
#endif #endif
#if defined(SWIZZLE_NORMALMAP) #if defined(SWIZZLE_NORMALMAP)
vec3 normal = 2.0 * texture2D(u_NormalMap, tex).agb - 1.0; vec3 normal = 2.0 * texture2D(u_NormalMap, tex).agb - 1.0;
#else #else
vec3 normal = 2.0 * texture2D(u_NormalMap, tex).rgb - 1.0; vec3 normal = 2.0 * texture2D(u_NormalMap, tex).rgb - 1.0;
#endif #endif
normal.z = sqrt(clamp(1.0 - dot(normal.xy, normal.xy), 0.0, 1.0)); normal.z = sqrt(clamp(1.0 - dot(normal.xy, normal.xy), 0.0, 1.0));
vec3 worldNormal = tangentToWorld * normal; vec3 worldNormal = tangentToWorld * normal;
#if defined(r_normalAmbient) #if defined(r_normalAmbient)
ambientDiff = 0.781341 * normal.z + 0.218659; ambientDiff = 0.781341 * normal.z + 0.218659;
#endif #endif
#elif defined(USE_LIGHT) && !defined(USE_FAST_LIGHT) #elif defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
vec3 worldNormal = surfNormal; vec3 worldNormal = surfNormal;
#endif #endif
#if (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)) || (defined(USE_TCGEN) && defined(USE_NORMALMAP)) #if (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)) || (defined(USE_TCGEN) && defined(USE_NORMALMAP))
worldNormal = normalize(worldNormal); worldNormal = normalize(worldNormal);
#endif #endif
#if defined(USE_TCGEN) && defined(USE_NORMALMAP) #if defined(USE_TCGEN) && defined(USE_NORMALMAP)
if (u_TCGen0 == TCGEN_ENVIRONMENT_MAPPED) if (u_TCGen0 == TCGEN_ENVIRONMENT_MAPPED)
{ {
tex = -reflect(normalize(SampleToView), worldNormal).yz * vec2(0.5, -0.5) + 0.5; tex = -reflect(normalize(SampleToView), worldNormal).yz * vec2(0.5, -0.5) + 0.5;
} }
#endif #endif
vec4 diffuse = texture2D(u_DiffuseMap, tex); vec4 diffuse = texture2D(u_DiffuseMap, tex);
#if defined(USE_LIGHT) && defined(USE_FAST_LIGHT) #if defined(USE_LIGHT) && defined(USE_FAST_LIGHT)
#if defined(USE_LIGHTMAP) #if defined(USE_LIGHTMAP)
diffuse.rgb *= directedLight; diffuse.rgb *= directedLight;
#endif #endif
#elif defined(USE_LIGHT) #elif defined(USE_LIGHT)
worldLight = normalize(worldLight); worldLight = normalize(worldLight);
#if defined(USE_LIGHTMAP) || defined(USE_LIGHT_VERTEX) #if defined(USE_LIGHTMAP) || defined(USE_LIGHT_VERTEX)
#if defined(r_normalAmbient) #if defined(r_normalAmbient)
vec3 ambientLight = directedLight * r_normalAmbient; vec3 ambientLight = directedLight * r_normalAmbient;
directedLight -= ambientLight; directedLight -= ambientLight;
#else #else
vec3 ambientLight = vec3(0.0); vec3 ambientLight = vec3(0.0);
#endif #endif
directedLight /= max(dot(surfNormal, worldLight), 0.004); directedLight /= max(dot(surfNormal, worldLight), 0.004);
#endif #endif
float NL = clamp(dot(worldNormal, worldLight), 0.0, 1.0); float NL = clamp(dot(worldNormal, worldLight), 0.0, 1.0);
float surfNL = clamp(dot(surfNormal, worldLight), 0.0, 1.0); float surfNL = clamp(dot(surfNormal, worldLight), 0.0, 1.0);
NL = min(NL, surfNL * 2.0); NL = min(NL, surfNL * 2.0);
float NE = clamp(dot(worldNormal, SampleToView), 0.0, 1.0); float NE = clamp(dot(worldNormal, SampleToView), 0.0, 1.0);
float fzero = u_MaterialInfo.x; float fzero = u_MaterialInfo.x;
float shininess = u_MaterialInfo.y; float shininess = u_MaterialInfo.y;
#if defined(USE_SPECULARMAP) #if defined(USE_SPECULARMAP)
vec4 specular = texture2D(u_SpecularMap, tex); vec4 specular = texture2D(u_SpecularMap, tex);
//specular.rgb = clamp(specular.rgb - diffuse.rgb, 0.0, 1.0); //specular.rgb = clamp(specular.rgb - diffuse.rgb, 0.0, 1.0);
shininess *= specular.a; shininess *= specular.a;
#endif #endif
float directedDiff = NL * CalcDiffuse(worldNormal, worldLight, SampleToView, NE, NL, fzero, shininess); float directedDiff = NL * CalcDiffuse(worldNormal, worldLight, SampleToView, NE, NL, fzero, shininess);
diffuse.rgb *= directedLight * directedDiff + ambientDiff * ambientLight; diffuse.rgb *= directedLight * directedDiff + ambientDiff * ambientLight;
#if defined(USE_SPECULARMAP) #if defined(USE_SPECULARMAP)
vec3 halfAngle = normalize(worldLight + SampleToView); vec3 halfAngle = normalize(worldLight + SampleToView);
float EH = clamp(dot(SampleToView, halfAngle), 0.0, 1.0); float EH = clamp(dot(SampleToView, halfAngle), 0.0, 1.0);
float NH = clamp(dot(worldNormal, halfAngle), 0.0, 1.0); float NH = clamp(dot(worldNormal, halfAngle), 0.0, 1.0);
float directedSpec = NL * CalcSpecular(NH, NL, NE, EH, fzero, shininess); float directedSpec = NL * CalcSpecular(NH, NL, NE, EH, fzero, shininess);
#if defined(r_normalAmbient) #if defined(r_normalAmbient)
vec3 ambientHalf = normalize(surfNormal + SampleToView); vec3 ambientHalf = normalize(surfNormal + SampleToView);
float ambientSpec = max(dot(ambientHalf, worldNormal) + 0.5, 0.0); float ambientSpec = max(dot(ambientHalf, worldNormal) + 0.5, 0.0);
ambientSpec *= ambientSpec * 0.44; ambientSpec *= ambientSpec * 0.44;
ambientSpec = pow(ambientSpec, shininess) * fzero; ambientSpec = pow(ambientSpec, shininess) * fzero;
specular.rgb *= directedSpec * directedLight + ambientSpec * ambientLight; specular.rgb *= directedSpec * directedLight + ambientSpec * ambientLight;
#else #else
specular.rgb *= directedSpec * directedLight; specular.rgb *= directedSpec * directedLight;
#endif #endif
#endif #endif
#endif #endif
gl_FragColor = diffuse; gl_FragColor = diffuse;
#if defined(USE_SPECULARMAP) && defined(USE_LIGHT) && !defined(USE_FAST_LIGHT) #if defined(USE_SPECULARMAP) && defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
gl_FragColor.rgb += specular.rgb; gl_FragColor.rgb += specular.rgb;
#endif #endif
gl_FragColor *= var_Color; gl_FragColor *= var_Color;
} }

View file

@ -1,227 +1,227 @@
attribute vec4 attr_TexCoord0; attribute vec4 attr_TexCoord0;
#if defined(USE_LIGHTMAP) #if defined(USE_LIGHTMAP)
attribute vec4 attr_TexCoord1; attribute vec4 attr_TexCoord1;
#endif #endif
attribute vec4 attr_Color; attribute vec4 attr_Color;
attribute vec4 attr_Position; attribute vec4 attr_Position;
attribute vec3 attr_Normal; attribute vec3 attr_Normal;
#if defined(USE_VERT_TANGENT_SPACE) #if defined(USE_VERT_TANGENT_SPACE)
attribute vec3 attr_Tangent; attribute vec3 attr_Tangent;
attribute vec3 attr_Bitangent; attribute vec3 attr_Bitangent;
#endif #endif
#if defined(USE_VERTEX_ANIMATION) #if defined(USE_VERTEX_ANIMATION)
attribute vec4 attr_Position2; attribute vec4 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 vec3 attr_Tangent2;
attribute vec3 attr_Bitangent2; attribute vec3 attr_Bitangent2;
#endif #endif
#endif #endif
#if defined(USE_LIGHT) && !defined(USE_LIGHT_VECTOR) #if defined(USE_LIGHT) && !defined(USE_LIGHT_VECTOR)
attribute vec3 attr_LightDirection; attribute vec3 attr_LightDirection;
#endif #endif
#if defined(USE_TCGEN) || defined(USE_NORMALMAP) || defined(USE_LIGHT) && !defined(USE_FAST_LIGHT) #if defined(USE_TCGEN) || defined(USE_NORMALMAP) || defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
uniform vec3 u_ViewOrigin; uniform vec3 u_ViewOrigin;
#endif #endif
#if defined(USE_TCGEN) #if defined(USE_TCGEN)
uniform int u_TCGen0; uniform int u_TCGen0;
#endif #endif
#if defined(USE_TCMOD) #if defined(USE_TCMOD)
uniform vec4 u_DiffuseTexMatrix; uniform vec4 u_DiffuseTexMatrix;
uniform vec4 u_DiffuseTexOffTurb; uniform vec4 u_DiffuseTexOffTurb;
#endif #endif
uniform mat4 u_ModelViewProjectionMatrix; uniform mat4 u_ModelViewProjectionMatrix;
uniform vec4 u_BaseColor; uniform vec4 u_BaseColor;
uniform vec4 u_VertColor; uniform vec4 u_VertColor;
#if defined(USE_MODELMATRIX) #if defined(USE_MODELMATRIX)
uniform mat4 u_ModelMatrix; uniform mat4 u_ModelMatrix;
#endif #endif
#if defined(USE_VERTEX_ANIMATION) #if defined(USE_VERTEX_ANIMATION)
uniform float u_VertexLerp; uniform float u_VertexLerp;
#endif #endif
#if defined(USE_LIGHT_VECTOR) #if defined(USE_LIGHT_VECTOR)
uniform vec4 u_LightOrigin; uniform vec4 u_LightOrigin;
#if defined(USE_FAST_LIGHT) #if defined(USE_FAST_LIGHT)
uniform vec3 u_DirectedLight; uniform vec3 u_DirectedLight;
uniform vec3 u_AmbientLight; uniform vec3 u_AmbientLight;
uniform float u_LightRadius; uniform float u_LightRadius;
#endif #endif
#endif #endif
varying vec2 var_DiffuseTex; varying vec2 var_DiffuseTex;
#if defined(USE_LIGHTMAP) #if defined(USE_LIGHTMAP)
varying vec2 var_LightTex; varying vec2 var_LightTex;
#endif #endif
#if defined(USE_NORMALMAP) || defined(USE_LIGHT) && !defined(USE_FAST_LIGHT) #if defined(USE_NORMALMAP) || defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
varying vec3 var_SampleToView; varying vec3 var_SampleToView;
#endif #endif
varying vec4 var_Color; varying vec4 var_Color;
#if defined(USE_NORMALMAP) && !defined(USE_VERT_TANGENT_SPACE) #if defined(USE_NORMALMAP) && !defined(USE_VERT_TANGENT_SPACE)
varying vec3 var_Position; varying vec3 var_Position;
#endif #endif
#if !defined(USE_FAST_LIGHT) #if !defined(USE_FAST_LIGHT)
varying vec3 var_Normal; varying vec3 var_Normal;
#if defined(USE_VERT_TANGENT_SPACE) #if defined(USE_VERT_TANGENT_SPACE)
varying vec3 var_Tangent; varying vec3 var_Tangent;
varying vec3 var_Bitangent; varying vec3 var_Bitangent;
#endif #endif
#endif #endif
#if defined(USE_LIGHT_VERTEX) && !defined(USE_FAST_LIGHT) #if defined(USE_LIGHT_VERTEX) && !defined(USE_FAST_LIGHT)
varying vec3 var_VertLight; varying vec3 var_VertLight;
#endif #endif
#if defined(USE_LIGHT) && !defined(USE_DELUXEMAP) && !defined(USE_FAST_LIGHT) #if defined(USE_LIGHT) && !defined(USE_DELUXEMAP) && !defined(USE_FAST_LIGHT)
varying vec3 var_WorldLight; varying vec3 var_WorldLight;
#endif #endif
#if defined(USE_LIGHT_VECTOR) && !defined(USE_FAST_LIGHT) && defined(USE_SHADOWMAP) #if defined(USE_LIGHT_VECTOR) && !defined(USE_FAST_LIGHT) && defined(USE_SHADOWMAP)
varying vec4 var_ScreenPos; varying vec4 var_ScreenPos;
#endif #endif
#if defined(USE_TCMOD) #if defined(USE_TCMOD)
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;
vec2 st2 = vec2(dot(st, texMatrix.xz), dot(st, texMatrix.yw)) + offTurb.xy; vec2 st2 = vec2(dot(st, texMatrix.xz), dot(st, texMatrix.yw)) + offTurb.xy;
vec3 offsetPos = position / 1024.0; vec3 offsetPos = position / 1024.0;
offsetPos.x += offsetPos.z; offsetPos.x += offsetPos.z;
vec2 texOffset = sin((offsetPos.xy + vec2(phase)) * 2.0 * M_PI); vec2 texOffset = sin((offsetPos.xy + vec2(phase)) * 2.0 * M_PI);
return st2 + texOffset * amplitude; return st2 + texOffset * amplitude;
} }
#endif #endif
void main() void main()
{ {
#if defined(USE_VERTEX_ANIMATION) #if defined(USE_VERTEX_ANIMATION)
vec4 position = mix(attr_Position, attr_Position2, u_VertexLerp); vec4 position = mix(attr_Position, attr_Position2, u_VertexLerp);
vec3 normal = normalize(mix(attr_Normal, attr_Normal2, u_VertexLerp)); vec3 normal = normalize(mix(attr_Normal, attr_Normal2, u_VertexLerp));
#if defined(USE_VERT_TANGENT_SPACE) #if defined(USE_VERT_TANGENT_SPACE)
vec3 tangent = normalize(mix(attr_Tangent, attr_Tangent2, u_VertexLerp)); vec3 tangent = normalize(mix(attr_Tangent, attr_Tangent2, u_VertexLerp));
vec3 bitangent = normalize(mix(attr_Bitangent, attr_Bitangent2, u_VertexLerp)); vec3 bitangent = normalize(mix(attr_Bitangent, attr_Bitangent2, u_VertexLerp));
#endif #endif
#else #else
vec4 position = attr_Position; vec4 position = attr_Position;
vec3 normal = attr_Normal; vec3 normal = attr_Normal;
#if defined(USE_VERT_TANGENT_SPACE) #if defined(USE_VERT_TANGENT_SPACE)
vec3 tangent = attr_Tangent; vec3 tangent = attr_Tangent;
vec3 bitangent = attr_Bitangent; vec3 bitangent = attr_Bitangent;
#endif #endif
#endif #endif
gl_Position = u_ModelViewProjectionMatrix * position; gl_Position = u_ModelViewProjectionMatrix * position;
#if defined(USE_LIGHT_VECTOR) && !defined(USE_FAST_LIGHT) && defined(USE_SHADOWMAP) #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; var_ScreenPos = gl_Position + vec2(1.0, 0.0).xxyx * gl_Position.w;
#endif #endif
#if (defined(USE_LIGHTMAP) || defined(USE_LIGHT_VERTEX)) && !defined(USE_DELUXEMAP) && !defined(USE_FAST_LIGHT) #if (defined(USE_LIGHTMAP) || defined(USE_LIGHT_VERTEX)) && !defined(USE_DELUXEMAP) && !defined(USE_FAST_LIGHT)
vec3 worldLight = attr_LightDirection; vec3 worldLight = attr_LightDirection;
#endif #endif
#if defined(USE_MODELMATRIX) #if defined(USE_MODELMATRIX)
position = u_ModelMatrix * position; position = u_ModelMatrix * position;
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)
tangent = (u_ModelMatrix * vec4(tangent, 0.0)).xyz; tangent = (u_ModelMatrix * vec4(tangent, 0.0)).xyz;
bitangent = (u_ModelMatrix * vec4(bitangent, 0.0)).xyz; bitangent = (u_ModelMatrix * vec4(bitangent, 0.0)).xyz;
#endif #endif
#if defined(USE_LIGHTMAP) && !defined(USE_DELUXEMAP) && !defined(USE_FAST_LIGHT) #if defined(USE_LIGHTMAP) && !defined(USE_DELUXEMAP) && !defined(USE_FAST_LIGHT)
worldLight = (u_ModelMatrix * vec4(worldLight, 0.0)).xyz; worldLight = (u_ModelMatrix * vec4(worldLight, 0.0)).xyz;
#endif #endif
#endif #endif
#if defined(USE_NORMALMAP) && !defined(USE_VERT_TANGENT_SPACE) #if defined(USE_NORMALMAP) && !defined(USE_VERT_TANGENT_SPACE)
var_Position = position.xyz; var_Position = position.xyz;
#endif #endif
#if defined(USE_TCGEN) || defined(USE_NORMALMAP) || defined(USE_LIGHT) && !defined(USE_FAST_LIGHT) #if defined(USE_TCGEN) || defined(USE_NORMALMAP) || defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
vec3 SampleToView = u_ViewOrigin - position.xyz; vec3 SampleToView = u_ViewOrigin - position.xyz;
#endif #endif
#if defined(USE_NORMALMAP) || defined(USE_LIGHT) && !defined(USE_FAST_LIGHT) #if defined(USE_NORMALMAP) || defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
var_SampleToView = SampleToView; var_SampleToView = SampleToView;
#endif #endif
vec2 tex; vec2 tex;
#if defined(USE_TCGEN) #if defined(USE_TCGEN)
if (u_TCGen0 == TCGEN_ENVIRONMENT_MAPPED) if (u_TCGen0 == TCGEN_ENVIRONMENT_MAPPED)
{ {
tex = -reflect(normalize(SampleToView), normal).yz * vec2(0.5, -0.5) + 0.5; tex = -reflect(normalize(SampleToView), normal).yz * vec2(0.5, -0.5) + 0.5;
} }
else else
#endif #endif
{ {
tex = attr_TexCoord0.st; tex = attr_TexCoord0.st;
} }
#if defined(USE_TCMOD) #if defined(USE_TCMOD)
var_DiffuseTex = ModTexCoords(tex, position.xyz, u_DiffuseTexMatrix, u_DiffuseTexOffTurb); var_DiffuseTex = ModTexCoords(tex, position.xyz, u_DiffuseTexMatrix, u_DiffuseTexOffTurb);
#else #else
var_DiffuseTex = tex; var_DiffuseTex = tex;
#endif #endif
#if defined(USE_LIGHTMAP) #if defined(USE_LIGHTMAP)
var_LightTex = attr_TexCoord1.st; var_LightTex = attr_TexCoord1.st;
#endif #endif
#if !defined(USE_FAST_LIGHT) #if !defined(USE_FAST_LIGHT)
var_Normal = normal; var_Normal = normal;
#if defined(USE_VERT_TANGENT_SPACE) #if defined(USE_VERT_TANGENT_SPACE)
var_Tangent = tangent; var_Tangent = tangent;
var_Bitangent = bitangent; var_Bitangent = bitangent;
#endif #endif
#endif #endif
#if defined(USE_LIGHT) && !defined(USE_DELUXEMAP) #if defined(USE_LIGHT) && !defined(USE_DELUXEMAP)
#if defined(USE_LIGHT_VECTOR) #if defined(USE_LIGHT_VECTOR)
vec3 worldLight = u_LightOrigin.xyz - (position.xyz * u_LightOrigin.w); vec3 worldLight = u_LightOrigin.xyz - (position.xyz * u_LightOrigin.w);
#endif #endif
#if !defined(USE_FAST_LIGHT) #if !defined(USE_FAST_LIGHT)
var_WorldLight = worldLight; var_WorldLight = worldLight;
#endif #endif
#endif #endif
#if defined(USE_LIGHT_VERTEX) && !defined(USE_FAST_LIGHT) #if defined(USE_LIGHT_VERTEX) && !defined(USE_FAST_LIGHT)
var_VertLight = u_VertColor.rgb * attr_Color.rgb; var_VertLight = u_VertColor.rgb * attr_Color.rgb;
var_Color.rgb = vec3(1.0); var_Color.rgb = vec3(1.0);
var_Color.a = u_VertColor.a * attr_Color.a + u_BaseColor.a; var_Color.a = u_VertColor.a * attr_Color.a + u_BaseColor.a;
#else #else
var_Color = u_VertColor * attr_Color + u_BaseColor; var_Color = u_VertColor * attr_Color + u_BaseColor;
#endif #endif
#if defined(USE_LIGHT_VECTOR) && defined(USE_FAST_LIGHT) #if defined(USE_LIGHT_VECTOR) && defined(USE_FAST_LIGHT)
#if defined(USE_INVSQRLIGHT) #if defined(USE_INVSQRLIGHT)
float intensity = 1.0 / dot(worldLight, worldLight); float intensity = 1.0 / dot(worldLight, worldLight);
#else #else
float intensity = clamp((1.0 - dot(worldLight, worldLight) / (u_LightRadius * u_LightRadius)) * 1.07, 0.0, 1.0); float intensity = clamp((1.0 - dot(worldLight, worldLight) / (u_LightRadius * u_LightRadius)) * 1.07, 0.0, 1.0);
#endif #endif
float NL = clamp(dot(normal, normalize(worldLight)), 0.0, 1.0); float NL = clamp(dot(normal, normalize(worldLight)), 0.0, 1.0);
var_Color.rgb *= u_DirectedLight * intensity * NL + u_AmbientLight; var_Color.rgb *= u_DirectedLight * intensity * NL + u_AmbientLight;
#endif #endif
} }

View file

@ -1,98 +1,98 @@
uniform sampler2D u_ShadowMap; uniform sampler2D u_ShadowMap;
uniform vec3 u_LightForward; uniform vec3 u_LightForward;
uniform vec3 u_LightUp; uniform vec3 u_LightUp;
uniform vec3 u_LightRight; uniform vec3 u_LightRight;
uniform vec4 u_LightOrigin; uniform vec4 u_LightOrigin;
uniform float u_LightRadius; uniform float u_LightRadius;
varying vec3 var_Position; varying vec3 var_Position;
varying vec3 var_Normal; varying vec3 var_Normal;
float sampleDistMap(sampler2D texMap, vec2 uv, float scale) float sampleDistMap(sampler2D texMap, vec2 uv, float scale)
{ {
vec3 distv = texture2D(texMap, uv).xyz; vec3 distv = texture2D(texMap, uv).xyz;
return dot(distv, vec3(1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0)) * scale; return dot(distv, vec3(1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0)) * scale;
} }
void main() void main()
{ {
vec3 lightToPos = var_Position - u_LightOrigin.xyz; vec3 lightToPos = var_Position - u_LightOrigin.xyz;
vec2 st = vec2(-dot(u_LightRight, lightToPos), dot(u_LightUp, lightToPos)); vec2 st = vec2(-dot(u_LightRight, lightToPos), dot(u_LightUp, lightToPos));
float fade = length(st); float fade = length(st);
#if defined(USE_DISCARD) #if defined(USE_DISCARD)
if (fade >= 1.0) if (fade >= 1.0)
{ {
discard; discard;
} }
#endif #endif
fade = clamp(8.0 - fade * 8.0, 0.0, 1.0); fade = clamp(8.0 - fade * 8.0, 0.0, 1.0);
st = st * 0.5 + vec2(0.5); st = st * 0.5 + vec2(0.5);
#if defined(USE_SOLID_PSHADOWS) #if defined(USE_SOLID_PSHADOWS)
float intensity = max(sign(u_LightRadius - length(lightToPos)), 0.0); float intensity = max(sign(u_LightRadius - length(lightToPos)), 0.0);
#else #else
float intensity = clamp((1.0 - dot(lightToPos, lightToPos) / (u_LightRadius * u_LightRadius)) * 2.0, 0.0, 1.0); float intensity = clamp((1.0 - dot(lightToPos, lightToPos) / (u_LightRadius * u_LightRadius)) * 2.0, 0.0, 1.0);
#endif #endif
float lightDist = length(lightToPos); float lightDist = length(lightToPos);
float dist; float dist;
#if defined(USE_DISCARD) #if defined(USE_DISCARD)
if (dot(u_LightForward, lightToPos) <= 0.0) if (dot(u_LightForward, lightToPos) <= 0.0)
{ {
discard; discard;
} }
if (dot(var_Normal, lightToPos) > 0.0) if (dot(var_Normal, lightToPos) > 0.0)
{ {
discard; discard;
} }
#else #else
intensity *= max(sign(dot(u_LightForward, lightToPos)), 0.0); intensity *= max(sign(dot(u_LightForward, lightToPos)), 0.0);
intensity *= max(sign(-dot(var_Normal, lightToPos)), 0.0); intensity *= max(sign(-dot(var_Normal, lightToPos)), 0.0);
#endif #endif
intensity *= fade; intensity *= fade;
#if defined(USE_PCF) #if defined(USE_PCF)
float part; float part;
dist = sampleDistMap(u_ShadowMap, st + vec2(-1.0/512.0, -1.0/512.0), u_LightRadius); dist = sampleDistMap(u_ShadowMap, st + vec2(-1.0/512.0, -1.0/512.0), u_LightRadius);
part = max(sign(lightDist - dist), 0.0); part = max(sign(lightDist - dist), 0.0);
dist = sampleDistMap(u_ShadowMap, st + vec2( 1.0/512.0, -1.0/512.0), u_LightRadius); dist = sampleDistMap(u_ShadowMap, st + vec2( 1.0/512.0, -1.0/512.0), u_LightRadius);
part += max(sign(lightDist - dist), 0.0); part += max(sign(lightDist - dist), 0.0);
dist = sampleDistMap(u_ShadowMap, st + vec2(-1.0/512.0, 1.0/512.0), u_LightRadius); dist = sampleDistMap(u_ShadowMap, st + vec2(-1.0/512.0, 1.0/512.0), u_LightRadius);
part += max(sign(lightDist - dist), 0.0); part += max(sign(lightDist - dist), 0.0);
dist = sampleDistMap(u_ShadowMap, st + vec2( 1.0/512.0, 1.0/512.0), u_LightRadius); dist = sampleDistMap(u_ShadowMap, st + vec2( 1.0/512.0, 1.0/512.0), u_LightRadius);
part += max(sign(lightDist - dist), 0.0); part += max(sign(lightDist - dist), 0.0);
#if defined(USE_DISCARD) #if defined(USE_DISCARD)
if (part <= 0.0) if (part <= 0.0)
{ {
discard; discard;
} }
#endif #endif
intensity *= part * 0.25; intensity *= part * 0.25;
#else #else
dist = sampleDistMap(u_ShadowMap, st, u_LightRadius); dist = sampleDistMap(u_ShadowMap, st, u_LightRadius);
#if defined(USE_DISCARD) #if defined(USE_DISCARD)
if (lightDist - dist <= 0.0) if (lightDist - dist <= 0.0)
{ {
discard; discard;
} }
#endif #endif
intensity *= max(sign(lightDist - dist), 0.0); intensity *= max(sign(lightDist - dist), 0.0);
#endif #endif
gl_FragColor.rgb = vec3(0); gl_FragColor.rgb = vec3(0);
gl_FragColor.a = clamp(intensity, 0.0, 0.75); gl_FragColor.a = clamp(intensity, 0.0, 0.75);
} }

View file

@ -1,17 +1,17 @@
attribute vec4 attr_Position; attribute vec4 attr_Position;
attribute vec3 attr_Normal; attribute vec3 attr_Normal;
uniform mat4 u_ModelViewProjectionMatrix; uniform mat4 u_ModelViewProjectionMatrix;
varying vec3 var_Position; varying vec3 var_Position;
varying vec3 var_Normal; varying vec3 var_Normal;
void main() void main()
{ {
vec4 position = attr_Position; vec4 position = attr_Position;
gl_Position = u_ModelViewProjectionMatrix * position; gl_Position = u_ModelViewProjectionMatrix * position;
var_Position = position.xyz; var_Position = position.xyz;
var_Normal = attr_Normal; var_Normal = attr_Normal;
} }

View file

@ -1,41 +1,41 @@
uniform vec4 u_LightOrigin; uniform vec4 u_LightOrigin;
uniform float u_LightRadius; uniform float u_LightRadius;
varying vec3 var_Position; varying vec3 var_Position;
void main() void main()
{ {
#if defined(USE_DEPTH) #if defined(USE_DEPTH)
float depth = length(u_LightOrigin.xyz - var_Position) / u_LightRadius; float depth = length(u_LightOrigin.xyz - var_Position) / u_LightRadius;
#if 0 #if 0
// 32 bit precision // 32 bit precision
const vec4 bitSh = vec4( 256 * 256 * 256, 256 * 256, 256, 1); const vec4 bitSh = vec4( 256 * 256 * 256, 256 * 256, 256, 1);
const vec4 bitMsk = vec4( 0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0); const vec4 bitMsk = vec4( 0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);
vec4 comp; vec4 comp;
comp = depth * bitSh; comp = depth * bitSh;
comp.xyz = fract(comp.xyz); comp.xyz = fract(comp.xyz);
comp -= comp.xxyz * bitMsk; comp -= comp.xxyz * bitMsk;
gl_FragColor = comp; gl_FragColor = comp;
#endif #endif
#if 1 #if 1
// 24 bit precision // 24 bit precision
const vec3 bitSh = vec3( 256 * 256, 256, 1); const vec3 bitSh = vec3( 256 * 256, 256, 1);
const vec3 bitMsk = vec3( 0, 1.0 / 256.0, 1.0 / 256.0); const vec3 bitMsk = vec3( 0, 1.0 / 256.0, 1.0 / 256.0);
vec3 comp; vec3 comp;
comp = depth * bitSh; comp = depth * bitSh;
comp.xy = fract(comp.xy); comp.xy = fract(comp.xy);
comp -= comp.xxy * bitMsk; comp -= comp.xxy * bitMsk;
gl_FragColor = vec4(comp, 1.0); gl_FragColor = vec4(comp, 1.0);
#endif #endif
#if 0 #if 0
// 8 bit precision // 8 bit precision
gl_FragColor = vec4(depth, depth, depth, 1); gl_FragColor = vec4(depth, depth, depth, 1);
#endif #endif
#else #else
gl_FragColor = vec4(0, 0, 0, 1); gl_FragColor = vec4(0, 0, 0, 1);
#endif #endif
} }

View file

@ -1,89 +1,89 @@
attribute vec4 attr_Position; attribute vec4 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 vec4 attr_Position2;
attribute vec3 attr_Normal2; attribute vec3 attr_Normal2;
//#endif //#endif
//#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;
uniform mat4 u_ModelMatrix; uniform mat4 u_ModelMatrix;
//#if defined(USE_VERTEX_ANIMATION) //#if defined(USE_VERTEX_ANIMATION)
uniform float u_VertexLerp; uniform float u_VertexLerp;
//#endif //#endif
varying vec3 var_Position; varying vec3 var_Position;
vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st) vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)
{ {
if (u_DeformGen == 0) if (u_DeformGen == 0)
{ {
return pos; return pos;
} }
float base = u_DeformParams[0]; float base = u_DeformParams[0];
float amplitude = u_DeformParams[1]; float amplitude = u_DeformParams[1];
float phase = u_DeformParams[2]; float phase = u_DeformParams[2];
float frequency = u_DeformParams[3]; float frequency = u_DeformParams[3];
float spread = u_DeformParams[4]; float spread = u_DeformParams[4];
if (u_DeformGen == DGEN_BULGE) if (u_DeformGen == DGEN_BULGE)
{ {
phase *= M_PI * 0.25 * st.x; phase *= M_PI * 0.25 * st.x;
} }
else // if (u_DeformGen <= DGEN_WAVE_INVERSE_SAWTOOTH) else // if (u_DeformGen <= DGEN_WAVE_INVERSE_SAWTOOTH)
{ {
phase += dot(pos.xyz, vec3(spread)); phase += dot(pos.xyz, vec3(spread));
} }
float value = phase + (u_Time * frequency); float value = phase + (u_Time * frequency);
float func; float func;
if (u_DeformGen == DGEN_WAVE_SIN) if (u_DeformGen == DGEN_WAVE_SIN)
{ {
func = sin(value * 2.0 * M_PI); func = sin(value * 2.0 * M_PI);
} }
else if (u_DeformGen == DGEN_WAVE_SQUARE) else if (u_DeformGen == DGEN_WAVE_SQUARE)
{ {
func = sign(sin(value * 2.0 * M_PI)); func = sign(sin(value * 2.0 * M_PI));
} }
else if (u_DeformGen == DGEN_WAVE_TRIANGLE) else if (u_DeformGen == DGEN_WAVE_TRIANGLE)
{ {
func = abs(fract(value + 0.75) - 0.5) * 4.0 - 1.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)
{ {
func = fract(value); func = fract(value);
} }
else if (u_DeformGen == DGEN_WAVE_INVERSE_SAWTOOTH) else if (u_DeformGen == DGEN_WAVE_INVERSE_SAWTOOTH)
{ {
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);
} }
return pos + normal * (base + func * amplitude); return pos + normal * (base + func * amplitude);
} }
void main() void main()
{ {
vec4 position = mix(attr_Position, attr_Position2, u_VertexLerp); vec4 position = mix(attr_Position, attr_Position2, u_VertexLerp);
vec3 normal = normalize(mix(attr_Normal, attr_Normal2, u_VertexLerp)); vec3 normal = normalize(mix(attr_Normal, attr_Normal2, u_VertexLerp));
position.xyz = DeformPosition(position.xyz, normal, attr_TexCoord0.st); position.xyz = DeformPosition(position.xyz, normal, attr_TexCoord0.st);
gl_Position = u_ModelViewProjectionMatrix * position; gl_Position = u_ModelViewProjectionMatrix * position;
var_Position = (u_ModelMatrix * position).xyz; var_Position = (u_ModelMatrix * position).xyz;
} }

View file

@ -1,127 +1,127 @@
uniform sampler2D u_ScreenDepthMap; uniform sampler2D u_ScreenDepthMap;
uniform sampler2D u_ShadowMap; uniform sampler2D u_ShadowMap;
#if defined(USE_SHADOW_CASCADE) #if defined(USE_SHADOW_CASCADE)
uniform sampler2D u_ShadowMap2; uniform sampler2D u_ShadowMap2;
uniform sampler2D u_ShadowMap3; uniform sampler2D u_ShadowMap3;
#endif #endif
uniform mat4 u_ShadowMvp; uniform mat4 u_ShadowMvp;
#if defined(USE_SHADOW_CASCADE) #if defined(USE_SHADOW_CASCADE)
uniform mat4 u_ShadowMvp2; uniform mat4 u_ShadowMvp2;
uniform mat4 u_ShadowMvp3; uniform mat4 u_ShadowMvp3;
#endif #endif
uniform vec3 u_ViewOrigin; uniform vec3 u_ViewOrigin;
uniform vec4 u_ViewInfo; // zfar / znear, zfar uniform vec4 u_ViewInfo; // zfar / znear, zfar
varying vec2 var_ScreenTex; varying vec2 var_ScreenTex;
varying vec3 var_ViewDir; varying vec3 var_ViewDir;
// Input: It uses texture coords as the random number seed. // Input: It uses texture coords as the random number seed.
// Output: Random number: [0,1), that is between 0.0 and 0.999999... inclusive. // Output: Random number: [0,1), that is between 0.0 and 0.999999... inclusive.
// Author: Michael Pohoreski // Author: Michael Pohoreski
// Copyright: Copyleft 2012 :-) // Copyright: Copyleft 2012 :-)
// Source: http://stackoverflow.com/questions/5149544/can-i-generate-a-random-number-inside-a-pixel-shader // Source: http://stackoverflow.com/questions/5149544/can-i-generate-a-random-number-inside-a-pixel-shader
float random( const vec2 p ) float random( const vec2 p )
{ {
// We need irrationals for pseudo randomness. // We need irrationals for pseudo randomness.
// Most (all?) known transcendental numbers will (generally) work. // Most (all?) known transcendental numbers will (generally) work.
const vec2 r = vec2( const vec2 r = vec2(
23.1406926327792690, // e^pi (Gelfond's constant) 23.1406926327792690, // e^pi (Gelfond's constant)
2.6651441426902251); // 2^sqrt(2) (Gelfond-Schneider constant) 2.6651441426902251); // 2^sqrt(2) (Gelfond-Schneider constant)
//return fract( cos( mod( 123456789., 1e-7 + 256. * dot(p,r) ) ) ); //return fract( cos( mod( 123456789., 1e-7 + 256. * dot(p,r) ) ) );
return mod( 123456789., 1e-7 + 256. * dot(p,r) ); return mod( 123456789., 1e-7 + 256. * dot(p,r) );
} }
float PCF(const sampler2D shadowmap, const vec2 st, const float dist) float PCF(const sampler2D shadowmap, const vec2 st, const float dist)
{ {
float mult; float mult;
float scale = 2.0 / r_shadowMapSize; float scale = 2.0 / r_shadowMapSize;
#if defined(USE_SHADOW_FILTER) #if defined(USE_SHADOW_FILTER)
float r = random(var_ScreenTex.xy); float r = random(var_ScreenTex.xy);
float sinr = sin(r) * scale; float sinr = sin(r) * scale;
float cosr = cos(r) * scale; float cosr = cos(r) * scale;
mat2 rmat = mat2(cosr, sinr, -sinr, cosr); mat2 rmat = mat2(cosr, sinr, -sinr, cosr);
mult = step(dist, texture2D(shadowmap, st + rmat * vec2(-0.7055767, 0.196515)).r); mult = step(dist, texture2D(shadowmap, st + rmat * vec2(-0.7055767, 0.196515)).r);
mult += step(dist, texture2D(shadowmap, st + rmat * vec2(0.3524343, -0.7791386)).r); mult += step(dist, texture2D(shadowmap, st + rmat * vec2(0.3524343, -0.7791386)).r);
mult += step(dist, texture2D(shadowmap, st + rmat * vec2(0.2391056, 0.9189604)).r); mult += step(dist, texture2D(shadowmap, st + rmat * vec2(0.2391056, 0.9189604)).r);
#if defined(USE_SHADOW_FILTER2) #if defined(USE_SHADOW_FILTER2)
mult += step(dist, texture2D(shadowmap, st + rmat * vec2(-0.07580382, -0.09224417)).r); mult += step(dist, texture2D(shadowmap, st + rmat * vec2(-0.07580382, -0.09224417)).r);
mult += step(dist, texture2D(shadowmap, st + rmat * vec2(0.5784913, -0.002528916)).r); mult += step(dist, texture2D(shadowmap, st + rmat * vec2(0.5784913, -0.002528916)).r);
mult += step(dist, texture2D(shadowmap, st + rmat * vec2(0.192888, 0.4064181)).r); mult += step(dist, texture2D(shadowmap, st + rmat * vec2(0.192888, 0.4064181)).r);
mult += step(dist, texture2D(shadowmap, st + rmat * vec2(-0.6335801, -0.5247476)).r); mult += step(dist, texture2D(shadowmap, st + rmat * vec2(-0.6335801, -0.5247476)).r);
mult += step(dist, texture2D(shadowmap, st + rmat * vec2(-0.5579782, 0.7491854)).r); mult += step(dist, texture2D(shadowmap, st + rmat * vec2(-0.5579782, 0.7491854)).r);
mult += step(dist, texture2D(shadowmap, st + rmat * vec2(0.7320465, 0.6317794)).r); mult += step(dist, texture2D(shadowmap, st + rmat * vec2(0.7320465, 0.6317794)).r);
mult *= 0.11111; mult *= 0.11111;
#else #else
mult *= 0.33333; mult *= 0.33333;
#endif #endif
#else #else
mult = step(dist, texture2D(shadowmap, st).r); mult = step(dist, texture2D(shadowmap, st).r);
#endif #endif
return mult; return mult;
} }
float getLinearDepth(sampler2D depthMap, vec2 tex, float zFarDivZNear) float getLinearDepth(sampler2D depthMap, vec2 tex, float zFarDivZNear)
{ {
float sampleZDivW = texture2D(depthMap, tex).r; float sampleZDivW = texture2D(depthMap, tex).r;
return 1.0 / mix(zFarDivZNear, 1.0, sampleZDivW); return 1.0 / mix(zFarDivZNear, 1.0, sampleZDivW);
} }
void main() void main()
{ {
float result; float result;
float depth = getLinearDepth(u_ScreenDepthMap, var_ScreenTex, u_ViewInfo.x); float depth = getLinearDepth(u_ScreenDepthMap, var_ScreenTex, u_ViewInfo.x);
float sampleZ = u_ViewInfo.y * depth; float sampleZ = u_ViewInfo.y * depth;
vec4 biasPos = vec4(u_ViewOrigin + var_ViewDir * depth * 0.99, 1.0); vec4 biasPos = vec4(u_ViewOrigin + var_ViewDir * depth * 0.99, 1.0);
vec4 shadowpos = u_ShadowMvp * biasPos; vec4 shadowpos = u_ShadowMvp * biasPos;
#if defined(USE_SHADOW_CASCADE) #if defined(USE_SHADOW_CASCADE)
const float fadeTo = 0.5; const float fadeTo = 0.5;
result = fadeTo; result = fadeTo;
#else #else
result = 0.0; result = 0.0;
#endif #endif
if (all(lessThanEqual(abs(shadowpos.xyz), vec3(abs(shadowpos.w))))) if (all(lessThanEqual(abs(shadowpos.xyz), vec3(abs(shadowpos.w)))))
{ {
shadowpos.xyz = shadowpos.xyz / shadowpos.w * 0.5 + 0.5; shadowpos.xyz = shadowpos.xyz / shadowpos.w * 0.5 + 0.5;
result = PCF(u_ShadowMap, shadowpos.xy, shadowpos.z); result = PCF(u_ShadowMap, shadowpos.xy, shadowpos.z);
} }
#if defined(USE_SHADOW_CASCADE) #if defined(USE_SHADOW_CASCADE)
else else
{ {
shadowpos = u_ShadowMvp2 * biasPos; shadowpos = u_ShadowMvp2 * biasPos;
if (all(lessThanEqual(abs(shadowpos.xyz), vec3(abs(shadowpos.w))))) if (all(lessThanEqual(abs(shadowpos.xyz), vec3(abs(shadowpos.w)))))
{ {
shadowpos.xyz = shadowpos.xyz / shadowpos.w * 0.5 + 0.5; shadowpos.xyz = shadowpos.xyz / shadowpos.w * 0.5 + 0.5;
result = PCF(u_ShadowMap2, shadowpos.xy, shadowpos.z); result = PCF(u_ShadowMap2, shadowpos.xy, shadowpos.z);
} }
else else
{ {
shadowpos = u_ShadowMvp3 * biasPos; shadowpos = u_ShadowMvp3 * biasPos;
if (all(lessThanEqual(abs(shadowpos.xyz), vec3(abs(shadowpos.w))))) if (all(lessThanEqual(abs(shadowpos.xyz), vec3(abs(shadowpos.w)))))
{ {
shadowpos.xyz = shadowpos.xyz / shadowpos.w * 0.5 + 0.5; shadowpos.xyz = shadowpos.xyz / shadowpos.w * 0.5 + 0.5;
result = PCF(u_ShadowMap3, shadowpos.xy, shadowpos.z); result = PCF(u_ShadowMap3, shadowpos.xy, shadowpos.z);
float fade = clamp(sampleZ / r_shadowCascadeZFar * 10.0 - 9.0, 0.0, 1.0); float fade = clamp(sampleZ / r_shadowCascadeZFar * 10.0 - 9.0, 0.0, 1.0);
result = mix(result, fadeTo, fade); result = mix(result, fadeTo, fade);
} }
} }
} }
#endif #endif
gl_FragColor = vec4(vec3(result), 1.0); gl_FragColor = vec4(vec3(result), 1.0);
} }

View file

@ -1,20 +1,20 @@
attribute vec4 attr_Position; attribute vec4 attr_Position;
attribute vec4 attr_TexCoord0; attribute vec4 attr_TexCoord0;
uniform vec3 u_ViewForward; uniform vec3 u_ViewForward;
uniform vec3 u_ViewLeft; uniform vec3 u_ViewLeft;
uniform vec3 u_ViewUp; uniform vec3 u_ViewUp;
uniform vec4 u_ViewInfo; // zfar / znear uniform vec4 u_ViewInfo; // zfar / znear
varying vec2 var_ScreenTex; varying vec2 var_ScreenTex;
varying vec3 var_ViewDir; varying vec3 var_ViewDir;
void main() void main()
{ {
gl_Position = attr_Position; gl_Position = attr_Position;
//vec2 screenCoords = gl_Position.xy / gl_Position.w; //vec2 screenCoords = gl_Position.xy / gl_Position.w;
//var_ScreenTex = screenCoords * 0.5 + 0.5; //var_ScreenTex = screenCoords * 0.5 + 0.5;
var_ScreenTex = attr_TexCoord0.xy; var_ScreenTex = attr_TexCoord0.xy;
vec2 screenCoords = attr_TexCoord0.xy * 2.0 - 1.0; vec2 screenCoords = attr_TexCoord0.xy * 2.0 - 1.0;
var_ViewDir = u_ViewForward + u_ViewLeft * -screenCoords.x + u_ViewUp * screenCoords.y; var_ViewDir = u_ViewForward + u_ViewLeft * -screenCoords.x + u_ViewUp * screenCoords.y;
} }

View file

@ -1,86 +1,86 @@
uniform sampler2D u_ScreenDepthMap; uniform sampler2D u_ScreenDepthMap;
uniform vec4 u_ViewInfo; // zfar / znear, zfar uniform vec4 u_ViewInfo; // zfar / znear, zfar
varying vec2 var_ScreenTex; varying vec2 var_ScreenTex;
vec2 poissonDisc[9] = vec2[9]( vec2 poissonDisc[9] = vec2[9](
vec2(-0.7055767, 0.196515), vec2(0.3524343, -0.7791386), vec2(-0.7055767, 0.196515), vec2(0.3524343, -0.7791386),
vec2(0.2391056, 0.9189604), vec2(-0.07580382, -0.09224417), vec2(0.2391056, 0.9189604), vec2(-0.07580382, -0.09224417),
vec2(0.5784913, -0.002528916), vec2(0.192888, 0.4064181), vec2(0.5784913, -0.002528916), vec2(0.192888, 0.4064181),
vec2(-0.6335801, -0.5247476), vec2(-0.5579782, 0.7491854), vec2(-0.6335801, -0.5247476), vec2(-0.5579782, 0.7491854),
vec2(0.7320465, 0.6317794) vec2(0.7320465, 0.6317794)
); );
// Input: It uses texture coords as the random number seed. // Input: It uses texture coords as the random number seed.
// Output: Random number: [0,1), that is between 0.0 and 0.999999... inclusive. // Output: Random number: [0,1), that is between 0.0 and 0.999999... inclusive.
// Author: Michael Pohoreski // Author: Michael Pohoreski
// Copyright: Copyleft 2012 :-) // Copyright: Copyleft 2012 :-)
// Source: http://stackoverflow.com/questions/5149544/can-i-generate-a-random-number-inside-a-pixel-shader // Source: http://stackoverflow.com/questions/5149544/can-i-generate-a-random-number-inside-a-pixel-shader
float random( const vec2 p ) float random( const vec2 p )
{ {
// We need irrationals for pseudo randomness. // We need irrationals for pseudo randomness.
// Most (all?) known transcendental numbers will (generally) work. // Most (all?) known transcendental numbers will (generally) work.
const vec2 r = vec2( const vec2 r = vec2(
23.1406926327792690, // e^pi (Gelfond's constant) 23.1406926327792690, // e^pi (Gelfond's constant)
2.6651441426902251); // 2^sqrt(2) (Gelfond-Schneider constant) 2.6651441426902251); // 2^sqrt(2) (Gelfond-Schneider constant)
//return fract( cos( mod( 123456789., 1e-7 + 256. * dot(p,r) ) ) ); //return fract( cos( mod( 123456789., 1e-7 + 256. * dot(p,r) ) ) );
return mod( 123456789., 1e-7 + 256. * dot(p,r) ); return mod( 123456789., 1e-7 + 256. * dot(p,r) );
} }
mat2 randomRotation( const vec2 p ) mat2 randomRotation( const vec2 p )
{ {
float r = random(p); float r = random(p);
float sinr = sin(r); float sinr = sin(r);
float cosr = cos(r); float cosr = cos(r);
return mat2(cosr, sinr, -sinr, cosr); return mat2(cosr, sinr, -sinr, cosr);
} }
float getLinearDepth(sampler2D depthMap, const vec2 tex, const float zFarDivZNear) float getLinearDepth(sampler2D depthMap, const vec2 tex, const float zFarDivZNear)
{ {
float sampleZDivW = texture2D(depthMap, tex).r; float sampleZDivW = texture2D(depthMap, tex).r;
return 1.0 / mix(zFarDivZNear, 1.0, sampleZDivW); return 1.0 / mix(zFarDivZNear, 1.0, sampleZDivW);
} }
float ambientOcclusion(sampler2D depthMap, const vec2 tex, const float zFarDivZNear, const float zFar) float ambientOcclusion(sampler2D depthMap, const vec2 tex, const float zFarDivZNear, const float zFar)
{ {
float result = 0; float result = 0;
float sampleZ = zFar * getLinearDepth(depthMap, tex, zFarDivZNear); float sampleZ = zFar * getLinearDepth(depthMap, tex, zFarDivZNear);
vec2 expectedSlope = vec2(dFdx(sampleZ), dFdy(sampleZ)) / vec2(dFdx(tex.x), dFdy(tex.y)); vec2 expectedSlope = vec2(dFdx(sampleZ), dFdy(sampleZ)) / vec2(dFdx(tex.x), dFdy(tex.y));
if (length(expectedSlope) > 5000.0) if (length(expectedSlope) > 5000.0)
return 1.0; return 1.0;
vec2 offsetScale = vec2(3.0 / sampleZ); vec2 offsetScale = vec2(3.0 / sampleZ);
mat2 rmat = randomRotation(tex); mat2 rmat = randomRotation(tex);
int i; int i;
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)
{ {
vec2 offset = rmat * poissonDisc[i] * offsetScale; vec2 offset = rmat * poissonDisc[i] * offsetScale;
float sampleZ2 = zFar * getLinearDepth(depthMap, tex + offset, zFarDivZNear); float sampleZ2 = zFar * getLinearDepth(depthMap, tex + offset, zFarDivZNear);
if (abs(sampleZ - sampleZ2) > 20.0) if (abs(sampleZ - sampleZ2) > 20.0)
result += 1.0; result += 1.0;
else else
{ {
float expectedZ = sampleZ + dot(expectedSlope, offset); float expectedZ = sampleZ + dot(expectedSlope, offset);
result += step(expectedZ - 1.0, sampleZ2); result += step(expectedZ - 1.0, sampleZ2);
} }
} }
result *= 0.33333; result *= 0.33333;
return result; return result;
} }
void main() void main()
{ {
float result = ambientOcclusion(u_ScreenDepthMap, var_ScreenTex, u_ViewInfo.x, u_ViewInfo.y); float result = ambientOcclusion(u_ScreenDepthMap, var_ScreenTex, u_ViewInfo.x, u_ViewInfo.y);
gl_FragColor = vec4(vec3(result), 1.0); gl_FragColor = vec4(vec3(result), 1.0);
} }

View file

@ -1,12 +1,12 @@
attribute vec4 attr_Position; attribute vec4 attr_Position;
attribute vec4 attr_TexCoord0; attribute vec4 attr_TexCoord0;
varying vec2 var_ScreenTex; varying vec2 var_ScreenTex;
void main() void main()
{ {
gl_Position = attr_Position; gl_Position = attr_Position;
var_ScreenTex = attr_TexCoord0.xy; var_ScreenTex = attr_TexCoord0.xy;
//vec2 screenCoords = gl_Position.xy / gl_Position.w; //vec2 screenCoords = gl_Position.xy / gl_Position.w;
//var_ScreenTex = screenCoords * 0.5 + 0.5; //var_ScreenTex = screenCoords * 0.5 + 0.5;
} }

View file

@ -1,12 +1,12 @@
#version 120 #version 120
uniform sampler2D u_DiffuseMap; uniform sampler2D u_DiffuseMap;
uniform vec4 u_Color; uniform vec4 u_Color;
varying vec2 var_Tex1; varying vec2 var_Tex1;
void main() void main()
{ {
gl_FragColor = texture2D(u_DiffuseMap, var_Tex1) * u_Color; gl_FragColor = texture2D(u_DiffuseMap, var_Tex1) * u_Color;
} }

View file

@ -1,15 +1,15 @@
#version 120 #version 120
attribute vec4 attr_Position; attribute vec4 attr_Position;
attribute vec4 attr_TexCoord0; attribute vec4 attr_TexCoord0;
uniform mat4 u_ModelViewProjectionMatrix; uniform mat4 u_ModelViewProjectionMatrix;
varying vec2 var_Tex1; varying vec2 var_Tex1;
void main() void main()
{ {
gl_Position = u_ModelViewProjectionMatrix * attr_Position; gl_Position = u_ModelViewProjectionMatrix * attr_Position;
var_Tex1 = attr_TexCoord0.st; var_Tex1 = attr_TexCoord0.st;
} }

View file

@ -1,48 +1,48 @@
uniform sampler2D u_TextureMap; uniform sampler2D u_TextureMap;
uniform sampler2D u_LevelsMap; uniform sampler2D u_LevelsMap;
uniform vec4 u_Color; uniform vec4 u_Color;
uniform vec2 u_AutoExposureMinMax; uniform vec2 u_AutoExposureMinMax;
uniform vec3 u_ToneMinAvgMaxLinear; uniform vec3 u_ToneMinAvgMaxLinear;
varying vec2 var_TexCoords; varying vec2 var_TexCoords;
const vec3 LUMINANCE_VECTOR = vec3(0.2125, 0.7154, 0.0721); //vec3(0.299, 0.587, 0.114); const vec3 LUMINANCE_VECTOR = vec3(0.2125, 0.7154, 0.0721); //vec3(0.299, 0.587, 0.114);
vec3 FilmicTonemap(vec3 x) vec3 FilmicTonemap(vec3 x)
{ {
const float SS = 0.22; // Shoulder Strength const float SS = 0.22; // Shoulder Strength
const float LS = 0.30; // Linear Strength const float LS = 0.30; // Linear Strength
const float LA = 0.10; // Linear Angle const float LA = 0.10; // Linear Angle
const float TS = 0.20; // Toe Strength const float TS = 0.20; // Toe Strength
const float TAN = 0.01; // Toe Angle Numerator const float TAN = 0.01; // Toe Angle Numerator
const float TAD = 0.30; // Toe Angle Denominator const float TAD = 0.30; // Toe Angle Denominator
vec3 SSxx = SS * x * x; vec3 SSxx = SS * x * x;
vec3 LSx = LS * x; vec3 LSx = LS * x;
vec3 LALSx = LSx * LA; vec3 LALSx = LSx * LA;
return ((SSxx + LALSx + TS * TAN) / (SSxx + LSx + TS * TAD)) - TAN / TAD; return ((SSxx + LALSx + TS * TAN) / (SSxx + LSx + TS * TAD)) - TAN / TAD;
//return ((x*(SS*x+LA*LS)+TS*TAN)/(x*(SS*x+LS)+TS*TAD)) - TAN/TAD; //return ((x*(SS*x+LA*LS)+TS*TAN)/(x*(SS*x+LS)+TS*TAD)) - TAN/TAD;
} }
void main() void main()
{ {
vec4 color = texture2D(u_TextureMap, var_TexCoords) * u_Color; vec4 color = texture2D(u_TextureMap, var_TexCoords) * u_Color;
vec3 minAvgMax = texture2D(u_LevelsMap, var_TexCoords).rgb; vec3 minAvgMax = texture2D(u_LevelsMap, var_TexCoords).rgb;
vec3 logMinAvgMaxLum = clamp(minAvgMax * 20.0 - 10.0, -u_AutoExposureMinMax.y, -u_AutoExposureMinMax.x); vec3 logMinAvgMaxLum = clamp(minAvgMax * 20.0 - 10.0, -u_AutoExposureMinMax.y, -u_AutoExposureMinMax.x);
float avgLum = exp2(logMinAvgMaxLum.y); float avgLum = exp2(logMinAvgMaxLum.y);
//float maxLum = exp2(logMinAvgMaxLum.z); //float maxLum = exp2(logMinAvgMaxLum.z);
color.rgb *= u_ToneMinAvgMaxLinear.y / avgLum; color.rgb *= u_ToneMinAvgMaxLinear.y / avgLum;
color.rgb = max(vec3(0.0), color.rgb - vec3(u_ToneMinAvgMaxLinear.x)); color.rgb = max(vec3(0.0), color.rgb - vec3(u_ToneMinAvgMaxLinear.x));
vec3 fWhite = 1.0 / FilmicTonemap(vec3(u_ToneMinAvgMaxLinear.z - u_ToneMinAvgMaxLinear.x)); vec3 fWhite = 1.0 / FilmicTonemap(vec3(u_ToneMinAvgMaxLinear.z - u_ToneMinAvgMaxLinear.x));
color.rgb = FilmicTonemap(color.rgb) * fWhite; color.rgb = FilmicTonemap(color.rgb) * fWhite;
gl_FragColor = clamp(color, 0.0, 1.0); gl_FragColor = clamp(color, 0.0, 1.0);
} }

View file

@ -1,13 +1,13 @@
attribute vec4 attr_Position; attribute vec4 attr_Position;
attribute vec4 attr_TexCoord0; attribute vec4 attr_TexCoord0;
uniform mat4 u_ModelViewProjectionMatrix; uniform mat4 u_ModelViewProjectionMatrix;
varying vec2 var_TexCoords; varying vec2 var_TexCoords;
void main() void main()
{ {
gl_Position = u_ModelViewProjectionMatrix * attr_Position; gl_Position = u_ModelViewProjectionMatrix * attr_Position;
var_TexCoords = attr_TexCoord0.st; var_TexCoords = attr_TexCoord0.st;
} }