Jump to content
  • Advertisement
Sign in to follow this  
dxCUDA

Per object lighting transformation error?

This topic is 2270 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Another day, another issue.

Currently I am rendering a red point light in the world, but seemingly one point light is being applied independently for each object. Obviously I want one point light in the world to effect all objects (objects to share the same lighting). This issue was also apparent with my directional light.

I think it might be an issue either in my shader transforming into clip space and maybe then I need to do a new transformation


input.p = mul( input.p, World );
output.p = mul( input.p, View );
output.p = mul( output.p, Projection );


Or the issue is in my baseObject render method, whereby I am rendering something per-object as opposed to globally, or there is a transformation I am missing to incorporate at this level


void dxBaseModel::render()
{
D3DXMatrixIdentity(&posMatrix);
D3DXMatrixIdentity(&rotMatrix);
D3DXMatrixIdentity(&meshWorld);


D3DXMatrixRotationYawPitchRoll(&rotMatrix, rotation.y, rotation.x, rotation.z);
D3DXMatrixTranslation(&posMatrix, position.x, position.y, position.z);
D3DXMatrixMultiply(&meshWorld, &rotMatrix, &posMatrix);

pViewMatrixEffectVariable->SetMatrix(viewMatrix);
pProjectionMatrixEffectVariable->SetMatrix(projectionMatrix);

myTexture.pTextureSR->SetResource( myTexture.textureSRV[0] );
myTexture.pBumSR->SetResource(myTexture.textureSRV[1]);
myTexture.pSpecSR->SetResource(myTexture.textureSRV[2]);


D3D10_TECHNIQUE_DESC TechDesc;

pBasicTechnique->GetDesc(&TechDesc);


for( UINT p = 0; p < TechDesc.Passes; p++ )
{
WVP = meshWorld*viewMatrix*projectionMatrix;
pWVPMatrixEffectVariable->SetMatrix((float*)&WVP);
pWorldMatrixEffectVariable->SetMatrix((float*)&meshWorld);


pBasicTechnique->GetPassByIndex( p )->Apply( 0 );

pMesh->DrawSubset(0);
}
}


Here's an image of the scene to illustrate the issue at hand.

Thanks

izlu2q.png Edited by dxCUDA

Share this post


Link to post
Share on other sites
Advertisement
Progress, but now the world is black,

I was setting


m_LightVec[lightNum]->pLightVar = pBasicEffect->GetVariableByName( "pLight" );
m_LightVec[lightNum]->pLightVar->SetRawValue(&m_LightVec[lightNum]->pointLight, 0, sizeof(pointLight));


to:


m_LightVec[lightNum]->pLightVar = pBasicEffect->GetVariableByName( "pLight" );
m_LightVec[lightNum]->pLightVar->SetRawValue(&m_LightVec[lightNum]->directionalLight, 0, sizeof(DirectionalLight));


Now I am sure the issue is in my shader to do with the position of the light. I was generating the image above when I by accident, used the directional light pos(dir).


else if (pLightType == 1)
{
lightIntensity = saturate(dot(bumpNormal, +pLight.pos));

// Determine the final diffuse color based on the diffuse color and the amount of light intensity.
color = saturate(material.Kd * lightIntensity);

// The vector from the surface to the light.
float3 lightVec = pLight.pos - input.p;

// The distance from surface to light.
float d = length(lightVec);

//if( d > pLight.range )
//return float4(0.0f, 0.0f, 0.0f, 0.0f);

// Normalize the light vector.
lightVec /= d;

//color = color / dot(pLight.att, float3(1.0f, d, d*d)) * textureColor;
color = color * textureColor;

specularPower1 = 5.0f;//Need to make this modifiable outside of the shader
if(lightIntensity > 0.0f)
{
//Calculate the reflection vector based on the light intensity, normal vector and light direction
reflection = normalize(2 * lightIntensity * bumpNormal +pLight.pos);

// Determine the amount of specular light based on the reflection vector, viewing direction, and specular power.
specular = pow(saturate(dot(reflection, lightVec)), specularPower1);

// Use the specular map to determine the intensity of specular light at this pixel.
specular = specular * specularIntensity;

// Add the specular component last to the output color.
color = saturate(color + specular);
}
//calculate lighting
I = calcBlinnPhongLighting( material, pLight.color, input.n, -pLight.pos, input.h );


I am still receiving the per-object light error as before still however! Edited by dxCUDA

Share this post


Link to post
Share on other sites
Ok, So I think I have fixed every issue under the sun relating to all my previous issues. One issue remains however, there is a very stark contrast between a lit area and the falloff with the lighting.

I've been heavily experimenting and nothing I do seems to have an impact. As I move in the scene the dark area moves towards me and I cannot illuminate this area with the spotlight.

34gt6yr.png


Thanks

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!