XNA UK User Group

A helping hand for bedroom coders throughout the land.
in

RandomChaos

May 2008 - Posts

  • Generic XNA - Movies in your Windows games

    Well, I started looking into this after a friend of mine asked if it could be done. I remembered the other week on Ziggyware that someone got a web cam to stream in an XNA app and so thought that the principle should be the same, taking the output, rendering it as a texture then applying it as you required. So started to try and do it myself, well I came a cropper as the examples I came across were for the old MDX and not XNA (I am not bright enough to do a full port), having to use unsafe code to get handles to the Game.Graphics device etc... but then I came across this post on codeplex as well as a few others which gives a class in XNA to do just this using DirectShow. Now all the examples I found seem to have originated from this post on CodeProject, as does the class I am using here.

    Now you may be wondering, where is the movie clip for this....well fraps does not seem to play well with the method I am using to do this and so does not generate a nice clip for me to put up, wish it did because I think it's pretty cool.

    Anyway, all I have done is got this lovely class's output image on a 3D surface. This means you can have movies playing in your games in a virtual cinema, have adverts playing on an advertising billboard as you race past in your racer game, have a television like in GTA IV (I love the cartoons!)

    Clip of the Web Cam in XNA done by MirageProject on YouTube, this gives you an idea of what my implementation looks like, but instead of giving it a device to read from you give it a *.wmv, *.mpg or any other supported format. Also, notice in my image above that the clip on the left is in black and white, this is down to the shader effect applied, not the clip.

    http://www.youtube.com/v/1s63YEWwgqI <p><a href="http://www.youtube.com/v/1s63YEWwgqI">http://www.youtube.com/v/1s63YEWwgqI</a></p>

     

    You can get the solution zip here. (You have to supply your own clips or the zip would have been huge!!)

  • RandomChaos Physics

    http://www.youtube.com/v/F8ImehSQ_ow <p><a href="http://www.youtube.com/v/F8ImehSQ_ow">http://www.youtube.com/v/F8ImehSQ_ow</a></p>

    So I have started work on a simple physics engine. I intend to have it serve both 2D and 3D development. I guess it wont have all the lovely bits and bobs that engines like BulletX have, but what the hell, it's going to help me understand how a Physics Engine works. Not sure about all the others, but this will naturally be exclusively for XNA and so written in C#. As ever I will put the full source up here once I have finished it so you can improve or add to it.

    So needless to say, other things may well be held up; Nova Wars and the Volumetric Cloud system being just two of them. As I think I have mentioned before; my goal now with the blog is to take all the samples I have put up and get them into an engine. This will also help me debug the samples as I will know what plays well with others and what does not. So I kind of think a Physics Engine, no matter how basic, will be a great addition.

    The clip in this post just shows where I currently am with the Physics Engine which is basic Force Generators. There is so much to do, not to mention adding 2D Physics too...I really have become an XNA junkie....help.....I don't seem to be able to stop..

  • Generic XNA - Fire 2D & 3D Shaders

    http://www.youtube.com/v/F2RMt7KKpW0 <p><a href="http://www.youtube.com/v/F2RMt7KKpW0">http://www.youtube.com/v/F2RMt7KKpW0</a></p>

    Well, this should be the final post on these flame shaders. As you have seen in the previous posts I have created 2D and 3D flame shaders based on the flame shader that comes with the NVIDIA SDK. When I initially created the 2D shader I found there was an issue with it when drawn with the 3D effect, turns out the issue was in the FireEmitterBase class, it was fixed by me setting the effect save state in the Begin call. Once that was done it all rendered fine.

    The only issue with the 2D flame shader is that you have to make a draw call per flame as an index.offset has to be passed per flame or the flame animations will all look the same.

    I have put them all in the same project, just added a new class for the 2D flame, as well as the shader it's self and a floor class.

    Solution can be found here.

  • Generic XNA - Fire 2D

    http://www.youtube.com/v/0pR_MX3ytuQ <p><a href="http://www.youtube.com/v/0pR_MX3ytuQ">http://www.youtube.com/v/0pR_MX3ytuQ</a></p>  

    Well, just posting my first attempt at getting the flame shader into 2D. It's not perfect, but as it stands at the moment, will give you 2D flames. When played with the 3D flames it does not seem to render well, but on it's own, as you can see it seems to be working. I am going to give it a bit of testing before I put the source out, but think it should be fine for pure 2D implementation, also still need to move the code into it's own solution....

    As ever C&C welcome.

  • Generic XNA - 3D Fire Sample

    Hope the music is acceptable this time...

    http://www.youtube.com/v/y-txtVQ7rUU <p><a href="http://www.youtube.com/v/y-txtVQ7rUU">http://www.youtube.com/v/y-txtVQ7rUU</a></p>

    Sorry about the quality of the clip, it was a 20MB clip, but I think youtube has crunched it up adn so it has lost some quality....

    OK, here is the code sample for the flame shader I have adapted from NVIDIA's Volumetric Flame shader. The emitter class is pretty much the same as the billboard particle samples in my earlier posts, the real work is in the shader. I took the original NVIDIA flame shader and merged it with my billboard shader resulting in the sample you see here.

    Now the emitter given in this sample is very basic, but I am sure you will be able either derive from it or use it as a template for your own flame emitter.

    I have had a few requests regarding a 2D version of the shader so I am going to look at applying it to a 2D context.

    Solution can be located here.

  • SkyBox Shader Fix

    I have found my skybox shader has a bug in it, the shader displays the cubemap as a reflection, the following shader code will give a better result.

    So, if you have used my skybox sample then replace the shader with this code:

    Texture surfaceTexture;
    samplerCUBE TextureSampler = sampler_state 
    { 
        texture = <surfaceTexture> ; 
        magfilter = LINEAR; 
        minfilter = LINEAR; 
        mipfilter = LINEAR; 
        AddressU = Mirror;
        AddressV = Mirror;
    };
    
    float4x4 World : World;
    float4x4 View : View;
    float4x4 Projection : Projection;
    
    float3 EyePosition : CameraPosition;
    
    struct VS_INPUT 
    {
        float4 Position    : POSITION0;
        float3 Normal : NORMAL0;    
    };
    
    struct VS_OUTPUT 
    {
        float4 Position    : POSITION0;
        float3 ViewDirection : TEXCOORD2;
            
    };
    
    float4 CubeMapLookup(float3 CubeTexcoord)
    {    
        return texCUBE(TextureSampler, CubeTexcoord);
    }
    
    VS_OUTPUT Transform(VS_INPUT Input)
    {
        float4x4 WorldViewProjection = mul(mul(World, View), Projection);
        float3 ObjectPosition = mul(Input.Position, World);
        
        VS_OUTPUT Output;
        Output.Position    = mul(Input.Position, WorldViewProjection);
        
        
        Output.ViewDirection = ObjectPosition - EyePosition;    
        
        return Output;
    }
    
    struct PS_INPUT 
    {    
        float3 ViewDirection : TEXCOORD2;
    };
    
    float4 BasicShader(PS_INPUT Input) : COLOR0
    {    
        float3 ViewDirection = normalize(Input.ViewDirection);    
        ViewDirection.x *= -1;
        return CubeMapLookup(ViewDirection);
    }
    
    technique BasicShader 
    {
        pass P0
        {
            VertexShader = compile vs_2_0 Transform();
            PixelShader  = compile ps_2_0 BasicShader();
        }
    }

    Sorry for giving you a crappy shader in the first place :P

  • Generic XNA - Fire

     

    Yes, I have been playing with fire! I have had this flame shader by NVIDIA (from the SDK) for ages now. I tried to implement in my olf RC3D Engine but it was a poor attempt and was of no real use to anyone, but I think I may have the beginnings of a decent implementation now. I have mixed the NVIDIA shader based on Yury Uralsky's "Volumetric Fire" with my billboard shader and billboard particle system and it seems to be playing quite well.

    Take a look at the clip and let me know what you think.

    http://www.youtube.com/v/ywhEuMNF19c <p><a href="http://www.youtube.com/v/ywhEuMNF19c">http://www.youtube.com/v/ywhEuMNF19c</a></p>

  • Generic XNA - Ocean II

    "Water, Water everywhere and not a drop to drink..."

    http://www.youtube.com/v/dp1wC53S4XA <p><a href="http://www.youtube.com/v/dp1wC53S4XA">http://www.youtube.com/v/dp1wC53S4XA</a></p>

    Yes more water. This is the fix to my original Ocean class. I found a fair few errors in the class, the shader was fine, just me as usual. As you can see the performance is better and is comparable with Anirudh S Shastry's shader I posted last time.

    Not much else to add so you can locate the solution here.