diff options
Diffstat (limited to 'drivers/gles3/shaders')
-rw-r--r-- | drivers/gles3/shaders/copy.glsl | 13 | ||||
-rw-r--r-- | drivers/gles3/shaders/cubemap_filter.glsl | 2 | ||||
-rw-r--r-- | drivers/gles3/shaders/effect_blur.glsl | 3 | ||||
-rw-r--r-- | drivers/gles3/shaders/particles.glsl | 4 | ||||
-rw-r--r-- | drivers/gles3/shaders/resolve.glsl | 3 | ||||
-rw-r--r-- | drivers/gles3/shaders/scene.glsl | 293 | ||||
-rw-r--r-- | drivers/gles3/shaders/tonemap.glsl | 4 |
7 files changed, 246 insertions, 76 deletions
diff --git a/drivers/gles3/shaders/copy.glsl b/drivers/gles3/shaders/copy.glsl index a7c388815d..d33193ee50 100644 --- a/drivers/gles3/shaders/copy.glsl +++ b/drivers/gles3/shaders/copy.glsl @@ -49,6 +49,9 @@ void main() { #define M_PI 3.14159265359 +#if !defined(USE_GLES_OVER_GL) +precision mediump float; +#endif #if defined(USE_CUBEMAP) || defined(USE_PANORAMA) in vec3 cube_interp; @@ -87,14 +90,6 @@ vec4 texturePanorama(vec3 normal,sampler2D pano ) { #endif -float sRGB_gamma_correct(float c){ - float a = 0.055; - if(c < 0.0031308) - return 12.92*c; - else - return (1.0+a)*pow(c, 1.0/2.4) - a; -} - uniform float stuff; uniform vec2 pixel_size; @@ -131,7 +126,7 @@ void main() { vec4 color = texture( source_cube, normalize(cube_interp) ); #else - vec4 color = texture( source, uv_interp ); + vec4 color = textureLod( source, uv_interp,0.0 ); #endif diff --git a/drivers/gles3/shaders/cubemap_filter.glsl b/drivers/gles3/shaders/cubemap_filter.glsl index ac4e47a440..485fbb6ee0 100644 --- a/drivers/gles3/shaders/cubemap_filter.glsl +++ b/drivers/gles3/shaders/cubemap_filter.glsl @@ -204,7 +204,7 @@ vec4 textureDualParaboloidArray(vec3 normal) { vec3 norm = normalize(normal); norm.xy/=1.0+abs(norm.z); norm.xy=norm.xy * vec2(0.5,0.25) + vec2(0.5,0.25); - if (norm.z<0) { + if (norm.z<0.0) { norm.y=0.5-norm.y+0.5; } return textureLod(source_dual_paraboloid_array, vec3(norm.xy, float(source_array_index) ), 0.0); diff --git a/drivers/gles3/shaders/effect_blur.glsl b/drivers/gles3/shaders/effect_blur.glsl index 2550335174..09e522866c 100644 --- a/drivers/gles3/shaders/effect_blur.glsl +++ b/drivers/gles3/shaders/effect_blur.glsl @@ -25,6 +25,9 @@ void main() { [fragment] +#if !defined(GLES_OVER_GL) +precision mediump float; +#endif in vec2 uv_interp; uniform sampler2D source_color; //texunit:0 diff --git a/drivers/gles3/shaders/particles.glsl b/drivers/gles3/shaders/particles.glsl index 6a977a201e..a62c124dfe 100644 --- a/drivers/gles3/shaders/particles.glsl +++ b/drivers/gles3/shaders/particles.glsl @@ -178,7 +178,7 @@ VERTEX_SHADER_CODE #if !defined(DISABLE_FORCE) - if (true) { + if (false) { vec3 force = vec3(0.0); for(int i=0;i<attractor_count;i++) { @@ -187,7 +187,7 @@ VERTEX_SHADER_CODE float dist = length(rel_vec); if (attractors[i].radius < dist) continue; - if (attractors[i].eat_radius>0 && attractors[i].eat_radius > dist) { + if (attractors[i].eat_radius>0.0 && attractors[i].eat_radius > dist) { out_velocity_active.a=0.0; } diff --git a/drivers/gles3/shaders/resolve.glsl b/drivers/gles3/shaders/resolve.glsl index 181a3c99ec..0b50a9c57b 100644 --- a/drivers/gles3/shaders/resolve.glsl +++ b/drivers/gles3/shaders/resolve.glsl @@ -15,6 +15,9 @@ void main() { [fragment] +#if !defined(GLES_OVER_GL) +precision mediump float; +#endif in vec2 uv_interp; uniform sampler2D source_specular; //texunit:0 diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index 9d474d3902..acece2e639 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -64,44 +64,45 @@ layout(std140) uniform SceneData { //ubo:0 highp mat4 camera_inverse_matrix; highp mat4 camera_matrix; - highp vec4 ambient_light_color; - highp vec4 bg_color; + mediump vec4 ambient_light_color; + mediump vec4 bg_color; - vec4 fog_color_enabled; - vec4 fog_sun_color_amount; + mediump vec4 fog_color_enabled; + mediump vec4 fog_sun_color_amount; - float ambient_energy; - float bg_energy; + mediump float ambient_energy; + mediump float bg_energy; - float z_offset; - float z_slope_scale; - float shadow_dual_paraboloid_render_zfar; - float shadow_dual_paraboloid_render_side; + mediump float z_offset; + mediump float z_slope_scale; + highp float shadow_dual_paraboloid_render_zfar; + highp float shadow_dual_paraboloid_render_side; highp vec2 screen_pixel_size; - vec2 shadow_atlas_pixel_size; - vec2 directional_shadow_pixel_size; + highp vec2 shadow_atlas_pixel_size; + highp vec2 directional_shadow_pixel_size; - float time; - float z_far; - float reflection_multiplier; - float subsurface_scatter_width; - float ambient_occlusion_affect_light; + highp float time; + highp float z_far; + mediump float reflection_multiplier; + mediump float subsurface_scatter_width; + mediump float ambient_occlusion_affect_light; bool fog_depth_enabled; - float fog_depth_begin; - float fog_depth_curve; + highp float fog_depth_begin; + highp float fog_depth_curve; bool fog_transmit_enabled; - float fog_transmit_curve; + highp float fog_transmit_curve; bool fog_height_enabled; - float fog_height_min; - float fog_height_max; - float fog_height_curve; + highp float fog_height_min; + highp float fog_height_max; + highp float fog_height_curve; }; uniform highp mat4 world_transform; + #ifdef USE_LIGHT_DIRECTIONAL layout(std140) uniform DirectionalLightData { //ubo:3 @@ -121,6 +122,90 @@ layout(std140) uniform DirectionalLightData { //ubo:3 #endif +#ifdef USE_VERTEX_LIGHTING +//omni and spot + +struct LightData { + + highp vec4 light_pos_inv_radius; + mediump vec4 light_direction_attenuation; + mediump vec4 light_color_energy; + mediump vec4 light_params; //cone attenuation, angle, specular, shadow enabled, + mediump vec4 light_clamp; + mediump vec4 shadow_color_contact; + highp mat4 shadow_matrix; + +}; + + +layout(std140) uniform OmniLightData { //ubo:4 + + LightData omni_lights[MAX_LIGHT_DATA_STRUCTS]; +}; + +layout(std140) uniform SpotLightData { //ubo:5 + + LightData spot_lights[MAX_LIGHT_DATA_STRUCTS]; +}; + +#ifdef USE_FORWARD_LIGHTING + + +uniform int omni_light_indices[MAX_FORWARD_LIGHTS]; +uniform int omni_light_count; + +uniform int spot_light_indices[MAX_FORWARD_LIGHTS]; +uniform int spot_light_count; + +#endif + +out vec4 diffuse_light_interp; +out vec4 specular_light_interp; + +void light_compute(vec3 N, vec3 L,vec3 V, vec3 light_color,float roughness,inout vec3 diffuse, inout vec3 specular) { + + float dotNL = max(dot(N,L), 0.0 ); + diffuse += dotNL * light_color; + + if (roughness > 0.0) { + + vec3 H = normalize(V + L); + float dotNH = max(dot(N,H), 0.0 ); + float intensity = pow( dotNH, (1.0-roughness) * 256.0); + specular += light_color * intensity; + + } +} + +void light_process_omni(int idx, vec3 vertex, vec3 eye_vec,vec3 normal, float roughness,inout vec3 diffuse, inout vec3 specular) { + + vec3 light_rel_vec = omni_lights[idx].light_pos_inv_radius.xyz-vertex; + float light_length = length( light_rel_vec ); + float normalized_distance = light_length*omni_lights[idx].light_pos_inv_radius.w; + vec3 light_attenuation = vec3(pow( max(1.0 - normalized_distance, 0.0), omni_lights[idx].light_direction_attenuation.w )); + + light_compute(normal,normalize(light_rel_vec),eye_vec,omni_lights[idx].light_color_energy.rgb * light_attenuation,roughness,diffuse,specular); + +} + +void light_process_spot(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, float roughness, inout vec3 diffuse, inout vec3 specular) { + + vec3 light_rel_vec = spot_lights[idx].light_pos_inv_radius.xyz-vertex; + float light_length = length( light_rel_vec ); + float normalized_distance = light_length*spot_lights[idx].light_pos_inv_radius.w; + vec3 light_attenuation = vec3(pow( max(1.0 - normalized_distance, 0.001), spot_lights[idx].light_direction_attenuation.w )); + vec3 spot_dir = spot_lights[idx].light_direction_attenuation.xyz; + float spot_cutoff=spot_lights[idx].light_params.y; + float scos = max(dot(-normalize(light_rel_vec), spot_dir),spot_cutoff); + float spot_rim = (1.0 - scos) / (1.0 - spot_cutoff); + light_attenuation *= 1.0 - pow( max(spot_rim,0.001), spot_lights[idx].light_params.x); + + + light_compute(normal,normalize(light_rel_vec),eye_vec,spot_lights[idx].light_color_energy.rgb*light_attenuation,roughness,diffuse,specular); +} + + +#endif /* Varyings */ @@ -288,6 +373,8 @@ void main() { #endif #endif + float roughness=0.0; + //defines that make writing custom shaders easier #define projection_matrix local_projection #define world_transform world_matrix @@ -376,6 +463,54 @@ VERTEX_SHADER_CODE #endif position_interp=gl_Position; + +#ifdef USE_VERTEX_LIGHTING + + diffuse_light_interp=vec4(0.0); + specular_light_interp=vec4(0.0); + +#ifdef USE_FORWARD_LIGHTING + + for(int i=0;i<omni_light_count;i++) { + light_process_omni(omni_light_indices[i],vertex_interp,-normalize( vertex_interp ),normal_interp,roughness,diffuse_light_interp.rgb,specular_light_interp.rgb); + } + + for(int i=0;i<spot_light_count;i++) { + light_process_spot(spot_light_indices[i],vertex_interp,-normalize( vertex_interp ),normal_interp,roughness,diffuse_light_interp.rgb,specular_light_interp.rgb); + } +#endif + +#ifdef USE_LIGHT_DIRECTIONAL + + vec3 directional_diffuse = vec3(0.0); + vec3 directional_specular = vec3(0.0); + light_compute(normal_interp,-light_direction_attenuation.xyz,-normalize( vertex_interp ),normal_interp,roughness,directional_diffuse,directional_specular); + + float diff_avg = dot(diffuse_light_interp.rgb,vec3(0.33333)); + float diff_dir_avg = dot(directional_diffuse,vec3(0.33333)); + if (diff_avg>0.0) { + diffuse_light_interp.a=diff_dir_avg/(diff_avg+diff_dir_avg); + } else { + diffuse_light_interp.a=1.0; + } + + diffuse_light_interp.rgb+=directional_diffuse; + + float spec_avg = dot(specular_light_interp.rgb,vec3(0.33333)); + float spec_dir_avg = dot(directional_specular,vec3(0.33333)); + if (spec_avg>0.0) { + specular_light_interp.a=spec_dir_avg/(spec_avg+spec_dir_avg); + } else { + specular_light_interp.a=1.0; + } + + specular_light_interp.rgb+=directional_specular; + +#endif //USE_LIGHT_DIRECTIONAL + + +#endif // USE_VERTEX_LIGHTING + } @@ -455,7 +590,7 @@ vec3 textureDualParaboloid(sampler2DArray p_tex, vec3 p_vec,float p_roughness) { // we need to lie the derivatives (normg) and assume that DP side is always the same // to get proper texure filtering vec2 normg=norm.xy; - if (norm.z>0) { + if (norm.z>0.0) { norm.y=0.5-norm.y+0.5; } @@ -479,7 +614,7 @@ vec3 textureDualParaboloid(sampler2D p_tex, vec3 p_vec,float p_roughness) { vec3 norm = normalize(p_vec); norm.xy/=1.0+abs(norm.z); norm.xy=norm.xy * vec2(0.5,0.25) + vec2(0.5,0.25); - if (norm.z>0) { + if (norm.z>0.0) { norm.y=0.5-norm.y+0.5; } return textureLod(p_tex, norm.xy, p_roughness * RADIANCE_MAX_LOD).xyz; @@ -511,39 +646,39 @@ layout(std140) uniform SceneData { highp mat4 camera_inverse_matrix; highp mat4 camera_matrix; - highp vec4 ambient_light_color; - highp vec4 bg_color; + mediump vec4 ambient_light_color; + mediump vec4 bg_color; - vec4 fog_color_enabled; - vec4 fog_sun_color_amount; + mediump vec4 fog_color_enabled; + mediump vec4 fog_sun_color_amount; - float ambient_energy; - float bg_energy; + mediump float ambient_energy; + mediump float bg_energy; - float z_offset; - float z_slope_scale; - float shadow_dual_paraboloid_render_zfar; - float shadow_dual_paraboloid_render_side; + mediump float z_offset; + mediump float z_slope_scale; + highp float shadow_dual_paraboloid_render_zfar; + highp float shadow_dual_paraboloid_render_side; highp vec2 screen_pixel_size; - vec2 shadow_atlas_pixel_size; - vec2 directional_shadow_pixel_size; + highp vec2 shadow_atlas_pixel_size; + highp vec2 directional_shadow_pixel_size; - float time; - float z_far; - float reflection_multiplier; - float subsurface_scatter_width; - float ambient_occlusion_affect_light; + highp float time; + highp float z_far; + mediump float reflection_multiplier; + mediump float subsurface_scatter_width; + mediump float ambient_occlusion_affect_light; bool fog_depth_enabled; - float fog_depth_begin; - float fog_depth_curve; + highp float fog_depth_begin; + highp float fog_depth_curve; bool fog_transmit_enabled; - float fog_transmit_curve; + highp float fog_transmit_curve; bool fog_height_enabled; - float fog_height_min; - float fog_height_max; - float fog_height_curve; + highp float fog_height_min; + highp float fog_height_max; + highp float fog_height_curve; }; //directional light data @@ -570,6 +705,10 @@ uniform highp sampler2DShadow directional_shadow; //texunit:-4 #endif +#ifdef USE_VERTEX_LIGHTING +in vec4 diffuse_light_interp; +in vec4 specular_light_interp; +#endif //omni and spot struct LightData { @@ -655,6 +794,8 @@ layout(location=0) out vec4 frag_color; in highp vec4 position_interp; uniform highp sampler2D depth_buffer; //texunit:-8 +#ifdef USE_CONTACT_SHADOWS + float contact_shadow_compute(vec3 pos, vec3 dir, float max_distance) { if (abs(dir.z)>0.99) @@ -715,6 +856,8 @@ float contact_shadow_compute(vec3 pos, vec3 dir, float max_distance) { return 1.0; } +#endif + // GGX Specular // Source: http://www.filmicworlds.com/images/ggx-opt/optimized-ggx.hlsl float G1V(float dotNV, float k) @@ -1010,13 +1153,16 @@ void light_process_omni(int idx, vec3 vertex, vec3 eye_vec,vec3 normal,vec3 bino splane.xy = clamp_rect.xy+splane.xy*clamp_rect.zw; float shadow = sample_shadow(shadow_atlas,shadow_atlas_pixel_size,splane.xy,splane.z,clamp_rect); + +#ifdef USE_CONTACT_SHADOWS + if (shadow>0.01 && omni_lights[idx].shadow_color_contact.a>0.0) { float contact_shadow = contact_shadow_compute(vertex,normalize(light_rel_vec),min(light_length,omni_lights[idx].shadow_color_contact.a)); shadow=min(shadow,contact_shadow); - } +#endif light_attenuation*=mix(omni_lights[idx].shadow_color_contact.rgb,vec3(1.0),shadow); } @@ -1043,13 +1189,14 @@ void light_process_spot(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 bi float shadow = sample_shadow(shadow_atlas,shadow_atlas_pixel_size,splane.xy,splane.z,spot_lights[idx].light_clamp); +#ifdef USE_CONTACT_SHADOWS if (shadow>0.01 && spot_lights[idx].shadow_color_contact.a>0.0) { float contact_shadow = contact_shadow_compute(vertex,normalize(light_rel_vec),min(light_length,spot_lights[idx].shadow_color_contact.a)); shadow=min(shadow,contact_shadow); } - +#endif light_attenuation*=mix(spot_lights[idx].shadow_color_contact.rgb,vec3(1.0),shadow); } @@ -1097,7 +1244,7 @@ void reflection_process(int idx, vec3 vertex, vec3 normal,vec3 binormal, vec3 ta vec3 norm = normalize(local_ref_vec); norm.xy/=1.0+abs(norm.z); norm.xy=norm.xy * vec2(0.5,0.25) + vec2(0.5,0.25); - if (norm.z>0) { + if (norm.z>0.0) { norm.y=0.5-norm.y+0.5; } @@ -1460,9 +1607,18 @@ FRAGMENT_SHADER_CODE //apply energy conservation +#ifdef USE_VERTEX_LIGHTING + + vec3 specular_light = specular_light_interp.rgb; + vec3 diffuse_light = diffuse_light_interp.rgb; +#else + vec3 specular_light = vec3(0.0,0.0,0.0); - vec3 ambient_light; vec3 diffuse_light = vec3(0.0,0.0,0.0); + +#endif + + vec3 ambient_light; vec3 env_reflection_light = vec3(0.0,0.0,0.0); vec3 eye_vec = -normalize( vertex_interp ); @@ -1515,7 +1671,7 @@ FRAGMENT_SHADER_CODE specular_blob_intensity*=specular * 2.0; #endif -#ifdef USE_LIGHT_DIRECTIONAL +#if defined(USE_LIGHT_DIRECTIONAL) vec3 light_attenuation=vec3(1.0); @@ -1640,13 +1796,14 @@ FRAGMENT_SHADER_CODE } #endif +#ifdef USE_CONTACT_SHADOWS if (shadow>0.01 && shadow_color_contact.a>0.0) { float contact_shadow = contact_shadow_compute(vertex,-light_direction_attenuation.xyz,shadow_color_contact.a); shadow=min(shadow,contact_shadow); } - +#endif light_attenuation=mix(shadow_color_contact.rgb,vec3(1.0),shadow); @@ -1654,7 +1811,13 @@ FRAGMENT_SHADER_CODE #endif //LIGHT_DIRECTIONAL_SHADOW +#ifdef USE_VERTEX_LIGHTING + diffuse_light*=mix(vec3(1.0),light_attenuation,diffuse_light_interp.a); + specular_light*=mix(vec3(1.0),light_attenuation,specular_light_interp.a); + +#else light_compute(normal,-light_direction_attenuation.xyz,eye_vec,binormal,tangent,light_color_energy.rgb*light_attenuation,albedo,light_params.z*specular_blob_intensity,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light); +#endif #endif //#USE_LIGHT_DIRECTIONAL @@ -1664,12 +1827,11 @@ FRAGMENT_SHADER_CODE #endif - #ifdef USE_FORWARD_LIGHTING + highp vec4 reflection_accum = vec4(0.0,0.0,0.0,0.0); highp vec4 ambient_accum = vec4(0.0,0.0,0.0,0.0); - for(int i=0;i<reflection_count;i++) { reflection_process(reflection_indices[i],vertex,normal,binormal,tangent,roughness,anisotropy,ambient_light,env_reflection_light,reflection_accum,ambient_accum); } @@ -1684,6 +1846,13 @@ FRAGMENT_SHADER_CODE ambient_light+=ambient_accum.rgb/ambient_accum.a; } + + +#ifdef USE_VERTEX_LIGHTING + + diffuse_light*=albedo; +#else + for(int i=0;i<omni_light_count;i++) { light_process_omni(omni_light_indices[i],vertex,eye_vec,normal,binormal,tangent,albedo,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,specular_blob_intensity,diffuse_light,specular_light); } @@ -1692,15 +1861,13 @@ FRAGMENT_SHADER_CODE light_process_spot(spot_light_indices[i],vertex,eye_vec,normal,binormal,tangent,albedo,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,specular_blob_intensity,diffuse_light,specular_light); } - +#endif //USE_VERTEX_LIGHTING #endif - - #ifdef RENDER_DEPTH //nothing happens, so a tree-ssa optimizer will result in no fragment shader :) #else @@ -1713,13 +1880,11 @@ FRAGMENT_SHADER_CODE #endif - - - - //energu conservation diffuse_light=mix(diffuse_light,vec3(0.0),metallic); ambient_light=mix(ambient_light,vec3(0.0),metallic); + + { #if defined(DIFFUSE_TOON) @@ -1744,7 +1909,7 @@ FRAGMENT_SHADER_CODE if (fog_color_enabled.a > 0.5) { - float fog_amount=0; + float fog_amount=0.0; diff --git a/drivers/gles3/shaders/tonemap.glsl b/drivers/gles3/shaders/tonemap.glsl index 3ce2edf4e9..c6dfc6917d 100644 --- a/drivers/gles3/shaders/tonemap.glsl +++ b/drivers/gles3/shaders/tonemap.glsl @@ -18,6 +18,10 @@ void main() { [fragment] +#if !defined(GLES_OVER_GL) +precision mediump float; +#endif + in vec2 uv_interp; |