diff options
author | Jeroen Bakker <j.bakker@atmind.nl> | 2018-05-25 09:06:36 +0300 |
---|---|---|
committer | Jeroen Bakker <j.bakker@atmind.nl> | 2018-05-28 18:07:39 +0300 |
commit | 765fd29d6855d098d8fcdd72ba595dfd1e4e4e17 (patch) | |
tree | f1877bfcaf5f4a309f294e2fb516a61c9d6f01aa /source/blender/draw/engines/eevee/shaders/default_world_frag.glsl | |
parent | ce5fa2decad115f023e2f5591255078768b4fa5e (diff) |
EEvEE: LookDev
Diffstat (limited to 'source/blender/draw/engines/eevee/shaders/default_world_frag.glsl')
-rw-r--r-- | source/blender/draw/engines/eevee/shaders/default_world_frag.glsl | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/source/blender/draw/engines/eevee/shaders/default_world_frag.glsl b/source/blender/draw/engines/eevee/shaders/default_world_frag.glsl index 90af87756f0..472d9c577b4 100644 --- a/source/blender/draw/engines/eevee/shaders/default_world_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/default_world_frag.glsl @@ -1,9 +1,57 @@ +#define M_PI 3.14159265358979323846 uniform float backgroundAlpha; +uniform mat4 ProjectionMatrix; +uniform mat4 ProjectionMatrixInverse; +uniform mat4 ViewMatrixInverse; +#ifdef LOOKDEV +uniform mat3 StudioLightMatrix; +uniform sampler2D image; +in vec3 viewPosition; +#else uniform vec3 color; +#endif out vec4 FragColor; +void background_transform_to_world(vec3 viewvec, out vec3 worldvec) +{ + vec4 v = (ProjectionMatrix[3][3] == 0.0) ? vec4(viewvec, 1.0) : vec4(0.0, 0.0, 1.0, 1.0); + vec4 co_homogenous = (ProjectionMatrixInverse * v); + + vec4 co = vec4(co_homogenous.xyz / co_homogenous.w, 0.0); + worldvec = (ViewMatrixInverse * co).xyz; +} + +float hypot(float x, float y) +{ + return sqrt(x * x + y * y); +} + +void node_tex_environment_equirectangular(vec3 co, sampler2D ima, out vec4 color) +{ + vec3 nco = normalize(co); + float u = -atan(nco.y, nco.x) / (2.0 * M_PI) + 0.5; + float v = atan(nco.z, hypot(nco.x, nco.y)) / M_PI + 0.5; + + /* Fix pole bleeding */ + float half_width = 0.5 / float(textureSize(ima, 0).x); + v = clamp(v, half_width, 1.0 - half_width); + + /* Fix u = 0 seam */ + /* This is caused by texture filtering, since uv don't have smooth derivatives + * at u = 0 or 2PI, hardware filtering is using the smallest mipmap for certain + * texels. So we force the highest mipmap and don't do anisotropic filtering. */ + color = textureLod(ima, vec2(u, v), 0.0); +} + void main() { - FragColor = vec4(color, backgroundAlpha); +#ifdef LOOKDEV + vec3 worldvec; + vec4 color; + background_transform_to_world(viewPosition, worldvec); + node_tex_environment_equirectangular(StudioLightMatrix * worldvec, image, color); +#endif + + FragColor = vec4(clamp(color.rgb, vec3(0.0), vec3(1e10)), backgroundAlpha); } |