• 9
• 9
• 11
• 12
• 9
• ### Similar Content

• Hello guys,

How do I know? Why does wavefront not show for me?
I already checked I have non errors yet.

And my download (mega.nz) should it is original but I tried no success...
- Add blend source and png file here I have tried tried,.....

PS: Why is our community not active? I wait very longer. Stop to lie me!
Thanks !

• I wasn't sure if this would be the right place for a topic like this so sorry if it isn't.
I'm currently working on a project for Uni using FreeGLUT to make a simple solar system simulation. I've got to the point where I've implemented all the planets and have used a Scene Graph to link them all together. The issue I'm having with now though is basically the planets and moons orbit correctly at their own orbit speeds.
I'm not really experienced with using matrices for stuff like this so It's likely why I can't figure out how exactly to get it working. This is where I'm applying the transformation matrices, as well as pushing and popping them. This is within the Render function that every planet including the sun and moons will have and run.
if (tag != "Sun") { glRotatef(orbitAngle, orbitRotation.X, orbitRotation.Y, orbitRotation.Z); } glPushMatrix(); glTranslatef(position.X, position.Y, position.Z); glRotatef(rotationAngle, rotation.X, rotation.Y, rotation.Z); glScalef(scale.X, scale.Y, scale.Z); glDrawElements(GL_TRIANGLES, mesh->indiceCount, GL_UNSIGNED_SHORT, mesh->indices); if (tag != "Sun") { glPopMatrix(); } The "If(tag != "Sun")" parts are my attempts are getting the planets to orbit correctly though it likely isn't the way I'm meant to be doing it. So I was wondering if someone would be able to help me? As I really don't have an idea on what I would do to get it working. Using the if statement is truthfully the closest I've got to it working but there are still weird effects like the planets orbiting faster then they should depending on the number of planets actually be updated/rendered.

• Hello everyone,
I have problem with texture

• Hello everyone
For @80bserver8 nice job - I have found Google search. How did you port from Javascript WebGL to C# OpenTK.?
I have been searched Google but it shows f***ing Unity 3D. I really want know how do I understand I want start with OpenTK But I want know where is porting of Javascript and C#?

Thanks!
• By mike44
Hi
I draw in a OpenGL framebuffer. All is fine but it eats FPS (frames per second), hence I wonder if I could execute the framebuffer drawing only every 5-10th loop or so?
Many thanks

# OpenGL Odd fragment shader depth output behavior? (Manual perspective division)

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

## Recommended Posts

I'm trying to implement shadow mapping with Vulkan. The rendering for the actual shadow map works fine, however in my scene shader, I need to do manual perspective division (Since gl_Position is already in use) to transform the scene depth values to light space (To be able to compare them with the samples from the shadow map), which produces weird results.

So I ended up doing some tests, and I've noticed very weird behavior with depth values in general.

Here are some example cases:

#1

If I use the default fragment shader (Implicit depth output), the depth values are written correctly.

void main()
{
gl_Position = MVP *vec4(vertexPosition,1.0);
}


void main()
{} // Also works with gl_FragDepth = gl_FragCoord.z;


Result (Everything is as expected):

(Depth values are linearized in post-processing to make them more clearly visible.)

#2

This case is an odd one which I've stumbled upon by accident. If I have any reference to gl_FragDepth anywhere in the fragment shader, the resulting depth values change for no apparant reason:

void main()
{
gl_Position = MVP *vec4(vertexPosition,1.0);
}


void main()
{
float d = gl_FragDepth;
} 

According to the OpenGL Docs, "If depth buffering is enabled and no shader writes to gl_FragDepth, then the fixed function value for depth will be used[...]", I'm assuming this also applies when using Vulkan(?). Obviously gl_FragDepth is not being written to here, and yet the result is different than case #1:

(Values are very close to 0, but don't quite reach 0.)

#3 Manual perspective division

If I don't use the default perspective division, and attempt to do it manually, only about half of the depth values for the geometry are being written.

void main()
{
gl_Position = MVP *vec4(vertexPosition,1.0);
gl_Position.xyz /= gl_Position.w;
gl_Position.w = 1.0;
}


void main()
{}


Result:

#4 Writing depth value manually

Attempting to calculate and pass the depth value to the fragment shader manually has similar results to case #3.

out float test_depth;

void main()
{
gl_Position = MVP *vec4(vertexPosition,1.0);
test_depth = gl_Position.z /gl_Position.w;
}



#version 320

in float test_depth;

void main()
{
gl_FragDepth = test_depth;
}



Result:

The depth range for the viewport is set to [0,1], in case that could make a difference. I'm using a 32bit floating point depth format, so precision shouldn't be a problem.

I have the latest AMD beta Vulkan drivers installed, and I'm using Vulkan 1.0.8.0.

Can someone explain this to me?

What's the 'proper' way of doing perspective division manually with Vulkan (i.e. replicating the default behavior manually)?

Edited by Silverlan