Troubleshooting this TutorialSometimes, even though you try hard to understand the information in a tutorial, things don't work out quite like you want it to. This page is here to help you resolve any problems you might be having with the tutorial on creating a reflection shader. The Common Mistakes section describes common problems that people have when doing the things in this tutorial, and how to resolve them. The Frequently Asked Questions section describes questions that people have that aren't related to mistakes, but rather, trying to understand the stuff better or exploring how it can be used. If your problem or concern isn't addressed here, feel free to add a comment below, so that I know where you're having trouble. I like to keep these pages fairly clean, so I may remove comments that I felt like have been addressed. If I remove your comment and you don't feel like the problem has been fixed, repost the question and we'll take another look at it. If a tutorial has a mistake in it, I will fix the mistake and reply to the comment with a brief explanation. However, after a couple of weeks I'll likely go back and remove the original comment as well as my reply, because, hopefully, the problem will have been fixed, and it won't be a concern any more. |
Common MistakesNone listed yet… |
Frequently Asked QuestionsWhy am I getting just a black screen? The most likely cause of this is because the file format that you are using, combined with the settings that you have chosen (or not—it may be the default settings that are doing it) end up in a situation where things just don't work, and you just get a black screen. Partly, this goes back to the settings that were in use when you (or anyone) made the skybox image. If you made it, you can go back into the settings and change it. If you purchased the skybox image, or got it from my site, you might not have control over those settings. At its root, the problem is that as of XNA 4.0, XNA likes to premultiply the alpha channel into the red, green, and blue channels (for some good reasons, admittedly)—that's the default. If your image already has premultiplied alpha values, or you don't want to use premultiplied alpha values in your game (which is our case, for this shader), you need to go in and change the setting on your skybox texture. Here's how to do this: 1. Look at your Properties for the skybox image/environment map. |
hi..the shader tutorials are great…
but how can i change the reflection shader to reflect the hole world and not only the skybox
greetz
I notice that when using this pixel shader I cannot render more complex shapes than a sphere. It renders the reflective objects as though there was no depth buffer, ie: background triangles keep 'poking through' any foreground surfaces.
I have tried manually creating a depth buffer and attaching it to the graphics device, and I've ensured "DepthBufferEnabled" is set correctly in the RenderState but none of this helps at all (nor was it necessary in your previous tutorials). So, I'm assuming that the pixel shader itself bypasses regular Depth buffering and would need to be modified to take care of Depth Buffering inside of the shader, is this correct ? Or have I just messed up somewhere else.
The models I am using work fine in the other tutorials, and the cullmode is correct…. the problem only occurs when I use the reflection shader.
Any ideas?
OH BTW, Just a quick heads-up: the sphere model is missing from your models page
Thanks for the amazing tutorials, you've really given me a lot of confidence and motivation, you're an absolute star : )))))
-Gary
//@Bryn : To reflect a whole world accurately requires 'raytracing' which is a VERY slow process and not suitable for games. If you look carefully at many racing games for example, the reflective cars often only reflect the skybox and not the other cars/objects. In practice this is usually good enough and the players rarely notice. Just switch to a different reflection map when a car goes into a tunnel for example, so that you're seeing tunnel lighting and not sky reflections : )
There IS a dirty method to aproximate this though. You can make a dynamic reflection surface …To do this you render a very wideangle view from the car back towards the camera for example, but render it into a texture. Then use this texture in calculating reflections. Doing this can really kill your framerate, and even where the card will handle it… it's still not something you could apply to multiple objects in your scene. This is similar to the way accurate side mirrors work in a racing game.
But my advice is, don't! Right now such inaccuracies are apparent to you. But, if your game is fun nobody will notice, honestly, and that should be your first goal, making it fun. Most of games programming is about deception. Trees are just camera-facing billboards, detail is faked with bumpmaps, buildings have no backs, but only programmers and cynics see these things - Worrying too much about the small details is the quickest route to an abandoned project : )
hope that helps//
Hmm… I don't know what to tell you. I just tried the Helicopter model that I've used in many of these tutorials and it all seems to be working like it should. But, then, I just updated this whole tutorial to XNA 4.0, and there may be some other changes I made that fixed this problem. (Though I can't think what those changes might be. This tutorial is more or less unchanged.)
I've uploaded a new version of my complete solution for the tutorial, which is currently using the Helicopter model. Take a look at that and see if there's anything different between your version and mine. Or perhaps, check to see if my version, running on your computer, causes the same problems you're describing.
Hi,
Great tutorials, but the reflection shader is giving me a headache. My sphere looks like it's refracting (sort of) instead of reflecting. I downloaded your example, made sure it worked and started trying to spot any differences in the code, properties, etc. I didn't find anything different. So I tried cleaning and rebuilding my project, only it wasn't my project that I was cleaning/rebuilding. I accidentally cleaned and rebuilt your project with no other alterations (except replacing the helicopter with the untextured sphere), but now your sphere looks exactly like mine. Needless to say, eyebrows were raised.
I tried deleting and recopying your example project over, but the changes have remained (yeah, oops). I've got a screenshot of what it now looks like with the camera in its starting postion, but I don't know if I can show you here.
I'll download the code and see what I get. You can always send me an email with the screenshot. Alternatively, you can upload the image to the web somewhere and just link to it. I'm pretty sure guests (and probably even registered users) don't have the ability to upload images here.
I'll let you know what I discover.
I just downloaded the sample code I posted and ran it. Then recompiled it and re-ran it. Then changed the helicopter to the UntexturedSphere.fbx file. I never saw anything out of place.
So unfortunately, I don't know what to tell you, except send me the screenshot, or post a link to it here. That's probably the next step.
The reflected cubemap on my sphere looked pinched in the middle as per my first screen shot link (see below).
I got the expeded result as per my second screen shot link (see below) when I changed the following line in the VertexShaderFunction from:
To (note the ".xyz"):
Things that could be contributing to the difference… I'm following along with these tutorials using MacOS with: Xamarin Studio 6.1.2; MonoGame 3.5.1; MonoGame Addin for Xamarin Studio 3.6. So that they'll be OpenGL-compatable my .fx files are using "compile vs_3_0" and "compile ps_3_0" directives (i.e.: Shader Model 3).
First screen shot link, using input.Normal, i681.photobucket.com /albums/vv178/grue2/input.Normal.png
Second screen shot link, instead using input.Normal.xyz, i681.photobucket.com /albums/vv178/grue2/input.Normal.xyz.png
Hello,
I just have a couple of quick remarks.
1) Regarding WorldInverseTranspose: I am not sure the following sentence is correct; did you mean before the transformation, considering the matrix WorldInverseTranspose is used? And by the way, why do we need to do this? Isn’t input.Normal already in absolute coordinates, just like input.Position? I am a little confused.
2) In SkyboxSampler, there is a new parameter called mipfilter; nevertheless, the tutorial gives no explanation about it. I think it would be a good idea. Looking for it, I see a notion of ‘mipmap’, which is new too.
‘The filtering option for combining pixels between two mipmap levels.’
‘MipFilter is used durring autogeneration of mipmaps. It describes the minification filter used to generate lower levels.’
3) I notice there is no image capture in this tutorial, as opposed to the previous ones; I think it would be nice to include one: it would be useful, especially for viewing the page offline (so that you do not have to play the video).
4) The end of the tutorial claims there ‘might’ be refraction and simple glass tutorials, apparently, but are these two lacking from the ‘Effects and HLSL Tutorials’ list? (How unfortunate!)
Once again, thank you for another nice tutorial.
Post preview:
Close preview