Hi,
In my game, I'm using a Double precision system to handle large planetary systems. So positions are stored using a DoubleVector (X, Y and Z are doubles instead of floats) and are then translated to Xna translation matrix for rendering.
I'm using SunBurn to render my planets with a Projection Matrix that is defined using 0.1f as near plane and 10000f as far plane. I then use a scaling algorithm applied to the planet World matrix to ensure that on the fartest distances, the planet is still visible but with the right perspective. I'm doing this because otherwise, I get float precision issues.
Now, I'm also drawing the planet orbits using circles that are rendered using the LineRenderHelper but it is rendered with another Projection Matrix that is scaled to 1f for near plane and 10e9f for far plane to make sure it is rendered at the right location. (the circle vertices are defined based on the orbit center).
Now, my issue is that because I'm using two different Projection Matrixes, the depthbuffers aren't equal and the depth tests do not allow me to make sure that the planet covers the orbit circles.
How would you make sure the two depthbuffers are equal? Setting the Depthbuffer on the GraphicsDevice to the one used by Sunburn doesn't seem to have any effect.
I'll try to post a screenshot later to illustrate my problem.
Thanks,
Philippe
And now, the screenshot to illustrate my issue.
Hi Philippe,
It sounds like the scaling algorithm might be generating a different depth than standard rendering. One solution would be to render the lines with a custom effect using the scaling algorithm.
It's also possible the visible range is so far that the depth is not accurate enough, to test this try rendering a planet directly in front of another to see if they are properly depth sorted.
Let me know if this helps!
Follow me on Twitter – development and personal tweetsAwesome XNA Videos – Lighting, Rendering, and game videos
Thanks John,
I've also thought of another solution that would be easier to maintain:
Do you think it would be possible to create a RenderableMesh or SceneObject based on the VectorColorPosition I have?
I know it will be using the lights setup in the scene but I have to dig into deferred shaders anyway :p
Thanks
Actually that should work great, and is a lot simpler. :)
It should be relatively easy to bypass the scene lighting as you already have a deferred shader for the custom scaling algorithm. For instance create an alternate "final technique" for the lines that does not sample from the lighting buffers and instead just uses the vertex color as the output color.
Hi john,
I really think a tutorial that goes through custom Deferred Effects using SunBurn deferred helper would be very useful, at least for me.
I understood looking at the CustomEffect sample the overall structure of Deferred Effects but maybe you could come up with a few material effects that shows how to use the builtin functions. I really don't know where to start :(
You already have a custom effect to implement the custom scaling (or did you implement it some other way)?
If so you can simply duplicate the "final" pixel shader function (named BlendMapFinalPassPS in the blend.fx example) and replace this code block:
// sample the pre-generated deferred lighting textures - use SunBurn's // multisampling helper function for anti-aliasing (only recommended for // deferred buffers). LightingMRTData data; data.lightingDiffuse = MultiSampleGBuffer(SceneLightingDiffuseSampler, screenuvlinear, screenuvcentroid); data.lightingSpecular = MultiSampleGBuffer(SceneLightingSpecularSampler, screenuvlinear, screenuvcentroid); // unpack the lighting data using SunBurn's helper function. float3 lightingdiffuse = 0.0f; float3 lightingspecular = 0.0f; LoadLightingData(data, lightingdiffuse, lightingspecular);
With something like this:
// set the emissive lighting values. float3 lightingdiffuse = 1.0f; float3 lightingspecular = 0.0f;
Then duplicate the "final" technique and assign its pixel shader property your newly created final function. You can now select the new technique in the SunBurn editor on objects using your shader.