Jump to content
  • Advertisement
Sign in to follow this  
montify

OpenGL Rendering Relative to the Eye Using the GPU

This topic is 2021 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello.

 

I have some float Precision errors with my Procedural Planet (Earth Size)

 

 

So i bought this Book:

 

http://www.amazon.de/3D-Engine-Design-Virtual-Globes/dp/1568817118/ref=sr_1_1?ie=UTF8&qid=1397083732&sr=8-1&keywords=3d+engine+design+for+virtual+globes

 

 

In this book describe a few technique to eliminate the "jittering"

 

 

i choosen Rendering Relative to Eye Using the GPU (Improving Precision with DSFUN90)

 

Here is the C#/OpenGl code from this Book (openSource Code) 

 

https://github.com/virtualglobebook/OpenGlobe/tree/master/Source/Examples/Chapter05/Jitter/GPURelativeToEyeDSFUN90

 
 
So i tried to do this with my Planet, but i get no result.
 
 
I have a ChunkedLOD Quadtree with 1 VertexBuffer(i.e each Patch has the same Vertex/IndexBuffer) only the worldMatrix is different for each Patch.
 
 
Here some Code:
 
 
 private static void DoubleToTwoFloats(double value, out float high, out float low)
        {
            high = (float)value;
            low = (float)(value - high);
        }

        private static void Vector3DToTwoVector3F(Vector3Double value, out Vector3 high, out Vector3 low)
        {
            float highX;
            float highY;
            float highZ;

            float lowX;
            float lowY;
            float lowZ;

            DoubleToTwoFloats(value.X, out highX, out lowX);
            DoubleToTwoFloats(value.Y, out highY, out lowY);
            DoubleToTwoFloats(value.Z, out highZ, out lowZ);

            high = new Vector3(highX, highY, highZ);
            low = new Vector3(lowX, lowY, lowZ);
        }
 


MatrixDouble m = world * cam.View;
                MatrixDouble mv = new MatrixDouble(
                    m.M11, m.M12, m.M13, 0,
                    m.M21, m.M22, m.M23, 0,
                    m.M31, m.M32, m.M33, 0,
                    m.M41, m.M42, m.M43, m.M44); 
    

                //RTC GPU 
                Vector3 eyeHigh;
                Vector3 eyeLow;

                Vector3 posHigh;
                Vector3 posLow;

                Vector3DToTwoVector3F(cam.Position, out eyeHigh, out eyeLow);
                Vector3DToTwoVector3F(position, out posHigh, out posLow);

                //High
                effect.Parameters["positionHigh"].SetValue(posHigh);
                effect.Parameters["u_cameraEyeHigh"].SetValue(eyeHigh);
                //Low
                effect.Parameters["positionLow"].SetValue(posLow);
                effect.Parameters["u_cameraEyeLow"].SetValue(eyeLow);
                effect.Parameters["u_modelViewPerspectiveMatrixRelativeToEye"].SetValue(Manager.ConvertToFloatMatrix(cam.Projection * mv));

The VertexShader look like:

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output;

	/*float3 worldPosition = mul(input.Position, World).xyz;
	float3 normalized = normalize(worldPosition);
	float4 scaled = float4(normalized * SeaLevel, 1);*/


	float3 t1 = positionLow - u_cameraEyeLow;
	float3 e = t1 - positionLow;
	float3 t2 = ((-u_cameraEyeLow - e) + (positionLow - (t1 - e))) + positionHigh - u_cameraEyeHigh;
	float3 highDifference = t1 + t2;
	float3 lowDifference = t2 - (highDifference - t1);


	output.Position = mul(u_modelViewPerspectiveMatrixRelativeToEye, float4(highDifference + lowDifference, 1.0));
	
	
	//output.Position = mul(mul(scaled, View), Projection);

    return output;
}

The CommentLines in the Shader are the Code, that i used befor. (With jittering)

 

 

 

Somebody out there, who can help me ? sad.png

 

 

best regards alex

Share this post


Link to post
Share on other sites
Advertisement

You have to be careful with the order of multiplications. The book uses openTK, an openGL wrapper for .NET, while you are using XNA with directX. In the vertexshader you had previously output.position = mul(<vector>, <matrix>), but now it is mul(<matrix>, <vector>), so you reversed the order. Try changing this and see what happens. There are currently some threads around dealing with the differences, perhaps you should read those to get the clue.

 

Edit:

Here are two links:

 
Edited by majorbrot

Share this post


Link to post
Share on other sites

Thank you for your reply..

 

 

so 

 

when i do in the Shader like this:
 

output.Position = mul( input.Position, WorldViewProj);

eyerything is fine 

 

But when i try to use the RTE method:
 

float3 highDifference = positionHigh - u_cameraEyeHigh;
		float3 lowDifference = positionLow - u_cameraEyeLow;

		float4 x = float4(highDifference + lowDifference, 1.0);

		output.Position = mul( x, WorldViewProj);

i see nothing on the screen :(

 

 

The Matrix:

 MatrixDouble m = world * cam.View;
                MatrixDouble mv = new MatrixDouble(
                    m.M11, m.M12, m.M13, 0,
                    m.M21, m.M22, m.M23, 0,
                    m.M31, m.M32, m.M33, 0,
                    m.M41, m.M42, m.M43, m.M44);

effect.Parameters["WorldViewProj"].SetValue(Manager.ConvertToFloatMatrix(mv *cam.Projection));

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!