Erayd
Member
I cannot seem to find a solution to my problem no matter how much time and research I put in to this topic. By all sources, my code is correct and I should have no problem, yet I do and now I need some expertise. My goal is to edit a sprite in a shader based on it's current pixel. I can't seem to get the x and y coordinate of the pixel being shaded no matter what I do. Currently I can only raise and rgb value of the entire sprite being shaded.
Vertex Shader:
I figured this code snippet would give more red to the top right corner of my sprite, instead, the whole sprite is now simply more red instead of just a few pixels.
Fragment Shader:
Draw Object Code:
The debug message above outputs:
Edit: Updated with cleaner code
Vertex Shader:
Code:
attribute vec3 in_Position; // (x,y,z)
attribute vec4 in_Colour; // (r,g,b,a)
attribute vec2 in_TextureCoord; // (u,v)
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
varying vec2 position;
void main()
{
vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);
gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
v_vColour = in_Colour;
v_vTexcoord = in_TextureCoord;
position = in_Position.xy;
}
Fragment Shader:
Code:
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
varying vec2 position;
uniform vec2 resolution;
uniform vec4 UV;
void main() {
vec4 color = texture2D(gm_BaseTexture, v_vTexcoord);
vec2 currPoint = vec2(v_vTexcoord.x + position.x, v_vTexcoord.y + position.y);
vec2 checkPoint = vec2(v_vTexcoord.x + 1.0/(resolution.x/2.0), 0.0);
if(distance(currPoint, checkPoint) > 0.25){
color.r = 1.0;
}
gl_FragColor = v_vColour * color;
}
Code:
/// @description Shading
shader_set(testShade);
UV = sprite_get_uvs(sprite_index, 0);
shader_set_uniform_f(shader_get_uniform(testShade, "UV"), UV[0], UV[1], UV[2], UV[3]);
shader_set_uniform_f(shader_get_uniform(testShade, "resolution"), sprite_width, sprite_height);
draw_self();
shader_reset();
show_debug_message("1: " + string(UV[0]) + " 2: " + string(UV[1]) + " 3: " + string(UV[2]) + " 4: " + string(UV[3]));
Code:
1: 0.73 2: 0.44 3: 0.74 4: 0.44
Last edited: