From 501037d84d050c11e7f43e47df67c837c6aca5a1 Mon Sep 17 00:00:00 2001 From: Edgaru089 Date: Fri, 25 Feb 2022 17:58:42 +0800 Subject: [PATCH] fix transparency & add glass --- internal/asset/shader/world/geometry.frag | 5 +++-- internal/asset/texture/world/glass.png | Bin 0 -> 147 bytes internal/game/logic.go | 2 +- internal/game/render.go | 1 + internal/world/blocks/default.go | 8 ++++++-- 5 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 internal/asset/texture/world/glass.png diff --git a/internal/asset/shader/world/geometry.frag b/internal/asset/shader/world/geometry.frag index 324b423..a504424 100644 --- a/internal/asset/shader/world/geometry.frag +++ b/internal/asset/shader/world/geometry.frag @@ -17,12 +17,13 @@ const float gamma = 2.2; void main() { + outputColor = texture(tex, fragTexCoord); + if (outputColor.a < 1e-3) + discard; outputPosition.xyz = fragPosWorld; outputPosition.w = fragDepthView; outputNormal.xyz = fragNormal; outputNormal.w = fragPosLightspaceZ; - outputColor = texture(tex, fragTexCoord); - outputColor = vec4(outputColor.rgb, outputColor.a); } diff --git a/internal/asset/texture/world/glass.png b/internal/asset/texture/world/glass.png new file mode 100644 index 0000000000000000000000000000000000000000..7270ac16982135d318c237805b3630655d5b0526 GIT binary patch literal 147 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`QJyZ2Ar_~TcYJvDw7%$L7q|I; z;|2*{US6Ij32WFUBqe;^^>zi@gjZ4`%ns)iuX0Q1DTtQK+j!4pWPacDFp0tPBmd?p vI^qhe)o-(E%;a=wFgRf%;mgzZl9{37|IbHWE!*w_ZDH_q^>bP0l+XkK)-*Am literal 0 HcmV?d00001 diff --git a/internal/game/logic.go b/internal/game/logic.go index b9c1384..0a81f68 100644 --- a/internal/game/logic.go +++ b/internal/game/logic.go @@ -24,7 +24,7 @@ const ( PlayerPlaceCooldown = 200 * time.Millisecond ) -var placeId = [10]int{blocks.Stone, blocks.Dirt, blocks.Grass, blocks.LogOak, blocks.PlanksOak, blocks.LeavesOak, blocks.Debug, blocks.DebugDir, blocks.Bedrock, blocks.Water} +var placeId = [10]int{blocks.Stone, blocks.Dirt, blocks.Grass, blocks.LogOak, blocks.PlanksOak, blocks.LeavesOak, blocks.Glass, blocks.DebugDir, blocks.Bedrock, blocks.Water} var placei = 0 var logs string diff --git a/internal/game/render.go b/internal/game/render.go index febabf6..92392dc 100644 --- a/internal/game/render.go +++ b/internal/game/render.go @@ -129,6 +129,7 @@ func (g *Game) initRender() (err error) { r.texture.GenerateMipMap() gl.BindTexture(gl.TEXTURE_2D, r.texture.Handle()) gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_MAX_ANISOTROPY, maxaf) + r.depthmap.shader.SetUniformTexture("tex", r.texture) r.gbuffer.shader.SetUniformTexture("tex", r.texture) r.water.shader.SetUniformTexture("tex", r.texture) igwrap.SetTextureFlag(r.texture.Handle(), igwrap.TextureFlag_Linear, igwrap.TextureFlag_FlipY) diff --git a/internal/world/blocks/default.go b/internal/world/blocks/default.go index baff876..b6d95b7 100644 --- a/internal/world/blocks/default.go +++ b/internal/world/blocks/default.go @@ -20,6 +20,8 @@ const ( Water + Glass + Count ) @@ -35,13 +37,15 @@ func init() { world.RegisterBlockBehaviour(7, world.BlockBehaviourStatic(world.BlockAppearance{Name: "bedrock"})) world.RegisterBlockBehaviour(8, world.BlockBehaviourStatic(world.BlockAppearance{Name: "sand"})) world.RegisterBlockBehaviour(9, world.BlockBehaviourStatic(world.BlockAppearance{Name: "log_oak", RenderType: world.ThreeTexture})) - world.RegisterBlockBehaviour(10, world.BlockBehaviourStatic(world.BlockAppearance{Name: "leaves_oak"})) + world.RegisterBlockBehaviour(10, world.BlockBehaviourStatic(world.BlockAppearance{Name: "leaves_oak", Transparent: true})) world.RegisterBlockBehaviour(11, world.BlockBehaviourStatic(world.BlockAppearance{Name: "planks_oak"})) world.RegisterBlockBehaviour(12, WaterBehaviour{}) - if Count != 13 { + world.RegisterBlockBehaviour(13, world.BlockBehaviourStatic(world.BlockAppearance{Name: "glass", Transparent: true})) + + if Count != 14 { panic("world.DefaultBlocks: block count not correct (check for block numbering in default_blocks.go)") }