diff --git a/build.gradle b/build.gradle index 8fb00dfa5..9ba452e8f 100644 --- a/build.gradle +++ b/build.gradle @@ -122,6 +122,14 @@ mixin { debug.export = true } +idea { + // Tell IDEA to always download sources/javadoc artifacts from maven. + module { + downloadJavadoc = true + downloadSources = true + } +} + // Workaround for SpongePowered/MixinGradle#38 afterEvaluate { tasks.configureReobfTaskForReobfJar.mustRunAfter(tasks.compileJava) diff --git a/docs/shader-api/fragment.glsl b/docs/shader-api/fragment.glsl index 659f788a0..95107cf4d 100644 --- a/docs/shader-api/fragment.glsl +++ b/docs/shader-api/fragment.glsl @@ -13,14 +13,19 @@ /*const*/ float flw_distance; +/*const*/ bool flw_vertexDiffuse; + +bool flw_fragDiffuse; vec4 flw_fragColor; ivec2 flw_fragOverlay; vec2 flw_fragLight; // To be implemented by the material fragment shader. -vec4 flw_fogFilter(vec4 color); -bool flw_discardPredicate(vec4 finalColor); void flw_materialFragment(); +// To be implement by fog shaders. +vec4 flw_fogFilter(vec4 color); +// To be implemented by discard shaders. +bool flw_discardPredicate(vec4 finalColor); // To be implemented by the context shader. void flw_beginFragment(); diff --git a/docs/shader-api/vertex.glsl b/docs/shader-api/vertex.glsl index 6601e8da0..169ade9ba 100644 --- a/docs/shader-api/vertex.glsl +++ b/docs/shader-api/vertex.glsl @@ -7,12 +7,16 @@ ivec2 flw_vertexOverlay; vec2 flw_vertexLight; vec3 flw_vertexNormal; +bool flw_vertexDiffuse; + /*const*/ FlwMaterial flw_material; // To be implemented by the instance shader. -void flw_transformBoundingSphere(in FlwInstance i, inout vec3 center, inout float radius); void flw_instanceVertex(FlwInstance i); +// To be implemented by the instance cull shader. +void flw_transformBoundingSphere(in FlwInstance i, inout vec3 center, inout float radius); + // To be implemented by the material vertex shader. void flw_materialVertex(); diff --git a/src/main/resources/assets/flywheel/flywheel/internal/common.frag b/src/main/resources/assets/flywheel/flywheel/internal/common.frag new file mode 100644 index 000000000..8016b7691 --- /dev/null +++ b/src/main/resources/assets/flywheel/flywheel/internal/common.frag @@ -0,0 +1,57 @@ +#include "flywheel:internal/packed_material.glsl" +#include "flywheel:internal/diffuse.glsl" + +// optimize discard usage +#ifdef GL_ARB_conservative_depth +layout (depth_greater) out float gl_FragDepth; +#endif + +uniform sampler2D _flw_diffuseTex; +uniform sampler2D _flw_overlayTex; +uniform sampler2D _flw_lightTex; + +flat in uint _flw_vertexDiffuse; + +out vec4 _flw_outputColor; + +void _flw_main() { + flw_sampleColor = texture(_flw_diffuseTex, flw_vertexTexCoord); + flw_fragColor = flw_vertexColor * flw_sampleColor; + flw_fragOverlay = flw_vertexOverlay; + flw_fragLight = flw_vertexLight; + + flw_vertexDiffuse = bool(_flw_vertexDiffuse); + flw_fragDiffuse = flw_vertexDiffuse; + + flw_beginFragment(); + flw_materialFragment(); + flw_endFragment(); + + vec4 color = flw_fragColor; + + if (flw_fragDiffuse) { + float diffuseFactor; + if (flywheel.constantAmbientLight == 1) { + diffuseFactor = diffuseNether(flw_vertexNormal); + } else { + diffuseFactor = diffuse(flw_vertexNormal); + } + color.rgb *= diffuseFactor; + } + + if (flw_material.useOverlay) { + vec4 overlayColor = texelFetch(_flw_overlayTex, flw_fragOverlay, 0); + color.rgb = mix(overlayColor.rgb, color.rgb, overlayColor.a); + } + + if (flw_material.useLight) { + vec4 lightColor = texture(_flw_lightTex, (flw_fragLight * 15.0 + 0.5) / 16.0); + color *= lightColor; + } + + if (flw_discardPredicate(color)) { + discard; + } + + _flw_outputColor = flw_fogFilter(color); +} diff --git a/src/main/resources/assets/flywheel/flywheel/internal/common.vert b/src/main/resources/assets/flywheel/flywheel/internal/common.vert new file mode 100644 index 000000000..cbbcef458 --- /dev/null +++ b/src/main/resources/assets/flywheel/flywheel/internal/common.vert @@ -0,0 +1,20 @@ +#include "flywheel:internal/fog_distance.glsl" + +flat out uint _flw_vertexDiffuse; + +void _flw_main(in FlwInstance instance) { + flw_vertexDiffuse = flw_material.diffuse; + + _flw_layoutVertex(); + flw_beginVertex(); + flw_instanceVertex(instance); + flw_materialVertex(); + flw_endVertex(); + + flw_vertexNormal = normalize(flw_vertexNormal); + + _flw_vertexDiffuse = uint(flw_vertexDiffuse); + + flw_distance = fogDistance(flw_vertexPos.xyz, flywheel.cameraPos.xyz, flywheel.fogShape); + gl_Position = flywheel.viewProjection * flw_vertexPos; +} diff --git a/src/main/resources/assets/flywheel/flywheel/internal/common_api_impl.frag b/src/main/resources/assets/flywheel/flywheel/internal/common_api_impl.frag index 06539b86c..e8d20c7c5 100644 --- a/src/main/resources/assets/flywheel/flywheel/internal/common_api_impl.frag +++ b/src/main/resources/assets/flywheel/flywheel/internal/common_api_impl.frag @@ -9,10 +9,13 @@ in vec3 flw_vertexNormal; in float flw_distance; +bool flw_vertexDiffuse; + vec4 flw_sampleColor; FlwMaterial flw_material; +bool flw_fragDiffuse; vec4 flw_fragColor; ivec2 flw_fragOverlay; vec2 flw_fragLight; diff --git a/src/main/resources/assets/flywheel/flywheel/internal/common_api_impl.vert b/src/main/resources/assets/flywheel/flywheel/internal/common_api_impl.vert index 13f709796..1c082e55d 100644 --- a/src/main/resources/assets/flywheel/flywheel/internal/common_api_impl.vert +++ b/src/main/resources/assets/flywheel/flywheel/internal/common_api_impl.vert @@ -1,5 +1,6 @@ #include "flywheel:internal/material.glsl" +// TODO: can we combine some of these internally to use fewer in/out slots? out vec4 flw_vertexPos; out vec4 flw_vertexColor; out vec2 flw_vertexTexCoord; @@ -9,4 +10,6 @@ out vec3 flw_vertexNormal; out float flw_distance; +bool flw_vertexDiffuse; + FlwMaterial flw_material; diff --git a/src/main/resources/assets/flywheel/flywheel/internal/indirect/main.frag b/src/main/resources/assets/flywheel/flywheel/internal/indirect/main.frag index f8a8dd043..334b7b461 100644 --- a/src/main/resources/assets/flywheel/flywheel/internal/indirect/main.frag +++ b/src/main/resources/assets/flywheel/flywheel/internal/indirect/main.frag @@ -1,47 +1,11 @@ -#include "flywheel:internal/packed_material.glsl" - -// optimize discard usage -#ifdef GL_ARB_conservative_depth -layout (depth_greater) out float gl_FragDepth; -#endif - -uniform sampler2D _flw_diffuseTex; -uniform sampler2D _flw_overlayTex; -uniform sampler2D _flw_lightTex; +#include "flywheel:internal/common.frag" flat in uvec3 _flw_packedMaterial; -out vec4 _flw_outputColor; - void main() { _flw_uberMaterialFragmentIndex = _flw_packedMaterial.x; _flw_unpackUint2x16(_flw_packedMaterial.y, _flw_uberCutoutIndex, _flw_uberFogIndex); _flw_unpackMaterialProperties(_flw_packedMaterial.z, flw_material); - 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_endFragment(); - - vec4 color = flw_fragColor; - - if (flw_material.useOverlay) { - vec4 overlayColor = texelFetch(_flw_overlayTex, flw_fragOverlay, 0); - color.rgb = mix(overlayColor.rgb, color.rgb, overlayColor.a); - } - - if (flw_material.useLight) { - vec4 lightColor = texture(_flw_lightTex, (flw_fragLight * 15.0 + 0.5) / 16.0); - color *= lightColor; - } - - if (flw_discardPredicate(color)) { - discard; - } - - _flw_outputColor = flw_fogFilter(color); + _flw_main(); } diff --git a/src/main/resources/assets/flywheel/flywheel/internal/indirect/main.vert b/src/main/resources/assets/flywheel/flywheel/internal/indirect/main.vert index 4bf056cbe..f59d82268 100644 --- a/src/main/resources/assets/flywheel/flywheel/internal/indirect/main.vert +++ b/src/main/resources/assets/flywheel/flywheel/internal/indirect/main.vert @@ -1,5 +1,4 @@ -#include "flywheel:internal/diffuse.glsl" -#include "flywheel:internal/fog_distance.glsl" +#include "flywheel:internal/common.vert" #include "flywheel:internal/packed_material.glsl" #include "flywheel:internal/indirect/buffers.glsl" #include "flywheel:internal/indirect/draw_command.glsl" @@ -33,24 +32,5 @@ void main() { uint objectIndex = objectIndices[gl_BaseInstance + gl_InstanceID]; FlwInstance instance = _flw_unpackInstance(objects[objectIndex].instance); - _flw_layoutVertex(); - flw_beginVertex(); - flw_instanceVertex(instance); - flw_materialVertex(); - 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 = fogDistance(flw_vertexPos.xyz, flywheel.cameraPos.xyz, flywheel.fogShape); - gl_Position = flywheel.viewProjection * flw_vertexPos; + _flw_main(instance); } diff --git a/src/main/resources/assets/flywheel/flywheel/internal/instancing/main.frag b/src/main/resources/assets/flywheel/flywheel/internal/instancing/main.frag index 6c9a0dc33..661c3a769 100644 --- a/src/main/resources/assets/flywheel/flywheel/internal/instancing/main.frag +++ b/src/main/resources/assets/flywheel/flywheel/internal/instancing/main.frag @@ -1,47 +1,11 @@ -#include "flywheel:internal/packed_material.glsl" - -// optimize discard usage -#ifdef GL_ARB_conservative_depth -layout (depth_greater) out float gl_FragDepth; -#endif - -uniform sampler2D _flw_diffuseTex; -uniform sampler2D _flw_overlayTex; -uniform sampler2D _flw_lightTex; +#include "flywheel:internal/common.frag" uniform uvec4 _flw_packedMaterial; -out vec4 _flw_outputColor; - void main() { _flw_uberMaterialFragmentIndex = _flw_packedMaterial.y; _flw_unpackUint2x16(_flw_packedMaterial.z, _flw_uberCutoutIndex, _flw_uberFogIndex); _flw_unpackMaterialProperties(_flw_packedMaterial.w, flw_material); - 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_endFragment(); - - vec4 color = flw_fragColor; - - if (flw_material.useOverlay) { - vec4 overlayColor = texelFetch(_flw_overlayTex, flw_fragOverlay, 0); - color.rgb = mix(overlayColor.rgb, color.rgb, overlayColor.a); - } - - if (flw_material.useLight) { - vec4 lightColor = texture(_flw_lightTex, (flw_fragLight * 15.0 + 0.5) / 16.0); - color *= lightColor; - } - - if (flw_discardPredicate(color)) { - discard; - } - - _flw_outputColor = flw_fogFilter(color); + _flw_main(); } diff --git a/src/main/resources/assets/flywheel/flywheel/internal/instancing/main.vert b/src/main/resources/assets/flywheel/flywheel/internal/instancing/main.vert index 2da982375..9bf8fd562 100644 --- a/src/main/resources/assets/flywheel/flywheel/internal/instancing/main.vert +++ b/src/main/resources/assets/flywheel/flywheel/internal/instancing/main.vert @@ -1,5 +1,4 @@ -#include "flywheel:internal/diffuse.glsl" -#include "flywheel:internal/fog_distance.glsl" +#include "flywheel:internal/common.vert" #include "flywheel:internal/packed_material.glsl" uniform uvec4 _flw_packedMaterial; @@ -10,24 +9,5 @@ void main() { FlwInstance instance = _flw_unpackInstance(); - _flw_layoutVertex(); - flw_beginVertex(); - flw_instanceVertex(instance); - flw_materialVertex(); - 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 = fogDistance(flw_vertexPos.xyz, flywheel.cameraPos.xyz, flywheel.fogShape); - gl_Position = flywheel.viewProjection * flw_vertexPos; + _flw_main(instance); }