Lighting + Shaders

Started by
8 comments, last by neneboricua19 18 years, 6 months ago
In an engine that is based solely on shaders, does the IDirect3DDevice9::SetLight method serve any function, or do you have to implement lighting in your shaders and put light parameters in shader variables?
Advertisement
You'll have to implement your own lighting in shaders. The SetLight function is only for the fixed function pipeline. If you're using shaders, you need to implement lighting inside the shaders.

neneboricua
You actually answered your own questions. [grin]
SetLight() is a fixed function method, so it does not have any effect when using shaders, like you assumed. And yes, you have to implement your own lighting (either per-vertex or per-pixel).

EDIT: Beaten.
Then what about the matricies? They still are used, right?
you mean world,view and projection matricies? They also need to be passed to the shader..

regards,
m4gnus
"There are 10 types of people in the world... those who understand binary and those who don't."
Yes, matrices are still used, but you have to calculate transformations manually in vertex shaders. So you can't use IDirect3DDevice9::SetTransform() to do transformations.

EDIT: Beaten. Again.
What do you mean calculate? Do you mean move from model space to view space? And do i have to use the setshaderconsts to pass matricies or can the shader retrieve matricies that i pass through settransform?
If you use a purely shader driven system you will be using NOTHING in the fixed function pipeline. So no, shaders can not retrieve matricies from SetTransform. You have to use SetShaderConstants (for assembly shaders... I'd say use HLSL) or set an effect parameter on an HLSL shader using the D3DX framework.
So, in effect, you can use less matricies then before (256 world matricies in fixed), only 256 floats in vertex shader... = 16 matricies..., and that is without any lights or anything!?
Quote:Original post by Axiverse
So, in effect, you can use less matricies then before (256 world matricies in fixed), only 256 floats in vertex shader... = 16 matricies..., and that is without any lights or anything!?

Not quite. This depends on the capabilites of the particular graphics card. If you're refering to vertex blending (i.e. skinning), the maximum number of matrices that can be handled by the fixed function pipeline is specified by the "MaxVertexBlendMatrixIndex" member of the D3DCAPS9 structure. The value is 256 when software vertex processing is used. Otherwise, you have to check this value. For example, the value of this cap on the Radeon 9800XT that I have at home is only 37.

Now compare that to a graphics card which supports the vertex shader 2.0 spec (like the previously mentioned Radeon 9800XT). A card with that supports this shader spec can handle at least 256 floating-point constant registers. Each register contains 4 floating point variables. If you were to store 4x4 matrices, you could store 64 matrices in the shader constants.

neneboricua

This topic is closed to new replies.

Advertisement