XNA Tutorials, Samples and Thoughts
- 2D 2009 2010 Amused Sloth AmusedSloth Animation Announcement Chickens Can't Fly Chickens Can Dream code Community Games DBP Deferred Rendering details Finally! Gamasutra license MVP News postprocessing Rebellion Rise Roy Sample Shadows summary Summit Trailer tutorial Windows Phone Windows Phone 7 WP7 XBLIG XNA XNA 4.0
- September 2011 (1)
- June 2011 (2)
- March 2011 (1)
- February 2011 (1)
- January 2011 (2)
- December 2010 (2)
- July 2010 (1)
- May 2010 (1)
- April 2010 (1)
- November 2009 (1)
- October 2009 (2)
- September 2009 (2)
- August 2009 (1)
- July 2009 (1)
- June 2009 (4)
- April 2009 (3)
- March 2009 (2)
- February 2009 (2)
- January 2009 (5)
- December 2008 (1)
- November 2008 (2)
- October 2008 (4)
- September 2008 (5)
- August 2008 (1)
- July 2008 (7)
- June 2008 (1)
- May 2008 (4)
- April 2008 (3)
- March 2008 (3)
- February 2008 (4)
- January 2008 (2)
- Small pre-pre-beta shadow mapping lirary (36)
- Working on shadows… (34)
- My technique for the shader-based dynamic 2D shadows (29)
- April Sample Online! (20)
- 2D Skeletal Animations (20)
- School Projects with XNA (17)
- Mass Effect Dialogue Sample (17)
- Welcome! (14)
- My experience with Toon Boom Studio (12)
- Adding softness to shadows (12)
AddictiveColors: Awesome idea, this screen space solution looks to be quite neat for games with many shadow casting...
meizitang: These healthy weight loss tips that will make it easier to take those first steps towards pursuing...
Adding the Effect files | Project Vanquish: [...] are unfamiliar with HLSL, Microsoft wrote a brilliant guide about programming in HLSL. And,...
Welcome to Project Vanquish! | Project Vanquish: [...] searching in the past regarding XNA and Deferred Rendering. The example that crops up the ...
De leukste filmpjes gratis plaatsen en bekijken.: De leukste filmpjes gratis plaatsen en bekijken.... [...]2D Skeletal Animations[...]...
Tim Stern: Hi Catalin, I discovered a possible mistake in your file Transformation.cs, function public...
louis vuitton: I'm glad I located your post. I would never have created sense of this subject on my own. I're...
consultoria de sistemas: consultoria de sistemas... [...]2D Skeletal Animations[...]...

about 3 years ago
That is really cool. I can’t wait to get home and play with it.
about 3 years ago
Downloading it now … c’mon c’mon … hurry up!
about 3 years ago
Wow, great visual effects!
about 3 years ago
Great stuff! One question though: why did you turn off fixed time step and syncing with vertical retrace? That caused some awful tearing on my machine. I re-enabled both and it still ran great. Any particular reason?
about 3 years ago
No particular reason.
I just disabled them so I could test the framerate of some configurations one last time, and forgot to re-enable them.
about 3 years ago
I uploaded the modified version. Thanks, Nick for pointing it out.
about 3 years ago
No problem. Thanks for the awesome sample. This effect is so going into my code.
about 3 years ago
“This effect is so going into my code.”
Ditto.
about 3 years ago
The energy bolt effect will come in handy in a game I’ve got in the works.
about 3 years ago
Oh my god, i have nearly cum in my pants playing with this!!! It’s amazing!
about 3 years ago
Hi Catalin
This is an amazing sample. May I ask for your advice?
I am creating a RPG in 3d. I want to have a lightning spell that looks like this. However, since this lightning is drawn with the spritebatch and in the 2d background, my terrain model covers up most of the lightning, so you cannot see the lightning. How can I create a lightning spell that moves from one player to another in 3d?
about 3 years ago
The actual lightning branches are all 3D vertices.
To put them in a 3D scene, you would have to modify some code, and instead of rendering the lightning on a transparent render taget (liek I do), render it directly into your scene.
about 3 years ago
Sorry, I am not very good with graphics. Can you upload a sample if it is not too hard for you? Thank you!
about 3 years ago
Hi again,
If I want to render the lightning effect in a 3d world, should I change texture coordinates in the lightning vertex class to a vector3, and then change the lightningpoint.texturecoordinate in the lightning bolt class to the point in 3d space?
about 3 years ago
No. The texture coordinates remain as they are. Each branch of the lighting should remains a billboard.
You basically need to set to 3D the Positions of the points. You also need to Modify the GetJittered function to add a random Vector3 vector instead of a random Vector2 vector.
about 3 years ago
I would make the modifications for 3D, but I don’t really have much free time for this.
about 3 years ago
Sorry Catalin, I hate to keep asking you questions. I will gladly send you the final modifications if I can successfully alter this.
The lightning vertex positions and lightningPoints already have vector 3s, so when you say set to 3d the positions of the points, are you referring to this code?
using (VertexDeclaration vdecl = new VertexDeclaration(device, LightningVertex.VertexElements))
{
device.VertexDeclaration = vdecl;
device.RenderState.CullMode = CullMode.None;
lightningDrawEffect.Begin();
lightningDrawEffect.CurrentTechnique.Passes[0].Begin();
device.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, lightningPoints, 0, lightningPoints.Length, indices, 0, indices.Length / 3);
lightningDrawEffect.CurrentTechnique.Passes[0].End();
lightningDrawEffect.End();
}
Sorry, this is the first time I am doing something advanced with graphics. I have already learned a lot from your sample!
about 3 years ago
No, that code is fine as it is.
I mean when you set the StartPoint and EndPoint.
In truth, most code already works with Vector3 wherever possible. So as I said above, I believe chaging the GetJitter function to add a random Vector3 should do the trick.
about 3 years ago
Wow it was that simple?! I changed getJitter to use a random vector3 and created a new property called JitterRightDeviation and a new method called GetRight to match the GetLeft method that you have. The lightning renders with a point in 3d for its source, but the destination still seems to be a point somewhere in 2D. Here is an image of my program. http://img300.imageshack.us/my.php?image=lightningkq9.jpg
The lightning should go from the person on the left to the person on the right, but it is going to the background for some reason? Also, you can only see the lightning if the player is jumping and above the terrain.
This is an amazing sample, beautifully made!
about 3 years ago
That’s probably related to the depth buffer.
about 2 years ago
Hiya, Ive implemented a 3d version of this, but split it into its own Draw() function so that I can render it with a depth buffer.
This bit works, it creates a 3d Jitter.
The only problem Im finding now, is that I cannot for the life of me, get the X/Y/Z coords to face the camera correctly.
So, from some angles, it looks fine, and from others – really really bad.
Is there something Im missing?
about 2 years ago
Thanks alot.
I will try to integrate this stuff into my deferred shading, it probably works well in alpha drawing.
about 2 years ago
I have finished integrating this stuff into my deferred shading.
I use it for my rainy scene with the following setup.
LightningDescriptor ld = new LightningDescriptor();
ld.AnimationFramerate = 12f;
ld.ExteriorColor = Color.WhiteSmoke;
ld.GlowIntensity = 3f;
Also when the time to draw the lightning is come, I only randomize once for the source point, but then every frame for destination point. (For this case I have one flag indicates that the lightning is started to draw yet, so the only one time for randomization of source point can be accomplished.)
One last note, I duration for the lightning in the rainy scene should not be more than 1 seconds, for my setup, I used 1, 0.75f, 0.5f seconds for many different pattern for my lightning.
Thanks for this great stuff.
about 2 years ago
I am attempting to use your effect in 3D. All I had to do was comment out the render target code and it works perfectly fine on PC. However, when I run it on the 360 it looks horrible, the lighting bolts have black squares and black sections. Here are the changes I made to the code:
public void GenerateTexture(GameTime gameTime, Matrix world, Matrix view, Matrix projection)
{
GraphicsDevice device = game.GraphicsDevice;
//device.SetRenderTarget(0, lightningRT);
//device.Clear(ClearOptions.Target,Color.TransparentBlack,1.0f,0);
lightningDrawEffect.Parameters["World"].SetValue(world);
lightningDrawEffect.Parameters["View"].SetValue(view);
lightningDrawEffect.Parameters["Projection"].SetValue(projection);
lightningDrawEffect.Parameters["StartColor"].SetValue(properties.InteriorColor.ToVector3());
lightningDrawEffect.Parameters["EndColor"].SetValue(properties.ExteriorColor.ToVector3());
device.RenderState.AlphaBlendEnable = true;
device.RenderState.BlendFunction = BlendFunction.Max;
using (VertexDeclaration vdecl = new VertexDeclaration(device, LightningVertex.VertexElements))
{
device.VertexDeclaration = vdecl;
device.RenderState.CullMode = CullMode.None;
lightningDrawEffect.Begin();
lightningDrawEffect.CurrentTechnique.Passes[0].Begin();
device.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, lightningPoints, 0, lightningPoints.Length, indices, 0, indices.Length / 3);
lightningDrawEffect.CurrentTechnique.Passes[0].End();
lightningDrawEffect.End();
}
//device.SetRenderTarget(0, null);
//if(properties.IsGlowEnabled)
// postProcessGlow.ApplyEffect(lightningRT, lightningRT, properties.GlowIntensity);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
//draw it in 2D
Matrix viewMatrix = Matrix.CreateLookAt(new Vector3(0, 0, 10), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
Matrix projectionMatrix = Matrix.CreateOrthographic(GraphicsDevice.Viewport.Width / 20, GraphicsDevice.Viewport.Height / 20, 0.01f, 50);
Matrix worldMatrix = Matrix.Identity;
//generate the lightning rendering
lightnings[currentItem].GenerateTexture(gameTime, worldMatrix, viewMatrix, projectionMatrix);
Rectangle rect = new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
//GraphicsDevice.Clear(Color.Black);
//spriteBatch.Begin(SpriteBlendMode.Additive);
//if (showBackground)
// spriteBatch.Draw(background,rect,Color.White);
////draw lightning texture over the scene
//spriteBatch.Draw(lightnings[currentItem].LightningTexture, rect, Color.White);
//spriteBatch.End();
base.Draw(gameTime);
}
about 2 years ago
Fantastic sample!
I’m trying to use lightning effect in a 2D game but I have some trouble to set source and destination point because I cannot understand how to “convert” from screen coordinates (the game use 1280×800 screen size)to lightning source/destination coordinates;
Can you help me?
Thanks,
Marco
about 1 year ago
Hiya, Ive implemented a 3d version of this. It still renders along a 2d plane but is rendered in 3d. I also created a 3d jitter function but that didn’t seem to change anything.
The only problem Im finding now, is that I cannot for the life of me, get the X/Y/Z coords to face the camera correctly.
So, from some angles, it looks fine, and from others – really really bad.
Is there something Im missing?
Please Help.
about 1 year ago
I’ve downloaded and run the sample.
It doesn’t do anything for me.
I can run it with no errors, make the background appear and disappear and exit.
How do I make the lightning appear?
-=PreZ=-
about 1 year ago
This looks fantastic, and very true to the original sample. My use would be 2D, to pre-render sprites of (glowy/neon) laserbeams. I’d absolutely love for a version of this to be updated and run-able in the new 4.0 version of the XNA Game Studio framework.
I’m trying out a re-instrumentation of the code, but may not be successful. If anyone already wanted to do this, then I’d love to hear about it.
about 1 year ago
I have tried to convert this to XNA 4.0 with no success I am to new to XNA, even though I have spent hours fixing all the errors more keep coming, if anyone has or can succesfully convert this to 4.0 please email it to me at djdduty@gmail.com I will give many many thanks
about 10 months ago
Any 4.0 version of this?
Converting it has so far failed for me…
So many things changed…
about 9 months ago
I upgraded this to 4.0 because I needed the effect for a project. Please note some parameters and colours may be different. Works fine when I compiled and ran using VS2010 Express.
http://www.hatchingdisaster.com/LightningSampleXNA4.zip
about 8 months ago
Cool effects. One question… can we use these classes in our commercial projects?
What are the license terms?
(I will put your names in the credits, of course).
Thank you.