Jump to content
  • Advertisement
Sign in to follow this  
ArgusMaker

Multi-Shading .. how to?

This topic is 2537 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

Hi there!
I come here doubtful..
I recently started off with HLSL shader programming and I made some per-pixel lighting effects with a tutorial (point-lighting and directional-lighting). Let PointLighting.fx be my hlsl shader file, I'm able to activate it and render something with one point-light source.
The point is, i'm actually trying to cast two lights on my object. My current code processes twice the same shader pass, properly changing its parameters to achieve the two different lights effects, but the second light is the only visible.
What may i do? Thanks in advance, and, once again, forgive my bad english...

Share this post


Link to post
Share on other sites
Advertisement
When rendering your second pass, disable depth writes, set the depth test to LESSEQUAL, and enable additive blending (SRCBLEND = D3DBLEND_ONE, DESTBLEND = D3DBLEND_ONE). This will cause the result of the second pass to be summed with the result of the first pass, and you'll get the contribution from both lights.

You can also author a shader (or usually a set of shaders), that can sum the contribution from multiple lights in one pass, but that is more advanced.

Share this post


Link to post
Share on other sites
ok i wrote this to prepare the device to draw in blending mode, it still only shows the second light. Maybe I forgot something?


pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE,FALSE);
pd3dDevice->SetRenderState(D3DRS_ZFUNC,D3DCMP_LESSEQUAL);
pd3dDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_ONE);
pd3dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_ONE);

Of course I restored the render states to the right values after rendering the second pass..

Share this post


Link to post
Share on other sites
Once you've rendered a mesh once with z writes enabled, the z-buffer is already filled with depth values at those pixels. There's no need to write them again, because you would just be writing the same exact depth values. The reason you switch the depth test is because using LESSTHAN will fail if you render something with the same exact depth as what's in the z buffer (which is what happens when you render the same mesh twice). So by using LESSEQUAL, the depth test will still pass.

Share this post


Link to post
Share on other sites
Ok thank you, i'm understanding a little bit more about directx every day with such little questions.
How useful is this forum!

Share this post


Link to post
Share on other sites

Hi there!
I come here doubtful..
I recently started off with HLSL shader programming and I made some per-pixel lighting effects with a tutorial (point-lighting and directional-lighting). Let PointLighting.fx be my hlsl shader file, I'm able to activate it and render something with one point-light source.
The point is, i'm actually trying to cast two lights on my object. My current code processes twice the same shader pass, properly changing its parameters to achieve the two different lights effects, but the second light is the only visible.
What may i do? Thanks in advance, and, once again, forgive my bad english...


You can do that without multiple passes. Instead you can use a loop in the pixel shader:

for(int i = 0; i < NUM_DIR_LIGHTS; i++)
{
//compute specular component
float s = max(0.0f, dot(normalW, DLights_dir));
pixColor += s*DLights_color;
}
pixColor += globalAmbient;

It's a very simple example, with directional ligth and only diffuse and ambiental component, but It's easy to extend for other stuff like specular component. As you can see you have an array for light direction, and another one for light color, and yo compute each light contribution in a loop.

Share this post


Link to post
Share on other sites
Yes, but i had to guarantee up to 30 lights, and each pixel shader has a limited number of mathematical functions available. Thank you anyway

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!