//////////////////////////////////////////////// // // sky shaders // //////////////////////////////////////////////// shader 0 "skybox" [ attribute vec4 vvertex, vcolor; attribute vec2 vtexcoord0; uniform mat4 skymatrix; uniform float ldrscale; varying vec4 colorscale; varying vec2 texcoord0; void main(void) { gl_Position = skymatrix * vvertex; texcoord0 = vtexcoord0; colorscale = vec4(ldrscale * vcolor.rgb, vcolor.a); } ] [ uniform sampler2D tex0; varying vec4 colorscale; varying vec2 texcoord0; fragdata(0) vec4 fragcolor; void main(void) { vec4 color = texture2D(tex0, texcoord0); fragcolor = colorscale * color; } ] shader 0 "skyboxoverbright" [ attribute vec4 vvertex, vcolor; attribute vec2 vtexcoord0; uniform mat4 skymatrix; uniform float ldrscale; varying vec4 colorscale; varying vec2 texcoord0; void main(void) { gl_Position = skymatrix * vvertex; texcoord0 = vtexcoord0; colorscale = vec4(ldrscale * vcolor.rgb, vcolor.a); } ] [ uniform sampler2D tex0; uniform vec3 overbrightparams; uniform float ldrscale; varying vec4 colorscale; varying vec2 texcoord0; fragdata(0) vec4 fragcolor; void main(void) { vec4 color = texture2D(tex0, texcoord0); float lum = dot(vec3(@lumweights), color.rgb); float overbright = mix(overbrightparams.x, overbrightparams.y, clamp(lum - overbrightparams.z, 0.0, 1.0)); color.rgb *= overbright; fragcolor = colorscale * color; } ] shader 0 "atmosphere" [ attribute vec4 vvertex; uniform mat4 sunmatrix; varying vec3 camvec; void main(void) { gl_Position = vvertex; vec4 p = sunmatrix * vvertex; camvec = p.xyz / p.w; } ] [ uniform vec4 sunlight; uniform vec3 sundir; uniform vec3 sunweight; uniform vec3 sundiskcolor; uniform vec2 sundiskparams; uniform vec4 opticaldepthparams; uniform vec3 mieparams; uniform vec3 betarayleigh, betamie, betaozone; uniform vec2 hdrgamma; varying vec3 camvec; fragdata(0) vec4 fragcolor; void main(void) { vec3 camdir = normalize(camvec); float costheta = dot(camdir, sundir); // sun disk float edgeoffset = max(1.0 - (1.0 - max(costheta, 0.0)*costheta)*sundiskparams.x, 0.0); // limb darken with distance to edge vec3 limbdarken = pow(vec3(edgeoffset), vec3(0.397, 0.503, 0.64)); // lighten edges for corona, but limit it to not interfere with limb darkening float corona = min(edgeoffset * sundiskparams.y, 1.0); corona = max(0.1725 / (1.15 - corona * corona) - 0.15, 0.0); // apply limb darkening and corona to clamped sunlight color vec3 sundisk = sundiskcolor * limbdarken * corona; // optical depth along view ray float offset = camdir.z*opticaldepthparams.w; vec3 depth = sqrt(offset*offset + opticaldepthparams.xyz) - offset; vec3 rayleighweight = betarayleigh * depth.x; vec3 mieweight = betamie * depth.y; vec3 ozoneweight = betaozone * (depth.z - depth.x); // extinction of light along view ray vec3 viewweight = sunweight - (rayleighweight + mieweight + ozoneweight); vec3 extinction = (exp2(viewweight) - 1.0) / viewweight; // calculate in-scattering float rphase = (1.5 + 0.5*costheta*costheta) * (3.0 / (16.0 * 3.14159265)); float mphase = inversesqrt(mieparams.x + mieparams.y*min(costheta, mieparams.z)); vec3 scatter = rayleighweight * rphase + mieweight * (mphase * mphase * mphase); // combine scattering and extinction with sundisk vec3 inscatter = (sunlight.rgb * scatter + sundisk) * extinction; @(hdrgammaencode inscatter) fragcolor = vec4(inscatter, sunlight.a); } ] shader 0 "skyfog" [ attribute vec4 vvertex, vcolor; uniform mat4 skymatrix; uniform float ldrscale; varying vec4 color; void main(void) { gl_Position = skymatrix * vvertex; color = vec4(ldrscale * vcolor.rgb, vcolor.a); } ] [ uniform sampler2D tex0; varying vec4 color; fragdata(0) vec4 fragcolor; void main(void) { fragcolor = color; } ]