Moving light source

Apr 26, 2010 at 12:26 AM

So I noticed that you have hidden the light classes so that modifying position is a bit tricky(unless I've missed something really obvious)

We had plans to have moving light sources  and I was just wondering if you're discouraging changing the position of the lights frequently?(this would be an everyframe operation pretty much not just once in a while)

 

Coordinator
Apr 26, 2010 at 10:45 AM
Edited Apr 26, 2010 at 10:47 AM

Hi.

I assume you are asking about MaterialShader and MaterialLightCollection?

When you call AddPointLight, the method returns an IMaterialPointLight interface. This interface has a Position property which is Get/Set, so you can use this interface to set the position of the light.
You may be unaware, but you can also add an IMaterialLight directly to a light collection (so lights can be removed, and do not need to be recreated with AddPointLight).

Hope that helps :-)

Apr 26, 2010 at 8:06 PM
Edited Apr 26, 2010 at 8:57 PM

Woah, wierd... Played around with it the whole night and got some error that I couldn't assign a value to it because it wasn't a variable, thought it was something that the interface didn't implement the get/set method but hey would you look at that... It works now.

 

Gonna try sneak another question into the mix, having problems getting lightning to work. Setting everything up like Tutorial 14 assigning specular values, a texture and all that to my material shader, adding the light's and to my dissapointment my mesh don't shine up like a christmas tree. I'm binding it aswell in the draw method.

Am I missing something really obvious here ya think?(yet to take a dive into shader's and lighting)  I've implemented your disk into my prototype just behind the mesh wich won't shine and it lits up without any problems.

 

Thanks on beforehand, I'll do my best to read up on this stuff further til/if I hear from you again(*hopeful* :>)

Coordinator
Apr 26, 2010 at 8:29 PM

This is actually a case where you have missed something, and it's not obvious. So it is kinda my fault :-)

If you are using per-pixel lights, then suddenly the pixel shader gets much more expensive. Around 3x as expensive. Basically normal lights optimise much better.
So by default, a material shader does not show specular lighting for per pixel lights. You have to set the 'UsePerPixelSpecular' property to true.

I know, it's not the best design decision. I will have to change how the MaterialShader works for XNA 4, so I will probably change this.

Apr 27, 2010 at 11:14 AM

So I had a look at your animation stress test and it seems when loading models(not building geometry) you gotta add the line

 

m_xModel.LightCollection = cGame.s_xLightCollection;

 

Where m_xModel is a ModelInstance

 

Anyhow, time to dive into some custom shader stuff so I can use specular map's instead of assigning a specular value to the whole material, will see how tricky this'll get with XEN.

 

Thanks alot for your help and time! :)

 

 

Coordinator
Apr 27, 2010 at 11:33 AM
Edited Apr 27, 2010 at 11:34 AM

Ahh yes, that is true.

The model instance internally stores it's own MaterialShader instances, as defined by the materials in the model. You set the light collection with that property of the model, or you can override the shader entirely with the ModelInstance SetShaderOverride method. (Both options also have DrawFlags available to force all models to use specific shaders / light collections)