diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-06-01 18:55:24 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-06-01 18:56:02 -0300 |
commit | c03131fc9f7aef119f864cc266330855134feb62 (patch) | |
tree | 5d6f3268548724e17a5d986118a9a2f7c4950dce /drivers/gles3/shaders | |
parent | 5dd52320cb5f85cf9cab0be18bf105f46344200d (diff) |
Rework shading modes and change location of light shader
Diffstat (limited to 'drivers/gles3/shaders')
-rw-r--r-- | drivers/gles3/shaders/canvas.glsl | 18 | ||||
-rw-r--r-- | drivers/gles3/shaders/particles.glsl | 4 | ||||
-rw-r--r-- | drivers/gles3/shaders/resolve.glsl | 2 | ||||
-rw-r--r-- | drivers/gles3/shaders/scene.glsl | 65 |
4 files changed, 73 insertions, 16 deletions
diff --git a/drivers/gles3/shaders/canvas.glsl b/drivers/gles3/shaders/canvas.glsl index e6c72da8f1..017009015e 100644 --- a/drivers/gles3/shaders/canvas.glsl +++ b/drivers/gles3/shaders/canvas.glsl @@ -211,6 +211,18 @@ MATERIAL_UNIFORMS #endif + +void light_compute(inout vec3 light,vec3 light_vec,float light_height,vec4 light_color,vec2 light_uv,vec4 shadow,vec3 normal,vec2 uv,vec2 screen_uv,vec4 color) { + +#if defined(USE_LIGHT_SHADER_CODE) + +LIGHT_SHADER_CODE + +#endif + +} + + void main() { vec4 color = color_interp; @@ -285,11 +297,7 @@ FRAGMENT_SHADER_CODE #if defined(USE_LIGHT_SHADER_CODE) //light is written by the light shader - { - vec4 light_out=light*color; -LIGHT_SHADER_CODE - color=light_out; - } + light_compute(light,light_vec,light_height,light_color,light_uv,shadow,normal,uv,screen_uv,color); #else diff --git a/drivers/gles3/shaders/particles.glsl b/drivers/gles3/shaders/particles.glsl index fa12dd7408..5d8a532f87 100644 --- a/drivers/gles3/shaders/particles.glsl +++ b/drivers/gles3/shaders/particles.glsl @@ -244,6 +244,10 @@ MATERIAL_UNIFORMS void main() { { +LIGHT_SHADER_CODE + } + + { FRAGMENT_SHADER_CODE } } diff --git a/drivers/gles3/shaders/resolve.glsl b/drivers/gles3/shaders/resolve.glsl index 6acc712299..181a3c99ec 100644 --- a/drivers/gles3/shaders/resolve.glsl +++ b/drivers/gles3/shaders/resolve.glsl @@ -20,7 +20,7 @@ in vec2 uv_interp; uniform sampler2D source_specular; //texunit:0 uniform sampler2D source_ssr; //texunit:1 -uniform float stuff; +uniform vec2 pixel_size; in vec2 uv2_interp; diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index 81166e84ff..5c65e10dbe 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -623,15 +623,66 @@ float GTR1(float NdotH, float a) void light_compute(vec3 N, vec3 L,vec3 V,vec3 B, vec3 T,vec3 light_color,vec3 diffuse_color, float specular_blob_intensity, float roughness, float rim,float rim_tint, float clearcoat, float clearcoat_gloss,float anisotropy,inout vec3 diffuse, inout vec3 specular) { +#if defined(USE_LIGHT_SHADER_CODE) +//light is written by the light shader + + +LIGHT_SHADER_CODE + + +#else + float dotNL = max(dot(N,L), 0.0 ); - float dotNV = max(dot(N,V), 0.0 ); +#if defined(DIFFUSE_HALF_LAMBERT) + + float hl = dot(N,L) * 0.5 + 0.5; + diffuse += hl * light_color * diffuse_color; + +#elif defined(DIFFUSE_OREN_NAYAR) + + { + float LdotV = dot(L, V); + float NdotL = dot(L, N); + float NdotV = dot(N, V); + + float s = LdotV - NdotL * NdotV; + float t = mix(1.0, max(NdotL, NdotV), step(0.0, s)); + + float sigma2 = roughness * roughness; + vec3 A = 1.0 + sigma2 * (diffuse_color / (sigma2 + 0.13) + 0.5 / (sigma2 + 0.33)); + float B = 0.45 * sigma2 / (sigma2 + 0.09); + + diffuse += diffuse_color * max(0.0, NdotL) * (A + vec3(B) * s / t) / M_PI; + } + +#elif defined(DIFFUSE_BURLEY) + + { + float NdotL = dot(L, N); + float NdotV = dot(N, V); + float VdotH = dot(N, normalize(L+V)); + float energyBias = mix(roughness, 0.0, 0.5); + float energyFactor = mix(roughness, 1.0, 1.0 / 1.51); + float fd90 = energyBias + 2.0 * VdotH * VdotH * roughness; + float f0 = 1.0; + float lightScatter = f0 + (fd90 - f0) * pow(1.0 - NdotL, 5.0); + float viewScatter = f0 + (fd90 - f0) * pow(1.0 - NdotV, 5.0); + + diffuse+= light_color * diffuse_color * lightScatter * viewScatter * energyFactor; + } +#else + + diffuse += dotNL * light_color * diffuse_color; +#endif + + + float dotNV = max(dot(N,V), 0.0 ); #if defined(LIGHT_USE_RIM) float rim_light = pow(1.0-dotNV,(1.0-roughness)*16.0); diffuse += rim_light * rim * mix(vec3(1.0),diffuse_color,rim_tint) * light_color; #endif - diffuse += dotNL * light_color * diffuse_color; if (roughness > 0.0) { @@ -685,6 +736,7 @@ void light_compute(vec3 N, vec3 L,vec3 V,vec3 B, vec3 T,vec3 light_color,vec3 di } +#endif //defined(USE_LIGHT_SHADER_CODE) } @@ -1507,14 +1559,7 @@ FRAGMENT_SHADER_CODE -#if defined(USE_LIGHT_SHADER_CODE) -//light is written by the light shader -{ -LIGHT_SHADER_CODE - -} -#endif #ifdef RENDER_DEPTH //nothing happens, so a tree-ssa optimizer will result in no fragment shader :) @@ -1566,7 +1611,7 @@ LIGHT_SHADER_CODE #endif //ENABLE_AO diffuse_buffer=vec4(emission+diffuse_light+ambient_light,ambient_scale); - specular_buffer=vec4(specular_light,max(specular.r,max(specular.g,specular.b))); + specular_buffer=vec4(specular_light,metallic); normal_mr_buffer=vec4(normalize(normal)*0.5+0.5,roughness); |