mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-27 07:26:48 +01:00
Frag shader go brr
- Add flw_vertexDiffuse and flw_fragDiffuse to glsl api. - Compute/apply diffuse in the fragment shader. - Move common glsl between instancing/indirect to common.vert/.frag. - Add a pittance more documentation to api spec. - Sneak in a block to build.gradle to always download sources/javadoc.
This commit is contained in:
parent
89f0e54717
commit
60b3d99a43
11 changed files with 111 additions and 123 deletions
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue