Hello, folks.
Can you help me with the following?
I am trying to utilize the fragment shader which is available here:
http://glslsandbox.com/e#4988.0But I want to use it solely for a single SFML RectangleShape.
Say, I have a green non-textured rectangle with the following coordinates:
up-left corner: (10,10);
bottom-right corner: (200,20);
I know how to apply shader to rectangle shape, during rendering, the problem I have is that
it is unclear how to calculate 'vec2 position' in the shader itself,
because gl_FragCoord.xy gives us window-related coordinates.
Possibly I might pass out vertex positions from a vertex shader and use this data from within a fragment shader?
I attached an image with the result I am trying to achieve.
The shader:
#ifdef GL_ES
precision mediump float;
#endif
//tigrou.ind@gmail.com 2012.11.22 (for gamedevstackexchange)
uniform float time;
uniform vec2 mouse;
uniform vec2 resolution;
void main( void ) {
//how to calculate it for my rectangle?
vec2 position = ( gl_FragCoord.xy / resolution.xy ) - mouse;
float waves = sin(position.x*10.0)*0.01*sin(time*10.0) + sin(position.x*10.0+1.3)*0.01*sin(time*10.0+10.5);
float color = position.y < waves ?(waves-position.y)*20.0 : 0.0;
color = min(pow(color,0.5),1.0);
gl_FragColor = vec4( position.y < waves ? mix(vec3(0.59,0.63,0.86),vec3(0.19,0.24,0.51),color) : vec3(0,0,0), 1.0 );
}
Thank you for your time, be glad for any valuable advices.