RBWhitaker's Shader Tutorials in MonoGame Help Part 2 - Skybox and Toon Shader

I posted earlier about how I’m going through RBWhitaker’s very old XNA tutorial about shaders and trying to get them to work with a Monogame project. I’m still having some trouble because I am new to this stuff so my only recourse is to post here and hope someone has some insight.

SKYBOX

I’m up to the Skybox tutorial but alas my Skybox isn’t working. It just doesn’t seem to show anything.

Here’s some of my current code:
The Skybox.fx. This is the same as Whitaker’s code but I had to update the versions at the end: float4x4 World;float4x4 View;float4x4 Projection;float3 CameraPosition; - Pastebin.com
The Skybox.cs code. This is pretty much exactly the same as Whitaker’s code I just changed where and how things were loaded.
using System;using System.Collections.Generic;using System.Linq;using Syst - Pastebin.com
Here’s the Shader code that calls the Skybox. Again, although my code is a bit different it is the same where it counts I believe:
using System;using System.Collections.Generic;using System.Linq;using Micr - Pastebin.com

Now there are two other elements here. The .dds image and the cube fbx. For the .dds I made sure that the premultiply alpha is set to false on the MG pipeline tool (Whitaker warns that often if the Skybox isn’t working it’s because this is set to true)

As for the cube I tested it to make sure it is being drawn at least. Maybe it’s drawing the Skybox externally instead of internally?

TOON SHADER

I also wanted to try out the Toon Shader, but did not get very far with this one at all.

Here is the code. Again I only updated the versions in the passes at the end:

The error I’m getting is with semantics:

semantics

I had no trouble with SV_POSITION and TEXCOORD0 semantics with other shaders. I don’t get it. Searching for this issue on google revealed that my .fx file may be being interpreted as a Vertex Shader when it needs to be interpreted as a Pixel Shader. I don’t know if that’s the case and, if it is, how to set it as a pixel shader.

CONCLUSION

Please keep in mind the purpose of this is for education. I don’t know if I necessarily want skyboxes and toon shaders in a game, but I do want to understand the problems here so that I can learn something.

I see your post was over a year ago but thought I’d reply anyway - did you ever get this to work?

I actually got this working in latest Monogame just today. His cube (fbx file) did not build in MGCB. I had to use a different one. Also make sure you do the whole thing with CullMode:

RasterizerState r = new RasterizerState();
r.CullMode = CullMode.CullClockwiseFace;
GraphicsDevice.RasterizerState = r;

skybox.Draw(viewMatrix, projectionMatrix, camPosition);

r = new RasterizerState();
r.CullMode = CullMode.CullCounterClockwiseFace;
GraphicsDevice.RasterizerState = r;

And for my shader I put:
VertexShader = compile vs_3_0 VertexShaderFunction();
PixelShader = compile ps_3_0 PixelShaderFunction();

Finally, when I changed the dds file PremultiplyAlpha to false, I had to click off of that file and onto another file in MGCB for it to actually save, then I rebuilt and it worked.

Just a few gotchas that were screwing me up for a while.

1 Like