Implementing point and directional light

Feb 27, 2013 at 8:30 PM
Hi, I need to implement point and directional lights, but for that purpose I need several things
  1. Change project properties to support pixel shader 3_0
  2. Edit engine in right places, I noticed there are lightchunks computed but I don't see their purpose, and how to edit them for another lights
  3. I created spot light using shaders only, but I have problem with camera_forward, because while using it to compute spot light it reverses y-axis while I am facing 180 degrees and turns back when I get to 0 degrees (i.e if I'm looking in direction 0* at the ground, the spot light is also at the ground, when I turn around to direction 180* still looking at the ground, the spot will slowly reverse with my turning and the spotlight will be pointing in the sky, although I'm still looking at the ground.
So can you tell me how to do those things ? I tried to change settings for pixel shader 3 but it still reverses to using 2_0, I don't fully understand the lightchunks in gameengine and why is camera_forward in .fx files doing that strange behavior, thanks
Coordinator
Feb 28, 2013 at 1:39 AM
It's been a long time since I've done rendering stuff, and I haven't seen that code in awhile, but if I remember right you can create multiple game objects and give them a LightComponent. The LightComponent would respond to the request for light chunks and pass any needed details to the graphics system that way. Think of a light chunk as a container for information about a light.

I'm not sure why changing the shaders to 3_0 isn't working. Make sure you have your project set to use HiDef mode instead of "Reach" mode. Those are project settings built into XNA. Beyond that I'm not sure. I've been able to change my water shader to use PS3_0 and it worked and let me use more instructions.

As for the camera forward I'm guessing the reversal of the Y axis is for rendering water reflections, the camera has to flip its Y position over 0 to render the reflection.


On Feb 27, 2013, at 1:30 PM, "Hessesian" <notifications@codeplex.com> wrote:

From: Hessesian

Hi, I need to implement point and directional lights, but for that purpose I need several things
  1. Change project properties to support pixel shader 3_0
  2. Edit engine in right places, I noticed there are lightchunks computed but I don't see their purpose, and how to edit them for another lights
  3. I created spot light using shaders only, but I have problem with camera_forward, because while using it to compute spot light it reverses y-axis while I am facing 180 degrees and turns back when I get to 0 degrees (i.e if I'm looking in direction 0* at the ground, the spot light is also at the ground, when I turn around to direction 180* still looking at the ground, the spot will slowly reverse with my turning and the spotlight will be pointing in the sky, although I'm still looking at the ground.
So can you tell me how to do those things ? I tried to change settings for pixel shader 3 but it still reverses to using 2_0, I don't fully understand the lightchunks in gameengine and why is camera_forward in .fx files doing that strange behavior, thanks
Feb 28, 2013 at 5:53 PM
Yes I managed to set it to highres, I don't know why it made problems before.

I don't see camera_forward being used anywhere, can you remember where do you create the reversion so I can turn it off ?
Coordinator
Mar 1, 2013 at 6:07 PM
The only place the camera's look-at is altered is probably in the water reflection code, which should be within GraphicsSystem.cs.


On Feb 28, 2013, at 10:53 AM, "Hessesian" <notifications@codeplex.com> wrote:

From: Hessesian

Yes I managed to set it to highres, I don't know why it made problems before.

I don't see camera_forward being used anywhere, can you remember where do you create the reversion so I can turn it off ?
Mar 6, 2013 at 11:31 PM
I managed to pass cameraForward by retrieving it by message pipeline and successfully creating one additional point and spot light, although editing engine to create light matrices from them seems like a challenge.

There is another bug I am encountering frequently, skydome is more often then not missing from the scene, there is simply black nothing above. Sometimes after restart or recompile there is skydome, but at the next start it is missing.

Any ideas where I should look for problem ?
Coordinator
Mar 6, 2013 at 11:46 PM
I've never seen a missing skydome, except when I hit the backspace key while to program is running (which deletes all objects from the scene except terrain and the root scene object). You might try and see if the skydome object itself is being deleted or if this is some kind of rendering issue, I'm guessing it is the latter, especially if you weren't seeing this behavior before.



On Mar 6, 2013, at 4:31 PM, "Hessesian" <notifications@codeplex.com> wrote:

From: Hessesian

I managed to pass cameraForward by retrieving it by message pipeline and successfully creating one additional point and spot light, although editing engine to create light matrices from them seems like a challenge.

There is another bug I am encountering frequently, skydome is more often then not missing from the scene, there is simply black nothing above. Sometimes after restart or recompile there is skydome, but at the next start it is missing.

Any ideas where I should look for problem ?
Mar 7, 2013 at 1:31 AM
How would I check it's existence ? I've looked almost everywhere and can't find why it's not working, sometimes it compiles with skydome sometimes not, I tried different model, different texture, nothing seems to be affecting it
Coordinator
Mar 7, 2013 at 8:02 AM
You could:
* place a breakpoint where entities are deleted and watch for the skydome.
* Put a breakpoint anywhere in the scene manager that updates each frame and then examine the list of entities and check if the skydome is in the list.
* I believe we remove all components from an entity before deleting the entity, and I think each component has a method called on it when it is removed from an entity, you could see if that is being called on the SkyDomeComponent.
* The skydome entity has a constant rotation component on it, you could place a breakpoint in that component's update method, which is called every frame.
* if you have a graphics profiler you may be able to see if the skydome texture is in memory, or even if the skydome itself is creating a draw call.
* Look at the demo with the original engine code and make sure it works normally, and if so then start copying your changes over, compiling and running after all significant changes until you find what code caused the problem to start.


On Mar 6, 2013, at 6:31 PM, "Hessesian" <notifications@codeplex.com> wrote:

From: Hessesian

How would I check it's existence ? I've looked almost everywhere and can't find why it's not working, sometimes it compiles with skydome sometimes not, I tried different model, different texture, nothing seems to be affecting it
Mar 7, 2013 at 5:30 PM
Engine is edited too much now, it even has some postprocessing and animations, but it seems that skydome exists, as it is calling skydome.fx.

It must be something pseudorandom, as one time it works other times it doesn't.

Also I need to create depth map with terrain, I tried reusing your function on shadow map but it ommits terrain, how can I include him in depth mapping ?
Coordinator
Mar 7, 2013 at 5:55 PM
Each entity can specify if it receives and/or casts shadows, terrain is set only to receive shadows. Look in the QueryForChunks function in TerrainComponent.cs and you'll see that it returns out early if the type is 'ShadowMapCreate'. Remove that check so it won't return early. Additionally you'll need to copy the shadow shader code from a shader that supports shadows into the terrain shader.

Be warned, shadowing terrain will not be cheap.



On Mar 7, 2013, at 10:30 AM, "Hessesian" <notifications@codeplex.com> wrote:

From: Hessesian

Engine is edited too much now, it even has some postprocessing and animations, but it seems that skydome exists, as it is calling skydome.fx.

It must be something pseudorandom, as one time it works other times it doesn't.

Also I need to create depth map with terrain, I tried reusing your function on shadow map but it ommits terrain, how can I include him in depth mapping ?
Mar 7, 2013 at 6:10 PM
Edited Mar 7, 2013 at 7:32 PM
I did that and it still skips the terrain, there must be some other check somewhere :-/ I see the !cancreateshadows but terraincomponent doesn't even has this value

/Edit: well it has in quadTree but when I change the check to !canreceiveShadows which should include terrain, it doesn't do that
Coordinator
Mar 8, 2013 at 3:30 AM
The TerrainComponent handles render requests with the QueryForChunks function. Other objects have RenderComponents, which use the flags you mentioned.


On Mar 7, 2013, at 11:10 AM, "Hessesian" <notifications@codeplex.com> wrote:

From: Hessesian

I did that and it still skips the terrain, there must be some other check somewhere :-/ I see the !cancreateshadows but terraincomponent doesn't even has this value
Mar 8, 2013 at 4:54 PM
It started doing that bug with skydome even in your original project. It seems it is bound together with another bug.

I changed skydome model and applied it, and it showed up, but disappeared when I looked too high with camera.

Funny thing is, some models are doing same behavior, trees for example disappear if I look with camera above their bottom halve. It doesn't happen with some more uniform objects like crates, so it's very strange behavior.

So, where is code that deletes objects if I'm not looking at them ? It might need some bugfixing.
Coordinator
Mar 8, 2013 at 6:29 PM
Interesting, as I read your post I was thinking it could be a culling bug. The culling is done in the QueryForChunks method in the RenderComponent. There are two checks done, one against the clipping plane if there is one (this makes rendering more efficient when processing water planes), and a check of the camera frustum against the bounding sphere. If it is based on your view I would comment out the clipping plane check, that one wouldn't happen if water was not in view.



On Mar 8, 2013, at 9:54 AM, "Hessesian" <notifications@codeplex.com> wrote:

From: Hessesian

It started doing that bug with skydome even in your original project. It seems it is bound together with another bug.

I changed skydome model and applied it, and it showed up, but disappeared when I looked too high with camera.

Funny thing is, some models are doing same behavior, trees for example disappear if I look with camera above their bottom halve. It doesn't happen with some more uniform objects like crates, so it's very strange behavior.

So, where is code that deletes objects if I'm not looking at them ? It might need some bugfixing.
Mar 8, 2013 at 10:36 PM
Edited Mar 8, 2013 at 10:52 PM
Commenting out if (!desc.ViewFrustum.Intersects(this.boundingSphere)) fixed the trees, unfortunately commenting out if (null != desc.ClippingPlane) did not help with the skydome :-/ although it must be bound with viewfrustrum as it disappears when I change it. Anyway so far thanks for the help, it's really appreciated that you are trying to help here

btw the (!desc.ViewFrustum.Intersects(this.boundingSphere)) in the render component fixes bug with tall models disappearing

commenting out (!desc.ViewFrustum.Intersects(this.boundingBox)) in WaterComponent.cs fixes the disappearing skydome

now to find out why it is not working and how to restore rendering optimalisation...