Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/shaders/glsl/water_high.fs
Show All 26 Lines | |||||
varying vec3 worldPos; | varying vec3 worldPos; | ||||
varying float waterDepth; | varying float waterDepth; | ||||
varying vec2 waterInfo; | varying vec2 waterInfo; | ||||
varying vec3 v; | varying vec3 v; | ||||
varying vec4 normalCoords; | varying vec4 normalCoords; | ||||
#if USE_REFLECTION | |||||
varying vec3 reflectionCoords; | varying vec3 reflectionCoords; | ||||
#endif | |||||
#if USE_REFRACTION | |||||
varying vec3 refractionCoords; | varying vec3 refractionCoords; | ||||
#endif | |||||
varying vec2 losCoords; | varying vec2 losCoords; | ||||
varying float fwaviness; | varying float fwaviness; | ||||
uniform float mapSize; | uniform float mapSize; | ||||
uniform samplerCube skyCube; | uniform samplerCube skyCube; | ||||
uniform sampler2D normalMap; | uniform sampler2D normalMap; | ||||
uniform sampler2D normalMap2; | uniform sampler2D normalMap2; | ||||
#if USE_FANCY_EFFECTS | #if USE_FANCY_EFFECTS | ||||
uniform sampler2D waterEffectsTexNorm; | uniform sampler2D waterEffectsTexNorm; | ||||
uniform sampler2D waterEffectsTexOther; | uniform sampler2D waterEffectsTexOther; | ||||
#endif | #endif | ||||
uniform vec4 waveParams1; // wavyEffect, BaseScale, Flattenism, Basebump | uniform vec4 waveParams1; // wavyEffect, BaseScale, Flattenism, Basebump | ||||
uniform vec4 waveParams2; // Smallintensity, Smallbase, Bigmovement, Smallmovement | uniform vec4 waveParams2; // Smallintensity, Smallbase, Bigmovement, Smallmovement | ||||
#if USE_REFLECTION | |||||
uniform sampler2D reflectionMap; | uniform sampler2D reflectionMap; | ||||
#endif | |||||
#if USE_REFRACTION | #if USE_REFRACTION | ||||
uniform sampler2D refractionMap; | uniform sampler2D refractionMap; | ||||
#endif | #endif | ||||
#if USE_REAL_DEPTH | #if USE_REAL_DEPTH | ||||
uniform sampler2D depthTex; | uniform sampler2D depthTex; | ||||
#endif | #endif | ||||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | void main() | ||||
ww1.x = wwInterp.x * WindCosSin.x - wwInterp.z * WindCosSin.y; | ww1.x = wwInterp.x * WindCosSin.x - wwInterp.z * WindCosSin.y; | ||||
ww1.z = wwInterp.x * WindCosSin.y + wwInterp.z * WindCosSin.x; | ww1.z = wwInterp.x * WindCosSin.y + wwInterp.z * WindCosSin.x; | ||||
ww1.y = wwInterp.y; | ww1.y = wwInterp.y; | ||||
// Flatten them based on waviness. | // Flatten them based on waviness. | ||||
vec3 n = normalize(mix(vec3(0.0, 1.0, 0.0), ww1, clamp(baseBump + fwaviness / flattenism, 0.0, 1.0))); | vec3 n = normalize(mix(vec3(0.0, 1.0, 0.0), ww1, clamp(baseBump + fwaviness / flattenism, 0.0, 1.0))); | ||||
#if USE_FANCY_EFFECTS | #if USE_FANCY_EFFECTS | ||||
vec4 fancyeffects = texture2D(waterEffectsTexNorm, gl_FragCoord.xy / screenSize); | vec4 fancyeffects = texture2D(waterEffectsTexNorm, gl_FragCoord.xy / screenSize); | ||||
n = mix(vec3(0.0, 1.0, 0.0), n, 0.5 + waterInfo.r / 2.0); | n = mix(vec3(0.0, 1.0, 0.0), n, 0.5 + waterInfo.r / 2.0); | ||||
n.xz = mix(n.xz, fancyeffects.rb, fancyeffects.a / 2.0); | n.xz = mix(n.xz, fancyeffects.rb, fancyeffects.a / 2.0); | ||||
#else | #else | ||||
n = mix(vec3(0.0, 1.0, 0.0), n, 0.5 + waterInfo.r / 2.0); | n = mix(vec3(0.0, 1.0, 0.0), n, 0.5 + waterInfo.r / 2.0); | ||||
#endif | #endif | ||||
n = vec3(-n.x, n.y, -n.z); // The final wave normal vector. | n = vec3(-n.x, n.y, -n.z); // The final wave normal vector. | ||||
// How perpendicular to the normal our view is. Used for fresnel. | // How perpendicular to the normal our view is. Used for fresnel. | ||||
float ndotv = clamp(dot(n, v), 0.0, 1.0); | float ndotv = clamp(dot(n, v), 0.0, 1.0); | ||||
// Fresnel for "how much reflection vs how much refraction". | // Fresnel for "how much reflection vs how much refraction". | ||||
fresnel = clamp(((pow(1.1 - ndotv, 2.0)) * 1.5), 0.1, 0.75); // Approximation. I'm using 1.1 and not 1.0 because it causes artifacts, see #1714 | fresnel = clamp(((pow(1.1 - ndotv, 2.0)) * 1.5), 0.1, 0.75); // Approximation. I'm using 1.1 and not 1.0 because it causes artifacts, see #1714 | ||||
Show All 33 Lines | #if USE_REAL_DEPTH | ||||
// Set depth to the depth at the undistorted point. | // Set depth to the depth at the undistorted point. | ||||
depth = waterDepth_undistorted; | depth = waterDepth_undistorted; | ||||
#else | #else | ||||
// fake depth computation: take the value at the vertex, add some if we are looking at a more oblique angle. | // fake depth computation: take the value at the vertex, add some if we are looking at a more oblique angle. | ||||
depth = waterDepth / (min(0.5, v.y) * 1.5 * min(0.5, v.y) * 2.0); | depth = waterDepth / (min(0.5, v.y) * 1.5 * min(0.5, v.y) * 2.0); | ||||
#endif | #endif | ||||
#if USE_REFRACTION | #if USE_REFRACTION | ||||
// for refraction we want to distort more as depth goes down. | // for refraction we want to distort more as depth goes down. | ||||
// 1) compute a distortion based on depth at the pixel. | // 1) compute a distortion based on depth at the pixel. | ||||
// 2) Re-sample the depth at the target point | // 2) Re-sample the depth at the target point | ||||
// 3) Sample refraction texture | // 3) Sample refraction texture | ||||
// distoFactor controls the amount of distortion relative to wave normals. | // distoFactor controls the amount of distortion relative to wave normals. | ||||
float distoFactor = 0.5 + clamp(depth / 2.0, 0.0, 7.0); | float distoFactor = 0.5 + clamp(depth / 2.0, 0.0, 7.0); | ||||
Show All 36 Lines | #endif | ||||
tex = texture2D(refractionMap, refrCoords + vec2(-blur, -blur + n.x)); | tex = texture2D(refractionMap, refrCoords + vec2(-blur, -blur + n.x)); | ||||
blurColor += vec4(tex.rgb * tex.a, tex.a); | blurColor += vec4(tex.rgb * tex.a, tex.a); | ||||
tex = texture2D(refractionMap, refrCoords + vec2(blur + n.z, -blur)); | tex = texture2D(refractionMap, refrCoords + vec2(blur + n.z, -blur)); | ||||
blurColor += vec4(tex.rgb * tex.a, tex.a); | blurColor += vec4(tex.rgb * tex.a, tex.a); | ||||
blurColor /= blurColor.a; | blurColor /= blurColor.a; | ||||
float blurFactor = (distoFactor / 7.0); | float blurFactor = (distoFactor / 7.0); | ||||
refColor = (refColor + blurColor.rgb * blurFactor) / (1.0 + blurFactor); | refColor = (refColor + blurColor.rgb * blurFactor) / (1.0 + blurFactor); | ||||
// Apply water tint and murk color. | #else // !USE_REFRACTION | ||||
float extFact = 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); | |||||
refrColor = mix(color, colll, extFact); | |||||
#else | |||||
#if USE_FANCY_EFFECTS | #if USE_FANCY_EFFECTS | ||||
depth = max(depth, fancyeffects.a); | depth = max(depth, fancyeffects.a); | ||||
#endif | #endif | ||||
vec3 refColor = color; | |||||
#endif | |||||
// Apply water tint and murk color only. | // 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(color * tint, color, ColextFact); | vec3 colll = mix(refColor * tint, refColor, ColextFact); | ||||
refrColor = mix(color, colll, extFact); | refrColor = mix(color, colll, extFact); | ||||
#endif | |||||
// Reflections | // Reflections | ||||
// 3 level of settings: | // 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 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 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. | // -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. | // reflMod reduces the intensity of reflections somewhat since they kind of wash refractions out otherwise. | ||||
Show All 16 Lines | if (refTex.a < 0.4) | ||||
reflColor = mix(textureCube(skyCube, (vec4(eye, 0.0) * skyBoxRot).xyz).rgb, refTex.rgb, refTex.a); | reflColor = mix(textureCube(skyCube, (vec4(eye, 0.0) * skyBoxRot).xyz).rgb, refTex.rgb, refTex.a); | ||||
// Let actual objects be reflected fully. | // Let actual objects be reflected fully. | ||||
reflMod = max(refTex.a, 0.75); | reflMod = max(refTex.a, 0.75); | ||||
#else | #else | ||||
reflColor = textureCube(skyCube, (vec4(eye, 0.0) * skyBoxRot).xyz).rgb; | reflColor = textureCube(skyCube, (vec4(eye, 0.0) * skyBoxRot).xyz).rgb; | ||||
#endif | #endif | ||||
#else | #else // !USE_REFLECTION && !USE_REFRACTION | ||||
// Simplest case for reflection, return a gradient of blue based on Y component. | // 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); | reflColor = mix(vec3(0.76, 0.84, 0.92), vec3(0.24, 0.43, 0.71), -eye.y); | ||||
#endif | #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; | ||||
Show All 40 Lines |
Wildfire Games · Phabricator