mirror of
https://github.com/ReactionQuake3/reaction.git
synced 2024-11-25 05:31:21 +00:00
IOQ3 commit 2371
This commit is contained in:
parent
549d2e26a7
commit
5bd81b560c
28 changed files with 1957 additions and 1957 deletions
|
@ -1,70 +1,70 @@
|
|||
uniform sampler2D u_TextureMap;
|
||||
|
||||
uniform vec4 u_Color;
|
||||
|
||||
uniform vec2 u_InvTexRes;
|
||||
varying vec2 var_TexCoords;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color;
|
||||
vec2 tc;
|
||||
|
||||
#if 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[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[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[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[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[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[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[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[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[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[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[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[5], -c[1]); color += texture2D(u_TextureMap, tc);
|
||||
|
||||
gl_FragColor = color * 0.04166667 * u_Color;
|
||||
#endif
|
||||
|
||||
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[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[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[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[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[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[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[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[3], -c[1]); color += texture2D(u_TextureMap, tc);
|
||||
|
||||
gl_FragColor = color * 0.0625 * u_Color;
|
||||
}
|
||||
uniform sampler2D u_TextureMap;
|
||||
|
||||
uniform vec4 u_Color;
|
||||
|
||||
uniform vec2 u_InvTexRes;
|
||||
varying vec2 var_TexCoords;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color;
|
||||
vec2 tc;
|
||||
|
||||
#if 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[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[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[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[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[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[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[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[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[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[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[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[5], -c[1]); color += texture2D(u_TextureMap, tc);
|
||||
|
||||
gl_FragColor = color * 0.04166667 * u_Color;
|
||||
#endif
|
||||
|
||||
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[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[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[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[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[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[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[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[3], -c[1]); color += texture2D(u_TextureMap, tc);
|
||||
|
||||
gl_FragColor = color * 0.0625 * u_Color;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
attribute vec4 attr_Position;
|
||||
attribute vec4 attr_TexCoord0;
|
||||
|
||||
uniform mat4 u_ModelViewProjectionMatrix;
|
||||
|
||||
varying vec2 var_TexCoords;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = u_ModelViewProjectionMatrix * attr_Position;
|
||||
var_TexCoords = attr_TexCoord0.st;
|
||||
}
|
||||
attribute vec4 attr_Position;
|
||||
attribute vec4 attr_TexCoord0;
|
||||
|
||||
uniform mat4 u_ModelViewProjectionMatrix;
|
||||
|
||||
varying vec2 var_TexCoords;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = u_ModelViewProjectionMatrix * attr_Position;
|
||||
var_TexCoords = attr_TexCoord0.st;
|
||||
}
|
||||
|
|
|
@ -1,55 +1,55 @@
|
|||
uniform sampler2D u_TextureMap;
|
||||
|
||||
uniform vec4 u_Color;
|
||||
|
||||
uniform vec2 u_InvTexRes;
|
||||
varying vec2 var_TexCoords;
|
||||
|
||||
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 minAvgMax;
|
||||
vec2 tc = var_TexCoords + u_InvTexRes * offset; minAvgMax = texture2D(u_TextureMap, tc).rgb;
|
||||
|
||||
#ifdef FIRST_PASS
|
||||
float lumi = max(dot(LUMINANCE_VECTOR, minAvgMax), 0.000001);
|
||||
float loglumi = clamp(log2(lumi), -10.0, 10.0);
|
||||
minAvgMax = vec3(loglumi * 0.05 + 0.5);
|
||||
#endif
|
||||
|
||||
return vec3(min(current.x, minAvgMax.x), current.y + minAvgMax.y, max(current.z, minAvgMax.z));
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 current = vec3(1.0, 0.0, 0.0);
|
||||
|
||||
#ifdef FIRST_PASS
|
||||
current = GetValues(vec2( 0.0, 0.0), current);
|
||||
#else
|
||||
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( 1.5, -1.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( 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( 1.5, 0.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( 1.5, 1.5), current);
|
||||
|
||||
current.y *= 0.0625;
|
||||
#endif
|
||||
|
||||
gl_FragColor = vec4(current, 1.0f);
|
||||
}
|
||||
uniform sampler2D u_TextureMap;
|
||||
|
||||
uniform vec4 u_Color;
|
||||
|
||||
uniform vec2 u_InvTexRes;
|
||||
varying vec2 var_TexCoords;
|
||||
|
||||
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 minAvgMax;
|
||||
vec2 tc = var_TexCoords + u_InvTexRes * offset; minAvgMax = texture2D(u_TextureMap, tc).rgb;
|
||||
|
||||
#ifdef FIRST_PASS
|
||||
float lumi = max(dot(LUMINANCE_VECTOR, minAvgMax), 0.000001);
|
||||
float loglumi = clamp(log2(lumi), -10.0, 10.0);
|
||||
minAvgMax = vec3(loglumi * 0.05 + 0.5);
|
||||
#endif
|
||||
|
||||
return vec3(min(current.x, minAvgMax.x), current.y + minAvgMax.y, max(current.z, minAvgMax.z));
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 current = vec3(1.0, 0.0, 0.0);
|
||||
|
||||
#ifdef FIRST_PASS
|
||||
current = GetValues(vec2( 0.0, 0.0), current);
|
||||
#else
|
||||
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( 1.5, -1.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( 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( 1.5, 0.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( 1.5, 1.5), current);
|
||||
|
||||
current.y *= 0.0625;
|
||||
#endif
|
||||
|
||||
gl_FragColor = vec4(current, 1.0f);
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
attribute vec4 attr_Position;
|
||||
attribute vec4 attr_TexCoord0;
|
||||
|
||||
uniform mat4 u_ModelViewProjectionMatrix;
|
||||
|
||||
varying vec2 var_TexCoords;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = u_ModelViewProjectionMatrix * attr_Position;
|
||||
var_TexCoords = attr_TexCoord0.st;
|
||||
}
|
||||
attribute vec4 attr_Position;
|
||||
attribute vec4 attr_TexCoord0;
|
||||
|
||||
uniform mat4 u_ModelViewProjectionMatrix;
|
||||
|
||||
varying vec2 var_TexCoords;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = u_ModelViewProjectionMatrix * attr_Position;
|
||||
var_TexCoords = attr_TexCoord0.st;
|
||||
}
|
||||
|
|
|
@ -1,58 +1,58 @@
|
|||
uniform sampler2D u_ScreenImageMap;
|
||||
uniform sampler2D u_ScreenDepthMap;
|
||||
|
||||
uniform vec4 u_ViewInfo; // zfar / znear, zfar
|
||||
varying vec2 var_ScreenTex;
|
||||
|
||||
//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[3] = float[3](0.60, 0.19, 0.0066);
|
||||
#define GAUSS_SIZE 4
|
||||
|
||||
float getLinearDepth(sampler2D depthMap, const vec2 tex, const float zFarDivZNear)
|
||||
{
|
||||
float sampleZDivW = texture2D(depthMap, tex).r;
|
||||
return 1.0 / mix(zFarDivZNear, 1.0, sampleZDivW);
|
||||
}
|
||||
|
||||
vec4 depthGaussian1D(sampler2D imageMap, sampler2D depthMap, vec2 tex, float zFarDivZNear, float zFar)
|
||||
{
|
||||
float scale = 1.0 / 256.0;
|
||||
|
||||
#if defined(USE_HORIZONTAL_BLUR)
|
||||
vec2 direction = vec2(1.0, 0.0) * scale;
|
||||
#else // if defined(USE_VERTICAL_BLUR)
|
||||
vec2 direction = vec2(0.0, 1.0) * scale;
|
||||
#endif
|
||||
|
||||
float depthCenter = zFar * getLinearDepth(depthMap, tex, zFarDivZNear);
|
||||
vec2 centerSlope = vec2(dFdx(depthCenter), dFdy(depthCenter)) / vec2(dFdx(tex.x), dFdy(tex.y));
|
||||
|
||||
vec4 result = texture2D(imageMap, tex) * gauss[0];
|
||||
float total = gauss[0];
|
||||
|
||||
int i, j;
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
for (j = 1; j < GAUSS_SIZE; j++)
|
||||
{
|
||||
vec2 offset = direction * j;
|
||||
float depthSample = zFar * getLinearDepth(depthMap, tex + offset, zFarDivZNear);
|
||||
float depthExpected = depthCenter + dot(centerSlope, offset);
|
||||
if(abs(depthSample - depthExpected) < 5.0)
|
||||
{
|
||||
result += texture2D(imageMap, tex + offset) * gauss[j];
|
||||
total += gauss[j];
|
||||
}
|
||||
}
|
||||
|
||||
direction = -direction;
|
||||
}
|
||||
|
||||
return result / total;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = depthGaussian1D(u_ScreenImageMap, u_ScreenDepthMap, var_ScreenTex, u_ViewInfo.x, u_ViewInfo.y);
|
||||
}
|
||||
uniform sampler2D u_ScreenImageMap;
|
||||
uniform sampler2D u_ScreenDepthMap;
|
||||
|
||||
uniform vec4 u_ViewInfo; // zfar / znear, zfar
|
||||
varying vec2 var_ScreenTex;
|
||||
|
||||
//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[3] = float[3](0.60, 0.19, 0.0066);
|
||||
#define GAUSS_SIZE 4
|
||||
|
||||
float getLinearDepth(sampler2D depthMap, const vec2 tex, const float zFarDivZNear)
|
||||
{
|
||||
float sampleZDivW = texture2D(depthMap, tex).r;
|
||||
return 1.0 / mix(zFarDivZNear, 1.0, sampleZDivW);
|
||||
}
|
||||
|
||||
vec4 depthGaussian1D(sampler2D imageMap, sampler2D depthMap, vec2 tex, float zFarDivZNear, float zFar)
|
||||
{
|
||||
float scale = 1.0 / 256.0;
|
||||
|
||||
#if defined(USE_HORIZONTAL_BLUR)
|
||||
vec2 direction = vec2(1.0, 0.0) * scale;
|
||||
#else // if defined(USE_VERTICAL_BLUR)
|
||||
vec2 direction = vec2(0.0, 1.0) * scale;
|
||||
#endif
|
||||
|
||||
float depthCenter = zFar * getLinearDepth(depthMap, tex, zFarDivZNear);
|
||||
vec2 centerSlope = vec2(dFdx(depthCenter), dFdy(depthCenter)) / vec2(dFdx(tex.x), dFdy(tex.y));
|
||||
|
||||
vec4 result = texture2D(imageMap, tex) * gauss[0];
|
||||
float total = gauss[0];
|
||||
|
||||
int i, j;
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
for (j = 1; j < GAUSS_SIZE; j++)
|
||||
{
|
||||
vec2 offset = direction * j;
|
||||
float depthSample = zFar * getLinearDepth(depthMap, tex + offset, zFarDivZNear);
|
||||
float depthExpected = depthCenter + dot(centerSlope, offset);
|
||||
if(abs(depthSample - depthExpected) < 5.0)
|
||||
{
|
||||
result += texture2D(imageMap, tex + offset) * gauss[j];
|
||||
total += gauss[j];
|
||||
}
|
||||
}
|
||||
|
||||
direction = -direction;
|
||||
}
|
||||
|
||||
return result / total;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = depthGaussian1D(u_ScreenImageMap, u_ScreenDepthMap, var_ScreenTex, u_ViewInfo.x, u_ViewInfo.y);
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
attribute vec4 attr_Position;
|
||||
attribute vec4 attr_TexCoord0;
|
||||
|
||||
varying vec2 var_ScreenTex;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = attr_Position;
|
||||
var_ScreenTex = attr_TexCoord0.xy;
|
||||
//vec2 screenCoords = gl_Position.xy / gl_Position.w;
|
||||
//var_ScreenTex = screenCoords * 0.5 + 0.5;
|
||||
}
|
||||
attribute vec4 attr_Position;
|
||||
attribute vec4 attr_TexCoord0;
|
||||
|
||||
varying vec2 var_ScreenTex;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = attr_Position;
|
||||
var_ScreenTex = attr_TexCoord0.xy;
|
||||
//vec2 screenCoords = gl_Position.xy / gl_Position.w;
|
||||
//var_ScreenTex = screenCoords * 0.5 + 0.5;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
uniform sampler2D u_DiffuseMap;
|
||||
|
||||
varying vec2 var_Tex1;
|
||||
varying vec4 var_Color;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture2D(u_DiffuseMap, var_Tex1);
|
||||
|
||||
gl_FragColor = color * var_Color;
|
||||
}
|
||||
uniform sampler2D u_DiffuseMap;
|
||||
|
||||
varying vec2 var_Tex1;
|
||||
varying vec4 var_Color;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture2D(u_DiffuseMap, var_Tex1);
|
||||
|
||||
gl_FragColor = color * var_Color;
|
||||
}
|
||||
|
|
|
@ -1,92 +1,92 @@
|
|||
attribute vec4 attr_Position;
|
||||
attribute vec4 attr_TexCoord0;
|
||||
attribute vec3 attr_Normal;
|
||||
|
||||
uniform vec4 u_DlightInfo;
|
||||
|
||||
#if defined(USE_DEFORM_VERTEXES)
|
||||
uniform int u_DeformGen;
|
||||
uniform float u_DeformParams[5];
|
||||
uniform float u_Time;
|
||||
#endif
|
||||
|
||||
uniform vec4 u_Color;
|
||||
uniform mat4 u_ModelViewProjectionMatrix;
|
||||
|
||||
varying vec2 var_Tex1;
|
||||
varying vec4 var_Color;
|
||||
|
||||
#if defined(USE_DEFORM_VERTEXES)
|
||||
vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)
|
||||
{
|
||||
if (u_DeformGen == 0)
|
||||
{
|
||||
return pos;
|
||||
}
|
||||
|
||||
float base = u_DeformParams[0];
|
||||
float amplitude = u_DeformParams[1];
|
||||
float phase = u_DeformParams[2];
|
||||
float frequency = u_DeformParams[3];
|
||||
float spread = u_DeformParams[4];
|
||||
|
||||
if (u_DeformGen == DGEN_BULGE)
|
||||
{
|
||||
phase *= M_PI * 0.25 * st.x;
|
||||
}
|
||||
else // if (u_DeformGen <= DGEN_WAVE_INVERSE_SAWTOOTH)
|
||||
{
|
||||
phase += dot(pos.xyz, vec3(spread));
|
||||
}
|
||||
|
||||
float value = phase + (u_Time * frequency);
|
||||
float func;
|
||||
|
||||
if (u_DeformGen == DGEN_WAVE_SIN)
|
||||
{
|
||||
func = sin(value * 2.0 * M_PI);
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_SQUARE)
|
||||
{
|
||||
func = sign(sin(value * 2.0 * M_PI));
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_TRIANGLE)
|
||||
{
|
||||
func = abs(fract(value + 0.75) - 0.5) * 4.0 - 1.0;
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_SAWTOOTH)
|
||||
{
|
||||
func = fract(value);
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_INVERSE_SAWTOOTH)
|
||||
{
|
||||
func = (1.0 - fract(value));
|
||||
}
|
||||
else if (u_DeformGen == DGEN_BULGE)
|
||||
{
|
||||
func = sin(value);
|
||||
}
|
||||
|
||||
return pos + normal * (base + func * amplitude);
|
||||
}
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 position = attr_Position;
|
||||
vec3 normal = attr_Normal;
|
||||
|
||||
#if defined(USE_DEFORM_VERTEXES)
|
||||
position.xyz = DeformPosition(position.xyz, normal, attr_TexCoord0.st);
|
||||
#endif
|
||||
|
||||
gl_Position = u_ModelViewProjectionMatrix * position;
|
||||
|
||||
vec3 dist = u_DlightInfo.xyz - position.xyz;
|
||||
|
||||
var_Tex1 = dist.xy * u_DlightInfo.a + vec2(0.5);
|
||||
float dlightmod = step(0.0, dot(dist, normal));
|
||||
dlightmod *= clamp(2.0 * (1.0 - abs(dist.z) * u_DlightInfo.a), 0.0, 1.0);
|
||||
|
||||
var_Color = u_Color * dlightmod;
|
||||
}
|
||||
attribute vec4 attr_Position;
|
||||
attribute vec4 attr_TexCoord0;
|
||||
attribute vec3 attr_Normal;
|
||||
|
||||
uniform vec4 u_DlightInfo;
|
||||
|
||||
#if defined(USE_DEFORM_VERTEXES)
|
||||
uniform int u_DeformGen;
|
||||
uniform float u_DeformParams[5];
|
||||
uniform float u_Time;
|
||||
#endif
|
||||
|
||||
uniform vec4 u_Color;
|
||||
uniform mat4 u_ModelViewProjectionMatrix;
|
||||
|
||||
varying vec2 var_Tex1;
|
||||
varying vec4 var_Color;
|
||||
|
||||
#if defined(USE_DEFORM_VERTEXES)
|
||||
vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)
|
||||
{
|
||||
if (u_DeformGen == 0)
|
||||
{
|
||||
return pos;
|
||||
}
|
||||
|
||||
float base = u_DeformParams[0];
|
||||
float amplitude = u_DeformParams[1];
|
||||
float phase = u_DeformParams[2];
|
||||
float frequency = u_DeformParams[3];
|
||||
float spread = u_DeformParams[4];
|
||||
|
||||
if (u_DeformGen == DGEN_BULGE)
|
||||
{
|
||||
phase *= M_PI * 0.25 * st.x;
|
||||
}
|
||||
else // if (u_DeformGen <= DGEN_WAVE_INVERSE_SAWTOOTH)
|
||||
{
|
||||
phase += dot(pos.xyz, vec3(spread));
|
||||
}
|
||||
|
||||
float value = phase + (u_Time * frequency);
|
||||
float func;
|
||||
|
||||
if (u_DeformGen == DGEN_WAVE_SIN)
|
||||
{
|
||||
func = sin(value * 2.0 * M_PI);
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_SQUARE)
|
||||
{
|
||||
func = sign(sin(value * 2.0 * M_PI));
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_TRIANGLE)
|
||||
{
|
||||
func = abs(fract(value + 0.75) - 0.5) * 4.0 - 1.0;
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_SAWTOOTH)
|
||||
{
|
||||
func = fract(value);
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_INVERSE_SAWTOOTH)
|
||||
{
|
||||
func = (1.0 - fract(value));
|
||||
}
|
||||
else if (u_DeformGen == DGEN_BULGE)
|
||||
{
|
||||
func = sin(value);
|
||||
}
|
||||
|
||||
return pos + normal * (base + func * amplitude);
|
||||
}
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 position = attr_Position;
|
||||
vec3 normal = attr_Normal;
|
||||
|
||||
#if defined(USE_DEFORM_VERTEXES)
|
||||
position.xyz = DeformPosition(position.xyz, normal, attr_TexCoord0.st);
|
||||
#endif
|
||||
|
||||
gl_Position = u_ModelViewProjectionMatrix * position;
|
||||
|
||||
vec3 dist = u_DlightInfo.xyz - position.xyz;
|
||||
|
||||
var_Tex1 = dist.xy * u_DlightInfo.a + vec2(0.5);
|
||||
float dlightmod = step(0.0, dot(dist, normal));
|
||||
dlightmod *= clamp(2.0 * (1.0 - abs(dist.z) * u_DlightInfo.a), 0.0, 1.0);
|
||||
|
||||
var_Color = u_Color * dlightmod;
|
||||
}
|
||||
|
|
|
@ -1,34 +1,34 @@
|
|||
uniform sampler2D u_TextureMap;
|
||||
|
||||
uniform vec2 u_InvTexRes;
|
||||
varying vec2 var_TexCoords;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color;
|
||||
vec2 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( 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(-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(-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, 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);
|
||||
|
||||
color *= 0.0625;
|
||||
|
||||
gl_FragColor = color;
|
||||
}
|
||||
uniform sampler2D u_TextureMap;
|
||||
|
||||
uniform vec2 u_InvTexRes;
|
||||
varying vec2 var_TexCoords;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color;
|
||||
vec2 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( 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(-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(-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, 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);
|
||||
|
||||
color *= 0.0625;
|
||||
|
||||
gl_FragColor = color;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
attribute vec4 attr_Position;
|
||||
attribute vec4 attr_TexCoord0;
|
||||
|
||||
uniform mat4 u_ModelViewProjectionMatrix;
|
||||
|
||||
varying vec2 var_TexCoords;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = u_ModelViewProjectionMatrix * attr_Position;
|
||||
var_TexCoords = attr_TexCoord0.st;
|
||||
}
|
||||
attribute vec4 attr_Position;
|
||||
attribute vec4 attr_TexCoord0;
|
||||
|
||||
uniform mat4 u_ModelViewProjectionMatrix;
|
||||
|
||||
varying vec2 var_TexCoords;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = u_ModelViewProjectionMatrix * attr_Position;
|
||||
var_TexCoords = attr_TexCoord0.st;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
uniform vec4 u_Color;
|
||||
|
||||
varying float var_Scale;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = u_Color;
|
||||
gl_FragColor.a *= sqrt(clamp(var_Scale, 0.0, 1.0));
|
||||
}
|
||||
uniform vec4 u_Color;
|
||||
|
||||
varying float var_Scale;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = u_Color;
|
||||
gl_FragColor.a *= sqrt(clamp(var_Scale, 0.0, 1.0));
|
||||
}
|
||||
|
|
|
@ -1,117 +1,117 @@
|
|||
attribute vec4 attr_Position;
|
||||
attribute vec3 attr_Normal;
|
||||
attribute vec4 attr_TexCoord0;
|
||||
|
||||
//#if defined(USE_VERTEX_ANIMATION)
|
||||
attribute vec4 attr_Position2;
|
||||
attribute vec3 attr_Normal2;
|
||||
//#endif
|
||||
|
||||
uniform vec4 u_FogDistance;
|
||||
uniform vec4 u_FogDepth;
|
||||
uniform float u_FogEyeT;
|
||||
|
||||
//#if defined(USE_DEFORM_VERTEXES)
|
||||
uniform int u_DeformGen;
|
||||
uniform float u_DeformParams[5];
|
||||
//#endif
|
||||
|
||||
uniform float u_Time;
|
||||
uniform mat4 u_ModelViewProjectionMatrix;
|
||||
|
||||
//#if defined(USE_VERTEX_ANIMATION)
|
||||
uniform float u_VertexLerp;
|
||||
//#endif
|
||||
|
||||
varying float var_Scale;
|
||||
|
||||
#if defined(USE_DEFORM_VERTEXES)
|
||||
vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)
|
||||
{
|
||||
if (u_DeformGen == 0)
|
||||
{
|
||||
return pos;
|
||||
}
|
||||
|
||||
float base = u_DeformParams[0];
|
||||
float amplitude = u_DeformParams[1];
|
||||
float phase = u_DeformParams[2];
|
||||
float frequency = u_DeformParams[3];
|
||||
float spread = u_DeformParams[4];
|
||||
|
||||
if (u_DeformGen == DGEN_BULGE)
|
||||
{
|
||||
phase *= M_PI * 0.25 * st.x;
|
||||
}
|
||||
else // if (u_DeformGen <= DGEN_WAVE_INVERSE_SAWTOOTH)
|
||||
{
|
||||
phase += dot(pos.xyz, vec3(spread));
|
||||
}
|
||||
|
||||
float value = phase + (u_Time * frequency);
|
||||
float func;
|
||||
|
||||
if (u_DeformGen == DGEN_WAVE_SIN)
|
||||
{
|
||||
func = sin(value * 2.0 * M_PI);
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_SQUARE)
|
||||
{
|
||||
func = sign(sin(value * 2.0 * M_PI));
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_TRIANGLE)
|
||||
{
|
||||
func = abs(fract(value + 0.75) - 0.5) * 4.0 - 1.0;
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_SAWTOOTH)
|
||||
{
|
||||
func = fract(value);
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_INVERSE_SAWTOOTH)
|
||||
{
|
||||
func = (1.0 - fract(value));
|
||||
}
|
||||
else if (u_DeformGen == DGEN_BULGE)
|
||||
{
|
||||
func = sin(value);
|
||||
}
|
||||
|
||||
return pos + normal * (base + func * amplitude);
|
||||
}
|
||||
#endif
|
||||
|
||||
float CalcFog(vec4 position)
|
||||
{
|
||||
float s = dot(position, u_FogDistance) * 8.0;
|
||||
float t = dot(position, u_FogDepth);
|
||||
|
||||
if (t < 1.0)
|
||||
{
|
||||
t = step(step(0.0, -u_FogEyeT), t);
|
||||
}
|
||||
else
|
||||
{
|
||||
t /= t - min(u_FogEyeT, 0.0);
|
||||
}
|
||||
|
||||
return s * t;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
#if defined(USE_VERTEX_ANIMATION)
|
||||
vec4 position = mix(attr_Position, attr_Position2, u_VertexLerp);
|
||||
vec3 normal = normalize(mix(attr_Normal, attr_Normal2, u_VertexLerp));
|
||||
#else
|
||||
vec4 position = attr_Position;
|
||||
vec3 normal = attr_Normal;
|
||||
#endif
|
||||
|
||||
#if defined(USE_DEFORM_VERTEXES)
|
||||
position.xyz = DeformPosition(position.xyz, normal, attr_TexCoord0.st);
|
||||
#endif
|
||||
|
||||
gl_Position = u_ModelViewProjectionMatrix * position;
|
||||
|
||||
var_Scale = CalcFog(position);
|
||||
}
|
||||
attribute vec4 attr_Position;
|
||||
attribute vec3 attr_Normal;
|
||||
attribute vec4 attr_TexCoord0;
|
||||
|
||||
//#if defined(USE_VERTEX_ANIMATION)
|
||||
attribute vec4 attr_Position2;
|
||||
attribute vec3 attr_Normal2;
|
||||
//#endif
|
||||
|
||||
uniform vec4 u_FogDistance;
|
||||
uniform vec4 u_FogDepth;
|
||||
uniform float u_FogEyeT;
|
||||
|
||||
//#if defined(USE_DEFORM_VERTEXES)
|
||||
uniform int u_DeformGen;
|
||||
uniform float u_DeformParams[5];
|
||||
//#endif
|
||||
|
||||
uniform float u_Time;
|
||||
uniform mat4 u_ModelViewProjectionMatrix;
|
||||
|
||||
//#if defined(USE_VERTEX_ANIMATION)
|
||||
uniform float u_VertexLerp;
|
||||
//#endif
|
||||
|
||||
varying float var_Scale;
|
||||
|
||||
#if defined(USE_DEFORM_VERTEXES)
|
||||
vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)
|
||||
{
|
||||
if (u_DeformGen == 0)
|
||||
{
|
||||
return pos;
|
||||
}
|
||||
|
||||
float base = u_DeformParams[0];
|
||||
float amplitude = u_DeformParams[1];
|
||||
float phase = u_DeformParams[2];
|
||||
float frequency = u_DeformParams[3];
|
||||
float spread = u_DeformParams[4];
|
||||
|
||||
if (u_DeformGen == DGEN_BULGE)
|
||||
{
|
||||
phase *= M_PI * 0.25 * st.x;
|
||||
}
|
||||
else // if (u_DeformGen <= DGEN_WAVE_INVERSE_SAWTOOTH)
|
||||
{
|
||||
phase += dot(pos.xyz, vec3(spread));
|
||||
}
|
||||
|
||||
float value = phase + (u_Time * frequency);
|
||||
float func;
|
||||
|
||||
if (u_DeformGen == DGEN_WAVE_SIN)
|
||||
{
|
||||
func = sin(value * 2.0 * M_PI);
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_SQUARE)
|
||||
{
|
||||
func = sign(sin(value * 2.0 * M_PI));
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_TRIANGLE)
|
||||
{
|
||||
func = abs(fract(value + 0.75) - 0.5) * 4.0 - 1.0;
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_SAWTOOTH)
|
||||
{
|
||||
func = fract(value);
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_INVERSE_SAWTOOTH)
|
||||
{
|
||||
func = (1.0 - fract(value));
|
||||
}
|
||||
else if (u_DeformGen == DGEN_BULGE)
|
||||
{
|
||||
func = sin(value);
|
||||
}
|
||||
|
||||
return pos + normal * (base + func * amplitude);
|
||||
}
|
||||
#endif
|
||||
|
||||
float CalcFog(vec4 position)
|
||||
{
|
||||
float s = dot(position, u_FogDistance) * 8.0;
|
||||
float t = dot(position, u_FogDepth);
|
||||
|
||||
if (t < 1.0)
|
||||
{
|
||||
t = step(step(0.0, -u_FogEyeT), t);
|
||||
}
|
||||
else
|
||||
{
|
||||
t /= t - min(u_FogEyeT, 0.0);
|
||||
}
|
||||
|
||||
return s * t;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
#if defined(USE_VERTEX_ANIMATION)
|
||||
vec4 position = mix(attr_Position, attr_Position2, u_VertexLerp);
|
||||
vec3 normal = normalize(mix(attr_Normal, attr_Normal2, u_VertexLerp));
|
||||
#else
|
||||
vec4 position = attr_Position;
|
||||
vec3 normal = attr_Normal;
|
||||
#endif
|
||||
|
||||
#if defined(USE_DEFORM_VERTEXES)
|
||||
position.xyz = DeformPosition(position.xyz, normal, attr_TexCoord0.st);
|
||||
#endif
|
||||
|
||||
gl_Position = u_ModelViewProjectionMatrix * position;
|
||||
|
||||
var_Scale = CalcFog(position);
|
||||
}
|
||||
|
|
|
@ -1,43 +1,43 @@
|
|||
uniform sampler2D u_DiffuseMap;
|
||||
|
||||
#if defined(USE_LIGHTMAP)
|
||||
uniform sampler2D u_LightMap;
|
||||
|
||||
uniform int u_Texture1Env;
|
||||
#endif
|
||||
|
||||
varying vec2 var_DiffuseTex;
|
||||
|
||||
#if defined(USE_LIGHTMAP)
|
||||
varying vec2 var_LightTex;
|
||||
#endif
|
||||
|
||||
varying vec4 var_Color;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture2D(u_DiffuseMap, var_DiffuseTex);
|
||||
#if defined(USE_LIGHTMAP)
|
||||
vec4 color2 = texture2D(u_LightMap, var_LightTex);
|
||||
#if defined(RGBE_LIGHTMAP)
|
||||
color2.rgb *= exp2(color2.a * 255.0 - 128.0);
|
||||
color2.a = 1.0;
|
||||
#endif
|
||||
|
||||
if (u_Texture1Env == TEXENV_MODULATE)
|
||||
{
|
||||
color *= color2;
|
||||
}
|
||||
else if (u_Texture1Env == TEXENV_ADD)
|
||||
{
|
||||
color += color2;
|
||||
}
|
||||
else if (u_Texture1Env == TEXENV_REPLACE)
|
||||
{
|
||||
color = color2;
|
||||
}
|
||||
#endif
|
||||
|
||||
gl_FragColor = color * var_Color;
|
||||
}
|
||||
uniform sampler2D u_DiffuseMap;
|
||||
|
||||
#if defined(USE_LIGHTMAP)
|
||||
uniform sampler2D u_LightMap;
|
||||
|
||||
uniform int u_Texture1Env;
|
||||
#endif
|
||||
|
||||
varying vec2 var_DiffuseTex;
|
||||
|
||||
#if defined(USE_LIGHTMAP)
|
||||
varying vec2 var_LightTex;
|
||||
#endif
|
||||
|
||||
varying vec4 var_Color;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture2D(u_DiffuseMap, var_DiffuseTex);
|
||||
#if defined(USE_LIGHTMAP)
|
||||
vec4 color2 = texture2D(u_LightMap, var_LightTex);
|
||||
#if defined(RGBE_LIGHTMAP)
|
||||
color2.rgb *= exp2(color2.a * 255.0 - 128.0);
|
||||
color2.a = 1.0;
|
||||
#endif
|
||||
|
||||
if (u_Texture1Env == TEXENV_MODULATE)
|
||||
{
|
||||
color *= color2;
|
||||
}
|
||||
else if (u_Texture1Env == TEXENV_ADD)
|
||||
{
|
||||
color += color2;
|
||||
}
|
||||
else if (u_Texture1Env == TEXENV_REPLACE)
|
||||
{
|
||||
color = color2;
|
||||
}
|
||||
#endif
|
||||
|
||||
gl_FragColor = color * var_Color;
|
||||
}
|
||||
|
|
|
@ -1,251 +1,251 @@
|
|||
attribute vec4 attr_Position;
|
||||
attribute vec3 attr_Normal;
|
||||
|
||||
#if defined(USE_VERTEX_ANIMATION)
|
||||
attribute vec4 attr_Position2;
|
||||
attribute vec3 attr_Normal2;
|
||||
#endif
|
||||
|
||||
attribute vec4 attr_Color;
|
||||
attribute vec4 attr_TexCoord0;
|
||||
|
||||
#if defined(USE_LIGHTMAP) || defined(USE_TCGEN)
|
||||
attribute vec4 attr_TexCoord1;
|
||||
#endif
|
||||
|
||||
uniform vec4 u_DiffuseTexMatrix;
|
||||
uniform vec4 u_DiffuseTexOffTurb;
|
||||
|
||||
#if defined(USE_TCGEN) || defined(USE_RGBAGEN)
|
||||
uniform vec3 u_ViewOrigin;
|
||||
#endif
|
||||
|
||||
#if defined(USE_TCGEN)
|
||||
uniform int u_TCGen0;
|
||||
uniform vec3 u_TCGen0Vector0;
|
||||
uniform vec3 u_TCGen0Vector1;
|
||||
#endif
|
||||
|
||||
#if defined(USE_FOG)
|
||||
uniform vec4 u_FogDistance;
|
||||
uniform vec4 u_FogDepth;
|
||||
uniform float u_FogEyeT;
|
||||
uniform vec4 u_FogColorMask;
|
||||
#endif
|
||||
|
||||
#if defined(USE_DEFORM_VERTEXES)
|
||||
uniform int u_DeformGen;
|
||||
uniform float u_DeformParams[5];
|
||||
uniform float u_Time;
|
||||
#endif
|
||||
|
||||
uniform mat4 u_ModelViewProjectionMatrix;
|
||||
uniform vec4 u_BaseColor;
|
||||
uniform vec4 u_VertColor;
|
||||
|
||||
#if defined(USE_RGBAGEN)
|
||||
uniform int u_ColorGen;
|
||||
uniform int u_AlphaGen;
|
||||
uniform vec3 u_AmbientLight;
|
||||
uniform vec3 u_DirectedLight;
|
||||
uniform vec4 u_LightOrigin;
|
||||
uniform float u_PortalRange;
|
||||
#endif
|
||||
|
||||
#if defined(USE_VERTEX_ANIMATION)
|
||||
uniform float u_VertexLerp;
|
||||
#endif
|
||||
|
||||
varying vec2 var_DiffuseTex;
|
||||
#if defined(USE_LIGHTMAP)
|
||||
varying vec2 var_LightTex;
|
||||
#endif
|
||||
varying vec4 var_Color;
|
||||
|
||||
#if defined(USE_DEFORM_VERTEXES)
|
||||
vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)
|
||||
{
|
||||
float base = u_DeformParams[0];
|
||||
float amplitude = u_DeformParams[1];
|
||||
float phase = u_DeformParams[2];
|
||||
float frequency = u_DeformParams[3];
|
||||
float spread = u_DeformParams[4];
|
||||
|
||||
if (u_DeformGen == DGEN_BULGE)
|
||||
{
|
||||
phase *= M_PI * 0.25 * st.x;
|
||||
}
|
||||
else // if (u_DeformGen <= DGEN_WAVE_INVERSE_SAWTOOTH)
|
||||
{
|
||||
phase += dot(pos.xyz, vec3(spread));
|
||||
}
|
||||
|
||||
float value = phase + (u_Time * frequency);
|
||||
float func;
|
||||
|
||||
if (u_DeformGen == DGEN_WAVE_SIN)
|
||||
{
|
||||
func = sin(value * 2.0 * M_PI);
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_SQUARE)
|
||||
{
|
||||
func = sign(sin(value * 2.0 * M_PI));
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_TRIANGLE)
|
||||
{
|
||||
func = abs(fract(value + 0.75) - 0.5) * 4.0 - 1.0;
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_SAWTOOTH)
|
||||
{
|
||||
func = fract(value);
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_INVERSE_SAWTOOTH)
|
||||
{
|
||||
func = (1.0 - fract(value));
|
||||
}
|
||||
else if (u_DeformGen == DGEN_BULGE)
|
||||
{
|
||||
func = sin(value);
|
||||
}
|
||||
|
||||
return pos + normal * (base + func * amplitude);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(USE_TCGEN)
|
||||
vec2 GenTexCoords(int TCGen, vec3 position, vec3 normal, vec3 TCGenVector0, vec3 TCGenVector1)
|
||||
{
|
||||
vec2 tex = attr_TexCoord0.st;
|
||||
|
||||
if (TCGen == TCGEN_LIGHTMAP)
|
||||
{
|
||||
tex = attr_TexCoord1.st;
|
||||
}
|
||||
else if (TCGen == TCGEN_ENVIRONMENT_MAPPED)
|
||||
{
|
||||
vec3 viewer = normalize(u_ViewOrigin - position);
|
||||
tex = -reflect(viewer, normal).yz * vec2(0.5, -0.5) + 0.5;
|
||||
}
|
||||
else if (TCGen == TCGEN_VECTOR)
|
||||
{
|
||||
tex = vec2(dot(position, TCGenVector0), dot(position, TCGenVector1));
|
||||
}
|
||||
|
||||
return tex;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(USE_TCMOD)
|
||||
vec2 ModTexCoords(vec2 st, vec3 position, vec4 texMatrix, vec4 offTurb)
|
||||
{
|
||||
float amplitude = offTurb.z;
|
||||
float phase = offTurb.w;
|
||||
vec2 st2 = vec2(dot(st, texMatrix.xz), dot(st, texMatrix.yw)) + offTurb.xy;
|
||||
|
||||
vec3 offsetPos = position / 1024.0;
|
||||
offsetPos.x += offsetPos.z;
|
||||
|
||||
vec2 texOffset = sin((offsetPos.xy + vec2(phase)) * 2.0 * M_PI);
|
||||
|
||||
return st2 + texOffset * amplitude;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(USE_RGBAGEN)
|
||||
vec4 CalcColor(vec3 position, vec3 normal)
|
||||
{
|
||||
vec4 color = u_VertColor * attr_Color + u_BaseColor;
|
||||
|
||||
if (u_ColorGen == CGEN_LIGHTING_DIFFUSE)
|
||||
{
|
||||
float incoming = clamp(dot(normal, u_LightOrigin.xyz), 0.0, 1.0);
|
||||
|
||||
color.rgb = clamp(u_DirectedLight * incoming + u_AmbientLight, 0.0, 1.0);
|
||||
}
|
||||
|
||||
vec3 toView = u_ViewOrigin - position;
|
||||
vec3 viewer = normalize(u_ViewOrigin - position);
|
||||
|
||||
if (u_AlphaGen == AGEN_LIGHTING_SPECULAR)
|
||||
{
|
||||
vec3 lightDir = normalize(vec3(-960.0, -1980.0, 96.0) - position.xyz);
|
||||
vec3 halfangle = normalize(lightDir + viewer);
|
||||
|
||||
color.a = pow(max(dot(normal, halfangle), 0.0), 8.0);
|
||||
}
|
||||
else if (u_AlphaGen == AGEN_PORTAL)
|
||||
{
|
||||
float alpha = length(toView) / u_PortalRange;
|
||||
|
||||
color.a = clamp(alpha, 0.0, 1.0);
|
||||
}
|
||||
else if (u_AlphaGen == AGEN_FRESNEL)
|
||||
{
|
||||
color.a = 0.10 + 0.90 * pow(1.0 - dot(normal, viewer), 5);
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(USE_FOG)
|
||||
float CalcFog(vec4 position)
|
||||
{
|
||||
float s = dot(position, u_FogDistance) * 8.0;
|
||||
float t = dot(position, u_FogDepth);
|
||||
|
||||
if (t < 1.0)
|
||||
{
|
||||
t = step(step(0.0, -u_FogEyeT), t);
|
||||
}
|
||||
else
|
||||
{
|
||||
t /= t - min(u_FogEyeT, 0.0);
|
||||
}
|
||||
|
||||
return s * t;
|
||||
}
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
#if defined(USE_VERTEX_ANIMATION)
|
||||
vec4 position = mix(attr_Position, attr_Position2, u_VertexLerp);
|
||||
vec3 normal = normalize(mix(attr_Normal, attr_Normal2, u_VertexLerp));
|
||||
#else
|
||||
vec4 position = attr_Position;
|
||||
vec3 normal = attr_Normal;
|
||||
#endif
|
||||
|
||||
#if defined(USE_DEFORM_VERTEXES)
|
||||
position.xyz = DeformPosition(position.xyz, normal, attr_TexCoord0.st);
|
||||
#endif
|
||||
|
||||
gl_Position = u_ModelViewProjectionMatrix * position;
|
||||
|
||||
#if defined(USE_TCGEN)
|
||||
vec2 tex = GenTexCoords(u_TCGen0, position.xyz, normal, u_TCGen0Vector0, u_TCGen0Vector1);
|
||||
#else
|
||||
vec2 tex = attr_TexCoord0.st;
|
||||
#endif
|
||||
|
||||
#if defined(USE_TCMOD)
|
||||
var_DiffuseTex = ModTexCoords(tex, position.xyz, u_DiffuseTexMatrix, u_DiffuseTexOffTurb);
|
||||
#else
|
||||
var_DiffuseTex = tex;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHTMAP)
|
||||
var_LightTex = attr_TexCoord1.st;
|
||||
#endif
|
||||
|
||||
#if defined(USE_RGBAGEN)
|
||||
var_Color = CalcColor(position.xyz, normal);
|
||||
#else
|
||||
var_Color = u_VertColor * attr_Color + u_BaseColor;
|
||||
#endif
|
||||
|
||||
#if defined(USE_FOG)
|
||||
var_Color *= vec4(1.0) - u_FogColorMask * sqrt(clamp(CalcFog(position), 0.0, 1.0));
|
||||
#endif
|
||||
}
|
||||
attribute vec4 attr_Position;
|
||||
attribute vec3 attr_Normal;
|
||||
|
||||
#if defined(USE_VERTEX_ANIMATION)
|
||||
attribute vec4 attr_Position2;
|
||||
attribute vec3 attr_Normal2;
|
||||
#endif
|
||||
|
||||
attribute vec4 attr_Color;
|
||||
attribute vec4 attr_TexCoord0;
|
||||
|
||||
#if defined(USE_LIGHTMAP) || defined(USE_TCGEN)
|
||||
attribute vec4 attr_TexCoord1;
|
||||
#endif
|
||||
|
||||
uniform vec4 u_DiffuseTexMatrix;
|
||||
uniform vec4 u_DiffuseTexOffTurb;
|
||||
|
||||
#if defined(USE_TCGEN) || defined(USE_RGBAGEN)
|
||||
uniform vec3 u_ViewOrigin;
|
||||
#endif
|
||||
|
||||
#if defined(USE_TCGEN)
|
||||
uniform int u_TCGen0;
|
||||
uniform vec3 u_TCGen0Vector0;
|
||||
uniform vec3 u_TCGen0Vector1;
|
||||
#endif
|
||||
|
||||
#if defined(USE_FOG)
|
||||
uniform vec4 u_FogDistance;
|
||||
uniform vec4 u_FogDepth;
|
||||
uniform float u_FogEyeT;
|
||||
uniform vec4 u_FogColorMask;
|
||||
#endif
|
||||
|
||||
#if defined(USE_DEFORM_VERTEXES)
|
||||
uniform int u_DeformGen;
|
||||
uniform float u_DeformParams[5];
|
||||
uniform float u_Time;
|
||||
#endif
|
||||
|
||||
uniform mat4 u_ModelViewProjectionMatrix;
|
||||
uniform vec4 u_BaseColor;
|
||||
uniform vec4 u_VertColor;
|
||||
|
||||
#if defined(USE_RGBAGEN)
|
||||
uniform int u_ColorGen;
|
||||
uniform int u_AlphaGen;
|
||||
uniform vec3 u_AmbientLight;
|
||||
uniform vec3 u_DirectedLight;
|
||||
uniform vec4 u_LightOrigin;
|
||||
uniform float u_PortalRange;
|
||||
#endif
|
||||
|
||||
#if defined(USE_VERTEX_ANIMATION)
|
||||
uniform float u_VertexLerp;
|
||||
#endif
|
||||
|
||||
varying vec2 var_DiffuseTex;
|
||||
#if defined(USE_LIGHTMAP)
|
||||
varying vec2 var_LightTex;
|
||||
#endif
|
||||
varying vec4 var_Color;
|
||||
|
||||
#if defined(USE_DEFORM_VERTEXES)
|
||||
vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)
|
||||
{
|
||||
float base = u_DeformParams[0];
|
||||
float amplitude = u_DeformParams[1];
|
||||
float phase = u_DeformParams[2];
|
||||
float frequency = u_DeformParams[3];
|
||||
float spread = u_DeformParams[4];
|
||||
|
||||
if (u_DeformGen == DGEN_BULGE)
|
||||
{
|
||||
phase *= M_PI * 0.25 * st.x;
|
||||
}
|
||||
else // if (u_DeformGen <= DGEN_WAVE_INVERSE_SAWTOOTH)
|
||||
{
|
||||
phase += dot(pos.xyz, vec3(spread));
|
||||
}
|
||||
|
||||
float value = phase + (u_Time * frequency);
|
||||
float func;
|
||||
|
||||
if (u_DeformGen == DGEN_WAVE_SIN)
|
||||
{
|
||||
func = sin(value * 2.0 * M_PI);
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_SQUARE)
|
||||
{
|
||||
func = sign(sin(value * 2.0 * M_PI));
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_TRIANGLE)
|
||||
{
|
||||
func = abs(fract(value + 0.75) - 0.5) * 4.0 - 1.0;
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_SAWTOOTH)
|
||||
{
|
||||
func = fract(value);
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_INVERSE_SAWTOOTH)
|
||||
{
|
||||
func = (1.0 - fract(value));
|
||||
}
|
||||
else if (u_DeformGen == DGEN_BULGE)
|
||||
{
|
||||
func = sin(value);
|
||||
}
|
||||
|
||||
return pos + normal * (base + func * amplitude);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(USE_TCGEN)
|
||||
vec2 GenTexCoords(int TCGen, vec3 position, vec3 normal, vec3 TCGenVector0, vec3 TCGenVector1)
|
||||
{
|
||||
vec2 tex = attr_TexCoord0.st;
|
||||
|
||||
if (TCGen == TCGEN_LIGHTMAP)
|
||||
{
|
||||
tex = attr_TexCoord1.st;
|
||||
}
|
||||
else if (TCGen == TCGEN_ENVIRONMENT_MAPPED)
|
||||
{
|
||||
vec3 viewer = normalize(u_ViewOrigin - position);
|
||||
tex = -reflect(viewer, normal).yz * vec2(0.5, -0.5) + 0.5;
|
||||
}
|
||||
else if (TCGen == TCGEN_VECTOR)
|
||||
{
|
||||
tex = vec2(dot(position, TCGenVector0), dot(position, TCGenVector1));
|
||||
}
|
||||
|
||||
return tex;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(USE_TCMOD)
|
||||
vec2 ModTexCoords(vec2 st, vec3 position, vec4 texMatrix, vec4 offTurb)
|
||||
{
|
||||
float amplitude = offTurb.z;
|
||||
float phase = offTurb.w;
|
||||
vec2 st2 = vec2(dot(st, texMatrix.xz), dot(st, texMatrix.yw)) + offTurb.xy;
|
||||
|
||||
vec3 offsetPos = position / 1024.0;
|
||||
offsetPos.x += offsetPos.z;
|
||||
|
||||
vec2 texOffset = sin((offsetPos.xy + vec2(phase)) * 2.0 * M_PI);
|
||||
|
||||
return st2 + texOffset * amplitude;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(USE_RGBAGEN)
|
||||
vec4 CalcColor(vec3 position, vec3 normal)
|
||||
{
|
||||
vec4 color = u_VertColor * attr_Color + u_BaseColor;
|
||||
|
||||
if (u_ColorGen == CGEN_LIGHTING_DIFFUSE)
|
||||
{
|
||||
float incoming = clamp(dot(normal, u_LightOrigin.xyz), 0.0, 1.0);
|
||||
|
||||
color.rgb = clamp(u_DirectedLight * incoming + u_AmbientLight, 0.0, 1.0);
|
||||
}
|
||||
|
||||
vec3 toView = u_ViewOrigin - position;
|
||||
vec3 viewer = normalize(u_ViewOrigin - position);
|
||||
|
||||
if (u_AlphaGen == AGEN_LIGHTING_SPECULAR)
|
||||
{
|
||||
vec3 lightDir = normalize(vec3(-960.0, -1980.0, 96.0) - position.xyz);
|
||||
vec3 halfangle = normalize(lightDir + viewer);
|
||||
|
||||
color.a = pow(max(dot(normal, halfangle), 0.0), 8.0);
|
||||
}
|
||||
else if (u_AlphaGen == AGEN_PORTAL)
|
||||
{
|
||||
float alpha = length(toView) / u_PortalRange;
|
||||
|
||||
color.a = clamp(alpha, 0.0, 1.0);
|
||||
}
|
||||
else if (u_AlphaGen == AGEN_FRESNEL)
|
||||
{
|
||||
color.a = 0.10 + 0.90 * pow(1.0 - dot(normal, viewer), 5);
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(USE_FOG)
|
||||
float CalcFog(vec4 position)
|
||||
{
|
||||
float s = dot(position, u_FogDistance) * 8.0;
|
||||
float t = dot(position, u_FogDepth);
|
||||
|
||||
if (t < 1.0)
|
||||
{
|
||||
t = step(step(0.0, -u_FogEyeT), t);
|
||||
}
|
||||
else
|
||||
{
|
||||
t /= t - min(u_FogEyeT, 0.0);
|
||||
}
|
||||
|
||||
return s * t;
|
||||
}
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
#if defined(USE_VERTEX_ANIMATION)
|
||||
vec4 position = mix(attr_Position, attr_Position2, u_VertexLerp);
|
||||
vec3 normal = normalize(mix(attr_Normal, attr_Normal2, u_VertexLerp));
|
||||
#else
|
||||
vec4 position = attr_Position;
|
||||
vec3 normal = attr_Normal;
|
||||
#endif
|
||||
|
||||
#if defined(USE_DEFORM_VERTEXES)
|
||||
position.xyz = DeformPosition(position.xyz, normal, attr_TexCoord0.st);
|
||||
#endif
|
||||
|
||||
gl_Position = u_ModelViewProjectionMatrix * position;
|
||||
|
||||
#if defined(USE_TCGEN)
|
||||
vec2 tex = GenTexCoords(u_TCGen0, position.xyz, normal, u_TCGen0Vector0, u_TCGen0Vector1);
|
||||
#else
|
||||
vec2 tex = attr_TexCoord0.st;
|
||||
#endif
|
||||
|
||||
#if defined(USE_TCMOD)
|
||||
var_DiffuseTex = ModTexCoords(tex, position.xyz, u_DiffuseTexMatrix, u_DiffuseTexOffTurb);
|
||||
#else
|
||||
var_DiffuseTex = tex;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHTMAP)
|
||||
var_LightTex = attr_TexCoord1.st;
|
||||
#endif
|
||||
|
||||
#if defined(USE_RGBAGEN)
|
||||
var_Color = CalcColor(position.xyz, normal);
|
||||
#else
|
||||
var_Color = u_VertColor * attr_Color + u_BaseColor;
|
||||
#endif
|
||||
|
||||
#if defined(USE_FOG)
|
||||
var_Color *= vec4(1.0) - u_FogColorMask * sqrt(clamp(CalcFog(position), 0.0, 1.0));
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -1,360 +1,360 @@
|
|||
uniform sampler2D u_DiffuseMap;
|
||||
|
||||
#if defined(USE_LIGHTMAP)
|
||||
uniform sampler2D u_LightMap;
|
||||
#endif
|
||||
|
||||
#if defined(USE_NORMALMAP)
|
||||
uniform sampler2D u_NormalMap;
|
||||
#endif
|
||||
|
||||
#if defined(USE_DELUXEMAP)
|
||||
uniform sampler2D u_DeluxeMap;
|
||||
#endif
|
||||
|
||||
#if defined(USE_SPECULARMAP)
|
||||
uniform sampler2D u_SpecularMap;
|
||||
#endif
|
||||
|
||||
#if defined(USE_SHADOWMAP)
|
||||
uniform sampler2D u_ShadowMap;
|
||||
#endif
|
||||
|
||||
uniform vec3 u_ViewOrigin;
|
||||
|
||||
#if defined(USE_TCGEN)
|
||||
uniform int u_TCGen0;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT_VECTOR)
|
||||
uniform vec3 u_DirectedLight;
|
||||
uniform vec3 u_AmbientLight;
|
||||
uniform float u_LightRadius;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT)
|
||||
uniform vec2 u_MaterialInfo;
|
||||
#endif
|
||||
|
||||
varying vec2 var_DiffuseTex;
|
||||
#if defined(USE_LIGHTMAP)
|
||||
varying vec2 var_LightTex;
|
||||
#endif
|
||||
varying vec4 var_Color;
|
||||
|
||||
#if defined(USE_NORMALMAP) && !defined(USE_VERT_TANGENT_SPACE)
|
||||
varying vec3 var_Position;
|
||||
#endif
|
||||
|
||||
varying vec3 var_SampleToView;
|
||||
|
||||
#if !defined(USE_FAST_LIGHT)
|
||||
varying vec3 var_Normal;
|
||||
#endif
|
||||
|
||||
#if defined(USE_VERT_TANGENT_SPACE)
|
||||
varying vec3 var_Tangent;
|
||||
varying vec3 var_Bitangent;
|
||||
#endif
|
||||
|
||||
varying vec3 var_VertLight;
|
||||
|
||||
#if defined(USE_LIGHT) && !defined(USE_DELUXEMAP)
|
||||
varying vec3 var_WorldLight;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT_VECTOR) && !defined(USE_FAST_LIGHT) && defined(USE_SHADOWMAP)
|
||||
varying vec4 var_ScreenPos;
|
||||
#endif
|
||||
|
||||
#define EPSILON 0.00000001
|
||||
|
||||
#if defined(USE_PARALLAXMAP)
|
||||
float SampleHeight(sampler2D normalMap, vec2 t)
|
||||
{
|
||||
#if defined(SWIZZLE_NORMALMAP)
|
||||
return texture2D(normalMap, t).r;
|
||||
#else
|
||||
return texture2D(normalMap, t).a;
|
||||
#endif
|
||||
}
|
||||
|
||||
float RayIntersectDisplaceMap(vec2 dp, vec2 ds, sampler2D normalMap)
|
||||
{
|
||||
const int linearSearchSteps = 16;
|
||||
const int binarySearchSteps = 6;
|
||||
|
||||
float depthStep = 1.0 / float(linearSearchSteps);
|
||||
|
||||
// current size of search window
|
||||
float size = depthStep;
|
||||
|
||||
// current depth position
|
||||
float depth = 0.0;
|
||||
|
||||
// best match found (starts with last position 1.0)
|
||||
float bestDepth = 1.0;
|
||||
|
||||
// search front to back for first point inside object
|
||||
for(int i = 0; i < linearSearchSteps - 1; ++i)
|
||||
{
|
||||
depth += size;
|
||||
|
||||
float t = 1.0 - SampleHeight(normalMap, dp + ds * depth);
|
||||
|
||||
if(bestDepth > 0.996) // if no depth found yet
|
||||
if(depth >= t)
|
||||
bestDepth = depth; // store best depth
|
||||
}
|
||||
|
||||
depth = bestDepth;
|
||||
|
||||
// recurse around first point (depth) for closest match
|
||||
for(int i = 0; i < binarySearchSteps; ++i)
|
||||
{
|
||||
size *= 0.5;
|
||||
|
||||
float t = 1.0 - SampleHeight(normalMap, dp + ds * depth);
|
||||
|
||||
if(depth >= t)
|
||||
{
|
||||
bestDepth = depth;
|
||||
depth -= 2.0 * size;
|
||||
}
|
||||
|
||||
depth += size;
|
||||
}
|
||||
|
||||
return bestDepth;
|
||||
}
|
||||
#endif
|
||||
|
||||
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)
|
||||
float gamma = dot(E, L) - NE * NL;
|
||||
float B = 2.22222 + 0.1 * shininess;
|
||||
|
||||
#if defined(USE_OREN_NAYAR)
|
||||
float A = 1.0 - 1.0 / (2.0 + 0.33 * shininess);
|
||||
gamma = clamp(gamma, 0.0, 1.0);
|
||||
#endif
|
||||
|
||||
#if defined(USE_TRIACE_OREN_NAYAR)
|
||||
float A = 1.0 - 1.0 / (2.0 + 0.65 * shininess);
|
||||
|
||||
if (gamma >= 0.0)
|
||||
#endif
|
||||
{
|
||||
B *= max(max(NL, NE), EPSILON);
|
||||
}
|
||||
|
||||
return (A + gamma / B) * (1.0 - fzero);
|
||||
#else
|
||||
return 1.0 - fzero;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(USE_SPECULARMAP)
|
||||
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)
|
||||
float blinn = pow(NH, shininess);
|
||||
#endif
|
||||
|
||||
#if defined(USE_BLINN)
|
||||
return blinn;
|
||||
#endif
|
||||
|
||||
#if defined(USE_COOK_TORRANCE) || defined (USE_TRIACE) || defined (USE_TORRANCE_SPARROW)
|
||||
float fresnel = fzero + (1.0 - fzero) * pow(1.0 - EH, 5);
|
||||
#endif
|
||||
|
||||
#if defined(USE_COOK_TORRANCE) || defined(USE_TORRANCE_SPARROW)
|
||||
float geo = 2.0 * NH * min(NE, NL);
|
||||
geo /= max(EH, geo);
|
||||
#endif
|
||||
|
||||
#if defined(USE_COOK_TORRANCE)
|
||||
float m_sq = 2.0 / max(shininess, EPSILON);
|
||||
float NH_sq = NH * NH;
|
||||
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);
|
||||
|
||||
return fresnel * geo * beckmann / max(NE, EPSILON);
|
||||
#endif
|
||||
|
||||
#if defined(USE_TRIACE)
|
||||
float scale = 0.1248582 * shininess + 0.2691817;
|
||||
|
||||
return fresnel * scale * blinn / max(max(NL, NE), EPSILON);
|
||||
#endif
|
||||
|
||||
#if defined(USE_TORRANCE_SPARROW)
|
||||
float scale = 0.125 * shininess + 1.0;
|
||||
|
||||
return fresnel * geo * scale * blinn / max(NE, EPSILON);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
#if !defined(USE_FAST_LIGHT) && (defined(USE_LIGHT) || defined(USE_NORMALMAP))
|
||||
vec3 surfNormal = normalize(var_Normal);
|
||||
#endif
|
||||
|
||||
#if defined(USE_DELUXEMAP)
|
||||
vec3 worldLight = 2.0 * texture2D(u_DeluxeMap, var_LightTex).xyz - vec3(1.0);
|
||||
//worldLight += var_WorldLight * 0.0001;
|
||||
#elif defined(USE_LIGHT)
|
||||
vec3 worldLight = var_WorldLight;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHTMAP)
|
||||
vec4 lightSample = texture2D(u_LightMap, var_LightTex).rgba;
|
||||
#if defined(RGBE_LIGHTMAP)
|
||||
lightSample.rgb *= exp2(lightSample.a * 255.0 - 128.0);
|
||||
#endif
|
||||
vec3 directedLight = lightSample.rgb;
|
||||
#elif defined(USE_LIGHT_VECTOR) && !defined(USE_FAST_LIGHT)
|
||||
#if defined(USE_INVSQRLIGHT)
|
||||
float intensity = 1.0 / dot(worldLight, worldLight);
|
||||
#else
|
||||
float intensity = clamp((1.0 - dot(worldLight, worldLight) / (u_LightRadius * u_LightRadius)) * 1.07, 0.0, 1.0);
|
||||
#endif
|
||||
|
||||
vec3 directedLight = u_DirectedLight * intensity;
|
||||
vec3 ambientLight = u_AmbientLight;
|
||||
|
||||
#if defined(USE_SHADOWMAP)
|
||||
//vec2 shadowTex = gl_FragCoord.xy * r_FBufScale;
|
||||
vec2 shadowTex = var_ScreenPos.xy / var_ScreenPos.w;
|
||||
directedLight *= texture2D(u_ShadowMap, shadowTex).r;
|
||||
#endif
|
||||
#elif defined(USE_LIGHT_VERTEX) && !defined(USE_FAST_LIGHT)
|
||||
vec3 directedLight = var_VertLight;
|
||||
#endif
|
||||
|
||||
#if defined(USE_TCGEN) || defined(USE_NORMALMAP) || (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT))
|
||||
vec3 SampleToView = normalize(var_SampleToView);
|
||||
#endif
|
||||
vec2 tex = var_DiffuseTex;
|
||||
|
||||
float ambientDiff = 1.0;
|
||||
|
||||
#if defined(USE_NORMALMAP)
|
||||
#if defined(USE_VERT_TANGENT_SPACE)
|
||||
vec3 tangent = var_Tangent;
|
||||
vec3 bitangent = var_Bitangent;
|
||||
#else
|
||||
vec3 q0 = dFdx(var_Position);
|
||||
vec3 q1 = dFdy(var_Position);
|
||||
vec2 st0 = dFdx(tex);
|
||||
vec2 st1 = dFdy(tex);
|
||||
float dir = sign(st1.t * st0.s - st0.t * st1.s);
|
||||
|
||||
vec3 tangent = normalize( q0 * st1.t - q1 * st0.t) * dir;
|
||||
vec3 bitangent = -normalize( q0 * st1.s - q1 * st0.s) * dir;
|
||||
#endif
|
||||
|
||||
mat3 tangentToWorld = mat3(tangent, bitangent, var_Normal);
|
||||
|
||||
#if defined(USE_PARALLAXMAP)
|
||||
vec3 offsetDir = normalize(SampleToView * tangentToWorld);
|
||||
#if 0
|
||||
float height = SampleHeight(u_NormalMap, tex);
|
||||
float pdist = 0.05 * height - (0.05 / 2.0);
|
||||
#else
|
||||
offsetDir.xy *= -0.05 / offsetDir.z;
|
||||
float pdist = RayIntersectDisplaceMap(tex, offsetDir.xy, u_NormalMap);
|
||||
#endif
|
||||
tex += offsetDir.xy * pdist;
|
||||
#endif
|
||||
#if defined(SWIZZLE_NORMALMAP)
|
||||
vec3 normal = 2.0 * texture2D(u_NormalMap, tex).agb - 1.0;
|
||||
#else
|
||||
vec3 normal = 2.0 * texture2D(u_NormalMap, tex).rgb - 1.0;
|
||||
#endif
|
||||
normal.z = sqrt(clamp(1.0 - dot(normal.xy, normal.xy), 0.0, 1.0));
|
||||
vec3 worldNormal = tangentToWorld * normal;
|
||||
#if defined(r_normalAmbient)
|
||||
ambientDiff = 0.781341 * normal.z + 0.218659;
|
||||
#endif
|
||||
#elif defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
vec3 worldNormal = surfNormal;
|
||||
#endif
|
||||
|
||||
#if (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)) || (defined(USE_TCGEN) && defined(USE_NORMALMAP))
|
||||
worldNormal = normalize(worldNormal);
|
||||
#endif
|
||||
|
||||
#if defined(USE_TCGEN) && defined(USE_NORMALMAP)
|
||||
if (u_TCGen0 == TCGEN_ENVIRONMENT_MAPPED)
|
||||
{
|
||||
tex = -reflect(normalize(SampleToView), worldNormal).yz * vec2(0.5, -0.5) + 0.5;
|
||||
}
|
||||
#endif
|
||||
|
||||
vec4 diffuse = texture2D(u_DiffuseMap, tex);
|
||||
|
||||
#if defined(USE_LIGHT) && defined(USE_FAST_LIGHT)
|
||||
#if defined(USE_LIGHTMAP)
|
||||
diffuse.rgb *= directedLight;
|
||||
#endif
|
||||
#elif defined(USE_LIGHT)
|
||||
worldLight = normalize(worldLight);
|
||||
|
||||
#if defined(USE_LIGHTMAP) || defined(USE_LIGHT_VERTEX)
|
||||
#if defined(r_normalAmbient)
|
||||
vec3 ambientLight = directedLight * r_normalAmbient;
|
||||
directedLight -= ambientLight;
|
||||
#else
|
||||
vec3 ambientLight = vec3(0.0);
|
||||
#endif
|
||||
directedLight /= max(dot(surfNormal, worldLight), 0.004);
|
||||
#endif
|
||||
|
||||
float NL = clamp(dot(worldNormal, worldLight), 0.0, 1.0);
|
||||
float surfNL = clamp(dot(surfNormal, worldLight), 0.0, 1.0);
|
||||
NL = min(NL, surfNL * 2.0);
|
||||
float NE = clamp(dot(worldNormal, SampleToView), 0.0, 1.0);
|
||||
|
||||
float fzero = u_MaterialInfo.x;
|
||||
float shininess = u_MaterialInfo.y;
|
||||
#if defined(USE_SPECULARMAP)
|
||||
vec4 specular = texture2D(u_SpecularMap, tex);
|
||||
//specular.rgb = clamp(specular.rgb - diffuse.rgb, 0.0, 1.0);
|
||||
shininess *= specular.a;
|
||||
#endif
|
||||
float directedDiff = NL * CalcDiffuse(worldNormal, worldLight, SampleToView, NE, NL, fzero, shininess);
|
||||
diffuse.rgb *= directedLight * directedDiff + ambientDiff * ambientLight;
|
||||
|
||||
#if defined(USE_SPECULARMAP)
|
||||
vec3 halfAngle = normalize(worldLight + SampleToView);
|
||||
|
||||
float EH = clamp(dot(SampleToView, 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);
|
||||
|
||||
#if defined(r_normalAmbient)
|
||||
vec3 ambientHalf = normalize(surfNormal + SampleToView);
|
||||
float ambientSpec = max(dot(ambientHalf, worldNormal) + 0.5, 0.0);
|
||||
ambientSpec *= ambientSpec * 0.44;
|
||||
ambientSpec = pow(ambientSpec, shininess) * fzero;
|
||||
specular.rgb *= directedSpec * directedLight + ambientSpec * ambientLight;
|
||||
#else
|
||||
specular.rgb *= directedSpec * directedLight;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
gl_FragColor = diffuse;
|
||||
|
||||
#if defined(USE_SPECULARMAP) && defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
gl_FragColor.rgb += specular.rgb;
|
||||
#endif
|
||||
|
||||
gl_FragColor *= var_Color;
|
||||
}
|
||||
uniform sampler2D u_DiffuseMap;
|
||||
|
||||
#if defined(USE_LIGHTMAP)
|
||||
uniform sampler2D u_LightMap;
|
||||
#endif
|
||||
|
||||
#if defined(USE_NORMALMAP)
|
||||
uniform sampler2D u_NormalMap;
|
||||
#endif
|
||||
|
||||
#if defined(USE_DELUXEMAP)
|
||||
uniform sampler2D u_DeluxeMap;
|
||||
#endif
|
||||
|
||||
#if defined(USE_SPECULARMAP)
|
||||
uniform sampler2D u_SpecularMap;
|
||||
#endif
|
||||
|
||||
#if defined(USE_SHADOWMAP)
|
||||
uniform sampler2D u_ShadowMap;
|
||||
#endif
|
||||
|
||||
uniform vec3 u_ViewOrigin;
|
||||
|
||||
#if defined(USE_TCGEN)
|
||||
uniform int u_TCGen0;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT_VECTOR)
|
||||
uniform vec3 u_DirectedLight;
|
||||
uniform vec3 u_AmbientLight;
|
||||
uniform float u_LightRadius;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT)
|
||||
uniform vec2 u_MaterialInfo;
|
||||
#endif
|
||||
|
||||
varying vec2 var_DiffuseTex;
|
||||
#if defined(USE_LIGHTMAP)
|
||||
varying vec2 var_LightTex;
|
||||
#endif
|
||||
varying vec4 var_Color;
|
||||
|
||||
#if defined(USE_NORMALMAP) && !defined(USE_VERT_TANGENT_SPACE)
|
||||
varying vec3 var_Position;
|
||||
#endif
|
||||
|
||||
varying vec3 var_SampleToView;
|
||||
|
||||
#if !defined(USE_FAST_LIGHT)
|
||||
varying vec3 var_Normal;
|
||||
#endif
|
||||
|
||||
#if defined(USE_VERT_TANGENT_SPACE)
|
||||
varying vec3 var_Tangent;
|
||||
varying vec3 var_Bitangent;
|
||||
#endif
|
||||
|
||||
varying vec3 var_VertLight;
|
||||
|
||||
#if defined(USE_LIGHT) && !defined(USE_DELUXEMAP)
|
||||
varying vec3 var_WorldLight;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT_VECTOR) && !defined(USE_FAST_LIGHT) && defined(USE_SHADOWMAP)
|
||||
varying vec4 var_ScreenPos;
|
||||
#endif
|
||||
|
||||
#define EPSILON 0.00000001
|
||||
|
||||
#if defined(USE_PARALLAXMAP)
|
||||
float SampleHeight(sampler2D normalMap, vec2 t)
|
||||
{
|
||||
#if defined(SWIZZLE_NORMALMAP)
|
||||
return texture2D(normalMap, t).r;
|
||||
#else
|
||||
return texture2D(normalMap, t).a;
|
||||
#endif
|
||||
}
|
||||
|
||||
float RayIntersectDisplaceMap(vec2 dp, vec2 ds, sampler2D normalMap)
|
||||
{
|
||||
const int linearSearchSteps = 16;
|
||||
const int binarySearchSteps = 6;
|
||||
|
||||
float depthStep = 1.0 / float(linearSearchSteps);
|
||||
|
||||
// current size of search window
|
||||
float size = depthStep;
|
||||
|
||||
// current depth position
|
||||
float depth = 0.0;
|
||||
|
||||
// best match found (starts with last position 1.0)
|
||||
float bestDepth = 1.0;
|
||||
|
||||
// search front to back for first point inside object
|
||||
for(int i = 0; i < linearSearchSteps - 1; ++i)
|
||||
{
|
||||
depth += size;
|
||||
|
||||
float t = 1.0 - SampleHeight(normalMap, dp + ds * depth);
|
||||
|
||||
if(bestDepth > 0.996) // if no depth found yet
|
||||
if(depth >= t)
|
||||
bestDepth = depth; // store best depth
|
||||
}
|
||||
|
||||
depth = bestDepth;
|
||||
|
||||
// recurse around first point (depth) for closest match
|
||||
for(int i = 0; i < binarySearchSteps; ++i)
|
||||
{
|
||||
size *= 0.5;
|
||||
|
||||
float t = 1.0 - SampleHeight(normalMap, dp + ds * depth);
|
||||
|
||||
if(depth >= t)
|
||||
{
|
||||
bestDepth = depth;
|
||||
depth -= 2.0 * size;
|
||||
}
|
||||
|
||||
depth += size;
|
||||
}
|
||||
|
||||
return bestDepth;
|
||||
}
|
||||
#endif
|
||||
|
||||
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)
|
||||
float gamma = dot(E, L) - NE * NL;
|
||||
float B = 2.22222 + 0.1 * shininess;
|
||||
|
||||
#if defined(USE_OREN_NAYAR)
|
||||
float A = 1.0 - 1.0 / (2.0 + 0.33 * shininess);
|
||||
gamma = clamp(gamma, 0.0, 1.0);
|
||||
#endif
|
||||
|
||||
#if defined(USE_TRIACE_OREN_NAYAR)
|
||||
float A = 1.0 - 1.0 / (2.0 + 0.65 * shininess);
|
||||
|
||||
if (gamma >= 0.0)
|
||||
#endif
|
||||
{
|
||||
B *= max(max(NL, NE), EPSILON);
|
||||
}
|
||||
|
||||
return (A + gamma / B) * (1.0 - fzero);
|
||||
#else
|
||||
return 1.0 - fzero;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(USE_SPECULARMAP)
|
||||
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)
|
||||
float blinn = pow(NH, shininess);
|
||||
#endif
|
||||
|
||||
#if defined(USE_BLINN)
|
||||
return blinn;
|
||||
#endif
|
||||
|
||||
#if defined(USE_COOK_TORRANCE) || defined (USE_TRIACE) || defined (USE_TORRANCE_SPARROW)
|
||||
float fresnel = fzero + (1.0 - fzero) * pow(1.0 - EH, 5);
|
||||
#endif
|
||||
|
||||
#if defined(USE_COOK_TORRANCE) || defined(USE_TORRANCE_SPARROW)
|
||||
float geo = 2.0 * NH * min(NE, NL);
|
||||
geo /= max(EH, geo);
|
||||
#endif
|
||||
|
||||
#if defined(USE_COOK_TORRANCE)
|
||||
float m_sq = 2.0 / max(shininess, EPSILON);
|
||||
float NH_sq = NH * NH;
|
||||
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);
|
||||
|
||||
return fresnel * geo * beckmann / max(NE, EPSILON);
|
||||
#endif
|
||||
|
||||
#if defined(USE_TRIACE)
|
||||
float scale = 0.1248582 * shininess + 0.2691817;
|
||||
|
||||
return fresnel * scale * blinn / max(max(NL, NE), EPSILON);
|
||||
#endif
|
||||
|
||||
#if defined(USE_TORRANCE_SPARROW)
|
||||
float scale = 0.125 * shininess + 1.0;
|
||||
|
||||
return fresnel * geo * scale * blinn / max(NE, EPSILON);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
#if !defined(USE_FAST_LIGHT) && (defined(USE_LIGHT) || defined(USE_NORMALMAP))
|
||||
vec3 surfNormal = normalize(var_Normal);
|
||||
#endif
|
||||
|
||||
#if defined(USE_DELUXEMAP)
|
||||
vec3 worldLight = 2.0 * texture2D(u_DeluxeMap, var_LightTex).xyz - vec3(1.0);
|
||||
//worldLight += var_WorldLight * 0.0001;
|
||||
#elif defined(USE_LIGHT)
|
||||
vec3 worldLight = var_WorldLight;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHTMAP)
|
||||
vec4 lightSample = texture2D(u_LightMap, var_LightTex).rgba;
|
||||
#if defined(RGBE_LIGHTMAP)
|
||||
lightSample.rgb *= exp2(lightSample.a * 255.0 - 128.0);
|
||||
#endif
|
||||
vec3 directedLight = lightSample.rgb;
|
||||
#elif defined(USE_LIGHT_VECTOR) && !defined(USE_FAST_LIGHT)
|
||||
#if defined(USE_INVSQRLIGHT)
|
||||
float intensity = 1.0 / dot(worldLight, worldLight);
|
||||
#else
|
||||
float intensity = clamp((1.0 - dot(worldLight, worldLight) / (u_LightRadius * u_LightRadius)) * 1.07, 0.0, 1.0);
|
||||
#endif
|
||||
|
||||
vec3 directedLight = u_DirectedLight * intensity;
|
||||
vec3 ambientLight = u_AmbientLight;
|
||||
|
||||
#if defined(USE_SHADOWMAP)
|
||||
//vec2 shadowTex = gl_FragCoord.xy * r_FBufScale;
|
||||
vec2 shadowTex = var_ScreenPos.xy / var_ScreenPos.w;
|
||||
directedLight *= texture2D(u_ShadowMap, shadowTex).r;
|
||||
#endif
|
||||
#elif defined(USE_LIGHT_VERTEX) && !defined(USE_FAST_LIGHT)
|
||||
vec3 directedLight = var_VertLight;
|
||||
#endif
|
||||
|
||||
#if defined(USE_TCGEN) || defined(USE_NORMALMAP) || (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT))
|
||||
vec3 SampleToView = normalize(var_SampleToView);
|
||||
#endif
|
||||
vec2 tex = var_DiffuseTex;
|
||||
|
||||
float ambientDiff = 1.0;
|
||||
|
||||
#if defined(USE_NORMALMAP)
|
||||
#if defined(USE_VERT_TANGENT_SPACE)
|
||||
vec3 tangent = var_Tangent;
|
||||
vec3 bitangent = var_Bitangent;
|
||||
#else
|
||||
vec3 q0 = dFdx(var_Position);
|
||||
vec3 q1 = dFdy(var_Position);
|
||||
vec2 st0 = dFdx(tex);
|
||||
vec2 st1 = dFdy(tex);
|
||||
float dir = sign(st1.t * st0.s - st0.t * st1.s);
|
||||
|
||||
vec3 tangent = normalize( q0 * st1.t - q1 * st0.t) * dir;
|
||||
vec3 bitangent = -normalize( q0 * st1.s - q1 * st0.s) * dir;
|
||||
#endif
|
||||
|
||||
mat3 tangentToWorld = mat3(tangent, bitangent, var_Normal);
|
||||
|
||||
#if defined(USE_PARALLAXMAP)
|
||||
vec3 offsetDir = normalize(SampleToView * tangentToWorld);
|
||||
#if 0
|
||||
float height = SampleHeight(u_NormalMap, tex);
|
||||
float pdist = 0.05 * height - (0.05 / 2.0);
|
||||
#else
|
||||
offsetDir.xy *= -0.05 / offsetDir.z;
|
||||
float pdist = RayIntersectDisplaceMap(tex, offsetDir.xy, u_NormalMap);
|
||||
#endif
|
||||
tex += offsetDir.xy * pdist;
|
||||
#endif
|
||||
#if defined(SWIZZLE_NORMALMAP)
|
||||
vec3 normal = 2.0 * texture2D(u_NormalMap, tex).agb - 1.0;
|
||||
#else
|
||||
vec3 normal = 2.0 * texture2D(u_NormalMap, tex).rgb - 1.0;
|
||||
#endif
|
||||
normal.z = sqrt(clamp(1.0 - dot(normal.xy, normal.xy), 0.0, 1.0));
|
||||
vec3 worldNormal = tangentToWorld * normal;
|
||||
#if defined(r_normalAmbient)
|
||||
ambientDiff = 0.781341 * normal.z + 0.218659;
|
||||
#endif
|
||||
#elif defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
vec3 worldNormal = surfNormal;
|
||||
#endif
|
||||
|
||||
#if (defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)) || (defined(USE_TCGEN) && defined(USE_NORMALMAP))
|
||||
worldNormal = normalize(worldNormal);
|
||||
#endif
|
||||
|
||||
#if defined(USE_TCGEN) && defined(USE_NORMALMAP)
|
||||
if (u_TCGen0 == TCGEN_ENVIRONMENT_MAPPED)
|
||||
{
|
||||
tex = -reflect(normalize(SampleToView), worldNormal).yz * vec2(0.5, -0.5) + 0.5;
|
||||
}
|
||||
#endif
|
||||
|
||||
vec4 diffuse = texture2D(u_DiffuseMap, tex);
|
||||
|
||||
#if defined(USE_LIGHT) && defined(USE_FAST_LIGHT)
|
||||
#if defined(USE_LIGHTMAP)
|
||||
diffuse.rgb *= directedLight;
|
||||
#endif
|
||||
#elif defined(USE_LIGHT)
|
||||
worldLight = normalize(worldLight);
|
||||
|
||||
#if defined(USE_LIGHTMAP) || defined(USE_LIGHT_VERTEX)
|
||||
#if defined(r_normalAmbient)
|
||||
vec3 ambientLight = directedLight * r_normalAmbient;
|
||||
directedLight -= ambientLight;
|
||||
#else
|
||||
vec3 ambientLight = vec3(0.0);
|
||||
#endif
|
||||
directedLight /= max(dot(surfNormal, worldLight), 0.004);
|
||||
#endif
|
||||
|
||||
float NL = clamp(dot(worldNormal, worldLight), 0.0, 1.0);
|
||||
float surfNL = clamp(dot(surfNormal, worldLight), 0.0, 1.0);
|
||||
NL = min(NL, surfNL * 2.0);
|
||||
float NE = clamp(dot(worldNormal, SampleToView), 0.0, 1.0);
|
||||
|
||||
float fzero = u_MaterialInfo.x;
|
||||
float shininess = u_MaterialInfo.y;
|
||||
#if defined(USE_SPECULARMAP)
|
||||
vec4 specular = texture2D(u_SpecularMap, tex);
|
||||
//specular.rgb = clamp(specular.rgb - diffuse.rgb, 0.0, 1.0);
|
||||
shininess *= specular.a;
|
||||
#endif
|
||||
float directedDiff = NL * CalcDiffuse(worldNormal, worldLight, SampleToView, NE, NL, fzero, shininess);
|
||||
diffuse.rgb *= directedLight * directedDiff + ambientDiff * ambientLight;
|
||||
|
||||
#if defined(USE_SPECULARMAP)
|
||||
vec3 halfAngle = normalize(worldLight + SampleToView);
|
||||
|
||||
float EH = clamp(dot(SampleToView, 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);
|
||||
|
||||
#if defined(r_normalAmbient)
|
||||
vec3 ambientHalf = normalize(surfNormal + SampleToView);
|
||||
float ambientSpec = max(dot(ambientHalf, worldNormal) + 0.5, 0.0);
|
||||
ambientSpec *= ambientSpec * 0.44;
|
||||
ambientSpec = pow(ambientSpec, shininess) * fzero;
|
||||
specular.rgb *= directedSpec * directedLight + ambientSpec * ambientLight;
|
||||
#else
|
||||
specular.rgb *= directedSpec * directedLight;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
gl_FragColor = diffuse;
|
||||
|
||||
#if defined(USE_SPECULARMAP) && defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
gl_FragColor.rgb += specular.rgb;
|
||||
#endif
|
||||
|
||||
gl_FragColor *= var_Color;
|
||||
}
|
||||
|
|
|
@ -1,227 +1,227 @@
|
|||
attribute vec4 attr_TexCoord0;
|
||||
#if defined(USE_LIGHTMAP)
|
||||
attribute vec4 attr_TexCoord1;
|
||||
#endif
|
||||
attribute vec4 attr_Color;
|
||||
|
||||
attribute vec4 attr_Position;
|
||||
attribute vec3 attr_Normal;
|
||||
|
||||
#if defined(USE_VERT_TANGENT_SPACE)
|
||||
attribute vec3 attr_Tangent;
|
||||
attribute vec3 attr_Bitangent;
|
||||
#endif
|
||||
|
||||
#if defined(USE_VERTEX_ANIMATION)
|
||||
attribute vec4 attr_Position2;
|
||||
attribute vec3 attr_Normal2;
|
||||
#if defined(USE_VERT_TANGENT_SPACE)
|
||||
attribute vec3 attr_Tangent2;
|
||||
attribute vec3 attr_Bitangent2;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT) && !defined(USE_LIGHT_VECTOR)
|
||||
attribute vec3 attr_LightDirection;
|
||||
#endif
|
||||
|
||||
#if defined(USE_TCGEN) || defined(USE_NORMALMAP) || defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
uniform vec3 u_ViewOrigin;
|
||||
#endif
|
||||
|
||||
#if defined(USE_TCGEN)
|
||||
uniform int u_TCGen0;
|
||||
#endif
|
||||
|
||||
#if defined(USE_TCMOD)
|
||||
uniform vec4 u_DiffuseTexMatrix;
|
||||
uniform vec4 u_DiffuseTexOffTurb;
|
||||
#endif
|
||||
|
||||
uniform mat4 u_ModelViewProjectionMatrix;
|
||||
uniform vec4 u_BaseColor;
|
||||
uniform vec4 u_VertColor;
|
||||
|
||||
#if defined(USE_MODELMATRIX)
|
||||
uniform mat4 u_ModelMatrix;
|
||||
#endif
|
||||
|
||||
#if defined(USE_VERTEX_ANIMATION)
|
||||
uniform float u_VertexLerp;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT_VECTOR)
|
||||
uniform vec4 u_LightOrigin;
|
||||
#if defined(USE_FAST_LIGHT)
|
||||
uniform vec3 u_DirectedLight;
|
||||
uniform vec3 u_AmbientLight;
|
||||
uniform float u_LightRadius;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
varying vec2 var_DiffuseTex;
|
||||
|
||||
#if defined(USE_LIGHTMAP)
|
||||
varying vec2 var_LightTex;
|
||||
#endif
|
||||
|
||||
#if defined(USE_NORMALMAP) || defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
varying vec3 var_SampleToView;
|
||||
#endif
|
||||
|
||||
varying vec4 var_Color;
|
||||
|
||||
#if defined(USE_NORMALMAP) && !defined(USE_VERT_TANGENT_SPACE)
|
||||
varying vec3 var_Position;
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(USE_FAST_LIGHT)
|
||||
varying vec3 var_Normal;
|
||||
#if defined(USE_VERT_TANGENT_SPACE)
|
||||
varying vec3 var_Tangent;
|
||||
varying vec3 var_Bitangent;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT_VERTEX) && !defined(USE_FAST_LIGHT)
|
||||
varying vec3 var_VertLight;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT) && !defined(USE_DELUXEMAP) && !defined(USE_FAST_LIGHT)
|
||||
varying vec3 var_WorldLight;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT_VECTOR) && !defined(USE_FAST_LIGHT) && defined(USE_SHADOWMAP)
|
||||
varying vec4 var_ScreenPos;
|
||||
#endif
|
||||
|
||||
#if defined(USE_TCMOD)
|
||||
vec2 ModTexCoords(vec2 st, vec3 position, vec4 texMatrix, vec4 offTurb)
|
||||
{
|
||||
float amplitude = offTurb.z;
|
||||
float phase = offTurb.w;
|
||||
vec2 st2 = vec2(dot(st, texMatrix.xz), dot(st, texMatrix.yw)) + offTurb.xy;
|
||||
|
||||
vec3 offsetPos = position / 1024.0;
|
||||
offsetPos.x += offsetPos.z;
|
||||
|
||||
vec2 texOffset = sin((offsetPos.xy + vec2(phase)) * 2.0 * M_PI);
|
||||
|
||||
return st2 + texOffset * amplitude;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
#if defined(USE_VERTEX_ANIMATION)
|
||||
vec4 position = mix(attr_Position, attr_Position2, u_VertexLerp);
|
||||
vec3 normal = normalize(mix(attr_Normal, attr_Normal2, u_VertexLerp));
|
||||
#if defined(USE_VERT_TANGENT_SPACE)
|
||||
vec3 tangent = normalize(mix(attr_Tangent, attr_Tangent2, u_VertexLerp));
|
||||
vec3 bitangent = normalize(mix(attr_Bitangent, attr_Bitangent2, u_VertexLerp));
|
||||
#endif
|
||||
#else
|
||||
vec4 position = attr_Position;
|
||||
vec3 normal = attr_Normal;
|
||||
#if defined(USE_VERT_TANGENT_SPACE)
|
||||
vec3 tangent = attr_Tangent;
|
||||
vec3 bitangent = attr_Bitangent;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
gl_Position = u_ModelViewProjectionMatrix * position;
|
||||
|
||||
#if defined(USE_LIGHT_VECTOR) && !defined(USE_FAST_LIGHT) && defined(USE_SHADOWMAP)
|
||||
var_ScreenPos = gl_Position + vec2(1.0, 0.0).xxyx * gl_Position.w;
|
||||
#endif
|
||||
|
||||
#if (defined(USE_LIGHTMAP) || defined(USE_LIGHT_VERTEX)) && !defined(USE_DELUXEMAP) && !defined(USE_FAST_LIGHT)
|
||||
vec3 worldLight = attr_LightDirection;
|
||||
#endif
|
||||
|
||||
#if defined(USE_MODELMATRIX)
|
||||
position = u_ModelMatrix * position;
|
||||
normal = (u_ModelMatrix * vec4(normal, 0.0)).xyz;
|
||||
#if defined(USE_VERT_TANGENT_SPACE)
|
||||
tangent = (u_ModelMatrix * vec4(tangent, 0.0)).xyz;
|
||||
bitangent = (u_ModelMatrix * vec4(bitangent, 0.0)).xyz;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHTMAP) && !defined(USE_DELUXEMAP) && !defined(USE_FAST_LIGHT)
|
||||
worldLight = (u_ModelMatrix * vec4(worldLight, 0.0)).xyz;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(USE_NORMALMAP) && !defined(USE_VERT_TANGENT_SPACE)
|
||||
var_Position = position.xyz;
|
||||
#endif
|
||||
|
||||
#if defined(USE_TCGEN) || defined(USE_NORMALMAP) || defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
vec3 SampleToView = u_ViewOrigin - position.xyz;
|
||||
#endif
|
||||
|
||||
#if defined(USE_NORMALMAP) || defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
var_SampleToView = SampleToView;
|
||||
#endif
|
||||
|
||||
vec2 tex;
|
||||
|
||||
#if defined(USE_TCGEN)
|
||||
if (u_TCGen0 == TCGEN_ENVIRONMENT_MAPPED)
|
||||
{
|
||||
tex = -reflect(normalize(SampleToView), normal).yz * vec2(0.5, -0.5) + 0.5;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
tex = attr_TexCoord0.st;
|
||||
}
|
||||
|
||||
#if defined(USE_TCMOD)
|
||||
var_DiffuseTex = ModTexCoords(tex, position.xyz, u_DiffuseTexMatrix, u_DiffuseTexOffTurb);
|
||||
#else
|
||||
var_DiffuseTex = tex;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHTMAP)
|
||||
var_LightTex = attr_TexCoord1.st;
|
||||
#endif
|
||||
|
||||
#if !defined(USE_FAST_LIGHT)
|
||||
var_Normal = normal;
|
||||
#if defined(USE_VERT_TANGENT_SPACE)
|
||||
var_Tangent = tangent;
|
||||
var_Bitangent = bitangent;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT) && !defined(USE_DELUXEMAP)
|
||||
#if defined(USE_LIGHT_VECTOR)
|
||||
vec3 worldLight = u_LightOrigin.xyz - (position.xyz * u_LightOrigin.w);
|
||||
#endif
|
||||
#if !defined(USE_FAST_LIGHT)
|
||||
var_WorldLight = worldLight;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT_VERTEX) && !defined(USE_FAST_LIGHT)
|
||||
var_VertLight = u_VertColor.rgb * attr_Color.rgb;
|
||||
var_Color.rgb = vec3(1.0);
|
||||
var_Color.a = u_VertColor.a * attr_Color.a + u_BaseColor.a;
|
||||
#else
|
||||
var_Color = u_VertColor * attr_Color + u_BaseColor;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT_VECTOR) && defined(USE_FAST_LIGHT)
|
||||
#if defined(USE_INVSQRLIGHT)
|
||||
float intensity = 1.0 / dot(worldLight, worldLight);
|
||||
#else
|
||||
float intensity = clamp((1.0 - dot(worldLight, worldLight) / (u_LightRadius * u_LightRadius)) * 1.07, 0.0, 1.0);
|
||||
#endif
|
||||
float NL = clamp(dot(normal, normalize(worldLight)), 0.0, 1.0);
|
||||
|
||||
var_Color.rgb *= u_DirectedLight * intensity * NL + u_AmbientLight;
|
||||
#endif
|
||||
}
|
||||
attribute vec4 attr_TexCoord0;
|
||||
#if defined(USE_LIGHTMAP)
|
||||
attribute vec4 attr_TexCoord1;
|
||||
#endif
|
||||
attribute vec4 attr_Color;
|
||||
|
||||
attribute vec4 attr_Position;
|
||||
attribute vec3 attr_Normal;
|
||||
|
||||
#if defined(USE_VERT_TANGENT_SPACE)
|
||||
attribute vec3 attr_Tangent;
|
||||
attribute vec3 attr_Bitangent;
|
||||
#endif
|
||||
|
||||
#if defined(USE_VERTEX_ANIMATION)
|
||||
attribute vec4 attr_Position2;
|
||||
attribute vec3 attr_Normal2;
|
||||
#if defined(USE_VERT_TANGENT_SPACE)
|
||||
attribute vec3 attr_Tangent2;
|
||||
attribute vec3 attr_Bitangent2;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT) && !defined(USE_LIGHT_VECTOR)
|
||||
attribute vec3 attr_LightDirection;
|
||||
#endif
|
||||
|
||||
#if defined(USE_TCGEN) || defined(USE_NORMALMAP) || defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
uniform vec3 u_ViewOrigin;
|
||||
#endif
|
||||
|
||||
#if defined(USE_TCGEN)
|
||||
uniform int u_TCGen0;
|
||||
#endif
|
||||
|
||||
#if defined(USE_TCMOD)
|
||||
uniform vec4 u_DiffuseTexMatrix;
|
||||
uniform vec4 u_DiffuseTexOffTurb;
|
||||
#endif
|
||||
|
||||
uniform mat4 u_ModelViewProjectionMatrix;
|
||||
uniform vec4 u_BaseColor;
|
||||
uniform vec4 u_VertColor;
|
||||
|
||||
#if defined(USE_MODELMATRIX)
|
||||
uniform mat4 u_ModelMatrix;
|
||||
#endif
|
||||
|
||||
#if defined(USE_VERTEX_ANIMATION)
|
||||
uniform float u_VertexLerp;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT_VECTOR)
|
||||
uniform vec4 u_LightOrigin;
|
||||
#if defined(USE_FAST_LIGHT)
|
||||
uniform vec3 u_DirectedLight;
|
||||
uniform vec3 u_AmbientLight;
|
||||
uniform float u_LightRadius;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
varying vec2 var_DiffuseTex;
|
||||
|
||||
#if defined(USE_LIGHTMAP)
|
||||
varying vec2 var_LightTex;
|
||||
#endif
|
||||
|
||||
#if defined(USE_NORMALMAP) || defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
varying vec3 var_SampleToView;
|
||||
#endif
|
||||
|
||||
varying vec4 var_Color;
|
||||
|
||||
#if defined(USE_NORMALMAP) && !defined(USE_VERT_TANGENT_SPACE)
|
||||
varying vec3 var_Position;
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(USE_FAST_LIGHT)
|
||||
varying vec3 var_Normal;
|
||||
#if defined(USE_VERT_TANGENT_SPACE)
|
||||
varying vec3 var_Tangent;
|
||||
varying vec3 var_Bitangent;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT_VERTEX) && !defined(USE_FAST_LIGHT)
|
||||
varying vec3 var_VertLight;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT) && !defined(USE_DELUXEMAP) && !defined(USE_FAST_LIGHT)
|
||||
varying vec3 var_WorldLight;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT_VECTOR) && !defined(USE_FAST_LIGHT) && defined(USE_SHADOWMAP)
|
||||
varying vec4 var_ScreenPos;
|
||||
#endif
|
||||
|
||||
#if defined(USE_TCMOD)
|
||||
vec2 ModTexCoords(vec2 st, vec3 position, vec4 texMatrix, vec4 offTurb)
|
||||
{
|
||||
float amplitude = offTurb.z;
|
||||
float phase = offTurb.w;
|
||||
vec2 st2 = vec2(dot(st, texMatrix.xz), dot(st, texMatrix.yw)) + offTurb.xy;
|
||||
|
||||
vec3 offsetPos = position / 1024.0;
|
||||
offsetPos.x += offsetPos.z;
|
||||
|
||||
vec2 texOffset = sin((offsetPos.xy + vec2(phase)) * 2.0 * M_PI);
|
||||
|
||||
return st2 + texOffset * amplitude;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
#if defined(USE_VERTEX_ANIMATION)
|
||||
vec4 position = mix(attr_Position, attr_Position2, u_VertexLerp);
|
||||
vec3 normal = normalize(mix(attr_Normal, attr_Normal2, u_VertexLerp));
|
||||
#if defined(USE_VERT_TANGENT_SPACE)
|
||||
vec3 tangent = normalize(mix(attr_Tangent, attr_Tangent2, u_VertexLerp));
|
||||
vec3 bitangent = normalize(mix(attr_Bitangent, attr_Bitangent2, u_VertexLerp));
|
||||
#endif
|
||||
#else
|
||||
vec4 position = attr_Position;
|
||||
vec3 normal = attr_Normal;
|
||||
#if defined(USE_VERT_TANGENT_SPACE)
|
||||
vec3 tangent = attr_Tangent;
|
||||
vec3 bitangent = attr_Bitangent;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
gl_Position = u_ModelViewProjectionMatrix * position;
|
||||
|
||||
#if defined(USE_LIGHT_VECTOR) && !defined(USE_FAST_LIGHT) && defined(USE_SHADOWMAP)
|
||||
var_ScreenPos = gl_Position + vec2(1.0, 0.0).xxyx * gl_Position.w;
|
||||
#endif
|
||||
|
||||
#if (defined(USE_LIGHTMAP) || defined(USE_LIGHT_VERTEX)) && !defined(USE_DELUXEMAP) && !defined(USE_FAST_LIGHT)
|
||||
vec3 worldLight = attr_LightDirection;
|
||||
#endif
|
||||
|
||||
#if defined(USE_MODELMATRIX)
|
||||
position = u_ModelMatrix * position;
|
||||
normal = (u_ModelMatrix * vec4(normal, 0.0)).xyz;
|
||||
#if defined(USE_VERT_TANGENT_SPACE)
|
||||
tangent = (u_ModelMatrix * vec4(tangent, 0.0)).xyz;
|
||||
bitangent = (u_ModelMatrix * vec4(bitangent, 0.0)).xyz;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHTMAP) && !defined(USE_DELUXEMAP) && !defined(USE_FAST_LIGHT)
|
||||
worldLight = (u_ModelMatrix * vec4(worldLight, 0.0)).xyz;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(USE_NORMALMAP) && !defined(USE_VERT_TANGENT_SPACE)
|
||||
var_Position = position.xyz;
|
||||
#endif
|
||||
|
||||
#if defined(USE_TCGEN) || defined(USE_NORMALMAP) || defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
vec3 SampleToView = u_ViewOrigin - position.xyz;
|
||||
#endif
|
||||
|
||||
#if defined(USE_NORMALMAP) || defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)
|
||||
var_SampleToView = SampleToView;
|
||||
#endif
|
||||
|
||||
vec2 tex;
|
||||
|
||||
#if defined(USE_TCGEN)
|
||||
if (u_TCGen0 == TCGEN_ENVIRONMENT_MAPPED)
|
||||
{
|
||||
tex = -reflect(normalize(SampleToView), normal).yz * vec2(0.5, -0.5) + 0.5;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
tex = attr_TexCoord0.st;
|
||||
}
|
||||
|
||||
#if defined(USE_TCMOD)
|
||||
var_DiffuseTex = ModTexCoords(tex, position.xyz, u_DiffuseTexMatrix, u_DiffuseTexOffTurb);
|
||||
#else
|
||||
var_DiffuseTex = tex;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHTMAP)
|
||||
var_LightTex = attr_TexCoord1.st;
|
||||
#endif
|
||||
|
||||
#if !defined(USE_FAST_LIGHT)
|
||||
var_Normal = normal;
|
||||
#if defined(USE_VERT_TANGENT_SPACE)
|
||||
var_Tangent = tangent;
|
||||
var_Bitangent = bitangent;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT) && !defined(USE_DELUXEMAP)
|
||||
#if defined(USE_LIGHT_VECTOR)
|
||||
vec3 worldLight = u_LightOrigin.xyz - (position.xyz * u_LightOrigin.w);
|
||||
#endif
|
||||
#if !defined(USE_FAST_LIGHT)
|
||||
var_WorldLight = worldLight;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT_VERTEX) && !defined(USE_FAST_LIGHT)
|
||||
var_VertLight = u_VertColor.rgb * attr_Color.rgb;
|
||||
var_Color.rgb = vec3(1.0);
|
||||
var_Color.a = u_VertColor.a * attr_Color.a + u_BaseColor.a;
|
||||
#else
|
||||
var_Color = u_VertColor * attr_Color + u_BaseColor;
|
||||
#endif
|
||||
|
||||
#if defined(USE_LIGHT_VECTOR) && defined(USE_FAST_LIGHT)
|
||||
#if defined(USE_INVSQRLIGHT)
|
||||
float intensity = 1.0 / dot(worldLight, worldLight);
|
||||
#else
|
||||
float intensity = clamp((1.0 - dot(worldLight, worldLight) / (u_LightRadius * u_LightRadius)) * 1.07, 0.0, 1.0);
|
||||
#endif
|
||||
float NL = clamp(dot(normal, normalize(worldLight)), 0.0, 1.0);
|
||||
|
||||
var_Color.rgb *= u_DirectedLight * intensity * NL + u_AmbientLight;
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -1,98 +1,98 @@
|
|||
uniform sampler2D u_ShadowMap;
|
||||
|
||||
uniform vec3 u_LightForward;
|
||||
uniform vec3 u_LightUp;
|
||||
uniform vec3 u_LightRight;
|
||||
uniform vec4 u_LightOrigin;
|
||||
uniform float u_LightRadius;
|
||||
varying vec3 var_Position;
|
||||
varying vec3 var_Normal;
|
||||
|
||||
float sampleDistMap(sampler2D texMap, vec2 uv, float scale)
|
||||
{
|
||||
vec3 distv = texture2D(texMap, uv).xyz;
|
||||
return dot(distv, vec3(1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0)) * scale;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 lightToPos = var_Position - u_LightOrigin.xyz;
|
||||
vec2 st = vec2(-dot(u_LightRight, lightToPos), dot(u_LightUp, lightToPos));
|
||||
|
||||
float fade = length(st);
|
||||
|
||||
#if defined(USE_DISCARD)
|
||||
if (fade >= 1.0)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
#endif
|
||||
|
||||
fade = clamp(8.0 - fade * 8.0, 0.0, 1.0);
|
||||
|
||||
st = st * 0.5 + vec2(0.5);
|
||||
|
||||
#if defined(USE_SOLID_PSHADOWS)
|
||||
float intensity = max(sign(u_LightRadius - length(lightToPos)), 0.0);
|
||||
#else
|
||||
float intensity = clamp((1.0 - dot(lightToPos, lightToPos) / (u_LightRadius * u_LightRadius)) * 2.0, 0.0, 1.0);
|
||||
#endif
|
||||
|
||||
float lightDist = length(lightToPos);
|
||||
float dist;
|
||||
|
||||
#if defined(USE_DISCARD)
|
||||
if (dot(u_LightForward, lightToPos) <= 0.0)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
|
||||
if (dot(var_Normal, lightToPos) > 0.0)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
#else
|
||||
intensity *= max(sign(dot(u_LightForward, lightToPos)), 0.0);
|
||||
intensity *= max(sign(-dot(var_Normal, lightToPos)), 0.0);
|
||||
#endif
|
||||
|
||||
intensity *= fade;
|
||||
#if defined(USE_PCF)
|
||||
float part;
|
||||
|
||||
dist = sampleDistMap(u_ShadowMap, st + vec2(-1.0/512.0, -1.0/512.0), u_LightRadius);
|
||||
part = max(sign(lightDist - dist), 0.0);
|
||||
|
||||
dist = sampleDistMap(u_ShadowMap, st + vec2( 1.0/512.0, -1.0/512.0), u_LightRadius);
|
||||
part += max(sign(lightDist - dist), 0.0);
|
||||
|
||||
dist = sampleDistMap(u_ShadowMap, st + vec2(-1.0/512.0, 1.0/512.0), u_LightRadius);
|
||||
part += max(sign(lightDist - dist), 0.0);
|
||||
|
||||
dist = sampleDistMap(u_ShadowMap, st + vec2( 1.0/512.0, 1.0/512.0), u_LightRadius);
|
||||
part += max(sign(lightDist - dist), 0.0);
|
||||
|
||||
#if defined(USE_DISCARD)
|
||||
if (part <= 0.0)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
#endif
|
||||
|
||||
intensity *= part * 0.25;
|
||||
#else
|
||||
dist = sampleDistMap(u_ShadowMap, st, u_LightRadius);
|
||||
|
||||
#if defined(USE_DISCARD)
|
||||
if (lightDist - dist <= 0.0)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
#endif
|
||||
|
||||
intensity *= max(sign(lightDist - dist), 0.0);
|
||||
#endif
|
||||
|
||||
gl_FragColor.rgb = vec3(0);
|
||||
gl_FragColor.a = clamp(intensity, 0.0, 0.75);
|
||||
}
|
||||
uniform sampler2D u_ShadowMap;
|
||||
|
||||
uniform vec3 u_LightForward;
|
||||
uniform vec3 u_LightUp;
|
||||
uniform vec3 u_LightRight;
|
||||
uniform vec4 u_LightOrigin;
|
||||
uniform float u_LightRadius;
|
||||
varying vec3 var_Position;
|
||||
varying vec3 var_Normal;
|
||||
|
||||
float sampleDistMap(sampler2D texMap, vec2 uv, float scale)
|
||||
{
|
||||
vec3 distv = texture2D(texMap, uv).xyz;
|
||||
return dot(distv, vec3(1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0)) * scale;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 lightToPos = var_Position - u_LightOrigin.xyz;
|
||||
vec2 st = vec2(-dot(u_LightRight, lightToPos), dot(u_LightUp, lightToPos));
|
||||
|
||||
float fade = length(st);
|
||||
|
||||
#if defined(USE_DISCARD)
|
||||
if (fade >= 1.0)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
#endif
|
||||
|
||||
fade = clamp(8.0 - fade * 8.0, 0.0, 1.0);
|
||||
|
||||
st = st * 0.5 + vec2(0.5);
|
||||
|
||||
#if defined(USE_SOLID_PSHADOWS)
|
||||
float intensity = max(sign(u_LightRadius - length(lightToPos)), 0.0);
|
||||
#else
|
||||
float intensity = clamp((1.0 - dot(lightToPos, lightToPos) / (u_LightRadius * u_LightRadius)) * 2.0, 0.0, 1.0);
|
||||
#endif
|
||||
|
||||
float lightDist = length(lightToPos);
|
||||
float dist;
|
||||
|
||||
#if defined(USE_DISCARD)
|
||||
if (dot(u_LightForward, lightToPos) <= 0.0)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
|
||||
if (dot(var_Normal, lightToPos) > 0.0)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
#else
|
||||
intensity *= max(sign(dot(u_LightForward, lightToPos)), 0.0);
|
||||
intensity *= max(sign(-dot(var_Normal, lightToPos)), 0.0);
|
||||
#endif
|
||||
|
||||
intensity *= fade;
|
||||
#if defined(USE_PCF)
|
||||
float part;
|
||||
|
||||
dist = sampleDistMap(u_ShadowMap, st + vec2(-1.0/512.0, -1.0/512.0), u_LightRadius);
|
||||
part = max(sign(lightDist - dist), 0.0);
|
||||
|
||||
dist = sampleDistMap(u_ShadowMap, st + vec2( 1.0/512.0, -1.0/512.0), u_LightRadius);
|
||||
part += max(sign(lightDist - dist), 0.0);
|
||||
|
||||
dist = sampleDistMap(u_ShadowMap, st + vec2(-1.0/512.0, 1.0/512.0), u_LightRadius);
|
||||
part += max(sign(lightDist - dist), 0.0);
|
||||
|
||||
dist = sampleDistMap(u_ShadowMap, st + vec2( 1.0/512.0, 1.0/512.0), u_LightRadius);
|
||||
part += max(sign(lightDist - dist), 0.0);
|
||||
|
||||
#if defined(USE_DISCARD)
|
||||
if (part <= 0.0)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
#endif
|
||||
|
||||
intensity *= part * 0.25;
|
||||
#else
|
||||
dist = sampleDistMap(u_ShadowMap, st, u_LightRadius);
|
||||
|
||||
#if defined(USE_DISCARD)
|
||||
if (lightDist - dist <= 0.0)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
#endif
|
||||
|
||||
intensity *= max(sign(lightDist - dist), 0.0);
|
||||
#endif
|
||||
|
||||
gl_FragColor.rgb = vec3(0);
|
||||
gl_FragColor.a = clamp(intensity, 0.0, 0.75);
|
||||
}
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
attribute vec4 attr_Position;
|
||||
attribute vec3 attr_Normal;
|
||||
|
||||
uniform mat4 u_ModelViewProjectionMatrix;
|
||||
varying vec3 var_Position;
|
||||
varying vec3 var_Normal;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 position = attr_Position;
|
||||
|
||||
gl_Position = u_ModelViewProjectionMatrix * position;
|
||||
|
||||
var_Position = position.xyz;
|
||||
var_Normal = attr_Normal;
|
||||
}
|
||||
attribute vec4 attr_Position;
|
||||
attribute vec3 attr_Normal;
|
||||
|
||||
uniform mat4 u_ModelViewProjectionMatrix;
|
||||
varying vec3 var_Position;
|
||||
varying vec3 var_Normal;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 position = attr_Position;
|
||||
|
||||
gl_Position = u_ModelViewProjectionMatrix * position;
|
||||
|
||||
var_Position = position.xyz;
|
||||
var_Normal = attr_Normal;
|
||||
}
|
||||
|
|
|
@ -1,41 +1,41 @@
|
|||
uniform vec4 u_LightOrigin;
|
||||
uniform float u_LightRadius;
|
||||
|
||||
varying vec3 var_Position;
|
||||
|
||||
void main()
|
||||
{
|
||||
#if defined(USE_DEPTH)
|
||||
float depth = length(u_LightOrigin.xyz - var_Position) / u_LightRadius;
|
||||
#if 0
|
||||
// 32 bit precision
|
||||
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);
|
||||
|
||||
vec4 comp;
|
||||
comp = depth * bitSh;
|
||||
comp.xyz = fract(comp.xyz);
|
||||
comp -= comp.xxyz * bitMsk;
|
||||
gl_FragColor = comp;
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
// 24 bit precision
|
||||
const vec3 bitSh = vec3( 256 * 256, 256, 1);
|
||||
const vec3 bitMsk = vec3( 0, 1.0 / 256.0, 1.0 / 256.0);
|
||||
|
||||
vec3 comp;
|
||||
comp = depth * bitSh;
|
||||
comp.xy = fract(comp.xy);
|
||||
comp -= comp.xxy * bitMsk;
|
||||
gl_FragColor = vec4(comp, 1.0);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
// 8 bit precision
|
||||
gl_FragColor = vec4(depth, depth, depth, 1);
|
||||
#endif
|
||||
#else
|
||||
gl_FragColor = vec4(0, 0, 0, 1);
|
||||
#endif
|
||||
}
|
||||
uniform vec4 u_LightOrigin;
|
||||
uniform float u_LightRadius;
|
||||
|
||||
varying vec3 var_Position;
|
||||
|
||||
void main()
|
||||
{
|
||||
#if defined(USE_DEPTH)
|
||||
float depth = length(u_LightOrigin.xyz - var_Position) / u_LightRadius;
|
||||
#if 0
|
||||
// 32 bit precision
|
||||
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);
|
||||
|
||||
vec4 comp;
|
||||
comp = depth * bitSh;
|
||||
comp.xyz = fract(comp.xyz);
|
||||
comp -= comp.xxyz * bitMsk;
|
||||
gl_FragColor = comp;
|
||||
#endif
|
||||
|
||||
#if 1
|
||||
// 24 bit precision
|
||||
const vec3 bitSh = vec3( 256 * 256, 256, 1);
|
||||
const vec3 bitMsk = vec3( 0, 1.0 / 256.0, 1.0 / 256.0);
|
||||
|
||||
vec3 comp;
|
||||
comp = depth * bitSh;
|
||||
comp.xy = fract(comp.xy);
|
||||
comp -= comp.xxy * bitMsk;
|
||||
gl_FragColor = vec4(comp, 1.0);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
// 8 bit precision
|
||||
gl_FragColor = vec4(depth, depth, depth, 1);
|
||||
#endif
|
||||
#else
|
||||
gl_FragColor = vec4(0, 0, 0, 1);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -1,89 +1,89 @@
|
|||
attribute vec4 attr_Position;
|
||||
attribute vec3 attr_Normal;
|
||||
attribute vec4 attr_TexCoord0;
|
||||
|
||||
//#if defined(USE_VERTEX_ANIMATION)
|
||||
attribute vec4 attr_Position2;
|
||||
attribute vec3 attr_Normal2;
|
||||
//#endif
|
||||
|
||||
//#if defined(USE_DEFORM_VERTEXES)
|
||||
uniform int u_DeformGen;
|
||||
uniform float u_DeformParams[5];
|
||||
//#endif
|
||||
|
||||
uniform float u_Time;
|
||||
uniform mat4 u_ModelViewProjectionMatrix;
|
||||
|
||||
uniform mat4 u_ModelMatrix;
|
||||
|
||||
//#if defined(USE_VERTEX_ANIMATION)
|
||||
uniform float u_VertexLerp;
|
||||
//#endif
|
||||
|
||||
varying vec3 var_Position;
|
||||
|
||||
vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)
|
||||
{
|
||||
if (u_DeformGen == 0)
|
||||
{
|
||||
return pos;
|
||||
}
|
||||
|
||||
float base = u_DeformParams[0];
|
||||
float amplitude = u_DeformParams[1];
|
||||
float phase = u_DeformParams[2];
|
||||
float frequency = u_DeformParams[3];
|
||||
float spread = u_DeformParams[4];
|
||||
|
||||
if (u_DeformGen == DGEN_BULGE)
|
||||
{
|
||||
phase *= M_PI * 0.25 * st.x;
|
||||
}
|
||||
else // if (u_DeformGen <= DGEN_WAVE_INVERSE_SAWTOOTH)
|
||||
{
|
||||
phase += dot(pos.xyz, vec3(spread));
|
||||
}
|
||||
|
||||
float value = phase + (u_Time * frequency);
|
||||
float func;
|
||||
|
||||
if (u_DeformGen == DGEN_WAVE_SIN)
|
||||
{
|
||||
func = sin(value * 2.0 * M_PI);
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_SQUARE)
|
||||
{
|
||||
func = sign(sin(value * 2.0 * M_PI));
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_TRIANGLE)
|
||||
{
|
||||
func = abs(fract(value + 0.75) - 0.5) * 4.0 - 1.0;
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_SAWTOOTH)
|
||||
{
|
||||
func = fract(value);
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_INVERSE_SAWTOOTH)
|
||||
{
|
||||
func = (1.0 - fract(value));
|
||||
}
|
||||
else if (u_DeformGen == DGEN_BULGE)
|
||||
{
|
||||
func = sin(value);
|
||||
}
|
||||
|
||||
return pos + normal * (base + func * amplitude);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 position = mix(attr_Position, attr_Position2, u_VertexLerp);
|
||||
vec3 normal = normalize(mix(attr_Normal, attr_Normal2, u_VertexLerp));
|
||||
|
||||
position.xyz = DeformPosition(position.xyz, normal, attr_TexCoord0.st);
|
||||
|
||||
gl_Position = u_ModelViewProjectionMatrix * position;
|
||||
|
||||
var_Position = (u_ModelMatrix * position).xyz;
|
||||
}
|
||||
attribute vec4 attr_Position;
|
||||
attribute vec3 attr_Normal;
|
||||
attribute vec4 attr_TexCoord0;
|
||||
|
||||
//#if defined(USE_VERTEX_ANIMATION)
|
||||
attribute vec4 attr_Position2;
|
||||
attribute vec3 attr_Normal2;
|
||||
//#endif
|
||||
|
||||
//#if defined(USE_DEFORM_VERTEXES)
|
||||
uniform int u_DeformGen;
|
||||
uniform float u_DeformParams[5];
|
||||
//#endif
|
||||
|
||||
uniform float u_Time;
|
||||
uniform mat4 u_ModelViewProjectionMatrix;
|
||||
|
||||
uniform mat4 u_ModelMatrix;
|
||||
|
||||
//#if defined(USE_VERTEX_ANIMATION)
|
||||
uniform float u_VertexLerp;
|
||||
//#endif
|
||||
|
||||
varying vec3 var_Position;
|
||||
|
||||
vec3 DeformPosition(const vec3 pos, const vec3 normal, const vec2 st)
|
||||
{
|
||||
if (u_DeformGen == 0)
|
||||
{
|
||||
return pos;
|
||||
}
|
||||
|
||||
float base = u_DeformParams[0];
|
||||
float amplitude = u_DeformParams[1];
|
||||
float phase = u_DeformParams[2];
|
||||
float frequency = u_DeformParams[3];
|
||||
float spread = u_DeformParams[4];
|
||||
|
||||
if (u_DeformGen == DGEN_BULGE)
|
||||
{
|
||||
phase *= M_PI * 0.25 * st.x;
|
||||
}
|
||||
else // if (u_DeformGen <= DGEN_WAVE_INVERSE_SAWTOOTH)
|
||||
{
|
||||
phase += dot(pos.xyz, vec3(spread));
|
||||
}
|
||||
|
||||
float value = phase + (u_Time * frequency);
|
||||
float func;
|
||||
|
||||
if (u_DeformGen == DGEN_WAVE_SIN)
|
||||
{
|
||||
func = sin(value * 2.0 * M_PI);
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_SQUARE)
|
||||
{
|
||||
func = sign(sin(value * 2.0 * M_PI));
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_TRIANGLE)
|
||||
{
|
||||
func = abs(fract(value + 0.75) - 0.5) * 4.0 - 1.0;
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_SAWTOOTH)
|
||||
{
|
||||
func = fract(value);
|
||||
}
|
||||
else if (u_DeformGen == DGEN_WAVE_INVERSE_SAWTOOTH)
|
||||
{
|
||||
func = (1.0 - fract(value));
|
||||
}
|
||||
else if (u_DeformGen == DGEN_BULGE)
|
||||
{
|
||||
func = sin(value);
|
||||
}
|
||||
|
||||
return pos + normal * (base + func * amplitude);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 position = mix(attr_Position, attr_Position2, u_VertexLerp);
|
||||
vec3 normal = normalize(mix(attr_Normal, attr_Normal2, u_VertexLerp));
|
||||
|
||||
position.xyz = DeformPosition(position.xyz, normal, attr_TexCoord0.st);
|
||||
|
||||
gl_Position = u_ModelViewProjectionMatrix * position;
|
||||
|
||||
var_Position = (u_ModelMatrix * position).xyz;
|
||||
}
|
||||
|
|
|
@ -1,127 +1,127 @@
|
|||
uniform sampler2D u_ScreenDepthMap;
|
||||
|
||||
uniform sampler2D u_ShadowMap;
|
||||
#if defined(USE_SHADOW_CASCADE)
|
||||
uniform sampler2D u_ShadowMap2;
|
||||
uniform sampler2D u_ShadowMap3;
|
||||
#endif
|
||||
|
||||
uniform mat4 u_ShadowMvp;
|
||||
#if defined(USE_SHADOW_CASCADE)
|
||||
uniform mat4 u_ShadowMvp2;
|
||||
uniform mat4 u_ShadowMvp3;
|
||||
#endif
|
||||
|
||||
uniform vec3 u_ViewOrigin;
|
||||
uniform vec4 u_ViewInfo; // zfar / znear, zfar
|
||||
|
||||
varying vec2 var_ScreenTex;
|
||||
varying vec3 var_ViewDir;
|
||||
|
||||
// Input: It uses texture coords as the random number seed.
|
||||
// Output: Random number: [0,1), that is between 0.0 and 0.999999... inclusive.
|
||||
// Author: Michael Pohoreski
|
||||
// Copyright: Copyleft 2012 :-)
|
||||
// Source: http://stackoverflow.com/questions/5149544/can-i-generate-a-random-number-inside-a-pixel-shader
|
||||
|
||||
float random( const vec2 p )
|
||||
{
|
||||
// We need irrationals for pseudo randomness.
|
||||
// Most (all?) known transcendental numbers will (generally) work.
|
||||
const vec2 r = vec2(
|
||||
23.1406926327792690, // e^pi (Gelfond's constant)
|
||||
2.6651441426902251); // 2^sqrt(2) (Gelfond-Schneider constant)
|
||||
//return fract( cos( 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 mult;
|
||||
float scale = 2.0 / r_shadowMapSize;
|
||||
|
||||
#if defined(USE_SHADOW_FILTER)
|
||||
float r = random(var_ScreenTex.xy);
|
||||
float sinr = sin(r) * scale;
|
||||
float cosr = cos(r) * scale;
|
||||
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.3524343, -0.7791386)).r);
|
||||
mult += step(dist, texture2D(shadowmap, st + rmat * vec2(0.2391056, 0.9189604)).r);
|
||||
#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.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.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.7320465, 0.6317794)).r);
|
||||
|
||||
mult *= 0.11111;
|
||||
#else
|
||||
mult *= 0.33333;
|
||||
#endif
|
||||
#else
|
||||
mult = step(dist, texture2D(shadowmap, st).r);
|
||||
#endif
|
||||
|
||||
return mult;
|
||||
}
|
||||
|
||||
float getLinearDepth(sampler2D depthMap, vec2 tex, float zFarDivZNear)
|
||||
{
|
||||
float sampleZDivW = texture2D(depthMap, tex).r;
|
||||
return 1.0 / mix(zFarDivZNear, 1.0, sampleZDivW);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
float result;
|
||||
|
||||
float depth = getLinearDepth(u_ScreenDepthMap, var_ScreenTex, u_ViewInfo.x);
|
||||
float sampleZ = u_ViewInfo.y * depth;
|
||||
|
||||
vec4 biasPos = vec4(u_ViewOrigin + var_ViewDir * depth * 0.99, 1.0);
|
||||
|
||||
vec4 shadowpos = u_ShadowMvp * biasPos;
|
||||
|
||||
#if defined(USE_SHADOW_CASCADE)
|
||||
const float fadeTo = 0.5;
|
||||
result = fadeTo;
|
||||
#else
|
||||
result = 0.0;
|
||||
#endif
|
||||
|
||||
if (all(lessThanEqual(abs(shadowpos.xyz), vec3(abs(shadowpos.w)))))
|
||||
{
|
||||
shadowpos.xyz = shadowpos.xyz / shadowpos.w * 0.5 + 0.5;
|
||||
result = PCF(u_ShadowMap, shadowpos.xy, shadowpos.z);
|
||||
}
|
||||
#if defined(USE_SHADOW_CASCADE)
|
||||
else
|
||||
{
|
||||
shadowpos = u_ShadowMvp2 * biasPos;
|
||||
|
||||
if (all(lessThanEqual(abs(shadowpos.xyz), vec3(abs(shadowpos.w)))))
|
||||
{
|
||||
shadowpos.xyz = shadowpos.xyz / shadowpos.w * 0.5 + 0.5;
|
||||
result = PCF(u_ShadowMap2, shadowpos.xy, shadowpos.z);
|
||||
}
|
||||
else
|
||||
{
|
||||
shadowpos = u_ShadowMvp3 * biasPos;
|
||||
|
||||
if (all(lessThanEqual(abs(shadowpos.xyz), vec3(abs(shadowpos.w)))))
|
||||
{
|
||||
shadowpos.xyz = shadowpos.xyz / shadowpos.w * 0.5 + 0.5;
|
||||
result = PCF(u_ShadowMap3, shadowpos.xy, shadowpos.z);
|
||||
|
||||
float fade = clamp(sampleZ / r_shadowCascadeZFar * 10.0 - 9.0, 0.0, 1.0);
|
||||
result = mix(result, fadeTo, fade);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
gl_FragColor = vec4(vec3(result), 1.0);
|
||||
}
|
||||
uniform sampler2D u_ScreenDepthMap;
|
||||
|
||||
uniform sampler2D u_ShadowMap;
|
||||
#if defined(USE_SHADOW_CASCADE)
|
||||
uniform sampler2D u_ShadowMap2;
|
||||
uniform sampler2D u_ShadowMap3;
|
||||
#endif
|
||||
|
||||
uniform mat4 u_ShadowMvp;
|
||||
#if defined(USE_SHADOW_CASCADE)
|
||||
uniform mat4 u_ShadowMvp2;
|
||||
uniform mat4 u_ShadowMvp3;
|
||||
#endif
|
||||
|
||||
uniform vec3 u_ViewOrigin;
|
||||
uniform vec4 u_ViewInfo; // zfar / znear, zfar
|
||||
|
||||
varying vec2 var_ScreenTex;
|
||||
varying vec3 var_ViewDir;
|
||||
|
||||
// Input: It uses texture coords as the random number seed.
|
||||
// Output: Random number: [0,1), that is between 0.0 and 0.999999... inclusive.
|
||||
// Author: Michael Pohoreski
|
||||
// Copyright: Copyleft 2012 :-)
|
||||
// Source: http://stackoverflow.com/questions/5149544/can-i-generate-a-random-number-inside-a-pixel-shader
|
||||
|
||||
float random( const vec2 p )
|
||||
{
|
||||
// We need irrationals for pseudo randomness.
|
||||
// Most (all?) known transcendental numbers will (generally) work.
|
||||
const vec2 r = vec2(
|
||||
23.1406926327792690, // e^pi (Gelfond's constant)
|
||||
2.6651441426902251); // 2^sqrt(2) (Gelfond-Schneider constant)
|
||||
//return fract( cos( 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 mult;
|
||||
float scale = 2.0 / r_shadowMapSize;
|
||||
|
||||
#if defined(USE_SHADOW_FILTER)
|
||||
float r = random(var_ScreenTex.xy);
|
||||
float sinr = sin(r) * scale;
|
||||
float cosr = cos(r) * scale;
|
||||
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.3524343, -0.7791386)).r);
|
||||
mult += step(dist, texture2D(shadowmap, st + rmat * vec2(0.2391056, 0.9189604)).r);
|
||||
#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.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.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.7320465, 0.6317794)).r);
|
||||
|
||||
mult *= 0.11111;
|
||||
#else
|
||||
mult *= 0.33333;
|
||||
#endif
|
||||
#else
|
||||
mult = step(dist, texture2D(shadowmap, st).r);
|
||||
#endif
|
||||
|
||||
return mult;
|
||||
}
|
||||
|
||||
float getLinearDepth(sampler2D depthMap, vec2 tex, float zFarDivZNear)
|
||||
{
|
||||
float sampleZDivW = texture2D(depthMap, tex).r;
|
||||
return 1.0 / mix(zFarDivZNear, 1.0, sampleZDivW);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
float result;
|
||||
|
||||
float depth = getLinearDepth(u_ScreenDepthMap, var_ScreenTex, u_ViewInfo.x);
|
||||
float sampleZ = u_ViewInfo.y * depth;
|
||||
|
||||
vec4 biasPos = vec4(u_ViewOrigin + var_ViewDir * depth * 0.99, 1.0);
|
||||
|
||||
vec4 shadowpos = u_ShadowMvp * biasPos;
|
||||
|
||||
#if defined(USE_SHADOW_CASCADE)
|
||||
const float fadeTo = 0.5;
|
||||
result = fadeTo;
|
||||
#else
|
||||
result = 0.0;
|
||||
#endif
|
||||
|
||||
if (all(lessThanEqual(abs(shadowpos.xyz), vec3(abs(shadowpos.w)))))
|
||||
{
|
||||
shadowpos.xyz = shadowpos.xyz / shadowpos.w * 0.5 + 0.5;
|
||||
result = PCF(u_ShadowMap, shadowpos.xy, shadowpos.z);
|
||||
}
|
||||
#if defined(USE_SHADOW_CASCADE)
|
||||
else
|
||||
{
|
||||
shadowpos = u_ShadowMvp2 * biasPos;
|
||||
|
||||
if (all(lessThanEqual(abs(shadowpos.xyz), vec3(abs(shadowpos.w)))))
|
||||
{
|
||||
shadowpos.xyz = shadowpos.xyz / shadowpos.w * 0.5 + 0.5;
|
||||
result = PCF(u_ShadowMap2, shadowpos.xy, shadowpos.z);
|
||||
}
|
||||
else
|
||||
{
|
||||
shadowpos = u_ShadowMvp3 * biasPos;
|
||||
|
||||
if (all(lessThanEqual(abs(shadowpos.xyz), vec3(abs(shadowpos.w)))))
|
||||
{
|
||||
shadowpos.xyz = shadowpos.xyz / shadowpos.w * 0.5 + 0.5;
|
||||
result = PCF(u_ShadowMap3, shadowpos.xy, shadowpos.z);
|
||||
|
||||
float fade = clamp(sampleZ / r_shadowCascadeZFar * 10.0 - 9.0, 0.0, 1.0);
|
||||
result = mix(result, fadeTo, fade);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
gl_FragColor = vec4(vec3(result), 1.0);
|
||||
}
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
attribute vec4 attr_Position;
|
||||
attribute vec4 attr_TexCoord0;
|
||||
|
||||
uniform vec3 u_ViewForward;
|
||||
uniform vec3 u_ViewLeft;
|
||||
uniform vec3 u_ViewUp;
|
||||
uniform vec4 u_ViewInfo; // zfar / znear
|
||||
|
||||
varying vec2 var_ScreenTex;
|
||||
varying vec3 var_ViewDir;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = attr_Position;
|
||||
//vec2 screenCoords = gl_Position.xy / gl_Position.w;
|
||||
//var_ScreenTex = screenCoords * 0.5 + 0.5;
|
||||
var_ScreenTex = attr_TexCoord0.xy;
|
||||
vec2 screenCoords = attr_TexCoord0.xy * 2.0 - 1.0;
|
||||
var_ViewDir = u_ViewForward + u_ViewLeft * -screenCoords.x + u_ViewUp * screenCoords.y;
|
||||
}
|
||||
attribute vec4 attr_Position;
|
||||
attribute vec4 attr_TexCoord0;
|
||||
|
||||
uniform vec3 u_ViewForward;
|
||||
uniform vec3 u_ViewLeft;
|
||||
uniform vec3 u_ViewUp;
|
||||
uniform vec4 u_ViewInfo; // zfar / znear
|
||||
|
||||
varying vec2 var_ScreenTex;
|
||||
varying vec3 var_ViewDir;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = attr_Position;
|
||||
//vec2 screenCoords = gl_Position.xy / gl_Position.w;
|
||||
//var_ScreenTex = screenCoords * 0.5 + 0.5;
|
||||
var_ScreenTex = attr_TexCoord0.xy;
|
||||
vec2 screenCoords = attr_TexCoord0.xy * 2.0 - 1.0;
|
||||
var_ViewDir = u_ViewForward + u_ViewLeft * -screenCoords.x + u_ViewUp * screenCoords.y;
|
||||
}
|
||||
|
|
|
@ -1,86 +1,86 @@
|
|||
uniform sampler2D u_ScreenDepthMap;
|
||||
|
||||
uniform vec4 u_ViewInfo; // zfar / znear, zfar
|
||||
|
||||
varying vec2 var_ScreenTex;
|
||||
|
||||
vec2 poissonDisc[9] = vec2[9](
|
||||
vec2(-0.7055767, 0.196515), vec2(0.3524343, -0.7791386),
|
||||
vec2(0.2391056, 0.9189604), vec2(-0.07580382, -0.09224417),
|
||||
vec2(0.5784913, -0.002528916), vec2(0.192888, 0.4064181),
|
||||
vec2(-0.6335801, -0.5247476), vec2(-0.5579782, 0.7491854),
|
||||
vec2(0.7320465, 0.6317794)
|
||||
);
|
||||
|
||||
// Input: It uses texture coords as the random number seed.
|
||||
// Output: Random number: [0,1), that is between 0.0 and 0.999999... inclusive.
|
||||
// Author: Michael Pohoreski
|
||||
// Copyright: Copyleft 2012 :-)
|
||||
// Source: http://stackoverflow.com/questions/5149544/can-i-generate-a-random-number-inside-a-pixel-shader
|
||||
|
||||
float random( const vec2 p )
|
||||
{
|
||||
// We need irrationals for pseudo randomness.
|
||||
// Most (all?) known transcendental numbers will (generally) work.
|
||||
const vec2 r = vec2(
|
||||
23.1406926327792690, // e^pi (Gelfond's constant)
|
||||
2.6651441426902251); // 2^sqrt(2) (Gelfond-Schneider constant)
|
||||
//return fract( cos( mod( 123456789., 1e-7 + 256. * dot(p,r) ) ) );
|
||||
return mod( 123456789., 1e-7 + 256. * dot(p,r) );
|
||||
}
|
||||
|
||||
mat2 randomRotation( const vec2 p )
|
||||
{
|
||||
float r = random(p);
|
||||
float sinr = sin(r);
|
||||
float cosr = cos(r);
|
||||
return mat2(cosr, sinr, -sinr, cosr);
|
||||
}
|
||||
|
||||
float getLinearDepth(sampler2D depthMap, const vec2 tex, const float zFarDivZNear)
|
||||
{
|
||||
float sampleZDivW = texture2D(depthMap, tex).r;
|
||||
return 1.0 / mix(zFarDivZNear, 1.0, sampleZDivW);
|
||||
}
|
||||
|
||||
float ambientOcclusion(sampler2D depthMap, const vec2 tex, const float zFarDivZNear, const float zFar)
|
||||
{
|
||||
float result = 0;
|
||||
|
||||
float sampleZ = zFar * getLinearDepth(depthMap, tex, zFarDivZNear);
|
||||
|
||||
vec2 expectedSlope = vec2(dFdx(sampleZ), dFdy(sampleZ)) / vec2(dFdx(tex.x), dFdy(tex.y));
|
||||
|
||||
if (length(expectedSlope) > 5000.0)
|
||||
return 1.0;
|
||||
|
||||
vec2 offsetScale = vec2(3.0 / sampleZ);
|
||||
|
||||
mat2 rmat = randomRotation(tex);
|
||||
|
||||
int i;
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
vec2 offset = rmat * poissonDisc[i] * offsetScale;
|
||||
float sampleZ2 = zFar * getLinearDepth(depthMap, tex + offset, zFarDivZNear);
|
||||
|
||||
if (abs(sampleZ - sampleZ2) > 20.0)
|
||||
result += 1.0;
|
||||
else
|
||||
{
|
||||
float expectedZ = sampleZ + dot(expectedSlope, offset);
|
||||
result += step(expectedZ - 1.0, sampleZ2);
|
||||
}
|
||||
}
|
||||
|
||||
result *= 0.33333;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
float result = ambientOcclusion(u_ScreenDepthMap, var_ScreenTex, u_ViewInfo.x, u_ViewInfo.y);
|
||||
|
||||
gl_FragColor = vec4(vec3(result), 1.0);
|
||||
}
|
||||
uniform sampler2D u_ScreenDepthMap;
|
||||
|
||||
uniform vec4 u_ViewInfo; // zfar / znear, zfar
|
||||
|
||||
varying vec2 var_ScreenTex;
|
||||
|
||||
vec2 poissonDisc[9] = vec2[9](
|
||||
vec2(-0.7055767, 0.196515), vec2(0.3524343, -0.7791386),
|
||||
vec2(0.2391056, 0.9189604), vec2(-0.07580382, -0.09224417),
|
||||
vec2(0.5784913, -0.002528916), vec2(0.192888, 0.4064181),
|
||||
vec2(-0.6335801, -0.5247476), vec2(-0.5579782, 0.7491854),
|
||||
vec2(0.7320465, 0.6317794)
|
||||
);
|
||||
|
||||
// Input: It uses texture coords as the random number seed.
|
||||
// Output: Random number: [0,1), that is between 0.0 and 0.999999... inclusive.
|
||||
// Author: Michael Pohoreski
|
||||
// Copyright: Copyleft 2012 :-)
|
||||
// Source: http://stackoverflow.com/questions/5149544/can-i-generate-a-random-number-inside-a-pixel-shader
|
||||
|
||||
float random( const vec2 p )
|
||||
{
|
||||
// We need irrationals for pseudo randomness.
|
||||
// Most (all?) known transcendental numbers will (generally) work.
|
||||
const vec2 r = vec2(
|
||||
23.1406926327792690, // e^pi (Gelfond's constant)
|
||||
2.6651441426902251); // 2^sqrt(2) (Gelfond-Schneider constant)
|
||||
//return fract( cos( mod( 123456789., 1e-7 + 256. * dot(p,r) ) ) );
|
||||
return mod( 123456789., 1e-7 + 256. * dot(p,r) );
|
||||
}
|
||||
|
||||
mat2 randomRotation( const vec2 p )
|
||||
{
|
||||
float r = random(p);
|
||||
float sinr = sin(r);
|
||||
float cosr = cos(r);
|
||||
return mat2(cosr, sinr, -sinr, cosr);
|
||||
}
|
||||
|
||||
float getLinearDepth(sampler2D depthMap, const vec2 tex, const float zFarDivZNear)
|
||||
{
|
||||
float sampleZDivW = texture2D(depthMap, tex).r;
|
||||
return 1.0 / mix(zFarDivZNear, 1.0, sampleZDivW);
|
||||
}
|
||||
|
||||
float ambientOcclusion(sampler2D depthMap, const vec2 tex, const float zFarDivZNear, const float zFar)
|
||||
{
|
||||
float result = 0;
|
||||
|
||||
float sampleZ = zFar * getLinearDepth(depthMap, tex, zFarDivZNear);
|
||||
|
||||
vec2 expectedSlope = vec2(dFdx(sampleZ), dFdy(sampleZ)) / vec2(dFdx(tex.x), dFdy(tex.y));
|
||||
|
||||
if (length(expectedSlope) > 5000.0)
|
||||
return 1.0;
|
||||
|
||||
vec2 offsetScale = vec2(3.0 / sampleZ);
|
||||
|
||||
mat2 rmat = randomRotation(tex);
|
||||
|
||||
int i;
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
vec2 offset = rmat * poissonDisc[i] * offsetScale;
|
||||
float sampleZ2 = zFar * getLinearDepth(depthMap, tex + offset, zFarDivZNear);
|
||||
|
||||
if (abs(sampleZ - sampleZ2) > 20.0)
|
||||
result += 1.0;
|
||||
else
|
||||
{
|
||||
float expectedZ = sampleZ + dot(expectedSlope, offset);
|
||||
result += step(expectedZ - 1.0, sampleZ2);
|
||||
}
|
||||
}
|
||||
|
||||
result *= 0.33333;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
float result = ambientOcclusion(u_ScreenDepthMap, var_ScreenTex, u_ViewInfo.x, u_ViewInfo.y);
|
||||
|
||||
gl_FragColor = vec4(vec3(result), 1.0);
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
attribute vec4 attr_Position;
|
||||
attribute vec4 attr_TexCoord0;
|
||||
|
||||
varying vec2 var_ScreenTex;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = attr_Position;
|
||||
var_ScreenTex = attr_TexCoord0.xy;
|
||||
//vec2 screenCoords = gl_Position.xy / gl_Position.w;
|
||||
//var_ScreenTex = screenCoords * 0.5 + 0.5;
|
||||
}
|
||||
attribute vec4 attr_Position;
|
||||
attribute vec4 attr_TexCoord0;
|
||||
|
||||
varying vec2 var_ScreenTex;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = attr_Position;
|
||||
var_ScreenTex = attr_TexCoord0.xy;
|
||||
//vec2 screenCoords = gl_Position.xy / gl_Position.w;
|
||||
//var_ScreenTex = screenCoords * 0.5 + 0.5;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#version 120
|
||||
|
||||
uniform sampler2D u_DiffuseMap;
|
||||
uniform vec4 u_Color;
|
||||
|
||||
varying vec2 var_Tex1;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = texture2D(u_DiffuseMap, var_Tex1) * u_Color;
|
||||
}
|
||||
#version 120
|
||||
|
||||
uniform sampler2D u_DiffuseMap;
|
||||
uniform vec4 u_Color;
|
||||
|
||||
varying vec2 var_Tex1;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = texture2D(u_DiffuseMap, var_Tex1) * u_Color;
|
||||
}
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
#version 120
|
||||
|
||||
attribute vec4 attr_Position;
|
||||
attribute vec4 attr_TexCoord0;
|
||||
|
||||
uniform mat4 u_ModelViewProjectionMatrix;
|
||||
|
||||
varying vec2 var_Tex1;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = u_ModelViewProjectionMatrix * attr_Position;
|
||||
var_Tex1 = attr_TexCoord0.st;
|
||||
}
|
||||
#version 120
|
||||
|
||||
attribute vec4 attr_Position;
|
||||
attribute vec4 attr_TexCoord0;
|
||||
|
||||
uniform mat4 u_ModelViewProjectionMatrix;
|
||||
|
||||
varying vec2 var_Tex1;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = u_ModelViewProjectionMatrix * attr_Position;
|
||||
var_Tex1 = attr_TexCoord0.st;
|
||||
}
|
||||
|
|
|
@ -1,48 +1,48 @@
|
|||
uniform sampler2D u_TextureMap;
|
||||
uniform sampler2D u_LevelsMap;
|
||||
|
||||
uniform vec4 u_Color;
|
||||
|
||||
uniform vec2 u_AutoExposureMinMax;
|
||||
uniform vec3 u_ToneMinAvgMaxLinear;
|
||||
|
||||
varying vec2 var_TexCoords;
|
||||
|
||||
const vec3 LUMINANCE_VECTOR = vec3(0.2125, 0.7154, 0.0721); //vec3(0.299, 0.587, 0.114);
|
||||
|
||||
vec3 FilmicTonemap(vec3 x)
|
||||
{
|
||||
const float SS = 0.22; // Shoulder Strength
|
||||
const float LS = 0.30; // Linear Strength
|
||||
const float LA = 0.10; // Linear Angle
|
||||
const float TS = 0.20; // Toe Strength
|
||||
const float TAN = 0.01; // Toe Angle Numerator
|
||||
const float TAD = 0.30; // Toe Angle Denominator
|
||||
|
||||
vec3 SSxx = SS * x * x;
|
||||
vec3 LSx = LS * x;
|
||||
vec3 LALSx = LSx * LA;
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture2D(u_TextureMap, var_TexCoords) * u_Color;
|
||||
vec3 minAvgMax = texture2D(u_LevelsMap, var_TexCoords).rgb;
|
||||
vec3 logMinAvgMaxLum = clamp(minAvgMax * 20.0 - 10.0, -u_AutoExposureMinMax.y, -u_AutoExposureMinMax.x);
|
||||
|
||||
float avgLum = exp2(logMinAvgMaxLum.y);
|
||||
//float maxLum = exp2(logMinAvgMaxLum.z);
|
||||
|
||||
color.rgb *= u_ToneMinAvgMaxLinear.y / avgLum;
|
||||
color.rgb = max(vec3(0.0), color.rgb - vec3(u_ToneMinAvgMaxLinear.x));
|
||||
|
||||
vec3 fWhite = 1.0 / FilmicTonemap(vec3(u_ToneMinAvgMaxLinear.z - u_ToneMinAvgMaxLinear.x));
|
||||
color.rgb = FilmicTonemap(color.rgb) * fWhite;
|
||||
|
||||
gl_FragColor = clamp(color, 0.0, 1.0);
|
||||
}
|
||||
uniform sampler2D u_TextureMap;
|
||||
uniform sampler2D u_LevelsMap;
|
||||
|
||||
uniform vec4 u_Color;
|
||||
|
||||
uniform vec2 u_AutoExposureMinMax;
|
||||
uniform vec3 u_ToneMinAvgMaxLinear;
|
||||
|
||||
varying vec2 var_TexCoords;
|
||||
|
||||
const vec3 LUMINANCE_VECTOR = vec3(0.2125, 0.7154, 0.0721); //vec3(0.299, 0.587, 0.114);
|
||||
|
||||
vec3 FilmicTonemap(vec3 x)
|
||||
{
|
||||
const float SS = 0.22; // Shoulder Strength
|
||||
const float LS = 0.30; // Linear Strength
|
||||
const float LA = 0.10; // Linear Angle
|
||||
const float TS = 0.20; // Toe Strength
|
||||
const float TAN = 0.01; // Toe Angle Numerator
|
||||
const float TAD = 0.30; // Toe Angle Denominator
|
||||
|
||||
vec3 SSxx = SS * x * x;
|
||||
vec3 LSx = LS * x;
|
||||
vec3 LALSx = LSx * LA;
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture2D(u_TextureMap, var_TexCoords) * u_Color;
|
||||
vec3 minAvgMax = texture2D(u_LevelsMap, var_TexCoords).rgb;
|
||||
vec3 logMinAvgMaxLum = clamp(minAvgMax * 20.0 - 10.0, -u_AutoExposureMinMax.y, -u_AutoExposureMinMax.x);
|
||||
|
||||
float avgLum = exp2(logMinAvgMaxLum.y);
|
||||
//float maxLum = exp2(logMinAvgMaxLum.z);
|
||||
|
||||
color.rgb *= u_ToneMinAvgMaxLinear.y / avgLum;
|
||||
color.rgb = max(vec3(0.0), color.rgb - vec3(u_ToneMinAvgMaxLinear.x));
|
||||
|
||||
vec3 fWhite = 1.0 / FilmicTonemap(vec3(u_ToneMinAvgMaxLinear.z - u_ToneMinAvgMaxLinear.x));
|
||||
color.rgb = FilmicTonemap(color.rgb) * fWhite;
|
||||
|
||||
gl_FragColor = clamp(color, 0.0, 1.0);
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
attribute vec4 attr_Position;
|
||||
attribute vec4 attr_TexCoord0;
|
||||
|
||||
uniform mat4 u_ModelViewProjectionMatrix;
|
||||
|
||||
varying vec2 var_TexCoords;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = u_ModelViewProjectionMatrix * attr_Position;
|
||||
var_TexCoords = attr_TexCoord0.st;
|
||||
}
|
||||
attribute vec4 attr_Position;
|
||||
attribute vec4 attr_TexCoord0;
|
||||
|
||||
uniform mat4 u_ModelViewProjectionMatrix;
|
||||
|
||||
varying vec2 var_TexCoords;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = u_ModelViewProjectionMatrix * attr_Position;
|
||||
var_TexCoords = attr_TexCoord0.st;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue