Upload
commit
989702490b
|
@ -0,0 +1,79 @@
|
|||
uniform sampler2D baseTexture;
|
||||
uniform sampler2D normalTexture;
|
||||
uniform sampler2D textureFlags;
|
||||
uniform sampler2D specialTexture;
|
||||
|
||||
uniform vec4 skyBgColor;
|
||||
uniform float fogDistance;
|
||||
uniform vec3 eyePosition;
|
||||
uniform float animationTimer;
|
||||
|
||||
varying vec3 vPosition;
|
||||
varying vec3 worldPosition;
|
||||
|
||||
varying vec3 normal;
|
||||
varying vec3 tangent;
|
||||
varying vec3 binormal;
|
||||
|
||||
varying vec3 eyeVec;
|
||||
varying vec3 lightVec;
|
||||
|
||||
const float e = 2.718281828459;
|
||||
const float BS = 10.0;
|
||||
|
||||
// Water normalmap code based on water shader by martinsh
|
||||
// http://devlog-martinsh.blogspot.com/
|
||||
|
||||
float windSpeed = 1.0; //wind speed
|
||||
float scale = 1.0; //overall wave scale
|
||||
vec2 bigWaves = vec2(1.5, 1.0); //strength of big waves
|
||||
vec2 midWaves = vec2(0.3, 0.15); //strength of middle sized waves
|
||||
vec2 smallWaves = vec2(0.4, 0.3); //strength of small waves
|
||||
float choppy = 0.05; //wave choppyness
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec2 windDir = vec2(0.0, 0.0); //wind direction XY
|
||||
float x,y,z;
|
||||
x = 0.5 * worldPosition.x;
|
||||
y = 0.25 * worldPosition.y;
|
||||
z = 0.5 * worldPosition.z;
|
||||
vec2 uv = vec2 (x + y, z - y);
|
||||
float timer = animationTimer * 50.0;
|
||||
if (normal.x == 0.0 && normal.z == 0.0)
|
||||
windDir = 0.7 * normalize(vec2(-binormal.x, -binormal.z));
|
||||
else if (binormal.x == 0.0 && binormal.z == 0.0)
|
||||
windDir = vec2 (4.5, -4.5);
|
||||
else
|
||||
windDir = 4.5 * normalize(vec2(binormal.x, binormal.z));
|
||||
|
||||
//normal map
|
||||
vec2 nCoord = vec2(0.0, 0.0);
|
||||
nCoord = uv * (scale * 0.05) + windDir * timer * (windSpeed * 0.04);
|
||||
vec3 normal0 = 2.0 * texture2D(normalTexture,
|
||||
nCoord + vec2(-timer * 0.015, -timer * 0.005)).rgb - 1.0;
|
||||
nCoord = uv * (scale * 0.1) + windDir * timer * (windSpeed * 0.08)
|
||||
- (normal0.xy / normal0.zz) * choppy;
|
||||
vec3 normal1 = 2.0 * texture2D(normalTexture,
|
||||
nCoord + vec2(timer * 0.020, timer * 0.015)).rgb - 1.0;
|
||||
nCoord = uv * (scale * 0.25) + windDir * timer * (windSpeed*0.07)-(normal1.xy/normal1.zz)*choppy;
|
||||
vec3 normal2 = 2.0 * texture2D(normalTexture, nCoord + vec2(-timer*0.04,-timer*0.03)).rgb - 1.0;
|
||||
nCoord = uv * (scale * 0.5) + windDir * timer * (windSpeed*0.09)-(normal2.xy/normal2.z)*choppy;
|
||||
vec3 normal3 = 2.0 * texture2D(normalTexture, nCoord + vec2(+timer*0.03,+timer*0.04)).rgb - 1.0;
|
||||
nCoord = uv * (scale* 1.0) + windDir * timer * (windSpeed*0.4)-(normal3.xy/normal3.zz)*choppy;
|
||||
vec3 normal4 = 2.0 * texture2D(normalTexture, nCoord + vec2(-timer*0.02,+timer*0.1)).rgb - 1.0;
|
||||
nCoord = uv * (scale * 2.0) + windDir * timer * (windSpeed*0.7)-(normal4.xy/normal4.zz)*choppy;
|
||||
vec3 normal5 = 2.0 * texture2D(normalTexture, nCoord + vec2(+timer*0.1,-timer*0.06)).rgb - 1.0;
|
||||
|
||||
vec3 nVec = vec3(normalize(normal0 * bigWaves.x + normal1 * bigWaves.y +
|
||||
normal2 * midWaves.x + normal3 * midWaves.y +
|
||||
normal4 * smallWaves.x + normal5 * smallWaves.y));
|
||||
|
||||
vec3 base = vec3(0.1, 0.51, 0.9);
|
||||
vec3 color = base * dot(-normalize(eyeVec), nVec);
|
||||
float alpha = clamp((color.r + color.b + color.g) * 1.5, 0.2, 0.65);
|
||||
vec4 col = vec4(color.rgb, 1.0);
|
||||
col *= gl_Color;
|
||||
col.a = alpha;
|
||||
gl_FragColor = vec4(col.rgba);
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
uniform mat4 mWorldViewProj;
|
||||
uniform mat4 mInvWorld;
|
||||
uniform mat4 mTransWorld;
|
||||
uniform mat4 mWorld;
|
||||
|
||||
uniform float dayNightRatio;
|
||||
uniform vec3 eyePosition;
|
||||
uniform float animationTimer;
|
||||
|
||||
varying vec3 vPosition;
|
||||
varying vec3 worldPosition;
|
||||
|
||||
varying vec3 eyeVec;
|
||||
varying vec3 lightVec;
|
||||
varying vec3 normal;
|
||||
varying vec3 binormal;
|
||||
varying vec3 tangent;
|
||||
|
||||
const float e = 2.718281828459;
|
||||
const float BS = 10.0;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||
gl_Position = mWorldViewProj * gl_Vertex;
|
||||
vPosition = gl_Position.xyz;
|
||||
worldPosition = (gl_Vertex).xyz;
|
||||
vec3 sunPosition = vec3 (0.0, eyePosition.y * BS + 900.0, 0.0);
|
||||
|
||||
normal = normalize(gl_Normal);
|
||||
tangent = normalize(gl_MultiTexCoord1.xyz);
|
||||
binormal = normalize(gl_MultiTexCoord2.xyz);
|
||||
|
||||
vec3 v;
|
||||
|
||||
lightVec = sunPosition - worldPosition;
|
||||
eyeVec = -(gl_ModelViewMatrix * gl_Vertex).xyz;
|
||||
|
||||
vec4 color;
|
||||
float day = gl_Color.r;
|
||||
float night = gl_Color.g;
|
||||
float light_source = gl_Color.b;
|
||||
|
||||
float rg = mix(night, day, dayNightRatio);
|
||||
rg += light_source * 2.5; // Make light sources brighter
|
||||
float b = rg;
|
||||
|
||||
// Moonlight is blue
|
||||
b += (day - night) / 13.0;
|
||||
rg -= (day - night) / 23.0;
|
||||
|
||||
// Emphase blue a bit in darker places
|
||||
// See C++ implementation in mapblock_mesh.cpp finalColorBlend()
|
||||
b += max(0.0, (1.0 - abs(b - 0.13) / 0.17) * 0.025);
|
||||
|
||||
// Artificial light is yellow-ish
|
||||
// See C++ implementation in mapblock_mesh.cpp finalColorBlend()
|
||||
rg += max(0.0, (1.0 - abs(rg - 0.85) / 0.15) * 0.065);
|
||||
|
||||
color.r = rg;
|
||||
color.g = rg;
|
||||
color.b = b;
|
||||
|
||||
color.a = gl_Color.a;
|
||||
gl_FrontColor = gl_BackColor = clamp(color, 0.0, 1.0);
|
||||
}
|
Loading…
Reference in New Issue