diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2017-03-28 01:09:45 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2017-03-28 01:09:45 +0300 |
commit | 6d21970aa06a31398ed4a78b1c596f30a0b9ee87 (patch) | |
tree | afd21bd7a3f0c98020c9207d631e1e96da73dfb0 /source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl | |
parent | 4d3d10f6251c09006890ebb00f490d4915d47a96 (diff) |
Eevee: Diffuse Lights (1 / 2)
I added srgb tonemapping for previewing purpose. Also since the color buffer is still not HDR, there is ugly artifacts (fixed in part2)
Diffstat (limited to 'source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl')
-rw-r--r-- | source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl | 72 |
1 files changed, 66 insertions, 6 deletions
diff --git a/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl b/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl index bd0f3da74c8..19498a611e8 100644 --- a/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl @@ -2,11 +2,28 @@ uniform int light_count; struct LightData { - vec4 position; - vec4 colorAndSpec; /* w : Spec Intensity */ - vec4 spotAndAreaData; + vec4 positionAndInfluence; /* w : InfluenceRadius */ + vec4 colorAndSpec; /* w : Spec Intensity */ + vec4 spotDataRadiusShadow; /* x : spot size, y : spot blend */ + vec4 rightVecAndSizex; /* xyz: Normalized up vector, w: Lamp Type */ + vec4 upVecAndSizey; /* xyz: Normalized right vector, w: Lamp Type */ + vec4 forwardVecAndType; /* xyz: Normalized forward vector, w: Lamp Type */ }; +/* convenience aliases */ +#define lampColor colorAndSpec.rgb +#define lampSpec colorAndSpec.a +#define lampPosition positionAndInfluence.xyz +#define lampInfluence positionAndInfluence.w +#define lampSizeX rightVecAndSizex.w +#define lampSizeY upVecAndSizey.w +#define lampRight rightVecAndSizex.xyz +#define lampUp upVecAndSizey.xyz +#define lampForward forwardVecAndType.xyz +#define lampType forwardVecAndType.w +#define lampSpotSize spotDataRadiusShadow.x +#define lampSpotBlend spotDataRadiusShadow.y + layout(std140) uniform light_block { LightData lights_data[MAX_LIGHT]; }; @@ -16,14 +33,57 @@ in vec3 worldNormal; out vec4 fragColor; +/* type */ +#define POINT 0.0 +#define SUN 1.0 +#define SPOT 2.0 +#define HEMI 3.0 +#define AREA 4.0 + +vec3 light_diffuse(LightData ld, vec3 N, vec3 W, vec3 color) { + vec3 light, wL, L; + + if (ld.lampType == SUN) { + L = -ld.lampForward; + light = color * direct_diffuse_sun(N, L) * ld.lampColor; + } + else { + wL = ld.lampPosition - W; + float dist = length(wL); + light = color * direct_diffuse_point(N, wL / dist, dist) * ld.lampColor; + } + + if (ld.lampType == SPOT) { + float z = dot(ld.lampForward, wL); + vec3 lL = wL / z; + float x = dot(ld.lampRight, lL) / ld.lampSizeX; + float y = dot(ld.lampUp, lL) / ld.lampSizeY; + + float ellipse = 1.0 / sqrt(1.0 + x * x + y * y); + + float spotmask = smoothstep(0.0, 1.0, (ellipse - ld.lampSpotSize) / ld.lampSpotBlend); + + light *= spotmask; + } + + return light; +} + +vec3 light_specular(LightData ld, vec3 V, vec3 N, vec3 T, vec3 B, vec3 spec, float roughness) { + vec3 L = normalize(ld.lampPosition - worldPosition); + vec3 light = L; + + return light; +} + void main() { vec3 n = normalize(worldNormal); vec3 diffuse = vec3(0.0); + vec3 albedo = vec3(1.0, 1.0, 1.0); + for (int i = 0; i < MAX_LIGHT && i < light_count; ++i) { - LightData ld = lights_data[i]; - vec3 l = normalize(ld.position.xyz - worldPosition); - diffuse += max(0.0, dot(l, n)) * ld.colorAndSpec.rgb / 3.14159; + diffuse += light_diffuse(lights_data[i], n, worldPosition, albedo); } fragColor = vec4(diffuse,1.0); |