# 2D (Deferred) Lightning - Rotating light

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

## Recommended Posts

Hi,

Well in last two-three weeks I started working in XNA (game dev in general). After reading/watching few tutorials, i started giving myself "homework" :). So first i managed to make simple 2D shooting game, and after that particle engine and so on... Few days ago i was drawn to shaders and 2D lighting. After searching for tutorials (most of them for 3D) I found this "http://www.soolstyle.com/2010/02/2d-deferred-lightning/". I really like the effect, but now I want something more than a circle of light :). For example the guy who made that "tutorial" implemented that technique in his game (on link I gave you can watch a youtube video of that game), a character in game has some sort of a flashlight, and light is rotating, following a mouse.

So I have a few questions for you guys:
1. How do I change a shape of a light (from circle shape to something like in that video game)?
If somebody is willing to explain to me why is this line of code in HSLS drawing light in circle shape?
 pixelPosition.x = screenWidth * PSIn.TexCoord.x; pixelPosition.y = screenHeight * PSIn.TexCoord.y; pixelPosition.z = depth * 2.0f;

2. And how do i make a rotating light?
I tried experimenting with everything that I could think of, and I thought that calculating angle between light source and mouse position could give me desired effect but with no luck.
float angle = atan2(mousePosition.x - lightPosition.x, mousePosition.y - lightPosition.y); lightPosition.x = lightPosition.x * cos(angle) - lightPosition.y * sin(angle);lightPosition.y = lightPosition.x * sin(angle) + lightPosition.y * cos(angle);pixelPosition.x = screenWidth * PSIn.TexCoord.x;pixelPosition.y = screenHeight * PSIn.TexCoord.y;pixelPosition.z = depth * 2.0f;//////////////////////////////OR//////////////////////////////float angle = atan2(mousePosition.x - lightPosition.x, mousePosition.y - lightPosition.y); pixelPosition.x = screenHeight * (PSIn.TexCoord.x * cos(angle) - PSIn.TexCoord.y * sin(angle));pixelPosition.y = screenHeight * (PSIn.TexCoord.x * sin(angle) + PSIn.TexCoord.y * cos(angle));pixelPosition.z = depth * 2.0f;

You can see a necessary code on a web page I gave you.

P.S. Sorry for my bad English. :(

1. 1
2. 2
3. 3
4. 4
Rutin
16
5. 5

• 12
• 9
• 12
• 37
• 12
• ### Forum Statistics

• Total Topics
631419
• Total Posts
2999981
×