Sign in to follow this  
6itru

Deferred Shading - strange results

Recommended Posts

6itru    129
Hi!
Im trying to get a simple deferred shading working.
I have GBuffer with 3 textures ( image, position, normal ).
Image :
[url="http://c.wrzuta.pl/wi2284/579c4dcd00211bd050a55184/deferred_shading_gbuffer"]http://c.wrzuta.pl/w...shading_gbuffer[/url]
Normal :
[url="http://c.wrzuta.pl/wi993/7e2c7735001e815c50a55184/deferred_shading_gbuffer"]http://c.wrzuta.pl/w...shading_gbuffer[/url]
Position:
[url="http://c.wrzuta.pl/wi2456/6ed9d23d00267fbe50a55184/deferred_shading_gbuffer"]http://c.wrzuta.pl/w...shading_gbuffer[/url]
I'm trying to compute point light ( when i was used directional light i almost work ) like that :
[CODE]
// Fragment Shader //
#version 330 core
out vec4 outputColor;
in block
{
vec2 TexCoord;
vec3 Normal;
} In;
uniform sampler2D gDiffuseSampler;
uniform sampler2D gPositionSampler;
uniform sampler2D gNormalSampler;
uniform vec3 lightPosition;
uniform vec3 lightColor;
uniform float lightRadius;
void main()
{
vec4 image = texture( gDiffuseSampler, In.TexCoord );
vec4 position = texture( gPositionSampler, In.TexCoord );
vec4 normal = texture( gNormalSampler, In.TexCoord );

vec3 lightDir = lightPosition - position.xyz ;

normal = normalize(normal);
lightDir = normalize(lightDir);

float att = clamp(1.0f-length(lightDir)/lightRadius,0.0,1.0);
float diff = max(dot(normal,lightDir), 0);

outputColor = att * vec4(diff * lightColor,1.0);
}
[/CODE]
i'm binding it on fullscreen quad.
Result :
[url="http://c.wrzuta.pl/wi15434/32f6a44f001a11ff50a554e2/result"]http://c.wrzuta.pl/w...50a554e2/result[/url]
It is looking like "camera is center of point light ;| dafuq? i write about ten different shaders ;| on every the same - "camera is point light center", if you set camera closer to object, light get stronger ;o? i dont know, what im doing wrong. Sorry for my bad english.
I will by grateful for your help.

Share this post


Link to post
Share on other sites
lauris71    841
Are you using floating point or integer textures. Do not forget that the latter can only hold values in range 0.0...1.0
Thus if you are reading (and storing) your position (and normal) values from texture you have to transform these:

Storing
[code]
vec4 outputcolor = 0.5 * (vec4(1.0, 1.0, 1.0, 1.0) + position);
[/code]

Reading
[code]
vec4 position = 2.0 * (vec4(0.5, 0.5, 0.5, 0.5) + texture( gPositionSampler, In.TexCoord ));
[/code]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this