Forum
Contact





DirectX using C#
DirectX using C++
DirectX using Visual Basic



Latest Forum posts

 Suggestion to change a few lines
  Posted by: Insomnica
  When: 06/09/2010 at 14:37:05

 Collision with series 1
  Posted by: radulph
  When: 05/09/2010 at 13:33:14

 HLSL calculating normals
  Posted by: miroslavign
  When: 04/09/2010 at 17:26:26

 Collision with series 1
  Posted by: ToastbrotX
  When: 04/09/2010 at 16:52:02

 HLSL calculating normals
  Posted by: Rich_Zap
  When: 04/09/2010 at 15:00:20

 Collision with series 1
  Posted by: ToastbrotX
  When: 04/09/2010 at 12:28:41

 HLSL calculating normals
  Posted by: miroslavign
  When: 04/09/2010 at 08:46:31

 Walk along a wall
  Posted by: Anonymous
  When: 03/09/2010 at 10:28:02

 model problems
  Posted by: muffinman
  When: 03/09/2010 at 06:47:32

 Vertices problem
  Posted by: Anonymous
  When: 03/09/2010 at 05:48:35

 OcTree Question
  Posted by: Zorzomezz
  When: 03/09/2010 at 04:07:03

 error x3000:syntax error
  Posted by: Anonymous
  When: 02/09/2010 at 06:55:17

 Reflection problem in corners ...
  Posted by: Anonymous
  When: 31/08/2010 at 20:53:30

 OcTree Question
  Posted by: radulph
  When: 31/08/2010 at 18:00:04

 model problems
  Posted by: Archenon
  When: 30/08/2010 at 05:54:27

 Changing computer breaks my game
  Posted by: Archenon
  When: 30/08/2010 at 05:49:50

 model problems
  Posted by: muffinman
  When: 28/08/2010 at 16:58:10

 Vertices problem
  Posted by: Anonymous
  When: 27/08/2010 at 15:35:36

 Changing computer breaks my game
  Posted by: radulph
  When: 27/08/2010 at 07:12:24

 effects file and XNA 4.0 (Beta)
  Posted by: radulph
  When: 26/08/2010 at 06:33:33




Topic: Strange light's movements



  
Goto parent category
  
Create a new user account


   Strange light's movements
 Poster : Totem
 Posts: 11
 Country : Italy
 City: Pavia

  
Posted by Totem on 17/08/2008 at 12:09:23
I followed the series 1 tutorials and I created a terrain with lighting. But when I rotate the terrain, the light disappears after a 90 degress rotation. Moreover i've changed the light vector to (1,1,1), because the previous one (that showed in tutorial 13) makes all dark.
Indeed, it looks like the light moves together with all the environment, but pointing in the same direction. This is the code of Draw method:
Dim WorldMatrix As Matrix = _
            Matrix.CreateTranslation(-Me.TerrainWidth / 2, 0, Me.TerrainHeight / 2) * _
            Matrix.CreateRotationY(Angle)

        Effect.Parameters("xView").SetValue(ViewMatrix)
        Effect.Parameters("xProjection").SetValue(ProjectionMatrix)
        Effect.Parameters("xWorld").SetValue(WorldMatrix)

        'Imposta la direzione della luce
        Dim LightDirection As New Vector3(1, 1.0F, 1.0F)
        LightDirection.Normalize()

        'Abilita la luce
        Effect.Parameters("xEnableLighting").SetValue(True)
        'Imposta il vettore luce negli effetti
        Effect.Parameters("xLightDirection").SetValue(LightDirection)
        'Introduce un po' di luce d'ambiente. Questo evita che triangoli non
        'colpiti direttamente dalla luce sia invisibili
        Effect.Parameters("xAmbient").SetValue(0.1F)
 Poster : radulph
 Posts: 218
 Country : germany
 City: hamburg

  
Posted by radulph on 17/08/2008 at 14:13:21
First, make sure, that you don't apply the world matrix on your light dir (inside the shader), as it is already given in world coordinates.

I'm pretty sure, the error comes from rotating the Normals. Remember, they don't have a position, only a direction!

First solution: Interpret the normals, not as direction, but rather as points to which your normals point to from the vertices. transform both values, and then regain the normals by subtracting the position of their end by the vertex pos. (and normalize)

Second Solution: Use the transposed inverted world matrix to transform the normals. but im not sure if it works in any case. further inverting matrices is not trivial!

;)
 Poster : Totem
 Posts: 11
 Country : Italy
 City: Pavia

  
Posted by Totem on 18/08/2008 at 12:28:26
I tried the second solution first: canceling world transformations on all the normals, but it does not work.

I am still trying to understand the first solution XD
If, as you said, the normals are not positions, but only directions, how would I do to subtract the vertex's position by their ends? I am quite sure you have thought a kind of recalculating operation before drawing, but I can't figure how it exactly works.
 Poster : radulph
 Posts: 218
 Country : germany
 City: hamburg

  
Posted by radulph on 18/08/2008 at 14:04:42
Sorry for not being that clear,

1.) Light position/direction shall not be transformed, as it is already given in world coordinates.

2.) Use the transposed inverted world matrix on the normals (not cancel transformation at all)

or the second method (unusual):


transform both the vertex-pos and the normal-point-to-pos with the world matrix,
subtract the new normal-point-to-pos from the new vertex pos, normalize

BTW, normal calculation need a normalization (sqrt == equal). It should be possible to avoid terrain rotation at all. For example one could rotate the camera instead...
 Poster : radulph
 Posts: 218
 Country : germany
 City: hamburg

  
Posted by radulph on 18/08/2008 at 14:17:08
ahhhhh wait! you dont even need to normalize the new normal, since its length will be still 1.

this is because rotation/translation doesn't change the distance between positions in the mesh.

excpet, of course, you would like to scale the terrain, then you would have to normalize the regained normel value.

;)
 Poster : Totem
 Posts: 11
 Country : Italy
 City: Pavia

  
Posted by Totem on 19/08/2008 at 04:30:08
I have ended with an easier solution: moving the camera instead of the entire terrain.

Anyway, thanks for your kindness.

  
Post a new reply
 





Google
 
Web www.riemers.net
If you appreciate the amount of time I spend creating and updating
these pages, feel free to donate -- any amount is welcome !
- Website design & DirectX code : Riemer Grootjans -
©2006 Riemer Grootjans


News
Home
Forum
XNA 2.0 Recipes Book (8)
XNA 3.0 Recipes Book (8)
Downloads
Extra Reading (3)
Matrices: geometrical
Matrix Mathematics
Homogenous matrices
Community Projects (1)
Tutorials (160)
XNA 3.0 using C# (89)
DirectX using C# (54)
Series 1:Terrain (14)
Opening a window
Linking to the Device
Drawing a triangle
Camera
Rotation - Translation
Indices
Terrain creation
Terrain from file
DirectInput
Importing bmp files
Colored vertices
DirectX Light basics
Mesh creation
Mesh lighting
Series 2: Flightsim (19)
Series 3: HLSL (19)
Short Tuts (2)
Resizing problem
Checking Device caps
DirectX using C++ (15)
DirectX using VB (2)