beyond-all-reason / Beyond-All-Reason

Main game repository for Beyond All Reason.
https://www.beyondallreason.info/
Other
1.8k stars 300 forks source link

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

Open Beherith opened 2 days ago

Beherith commented 2 days ago

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 commented 2 days ago

Can confirm this works as expected.

saurtron commented 1 day ago

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 commented 1 day ago

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 commented 1 day ago

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 commented 1 day ago

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 commented 12 hours ago

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