XNA UK User Group

A helping hand for bedroom coders throughout the land.
in

RandomChaos

November 2007 - Posts

  • Sky Sphere Clouds Source

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

    I have altered the shader a bit since my last post. I now only use a single cloud texture, sample that three times and rotate each sample over the other and add the result to the sky color. I have done this as passing more was having an impact on FPS.

    So I have added two new functions to the shader to do the rotation of the textures.SwirlHoriz and SwirlVert.

    SwirlHoriz: This function is used to rotate the cloud texture horizontaly around the sky sphere, either clockwise or anti-clockwise.

    float2 SwirlHoriz(float2 coord,bool clockwise)
    {
       if(clockwise)
       {
           coord.x +=  cloudTimer;
           if(coord.x > 1)    
               coord.x = coord.x-1;
       }
       else
       {        
           coord.x -= cloudTimer;
           if(coord.x < 0)    
               coord.x = coord.x+1;
       }    
       
       return coord;
    }

    SwirlVert: This function is used to rotate the cloud texture verticaly around the sky sphere, either up or down.

    float2 SwirlVert(float2 coord,bool up)
    {
       if(up)
       {
           coord.y -= cloudTimer;
           if(coord.y < 0)    
               coord.y = coord.y+1;
       }
       else
       {
           coord.y += cloudTimer;
           if(coord.y > 1)    
               coord.y = coord.y-1;
       }
       
       return coord;
    }

    I have named this source Cloud I as I have just got a new book on HLSL and so I feel I will re work this at some point, in the mean time, here is what I have done.

    GenericXNAExampleSkyBox2CloudsI.zip

  • Dynamic Sky Sphere With Clouds

    OK, have a major project on at work, but still finding time to play with this :P Just so you don't go reading the whole post and then find there is no source link at the bottom, there is no source with this post.....

    Right, so I wanted to add clouds to this shader and I thought, a Perlin noise generated cloud system would be great! So I set off down the road of getting a Perlin noise generation function into my shader and I first came across ret noise(x). Alas, the first incarnation of this page told me it was available from PS 1.1 up to PS 3.0 (it has changed now:P) and so for a few hours I tried to implement this function in my shader but the swine would always return 0.....not much noise eh. So I asked around the community and it turns out that this intrinsic function is not available :)

    So my next stop was to get a Perlin equation (remember I have no education so unlike you guys I had to look this stuff up) I found plenty of examples including a talk from the man himself! But due to the very small area of my brain where I store my maths stuff I thought "Hey! I am sure there must be an NVIDIA shader out there that has noise!" and indeed there are. I then set about  bolting in a function from an NVIDIA shader; think it was the Dura wood one, anyway, got that in there and compiled................turns out my shader combined with this method turns out to be "too complex" would you believe, even if I put in multiple passes. In the end I have decided to fake my Perlin noise clouds. I use a few images generated in photoshop using the cloud render. over lap these and rotate them either vertically, horizontally or even both either clockwise or anti-clockwise giving me my cloud effect. I use one image as the cloud base and another two to subtract from it giving me separate clouds.

    Here are a few pictures to show you how I am progressing:-

    This is the first image I took, this is a single cloud texture with no rotation

     

    As you can see, not much definition.

    Still a single  texture but I increased the intensity (first two images played at *.5) and with horizontal rotation

     

    Looks like we have some kind of cloud effect.

    Now these are where I am up to now, 3 textures, the first  horizontally rotated clockwise, the second horizontally rotated anti-clockwise and the third has vertical and horizontal rotation.

      

     

    May not be the greatest cloud system yet, but I am liking the results so far. As ever you comments and input are welcome, don't be shy.

  • Terrain with Roads


    Well this is the source post for my terrain and road map stuff. I will briefly describe what I have added and then onto where the source download is.

     So all I have done is add another Vector4 to the vertex element that holds the weight of the given road texture to be drawn. This then needed a new string array to hold the asset paths and an array of Texture2D's, one for the textures and one for the normal maps. Also a new texture to hold the road map it's self.

    I added code to the LoadData method to store the road map weights for the three road channels, the LoadGraphiceContent method gets altered to load the extra textures, and naturally the Draw method and constructor.

    I have also added an ambient light parameter, but this was a precursor to what I am doing with the Dynamic Sky Sphere so it is not used much here.

    I also intend to add a GetRoadChannel method so that you can tell if you are on a road and if so, what road you are on so if you are using it for an off roading type game then you can alter the physics when the car is on or off the road. Might even extend this to the terrain weights too as driving over grass will be different to driving over sand or stone.

    GenericXNAExampleTerrain2.zip 

  • Terrain With Road Map


    I know, how many times can a guy extend a terrain class!!!!? Lots I guess, this extension to the class and shader adds another map image that I call a road map. As you can guess this image holds a map of where I want to draw roads on my terrain. It is made up of four colors, Black (no road), Red (road texture 0), Blue (road texture 1) and Green (road texture 2).

    I have extended the vertex element to hold another vector 4 for the "weights" of each road type, I have not used the W of the Vector and have it there for now as an extra info element (not found a use for it yet, guess I could add another road texture)

    I will upload the source once I have tidied up the code. As ever, here are some shots...

     

     

  • Dynamic Sky Sphere So Far...


    I am posting the source to this now as I have a project at work that is going to take up my time over Christmas and into the new year and also have to start studying if I am going to get anywhere with my Microsoft Certification :( I am not going to have chance to add any more to it.

    So this is the project as it currently stands. I have modified the SkyBox class, adding a public field called SunPos so that other objects in the scene know where the sun is and can use that for there main lighting source, there is also an Update method in there now which calculates the time of day to be passed to the shader, this can either be generated by the class or it will use the system time (default). As I said in my last post, I have added a point light to the terrain shader so you can navigate at night.

    Controls
    ESC - Quit

    WASD - Translate the camera.
    Mouse - Rotate Camera

    F1 - Real time
    F2 - Game Time (not to be confused with GameTime object)

    L - Light On
    O - Light Off

     As ever, your comments are more than welcome...

    GenericXNABoundingBoxExample2.zip

  • Dynamic Sky Sphere

    I guess this started out as a bit of a toy. Using my old skybox code, I thought it would be a good idea to have the shader manage the lighting of the sky, you know have like a nice sun rise/set, have the color of the sky slowly change over time. But as I was using a box it meant that you got some corners in the sky, now I have done some things in my youth that have altered my perception of the world around me, but nothing ever put corners in the sky.. So I thought about using a sphere, so I built one in Blender3D and UV'd it as a sphere so I would get a nice set of tex-coords.

    As you can see from the screen shots I am also passing the lighting position to the terrain shader as the time passes. I have also added a point light calculation to the terrain shader so you can see where you are going in the dark.

    This is going to be an on going project of mine, at the moment there is no "Sun" in the sky sphere and I want to add weather to it (clouds etc..), it may well be out side my technical capability, but I wont know until I try :)

    In my next post I will describe the shader as it currently stands. As ever your comments are welcome.

     Here are a few shots to be getting on with.. (notice the time of day in the top left hand corner of each shot)

       

      

  • OOBB Collision Detection


    Well thanks to Ultrahead and his blog he gave me, I have been able to put this example up of a OOBB (Object Orienated Bounding Box). Using the same code from the last project I have added the source from Minh at Channel 9. Took me a while to get it integrated as he is creating the roataiton from a vector where I am using a Quaternion and his example does not use any scale, so for a noob like me it took a bit to get going.

    But I have it here now, so I hope you find it of some use.

    Oh, and thanks Minh for putting your source up for us to learn from and to Ultrahead for puting it infront of me. 

     GenericXNABoundingBoxExample2.zip