Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - orestarh

Pages: [1]
1
Graphics / Re: fragment shader question
« on: December 24, 2015, 07:32:06 pm »
Hapax, you were right:) it works like a charm, simple and elegant.

2
Graphics / Re: fragment shader question
« on: December 23, 2015, 06:21:43 pm »
I solved it using the following:
_shader.setParameter("width", wh.x); //rectangle's width
_shader.setParameter("height", wh.y); //rectangle's height

_rectShape.setTextureRect(sf::IntRect(sf::Vector2i(0, 0), sf::Vector2i(wh.x, wh.y)));
 
and then in shader  I have:
uniform float width;
uniform float height;

void main(void) {
    vec2 position = gl_TexCoord[0].xy / vec2(width, height);
    //...
}
 

Now back to the 1st option, I am still having troubles with it.
I.e now I pass window coordinates to shader:
Code: [Select]
    auto foo = target.mapCoordsToPixel(_pos);
    _shader.setParameter("posx", foo.x);
    _shader.setParameter("posy", foo.y);
and in shader I use:
Code: [Select]
uniform float width;
uniform float height;
uniform float posx;
uniform float posy;

void main(void) {
    vec2 position = vec2(posx, posy) / vec2(width, height);
    //...
and have unpleasant results.

3
Graphics / Re: fragment shader question
« on: December 23, 2015, 06:33:10 am »
I solved it, using your 2nd option, finally. It works no matter whether the texture is set or not.

Out of curiosity, as for your 1st option:
Quote
gl_FragCoord is an input variable that contains the window relative coordinate (x, y, z, 1/w) values for the fragment.
, therefore I guess it won't work in my scenario, because the rectangle's position uses  absolute world coordinates. These are the two different things. Please correct me if I am wrong.

Anyway, thank you for helping me out!

4
Graphics / Re: fragment shader question
« on: December 22, 2015, 05:29:48 pm »
thank you, Hapax.

Tried to implement your approach, but all I have is a rectangle filled with one color. Maybe setting texture rect without texture is wrong? I mean, it is still just a simple rectangle without any texture.

5
Graphics / fragment shader question
« on: December 21, 2015, 01:27:59 pm »
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.0
But 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.

Pages: [1]
anything