Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add another VBO for selected aircraft to draw them after water #3965

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Beherith
Copy link
Collaborator

Work done

Aircraft, due to often being much higher up in Z, are now drawn in DrawWorld instead of DrawWorldPreUnit to prevent water distortion from affecting them. Note that this causes subtle other rendering problems later, but meh.

BEFORE:

AFTER:

image

@bcdrme pls

@bcdrme
Copy link

bcdrme commented Nov 23, 2024

Can confirm this works as expected.

@saurtron
Copy link
Contributor

saurtron commented Nov 24, 2024

I tested it and works, but I see you say the depth test seems not to work, but if you add PolygonOffset you can see it actually affects the lines.

line 136

                 selectShader:SetUniform("iconDistance", 99999) -- pass
+                gl.PolygonOffset( 150 , 150 )

line 161

                glTexture(0, false)
+               gl.PolygonOffset(false)

offset

Just set 150, 150 so seemed to have some effect btw, no idea how that works :D

@Beherith
Copy link
Collaborator Author

I tested it and works, but I see you say the depth test seems not to work, but if you add PolygonOffset you can see it actually affects the lines.

What I meant is that depth test in the DrawWorldPreUnit pass does not seem to work. As terrian does not occlude selection circles (which I am OK with)

@saurtron
Copy link
Contributor

saurtron commented Nov 24, 2024

What I meant is that depth test in the DrawWorldPreUnit pass does not seem to work. As terrian does not occlude selection circles (which I am OK with)

Right, the gl.DepthFunc must have been set to something special, trying gl.DepthTest(GL.LEQUAL) makes them occlude. I think it also has DepthMask disabled.

@saurtron
Copy link
Contributor

saurtron commented Nov 24, 2024

Anyways, don't you think the fact with this PR selection draw on top of the air units is a problem?

I believe selection should be drawn below units. With DrawWorldPreUnit they get drawn before units, so the selection can be drawn without really checking the depth buffer or even writing to it. With DrawWorld this can't be done, so air unit wings, at least with figs, go below the selection that looks a bit weird imo. Ie, like the "no offset" image above.

I think PolygonOffset, or maybe something like gl_FragDepth = gl_FragCoord.z+0.6*gl_FragCoord.w; inside the fragment shader can help in offsetting, so the selection looks more proper with the air units.

Regarding PolygonOffset I'm not sure what's the right values to pass, with the shader I'm also not sure if that's the right way to offset the depth fragment, but testing that seems to give a good balance of drawing selection below wings but also looking ok when looking at air units from the front. With this it can look more like the "offset" image that imo is better if you can manage to get the right parameters.

@Beherith
Copy link
Collaborator Author

Polygonoffset is considered deprecated, note how the lua api now has a ZPULL define for this exact role. Ty for the depthtest tip though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants