Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Deferred Shading - strange results


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 6itru   Members   -  Reputation: 129

Like
0Likes
Like

Posted 15 November 2012 - 03:01 PM

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.

Sponsor:

#2 Lauris Kaplinski   Members   -  Reputation: 841

Like
2Likes
Like

Posted 16 November 2012 - 03:50 PM

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/




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS