Directional Light

Started by
35 comments, last by belfegor 10 years, 9 months ago

@Anddos: I tried that:


mesh->CloneMeshFVF(D3DXMESH_32BIT | D3DXMESH_MANAGED, staticMesh->GetFVF() | D3DFVF_NORMAL, m_d3dDevice, &mesh);

Still the same problem, I don't see the specular light.

Advertisement

Well, I still don't see the specular light, however when I move the mesh and rotate it I begin to see the specular light (but in weird shape and just a tiny spot in random position on the mesh):

When the I set the material power to a smaller number for example (1.0) I get larger specular!

[attachment=16937:spec.png]

What's that?

did you inverse the meshs worldspace to localspace?, you need to be working in localspace matrix in order to get specular lighting to show on the model...

:)

@Anddos: I'm doing the following:


// In Vertex Shader:
Out.worldPos = mul(float4(IN.Pos, 1.0f), World).xyz;

//In Pixel Shader:
float3 viewDir = normalize(cameraPos - IN.worldPos);

I have attached a sample of some source code that shows how do specular lighting,there is a prebuilt exe to so you can test it before you make you're own changes.

:)

@Anddos: I have been looking at the sample for a very long time, I still didn't get it to work as expected.

You might want to look at the shader code that I recently posted to make sure that there is no bugs.

When I change the line:


float3 viewDir =  cameraPos - worldPos;

To:


float3 viewDir =  worldPos - cameraPos;

I get better results, however, when I set a small number for the material power (shininess) I get very high specular light and when I set a large number for the material power (shininess) I get smaller specular light.

Daft question, but why are you multiplying the normal by the world matrix in your vertex shader?


Out.Normal = mul(IN.Normal, (float3x3)World);

Aimee

We are now on Tumblr, so please come and check out our site!

http://xpod-games.com

@AmzBee


Daft question, but why are you multiplying the normal by the world matrix in your vertex shader?

They are directional vectors and are dependent on object orientation.

@Medo


Well, I still don't see the specular light, however when I move the mesh and rotate it I begin to see the specular light (but in weird shape and just a tiny spot in random position on the mesh):

specular highlight wiki


Specular reflection is visible only where the surface normal is oriented precisely halfway between the direction of incoming light and the direction of the viewer; this is called the half-angle direction because it bisects (divides into halves) the angle between the incoming light and the viewer


I get better results, however, when I set a small number for the material power (shininess) I get very high specular light and when I set a large number for the material power (shininess) I get smaller specular light.

That is to be expected.

@belfegor:

That is to be expected.

How do I fix that? I'm expecting If:

Shininess = 0 then no specular light

Shininess = 5 then a little specular

Shininess = 80 then high specular

What I'm getting now? 1 = High specular light, 80 = Less specular light, 200 = Tiny specular light

This topic is closed to new replies.

Advertisement