Jump to content
  • Advertisement
Sign in to follow this  
DamienGreen

MDX: Applying light effects to sprites?

This topic is 4281 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
I'm pretty sure this doesn't work because ID3DXSprite doesn't use the FFP (remember that SetLight() is purely a fixed-function interface). Instead, it probably uses its own shaders so that it can maximize the number of textured quads that can be rendered at once.

Like you mentioned, you could try some alpha blending tricks to give the illusion of lighting. Also remember that Draw() has a modulation color, too (although this very well may not suit your needs).

Additionally, you could always make your own sprite renderer and do all the lighting that you want. Implementing the basics should be very easy, if you are interested.

Share this post


Link to post
Share on other sites
Thanks for the reply. Yeah I wrote a sprite renderer some time ago for DirectX in Visual Basic 6. I thought that there may be a problem with this but was hoping I might be able to light the resulting quads. Nevermind, I could indeed write my own library, I'm sure I can reuse a lot of the VB6 logic...

Since I made this post yesterday, I have managed to create some pretty good fake effects by messing with the Device RenderState property to change the Source and Destination blend types. I think this will suffice nicely for my needs.

You can indeed colour a sprite, but unfotunately this provides a uniform adjustment to the whole texture rendering it rather useless for situations where light would fall on just the top of something for example. I'd rather not go down the road of partially lighting part of a sprite by redrawing a bit of it etc.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!