Facepunch / garrysmod-issues

Garry's Mod issue tracker
143 stars 56 forks source link

Water does not render in Orthographic view; both render.RenderView and CalcView. #5085

Open Pugsworth opened 2 years ago

Pugsworth commented 2 years ago

Details

Steps to reproduce

Simply run this code on any map with water (gm_construct for example).

hook.Add("CalcView", "waterbug", function(ply, pos, angles, fov)
    return {
        znear = 1,
        zfar = 32768,
        ortho = {
            left   = -ScrW(),
            right  = ScrW(),
            top    = -ScrH(),
            bottom = ScrH()
        }
    }
end)

I couldn't really find if this was a known bug already or if there was a fix for it.

jorjic commented 2 years ago

You can see it rendering if you look at it the wrong way, only when that part of the screen should be occluded.

image

I expect the problem to happen near here. Maybe it was fixed somewhere in this massive commit. Can you try to reproduce this on other maps? Does TF2 have this problem? Does CS:GO? If there's a Source game that fixed this, maybe it can be ported.

You could try working around it by using render targets, stencils, and clipping planes. mat_showwatertextures displays the intermediate textures used to draw water surface reflection. The shader code is in the public Source SDK 2013 base, so you can check that to get a better understanding of how it works, but it's surprisingly simple.

Pugsworth commented 2 years ago

You can see it rendering if you look at it the wrong way, only when that part of the screen should be occluded.

I expect the problem to happen near here. Maybe it was fixed somewhere in this massive commit. Can you try to reproduce this on other maps? Does TF2 have this problem? Does CS:GO? If there's a Source game that fixed this, maybe it can be ported.

You could try working around it by using render targets, stencils, and clipping planes. mat_showwatertextures displays the intermediate textures used to draw water surface reflection. The shader code is in the public Source SDK 2013 base, so you can check that to get a better understanding of how it works, but it's surprisingly simple.

Oh interesting. It's almost like the depth sorting gets broken. I will have to play with trying to render just the water in orthographic and overlaying that on top.

It is a problem in every single map I've tried, so there's that.

Something to note, too; camortho causes the exact same effect. I'll have to try it in other games/engine branches to see if Valve ever fixed it.

jorjic commented 2 years ago

Oh interesting. It's almost like the depth sorting gets broken.

I think it's something like this.

Something to note, too; camortho causes the exact same effect. I'll have to try it in other games/engine branches to see if Valve ever fixed it.

I tested TF2 and it was affected. I did not try CSGO because camortho is not present. I think Valve never fixed it.

jorjic commented 2 years ago

Setting mat_dxlevel below 90 will default to a different water shader, which will work in orthographic rendering. This might be a problem in the shader (and here). The water shaders for DX9 and DX8 are different formats, and I'm not familiar with either of them. They're included in Source SDK, so it's possible to download and compile them and test changes.