Light Shader

Started by
39 comments, last by belfegor 10 years, 10 months ago

Does that mean that I have to create light shader in every shader file to make the mesh get light effect? I'm confused.

Advertisement

For each single object:

  • Render Diffuse with texture (special shader of the mesh)
  • Render lighting (could be the same shader all over)
  • Blend the results together

So basically you would have two shaders for one mesh, but one of these shaders would be the same all over. I guess.

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

device->SetPixelShader() only accept one shader file, how do I set 2 shaders?

First you draw your objects once with one shader:


// activates shader 1
device->SetPixelShader(PixelShader1); // one that apply diffuse texture
Object.Draw();

Then you draw it again with other pixel shadr but enable alpha blending, for example it could be ADD mode:


// activates shader 2 ( 1 one is now "disabled")
device->SetPixelShader(PixelShader2); // one that does lightning
device->SetRenderState( d3drs_alphablendenable, true)
device->SetRenderState( d3drs_srcblend, one)
device->SetRenderState( d3drs_destblend, one)
Object.Draw();

So it blends over what is rendered before it. Get it?

Or you could do all in one shader (diffuse + lighning), but that is your choice.

Have you ever worked in Photoshop with different layers and blend them?

If so, it is the similar thing.

@belfegor: That means I will have to draw most meshes twice? That will not be a good idea for performance, drawing everything twice?

Yes you have to draw twice and maybe even more for other effects. Note that this isn't necessary the bad thing at all, most games do it this way.

There is also some other techniques used to minimize draw call count but have other disadvantages. Search forum for "Light pre-pass" and "Deferred rendering".

You have to choose what best suit your game/scene.

I actually pointed out:

"You can mix FVF for vertex structure in D3D9 C++ and also use an effect file that provides a vertex shader."

Once you select a vertex shader/pixel shader, you have fewer options for setting device states than if you remained strictly with the FFP.

Please read here for more info:

http://msdn.microsoft.com/en-us/library/windows/desktop/jj658611(v=vs.85).aspx

Declaring your vertex structures using FVF does not imply that you are strictly FFP. You can still set a vertex shader/pixel shader (either directly or through effect file usage). Once you've set a vertex shader/pixel shader, you've opted out of FFP for that part of the pipeline.

Any examples for point and spot lights using shader?

I want to be able to set the light by giving its position and color to the Shader, I mean (example):


effect->SetPosition(...); // Light position
effect->SetColor(...);   // Light color
// etc...

Look here for DX9 demos

This one has all 3 light types.

I notice when I do that:


// activates shader 2 ( 1 one is now "disabled")
device->SetPixelShader(PixelShader2); // one that does lightning
device->SetRenderState( d3drs_alphablendenable, true)
device->SetRenderState( d3drs_srcblend, one)
device->SetRenderState( d3drs_destblend, one)
Object.Draw();

I get ZFighting.

This topic is closed to new replies.

Advertisement