Jump to content
  • Advertisement
Sign in to follow this  

Dynamic generation of Lens Flare rays

This topic is 4887 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

Hello there, I was implementing a HLSL lens flare generator, but I'm having some problems with the dynamic generation of the lens flare rays. Here it was suggested to generate these rays using particles, but since in a pixel shader the main function gets called for every pixel, it would become very ankward to write to specific areas of the texture. So the method that would apply on every pixel of the texture is the same method that on that page it is suggested to avoid [smile]. And that is calculating atan2 for every pixel in the texture and using the resulting angle as an index for a look-up array. This is the code I was basing myself on:
private idx3d_Texture createRays(int size, int rays, int rad, int color)
	int pos;	float relPos;
	idx3d_Texture texture=new idx3d_Texture(size,size);
	int[] radialMap=new int [1024];
	idx3d_Math.clearBuffer(radialMap, 0);
	for (int i=0;i<rays;i++)
		for (int k=pos-rad; k<=pos+rad; k++)
		int angle,offset,reldist;
		float xrel,yrel;
	for (int y=size-1;y>=0;y--)
		for (int x=size-1;x>=0;x--)
	return texture;

I managed to port the second for-loop of the function to a HLSL shader, while for the first part I was using a 1024 * 1 texture to simulate the radial map built in the first part. This texture was then filled with a radial gradient. It seems to work: I'm getting textures like Japan's naval flag [attention]. What I would like to know is what I'm really doing by using atan2 and why it is effectively displaying raylike features in my texture [smile]. I suppose that in the first for-loop it is creating a "radial map" in order to filter out some rays and add some randomness. In fact, since my "radial map" is a simple gradient, the line that computes the "angle" value, where it remaps the atan2 value to the [0..1024] range is in reality affecting the number of rays that are rendered. If I multiply that value by 2 I get two rays, while by 16, sixteen rays and so on. If the number becomes too big I get some circular patterns. I guess this depends on my radial map being not suitable, am I correct? So I should generate that radial map via code and then pass it to the shader and it should work. So is this the right way to do it?

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!