Jump to content

  • Log In with Google      Sign In   
  • Create Account

Rendering Relative to the Eye Using the GPU


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 montify   Members   -  Reputation: 390

Like
0Likes
Like

Posted 09 April 2014 - 04:58 PM

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



Sponsor:

#2 majorbrot   Members   -  Reputation: 571

Like
1Likes
Like

Posted 10 April 2014 - 01:29 AM

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, 10 April 2014 - 01:38 AM.


#3 montify   Members   -  Reputation: 390

Like
0Likes
Like

Posted 10 April 2014 - 04:13 AM

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));





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS