Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/shaders/glsl/water_high.fs
Show First 20 Lines • Show All 128 Lines • ▼ Show 20 Lines | vec3 get_fog(vec3 color) | ||||
fogFactor = fogFactor * (1.0 - maxFog) + maxFog; | fogFactor = fogFactor * (1.0 - maxFog) + maxFog; | ||||
fogFactor = clamp(fogFactor, 0.0, 1.0); | fogFactor = clamp(fogFactor, 0.0, 1.0); | ||||
return mix(fogColor, color, fogFactor); | return mix(fogColor, color, fogFactor); | ||||
} | } | ||||
vec4 getReflection(vec3 normal) | |||||
{ | |||||
// Reflections | |||||
// 3 level of settings: | |||||
// -If a player has refraction and reflection disabled, we return a gradient of blue based on the Y component. | |||||
// -If a player has refraction OR reflection, we return a reflection of the actual skybox used. | |||||
// -If a player has reflection enabled, we also return a reflection of actual entities where applicable. | |||||
// reflMod reduces the intensity of reflections somewhat since they kind of wash refractions out otherwise. | |||||
float reflMod = 0.75; | |||||
vec3 eye = reflect(v_eyeVec, normal); | |||||
#if USE_REFLECTION || USE_REFRACTION | |||||
#if USE_REFLECTION | |||||
float refVY = clamp(v_eyeVec.y * 2.0, 0.05, 1.0); | |||||
// Distort the reflection coords based on waves. | |||||
vec2 reflCoords = (0.5 * reflectionCoords.xy - 15.0 * normal.zx / refVY) / reflectionCoords.z + 0.5; | |||||
vec4 refTex = texture2D(reflectionMap, reflCoords); | |||||
vec3 reflColor = refTex.rgb; | |||||
// Interpolate between the sky color and nearby objects. | |||||
// Only do this when alpha is rather low, or transparent leaves show up as extremely white. | |||||
if (refTex.a < 0.4) | |||||
reflColor = mix(textureCube(skyCube, (vec4(eye, 0.0) * skyBoxRot).xyz).rgb, refTex.rgb, refTex.a); | |||||
// Let actual objects be reflected fully. | |||||
reflMod = max(refTex.a, 0.75); | |||||
#else | |||||
Stan: We support #elif now I believe that I updated the preprocessor :) | |||||
vec3 reflColor = textureCube(skyCube, (vec4(eye, 0.0) * skyBoxRot).xyz).rgb; | |||||
#endif | |||||
#else // !USE_REFLECTION && !USE_REFRACTION | |||||
// Simplest case for reflection, return a gradient of blue based on Y component. | |||||
vec3 reflColor = mix(vec3(0.76, 0.84, 0.92), vec3(0.24, 0.43, 0.71), -eye.y); | |||||
#endif | |||||
return vec4(reflColor, reflMod); | |||||
} | |||||
void main() | void main() | ||||
{ | { | ||||
float fresnel; | float fresnel; | ||||
vec2 reflCoords, refrCoords; | vec2 refrCoords; | ||||
vec3 reflColor, refrColor, specular; | vec3 refrColor, specular; | ||||
float losMod; | float losMod; | ||||
// Calculate water normals. | // Calculate water normals. | ||||
float wavyEffect = waveParams1.r; | float wavyEffect = waveParams1.r; | ||||
float baseScale = waveParams1.g; | float baseScale = waveParams1.g; | ||||
float flattenism = waveParams1.b; | float flattenism = waveParams1.b; | ||||
float baseBump = waveParams1.a; | float baseBump = waveParams1.a; | ||||
▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | |||||
#endif | #endif | ||||
// Apply water tint and murk color. | // Apply water tint and murk color. | ||||
float extFact = max(0.0, 1.0 - (depth * fixedVy / murky)); | float extFact = max(0.0, 1.0 - (depth * fixedVy / murky)); | ||||
float ColextFact = max(0.0, 1.0 - (depth * fixedVy / murky)); | float ColextFact = max(0.0, 1.0 - (depth * fixedVy / murky)); | ||||
vec3 colll = mix(refColor * tint, refColor, ColextFact); | vec3 colll = mix(refColor * tint, refColor, ColextFact); | ||||
refrColor = mix(color, colll, extFact); | refrColor = mix(color, colll, extFact); | ||||
// Reflections | vec4 reflColor = getReflection(normal); | ||||
// 3 level of settings: | |||||
// -If a player has refraction and reflection disabled, we return a gradient of blue based on the Y component. | |||||
// -If a player has refraction OR reflection, we return a reflection of the actual skybox used. | |||||
// -If a player has reflection enabled, we also return a reflection of actual entities where applicable. | |||||
// reflMod reduces the intensity of reflections somewhat since they kind of wash refractions out otherwise. | |||||
float reflMod = 0.75; | |||||
vec3 eye = reflect(v_eyeVec, normal); | |||||
#if USE_REFLECTION || USE_REFRACTION | |||||
#if USE_REFLECTION | |||||
float refVY = clamp(v_eyeVec.y * 2.0, 0.05, 1.0); | |||||
// Distort the reflection coords based on waves. | |||||
reflCoords = (0.5 * reflectionCoords.xy - 15.0 * normal.zx / refVY) / reflectionCoords.z + 0.5; | |||||
vec4 refTex = texture2D(reflectionMap, reflCoords); | |||||
reflColor = refTex.rgb; | |||||
// Interpolate between the sky color and nearby objects. | |||||
// Only do this when alpha is rather low, or transparent leaves show up as extremely white. | |||||
if (refTex.a < 0.4) | |||||
reflColor = mix(textureCube(skyCube, (vec4(eye, 0.0) * skyBoxRot).xyz).rgb, refTex.rgb, refTex.a); | |||||
// Let actual objects be reflected fully. | |||||
reflMod = max(refTex.a, 0.75); | |||||
#else | |||||
reflColor = textureCube(skyCube, (vec4(eye, 0.0) * skyBoxRot).xyz).rgb; | |||||
#endif | |||||
#else // !USE_REFLECTION && !USE_REFRACTION | |||||
// Simplest case for reflection, return a gradient of blue based on Y component. | |||||
reflColor = mix(vec3(0.76, 0.84, 0.92), vec3(0.24, 0.43, 0.71), -eye.y); | |||||
#endif | |||||
losMod = texture2D(losMap, losCoords.st).a; | losMod = texture2D(losMap, losCoords.st).a; | ||||
losMod = losMod < 0.03 ? 0.0 : losMod; | losMod = losMod < 0.03 ? 0.0 : losMod; | ||||
vec3 color; | vec3 color; | ||||
#if USE_SHADOWS_ON_WATER && USE_SHADOW | #if USE_SHADOWS_ON_WATER && USE_SHADOW | ||||
float fresShadow = mix(fresnel, fresnel * shadow, 0.05 + murkiness * 0.2); | float fresShadow = mix(fresnel, fresnel * shadow, 0.05 + murkiness * 0.2); | ||||
color = mix(refrColor, reflColor, fresShadow * reflMod); | color = mix(refrColor, reflColor.rgb, fresShadow * reflColor.a); | ||||
#else | #else | ||||
color = mix(refrColor, reflColor, fresnel * reflMod); | color = mix(refrColor, reflColor.rgb, fresnel * reflColor.a); | ||||
#endif | #endif | ||||
#if USE_SHADOWS_ON_WATER && USE_SHADOW | #if USE_SHADOWS_ON_WATER && USE_SHADOW | ||||
color += shadow * specular; | color += shadow * specular; | ||||
#else | #else | ||||
color += specular; | color += specular; | ||||
#endif | #endif | ||||
Show All 25 Lines |
Wildfire Games · Phabricator
We support #elif now I believe that I updated the preprocessor :)