Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/shaders/glsl/water_high.fs
Show First 20 Lines • Show All 287 Lines • ▼ Show 20 Lines | |||||
#endif | #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. | |||||
float reflMod = 0.75; | float reflMod = 0.75; | ||||
vec3 eye = reflect(v, n); | vec3 eye = reflect(v, n); | ||||
#if USE_REFLECTION || USE_REFRACTION | #if USE_REFLECTION || USE_REFRACTION | ||||
#if USE_REFLECTION | #if USE_REFLECTION | ||||
float refVY = clamp(v.y * 2.0, 0.05, 1.0); | float refVY = clamp(v.y * 2.0, 0.05, 1.0); | ||||
// Distort the reflection coords based on waves. | // Distort the reflection coords based on waves. | ||||
reflCoords = (0.5 * reflectionCoords.xy - 15.0 * n.zx / refVY) / reflectionCoords.z + 0.5; | reflCoords = (0.5 * reflectionCoords.xy - 15.0 * n.zx / refVY) / reflectionCoords.z + 0.5; | ||||
vec4 refTex = texture2D(reflectionMap, reflCoords); | vec4 refTex = texture2D(reflectionMap, reflCoords); | ||||
reflColor = refTex.rgb; | reflColor = refTex.rgb; | ||||
if (refTex.a < 0.99) | if (refTex.a < 0.99) | ||||
{ | |||||
#endif | |||||
// Calculate where we intersect with the skycube. | |||||
Ray myRay = Ray(vec3(worldPos.x / 4.0, worldPos.y, worldPos.z / 4.0), eye); | |||||
vec3 start = vec3(-1500.0 + mapSize / 2.0, -100.0, -1500.0 + mapSize / 2.0); | |||||
vec3 end = vec3(1500.0 + mapSize / 2.0, 500.0, 1500.0 + mapSize / 2.0); | |||||
float tmin = IntersectBox(myRay, start, end); | |||||
vec4 newpos = vec4(-worldPos.x / 4.0, worldPos.y, -worldPos.z / 4.0, 1.0) + vec4(eye * tmin, 0.0) - vec4(-mapSize / 2.0, worldPos.y, -mapSize / 2.0, 0.0); | |||||
newpos *= skyBoxRot; | |||||
newpos.y *= 4.0; | |||||
#if !USE_REFLECTION | |||||
reflColor = textureCube(skyCube, newpos.rgb).rgb; | |||||
#else | |||||
// Interpolate between the sky color and nearby objects. | // Interpolate between the sky color and nearby objects. | ||||
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); | ||||
} | |||||
// reflMod is used to reduce the intensity of sky reflections, which otherwise are too extreme. | // Let actual objects be reflected fully. | ||||
reflMod = max(refTex.a, 0.75); | reflMod = max(refTex.a, 0.75); | ||||
#else | |||||
reflColor = textureCube(skyCube, (vec4(eye, 0.0) * skyBoxRot).xyz).rgb; | |||||
#endif | #endif | ||||
#else | #else | ||||
// 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; | ||||
▲ Show 20 Lines • Show All 41 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator