Skip to content

Commit

Permalink
Materials for paged atlas support (#7581)
Browse files Browse the repository at this point in the history
* Added sprite and particlefx paged materials + shaders

* Use lowp instead
  • Loading branch information
Jhonnyg committed Apr 17, 2023
1 parent eb0b8bd commit 3dbbf1d
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 0 deletions.
14 changes: 14 additions & 0 deletions engine/engine/content/builtins/materials/particlefx_paged_atlas.fp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
varying mediump vec2 var_texcoord0;
varying lowp vec4 var_color;
varying lowp float var_page_index;

uniform lowp sampler2DArray texture_sampler;
uniform lowp vec4 tint;

void main()
{
// Pre-multiply alpha since all runtime textures already are
lowp vec4 tint_pm = vec4(tint.xyz * tint.w, tint.w);
// var_color is vertex color from the particle system, pre-multiplied in vertex program
gl_FragColor = texture2DArray(texture_sampler, vec3(var_texcoord0.xy, var_page_index)) * var_color * tint_pm;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: "particle_paged_atlas"
vertex_program: "/builtins/materials/particlefx_paged_atlas.vp"
fragment_program: "/builtins/materials/particlefx_paged_atlas.fp"
tags: "particle"
vertex_constants {
name: "view_proj"
type: CONSTANT_TYPE_VIEWPROJ
}
fragment_constants {
name: "tint"
type: CONSTANT_TYPE_USER
value: {x: 1 y: 1 z: 1 w: 1}
}
max_page_count: 4
19 changes: 19 additions & 0 deletions engine/engine/content/builtins/materials/particlefx_paged_atlas.vp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
uniform highp mat4 view_proj;

// positions are in world space
attribute highp vec4 position;
attribute mediump vec2 texcoord0;
attribute lowp vec4 color;
attribute lowp float page_index;

varying mediump vec2 var_texcoord0;
varying lowp vec4 var_color;
varying lowp float var_page_index;

void main()
{
gl_Position = view_proj * vec4(position.xyz, 1.0);
var_texcoord0 = texcoord0;
var_color = vec4(color.rgb * color.a, color.a);
var_page_index = page_index;
}
12 changes: 12 additions & 0 deletions engine/engine/content/builtins/materials/sprite_paged_atlas.fp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
varying mediump vec2 var_texcoord0;
varying lowp float var_page_index;

uniform lowp sampler2DArray texture_sampler;
uniform lowp vec4 tint;

void main()
{
// Pre-multiply alpha since all runtime textures already are
lowp vec4 tint_pm = vec4(tint.xyz * tint.w, tint.w);
gl_FragColor = texture2DArray(texture_sampler, vec3(var_texcoord0.xy, var_page_index)) * tint_pm;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: "sprite_paged_atlas"
vertex_program: "/builtins/materials/sprite_paged_atlas.vp"
fragment_program: "/builtins/materials/sprite_paged_atlas.fp"
tags: "tile"
vertex_constants {
name: "view_proj"
type: CONSTANT_TYPE_VIEWPROJ
}
fragment_constants {
name: "tint"
type: CONSTANT_TYPE_USER
value: {x: 1 y: 1 z: 1 w: 1}
}
max_page_count: 4
16 changes: 16 additions & 0 deletions engine/engine/content/builtins/materials/sprite_paged_atlas.vp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
uniform highp mat4 view_proj;

// positions are in world space
attribute highp vec4 position;
attribute mediump vec2 texcoord0;
attribute lowp float page_index;

varying mediump vec2 var_texcoord0;
varying lowp float var_page_index;

void main()
{
gl_Position = view_proj * vec4(position.xyz, 1.0);
var_texcoord0 = texcoord0;
var_page_index = page_index;
}

0 comments on commit 3dbbf1d

Please sign in to comment.