Better Organized Generated Normal stuff

This commit is contained in:
Rbanh committed 2024-06-22 17:05:41 -04:00
1 parent 0f859671ea
commit 16d5613af1
25 files changed
+1204 -497

No files matched your search

+3 -3
View File
@@ -7,7 +7,7 @@ vec3 GetSkyColor(vec3 viewPos, bool isReflection) {
float groundDensity = 0.1 * (4.0 - 3.0 * sunVisibility) *
(10.0 * rainStrength * rainStrength + 1.0);
float exposure = exp2(timeBrightness * 0.75 - 0.75 + SKY_EXPOSURE_D);
float nightExposure = exp2(-3.5 + SKY_EXPOSURE_N);
float weatherExposure = exp2(SKY_EXPOSURE_W);
@@ -42,8 +42,8 @@ vec3 GetSkyColor(vec3 viewPos, bool isReflection) {
lightSky = lightSky / (1.0 + lightSky * rainStrength);
sky = mix(
sqrt(sky * (1.0 - lightMix)),
sqrt(lightSky),
sqrt(sky * (1.0 - lightMix)),
sqrt(lightSky),
lightMix
);
sky *= sky;
+109
View File
@@ -0,0 +1,109 @@
// Only allow generated normals for material format 2 aka Integrated
#if MATERIAL_FORMAT != 2
#ifdef GENERATED_NORMALS
#undef GENERATED_NORMALS
#endif
#endif
//Common Functions//
float GetLuminance(vec3 color) {
return dot(color,vec3(0.299, 0.587, 0.114));
}
float pow2(float x) {
return x * x;
}
vec2 pow2(vec2 x) {
return x * x;
}
vec3 pow2(vec3 x) {
return x * x;
}
float pow1_5(float x) { // Faster pow(x, 1.5) approximation (that isn't accurate at all) if x is between 0 and 1
return x - x * pow2(1.0 - x); // Thanks to SixthSurge
}
vec2 pow1_5(vec2 x) {
return x - x * pow2(1.0 - x);
}
vec3 pow1_5(vec3 x) {
return x - x * pow2(1.0 - x);
}
bool CheckForColor(vec3 albedo, vec3 check) { // Thanks to Builderb0y
vec3 dif = albedo - check * 0.003921568;
return dif == clamp(dif, vec3(-0.001), vec3(0.001));
}
float GetMaxColorDif(vec3 color) {
vec3 dif = abs(vec3(color.r - color.g, color.g - color.b, color.r - color.b));
return max(dif.r, max(dif.g, dif.b));
}
float smoothstep1(float x) {
return x * x * (3.0 - 2.0 * x);
}
vec2 smoothstep1(vec2 x) {
return x * x * (3.0 - 2.0 * x);
}
vec3 smoothstep1(vec3 x) {
return x * x * (3.0 - 2.0 * x);
}
float sqrt1(float x) { // Faster sqrt() approximation (that isn't accurate at all) if x is between 0 and 1
return x * (2.0 - x); // Thanks to Builderb0y
}
vec2 sqrt1(vec2 x) {
return x * (2.0 - x);
}
vec3 sqrt1(vec3 x) {
return x * (2.0 - x);
}
vec4 sqrt1(vec4 x) {
return x * (2.0 - x);
}
float sqrt3(float x) {
x = 1.0 - x;
x *= x;
x *= x;
x *= x;
return 1.0 - x;
}
vec2 sqrt3(vec2 x) {
x = 1.0 - x;
x *= x;
x *= x;
x *= x;
return 1.0 - x;
}
vec3 sqrt3(vec3 x) {
x = 1.0 - x;
x *= x;
x *= x;
x *= x;
return 1.0 - x;
}
vec4 sqrt3(vec4 x) {
x = 1.0 - x;
x *= x;
x *= x;
x *= x;
return 1.0 - x;
}
float min1(float x) {
return min(x, 1.0);
}
float max0(float x) {
return max(x, 0.0);
}
float clamp01(float x) {
return clamp(x, 0.0, 1.0);
}
vec2 clamp01(vec2 x) {
return clamp(x, vec2(0.0), vec2(1.0));
}
vec3 clamp01(vec3 x) {
return clamp(x, vec3(0.0), vec3(1.0));
}
@@ -2,6 +2,7 @@
#include "/lib/lighting/shadows.glsl"
#endif
void GetLighting(inout vec3 albedo, out vec3 shadow, vec3 viewPos, vec3 worldPos, vec3 normal,
vec2 lightmap, float smoothLighting, float NoL, float vanillaDiffuse,
float parallaxShadow, float emission, float subsurface, float basicSubsurface) {
+5 -2
View File
@@ -81,13 +81,16 @@ Please don't edit anything from Undefine section and onwards.
#define SELF_SHADOW_STRENGTH 16 //[4 8 16 32 64]
//#define DIRECTIONAL_LIGHTMAP
#define DIRECTIONAL_LIGHTMAP_STRENGTH 1.0 //[2.0 1.4 1.0 0.7 0.5]
#define NORMAL_DAMPENING
#define NORMAL_PLANTS
#define GENERATED_NORMALS
#define GENERATED_NORMAL_MULT 100 //[25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 110 120 130 140 150 160 170 180 190 200 250 300 400]
#define GENERATED_NORMAL_THRESHOLD 0.05 //[0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.10 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.20]
#define GENERATED_NORMAL_CLAMP 0.20 //[0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20 0.22 0.24 0.26 0.28 0.30 0.32 0.34 0.36 0.38 0.40]
#define GENERATED_NORMAL_RESOLUTION 128 //[16 32 64 128 256 512]
#define NORMAL_DAMPENING
#define NORMAL_PLANTS
#define INTEGRATED_SPECULAR
#define SSS
#define BASIC_SSS
+3 -1
View File
@@ -15,4 +15,6 @@ void GetMaterials(out float smoothness, out float skyOcclusion, out vec3 normal,
normal = DecodeNormal(texture2D(colortex6, coord).xy);
fresnel3 = texture2D(colortex7, coord).rgb * smoothness;
}
}
+26 -1
View File
@@ -1,3 +1,27 @@
struct Material {
vec3 albedo;
vec3 emission;
vec3 f0;
vec3 f82; // hardcoded metals only
float roughness;
float sss_amount;
float sheen_amount; // SSS "sheen" for tall grass
float porosity;
float ssr_multiplier;
float normal_multiplier; // normal map multiplier for generated normals
bool is_metal;
bool is_hardcoded_metal;
};
#ifdef GENERATED_NORMALS
#include "/lib/surface/generatedNormals.glsl"
#endif
void GetMaterials(out float smoothness, out float metalness, out float f0, inout float emission,
inout float subsurface, out float porosity, out float ao, out vec3 normalMap,
vec2 newCoord, vec2 dcdx, vec2 dcdy)
@@ -127,4 +151,5 @@ void GetMaterials(out float smoothness, out float metalness, out float f0, inout
normalMap = normalize(mix(vec3(0.0, 0.0, 1.0), normalMap, 1.0 / exp2(miplevel)));
#endif
}
}
@@ -1,105 +0,0 @@
// if (blockEntityId < 60028) {
// if (blockEntityId < 60012) {
// if (blockEntityId < 60004) {
// if (blockEntityId == 10548) { // Enchanting Table:Book
// smoothnessG = pow2(color.g) * 0.35;
// if (color.b < 0.0001 && color.r > color.g) {
// emission = color.g * 4.0;
// }
// } else if (blockEntityId == 60000) { //
// }
// } else {
// if (blockEntityId == 60004) { // Signs
// noSmoothLighting = true;
// if (glColor.r + glColor.g + glColor.b <= 2.99 || lmCoord.x > 0.999) { // Sign Text
// #include "/lib/materials/specificMaterials/others/signText.glsl"
// }
// #ifdef COATED_TEXTURES
// noiseFactor = 0.66;
// #endif
// } else /*if (blockEntityId == 60008)*/ { // Chest
// noSmoothLighting = true;
// smoothnessG = pow2(color.g);
// #ifdef COATED_TEXTURES
// noiseFactor = 0.66;
// #endif
// }
// }
// } else {
// if (blockEntityId < 60020) {
// if (blockEntityId == 60012) { // Ender Chest
// noSmoothLighting = true;
// float factor = min(pow2(color.g), 0.25);
// smoothnessG = factor * 2.0;
// if (color.g > color.r || color.b > color.g)
// emission = pow2(factor) * 20.0;
// emission += 0.35;
// #ifdef COATED_TEXTURES
// noiseFactor = 0.66;
// #endif
// } else /*if (blockEntityId == 60016)*/ { // Shulker Box+, Banner+, Head+, Bed+
// noSmoothLighting = true;
// #ifdef COATED_TEXTURES
// noiseFactor = 0.2;
// #endif
// }
// } else {
// if (blockEntityId == 60020) { // Conduit
// noSmoothLighting = true;
// lmCoordM.x = 0.9;
// if (color.b > color.r) { // Conduit:Wind, Conduit:Blue Pixels of The Eye
// emission = color.r * 16.0;
// } else if (color.r > color.b * 2.5) { // Conduit:Red Pixels of The Eye
// emission = 20.0;
// color.rgb *= vec3(1.0, 0.25, 0.1);
// }
// } else /*if (blockEntityId == 60024)*/ { // End Portal, End Gateway
// #include "/lib/materials/specificMaterials/others/endPortalEffect.glsl"
// }
// }
// }
// } else {
// if (blockEntityId < 60044) {
// if (blockEntityId < 60036) {
// if (blockEntityId == 60028) { //
// } else /*if (blockEntityId == 60032)*/ { // Bell
// if (color.r + color.g > color.b + 0.5) { // Bell:Golden Part
// #include "/lib/materials/specificMaterials/terrain/goldBlock.glsl"
// } else {
// #include "/lib/materials/specificMaterials/terrain/stone.glsl"
// }
// }
// } else {
// if (blockEntityId == 60036) { //
// } else /*if (blockEntityId == 60040)*/ { //
// }
// }
// } else {
// if (blockEntityId < 60052) {
// if (blockEntityId == 60044) { //
// } else /*if (blockEntityId == 60048)*/ { //
// }
// } else {
// if (blockEntityId == 60052) { //
// } else if (blockEntityId == 60056) { //
// }
// }
// }
// }
@@ -0,0 +1,697 @@
#if !defined INCLUDE_MISC_MATERIAL
#define INCLUDE_MISC_MATERIAL
const float air_n = 1.000293; // for 0°C and 1 atm
const float water_n = 1.333; // for 20°C
struct Material {
vec3 albedo;
vec3 emission;
vec3 f0;
vec3 f82; // hardcoded metals only
float roughness;
float sss_amount;
float sheen_amount; // SSS "sheen" for tall grass
float porosity;
float ssr_multiplier;
float normal_multiplier; // normal map multiplier for generated normals
bool is_metal;
bool is_hardcoded_metal;
};
const Material water_material = Material(vec3(0.0), vec3(0.0), vec3(0.02), vec3(0.0), 0.002, 1.0, 0.0, 0.0, 1.0, 1.0, false, false);
#if TEXTURE_FORMAT == TEXTURE_FORMAT_LAB
void decode_specular_map(vec4 specular_map, inout Material material) {
// f0 and f82 values for hardcoded metals from Jessie LC (https://github.com/Jessie-LC)
const vec3[] metal_f0 = vec3[](
vec3(0.78, 0.77, 0.74), // Iron
vec3(1.00, 0.90, 0.61), // Gold
vec3(1.00, 0.98, 1.00), // Aluminum
vec3(0.77, 0.80, 0.79), // Chrome
vec3(1.00, 0.89, 0.73), // Copper
vec3(0.79, 0.87, 0.85), // Lead
vec3(0.92, 0.90, 0.83), // Platinum
vec3(1.00, 1.00, 0.91) // Silver
);
const vec3[] metal_f82 = vec3[](
vec3(0.74, 0.76, 0.76),
vec3(1.00, 0.93, 0.73),
vec3(0.96, 0.97, 0.98),
vec3(0.74, 0.79, 0.78),
vec3(1.00, 0.90, 0.80),
vec3(0.83, 0.80, 0.83),
vec3(0.89, 0.87, 0.81),
vec3(1.00, 1.00, 0.95)
);
material.roughness = sqr(1.0 - specular_map.r);
material.emission = max(material.emission, material.albedo * specular_map.a * float(specular_map.a != 1.0));
if (specular_map.g < 229.5 / 255.0) {
#ifdef F0_FALLBACK
if (specular_map.g < 0.5 / 255.0) specular_map.g = 0.04;
#endif
// Dielectrics
material.f0 = max(material.f0, specular_map.g);
float has_sss = step(64.5 / 255.0, specular_map.b);
material.sss_amount = max(material.sss_amount, linear_step(64.0 / 255.0, 1.0, specular_map.b * has_sss));
material.porosity = linear_step(0.0, 64.0 / 255.0, max0(specular_map.b - specular_map.b * has_sss));
} else if (specular_map.g < 237.5 / 255.0) {
// Hardcoded metals
uint metal_id = clamp(uint(255.0 * specular_map.g) - 230u, 0u, 7u);
material.f0 = metal_f0[metal_id];
material.f82 = metal_f82[metal_id];
material.is_metal = true;
material.is_hardcoded_metal = true;
} else {
// Albedo metal
material.f0 = material.albedo;
material.is_metal = true;
}
material.ssr_multiplier = step(0.01, (material.f0.x - material.f0.x * material.roughness * SSR_ROUGHNESS_THRESHOLD)); // based on Kneemund's method
}
#elif TEXTURE_FORMAT == TEXTURE_FORMAT_OLD
void decode_specular_map(vec4 specular_map, inout Material material) {
material.roughness = sqr(1.0 - specular_map.r);
material.is_metal = specular_map.g > 0.5;
material.f0 = material.is_metal ? material.albedo : material.f0;
material.emission = max(material.emission, material.albedo * specular_map.b);
material.ssr_multiplier = step(0.01, (material.f0.x - material.f0.x * material.roughness * SSR_ROUGHNESS_THRESHOLD)); // based on Kneemund's method
}
#endif
void decode_specular_map(vec4 specular_map, inout Material material, out bool parallax_shadow) {
#if defined POM && defined POM_SHADOW
// Specular map alpha >= 0.5 => parallax shadow
parallax_shadow = specular_map.a >= 0.5;
specular_map.a = fract(specular_map.a * 2.0);
#endif
decode_specular_map(specular_map, material);
}
Material material_from(vec3 albedo_srgb, uint material_mask, vec3 world_pos, vec3 normal, inout vec2 light_levels) {
vec3 block_pos = fract(world_pos);
// Create material with default values
Material material;
material.albedo = srgb_eotf_inv(albedo_srgb) * rec709_to_rec2020;
material.emission = vec3(0.0);
material.f0 = vec3(0.0);
material.f82 = vec3(0.0);
material.roughness = 1.0;
material.sss_amount = 0.0;
material.sheen_amount = 0.0;
material.porosity = 0.0;
material.ssr_multiplier = 0.0;
material.normal_multiplier = 1.0;
material.is_metal = false;
material.is_hardcoded_metal = false;
// Hardcoded materials for specific blocks
// Using binary split search to minimise branches per fragment (TODO: measure impact)
vec3 hsl = rgb_to_hsl(albedo_srgb);
vec3 albedo_sqrt = sqrt(material.albedo);
if (material_mask < 32u) { // 0-32
if (material_mask < 16u) { // 0-16
if (material_mask < 8u) { // 0-8
if (material_mask < 4u) { // 0-4
if (material_mask >= 2u) { // 2-4
if (material_mask == 2u) { // 2
#ifdef HARDCODED_SSS
// Small plants
material.sss_amount = 0.5;
material.sheen_amount = 0.5;
#endif
} else { // 3
#ifdef HARDCODED_SSS
// Tall plants (lower half)
material.sss_amount = 0.5;
material.sheen_amount = 0.5;
#endif
}
}
} else { // 4-8
if (material_mask < 6u) { // 4-6
if (material_mask == 4u) { // 4
#ifdef HARDCODED_SSS
// Tall plants (upper half)
material.sss_amount = 0.5;
material.sheen_amount = 0.5;
#endif
} else { // 5
// Leaves
#ifdef HARDCODED_SPECULAR
float smoothness = 0.5 * smoothstep(0.16, 0.5, hsl.z);
material.roughness = sqr(1.0 - smoothness);
material.f0 = vec3(0.02);
material.sheen_amount = 0.5;
#endif
#ifdef HARDCODED_SSS
material.sss_amount = 1.0;
#endif
}
} else { // 6-8
if (material_mask == 6u) { // 6
#ifdef HARDCODED_SPECULAR
// Grass, stone, spruce and dark oak planks
float smoothness = 0.33 * smoothstep(0.2, 0.6, hsl.z);
material.roughness = sqr(1.0 - smoothness);
material.f0 = vec3(0.02);
#endif
#ifdef HARDCODED_POROSITY
material.porosity = 0.2;
#endif
} else { // 7
// Sand
#ifdef HARDCODED_SPECULAR
float smoothness = 0.8 * linear_step(0.81, 0.96, hsl.z);
material.roughness = sqr(1.0 - smoothness);
material.f0 = vec3(0.02);
#endif
#ifdef HARDCODED_POROSITY
material.porosity = 1.35;
#endif
}
}
}
} else { // 8-16
if (material_mask < 12u) { // 8-12
if (material_mask < 10u) { // 8-10
if (material_mask == 8u) { // 8
// Ice
#ifdef HARDCODED_SPECULAR
float smoothness = pow4(linear_step(0.4, 0.8, hsl.z)) * 0.6;
material.roughness = sqr(1.0 - smoothness);
material.f0 = vec3(0.02);
material.ssr_multiplier = 1.0;
#endif
#ifdef HARDCODED_SSS
// Strong SSS
material.sss_amount = 0.75;
#endif
#ifdef HARDCODED_POROSITY
material.porosity = 0.2;
#endif
} else { // 9
// Red sand, birch planks
#ifdef HARDCODED_SPECULAR
float smoothness = 0.4 * linear_step(0.61, 0.85, hsl.z);
material.roughness = sqr(1.0 - smoothness);
material.f0 = vec3(0.02);
#endif
#ifdef HARDCODED_POROSITY
material.porosity = 0.5;
#endif
}
} else { // 10-12
if (material_mask == 10u) { // 10
// Oak, jungle and acacia planks, granite and diorite
#ifdef HARDCODED_SPECULAR
float smoothness = 0.5 * linear_step(0.4, 0.8, hsl.z);
material.roughness = sqr(1.0 - smoothness);
material.f0 = vec3(0.02);
#endif
#ifdef HARDCODED_POROSITY
material.porosity = 0.2;
#endif
} else { // 11
// Obsidian, nether bricks
#ifdef HARDCODED_SPECULAR
float smoothness = linear_step(0.02, 0.4, hsl.z);
material.roughness = sqr(1.0 - smoothness);
material.f0 = vec3(0.02);
material.ssr_multiplier = 1.0;
#endif
}
}
} else { // 12-16
if (material_mask < 14u) { // 12-14
if (material_mask == 12u) { // 12
// Metals
#ifdef HARDCODED_SPECULAR
float smoothness = sqrt(linear_step(0.1, 0.9, hsl.z));
material.roughness = max(sqr(1.0 - smoothness), 0.04);
material.f0 = material.albedo;
material.is_metal = true;
material.ssr_multiplier = 1.0;
#endif
} else { // 13
// Gems
#ifdef HARDCODED_SPECULAR
float smoothness = sqrt(linear_step(0.1, 0.9, hsl.z));
material.roughness = max(sqr(1.0 - smoothness), 0.04);
material.f0 = vec3(0.25);
material.ssr_multiplier = 1.0;
#endif
}
} else { // 14-16
if (material_mask == 14u) { // 14
#ifdef HARDCODED_SSS
// Strong SSS
material.sss_amount = 0.6;
#endif
#ifdef HARDCODED_POROSITY
material.porosity = 0.5;
#endif
} else { // 15
#ifdef HARDCODED_SSS
// Weak SSS
material.sss_amount = 0.1;
#endif
#ifdef HARDCODED_POROSITY
material.porosity = 0.25;
#endif
}
}
}
}
} else { // 16-32
if (material_mask < 24u) { // 16-24
if (material_mask < 20u) { // 16-20
if (material_mask < 18u) { // 16-18
if (material_mask == 16u) { // 16
#ifdef HARDCODED_EMISSION
// Chorus plant
material.emission = 0.25 * albedo_sqrt * pow4(hsl.z);
#endif
} else { // 17
#ifdef HARDCODED_SPECULAR
// End stone
float smoothness = 0.4 * linear_step(0.61, 0.85, hsl.z);
material.roughness = sqr(1.0 - smoothness);
material.f0 = vec3(0.02);
material.ssr_multiplier = 1.0;
#endif
}
} else { // 18-20
if (material_mask == 18u) { // 18
// Metals
#ifdef HARDCODED_SPECULAR
float smoothness = sqrt(linear_step(0.1, 0.9, hsl.z));
material.roughness = max(sqr(1.0 - smoothness), 0.04);
material.f0 = material.albedo;
material.is_metal = true;
material.ssr_multiplier = 1.0;
#endif
} else { // 19
// Warped stem
#ifdef HARDCODED_EMISSION
float emission_amount = mix(
1.0,
float(any(lessThan(
vec4(block_pos.yz, 1.0 - block_pos.yz),
vec4(rcp(16.0) - 1e-3)
))),
step(0.5, abs(normal.x))
);
float blue = isolate_hue(hsl, 200.0, 60.0);
material.emission = albedo_sqrt * hsl.y * blue * emission_amount;
#endif
}
}
} else { // 20-24
if (material_mask < 22u) { // 20-22
if (material_mask == 20u) { // 20
// Warped stem
#ifdef HARDCODED_EMISSION
float emission_amount = mix(
1.0,
float(any(lessThan(
vec4(block_pos.xz, 1.0 - block_pos.xz),
vec4(rcp(16.0) - 1e-3)
))),
step(0.5, abs(normal.y))
);
float blue = isolate_hue(hsl, 200.0, 60.0);
material.emission = albedo_sqrt * hsl.y * blue * emission_amount;
#endif
} else { // 21
// Warped stem
#ifdef HARDCODED_EMISSION
float emission_amount = mix(
1.0,
float(any(lessThan(
vec4(block_pos.xy, 1.0 - block_pos.xy),
vec4(rcp(16.0) - 1e-3)
))),
step(0.5, abs(normal.z))
);
float blue = isolate_hue(hsl, 200.0, 60.0);
material.emission = albedo_sqrt * hsl.y * blue * emission_amount;
#endif
}
} else { // 22-24
if (material_mask == 22u) { // 22
// Warped hyphae
#ifdef HARDCODED_EMISSION
float blue = isolate_hue(hsl, 200.0, 60.0);
material.emission = albedo_sqrt * hsl.y * blue;
#endif
} else { // 23
// Crimson stem
#ifdef HARDCODED_EMISSION
float emission_amount = mix(
1.0,
float(any(lessThan(
vec4(block_pos.yz, 1.0 - block_pos.yz),
vec4(rcp(16.0) - 1e-3)
))),
step(0.5, abs(normal.x))
);
material.emission = albedo_sqrt * linear_step(0.33, 0.5, hsl.z) * emission_amount;
#endif
}
}
}
} else { // 24-32
if (material_mask < 28u) { // 24-28
if (material_mask < 26u) { // 24-26
if (material_mask == 24u) { // 24
// Crimson stem
#ifdef HARDCODED_EMISSION
float emission_amount = mix(
1.0,
float(any(lessThan(
vec4(block_pos.xz, 1.0 - block_pos.xz),
vec4(rcp(16.0) - 1e-3)
))),
step(0.5, abs(normal.y))
);
material.emission = albedo_sqrt * linear_step(0.33, 0.5, hsl.z) * emission_amount;
#endif
} else { // 25
// Crimson stem
#ifdef HARDCODED_EMISSION
float emission_amount = mix(
1.0,
float(any(lessThan(
vec4(block_pos.xy, 1.0 - block_pos.xy),
vec4(rcp(16.0) - 1e-3)
))),
step(0.5, abs(normal.z))
);
material.emission = albedo_sqrt * linear_step(0.33, 0.5, hsl.z) * emission_amount;
#endif
}
} else { // 26-28
if (material_mask == 26u) { // 26
// Crimson hyphae
#ifdef HARDCODED_EMISSION
material.emission = albedo_sqrt * linear_step(0.33, 0.5, hsl.z);
#endif
} else { // 27
}
}
} else { // 28-32
if (material_mask < 30) { // 28-30
if (material_mask == 28u) { // 28
} else { // 29
}
} else { // 30-32
if (material_mask == 30u) { // 30
} else { // 31
}
}
}
}
}
} else if (material_mask < 64u) { // 32-64
if (material_mask < 48u) { // 32-48
if (material_mask < 40u) { // 32-40
if (material_mask < 36u) { // 32-36
if (material_mask < 34u) { // 32-34
if (material_mask == 32u) { // 32
#ifdef HARDCODED_EMISSION
// Strong white light
material.emission = 1.00 * albedo_sqrt * (0.1 + 0.9 * cube(hsl.z));
#endif
} else { // 33
#ifdef HARDCODED_EMISSION
// Medium white light
material.emission = 0.66 * albedo_sqrt * linear_step(0.75, 0.9, hsl.z);
#endif
}
} else { // 34-36
if (material_mask == 34u) { // 34
#ifdef HARDCODED_EMISSION
// Weak white light
material.emission = 0.2 * albedo_sqrt * (0.1 + 0.9 * pow4(hsl.z));
#endif
} else { // 35
#ifdef HARDCODED_EMISSION
// Strong golden light
material.emission = 0.85 * albedo_sqrt * linear_step(0.4, 0.6, 0.2 * hsl.y + 0.55 * hsl.z);
#endif
}
}
} else { // 36-40
if (material_mask < 38u) { // 36-38
if (material_mask == 36u) { // 36
#ifdef HARDCODED_EMISSION
// Medium golden light
material.emission = 0.85 * albedo_sqrt * linear_step(0.78, 0.85, hsl.z);
#endif
} else { // 37
#ifdef HARDCODED_EMISSION
// Weak golden light
float blue = isolate_hue(hsl, 200.0, 30.0);
material.emission = 0.8 * albedo_sqrt * linear_step(0.47, 0.50, 0.2 * hsl.y + 0.5 * hsl.z + 0.1 * blue);
#endif
}
} else { // 38-40
if (material_mask == 38u) { // 38
#ifdef HARDCODED_EMISSION
// Redstone components
vec3 ap1 = material.albedo * rec2020_to_ap1_unlit;
float l = 0.5 * (min_of(ap1) + max_of(ap1));
float redness = ap1.r * rcp(ap1.g + ap1.b);
material.emission = 0.33 * material.albedo * step(0.45, redness * l);
#endif
} else { // 39
#ifdef HARDCODED_EMISSION
// Lava
material.emission = 4.0 * albedo_sqrt * (0.2 + 0.8 * isolate_hue(hsl, 30.0, 15.0)) * step(0.4, hsl.y);
#endif
}
}
}
} else { // 40-48
if (material_mask < 44u) { // 40-44
if (material_mask < 42u) { // 40-42
if (material_mask == 40u) { // 40
#ifdef HARDCODED_EMISSION
// Medium orange emissives
material.emission = 0.60 * albedo_sqrt * (0.1 + 0.9 * cube(hsl.z));
#endif
} else { // 41
#ifdef HARDCODED_EMISSION
// Brewing stand
material.emission = 0.85 * albedo_sqrt * linear_step(0.77, 0.85, hsl.z);
#endif
}
} else { // 42-44
if (material_mask == 42u) { // 42
#ifdef HARDCODED_EMISSION
// Jack o' Lantern
material.emission = 0.80 * albedo_sqrt * step(0.73, 0.1 * hsl.y + 0.7 * hsl.z);
#endif
} else { // 43
#ifdef HARDCODED_EMISSION
// Soul lights
float blue = isolate_hue(hsl, 200.0, 30.0);
material.emission = 0.66 * albedo_sqrt * linear_step(0.8, 1.0, blue + hsl.z);
#endif
}
}
} else { // 44-48
if (material_mask < 46u) { // 44-46
if (material_mask == 44u) { // 44
#ifdef HARDCODED_EMISSION
// Beacon
material.emission = step(0.2, hsl.z) * albedo_sqrt * step(max_of(abs(block_pos - 0.5)), 0.4);
#endif
} else { // 45
#ifdef HARDCODED_EMISSION
// End portal frame
material.emission = 0.33 * material.albedo * isolate_hue(hsl, 120.0, 50.0);
#endif
}
} else { // 46-48
if (material_mask == 46u) { // 46
#ifdef HARDCODED_EMISSION
// Sculk
material.emission = 0.2 * material.albedo * isolate_hue(hsl, 200.0, 40.0) * smoothstep(0.5, 0.7, hsl.z) * (1.0 - linear_step(0.0, 20.0, distance(world_pos, cameraPosition)));
#endif
} else { // 47
#ifdef HARDCODED_EMISSION
// Pink glow
material.emission = vec3(0.75) * isolate_hue(hsl, 310.0, 50.0);
#endif
}
}
}
}
} else { // 48-64
if (material_mask < 56u) { // 48-56
if (material_mask < 52u) { // 48-52
if (material_mask < 50u) { // 48-50
if (material_mask == 48u) { // 48
material.emission = 0.5 * albedo_sqrt * linear_step(0.5, 0.6, hsl.z);
} else { // 49
#ifdef HARDCODED_EMISSION
// Jack o' Lantern + nether mushrooms
material.emission = 0.80 * albedo_sqrt * step(0.73, 0.1 * hsl.y + 0.7 * hsl.z);
#endif
}
} else { // 50-52
if (material_mask == 50u) { // 50
#ifdef HARDCODED_EMISSION
// Candles
material.emission = vec3(0.2) * pow4(clamp01(block_pos.y * 2.0));
#endif
} else { // 51
#ifdef HARDCODED_EMISSION
// Ochre froglight
material.emission = 0.40 * albedo_sqrt * (0.1 + 0.9 * cube(hsl.z));
#endif
}
}
} else { // 52-56
if (material_mask < 54u) { // 52-54
if (material_mask == 52u) { // 52
#ifdef HARDCODED_EMISSION
// Verdant froglight
material.emission = 0.40 * albedo_sqrt * (0.1 + 0.9 * cube(hsl.z));
#endif
} else { // 53
#ifdef HARDCODED_EMISSION
// Pearlescent froglight
material.emission = 0.40 * albedo_sqrt * (0.1 + 0.9 * cube(hsl.z));
#endif
}
} else { // 54-56
if (material_mask == 54u) { // 54
} else { // 55
#ifdef HARDCODED_EMISSION
// Amethyst cluster
material.emission = vec3(0.20) * (0.1 + 0.9 * hsl.z);
#endif
}
}
}
} else { // 56-64
if (material_mask < 60u) { // 56-60
if (material_mask < 58u) { // 56-58
if (material_mask == 56u) { // 56
#ifdef HARDCODED_EMISSION
// Calibrated sculk sensor
material.emission = 0.2 * material.albedo * isolate_hue(hsl, 200.0, 40.0) * smoothstep(0.5, 0.7, hsl.z) * (1.0 - linear_step(0.0, 20.0, distance(world_pos, cameraPosition)));
material.emission += vec3(0.20) * (0.1 + 0.9 * hsl.z) * step(0.5, isolate_hue(hsl, 270.0, 50.0) + 0.55 * hsl.z);
#endif
} else { // 57
#ifdef HARDCODED_EMISSION
// Active sculk sensor
material.emission = vec3(0.20) * (0.1 + 0.9 * hsl.z);
#endif
}
} else { // 58-60
if (material_mask == 58u) { // 58
#ifdef HARDCODED_EMISSION
// Redstone block
material.emission = 0.33 * albedo_sqrt;
#endif
} else { // 59
#ifdef HARDCODED_EMISSION
// Emerald block
material.emission = 0.1 * albedo_sqrt;
#endif
}
}
} else { // 60-64
if (material_mask < 62u) { // 60-62
if (material_mask == 60u) { // 60
#ifdef HARDCODED_EMISSION
// Lapis block
material.emission = 0.33 * albedo_sqrt;
#endif
} else { // 61
}
} else { // 62-64
if (material_mask == 62u) { // 62
// Nether portal
material.emission = vec3(1.0);
} else { // 63
// End portal
material.emission = vec3(1.0);
}
}
}
}
}
} else if (material_mask < 264u) { // 64 - 264
if(material_mask == 80) { // 80
// Powered lightning rod
material.emission = vec3(1.0);
} /*else {
}*/
} else if (material_mask < 331u) { // 264 - 331
// Colored Candles
material.emission = vec3(0.2) * pow4(clamp01(block_pos.y * 2.0));
} /*else if (material_mask == PHYSICS_MOD_SNOW_ID) {
#ifdef HARDCODED_SPECULAR
material.f0 = vec3(0.02);
material.roughness = 0.5;
#endif
#ifdef HARDCODED_SSS
material.sss_amount = 1.0;
material.sheen_amount = 1.0;
#endif
}*/
if (164u <= material_mask && material_mask < 180u) {
// Stained glass, honey and slime
#ifdef HARDCODED_SPECULAR
material.f0 = vec3(0.04);
material.roughness = 0.1;
material.ssr_multiplier = 1.0;
#endif
#ifdef HARDCODED_SSS
material.sss_amount = 0.5;
#endif
}
return material;
}
#endif // INCLUDE_MISC_MATERIAL
-15
View File
@@ -1,15 +0,0 @@
float min1(float x) {
return min(x, 1.0);
}
float max0(float x) {
return max(x, 0.0);
}
float clamp01(float x) {
return clamp(x, 0.0, 1.0);
}
vec2 clamp01(vec2 x) {
return clamp(x, vec2(0.0), vec2(1.0));
}
vec3 clamp01(vec3 x) {
return clamp(x, vec3(0.0), vec3(1.0));
}