DamienRoot6

Hi,

Does anyone know if it is possible to apply Direct3D lights to sprites constructed using the Sprite helper class in Managed DirectX Since the class creates a quad for the sprite, I would have thought it possible to light the quad or rather the quad's texture.

I have tried adding a light to my sprite scene and have tried doing this both before and after drawing the sprites. However, I cannot seem to get the lights to work. I have used the following code:

// This is in my initialise section:

m_Direct3DDevice.RenderState.Lighting = true;
m_Direct3DDevice.RenderState.ZBufferEnable = true;

// This is in my render loop:

m_Direct3DDevice.Clear(Microsoft.DirectX.Direct3D.ClearFlags.Target, Color.Black, 1.0f, 0);

m_Direct3DDevice.BeginScene();

Light l = new Light();

l.Ambient = Color.Green;
l.Diffuse = Color.Green;
l.Type = LightType.Point;
l.Direction = new Vector3(0, -1, 0);
l.Position = new Vector3(0, 10, 0);
l.Range = 50;

m_Direct3DDevice.RenderState.Lighting = true;
m_Direct3DDevice.Lights[0].FromLight(l);
m_Direct3DDevice.Lights[0].Enabled = true;
m_Direct3DDevice.Lights[0].Update();


// code for drawing the sprites is placed in here.... I haven't included it for reasons of space.....

m_Direct3DDevice.EndScene();
m_Direct3DDevice.Present();

// End of render loop

All that happens at the moment is that the sprites draw themselves as normal with no application of any light effects.

If it is not possible to light sprites, can anyone suggest how I might fake lighting I'm imagining some Alpha Blending trickery might do the job....

Thanks,

Damien.


Re: Game Technologies: Graphics Managed DirectX Sprites: Is it possible to light them?

BLANC Guillaume

It should work. Have you try rendering something else but sprites in order to see if lighting is working with the exact same code





Re: Game Technologies: Graphics Managed DirectX Sprites: Is it possible to light them?

Bad Habit

The quads may require normal data for lighting to work. Another thing to test is to add a material and turn the diffuse, specular, colour and power up to see if that achieves anything. If it doesnĄŻt then you may need to create your own class so that normals are added.





Re: Game Technologies: Graphics Managed DirectX Sprites: Is it possible to light them?

Inaki Ayucar

I havenĄŻt tried but I guess that wonĄŻt work.

Take a look at the sprite helper function. IĄŻll do that tomorrow but I guess itĄŻs using an unlit vertex format.

You can use the System.Drawing.Color passed as an argument to the Sprite.Draw2D function to simulate lighting, but that would require to calculate the light color at the point. You can also do something similar using Point Sprites, some kind of 3d positioned sprites, but they have some constraints.

You cand also do a billboarding manager class, as I do. There was an example of how to do that in a DX SDK sample some versions ago.






Re: Game Technologies: Graphics Managed DirectX Sprites: Is it possible to light them?

abcdefgqwerty2

I have been wondering how to do the exact same thing. I didnt know a sprite had quads associated with it. I was thinking I could use the rectangle the sprite uses and give it a normal, but I couldnt figure out how or get it to work.




Re: Game Technologies: Graphics Managed DirectX Sprites: Is it possible to light them?

DamienRoot6

Thanks for your replies guys. I too don't think this is possible. If it was, I'm sure the web would be awash with various examples. I have taken an entirely different approach using various options for the source and destination blends for the render device to achieve some very convincing fake light effects with textures consisting of black / white gradient fills. I certainly have what I want for my game now and would suggest that anyone wanting to achieve the same effect to look here, this page was particularly useful:

http://blogs.msdn.com/shawnhar/archive/2007/01/02/spritebatch-and-custom-blend-modes.aspx

Thanks again though.

Damien.





Re: Game Technologies: Graphics Managed DirectX Sprites: Is it possible to light them?

Inaki Ayucar

Yes, sprites are rendered using an underlying geometry. Anyway, have you considered using the color parameter in the Sprting.Draw2D method for simulating lighting I thing that would be much cheaper than using the blending effect.

If you are so kind, could you mark my answer as "helpful" or "answer" If it helped you, of course.

Thanks!






Re: Game Technologies: Graphics Managed DirectX Sprites: Is it possible to light them?

DamienRoot6

Yes I have looked at the color parameter. However, it lights the whole sprite which isn't all that useful. However, the blending methods I am using seem to work fine and run at good speed. TBH I'm only blitting some very simple objects so i would doubt it even comes close to taxing any half decent graphics card