From 1e74665abc595d37a6d8f065de9ed6fa4aa711f7 Mon Sep 17 00:00:00 2001 From: Edgaru089 Date: Fri, 25 Feb 2022 21:10:38 +0800 Subject: [PATCH] more fixes to textured transparency --- internal/asset/shader/world/shadowmap.frag | 6 ++++++ internal/asset/shader/world/shadowmap.vert | 3 +++ internal/game/render.go | 3 +++ 3 files changed, 12 insertions(+) diff --git a/internal/asset/shader/world/shadowmap.frag b/internal/asset/shader/world/shadowmap.frag index e5874e3..4d6b957 100644 --- a/internal/asset/shader/world/shadowmap.frag +++ b/internal/asset/shader/world/shadowmap.frag @@ -1,6 +1,12 @@ #version 330 +uniform sampler2D tex; + +in vec2 fragTexCoord; + void main() { + if (texture(tex, fragTexCoord).a < 1e-3) + discard; // gl_FragDepth = gl.FragCoord.z; } diff --git a/internal/asset/shader/world/shadowmap.vert b/internal/asset/shader/world/shadowmap.vert index 96b1eb4..4ddf2c6 100644 --- a/internal/asset/shader/world/shadowmap.vert +++ b/internal/asset/shader/world/shadowmap.vert @@ -8,7 +8,10 @@ layout (location = 1) in vec3 normal; layout (location = 2) in vec2 vertTexCoord; layout (location = 3) in float light; +out vec2 fragTexCoord; + void main() { + fragTexCoord = vertTexCoord; gl_Position = lightspace * model * vec4(vert, 1.0); } diff --git a/internal/game/render.go b/internal/game/render.go index 92392dc..b0a4692 100644 --- a/internal/game/render.go +++ b/internal/game/render.go @@ -351,6 +351,7 @@ func (g *Game) Render(win *glfw.Window) { gl.Viewport(0, 0, int32(ShadowmapSize[0]), int32(ShadowmapSize[1])) gl.BindFramebuffer(gl.FRAMEBUFFER, g.render.depthmap.fbo) gl.Clear(gl.DEPTH_BUFFER_BIT) + gl.Disable(gl.CULL_FACE) lightPos := g.view.EyePos.Add(normalSun.Multiply(50)) lightView := mgl32.LookAt(lightPos[0], lightPos[1], lightPos[2], g.view.EyePos[0], g.view.EyePos[1], g.view.EyePos[2], 0, 1, 0) @@ -361,6 +362,7 @@ func (g *Game) Render(win *glfw.Window) { io.RenderDir = g.view.EyePos.Add(lightPos.Negative()).ToFloat64() g.render.depthmap.shader.UseProgram() + g.render.depthmap.shader.BindTextures() g.render.depthmap.shader.SetUniformMat4("lightspace", lightspace) g.world.Render() @@ -377,6 +379,7 @@ func (g *Game) Render(win *glfw.Window) { gl.BindFramebuffer(gl.FRAMEBUFFER, g.render.gbuffer.fbo) gl.ClearColor(0, 0, 0, 1) gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) + gl.Enable(gl.CULL_FACE) gl.Disable(gl.BLEND) g.render.gbuffer.shader.UseProgram()