forked from mirrors/0ad
Removes GLSL shaders code duplication for fog and shadows
Comments By: Stan Differential Revision: https://code.wildfiregames.com/D3340 This was SVN commit r24598.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
#ifndef INCLUDED_FOG
|
||||
#define INCLUDED_FOG
|
||||
|
||||
#if USE_FOG
|
||||
uniform vec3 fogColor;
|
||||
uniform vec2 fogParams;
|
||||
#endif
|
||||
|
||||
vec3 applyFog(vec3 color)
|
||||
{
|
||||
#if USE_FOG
|
||||
float density = fogParams.x;
|
||||
float maxFog = fogParams.y;
|
||||
|
||||
const float LOG2 = 1.442695;
|
||||
float z = gl_FragCoord.z / gl_FragCoord.w;
|
||||
float fogFactor = exp2(-density * density * z * z * LOG2);
|
||||
|
||||
fogFactor = fogFactor * (1.0 - maxFog) + maxFog;
|
||||
|
||||
fogFactor = clamp(fogFactor, 0.0, 1.0);
|
||||
|
||||
return mix(fogColor, color, fogFactor);
|
||||
#else
|
||||
return color;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // INCLUDED_FOG
|
||||
@@ -0,0 +1,44 @@
|
||||
#ifndef INCLUDED_SHADOWS_FRAGMENT
|
||||
#define INCLUDED_SHADOWS_FRAGMENT
|
||||
|
||||
#if USE_SHADOW
|
||||
varying vec4 v_shadow;
|
||||
#if USE_SHADOW_SAMPLER
|
||||
uniform sampler2DShadow shadowTex;
|
||||
#if USE_SHADOW_PCF
|
||||
uniform vec4 shadowScale;
|
||||
#endif
|
||||
#else
|
||||
uniform sampler2D shadowTex;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
float get_shadow()
|
||||
{
|
||||
float shadowBias = 0.003;
|
||||
#if USE_SHADOW && !DISABLE_RECEIVE_SHADOWS
|
||||
float biasedShdwZ = v_shadow.z - shadowBias;
|
||||
#if USE_SHADOW_SAMPLER
|
||||
#if USE_SHADOW_PCF
|
||||
vec2 offset = fract(v_shadow.xy - 0.5);
|
||||
vec4 size = vec4(offset + 1.0, 2.0 - offset);
|
||||
vec4 weight = (vec4(1.0, 1.0, -0.5, -0.5) + (v_shadow.xy - 0.5*offset).xyxy) * shadowScale.zwzw;
|
||||
return (1.0/9.0)*dot(size.zxzx*size.wwyy,
|
||||
vec4(shadow2D(shadowTex, vec3(weight.zw, biasedShdwZ)).r,
|
||||
shadow2D(shadowTex, vec3(weight.xw, biasedShdwZ)).r,
|
||||
shadow2D(shadowTex, vec3(weight.zy, biasedShdwZ)).r,
|
||||
shadow2D(shadowTex, vec3(weight.xy, biasedShdwZ)).r));
|
||||
#else
|
||||
return shadow2D(shadowTex, vec3(v_shadow.xy, biasedShdwZ)).r;
|
||||
#endif
|
||||
#else
|
||||
if (biasedShdwZ >= 1.0)
|
||||
return 1.0;
|
||||
return (biasedShdwZ < texture2D(shadowTex, v_shadow.xy).x ? 1.0 : 0.0);
|
||||
#endif
|
||||
#else
|
||||
return 1.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // INCLUDED_SHADOWS_FRAGMENT
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef INCLUDED_SHADOWS_VERTEX
|
||||
#define INCLUDED_SHADOWS_VERTEX
|
||||
|
||||
#if USE_SHADOW
|
||||
uniform mat4 shadowTransform;
|
||||
varying vec4 v_shadow;
|
||||
#if USE_SHADOW_SAMPLER && USE_SHADOW_PCF
|
||||
uniform vec4 shadowScale;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void calculatePositionInShadowSpace(vec4 position)
|
||||
{
|
||||
#if USE_SHADOW
|
||||
v_shadow = shadowTransform * position;
|
||||
#if USE_SHADOW_SAMPLER && USE_SHADOW_PCF
|
||||
v_shadow.xy *= shadowScale.xy;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // INCLUDED_SHADOWS_VERTEX
|
||||
@@ -1,23 +1,14 @@
|
||||
#version 120
|
||||
|
||||
#include "common/fog.h"
|
||||
#include "common/shadows_fragment.h"
|
||||
|
||||
uniform sampler2D baseTex;
|
||||
uniform sampler2D losTex;
|
||||
uniform sampler2D aoTex;
|
||||
uniform sampler2D normTex;
|
||||
uniform sampler2D specTex;
|
||||
|
||||
#if USE_SHADOW
|
||||
varying vec4 v_shadow;
|
||||
#if USE_SHADOW_SAMPLER
|
||||
uniform sampler2DShadow shadowTex;
|
||||
#if USE_SHADOW_PCF
|
||||
uniform vec4 shadowScale;
|
||||
#endif
|
||||
#else
|
||||
uniform sampler2D shadowTex;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if USE_OBJECTCOLOR
|
||||
uniform vec3 objectColor;
|
||||
#else
|
||||
@@ -31,9 +22,6 @@ uniform vec3 ambient;
|
||||
uniform vec3 sunColor;
|
||||
uniform vec3 sunDir;
|
||||
|
||||
uniform vec3 fogColor;
|
||||
uniform vec2 fogParams;
|
||||
|
||||
varying vec4 v_lighting;
|
||||
varying vec2 v_tex;
|
||||
varying vec2 v_los;
|
||||
@@ -65,50 +53,6 @@ varying vec2 v_los;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
float get_shadow()
|
||||
{
|
||||
float shadowBias = 0.003;
|
||||
#if USE_SHADOW && !DISABLE_RECEIVE_SHADOWS
|
||||
float biasedShdwZ = v_shadow.z - shadowBias;
|
||||
#if USE_SHADOW_SAMPLER
|
||||
#if USE_SHADOW_PCF
|
||||
vec2 offset = fract(v_shadow.xy - 0.5);
|
||||
vec4 size = vec4(offset + 1.0, 2.0 - offset);
|
||||
vec4 weight = (vec4(1.0, 1.0, -0.5, -0.5) + (v_shadow.xy - 0.5*offset).xyxy) * shadowScale.zwzw;
|
||||
return (1.0/9.0)*dot(size.zxzx*size.wwyy,
|
||||
vec4(shadow2D(shadowTex, vec3(weight.zw, biasedShdwZ)).r,
|
||||
shadow2D(shadowTex, vec3(weight.xw, biasedShdwZ)).r,
|
||||
shadow2D(shadowTex, vec3(weight.zy, biasedShdwZ)).r,
|
||||
shadow2D(shadowTex, vec3(weight.xy, biasedShdwZ)).r));
|
||||
#else
|
||||
return shadow2D(shadowTex, vec3(v_shadow.xy, biasedShdwZ)).r;
|
||||
#endif
|
||||
#else
|
||||
if (biasedShdwZ >= 1.0)
|
||||
return 1.0;
|
||||
return (biasedShdwZ < texture2D(shadowTex, v_shadow.xy).x ? 1.0 : 0.0);
|
||||
#endif
|
||||
#else
|
||||
return 1.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
vec3 get_fog(vec3 color)
|
||||
{
|
||||
float density = fogParams.x;
|
||||
float maxFog = fogParams.y;
|
||||
|
||||
const float LOG2 = 1.442695;
|
||||
float z = gl_FragCoord.z / gl_FragCoord.w;
|
||||
float fogFactor = exp2(-density * density * z * z * LOG2);
|
||||
|
||||
fogFactor = fogFactor * (1.0 - maxFog) + maxFog;
|
||||
|
||||
fogFactor = clamp(fogFactor, 0.0, 1.0);
|
||||
|
||||
return mix(fogColor, color, fogFactor);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 coord = v_tex;
|
||||
@@ -225,9 +169,7 @@ void main()
|
||||
color = mix(texdiffuse, color, specular.a);
|
||||
#endif
|
||||
|
||||
#if USE_FOG
|
||||
color = get_fog(color);
|
||||
#endif
|
||||
color = applyFog(color);
|
||||
|
||||
#if !IGNORE_LOS
|
||||
float los = texture2D(losTex, v_los).a;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#version 120
|
||||
|
||||
#include "common/shadows_vertex.h"
|
||||
|
||||
uniform mat4 transform;
|
||||
uniform vec3 cameraPos;
|
||||
#ifdef GL_ES
|
||||
@@ -10,13 +12,8 @@ uniform vec3 sunDir;
|
||||
uniform vec3 sunColor;
|
||||
#endif
|
||||
uniform vec2 losTransform;
|
||||
uniform mat4 shadowTransform;
|
||||
uniform mat4 instancingTransform;
|
||||
|
||||
#if USE_SHADOW_SAMPLER && USE_SHADOW_PCF
|
||||
uniform vec4 shadowScale;
|
||||
#endif
|
||||
|
||||
#if USE_WIND
|
||||
uniform vec4 sim_time;
|
||||
uniform vec4 windData;
|
||||
@@ -26,10 +23,6 @@ varying vec4 v_lighting;
|
||||
varying vec2 v_tex;
|
||||
varying vec2 v_los;
|
||||
|
||||
#if USE_SHADOW
|
||||
varying vec4 v_shadow;
|
||||
#endif
|
||||
|
||||
#if (USE_INSTANCING || USE_GPU_SKINNING) && USE_AO
|
||||
varying vec2 v_tex2;
|
||||
#endif
|
||||
@@ -173,12 +166,7 @@ void main()
|
||||
v_tex2 = a_uv1;
|
||||
#endif
|
||||
|
||||
#if USE_SHADOW
|
||||
v_shadow = shadowTransform * position;
|
||||
#if USE_SHADOW_SAMPLER && USE_SHADOW_PCF
|
||||
v_shadow.xy *= shadowScale.xy;
|
||||
#endif
|
||||
#endif
|
||||
calculatePositionInShadowSpace(position);
|
||||
|
||||
v_los = position.xz * losTransform.x + losTransform.y;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#version 120
|
||||
|
||||
#include "common/shadows_fragment.h"
|
||||
|
||||
uniform sampler2D baseTex;
|
||||
uniform sampler2D losTex;
|
||||
uniform sampler2D aoTex;
|
||||
@@ -9,17 +11,6 @@ uniform sampler2D specTex;
|
||||
uniform sampler2D waterTex;
|
||||
uniform samplerCube skyCube;
|
||||
|
||||
#if USE_SHADOW
|
||||
#if USE_SHADOW_SAMPLER
|
||||
uniform sampler2DShadow shadowTex;
|
||||
#if USE_SHADOW_PCF
|
||||
uniform vec4 shadowScale;
|
||||
#endif
|
||||
#else
|
||||
uniform sampler2D shadowTex;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if USE_OBJECTCOLOR
|
||||
uniform vec3 objectColor;
|
||||
#else
|
||||
@@ -41,44 +32,14 @@ uniform float murkiness;
|
||||
uniform vec3 reflectionTint;
|
||||
uniform float reflectionTintStrength;
|
||||
|
||||
|
||||
float waterDepth = 4.0;
|
||||
float fullDepth = 5.0; // Depth at which to use full murkiness (shallower water will be clearer)
|
||||
|
||||
|
||||
varying vec4 worldPos;
|
||||
varying vec4 v_tex;
|
||||
varying vec4 v_shadow;
|
||||
varying vec2 v_los;
|
||||
|
||||
|
||||
float get_shadow(vec4 coords)
|
||||
{
|
||||
#if USE_SHADOW && !DISABLE_RECEIVE_SHADOWS
|
||||
#if USE_SHADOW_SAMPLER
|
||||
#if USE_SHADOW_PCF
|
||||
vec2 offset = fract(coords.xy - 0.5);
|
||||
vec4 size = vec4(offset + 1.0, 2.0 - offset);
|
||||
vec4 weight = (vec4(1.0, 1.0, -0.5, -0.5) + (coords.xy - 0.5*offset).xyxy) * shadowScale.zwzw;
|
||||
return (1.0/9.0)*dot(size.zxzx*size.wwyy,
|
||||
vec4(shadow2D(shadowTex, vec3(weight.zw, coords.z)).r,
|
||||
shadow2D(shadowTex, vec3(weight.xw, coords.z)).r,
|
||||
shadow2D(shadowTex, vec3(weight.zy, coords.z)).r,
|
||||
shadow2D(shadowTex, vec3(weight.xy, coords.z)).r));
|
||||
#else
|
||||
return shadow2D(shadowTex, coords.xyz).r;
|
||||
#endif
|
||||
#else
|
||||
if (coords.z >= 1.0)
|
||||
return 1.0;
|
||||
return (coords.z <= texture2D(shadowTex, coords.xy).x ? 1.0 : 0.0);
|
||||
#endif
|
||||
#else
|
||||
return 1.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 n, l, h, v; // Normal, light vector, half-vector and view vector (vector to eye)
|
||||
|
||||
@@ -5,22 +5,18 @@
|
||||
#version 120
|
||||
#endif
|
||||
|
||||
#include "common/shadows_vertex.h"
|
||||
|
||||
uniform mat4 transform;
|
||||
uniform vec3 cameraPos;
|
||||
uniform vec3 sunDir;
|
||||
uniform vec3 sunColor;
|
||||
uniform vec2 losTransform;
|
||||
uniform mat4 shadowTransform;
|
||||
uniform mat4 instancingTransform;
|
||||
|
||||
uniform float sim_time;
|
||||
uniform vec2 translation;
|
||||
|
||||
#if USE_SHADOW_SAMPLER && USE_SHADOW_PCF
|
||||
uniform vec4 shadowScale;
|
||||
#endif
|
||||
|
||||
|
||||
attribute vec3 a_vertex;
|
||||
attribute vec3 a_normal;
|
||||
#if USE_INSTANCING
|
||||
@@ -37,21 +33,16 @@ attribute vec2 a_uv1;
|
||||
attribute vec4 a_skinWeights;
|
||||
#endif
|
||||
|
||||
|
||||
varying vec4 worldPos;
|
||||
varying vec4 v_tex;
|
||||
varying vec4 v_shadow;
|
||||
varying vec2 v_los;
|
||||
|
||||
|
||||
vec4 fakeCos(vec4 x)
|
||||
{
|
||||
vec4 tri = abs(fract(x + 0.5) * 2.0 - 1.0);
|
||||
return tri * tri *(3.0 - 2.0 * tri);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
worldPos = instancingTransform * vec4(a_vertex, 1.0);
|
||||
@@ -60,15 +51,9 @@ void main()
|
||||
|
||||
v_tex.zw = a_uv0;
|
||||
|
||||
#if USE_SHADOW
|
||||
v_shadow = shadowTransform * worldPos;
|
||||
#if USE_SHADOW_SAMPLER && USE_SHADOW_PCF
|
||||
v_shadow.xy *= shadowScale.xy;
|
||||
#endif
|
||||
#endif
|
||||
calculatePositionInShadowSpace(worldPos);
|
||||
|
||||
v_los = worldPos.xz * losTransform.x + losTransform.y;
|
||||
|
||||
gl_Position = transform * worldPos;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,31 +1,19 @@
|
||||
#version 120
|
||||
|
||||
#include "common/shadows_fragment.h"
|
||||
|
||||
uniform sampler2D baseTex;
|
||||
uniform sampler2D losTex;
|
||||
|
||||
|
||||
#if USE_SHADOW
|
||||
#if USE_SHADOW_SAMPLER
|
||||
uniform sampler2DShadow shadowTex;
|
||||
#if USE_SHADOW_PCF
|
||||
uniform vec4 shadowScale;
|
||||
#endif
|
||||
#else
|
||||
uniform sampler2D shadowTex;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
uniform vec3 shadingColor;
|
||||
uniform vec3 ambient;
|
||||
uniform vec3 sunColor;
|
||||
uniform vec3 sunDir;
|
||||
uniform vec3 cameraPos;
|
||||
|
||||
|
||||
uniform float specularPower;
|
||||
uniform vec3 specularColor;
|
||||
|
||||
|
||||
varying vec4 v_tex;
|
||||
varying vec4 v_shadow;
|
||||
varying vec2 v_los;
|
||||
@@ -34,33 +22,6 @@ varying vec3 v_normal;
|
||||
varying float v_transp;
|
||||
varying vec3 v_lighting;
|
||||
|
||||
float get_shadow()
|
||||
{
|
||||
#if USE_SHADOW && !DISABLE_RECEIVE_SHADOWS
|
||||
#if USE_SHADOW_SAMPLER
|
||||
#if USE_SHADOW_PCF
|
||||
vec2 offset = fract(v_shadow.xy - 0.5);
|
||||
vec4 size = vec4(offset + 1.0, 2.0 - offset);
|
||||
vec4 weight = (vec4(1.0, 1.0, -0.5, -0.5) + (v_shadow.xy - 0.5*offset).xyxy) * shadowScale.zwzw;
|
||||
return (1.0/9.0)*dot(size.zxzx*size.wwyy,
|
||||
vec4(shadow2D(shadowTex, vec3(weight.zw, v_shadow.z)).r,
|
||||
shadow2D(shadowTex, vec3(weight.xw, v_shadow.z)).r,
|
||||
shadow2D(shadowTex, vec3(weight.zy, v_shadow.z)).r,
|
||||
shadow2D(shadowTex, vec3(weight.xy, v_shadow.z)).r));
|
||||
#else
|
||||
return shadow2D(shadowTex, v_shadow.xyz).r;
|
||||
#endif
|
||||
#else
|
||||
if (v_shadow.z >= 1.0)
|
||||
return 1.0;
|
||||
return (v_shadow.z <= texture2D(shadowTex, v_shadow.xy).x ? 1.0 : 0.0);
|
||||
#endif
|
||||
#else
|
||||
return 1.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
//vec4 texdiffuse = textureGrad(baseTex, vec3(fract(v_tex.xy), v_tex.z), dFdx(v_tex.xy), dFdy(v_tex.xy));
|
||||
|
||||
@@ -5,22 +5,18 @@
|
||||
#version 120
|
||||
#endif
|
||||
|
||||
#include "common/shadows_vertex.h"
|
||||
|
||||
uniform mat4 transform;
|
||||
uniform vec3 cameraPos;
|
||||
uniform vec3 sunDir;
|
||||
uniform vec3 sunColor;
|
||||
uniform vec2 losTransform;
|
||||
uniform mat4 shadowTransform;
|
||||
uniform mat4 instancingTransform;
|
||||
|
||||
uniform float sim_time;
|
||||
uniform vec2 translation;
|
||||
|
||||
#if USE_SHADOW_SAMPLER && USE_SHADOW_PCF
|
||||
uniform vec4 shadowScale;
|
||||
#endif
|
||||
|
||||
|
||||
attribute vec3 a_vertex;
|
||||
attribute vec3 a_normal;
|
||||
attribute vec2 a_uv0;
|
||||
@@ -28,14 +24,12 @@ attribute vec2 a_uv1;
|
||||
|
||||
varying vec4 worldPos;
|
||||
varying vec4 v_tex;
|
||||
varying vec4 v_shadow;
|
||||
varying vec2 v_los;
|
||||
varying vec3 v_half;
|
||||
varying vec3 v_normal;
|
||||
varying float v_transp;
|
||||
varying vec3 v_lighting;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
worldPos = instancingTransform * vec4(a_vertex, 1.0);
|
||||
@@ -43,12 +37,7 @@ void main()
|
||||
v_tex.xy = a_uv0 + sim_time * translation;
|
||||
v_transp = a_uv1.x;
|
||||
|
||||
#if USE_SHADOW
|
||||
v_shadow = shadowTransform * worldPos;
|
||||
#if USE_SHADOW_SAMPLER && USE_SHADOW_PCF
|
||||
v_shadow.xy *= shadowScale.xy;
|
||||
#endif
|
||||
#endif
|
||||
calculatePositionInShadowSpace(worldPos);
|
||||
|
||||
v_los = worldPos.xz * losTransform.x + losTransform.y;
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#version 110
|
||||
|
||||
#include "common/fog.h"
|
||||
|
||||
uniform sampler2D baseTex;
|
||||
uniform sampler2D losTex;
|
||||
|
||||
@@ -8,24 +10,6 @@ varying vec2 v_los;
|
||||
varying vec4 v_color;
|
||||
|
||||
uniform vec3 sunColor;
|
||||
uniform vec3 fogColor;
|
||||
uniform vec2 fogParams;
|
||||
|
||||
vec4 get_fog(vec4 color)
|
||||
{
|
||||
float density = fogParams.x;
|
||||
float maxFog = fogParams.y;
|
||||
|
||||
const float LOG2 = 1.442695;
|
||||
float z = gl_FragCoord.z / gl_FragCoord.w;
|
||||
float fogFactor = exp2(-density * density * z * z * LOG2);
|
||||
|
||||
fogFactor = fogFactor * (1.0 - maxFog) + maxFog;
|
||||
|
||||
fogFactor = clamp(fogFactor, 0.0, 1.0);
|
||||
|
||||
return vec4(mix(fogColor, color.rgb, fogFactor),color.a);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
@@ -35,9 +19,7 @@ void main()
|
||||
los = los < 0.03 ? 0.0 : los;
|
||||
color.rgb *= los;
|
||||
|
||||
#if USE_FOG
|
||||
color = get_fog(color);
|
||||
#endif
|
||||
color.rgb = applyFog(color.rgb);
|
||||
|
||||
gl_FragColor = color;
|
||||
}
|
||||
|
||||
@@ -1,30 +1,10 @@
|
||||
#version 110
|
||||
|
||||
#include "common/fog.h"
|
||||
|
||||
uniform vec4 playerColor;
|
||||
uniform vec3 fogColor;
|
||||
uniform vec2 fogParams;
|
||||
|
||||
vec3 get_fog(vec3 color)
|
||||
{
|
||||
float density = fogParams.x;
|
||||
float maxFog = fogParams.y;
|
||||
|
||||
const float LOG2 = 1.442695;
|
||||
float z = gl_FragCoord.z / gl_FragCoord.w;
|
||||
float fogFactor = exp2(-density * density * z * z * LOG2);
|
||||
|
||||
fogFactor = fogFactor * (1.0 - maxFog) + maxFog;
|
||||
|
||||
fogFactor = clamp(fogFactor, 0.0, 1.0);
|
||||
|
||||
return mix(fogColor, color, fogFactor);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
#if USE_FOG
|
||||
gl_FragColor = vec4(get_fog(playerColor.rgb), playerColor.a);
|
||||
#else
|
||||
gl_FragColor = vec4(playerColor.rgb, playerColor.a);
|
||||
#endif
|
||||
gl_FragColor = vec4(applyFog(playerColor.rgb), playerColor.a);
|
||||
}
|
||||
|
||||
@@ -1,39 +1,23 @@
|
||||
#version 120
|
||||
|
||||
#include "common/fog.h"
|
||||
#include "common/shadows_fragment.h"
|
||||
|
||||
uniform sampler2D baseTex;
|
||||
uniform sampler2D blendTex;
|
||||
uniform sampler2D losTex;
|
||||
uniform sampler2D normTex;
|
||||
uniform sampler2D specTex;
|
||||
|
||||
#if USE_SHADOW
|
||||
uniform float shadowAngle;
|
||||
#if USE_SHADOW_SAMPLER
|
||||
uniform sampler2DShadow shadowTex;
|
||||
#if USE_SHADOW_PCF
|
||||
uniform vec4 shadowScale;
|
||||
#endif
|
||||
#else
|
||||
uniform sampler2D shadowTex;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
uniform vec3 shadingColor;
|
||||
uniform vec3 ambient;
|
||||
uniform vec3 sunColor;
|
||||
uniform vec3 sunDir;
|
||||
|
||||
uniform vec3 fogColor;
|
||||
uniform vec2 fogParams;
|
||||
|
||||
uniform vec2 textureTransform;
|
||||
|
||||
varying vec3 v_lighting;
|
||||
|
||||
#if USE_SHADOW
|
||||
varying vec4 v_shadow;
|
||||
#endif
|
||||
|
||||
varying vec2 v_los;
|
||||
varying vec2 v_blend;
|
||||
|
||||
@@ -64,34 +48,6 @@ varying vec3 v_normal;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
float get_shadow()
|
||||
{
|
||||
float shadowBias = 0.0005;
|
||||
#if USE_SHADOW && !DISABLE_RECEIVE_SHADOWS
|
||||
float biasedShdwZ = v_shadow.z - shadowBias;
|
||||
#if USE_SHADOW_SAMPLER
|
||||
#if USE_SHADOW_PCF
|
||||
vec2 offset = fract(v_shadow.xy - 0.5);
|
||||
vec4 size = vec4(offset + 1.0, 2.0 - offset);
|
||||
vec4 weight = (vec4(1.0, 1.0, -0.5, -0.5) + (v_shadow.xy - 0.5*offset).xyxy) * shadowScale.zwzw;
|
||||
return (1.0/9.0)*dot(size.zxzx*size.wwyy,
|
||||
vec4(shadow2D(shadowTex, vec3(weight.zw, biasedShdwZ)).r,
|
||||
shadow2D(shadowTex, vec3(weight.xw, biasedShdwZ)).r,
|
||||
shadow2D(shadowTex, vec3(weight.zy, biasedShdwZ)).r,
|
||||
shadow2D(shadowTex, vec3(weight.xy, biasedShdwZ)).r));
|
||||
#else
|
||||
return shadow2D(shadowTex, vec3(v_shadow.xy, biasedShdwZ)).r;
|
||||
#endif
|
||||
#else
|
||||
if (biasedShdwZ >= 1.0)
|
||||
return 1.0;
|
||||
return (biasedShdwZ < texture2D(shadowTex, v_shadow.xy).x ? 1.0 : 0.0);
|
||||
#endif
|
||||
#else
|
||||
return 1.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if USE_TRIPLANAR
|
||||
vec4 triplanar(sampler2D sampler, vec3 wpos)
|
||||
{
|
||||
@@ -143,22 +99,6 @@ vec4 triplanarNormals(sampler2D sampler, vec3 wpos)
|
||||
}
|
||||
#endif
|
||||
|
||||
vec3 get_fog(vec3 color)
|
||||
{
|
||||
float density = fogParams.x;
|
||||
float maxFog = fogParams.y;
|
||||
|
||||
const float LOG2 = 1.442695;
|
||||
float z = gl_FragCoord.z / gl_FragCoord.w;
|
||||
float fogFactor = exp2(-density * density * z * z * LOG2);
|
||||
|
||||
fogFactor = fogFactor * (1.0 - maxFog) + maxFog;
|
||||
|
||||
fogFactor = clamp(fogFactor, 0.0, 1.0);
|
||||
|
||||
return mix(fogColor, color, fogFactor);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
#if BLEND
|
||||
@@ -236,9 +176,7 @@ void main()
|
||||
color = mix(texdiffuse, color, specular.a);
|
||||
#endif
|
||||
|
||||
#if USE_FOG
|
||||
color = get_fog(color);
|
||||
#endif
|
||||
color = applyFog(color);
|
||||
|
||||
float los = texture2D(losTex, v_los).a;
|
||||
los = los < 0.03 ? 0.0 : los;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#version 120
|
||||
|
||||
#include "common/shadows_vertex.h"
|
||||
|
||||
uniform mat4 transform;
|
||||
uniform vec3 cameraPos;
|
||||
#ifdef GL_ES
|
||||
@@ -11,18 +13,9 @@ uniform vec3 sunColor;
|
||||
#endif
|
||||
uniform vec2 textureTransform;
|
||||
uniform vec2 losTransform;
|
||||
uniform mat4 shadowTransform;
|
||||
|
||||
#if USE_SHADOW_SAMPLER && USE_SHADOW_PCF
|
||||
uniform vec4 shadowScale;
|
||||
#endif
|
||||
|
||||
varying vec3 v_lighting;
|
||||
|
||||
#if USE_SHADOW
|
||||
varying vec4 v_shadow;
|
||||
#endif
|
||||
|
||||
varying vec2 v_los;
|
||||
varying vec2 v_blend;
|
||||
|
||||
@@ -44,7 +37,6 @@ varying vec3 v_normal;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
attribute vec3 a_vertex;
|
||||
attribute vec3 a_normal;
|
||||
attribute vec2 a_uv0;
|
||||
@@ -89,12 +81,7 @@ void main()
|
||||
v_blend = a_uv1;
|
||||
#endif
|
||||
|
||||
#if USE_SHADOW
|
||||
v_shadow = shadowTransform * vec4(a_vertex, 1.0);
|
||||
#if USE_SHADOW_SAMPLER && USE_SHADOW_PCF
|
||||
v_shadow.xy *= shadowScale.xy;
|
||||
#endif
|
||||
#endif
|
||||
calculatePositionInShadowSpace(vec4(a_vertex, 1.0));
|
||||
|
||||
v_normal = a_normal;
|
||||
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
#version 110
|
||||
|
||||
#include "common/fog.h"
|
||||
|
||||
#if USE_SHADOWS_ON_WATER
|
||||
#include "common/shadows_fragment.h"
|
||||
#endif
|
||||
|
||||
// Environment settings
|
||||
uniform vec3 ambient;
|
||||
uniform vec3 sunDir;
|
||||
@@ -18,9 +24,6 @@ uniform float murkiness; // Amount of tint to blend in with the refracted color
|
||||
uniform float windAngle;
|
||||
varying vec2 WindCosSin;
|
||||
|
||||
uniform vec3 fogColor;
|
||||
uniform vec2 fogParams;
|
||||
|
||||
uniform vec2 screenSize;
|
||||
varying float moddedTime;
|
||||
|
||||
@@ -66,43 +69,6 @@ uniform vec4 waveParams2; // Smallintensity, Smallbase, Bigmovement, Smallmoveme
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if USE_SHADOWS_ON_WATER && USE_SHADOW
|
||||
varying vec4 v_shadow;
|
||||
#if USE_SHADOW_SAMPLER
|
||||
uniform sampler2DShadow shadowTex;
|
||||
#if USE_SHADOW_PCF
|
||||
uniform vec4 shadowScale;
|
||||
#endif
|
||||
#else
|
||||
uniform sampler2D shadowTex;
|
||||
#endif
|
||||
float get_shadow(vec4 coords)
|
||||
{
|
||||
#if USE_SHADOWS_ON_WATER && !DISABLE_RECEIVE_SHADOWS
|
||||
#if USE_SHADOW_SAMPLER
|
||||
#if USE_SHADOW_PCF
|
||||
vec2 offset = fract(coords.xy - 0.5);
|
||||
vec4 size = vec4(offset + 1.0, 2.0 - offset);
|
||||
vec4 weight = (vec4(1.0, 1.0, -0.5, -0.5) + (coords.xy - 0.5 * offset).xyxy) * shadowScale.zwzw;
|
||||
return (1.0 / 9.0) * dot(size.zxzx * size.wwyy,
|
||||
vec4(shadow2D(shadowTex, vec3(weight.zw, coords.z)).r,
|
||||
shadow2D(shadowTex, vec3(weight.xw, coords.z)).r,
|
||||
shadow2D(shadowTex, vec3(weight.zy, coords.z)).r,
|
||||
shadow2D(shadowTex, vec3(weight.xy, coords.z)).r));
|
||||
#else
|
||||
return shadow2D(shadowTex, coords.xyz).r;
|
||||
#endif
|
||||
#else
|
||||
if (coords.z >= 1.0)
|
||||
return 1.0;
|
||||
return (coords.z <= texture2D(shadowTex, coords.xy).x ? 1.0 : 0.0);
|
||||
#endif
|
||||
#else
|
||||
return 1.0;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
// TODO: convert this to something not only for AABBs
|
||||
struct Ray {
|
||||
vec3 Origin;
|
||||
@@ -117,22 +83,6 @@ float IntersectBox (in Ray ray, in vec3 minimum, in vec3 maximum)
|
||||
return min ( MAX.x, min ( MAX.y, MAX.z ) );
|
||||
}
|
||||
|
||||
vec3 get_fog(vec3 color)
|
||||
{
|
||||
float density = fogParams.x;
|
||||
float maxFog = fogParams.y;
|
||||
|
||||
const float LOG2 = 1.442695;
|
||||
float z = gl_FragCoord.z / gl_FragCoord.w;
|
||||
float fogFactor = exp2(-density * density * z * z * LOG2);
|
||||
|
||||
fogFactor = fogFactor * (1.0 - maxFog) + maxFog;
|
||||
|
||||
fogFactor = clamp(fogFactor, 0.0, 1.0);
|
||||
|
||||
return mix(fogColor, color, fogFactor);
|
||||
}
|
||||
|
||||
vec3 getNormal(vec4 fancyeffects)
|
||||
{
|
||||
float wavyEffect = waveParams1.r;
|
||||
@@ -365,7 +315,7 @@ void main()
|
||||
vec3 specular = getSpecular(normal, eyeVec);
|
||||
|
||||
#if USE_SHADOWS_ON_WATER && USE_SHADOW
|
||||
float shadow = get_shadow(vec4(v_shadow.xy, v_shadow.zw));
|
||||
float shadow = get_shadow();
|
||||
float fresShadow = mix(fresnel, fresnel * shadow, 0.05 + murkiness * 0.2);
|
||||
vec3 color = mix(refrColor.rgb, reflColor.rgb, fresShadow * reflColor.a);
|
||||
color += shadow * specular;
|
||||
@@ -378,9 +328,7 @@ void main()
|
||||
|
||||
color = clamp(mix(color, foam.rgb, foam.a), 0.0, 1.0);
|
||||
|
||||
#if USE_FOG
|
||||
color = get_fog(color);
|
||||
#endif
|
||||
color = applyFog(color);
|
||||
|
||||
float alpha = refrColor.a;
|
||||
float losMod = texture2D(losTex, losCoords.st).a;
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
#version 110
|
||||
|
||||
#if USE_SHADOWS_ON_WATER
|
||||
#include "common/shadows_vertex.h"
|
||||
#endif
|
||||
|
||||
uniform mat4 reflectionMatrix;
|
||||
uniform mat4 refractionMatrix;
|
||||
uniform mat4 losMatrix;
|
||||
uniform mat4 shadowTransform;
|
||||
uniform float repeatScale;
|
||||
uniform float windAngle;
|
||||
// "Wildness" of the reflections and refractions; choose based on texture
|
||||
uniform float waviness;
|
||||
uniform vec3 sunDir;
|
||||
|
||||
#if USE_SHADOW_SAMPLER && USE_SHADOW_PCF
|
||||
uniform vec4 shadowScale;
|
||||
#endif
|
||||
|
||||
uniform float time;
|
||||
|
||||
uniform mat4 transform;
|
||||
@@ -39,10 +38,6 @@ varying vec2 losCoords;
|
||||
varying float fwaviness;
|
||||
varying vec2 WindCosSin;
|
||||
|
||||
#if USE_SHADOW && USE_SHADOWS_ON_WATER
|
||||
varying vec4 v_shadow;
|
||||
#endif
|
||||
|
||||
attribute vec3 a_vertex;
|
||||
attribute vec2 a_waterInfo;
|
||||
attribute vec3 a_otherPosition;
|
||||
@@ -69,11 +64,8 @@ void main()
|
||||
#endif
|
||||
losCoords = (losMatrix * vec4(a_vertex, 1.0)).rg;
|
||||
|
||||
#if USE_SHADOW && USE_SHADOWS_ON_WATER
|
||||
v_shadow = shadowTransform * vec4(a_vertex, 1.0);
|
||||
#if USE_SHADOW_SAMPLER && USE_SHADOW_PCF
|
||||
v_shadow.xy *= shadowScale.xy;
|
||||
#endif
|
||||
#if USE_SHADOWS_ON_WATER
|
||||
calculatePositionInShadowSpace(vec4(a_vertex, 1.0));
|
||||
#endif
|
||||
|
||||
v_eyeVec = normalize(cameraPos - worldPos);
|
||||
|
||||
@@ -101,9 +101,6 @@ public:
|
||||
CStr vertexCode = preprocessor.Preprocess(vertexFile.GetAsString());
|
||||
CStr fragmentCode = preprocessor.Preprocess(fragmentFile.GetAsString());
|
||||
|
||||
// printf(">>>\n%s<<<\n", vertexCode.c_str());
|
||||
// printf(">>>\n%s<<<\n", fragmentCode.c_str());
|
||||
|
||||
if (!Compile(GL_VERTEX_PROGRAM_ARB, "vertex", m_VertexProgram, m_VertexFile, vertexCode))
|
||||
return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user