mirror of
https://github.com/Insality/druid
synced 2025-09-27 18:12:21 +02:00
Test shaders
This commit is contained in:
84
druid/materials/gui_repeat/gui_repeat.fp
Normal file
84
druid/materials/gui_repeat/gui_repeat.fp
Normal file
@@ -0,0 +1,84 @@
|
||||
#version 140
|
||||
|
||||
uniform sampler2D texture_sampler;
|
||||
|
||||
in vec2 var_texcoord0;
|
||||
in vec4 var_color;
|
||||
in vec4 var_uv;
|
||||
in vec4 var_repeat; // [repeat_x, repeat_y, anchor_x, anchor_y]
|
||||
in vec4 var_params; // [margin_x, margin_y, offset_x, offset_y]
|
||||
in vec4 var_perspective;
|
||||
in vec4 var_uv_rotated;
|
||||
|
||||
out vec4 color_out;
|
||||
|
||||
void main() {
|
||||
vec2 pivot = var_repeat.zw;
|
||||
// Margin is a value between 0 and 1 that means offset/padding from the one image to another
|
||||
vec2 margin = var_params.xy;
|
||||
vec2 offset = var_params.zw;
|
||||
vec2 repeat = var_repeat.xy;
|
||||
|
||||
// Atlas UV to local UV [0, 1]
|
||||
float u = (var_texcoord0.x - var_uv.x) / (var_uv.z - var_uv.x);
|
||||
float v = (var_texcoord0.y - var_uv.y) / (var_uv.w - var_uv.y);
|
||||
|
||||
// Adjust local UV by the pivot point. So 0:0 will be at the pivot point of node
|
||||
u = u - (0.5 + pivot.x);
|
||||
v = v - (0.5 - pivot.y);
|
||||
|
||||
// If rotated, swap UV
|
||||
if (var_uv_rotated.y < 0.5) {
|
||||
float temp = u;
|
||||
u = v;
|
||||
v = temp;
|
||||
}
|
||||
|
||||
// Adjust repeat by the margin
|
||||
repeat.x = repeat.x / (1.0 + margin.x);
|
||||
repeat.y = repeat.y / (1.0 + margin.y);
|
||||
|
||||
// Repeat is a value between 0 and 1 that represents the number of times the texture is repeated in the atlas.
|
||||
float tile_u = fract(u * repeat.x);
|
||||
float tile_v = fract(v * repeat.y);
|
||||
|
||||
float tile_width = 1.0 / repeat.x;
|
||||
float tile_height = 1.0 / repeat.y;
|
||||
|
||||
// Adjust tile UV by the pivot point.
|
||||
// Not center is left top corner, need to adjust it to pivot point
|
||||
tile_u = fract(tile_u + pivot.x + 0.5);
|
||||
tile_v = fract(tile_v - pivot.y + 0.5);
|
||||
|
||||
// Apply offset
|
||||
tile_u = fract(tile_u + offset.x);
|
||||
tile_v = fract(tile_v + offset.y);
|
||||
|
||||
// Extend margins
|
||||
margin = margin * 0.5;
|
||||
tile_u = mix(0.0 - margin.x, 1.0 + margin.x, tile_u);
|
||||
tile_v = mix(0.0 - margin.y, 1.0 + margin.y, tile_v);
|
||||
float alpha = 0.0;
|
||||
// If the tile is outside the margins, make it transparent, without IF
|
||||
alpha = step(0.0, tile_u) * step(tile_u, 1.0) * step(0.0, tile_v) * step(tile_v, 1.0);
|
||||
|
||||
tile_u = clamp(tile_u, 0.0, 1.0); // Keep borders in the range 0-1
|
||||
tile_v = clamp(tile_v, 0.0, 1.0); // Keep borders in the range 0-1
|
||||
|
||||
if (var_uv_rotated.y < 0.5) {
|
||||
float temp = tile_u;
|
||||
tile_u = tile_v;
|
||||
tile_v = temp;
|
||||
}
|
||||
|
||||
// Remap local UV to the atlas UV
|
||||
vec2 uv = vec2(
|
||||
mix(var_uv.x, var_uv.z, tile_u), // Get texture coordinate from the atlas
|
||||
mix(var_uv.y, var_uv.w, tile_v) // Get texture coordinate from the atlas
|
||||
//mix(var_uv.x, var_uv.z, tile_u * var_uv_rotated.x + tile_v * var_uv_rotated.z),
|
||||
//mix(var_uv.y, var_uv.w, 1.0 - (tile_u * var_uv_rotated.y + tile_v * var_uv_rotated.x))
|
||||
);
|
||||
|
||||
lowp vec4 tex = texture(texture_sampler, uv);
|
||||
color_out = tex * var_color;
|
||||
}
|
43
druid/materials/gui_repeat/gui_repeat.material
Normal file
43
druid/materials/gui_repeat/gui_repeat.material
Normal file
@@ -0,0 +1,43 @@
|
||||
name: "repeat"
|
||||
tags: "gui"
|
||||
vertex_program: "/druid/materials/gui_repeat/gui_repeat.vp"
|
||||
fragment_program: "/druid/materials/gui_repeat/gui_repeat.fp"
|
||||
vertex_constants {
|
||||
name: "view_proj"
|
||||
type: CONSTANT_TYPE_VIEWPROJ
|
||||
}
|
||||
vertex_constants {
|
||||
name: "uv_coord"
|
||||
type: CONSTANT_TYPE_USER
|
||||
value {
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
}
|
||||
vertex_constants {
|
||||
name: "uv_repeat"
|
||||
type: CONSTANT_TYPE_USER
|
||||
value {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
}
|
||||
}
|
||||
vertex_constants {
|
||||
name: "params"
|
||||
type: CONSTANT_TYPE_USER
|
||||
value {
|
||||
}
|
||||
}
|
||||
vertex_constants {
|
||||
name: "perspective"
|
||||
type: CONSTANT_TYPE_USER
|
||||
value {
|
||||
}
|
||||
}
|
||||
vertex_constants {
|
||||
name: "uv_rotated"
|
||||
type: CONSTANT_TYPE_USER
|
||||
value {
|
||||
x: 1.0
|
||||
}
|
||||
}
|
55
druid/materials/gui_repeat/gui_repeat.vp
Normal file
55
druid/materials/gui_repeat/gui_repeat.vp
Normal file
@@ -0,0 +1,55 @@
|
||||
#version 140
|
||||
|
||||
in mediump vec3 position;
|
||||
in mediump vec2 texcoord0;
|
||||
in lowp vec4 color;
|
||||
|
||||
uniform vertex_inputs
|
||||
{
|
||||
highp mat4 view_proj;
|
||||
highp vec4 uv_coord;
|
||||
highp vec4 uv_repeat; // [repeat_x, repeat_y, pivot_x, pivot_y]
|
||||
vec4 uv_rotated;
|
||||
vec4 params; // [margin_x, margin_y, offset_x, offset_y]
|
||||
vec4 perspective; // [perspective_x, perspective_y, zoom, offset_y]
|
||||
};
|
||||
|
||||
out mediump vec2 var_texcoord0;
|
||||
out lowp vec4 var_color;
|
||||
out highp vec4 var_uv;
|
||||
out highp vec4 var_repeat;
|
||||
out vec4 var_params;
|
||||
out vec4 var_perspective;
|
||||
out vec4 var_uv_rotated;
|
||||
|
||||
void main()
|
||||
{
|
||||
var_texcoord0 = texcoord0;
|
||||
var_color = vec4(color.rgb * color.a, color.a);
|
||||
var_uv = uv_coord;
|
||||
var_repeat = uv_repeat;
|
||||
var_params = params;
|
||||
var_perspective = perspective;
|
||||
var_uv_rotated = uv_rotated;
|
||||
|
||||
float perspective_y = position.z;
|
||||
|
||||
float scale_x = 1.0 - abs(perspective.x);
|
||||
float scale_y = 1.0 - abs(perspective_y);
|
||||
|
||||
mat4 transform = mat4(
|
||||
scale_x, 0, 0, perspective.z,
|
||||
0, scale_y, 0, perspective.w,
|
||||
0, 0, 1, 0,
|
||||
perspective.x, perspective_y, 0, 1.0
|
||||
);
|
||||
|
||||
// Matrix Info = mat4(
|
||||
// scale_x, skew_x, 0, offset_x,
|
||||
// skew_y, scale_y, 0, offset_y,
|
||||
// 0, 0, scale_z, offset_z,
|
||||
// perspective_x, perspective_y, perspective_z, zoom
|
||||
//)
|
||||
|
||||
gl_Position = view_proj * vec4(position.xyz, 1.0) * transform;
|
||||
}
|
18
druid/materials/skew/gui_skew.fp
Normal file
18
druid/materials/skew/gui_skew.fp
Normal file
@@ -0,0 +1,18 @@
|
||||
#version 140
|
||||
|
||||
uniform sampler2D texture_sampler;
|
||||
|
||||
in vec2 var_texcoord0;
|
||||
in vec4 var_color;
|
||||
|
||||
out vec4 color_out;
|
||||
|
||||
void main() {
|
||||
lowp vec4 tex = texture(texture_sampler, var_texcoord0.xy);
|
||||
if (tex.a < 0.5) {
|
||||
discard;
|
||||
}
|
||||
|
||||
// Final color of stencil texture
|
||||
color_out = tex * var_color;
|
||||
}
|
8
druid/materials/skew/gui_skew.material
Normal file
8
druid/materials/skew/gui_skew.material
Normal file
@@ -0,0 +1,8 @@
|
||||
name: "repeat"
|
||||
tags: "gui"
|
||||
vertex_program: "/druid/materials/stencil/gui_stencil.vp"
|
||||
fragment_program: "/druid/materials/stencil/gui_stencil.fp"
|
||||
vertex_constants {
|
||||
name: "view_proj"
|
||||
type: CONSTANT_TYPE_VIEWPROJ
|
||||
}
|
20
druid/materials/skew/gui_skew.vp
Normal file
20
druid/materials/skew/gui_skew.vp
Normal file
@@ -0,0 +1,20 @@
|
||||
#version 140
|
||||
|
||||
uniform vertex_inputs {
|
||||
highp mat4 view_proj;
|
||||
};
|
||||
|
||||
// positions are in world space
|
||||
in mediump vec3 position;
|
||||
in mediump vec2 texcoord0;
|
||||
in lowp vec4 color;
|
||||
|
||||
out mediump vec2 var_texcoord0;
|
||||
out lowp vec4 var_color;
|
||||
|
||||
void main()
|
||||
{
|
||||
var_texcoord0 = texcoord0;
|
||||
var_color = vec4(color.rgb * color.a, color.a);
|
||||
gl_Position = view_proj * vec4(position.xyz, 1.0);
|
||||
}
|
Reference in New Issue
Block a user