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.


rocklobster

Member Since 24 Jul 2011
Offline Last Active Apr 22 2014 04:29 AM

Posts I've Made

In Topic: RTT with working on ATI but not nVidia (OpenGL)

27 August 2013 - 03:39 AM

Bingo! Thanks mate.


In Topic: New version: Try out my engine demo?

21 August 2013 - 03:07 AM

Runs fine on my machine (60 always):

 

CPU: i5-2500k 3.3ghz

RAM: 12GB

OS: Windows 64-bit

GPU: Sapphire 6950


In Topic: Directional lighting problems with transforming

20 August 2013 - 04:29 AM

Awesome mate, seems to be working fine now! Cheers for the help.


In Topic: Directional lighting problems with transforming

19 August 2013 - 07:43 PM

Cheers I'll give it a shot when I get home from work.


In Topic: Directional lighting problems with transforming

19 August 2013 - 12:35 AM

Ok so this is what I've changed:

glm::mat4 modelMatrix = modelNode->GetTransform();
glm::mat4 modelView = viewMatrix * modelMatrix;
glm::mat4 mvp = m_renderSystem->GetCamera()->GetProjectionMatrix() * modelView;
glm::mat3 normalMat = glm::transpose(glm::inverse(glm::mat3(modelView)));

m_graphics->SetUniform(id, "u_NormalMatrix", 1, false, normalMat); 
m_graphics->SetUniform(id, "u_ModelMatrix", 1, false, modelMatrix);
m_graphics->SetUniform(id, "u_ModelViewMatrix", 1, false, modelView);
m_graphics->SetUniform(id, "u_MVP", 1, false, mvp); 

Vertex Shader:

 

Multiplying the in_Position by the u_ModelMatrix, getting the direction from the light position to the vertex in world space and then multiplying by normal matrix to get oriented in eye space.

void main()
{
	PositionEye = vec3(u_ModelViewMatrix * vec4(in_Position, 1.0));
	NormalEye =  u_NormalMatrix * in_Normal;
	TexCoord = in_TexCoord;
	
	vec3 PosWorld = vec3(u_ModelMatrix * vec4(in_Position, 1.0));
	vec3 lightDirWorld = normalize(GlobalLightPos - PosWorld);
	LightDirEye = u_NormalMatrix * lightDirWorld;	
	
	gl_Position = u_MVP * vec4(in_Position, 1.0);
}

Fragment Shader:

 

Basically the same, doing normalising here instead of vertex shader.

vec3 shadePixel(vec3 diff)
{
	vec3 s = normalize(LightDirEye);
	float sDotN = max(dot(s, normalize(NormalEye)), 0.0);
	vec3 diffuse = vec3(1.0, 1.0, 1.0) * diff * sDotN;

	return diffuse;
}

void main()
{
	vec3 diff = texture(Texture, TexCoord * TexRepeat);

	out_Position = PositionEye;
	out_Normal = normalize(NormalEye);
	out_Diffuse = shadePixel(texture(Texture, TexCoord * TexRepeat));
	out_Tangent = Tangent;
	out_Binormal = Binormal;
}

Now this seems to be creating a weird effect, half of my world is shaded which looks normal, the other half is just completely black!?!


PARTNERS