Restructured shaderlib by moving functions and renaming files
This commit is contained in:
parent
c70eaed0c4
commit
40374bd849
10 changed files with 53 additions and 49 deletions
21
shaderlib/place_texture.gdshaderinc
Normal file
21
shaderlib/place_texture.gdshaderinc
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
|
||||
/*
|
||||
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
|
||||
}
|
||||
Reference in a new issue