shaderlib: Implement place_texture() and provide an example, replace mix.gdshader example; implements #17
This commit is contained in:
parent
8b5a1cc37d
commit
1aa217776c
8 changed files with 48 additions and 21 deletions
19
shaderlib/transform.gdshaderinc
Normal file
19
shaderlib/transform.gdshaderinc
Normal file
|
@ -0,0 +1,19 @@
|
|||
|
||||
// Load in a texture from a sampler2D with an offset and scale
|
||||
// See examples/place_texture.gdshader
|
||||
vec4 place_texture(sampler2D sampler, vec2 uv, vec2 texture_pixel_size, vec2 offset, vec2 scale) {
|
||||
vec2 texture_size = vec2(textureSize(sampler, 0));
|
||||
// position of current pixel; sample color c
|
||||
vec2 pos = (uv - offset) / (texture_size*texture_pixel_size) / scale;
|
||||
vec4 c = texture(sampler, pos);
|
||||
// top-left bounds
|
||||
vec2 a = offset;
|
||||
// bottom-right bounds
|
||||
vec2 b = offset + (texture_size*texture_pixel_size) * scale;
|
||||
// check bounds
|
||||
if (
|
||||
a.x < uv.x && a.y < uv.y
|
||||
&& b.x > uv.x && b.y > uv.y
|
||||
) { return c; } // within bounds -> return color
|
||||
return vec4(0); // not within bounds -> return transparency
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue