Flicker in lighting

Flicker in lighting

Post by LiquidSk » Sun, 21 Apr 2002 17:18:22



When I transform my mesh by the world matrix lighting is fine, but when I
"move the camera around the mesh" by changing the view matrix lighting
begins to flicker. Anybody know what could cause this? The light is a
directional light and I'm using the following render states to control
lighting:

D3DRS_LIGHTING, TRUE
D3DRS_SPECULARENABLE, TRUE
D3DRS_SHADEMODE, D3DSHADE_FLAT
D3DRS_LOCALVIEWER, FALSE
D3DRS_NORMALIZENORMALS, TRUE
D3DRS_FOGENABLE, FALSE

 
 
 

Flicker in lighting

Post by JC » Sun, 21 Apr 2002 17:41:04


I get this effect if I add more lights than the device handles.


Quote:> When I transform my mesh by the world matrix lighting is fine, but when I
> "move the camera around the mesh" by changing the view matrix lighting
> begins to flicker. Anybody know what could cause this? The light is a
> directional light and I'm using the following render states to control
> lighting:

> D3DRS_LIGHTING, TRUE
> D3DRS_SPECULARENABLE, TRUE
> D3DRS_SHADEMODE, D3DSHADE_FLAT
> D3DRS_LOCALVIEWER, FALSE
> D3DRS_NORMALIZENORMALS, TRUE
> D3DRS_FOGENABLE, FALSE


 
 
 

Flicker in lighting

Post by LiquidSk » Sun, 21 Apr 2002 19:32:07


I'm only using 1 light, so that's not the problem.


> I get this effect if I add more lights than the device handles.



> > When I transform my mesh by the world matrix lighting is fine, but when
I
> > "move the camera around the mesh" by changing the view matrix lighting
> > begins to flicker. Anybody know what could cause this? The light is a
> > directional light and I'm using the following render states to control
> > lighting:

> > D3DRS_LIGHTING, TRUE
> > D3DRS_SPECULARENABLE, TRUE
> > D3DRS_SHADEMODE, D3DSHADE_FLAT
> > D3DRS_LOCALVIEWER, FALSE
> > D3DRS_NORMALIZENORMALS, TRUE
> > D3DRS_FOGENABLE, FALSE

 
 
 

Flicker in lighting

Post by Rich [Microsoft Direct3D MV » Mon, 22 Apr 2002 01:23:59


[Please do not mail me a copy of your followup]



Quote:>When I transform my mesh by the world matrix lighting is fine, but when I
>"move the camera around the mesh" by changing the view matrix lighting
>begins to flicker.

Can you be more specific by what you mean by "flicker"?

Can you reproduce it in any other samples?

My rt_Lighting sample should let you recreate exactly what you are
doing in your code.
--
Ask me about my upcoming book on Direct3D from Addison-Wesley!
  Direct3D Book http://www.xmission.com/~legalize/book/
    izfree: Open source tools for Windows Installer
            http://izfree.sourceforge.net

 
 
 

Flicker in lighting

Post by n! » Mon, 22 Apr 2002 03:52:15


Quote:> When I transform my mesh by the world matrix lighting is fine, but when I
> "move the camera around the mesh" by changing the view matrix lighting
> begins to flicker. Anybody know what could cause this? The light is a
> directional light and I'm using the following render states to control
> lighting:

>  D3DRS_SPECULARENABLE, TRUE
> D3DRS_SHADEMODE, D3DSHADE_FLAT

Try using D3DSHADE_GOURAUD (for the D3DRS_SHADEMODE render state). I'm
assuming that rather than meaning 'flicker' (which suggests the lighting
goes on/off or very dark/very light) you might mean that the lighting does
not adjust smoothly as the view pans.

Hmmm, thinking about it, this may be a combination of specular lighting and
flat shading. Specular lighting is calculated using the half-way vector
between the viewer and the surface normal, so if the viewer is moving and
both the object and light are stationary the specular result will change.
Flat shading computes the result only for the entire face rather than for
each vertex which means the face may suddenly 'get brighter' or 'get
darker'. The intensity of this effect may change with different
specular-power values for the surface material. Try disabling specular
lighting and see if the result is less pronounced.

n!

 
 
 

Flicker in lighting

Post by LiquidSk » Mon, 22 Apr 2002 04:53:27




Quote:> Can you be more specific by what you mean by "flicker"?

At certain angles the light intensity seems to be random each frame.

Quote:> Can you reproduce it in any other samples?

In the SDK samples?

Quote:> My rt_Lighting sample should let you recreate exactly what you are
> doing in your code.

It does not compile:

app.cpp(283) : error C2039: 'D3DXTessellateNPatches' : is not a member of
'`global namespace''
app.cpp(283) : error C2065: 'D3DXTessellateNPatches' : undeclared identifier
d3dapp.cpp(848) : error C2065: 'D3DPMISCCAPS_NULLREFERENCE' : undeclared
identifier

Is it for 8.1?

 
 
 

Flicker in lighting

Post by Rich [Microsoft Direct3D MV » Mon, 22 Apr 2002 05:02:48


[Please do not mail me a copy of your followup]





>> Can you be more specific by what you mean by "flicker"?

>At certain angles the light intensity seems to be random each frame.

So you're saying if the viewing angle isn't changing, you're just
redrawing the same scene over and over with no changes, then the
lighting intensity varies?  This sounds like a bug in your code
somewhere.

Quote:>> Can you reproduce it in any other samples?

>In the SDK samples?

Yes; the SDK samples do lighting all over the place.  If they don't
exhibit the problem, that points the finger back at your code having a
bug.  If they also exhibit the problem, that points the finger at
something besides your code -- perhaps your driver.

Quote:>> My rt_Lighting sample should let you recreate exactly what you are
>> doing in your code.

>It does not compile:

>app.cpp(283) : error C2039: 'D3DXTessellateNPatches' : is not a member of
>'`global namespace''
>app.cpp(283) : error C2065: 'D3DXTessellateNPatches' : undeclared identifier
>d3dapp.cpp(848) : error C2065: 'D3DPMISCCAPS_NULLREFERENCE' : undeclared
>identifier

>Is it for 8.1?

On the download web page it says:

    "Note: This sample was created with the DX8.1 SDK AppWizard."

To make it work with 8.0 should only take a few modifications, but I
haven't tried it myself as I have 8.1.  You can take out the N-patch
tesselation, that's just to get the vertex density of the teapot a
little higher than the stock result of D3DXCreateTeapot.  You might
have to tweak any calls to optimizing the mesh as well; 8.1 added an
additional argument, I think.
--
Ask me about my upcoming book on Direct3D from Addison-Wesley!
  Direct3D Book http://www.xmission.com/~legalize/book/
    izfree: Open source tools for Windows Installer
            http://izfree.sourceforge.net

 
 
 

Flicker in lighting

Post by LiquidSk » Mon, 22 Apr 2002 05:22:29



Quote:> Try using D3DSHADE_GOURAUD (for the D3DRS_SHADEMODE render state). I'm
> assuming that rather than meaning 'flicker' (which suggests the lighting
> goes on/off or very dark/very light) you might mean that the lighting does
> not adjust smoothly as the view pans.

Yep, thats the flickering I'm seeing. I have tried D3DSHADE_GOURAUD but it
look exactly the same since my object is a cube (where each vertex normal is
the same as the normal of the face it belongs to).

Quote:> Hmmm, thinking about it, this may be a combination of specular lighting
and
> flat shading. Specular lighting is calculated using the half-way vector
> between the viewer and the surface normal, so if the viewer is moving and
> both the object and light are stationary the specular result will change.
> Flat shading computes the result only for the entire face rather than for
> each vertex which means the face may suddenly 'get brighter' or 'get
> darker'. The intensity of this effect may change with different
> specular-power values for the surface material. Try disabling specular
> lighting and see if the result is less pronounced.

I can't follow you here. Why would the intensity suddenly get britghter when
specular is used with flat shading? Also I'm not really interested in
disabling specular, since that would not allow me to do the lighting I want.
 
 
 

Flicker in lighting

Post by LiquidSk » Mon, 22 Apr 2002 05:37:43




> [Please do not mail me a copy of your followup]




in

> >> Can you be more specific by what you mean by "flicker"?

> >At certain angles the light intensity seems to be random each frame.

> So you're saying if the viewing angle isn't changing, you're just
> redrawing the same scene over and over with no changes, then the
> lighting intensity varies?  This sounds like a bug in your code
> somewhere.

No sorry, the 'flickering' only appears when the viewing angle is changing.

Quote:> >> Can you reproduce it in any other samples?

> >In the SDK samples?

> Yes; the SDK samples do lighting all over the place.  If they don't
> exhibit the problem, that points the finger back at your code having a
> bug.  If they also exhibit the problem, that points the finger at
> something besides your code -- perhaps your driver.

I could do that, but since my example is very simple (just changing the view
matrix and rendering a cube) it seems a bit overkill to start modifying one
of the samples. Or maybe there is a sample in 8.0 sdk which uses lighting
and 'moves the camera around' ?
 
 
 

Flicker in lighting

Post by n! » Mon, 22 Apr 2002 05:59:41


Quote:> Yep, thats the flickering I'm seeing. I have tried D3DSHADE_GOURAUD but it
> look exactly the same since my object is a cube (where each vertex normal
is
> the same as the normal of the face it belongs to).

Ahh, ok I didn't know it was just a cube.

Quote:> Flat shading computes the result only for the entire face rather than for
> > each vertex which means the face may suddenly 'get brighter' or 'get
> > darker'. The intensity of this effect may change with different
> > specular-power values for the surface material. Try disabling specular
> > lighting and see if the result is less pronounced.

> I can't follow you here. Why would the intensity suddenly get britghter
when
> specular is used with flat shading? Also I'm not really interested in
> disabling specular, since that would not allow me to do the lighting I

want.

I meant with respect to the neighbouring polygons, the surface normal for
one polygon may be much nearer the reflection than the next one. Hence a
large difference in intensities (the gouraud shading would interpolate
across the polygon giving a smoother transition). However this is a cube so
it certainly can't be this (now I see why you have the shading equation set
to flat, sorry). I've certainly had a cube with specular lighting looking
ok.
I didn't mean to disable specular permanently just to see if it behaved
better without it (it may narrow it down to the specular settings alone or
at least rule them out).

n!

 
 
 

1. Flickering Candle light

Anybody have any suggestions for creating a 'flickering' candle or
torchlight?  Something in the order of a flickering spotlight that
radiates in all directions....I need to cast shadows too.  I tried
Overshooting a spotlight, but didn't like the effects....

Thanx

2. Which Sprite BitBlit is faster?

3. Flickering flame light

4. Tube Librarian V1.1B

5. Flicker Flicker Flicker and big Bitmaps

6. blend a finger into the hand as one object?

7. Flicker Flicker Always a Flicker

8. parts maker for 3d studio and more

9. Flicker Light Studio presents Tom Repasky

10. BMRT&flickering lights

11. flickering lights

12. Random Flickering Light

13. Flickering Lights