Momfus
Member
Hi, I'm new in the use of shaders and i tried to make a shader on a sprite that make all the area inside a circle (center in the middle of the sprite) with a gray color and nothing outside of that circle.
I have a object ob_planet with a 300x300 sprite (is just a circle with different colors) and in the creat event i have this:
In the draw event this:
Now, in the fragment of the shader
I read the xorTutorials.com and thebookofshaders.com but i can't make a circle with a "r" radio that make the sprite gray inside the circle. Some help please?
I have a object ob_planet with a 300x300 sprite (is just a circle with different colors) and in the creat event i have this:
Code:
my_shader = shader_circle_gray;
uv = sprite_get_uvs(sprite_index, 0);
middle = 0;
middle[0] = (uv[0] + uv[2])/2;
middle[1] = (uv[1] + uv[3])/2;
In the draw event this:
Code:
shader_set(my_shader);
var shader_params = shader_get_uniform(my_shader, "middle");
shader_set_uniform_f_array(shader_params, middle );
draw_self();
shader_reset();
Now, in the fragment of the shader
Code:
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform vec2 middle; //middle of the sprite using uv
void main(){
vec4 o_pixel = v_vColour * texture2D(gm_BaseTexture, v_vTexcoord);
float red = o_pixel.r;
float green = o_pixel.g;
float blue = o_pixel.b;
float alpha = o_pixel.a;
//circle radio
float radio = 0.1;
if( "know if the actual pixel is in the circle area center in the middle" ){
float gray= (red + green + blue ) / 3.0;
red = gray;
green = gray;
blue = gray;
}
o_pixel = vec4(red, green, blue, alpha);
gl_FragColor = o_pixel;
}
I read the xorTutorials.com and thebookofshaders.com but i can't make a circle with a "r" radio that make the sprite gray inside the circle. Some help please?