From eb60e7d1792a9a57031e94b15c669a66bbeba930 Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Fri, 1 Dec 2023 23:44:04 -0800 Subject: [PATCH] Usurper materials, do you have any last words? - Pipeline shaders now implement all currently used material properties. - Rename flw_initVertex/flw_initFragment to flw_begin*. - Rename flw_contextVertex/flw_contextFragment to flw_end*. - Bind the diffuse texture by hand instead of calling bindActive. - Add cutout property to materials that need it. --- .../flywheel/backend/MaterialUtil.java | 4 +- .../engine/indirect/IndirectDrawSet.java | 1 - .../flywheel/lib/material/Materials.java | 8 +++ .../flywheel/flywheel/api/fragment.glsl | 4 +- .../flywheel/flywheel/api/material.glsl | 2 + .../assets/flywheel/flywheel/api/vertex.glsl | 4 +- .../flywheel/flywheel/context/crumbling.frag | 20 ++----- .../flywheel/flywheel/context/crumbling.vert | 8 +-- .../flywheel/flywheel/context/world.frag | 31 +---------- .../flywheel/flywheel/context/world.vert | 8 ++- .../internal/indirect/api/fragment.glsl | 4 +- .../internal/indirect/api/vertex.glsl | 4 +- .../flywheel/internal/indirect/draw.frag | 52 +++++++++++++++++- .../flywheel/internal/indirect/draw.vert | 19 ++++++- .../internal/instancing/api/fragment.glsl | 4 +- .../internal/instancing/api/vertex.glsl | 4 +- .../flywheel/internal/instancing/draw.frag | 53 ++++++++++++++++++- .../flywheel/internal/instancing/draw.vert | 20 ++++++- .../flywheel/flywheel/material/shaded.vert | 8 --- 19 files changed, 171 insertions(+), 87 deletions(-) diff --git a/src/main/java/com/jozufozu/flywheel/backend/MaterialUtil.java b/src/main/java/com/jozufozu/flywheel/backend/MaterialUtil.java index 49bb6f116..4b37e8b5e 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/MaterialUtil.java +++ b/src/main/java/com/jozufozu/flywheel/backend/MaterialUtil.java @@ -15,8 +15,10 @@ public class MaterialUtil { AbstractTexture texture = Minecraft.getInstance() .getTextureManager() .getTexture(material.baseTexture()); + var textureId = texture.getId(); texture.setFilter(material.blur(), material.mip()); - RenderSystem.setShaderTexture(0, texture.getId()); + RenderSystem.setShaderTexture(0, textureId); + RenderSystem.bindTexture(textureId); if (!material.backfaceCull()) { RenderSystem.disableCull(); diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectDrawSet.java b/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectDrawSet.java index d7a35519a..8162c7559 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectDrawSet.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/indirect/IndirectDrawSet.java @@ -74,7 +74,6 @@ public class IndirectDrawSet { private record MultiDraw(Material material, int start, int end) { void submit() { MaterialUtil.setup(material); - Textures.bindActiveTextures(); glMultiDrawElementsIndirect(GL_TRIANGLES, GL_UNSIGNED_INT, start * IndirectBuffers.DRAW_COMMAND_STRIDE, end - start, (int) IndirectBuffers.DRAW_COMMAND_STRIDE); MaterialUtil.clear(material); } diff --git a/src/main/java/com/jozufozu/flywheel/lib/material/Materials.java b/src/main/java/com/jozufozu/flywheel/lib/material/Materials.java index 6c313f037..48200aa98 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/material/Materials.java +++ b/src/main/java/com/jozufozu/flywheel/lib/material/Materials.java @@ -1,5 +1,6 @@ package com.jozufozu.flywheel.lib.material; +import com.jozufozu.flywheel.api.material.Cutout; import com.jozufozu.flywheel.api.material.Material; import com.jozufozu.flywheel.api.material.MaterialVertexTransformer; import com.jozufozu.flywheel.api.material.Transparency; @@ -46,6 +47,7 @@ public final class Materials { .baseTexture(InventoryMenu.BLOCK_ATLAS) .mip(true) .shaders(StandardMaterialShaders.SHADED_CUTOUT) + .cutout(Cutout.EPSILON) .fallbackRenderType(RenderType.cutoutMipped()) .vertexTransformer(SHADING_TRANSFORMER) .build(); @@ -54,6 +56,7 @@ public final class Materials { .baseTexture(InventoryMenu.BLOCK_ATLAS) .mip(true) .shaders(StandardMaterialShaders.CUTOUT) + .cutout(Cutout.EPSILON) .fallbackRenderType(RenderType.cutoutMipped()) .build(); @@ -61,6 +64,7 @@ public final class Materials { .baseTexture(InventoryMenu.BLOCK_ATLAS) .mip(false) .shaders(StandardMaterialShaders.SHADED_CUTOUT) + .cutout(Cutout.EPSILON) .fallbackRenderType(RenderType.cutout()) .vertexTransformer(SHADING_TRANSFORMER) .build(); @@ -69,6 +73,7 @@ public final class Materials { .baseTexture(InventoryMenu.BLOCK_ATLAS) .mip(false) .shaders(StandardMaterialShaders.CUTOUT) + .cutout(Cutout.EPSILON) .fallbackRenderType(RenderType.cutout()) .build(); @@ -93,6 +98,7 @@ public final class Materials { .mip(true) .transparency(Transparency.TRANSLUCENT) .shaders(StandardMaterialShaders.SHADED_CUTOUT) + .cutout(Cutout.EPSILON) .fallbackRenderType(RenderType.tripwire()) .vertexTransformer(SHADING_TRANSFORMER) .build(); @@ -102,6 +108,7 @@ public final class Materials { .mip(true) .transparency(Transparency.TRANSLUCENT) .shaders(StandardMaterialShaders.CUTOUT) + .cutout(Cutout.EPSILON) .fallbackRenderType(RenderType.tripwire()) .build(); @@ -116,6 +123,7 @@ public final class Materials { .mip(false) .backfaceCull(false) .shaders(StandardMaterialShaders.SHADED_CUTOUT) + .cutout(Cutout.EPSILON) .fallbackRenderType(Sheets.shulkerBoxSheet()) .build(); public static final Material BELL = SimpleMaterial.builder() diff --git a/src/main/resources/assets/flywheel/flywheel/api/fragment.glsl b/src/main/resources/assets/flywheel/flywheel/api/fragment.glsl index 586d9650b..07ba92e78 100644 --- a/src/main/resources/assets/flywheel/flywheel/api/fragment.glsl +++ b/src/main/resources/assets/flywheel/flywheel/api/fragment.glsl @@ -28,5 +28,5 @@ bool flw_discardPredicate(vec4 finalColor); void flw_materialFragment(); // To be implemented by the context shader. -void flw_initFragment(); -void flw_contextFragment(); +void flw_beginFragment(); +void flw_endFragment(); diff --git a/src/main/resources/assets/flywheel/flywheel/api/material.glsl b/src/main/resources/assets/flywheel/flywheel/api/material.glsl index bd338d490..fd9b0f455 100644 --- a/src/main/resources/assets/flywheel/flywheel/api/material.glsl +++ b/src/main/resources/assets/flywheel/flywheel/api/material.glsl @@ -1,6 +1,7 @@ const uint FLW_FOG_LINEAR = 0u; const uint FLW_FOG_LINEAR_FADE = 1u; const uint FLW_FOG_NONE = 2u; +const uint FLW_FOG_CUSTOM = 3u; const uint FLW_TRANSPARENCY_OPAQUE = 0u; const uint FLW_TRANSPARENCY_ADDITIVE = 1u; @@ -12,6 +13,7 @@ const uint FLW_TRANSPARENCY_TRANSLUCENT = 5u; const uint FLW_CUTOUT_OFF = 0u; const uint FLW_CUTOUT_EPSILON = 1u; const uint FLW_CUTOUT_HALF = 2u; +const uint FLW_CUTOUT_CUSTOM = 3u; const uint FLW_WRITE_MASK_BOTH = 0u; const uint FLW_WRITE_MASK_COLOR = 1u; diff --git a/src/main/resources/assets/flywheel/flywheel/api/vertex.glsl b/src/main/resources/assets/flywheel/flywheel/api/vertex.glsl index fc3924c01..8e944eec3 100644 --- a/src/main/resources/assets/flywheel/flywheel/api/vertex.glsl +++ b/src/main/resources/assets/flywheel/flywheel/api/vertex.glsl @@ -27,5 +27,5 @@ void flw_instanceVertex(FlwInstance i); void flw_materialVertex(); // To be implemented by the context shader. -void flw_initVertex(); -void flw_contextVertex(); +void flw_beginVertex(); +void flw_endVertex(); diff --git a/src/main/resources/assets/flywheel/flywheel/context/crumbling.frag b/src/main/resources/assets/flywheel/flywheel/context/crumbling.frag index a85abf204..bb8ffc68b 100644 --- a/src/main/resources/assets/flywheel/flywheel/context/crumbling.frag +++ b/src/main/resources/assets/flywheel/flywheel/context/crumbling.frag @@ -1,24 +1,13 @@ #include "flywheel:api/fragment.glsl" -// optimize discard usage -#ifdef ALPHA_DISCARD -#ifdef GL_ARB_conservative_depth -layout (depth_greater) out float gl_FragDepth; -#endif -#endif - -uniform sampler2D flw_diffuseTex; uniform sampler2D flw_crumblingTex; in vec2 _flw_crumblingTexCoord; -out vec4 fragColor; - vec4 flw_crumblingSampleColor; -void flw_initFragment() { +void flw_beginFragment() { flw_crumblingSampleColor = texture(flw_crumblingTex, _flw_crumblingTexCoord); - flw_sampleColor = texture(flw_diffuseTex, flw_vertexTexCoord); // Let the other components modify the diffuse color as they normally would. flw_fragColor = flw_vertexColor * flw_sampleColor; @@ -26,13 +15,10 @@ void flw_initFragment() { flw_fragLight = flw_vertexLight; } -void flw_contextFragment() { - vec4 color = flw_fragColor; - +void flw_endFragment() { // Still need to discard based on the diffuse color so we don't crumble over empty space. - if (flw_discardPredicate(color) || flw_crumblingSampleColor.a < 0.01) { + if (flw_crumblingSampleColor.a < 0.01) { discard; } - fragColor = flw_fogFilter(flw_crumblingSampleColor); } diff --git a/src/main/resources/assets/flywheel/flywheel/context/crumbling.vert b/src/main/resources/assets/flywheel/flywheel/context/crumbling.vert index 2767c2b1a..68a7bb435 100644 --- a/src/main/resources/assets/flywheel/flywheel/context/crumbling.vert +++ b/src/main/resources/assets/flywheel/flywheel/context/crumbling.vert @@ -65,14 +65,10 @@ vec2 getCrumblingTexCoord() { return vec2(-flw_vertexPos.x, -flw_vertexPos.y); } -void flw_initVertex() { +void flw_beginVertex() { // no-op } -void flw_contextVertex() { +void flw_endVertex() { _flw_crumblingTexCoord = getCrumblingTexCoord(); - - flw_distance = fog_distance(flw_vertexPos.xyz, flywheel.cameraPos.xyz, flywheel.fogShape); - gl_Position = flywheel.viewProjection * flw_vertexPos; - flw_vertexNormal = normalize(flw_vertexNormal); } diff --git a/src/main/resources/assets/flywheel/flywheel/context/world.frag b/src/main/resources/assets/flywheel/flywheel/context/world.frag index 951ad85b0..ae85806e7 100644 --- a/src/main/resources/assets/flywheel/flywheel/context/world.frag +++ b/src/main/resources/assets/flywheel/flywheel/context/world.frag @@ -1,36 +1,9 @@ #include "flywheel:api/fragment.glsl" -// optimize discard usage -#ifdef ALPHA_DISCARD -#ifdef GL_ARB_conservative_depth -layout (depth_greater) out float gl_FragDepth; -#endif -#endif +void flw_beginFragment() { -uniform sampler2D flw_diffuseTex; -uniform sampler2D flw_overlayTex; -uniform sampler2D flw_lightTex; - -out vec4 fragColor; - -void flw_initFragment() { - flw_sampleColor = texture(flw_diffuseTex, flw_vertexTexCoord); - flw_fragColor = flw_vertexColor * flw_sampleColor; - flw_fragOverlay = flw_vertexOverlay; - flw_fragLight = flw_vertexLight; } -void flw_contextFragment() { - vec4 overlayColor = texelFetch(flw_overlayTex, flw_fragOverlay, 0); - vec4 lightColor = texture(flw_lightTex, (flw_fragLight * 15.0 + 0.5) / 16.0); +void flw_endFragment() { - vec4 color = flw_fragColor; - color.rgb = mix(overlayColor.rgb, color.rgb, overlayColor.a); - color *= lightColor; - - if (flw_discardPredicate(color)) { - discard; - } - - fragColor = flw_fogFilter(color); } diff --git a/src/main/resources/assets/flywheel/flywheel/context/world.vert b/src/main/resources/assets/flywheel/flywheel/context/world.vert index e6f413cb8..e27fe3fab 100644 --- a/src/main/resources/assets/flywheel/flywheel/context/world.vert +++ b/src/main/resources/assets/flywheel/flywheel/context/world.vert @@ -1,12 +1,10 @@ #include "flywheel:api/vertex.glsl" #include "flywheel:util/fog.glsl" -void flw_initVertex() { +void flw_beginVertex() { // noop } -void flw_contextVertex() { - flw_distance = fog_distance(flw_vertexPos.xyz, flywheel.cameraPos.xyz, flywheel.fogShape); - gl_Position = flywheel.viewProjection * flw_vertexPos; - flw_vertexNormal = normalize(flw_vertexNormal); +void flw_endVertex() { + } diff --git a/src/main/resources/assets/flywheel/flywheel/internal/indirect/api/fragment.glsl b/src/main/resources/assets/flywheel/flywheel/internal/indirect/api/fragment.glsl index 45573db55..0eaa0a153 100644 --- a/src/main/resources/assets/flywheel/flywheel/internal/indirect/api/fragment.glsl +++ b/src/main/resources/assets/flywheel/flywheel/internal/indirect/api/fragment.glsl @@ -29,9 +29,9 @@ vec4 flw_fogFilter(vec4 color); bool flw_discardPredicate(vec4 finalColor); -void flw_initFragment(); +void flw_beginFragment(); void flw_materialFragment(); -void flw_contextFragment(); +void flw_endFragment(); // ------------------------------------------ // INTERNAL diff --git a/src/main/resources/assets/flywheel/flywheel/internal/indirect/api/vertex.glsl b/src/main/resources/assets/flywheel/flywheel/internal/indirect/api/vertex.glsl index e1dc35403..833410b58 100644 --- a/src/main/resources/assets/flywheel/flywheel/internal/indirect/api/vertex.glsl +++ b/src/main/resources/assets/flywheel/flywheel/internal/indirect/api/vertex.glsl @@ -20,10 +20,10 @@ out vec4 flw_var3; FlwMaterial flw_material; void flw_layoutVertex(); -void flw_initVertex(); +void flw_beginVertex(); void flw_instanceVertex(FlwInstance i); void flw_materialVertex(); -void flw_contextVertex(); +void flw_endVertex(); // ------------------------------------------ // INTERNAL diff --git a/src/main/resources/assets/flywheel/flywheel/internal/indirect/draw.frag b/src/main/resources/assets/flywheel/flywheel/internal/indirect/draw.frag index 8a6f93d99..81a1a3074 100644 --- a/src/main/resources/assets/flywheel/flywheel/internal/indirect/draw.frag +++ b/src/main/resources/assets/flywheel/flywheel/internal/indirect/draw.frag @@ -1,14 +1,62 @@ #include "flywheel:internal/indirect/api/fragment.glsl" #include "flywheel:internal/material.glsl" +// optimize discard usage +#ifdef ALPHA_DISCARD +#ifdef GL_ARB_conservative_depth +layout (depth_greater) out float gl_FragDepth; +#endif +#endif + +uniform sampler2D flw_diffuseTex; +uniform sampler2D flw_overlayTex; +uniform sampler2D flw_lightTex; + flat in uvec2 _flw_material; +out vec4 fragColor; + void main() { _flw_materialFragmentID = _flw_material.x; _flw_unpackMaterial(_flw_material.y, flw_material); - flw_initFragment(); + flw_sampleColor = texture(flw_diffuseTex, flw_vertexTexCoord); + flw_fragColor = flw_vertexColor * flw_sampleColor; + flw_fragOverlay = flw_vertexOverlay; + flw_fragLight = flw_vertexLight; + + flw_beginFragment(); flw_materialFragment(); - flw_contextFragment(); + flw_endFragment(); + + vec4 overlayColor = texelFetch(flw_overlayTex, flw_fragOverlay, 0); + vec4 lightColor = texture(flw_lightTex, (flw_fragLight * 15.0 + 0.5) / 16.0); + + vec4 color = flw_fragColor; + color.rgb = mix(overlayColor.rgb, color.rgb, overlayColor.a); + + if (flw_material.lighting) { + color *= lightColor; + } + + if (flw_material.cutout == FLW_CUTOUT_EPSILON && color.a < 0.01) { + discard; + } else if (flw_material.cutout == FLW_CUTOUT_HALF && color.a < 0.5) { + discard; + } else if (flw_material.cutout == FLW_CUTOUT_CUSTOM) { + if (flw_discardPredicate(color)) { + discard; + } + } + + if (flw_material.fog == FLW_FOG_LINEAR) { + color = linear_fog(color, flw_distance, flywheel.fogRange.x, flywheel.fogRange.y, flywheel.fogColor); + } else if (flw_material.fog == FLW_FOG_LINEAR_FADE) { + color = linear_fog_fade(color, flw_distance, flywheel.fogRange.x, flywheel.fogRange.y); + } else if (flw_material.fog == FLW_FOG_CUSTOM) { + color = flw_fogFilter(color); + } + + fragColor = color; } diff --git a/src/main/resources/assets/flywheel/flywheel/internal/indirect/draw.vert b/src/main/resources/assets/flywheel/flywheel/internal/indirect/draw.vert index 1abe66d1f..36e9c35c5 100644 --- a/src/main/resources/assets/flywheel/flywheel/internal/indirect/draw.vert +++ b/src/main/resources/assets/flywheel/flywheel/internal/indirect/draw.vert @@ -34,8 +34,23 @@ void main() { _flw_material = uvec2(_flw_materialFragmentID, p); flw_layoutVertex(); - flw_initVertex(); + flw_beginVertex(); flw_instanceVertex(i); flw_materialVertex(); - flw_contextVertex(); + flw_endVertex(); + + flw_vertexNormal = normalize(flw_vertexNormal); + + if (flw_material.diffuse) { + float diffuseFactor; + if (flywheel.constantAmbientLight == 1) { + diffuseFactor = diffuseNether(flw_vertexNormal); + } else { + diffuseFactor = diffuse(flw_vertexNormal); + } + flw_vertexColor = vec4(flw_vertexColor.rgb * diffuseFactor, flw_vertexColor.a); + } + + flw_distance = fog_distance(flw_vertexPos.xyz, flywheel.cameraPos.xyz, flywheel.fogShape); + gl_Position = flywheel.viewProjection * flw_vertexPos; } diff --git a/src/main/resources/assets/flywheel/flywheel/internal/instancing/api/fragment.glsl b/src/main/resources/assets/flywheel/flywheel/internal/instancing/api/fragment.glsl index 6efbbabb9..3da9b596e 100644 --- a/src/main/resources/assets/flywheel/flywheel/internal/instancing/api/fragment.glsl +++ b/src/main/resources/assets/flywheel/flywheel/internal/instancing/api/fragment.glsl @@ -28,9 +28,9 @@ vec4 flw_fogFilter(vec4 color); bool flw_discardPredicate(vec4 finalColor); -void flw_initFragment(); +void flw_beginFragment(); void flw_materialFragment(); -void flw_contextFragment(); +void flw_endFragment(); // ----------------------------------------- // INTERNAL diff --git a/src/main/resources/assets/flywheel/flywheel/internal/instancing/api/vertex.glsl b/src/main/resources/assets/flywheel/flywheel/internal/instancing/api/vertex.glsl index 32749d0ba..eab3098f4 100644 --- a/src/main/resources/assets/flywheel/flywheel/internal/instancing/api/vertex.glsl +++ b/src/main/resources/assets/flywheel/flywheel/internal/instancing/api/vertex.glsl @@ -19,10 +19,10 @@ out vec4 flw_var3; FlwMaterial flw_material; void flw_layoutVertex(); -void flw_initVertex(); +void flw_beginVertex(); void flw_instanceVertex(FlwInstance i); void flw_materialVertex(); -void flw_contextVertex(); +void flw_endVertex(); // ------------------------------------ // INTERNAL diff --git a/src/main/resources/assets/flywheel/flywheel/internal/instancing/draw.frag b/src/main/resources/assets/flywheel/flywheel/internal/instancing/draw.frag index 4e7d38e91..bca858c65 100644 --- a/src/main/resources/assets/flywheel/flywheel/internal/instancing/draw.frag +++ b/src/main/resources/assets/flywheel/flywheel/internal/instancing/draw.frag @@ -1,5 +1,19 @@ #include "flywheel:internal/instancing/api/fragment.glsl" #include "flywheel:internal/material.glsl" +#include "flywheel:util/fog.glsl" + +// optimize discard usage +#ifdef ALPHA_DISCARD +#ifdef GL_ARB_conservative_depth +layout (depth_greater) out float gl_FragDepth; +#endif +#endif + +uniform sampler2D flw_diffuseTex; +uniform sampler2D flw_overlayTex; +uniform sampler2D flw_lightTex; + +out vec4 fragColor; void main() { _flw_materialVertexID = _flw_material_instancing.x; @@ -7,7 +21,42 @@ void main() { _flw_unpackMaterial(_flw_material_instancing.z, flw_material); - flw_initFragment(); + flw_sampleColor = texture(flw_diffuseTex, flw_vertexTexCoord); + flw_fragColor = flw_vertexColor * flw_sampleColor; + flw_fragOverlay = flw_vertexOverlay; + flw_fragLight = flw_vertexLight; + + flw_beginFragment(); flw_materialFragment(); - flw_contextFragment(); + flw_endFragment(); + + vec4 overlayColor = texelFetch(flw_overlayTex, flw_fragOverlay, 0); + vec4 lightColor = texture(flw_lightTex, (flw_fragLight * 15.0 + 0.5) / 16.0); + + vec4 color = flw_fragColor; + color.rgb = mix(overlayColor.rgb, color.rgb, overlayColor.a); + + if (flw_material.lighting) { + color *= lightColor; + } + + if (flw_material.cutout == FLW_CUTOUT_EPSILON && color.a < 0.01) { + discard; + } else if (flw_material.cutout == FLW_CUTOUT_HALF && color.a < 0.5) { + discard; + } else if (flw_material.cutout == FLW_CUTOUT_CUSTOM) { + if (flw_discardPredicate(color)) { + discard; + } + } + + if (flw_material.fog == FLW_FOG_LINEAR) { + color = linear_fog(color, flw_distance, flywheel.fogRange.x, flywheel.fogRange.y, flywheel.fogColor); + } else if (flw_material.fog == FLW_FOG_LINEAR_FADE) { + color = linear_fog_fade(color, flw_distance, flywheel.fogRange.x, flywheel.fogRange.y); + } else if (flw_material.fog == FLW_FOG_CUSTOM) { + color = flw_fogFilter(color); + } + + fragColor = color; } diff --git a/src/main/resources/assets/flywheel/flywheel/internal/instancing/draw.vert b/src/main/resources/assets/flywheel/flywheel/internal/instancing/draw.vert index 2290a60fd..46ab9efb4 100644 --- a/src/main/resources/assets/flywheel/flywheel/internal/instancing/draw.vert +++ b/src/main/resources/assets/flywheel/flywheel/internal/instancing/draw.vert @@ -1,5 +1,6 @@ #include "flywheel:internal/instancing/api/vertex.glsl" #include "flywheel:internal/material.glsl" +#include "flywheel:util/diffuse.glsl" void main() { _flw_materialVertexID = _flw_material_instancing.x; @@ -10,8 +11,23 @@ void main() { FlwInstance i = _flw_unpackInstance(); flw_layoutVertex(); - flw_initVertex(); + flw_beginVertex(); flw_instanceVertex(i); flw_materialVertex(); - flw_contextVertex(); + flw_endVertex(); + + flw_vertexNormal = normalize(flw_vertexNormal); + + if (flw_material.diffuse) { + float diffuseFactor; + if (flywheel.constantAmbientLight == 1) { + diffuseFactor = diffuseNether(flw_vertexNormal); + } else { + diffuseFactor = diffuse(flw_vertexNormal); + } + flw_vertexColor = vec4(flw_vertexColor.rgb * diffuseFactor, flw_vertexColor.a); + } + + flw_distance = fog_distance(flw_vertexPos.xyz, flywheel.cameraPos.xyz, flywheel.fogShape); + gl_Position = flywheel.viewProjection * flw_vertexPos; } diff --git a/src/main/resources/assets/flywheel/flywheel/material/shaded.vert b/src/main/resources/assets/flywheel/flywheel/material/shaded.vert index 979e923ac..e25e78371 100644 --- a/src/main/resources/assets/flywheel/flywheel/material/shaded.vert +++ b/src/main/resources/assets/flywheel/flywheel/material/shaded.vert @@ -2,13 +2,5 @@ #include "flywheel:util/diffuse.glsl" void flw_materialVertex() { - flw_vertexNormal = normalize(flw_vertexNormal); - float diffuseFactor; - if (flywheel.constantAmbientLight == 1) { - diffuseFactor = diffuseNether(flw_vertexNormal); - } else { - diffuseFactor = diffuse(flw_vertexNormal); - } - flw_vertexColor = vec4(flw_vertexColor.rgb * diffuseFactor, flw_vertexColor.a); }