Jump to content

  • Log In with Google      Sign In   
  • Create Account

Per object lighting transformation error?


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
2 replies to this topic

#1 dxCUDA   Members   -  Reputation: 141

Like
0Likes
Like

Posted 01 June 2012 - 01:32 PM

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

Posted Image

Edited by dxCUDA, 01 June 2012 - 01:33 PM.


Sponsor:

#2 dxCUDA   Members   -  Reputation: 141

Like
0Likes
Like

Posted 01 June 2012 - 02:44 PM

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, 01 June 2012 - 02:50 PM.


#3 dxCUDA   Members   -  Reputation: 141

Like
0Likes
Like

Posted 02 June 2012 - 05:44 AM

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.

Posted Image


Thanks




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