Original Post
🔒 Locked
Specular lighting
Advertisement
Specular lighting is part of the fixed-function T&L pipeline - you need to configure the lights, a material, and then turn it on using the render state you mention.
However, are you saying that D3DRS_SPECULARENABLE == TRUE changes the way your vertex shaders work? As far as I'm aware they should be mutually exclusive and setting the lighting render states when using vertex shaders shouldn't have any effect [oh]
hth
Jack
However, are you saying that D3DRS_SPECULARENABLE == TRUE changes the way your vertex shaders work? As far as I'm aware they should be mutually exclusive and setting the lighting render states when using vertex shaders shouldn't have any effect [oh]
hth
Jack
D3DRS_SPECULARENABLE=TRUE actually serves two purposes:
* when the fixed function lighting pipeline is enabled (D3DRS_LIGHTING=TRUE), D3DRS_SPECULARENABLE=TRUE enables per-vertex computation of specular illumination (Blinn-Phong N.H style). The specular parts of the D3D material and light are only used when it's set to TRUE.
AND
* enables the per-pixel "specular add" stage. This occurs after pixel processing (the fixed function texture blending cascade OR a pixel shader) but before frame buffer blending (alpha blend etc).
Most hardware has an additional, less programmable stage after the traditional texture blending cascade which is specialised for adding the specular colour to the pixel and fog blending. On the PC (Xbox offers more flexibile access), the D3DRS_SPECULARENABLE and D3DRS_FOG* states are how you control what this stage does.
The reason specular is added on this way goes back to single texture hardware - if you only have one texture, then in most cases, that texture is going to represent the diffuse colouring of what it's applied to.
For lighting, the sensible thing to do is modulate the diffuse illumination with the diffuse texture (Texture*DiffuseLight); but light is additive, so specular highlights need to be added after the whole diffuse contribution has been dealt with, doing Texture*(DiffuseLight+SpecularLight) would be wrong since the diffuse texture would be blended with a value that also included specular. What's needed is (Texture*DiffuseLight)+SpecularLight and all modern hardware supports 2 (or more) per pixel colour iterators - which is why specular addition is done as an extra hidden stage after the usual texture blending cascade.
Long and short of it for the moment (I'd expect this to change in a future version of D3D):
What you output in oD1/v1 will be added on after your shader/FFP texture blending if D3DRS_SPECULARENABLE=TRUE. Of course in these days of complex pixel shaders, you're free to set D3DRS_SPECULARENABLE to FALSE and perform the specular addition yourself in the pixel shader.
* when the fixed function lighting pipeline is enabled (D3DRS_LIGHTING=TRUE), D3DRS_SPECULARENABLE=TRUE enables per-vertex computation of specular illumination (Blinn-Phong N.H style). The specular parts of the D3D material and light are only used when it's set to TRUE.
AND
* enables the per-pixel "specular add" stage. This occurs after pixel processing (the fixed function texture blending cascade OR a pixel shader) but before frame buffer blending (alpha blend etc).
Most hardware has an additional, less programmable stage after the traditional texture blending cascade which is specialised for adding the specular colour to the pixel and fog blending. On the PC (Xbox offers more flexibile access), the D3DRS_SPECULARENABLE and D3DRS_FOG* states are how you control what this stage does.
The reason specular is added on this way goes back to single texture hardware - if you only have one texture, then in most cases, that texture is going to represent the diffuse colouring of what it's applied to.
For lighting, the sensible thing to do is modulate the diffuse illumination with the diffuse texture (Texture*DiffuseLight); but light is additive, so specular highlights need to be added after the whole diffuse contribution has been dealt with, doing Texture*(DiffuseLight+SpecularLight) would be wrong since the diffuse texture would be blended with a value that also included specular. What's needed is (Texture*DiffuseLight)+SpecularLight and all modern hardware supports 2 (or more) per pixel colour iterators - which is why specular addition is done as an extra hidden stage after the usual texture blending cascade.
Long and short of it for the moment (I'd expect this to change in a future version of D3D):
What you output in oD1/v1 will be added on after your shader/FFP texture blending if D3DRS_SPECULARENABLE=TRUE. Of course in these days of complex pixel shaders, you're free to set D3DRS_SPECULARENABLE to FALSE and perform the specular addition yourself in the pixel shader.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement