Deferred Shading - strange results

Started by
0 comments, last by lauris71 11 years, 5 months ago
Hi!
Im trying to get a simple deferred shading working.
I have GBuffer with 3 textures ( image, position, normal ).
Image :
http://c.wrzuta.pl/w...shading_gbuffer
Normal :
http://c.wrzuta.pl/w...shading_gbuffer
Position:
http://c.wrzuta.pl/w...shading_gbuffer
I'm trying to compute point light ( when i was used directional light i almost work ) like that :

// 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);
}

i'm binding it on fullscreen quad.
Result :
http://c.wrzuta.pl/w...50a554e2/result
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.
Advertisement
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

vec4 outputcolor = 0.5 * (vec4(1.0, 1.0, 1.0, 1.0) + position);


Reading

vec4 position = 2.0 * (vec4(0.5, 0.5, 0.5, 0.5) + texture( gPositionSampler, In.TexCoord ));
Lauris Kaplinski

First technology demo of my game Shinya is out: http://lauris.kaplinski.com/shinya
Khayyam 3D - a freeware poser and scene builder application: http://khayyam.kaplinski.com/

This topic is closed to new replies.

Advertisement