[solved] SVN Rev 862 Terrain lighting - Reflection light

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
Yarcanox
Posts: 33
Joined: Sat Apr 14, 2007 11:23 pm

[solved] SVN Rev 862 Terrain lighting - Reflection light

Post by Yarcanox »

Solution: Because of the new light system I needed to use another way of setting the light direction. The light had exact the same angle like the plane, and this confused the lighting
I am working on a linux system (ubuntu linux) with opengl 1.5, using an NVidia GeForce4 Ti 4200 with AGP8X/AGP/SSE2

I added a directional ambient light and a simple terrain

Code: Select all

  smgr->setAmbientLight(video::SColorf(0.4f,0.4f,0.4f));
  globallight = smgr->addLightSceneNode(smgr->getRootSceneNode(),core::vector3df(0, 0, 0),video::SColorf(0.7f, 0.7f, 0.7f),100.0f,-1);
  glight = globallight->getLightData();
  glight.Type = video::ELT_DIRECTIONAL;
  glight.Position = core::vector3df(20,20,0);
  globallight->setLightData(glight);

Code: Select all

  levelterrain = smgr->addTerrainSceneNode("data/lev01.png");
  levelterrain->setScale(core::vector3df(15.0f, 1.8f, 15.0f));
  levelterrain->setMaterialTexture(0, driver->getTexture("data/lev01tex.png"));
  levelterrain->setMaterialTexture(1, driver->getTexture("data/sanddetail.png"));	
  levelterrain->setMaterialType(video::EMT_DETAIL_MAP);
  levelterrain->scaleTexture(1.0f, 40.0f);
  levelterrain->setPosition(core::vector3df(-500,-450,-250));
  r = 0;i = 8;
  while (r < 8) {
   i -= 1;
   levelterrain->overrideLODDistance(r,1800 - (i * 200));
   r += 1;
  }
This SVN Revision has now a nice reflection on the terrain which the latest stable 1.3.1 didn't have (or it wasn't turned on there somehow).
But it is a bit "blinky": Depending on the camera rotation, it appears or appears not. The position is completely irrelevant, I can move around without changing the angle and it stays if it is there or it stays away if it is currently not there. While rotating the cam, it blinks around, and when the camera is still, it stays there or stays away, so it has to do with the angles.

Here are two screenshots of it, the first with an angle where the light appeared and the second one with a camera angle where the reflection light was hidden (Note: The normal lighting of the terrain works, I mean the hills are bright on the sunside and dark on the other side like it should be, it is only the nice reflection light which blinks around)

Image

Image

PS: I just used the window mode to make screenshots using the linux screenshot tool, the bug appears in fullscreen mode too.
Last edited by Yarcanox on Sat Aug 25, 2007 7:53 pm, edited 1 time in total.
I'm not a native English speaker.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

First of all: Don't change the Position field of the SLight struct. Use the LightSceneNode Position. Next, directional light has no position, it only has a direction and is infinitely far away. The direction is computed from the rotation of the LightSceneNode, the untransformed light direction is (0,0,1).
All this only holds for the latest SVN revision, because the light handling has changed. Before, some strange things happended with SLight.Position to get either a position or a direction from it.
I guess that you encounter some problems because the light's direction is parallel to your plane. Just rotate the light a little towards the negative axis.
Yarcanox
Posts: 33
Joined: Sat Apr 14, 2007 11:23 pm

Post by Yarcanox »

How can I set the direction for the light now? With slightstruct.setposition, with lightscenenode.setposition or with lightscenenode.setrotation?
I do of course now that the light is infinite, and in the old version the code above created a light which shine with an angle like (20,20,0) to (0,0,0) :?
I tried to rotate the light, but I can't get the angle changed in the SVN version

EDIT: oh lightscenenode.setrotation works now :) must have done something wrong when trying this at first
I'm not a native English speaker.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Yes, you can set the position and the direction by transforming the lightscenenode. Use setRotation for the direction.
It should be noted that you cannot override the SLight struct values Position and Direction. These values are completely ignored and only used internally.
Yarcanox
Posts: 33
Joined: Sat Apr 14, 2007 11:23 pm

Post by Yarcanox »

yep I removed the part which tries to do this. thank you for your help
I'm not a native English speaker.
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

Could this be the changes I found in my terrain?

OpenGL and DirectX have a different representation for the light in my scene. I have 1 light and the terrain is lightmapped (surface with Lightmap+light). OpenGl is too bright, DirectX is too dark.
Post Reply