Randomchaos MG Samples

Hi all,

I have been posting bits all over the shop here lately as I am getting back into MG as a hobby again, and creating my own engine and editor, as I am doing this, I am reading a post or two about things I have written or looked into back in my old XNA MVP days, and so I have started porting some of my old Randomchaos XNA-UK blog posts to MG and keeping them on GitHub. I will also be adding bits I think might be useful to others from my engine here too.

Anyway, I thought, rather than me updating the various threads I have posted my repo on here Ill post all updates here as and when I make them.

At the moment my repo has the following examples:

  • Basic UI example
  • Scene Ray picking example
  • Post Processing example
  • Basic Terrain example
  • Geo Clip Map Terrain example
  • NVIDIA Ocean shader example

I am adding them quite quick, and if you have a look, it could do with a tidy up really, but if I can get them on there, then at least I have them working in MG rather than XNA(1-4)

Hope you guys find them useful, let me know if you have any issues or questions regarding the examples, some of it I wrote years ago, so ill do my best to recall what I was thinking at the time :stuck_out_tongue:

Anyway, as I add stuff ill reply here.

The repo can be found here. I will update the Wiki at some point and show images of the sandbox projects running too.


Awesome! Your old XNA stuff was what got me interested in learning XNA/Monogame and shaders in the first place. :slight_smile:


Ahh cool, always nice to know the stuff I wrote/write helped people out, or they found it interesting :slight_smile:

1 Like

So, yesterday looking through my old XNA posts I came across a skysphere shader I did. There were a few post I did on it, and it goes as I think most of my old posts did describing what I am finding as I am going along.

Here are the posts in order:
Dynamic Sky Sphere
Dynamic Sky Sphere So Far…
Dynamic Sky Sphere With Clouds
Sky Sphere Clouds Source

It’s interesting going over these old posts, seeing the code again after a while and thinking that I would not write it that way now lol.

Anyway, I am porting the core functionality of these posts and samples, and sort of doing a little pruning and tidying of the code, but trying to keep to the original code base as much as I can.

I may do the HLSL lighting tutorial series I did next…


As I was looking into the code a bit I noticed that there is the half pixel correction present in the shaders which isn’t necessary anymore since shader model 4.0 (I don’t know at the moment which shader model is used in the source but you could check if you can remove this part).

I remember the difference was quite noticeable for gaussian blur shaders for example when I removed the half pixel offset.

Yea, that’s a legacy of DX9 and XNA. The half pixel fir gaussian is badly named, I think it’s actually pixel size.

Remember I am sporting them from my old XNA posts, but if you spot anything like this I’ll either fix it, or explain why I think it should be there :slight_smile:

Thanks for taking the time to take a look :smiley:

OK, so today’s update is as follows:

Ported the Light & Shade posts I did in XNA

Posts in order

8 post in all, but I have only done post 1-3, 5,6 & 8

also note, the skull and teapot assets, while added in the solution do not compile with the MG content pipeline. So, I have added a per build event that copies them from another folder at the root of the solution.

xcopy /E /Y “$(SolutionDir)XNAXNAAssets” “$(TargetDir)Content”

Here are images from the 6 posts it does cover.

Light & Shade I
Ambient Light, Diffuse Light, and combined

Light & Shade II
Diffuse light with color, multi lights and specular (Blinn-Phong)

Light & Shade III
Color Maps, Glow maps, bump maps and reflection/specular maps

Light & Shade V
NVIDIA Glass shader

Light & Shade VI
Refraction and Reflection

Light & Shade VIII
Planet shader, multi pass.

Hope you guys find these useful :slight_smile:


Hi @Kwyrky,

I just updated the repo and removed the legacy halfPixel stuff :slight_smile:

Thanks for the heads up :smiley:


Today, I have started to port my old XNA fire shaders. The one done today is from this original post

Had some issue with it as it seems that MG does not like to import 3D Textures, but have a work around in there for now…

Here it is in action:

Gahh… One gif failed to upload, but it’s here on my twitter feed

Hope you find it useful :slight_smile:

1 Like

Tonight I have added some more to the Fire project, put in my old school fire too.

All from my archive blog:

Hope you find it useful :slight_smile:


Not checked in yet, but started to create a Deferred Lighting sample in my MonoGame repo. Looks like I have an issue with either calculating normals, or importing them :stuck_out_tongue:

If I do check it in today, it will not be ready, it’s still a work in progress :slight_smile:

1 Like

OK, coming together now, sorted my normal’s issue :slight_smile:

Might commit the first drop this afternoon :slight_smile:

1 Like

Just got shadow maps done too, just hope I can get it checked in today, I really should be working though :confused:

1 Like

Multi lights with multi shadows, soft and hard shadows shown here, just need to tidy the code and shaders up a bit now lol


Looks good! Are you planning to tackle point light shadows?

Yea, not sure how efficient they are though, as you are looking at a 6 way render per point light :confused:

You could update the shadow maps only if necessary.

It might be an option to go with paraboloid mapping which requires only two shadow maps but is a bit heavier to calculate and has other disadvantages like a visible seam in some cases.

1 Like

Ya i never could get parabolic shadow mapping to work right due to the seem which really is a deal breaker.
Would love to see a working example of that which is equivalent to a cubed shadow map.

Im gonna check this out when if i get a chance. looks succinct and in order.

Is that water just a quad with refraction or is that a actual model mesh warping under the vertice shader ?

Little bit more in there today, need to clock off in a bit though. Going to check it in, but please be aware this is a WIP :slight_smile:

1 Like

The water is a mesh, the wave function is done on the GPU. :slight_smile: