# 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.

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



VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{

/*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 ?

best regards alex

##### Share on other sites

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:

Edited by majorbrot

##### Share on other sites

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


• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 9
• 11
• 15
• 21
• 26