diff options
Diffstat (limited to 'drivers/gles3/shaders')
-rw-r--r-- | drivers/gles3/shaders/canvas.glsl | 126 | ||||
-rw-r--r-- | drivers/gles3/shaders/copy.glsl | 5 | ||||
-rw-r--r-- | drivers/gles3/shaders/particles.glsl | 9 |
3 files changed, 136 insertions, 4 deletions
diff --git a/drivers/gles3/shaders/canvas.glsl b/drivers/gles3/shaders/canvas.glsl index 7be6ee857a..e97ce62daa 100644 --- a/drivers/gles3/shaders/canvas.glsl +++ b/drivers/gles3/shaders/canvas.glsl @@ -11,11 +11,26 @@ uniform vec4 src_rect; #else +#ifdef USE_INSTANCING + +layout(location=8) in highp vec4 instance_xform0; +layout(location=9) in highp vec4 instance_xform1; +layout(location=10) in highp vec4 instance_xform2; +layout(location=11) in lowp vec4 instance_color; + +#ifdef USE_INSTANCE_CUSTOM +layout(location=12) in highp vec4 instance_custom_data; +#endif + +#endif + layout(location=4) in highp vec2 uv_attrib; //skeletn #endif +uniform highp vec2 color_texpixel_size; + layout(std140) uniform CanvasItemData { //ubo:0 @@ -30,6 +45,12 @@ uniform highp mat4 extra_matrix; out mediump vec2 uv_interp; out mediump vec4 color_interp; +#ifdef USE_NINEPATCH + +out highp vec2 pixel_size_interp; +#endif + + #ifdef USE_LIGHTING layout(std140) uniform LightData { //ubo:1 @@ -64,7 +85,10 @@ const bool at_light_pass = true; const bool at_light_pass = false; #endif - +#ifdef USE_PARTICLES +uniform int h_frames; +uniform int v_frames; +#endif VERTEX_SHADER_GLOBALS @@ -82,6 +106,12 @@ void main() { vec4 vertex_color = color_attrib; +#ifdef USE_INSTANCING + mat4 extra_matrix2 = extra_matrix * transpose(mat4(instance_xform0,instance_xform1,instance_xform2,vec4(0.0,0.0,0.0,1.0))); + vertex_color*=instance_color; +#else + mat4 extra_matrix2 = extra_matrix; +#endif #ifdef USE_TEXTURE_RECT @@ -95,6 +125,22 @@ void main() { #endif +#ifdef USE_PARTICLES + //scale by texture size + outvec.xy/=color_texpixel_size; + + //compute h and v frames and adjust UV interp for animation + int total_frames = h_frames * v_frames; + int frame = min(int(float(total_frames) *instance_custom_data.z),total_frames-1); + float frame_w = 1.0/float(h_frames); + float frame_h = 1.0/float(v_frames); + uv_interp.x = uv_interp.x * frame_w + frame_w * float(frame % h_frames); + uv_interp.y = uv_interp.y * frame_h + frame_h * float(frame / v_frames); + +#endif + +#define extra_matrix extra_matrix2 + { vec2 src_vtx=outvec.xy; @@ -102,11 +148,19 @@ VERTEX_SHADER_CODE } + +#ifdef USE_NINEPATCH + + pixel_size_interp=abs(dst_rect.zw) * vertex; +#endif + #if !defined(SKIP_TRANSFORM_USED) outvec = extra_matrix * outvec; outvec = modelview_matrix * outvec; #endif +#undef extra_matrix + color_interp = vertex_color; #ifdef USE_PIXEL_SNAP @@ -235,6 +289,58 @@ uniform vec4 dst_rect; uniform vec4 src_rect; uniform bool clip_rect_uv; +#ifdef USE_NINEPATCH + +in highp vec2 pixel_size_interp; + +uniform int np_repeat_v; +uniform int np_repeat_h; +uniform bool np_draw_center; +//left top right bottom in pixel coordinates +uniform vec4 np_margins; + + + +float map_ninepatch_axis(float pixel, float draw_size,float tex_pixel_size,float margin_begin,float margin_end,int np_repeat,inout int draw_center) { + + + float tex_size = 1.0/tex_pixel_size; + + if (pixel < margin_begin) { + return pixel * tex_pixel_size; + } else if (pixel >= draw_size-margin_end) { + return (tex_size-(draw_size-pixel)) * tex_pixel_size; + } else { + if (!np_draw_center){ + draw_center--; + } + + if (np_repeat==0) { //stretch + //convert to ratio + float ratio = (pixel - margin_begin) / (draw_size - margin_begin - margin_end); + //scale to source texture + return (margin_begin + ratio * (tex_size - margin_begin - margin_end)) * tex_pixel_size; + } else if (np_repeat==1) { //tile + //convert to ratio + float ofs = mod((pixel - margin_begin), tex_size - margin_begin - margin_end); + //scale to source texture + return (margin_begin + ofs) * tex_pixel_size; + } else if (np_repeat==2) { //tile fit + //convert to ratio + float src_area = draw_size - margin_begin - margin_end; + float dst_area = tex_size - margin_begin - margin_end; + float scale = max(1.0,floor(src_area / max(dst_area,0.0000001) + 0.5)); + + //convert to ratio + float ratio = (pixel - margin_begin) / src_area; + ratio = mod(ratio * scale,1.0); + return (margin_begin + ratio * dst_area) * tex_pixel_size; + } + } + +} + +#endif #endif uniform bool use_default_normal; @@ -245,6 +351,22 @@ void main() { vec2 uv = uv_interp; #ifdef USE_TEXTURE_RECT + +#ifdef USE_NINEPATCH + + int draw_center=2; + uv = vec2( + map_ninepatch_axis(pixel_size_interp.x,abs(dst_rect.z),color_texpixel_size.x,np_margins.x,np_margins.z,np_repeat_h,draw_center), + map_ninepatch_axis(pixel_size_interp.y,abs(dst_rect.w),color_texpixel_size.y,np_margins.y,np_margins.w,np_repeat_v,draw_center) + ); + + if (draw_center==0) { + color.a=0; + } + + uv = uv*src_rect.zw+src_rect.xy; //apply region if needed +#endif + if (clip_rect_uv) { vec2 half_texpixel = color_texpixel_size * 0.5; @@ -267,6 +389,8 @@ void main() { #endif + + vec3 normal; #if defined(NORMAL_USED) diff --git a/drivers/gles3/shaders/copy.glsl b/drivers/gles3/shaders/copy.glsl index 4c8648903e..b0fb525e20 100644 --- a/drivers/gles3/shaders/copy.glsl +++ b/drivers/gles3/shaders/copy.glsl @@ -129,6 +129,11 @@ void main() { color.rgb = mix( (vec3(1.0)+a)*pow(color.rgb,vec3(1.0/2.4))-a , 12.92*color.rgb , lessThan(color.rgb,vec3(0.0031308))); #endif +#ifdef SRGB_TO_LINEAR + + color.rgb = mix(pow((color.rgb + vec3(0.055)) * (1.0 / (1 + 0.055)),vec3(2.4)),color.rgb * (1.0 / 12.92),lessThan(color.rgb,vec3(0.04045))); +#endif + #ifdef DEBUG_GRADIENT color.rg=uv_interp; color.b=0.0; diff --git a/drivers/gles3/shaders/particles.glsl b/drivers/gles3/shaders/particles.glsl index 7e7b083f73..ec2577538c 100644 --- a/drivers/gles3/shaders/particles.glsl +++ b/drivers/gles3/shaders/particles.glsl @@ -37,6 +37,7 @@ uniform bool clear; uniform uint cycle; uniform float lifetime; uniform mat4 emission_transform; +uniform uint random_seed; out highp vec4 out_color; //tfb: @@ -104,7 +105,9 @@ void main() { bool shader_active = velocity_active.a > 0.5; if (system_phase > prev_system_phase) { - if (prev_system_phase < restart_phase && system_phase >= restart_phase) { + // restart_phase >= prev_system_phase is used so particles emit in the first frame they are processed + + if (restart_phase >= prev_system_phase && restart_phase < system_phase ) { restart=true; #ifdef USE_FRACTIONAL_DELTA local_delta = (system_phase - restart_phase) * lifetime; @@ -112,12 +115,12 @@ void main() { } } else { - if (prev_system_phase < restart_phase) { + if (restart_phase >= prev_system_phase) { restart=true; #ifdef USE_FRACTIONAL_DELTA local_delta = (1.0 - restart_phase + system_phase) * lifetime; #endif - } else if (system_phase >= restart_phase) { + } else if (restart_phase < system_phase ) { restart=true; #ifdef USE_FRACTIONAL_DELTA local_delta = (system_phase - restart_phase) * lifetime; |