Jump to content

View more

Image of the Day

雑魚は多めにして、爽快感重視にしつつ・・・(´・ω・`)
早いとこ、ベースを作って、完成にもっていかないとね。
タイトルもまだ迷ってるだよなぁ。 
#indiedev  #indiegame #screenshotsaturday https://t.co/IwVbswGrhe
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Diffuse Lighting, GLSL.

4: Adsense

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 Slushy   Members   

168
Like
0Likes
Like

Posted 26 October 2013 - 07:33 AM

Hello, im back again with another question. So I've been working on diffuse lighting for a couple of days now and I can't seem to get it working properly. I get the feeling that there is something messed up with my direction/position Vector of the light. But I can't seem to figure out what. Either way, here are my shaders:

VertexShader.glsl

#version 330

uniform mat4 perspectiveMatrix;
uniform mat4 viewMatrix;
uniform mat4 modelMatrix;

layout(location = 0) in vec3 in_Position;
layout(location = 1) in vec2 in_TextureCoord;
layout(location = 2) in vec3 in_Normal;

out vec2 frag_TextureCoord;
out vec3 normal;

void main(void){
	gl_Position = perspectiveMatrix * viewMatrix * modelMatrix * vec4(in_Position, 1.0);
	
	normal = mat3(modelMatrix) * in_Normal;
	normal = normalize(normal);
    
	frag_TextureCoord = in_TextureCoord;
}

FragmentShader.glsl

#version 330

uniform sampler2D texture_diffuse;

uniform vec3 lightPosition;
uniform vec3 lightColor;
uniform float lightPower;

in vec2 frag_TextureCoord;
in vec3 normal;

out vec3 out_Color;

void main(void){
	float lightIntensity;
	vec3 lightDir;
	
	lightDir = -lightPosition;
	lightIntensity = clamp(dot(normal, lightDir), 0.0f, 1.0f);
	
	out_Color = clamp((lightColor * lightIntensity), 0.0f, 1.0f);
	out_Color = out_Color * texture(texture_diffuse, frag_TextureCoord).rgb;
}

My position/direction vector that I send to my fragment shader in the uniform is: 0, -1, 0

and what I get is this:

GcNZPLM.png



#2 Slushy   Members   

168
Like
1Likes
Like

Posted 29 October 2013 - 10:20 AM

I solved it, it's kinda embarassing. I had the offset wrong in my interleaved vbo. It gathered the wrong normals and that messed it up.






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.