diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-10-03 16:33:42 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2016-10-03 21:35:16 +0200 |
commit | 22d83bc9f655d5ae7a1b49709c4c1b663725daf5 (patch) | |
tree | a817195c08d4713a70ca014a3f63f5937934fe36 /drivers/gles3/shaders | |
parent | 78d97b060a6873a454e710380cb9ef1bde5e4c65 (diff) |
Begining of GLES3 renderer:
-Most 2D drawing is implemented
-Missing shaders
-Missing all 3D
-Editor needs to be set on update always to be used, otherwise it does not refresh
-Large parts of editor not working
Diffstat (limited to 'drivers/gles3/shaders')
-rw-r--r-- | drivers/gles3/shaders/SCsub | 7 | ||||
-rw-r--r-- | drivers/gles3/shaders/canvas.glsl | 428 | ||||
-rw-r--r-- | drivers/gles3/shaders/canvas_shadow.glsl | 49 | ||||
-rw-r--r-- | drivers/gles3/shaders/copy.glsl | 52 |
4 files changed, 536 insertions, 0 deletions
diff --git a/drivers/gles3/shaders/SCsub b/drivers/gles3/shaders/SCsub new file mode 100644 index 0000000000..628fa14e4e --- /dev/null +++ b/drivers/gles3/shaders/SCsub @@ -0,0 +1,7 @@ +Import('env') + +if env['BUILDERS'].has_key('GLES3_GLSL'): + env.GLES3_GLSL('copy.glsl'); + env.GLES3_GLSL('canvas.glsl'); + env.GLES3_GLSL('canvas_shadow.glsl'); + diff --git a/drivers/gles3/shaders/canvas.glsl b/drivers/gles3/shaders/canvas.glsl new file mode 100644 index 0000000000..eed2239ec9 --- /dev/null +++ b/drivers/gles3/shaders/canvas.glsl @@ -0,0 +1,428 @@ +[vertex] + + +layout(location=0) in highp vec3 vertex; +layout(location=3) in vec4 color_attrib; + +#ifdef USE_TEXTURE_RECT + +layout(location=1) in highp vec4 dst_rect; +layout(location=2) in highp vec4 src_rect; + +#else + +layout(location=4) in highp vec2 uv_attrib; + +//skeletn +#endif + + +layout(std140) uniform CanvasItemData { //ubo:0 + + highp mat4 projection_matrix; +}; + +uniform highp mat4 modelview_matrix; +uniform highp mat4 extra_matrix; + + +out mediump vec2 uv_interp; +out mediump vec4 color_interp; + +#if defined(USE_TIME) +uniform float time; +#endif + +#ifdef USE_LIGHTING + +layout(std140) uniform LightData { //ubo:1 + + //light matrices + highp mat4 light_matrix; + highp mat4 light_local_matrix; + highp mat4 shadow_matrix; + highp vec4 light_color; + highp vec4 light_shadow_color; + highp vec2 light_pos; + highp float shadowpixel_size; + highp float shadow_gradient; + highp float light_height; + highp float light_outside_alpha; + highp float shadow_distance_mult; +}; + +out vec4 light_uv_interp; + +#if defined(NORMAL_USED) +out vec4 local_rot; +#endif + +#ifdef USE_SHADOWS +out highp vec2 pos; +#endif + +#endif + + +VERTEX_SHADER_GLOBALS + +void main() { + + color_interp = color_attrib; + + +#ifdef USE_TEXTURE_RECT + + + uv_interp = src_rect.xy + abs(src_rect.zw) * vertex.xy; + highp vec4 outvec = vec4(dst_rect.xy + dst_rect.zw * mix(vertex.xy,vec2(1.0,1.0)-vertex.xy,lessThan(src_rect.zw,vec2(0.0,0.0))),0.0,1.0); + +#else + uv_interp = uv_attrib; + highp vec4 outvec = vec4(vertex, 1.0); +#endif + + +{ + vec2 src_vtx=outvec.xy; + +VERTEX_SHADER_CODE + +} + +#if !defined(USE_WORLD_VEC) + outvec = extra_matrix * outvec; + outvec = modelview_matrix * outvec; +#endif + + + +#ifdef USE_PIXEL_SNAP + + outvec.xy=floor(outvec.xy+0.5); +#endif + + + gl_Position = projection_matrix * outvec; + +#ifdef USE_LIGHTING + + light_uv_interp.xy = (light_matrix * outvec).xy; + light_uv_interp.zw =(light_local_matrix * outvec).xy; +#ifdef USE_SHADOWS + pos=outvec.xy; +#endif + +#if defined(NORMAL_USED) + local_rot.xy=normalize( (modelview_matrix * ( extra_matrix * vec4(1.0,0.0,0.0,0.0) )).xy ); + local_rot.zw=normalize( (modelview_matrix * ( extra_matrix * vec4(0.0,1.0,0.0,0.0) )).xy ); +#ifdef USE_TEXTURE_RECT + local_rot.xy*=sign(src_rect.z); + local_rot.zw*=sign(src_rect.w); +#endif + +#endif + +#endif + +} + +[fragment] + + + +uniform mediump sampler2D color_texture; // texunit:0 + +in mediump vec2 uv_interp; +in mediump vec4 color_interp; + + +#if defined(ENABLE_TEXSCREEN) + +uniform sampler2D texscreen_tex; // texunit:-3 + +#endif + +#if defined(USE_TIME) +uniform float time; +#endif + +#ifdef USE_LIGHTING + +layout(std140) uniform LightData { + + highp mat4 light_matrix; + highp mat4 light_local_matrix; + highp mat4 shadow_matrix; + highp vec4 light_color; + highp vec4 light_shadow_color; + highp vec2 light_pos; + highp float shadowpixel_size; + highp float shadow_gradient; + highp float light_height; + highp float light_outside_alpha; + highp float shadow_distance_mult; +}; + +uniform lowp sampler2D light_texture; // texunit:-1 +in vec4 light_uv_interp; + + +#if defined(NORMAL_USED) +in vec4 local_rot; +#endif + +#ifdef USE_SHADOWS + +uniform highp sampler2D shadow_texture; // texunit:-2 +in highp vec2 pos; + +#endif + +#endif + +uniform mediump vec4 final_modulate; + +FRAGMENT_SHADER_GLOBALS + + +layout(location=0) out mediump vec4 frag_color; + +void main() { + + vec4 color = color_interp; +#if defined(NORMAL_USED) + vec3 normal = vec3(0.0,0.0,1.0); +#endif + +#ifdef USE_DISTANCE_FIELD + const float smoothing = 1.0/32.0; + float distance = texture(color_texture, uv_interp).a; + color.a = smoothstep(0.5 - smoothing, 0.5 + smoothing, distance) * color.a; +#else + color *= texture( color_texture, uv_interp ); + +#endif + + +#if defined(ENABLE_SCREEN_UV) + vec2 screen_uv = gl_FragCoord.xy*screen_uv_mult; +#endif + + +{ +#if defined(USE_NORMALMAP) + vec3 normal_map=vec3(0.0,0.0,1.0); + float normal_depth=1.0; +#endif + +FRAGMENT_SHADER_CODE + +#if defined(USE_NORMALMAP) + normal = mix(vec3(0.0,0.0,1.0), normal_map * vec3(2.0,-2.0,1.0) - vec3( 1.0, -1.0, 0.0 ), normal_depth ); +#endif + +} +#ifdef DEBUG_ENCODED_32 + highp float enc32 = dot( color,highp vec4(1.0 / (256.0 * 256.0 * 256.0),1.0 / (256.0 * 256.0),1.0 / 256.0,1) ); + color = vec4(vec3(enc32),1.0); +#endif + + + color*=final_modulate; + + + + +#ifdef USE_LIGHTING + + vec2 light_vec = light_uv_interp.zw;; //for shadow and normal mapping + +#if defined(NORMAL_USED) + normal.xy = mat2(local_rot.xy,local_rot.zw) * normal.xy; +#endif + + float att=1.0; + + vec2 light_uv = light_uv_interp.xy; + vec4 light = texture(light_texture,light_uv) * light_color; +#if defined(USE_OUTPUT_SHADOW_COLOR) + vec4 shadow_color=vec4(0.0,0.0,0.0,0.0); +#endif + + if (any(lessThan(light_uv_interp.xy,vec2(0.0,0.0))) || any(greaterThanEqual(light_uv_interp.xy,vec2(1.0,1.0)))) { + color.a*=light_outside_alpha; //invisible + + } else { + +#if defined(USE_LIGHT_SHADER_CODE) +//light is written by the light shader + { + vec4 light_out=light*color; +LIGHT_SHADER_CODE + color=light_out; + } + +#else + +#if defined(NORMAL_USED) + vec3 light_normal = normalize(vec3(light_vec,-light_height)); + light*=max(dot(-light_normal,normal),0.0); +#endif + + color*=light; +/* +#ifdef USE_NORMAL + color.xy=local_rot.xy;//normal.xy; + color.zw=vec2(0.0,1.0); +#endif +*/ + +//light shader code +#endif + + +#ifdef USE_SHADOWS + + float angle_to_light = -atan(light_vec.x,light_vec.y); + float PI = 3.14159265358979323846264; + /*int i = int(mod(floor((angle_to_light+7.0*PI/6.0)/(4.0*PI/6.0))+1.0, 3.0)); // +1 pq os indices estao em ordem 2,0,1 nos arrays + float ang*/ + + float su,sz; + + float abs_angle = abs(angle_to_light); + vec2 point; + float sh; + if (abs_angle<45.0*PI/180.0) { + point = light_vec; + sh=0.0+(1.0/8.0); + } else if (abs_angle>135.0*PI/180.0) { + point = -light_vec; + sh = 0.5+(1.0/8.0); + } else if (angle_to_light>0.0) { + + point = vec2(light_vec.y,-light_vec.x); + sh = 0.25+(1.0/8.0); + } else { + + point = vec2(-light_vec.y,light_vec.x); + sh = 0.75+(1.0/8.0); + + } + + + highp vec4 s = shadow_matrix * vec4(point,0.0,1.0); + s.xyz/=s.w; + su=s.x*0.5+0.5; + sz=s.z*0.5+0.5; + //sz=lightlength(light_vec); + + highp float shadow_attenuation=0.0; + +#ifdef USE_RGBA_SHADOWS + +#define SHADOW_DEPTH(m_tex,m_uv) dot(texture2D((m_tex),(m_uv)),vec4(1.0 / (256.0 * 256.0 * 256.0),1.0 / (256.0 * 256.0),1.0 / 256.0,1) ) + +#else + +#define SHADOW_DEPTH(m_tex,m_uv) (texture2D((m_tex),(m_uv)).r) + +#endif + + + +#ifdef SHADOW_USE_GRADIENT + +#define SHADOW_TEST(m_ofs) { highp float sd = SHADOW_DEPTH(shadow_texture,vec2(m_ofs,sh)); shadow_attenuation+=1.0-smoothstep(sd,sd+shadow_gradient,sz); } + +#else + +#define SHADOW_TEST(m_ofs) { highp float sd = SHADOW_DEPTH(shadow_texture,vec2(m_ofs,sh)); shadow_attenuation+=step(sz,sd); } + +#endif + + +#ifdef SHADOW_FILTER_NEAREST + + SHADOW_TEST(su+shadowpixel_size); + +#endif + + +#ifdef SHADOW_FILTER_PCF3 + + SHADOW_TEST(su+shadowpixel_size); + SHADOW_TEST(su); + SHADOW_TEST(su-shadowpixel_size); + shadow_attenuation/=3.0; + +#endif + + +#ifdef SHADOW_FILTER_PCF5 + + SHADOW_TEST(su+shadowpixel_size*3.0); + SHADOW_TEST(su+shadowpixel_size*2.0); + SHADOW_TEST(su+shadowpixel_size); + SHADOW_TEST(su); + SHADOW_TEST(su-shadowpixel_size); + SHADOW_TEST(su-shadowpixel_size*2.0); + SHADOW_TEST(su-shadowpixel_size*3.0); + shadow_attenuation/=5.0; + +#endif + + +#ifdef SHADOW_FILTER_PCF9 + + SHADOW_TEST(su+shadowpixel_size*4.0); + SHADOW_TEST(su+shadowpixel_size*3.0); + SHADOW_TEST(su+shadowpixel_size*2.0); + SHADOW_TEST(su+shadowpixel_size); + SHADOW_TEST(su); + SHADOW_TEST(su-shadowpixel_size); + SHADOW_TEST(su-shadowpixel_size*2.0); + SHADOW_TEST(su-shadowpixel_size*3.0); + SHADOW_TEST(su-shadowpixel_size*4.0); + shadow_attenuation/=9.0; + +#endif + +#ifdef SHADOW_FILTER_PCF13 + + SHADOW_TEST(su+shadowpixel_size*6.0); + SHADOW_TEST(su+shadowpixel_size*5.0); + SHADOW_TEST(su+shadowpixel_size*4.0); + SHADOW_TEST(su+shadowpixel_size*3.0); + SHADOW_TEST(su+shadowpixel_size*2.0); + SHADOW_TEST(su+shadowpixel_size); + SHADOW_TEST(su); + SHADOW_TEST(su-shadowpixel_size); + SHADOW_TEST(su-shadowpixel_size*2.0); + SHADOW_TEST(su-shadowpixel_size*3.0); + SHADOW_TEST(su-shadowpixel_size*4.0); + SHADOW_TEST(su-shadowpixel_size*5.0); + SHADOW_TEST(su-shadowpixel_size*6.0); + shadow_attenuation/=13.0; + +#endif + + +#if defined(USE_OUTPUT_SHADOW_COLOR) + color=mix(shadow_color,color,shadow_attenuation); +#else + //color*=shadow_attenuation; + color=mix(light_shadow_color,color,shadow_attenuation); +#endif +//use shadows +#endif + } + +//use lighting +#endif +// color.rgb*=color.a; + frag_color = color; + +} + diff --git a/drivers/gles3/shaders/canvas_shadow.glsl b/drivers/gles3/shaders/canvas_shadow.glsl new file mode 100644 index 0000000000..c757990de0 --- /dev/null +++ b/drivers/gles3/shaders/canvas_shadow.glsl @@ -0,0 +1,49 @@ +[vertex] + + + +uniform highp mat4 projection_matrix; +uniform highp mat4 light_matrix; +uniform highp mat4 world_matrix; +uniform highp float distance_norm; + +layout(location=0) in highp vec3 vertex; + +out highp vec4 position_interp; + +void main() { + + gl_Position = projection_matrix * (light_matrix * (world_matrix * vec4(vertex,1.0))); + position_interp=gl_Position; +} + +[fragment] + +in highp vec4 position_interp; + +#ifdef USE_RGBA_SHADOWS + +layout(location=0) out lowp vec4 distance_buf; + +#else + +layout(location=0) out highp float distance_buf; + +#endif + +void main() { + + highp float depth = ((position_interp.z / position_interp.w) + 1.0) * 0.5 + 0.0;//bias; + +#ifdef USE_RGBA_SHADOWS + + highp vec4 comp = fract(depth * vec4(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0)); + comp -= comp.xxyz * vec4(0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0); + distance_buf=comp; +#else + + distance_buf=depth; + +#endif +} + diff --git a/drivers/gles3/shaders/copy.glsl b/drivers/gles3/shaders/copy.glsl new file mode 100644 index 0000000000..aba280186a --- /dev/null +++ b/drivers/gles3/shaders/copy.glsl @@ -0,0 +1,52 @@ +[vertex] + + +layout(location=0) in highp vec4 vertex_attrib; +#ifdef USE_CUBEMAP +layout(location=4) in vec3 cube_in; +#else +layout(location=4) in vec2 uv_in; // attrib:4 +#endif +layout(location=5) in vec2 uv2_in; // attrib:5 + +#ifdef USE_CUBEMAP +out vec3 cube_interp; +#else +out vec2 uv_interp; +#endif + +out vec2 uv2_interp; + +void main() { + +#ifdef USE_CUBEMAP + cube_interp = cube_in; +#else + uv_interp = uv_in; +#endif + uv2_interp = uv2_in; + gl_Position = vertex_attrib; +} + +[fragment] + + +#ifdef USE_CUBEMAP +in vec3 cube_interp; +uniform samplerCube source_cube; +#else +in vec2 uv_interp; +uniform sampler2D source; +#endif + +in vec2 uv2_interp; + +layout(location = 0) vec4 frag_color; //color:0 + +void main() { + + //vec4 color = color_interp; + + frag_color = color; +} + |