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 - Blasphemer

Pages: [1]
1
SFML projects / Re: TGUI: GUI library for SFML
« on: September 12, 2015, 07:20:11 pm »
I am using it in my project, its simple to integrate, easy to use and it works very well. Keep up the great work.  :)

2
are you talking 2d or 3d?

I implemented a 2d lighting shader with normal maps and I sent the light position to the shader already converted to screen coords. I even asked this somewhat similar question:
http://en.sfml-dev.org/forums/index.php?topic=17352.0

so if you are talking 2d I can give you more info.

Yes I am talking about 2D. I have already implemented the shader with the approach outlined in the OP. The code is here:

uniform sampler2D texture;

uniform vec2 light_position;
uniform vec4 light_color;
uniform float light_intensity;

uniform vec2 topleft;
uniform vec2 topright;
uniform vec2 bottomright;
uniform vec2 bottomleft;

vec2 resize_vect(vec2 vect, float lenght)
{
        float vect_lenght = sqrt(vect.x * vect.x + vect.y * vect.y); //get vector's lenght

        vect.x = vect.x / vect_lenght; //normalize vector
        vect.y = vect.y / vect_lenght;

        vect.x = vect.x * lenght; //multiply it by lenght
        vect.y = vect.y * lenght;

        return vect;
}

void main()
{
       
       
        vec2 fragment_position_x = topleft + resize_vect(topright - topleft, gl_TexCoord[0].x*3 * distance(topleft, topright));
        vec2 fragment_position_y = topleft + resize_vect(bottomleft - topleft, gl_TexCoord[0].y * distance(topleft, bottomleft));
        vec2 fragment_position = fragment_position_x + (fragment_position_y - topleft);
       
        vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);
       
        float intensity = (light_intensity/5) / clamp(distance(fragment_position, light_position), 0.001, 4000000.0);
       
        vec4 light = vec4(pixel.r*light_color.r*intensity, pixel.g*light_color.g*intensity, pixel.b*light_color.b*intensity, pixel.a);

        gl_FragColor = light;

(I have to multiply gl_TexCoord[0].x by 3 because I am also storing glow map and environment map in the same texture so the end of the first texture is at x = 1/3)

3
Graphics / Determining world position of the current fragment in a shader
« on: January 22, 2015, 12:59:12 pm »
I am trying to make a lighting fragment shader. For that, I need to know the world position of the fragment in order to determine its distance to the light source (in world units). Should I do it by setting up a varying world coordinates variable in a vertex shader? If so, can SFML provide the model matrix needed to compute the vertex world position like this?:

vec2 world_coords = gl_Vertex * gl_ModelMatrix

Or should I compute the vertex world positions in SFML - getting the entity transform, applying it to local vertex coords then passing the results to the vertex shader?

Is this even the correct way to make a per-pixel lighting shader with SFML that would not change output with view/screen transformations?

Pages: [1]