Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/shaders/glsl/terrain_common.fs
#version 120 | #version 120 | ||||
#include "common/fog.h" | |||||
#include "common/shadows_fragment.h" | |||||
uniform sampler2D baseTex; | uniform sampler2D baseTex; | ||||
uniform sampler2D blendTex; | uniform sampler2D blendTex; | ||||
uniform sampler2D losTex; | uniform sampler2D losTex; | ||||
uniform sampler2D normTex; | uniform sampler2D normTex; | ||||
uniform sampler2D specTex; | 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 shadingColor; | ||||
uniform vec3 ambient; | uniform vec3 ambient; | ||||
uniform vec3 sunColor; | uniform vec3 sunColor; | ||||
uniform vec3 sunDir; | uniform vec3 sunDir; | ||||
uniform vec3 fogColor; | |||||
uniform vec2 fogParams; | |||||
uniform vec2 textureTransform; | uniform vec2 textureTransform; | ||||
varying vec3 v_lighting; | varying vec3 v_lighting; | ||||
#if USE_SHADOW | |||||
varying vec4 v_shadow; | |||||
#endif | |||||
varying vec2 v_los; | varying vec2 v_los; | ||||
varying vec2 v_blend; | varying vec2 v_blend; | ||||
#if USE_TRIPLANAR | #if USE_TRIPLANAR | ||||
varying vec3 v_tex; | varying vec3 v_tex; | ||||
#else | #else | ||||
varying vec2 v_tex; | varying vec2 v_tex; | ||||
#endif | #endif | ||||
Show All 14 Lines | #if USE_NORMAL_MAP | ||||
varying vec4 v_tangent; | varying vec4 v_tangent; | ||||
varying vec3 v_bitangent; | varying vec3 v_bitangent; | ||||
#endif | #endif | ||||
#if USE_SPECULAR || USE_SPECULAR_MAP | #if USE_SPECULAR || USE_SPECULAR_MAP | ||||
varying vec3 v_half; | varying vec3 v_half; | ||||
#endif | #endif | ||||
#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 | #if USE_TRIPLANAR | ||||
vec4 triplanar(sampler2D sampler, vec3 wpos) | vec4 triplanar(sampler2D sampler, vec3 wpos) | ||||
{ | { | ||||
float tighten = 0.4679; | float tighten = 0.4679; | ||||
vec3 blending = abs(normalize(v_normal)) - tighten; | vec3 blending = abs(normalize(v_normal)) - tighten; | ||||
blending = max(blending, 0.0); | blending = max(blending, 0.0); | ||||
Show All 35 Lines | vec4 triplanarNormals(sampler2D sampler, vec3 wpos) | ||||
col3.y = 1.0 - col3.y; | col3.y = 1.0 - col3.y; | ||||
vec4 colBlended = col1 * blending.x + col2 * blending.y + col3 * blending.z; | vec4 colBlended = col1 * blending.x + col2 * blending.y + col3 * blending.z; | ||||
return colBlended; | return colBlended; | ||||
} | } | ||||
#endif | #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() | void main() | ||||
{ | { | ||||
#if BLEND | #if BLEND | ||||
// Use alpha from blend texture | // Use alpha from blend texture | ||||
gl_FragColor.a = 1.0 - texture2D(blendTex, v_blend).a; | gl_FragColor.a = 1.0 - texture2D(blendTex, v_blend).a; | ||||
#if USE_GRASS | #if USE_GRASS | ||||
if (gl_FragColor.a < LAYER / 10.0) | if (gl_FragColor.a < LAYER / 10.0) | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | void main() | ||||
#endif | #endif | ||||
vec3 color = (texdiffuse * sundiffuse + specular.rgb) * get_shadow() + texdiffuse * ambient; | vec3 color = (texdiffuse * sundiffuse + specular.rgb) * get_shadow() + texdiffuse * ambient; | ||||
#if USE_SPECULAR_MAP && USE_SELF_LIGHT | #if USE_SPECULAR_MAP && USE_SELF_LIGHT | ||||
color = mix(texdiffuse, color, specular.a); | color = mix(texdiffuse, color, specular.a); | ||||
#endif | #endif | ||||
#if USE_FOG | color = applyFog(color); | ||||
color = get_fog(color); | |||||
#endif | |||||
float los = texture2D(losTex, v_los).a; | float los = texture2D(losTex, v_los).a; | ||||
los = los < 0.03 ? 0.0 : los; | los = los < 0.03 ? 0.0 : los; | ||||
color *= los; | color *= los; | ||||
#if DECAL | #if DECAL | ||||
color *= shadingColor; | color *= shadingColor; | ||||
#endif | #endif | ||||
gl_FragColor.rgb = color; | gl_FragColor.rgb = color; | ||||
#if USE_GRASS | #if USE_GRASS | ||||
gl_FragColor.a = tex.a; | gl_FragColor.a = tex.a; | ||||
#endif | #endif | ||||
} | } |
Wildfire Games · Phabricator