clean up; dimension support

This commit is contained in:
NULL511 2024-05-02 23:38:35 -04:00
parent c29d08a5f5
commit 81a937790c
14 changed files with 513 additions and 491 deletions

View File

@ -0,0 +1,313 @@
layout (local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
const ivec3 workGroups = ivec3(4, 5, 1);
#ifdef IS_LPV_ENABLED
#include "/lib/blocks.glsl"
#include "/lib/lpv_blocks.glsl"
const vec3 LightColor_Candles = vec3(1.0, 0.4, 0.1);
const vec3 LightColor_SeaPickle = vec3(0.283, 0.394, 0.212);
uint BuildLpvMask(const in uint north, const in uint east, const in uint south, const in uint west, const in uint up, const in uint down) {
return east | (west << 1) | (down << 2) | (up << 3) | (south << 4) | (north << 5);
}
#endif
void main() {
#ifdef IS_LPV_ENABLED
uint blockId = uint(gl_GlobalInvocationID.x + gl_GlobalInvocationID.y * 32 + LpvBlockMapOffset);
//if (blockId >= 1280) return;
vec3 lightColor = vec3(0.0);
float lightRange = 0.0;
float mixWeight = 0.0;
uint mixMask = 0xFFFF;
vec3 tintColor = vec3(1.0);
switch (blockId) {
case BLOCK_BEACON:
lightColor = vec3(1.0);
lightRange = 15.0;
break;
case BLOCK_CANDLES_LIT_1:
lightColor = LightColor_Candles;
lightRange = 3.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_LIT_2:
lightColor = LightColor_Candles;
lightRange = 6.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_LIT_3:
lightColor = LightColor_Candles;
lightRange = 9.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_LIT_4:
lightColor = LightColor_Candles;
lightRange = 12.0;
mixWeight = 1.0;
break;
case BLOCK_CAVE_VINE_BERRIES:
lightColor = vec3(0.717, 0.541, 0.188);
lightRange = 14.0;
mixWeight = 1.0;
break;
case BLOCK_CONDUIT:
lightColor = vec3(1.0);
lightRange = 15.0;
break;
case BLOCK_END_GATEWAY:
lightColor = vec3(1.0);
lightRange = 15.0;
break;
case BLOCK_END_ROD:
lightColor = vec3(0.957, 0.929, 0.875);
lightRange = 14.0;
break;
case BLOCK_FIRE:
lightColor = vec3(0.864, 0.598, 0.348);
lightRange = 15.0;
mixWeight = 1.0;
break;
case BLOCK_FROGLIGHT_OCHRE:
lightColor = vec3(0.768, 0.648, 0.108);
lightRange = 15.0;
break;
case BLOCK_FROGLIGHT_PEARLESCENT:
lightColor = vec3(0.737, 0.435, 0.658);
lightRange = 15.0;
break;
case BLOCK_FROGLIGHT_VERDANT:
lightColor = vec3(0.463, 0.763, 0.409);
lightRange = 15.0;
break;
case BLOCK_GLOWSTONE:
lightColor = vec3(0.747, 0.594, 0.326);
lightRange = 15.0;
break;
case BLOCK_JACK_O_LANTERN:
lightColor = vec3(1.0, 0.7, 0.1);
lightRange = 15.0;
break;
case BLOCK_LANTERN:
lightColor = vec3(1.0, 0.7, 0.1);
lightRange = 15.0;
mixWeight = 0.8;
break;
case BLOCK_LAVA:
lightColor = vec3(0.804, 0.424, 0.149);
lightRange = 15.0;
break;
case BLOCK_MAGMA:
lightColor = vec3(0.747, 0.323, 0.110);
lightRange = 3.0;
break;
case BLOCK_REDSTONE_LAMP_LIT:
lightColor = vec3(0.953, 0.796, 0.496);
lightRange = 15.0;
break;
case BLOCK_REDSTONE_TORCH_LIT:
lightColor = vec3(0.939, 0.305, 0.164);
lightRange = 7.0;
break;
case BLOCK_RESPAWN_ANCHOR_4:
lightColor = vec3(1.0, 0.2, 1.0);
lightRange = 15.0;
break;
case BLOCK_SCULK_SENSOR_ACTIVE:
lightColor = vec3(0.1, 0.4, 1.0);
lightRange = 1.0;
break;
case BLOCK_SEA_PICKLE_WET_1:
lightColor = LightColor_SeaPickle;
lightRange = 6.0;
mixWeight = 1.0;
break;
case BLOCK_SEA_PICKLE_WET_2:
lightColor = LightColor_SeaPickle;
lightRange = 9.0;
mixWeight = 1.0;
break;
case BLOCK_SEA_PICKLE_WET_3:
lightColor = LightColor_SeaPickle;
lightRange = 12.0;
mixWeight = 1.0;
break;
case BLOCK_SEA_PICKLE_WET_4:
lightColor = LightColor_SeaPickle;
lightRange = 15.0;
mixWeight = 1.0;
break;
case BLOCK_SEA_LANTERN:
lightColor = vec3(0.553, 0.748, 0.859);
lightRange = 15.0;
break;
case BLOCK_SHROOMLIGHT:
lightColor = vec3(0.848, 0.469, 0.205);
lightRange = 15.0;
break;
case BLOCK_SMOKER_LIT:
lightColor = vec3(0.8, 0.7, 0.1);
lightRange = 13.0;
break;
case BLOCK_SOUL_FIRE:
lightColor = vec3(0.1, 0.6, 1.0);
lightRange = 10.0;
mixWeight = 1.0;
break;
case BLOCK_SOUL_LANTERN:
case BLOCK_SOUL_TORCH:
lightColor = vec3(0.1, 0.6, 1.0);
lightRange = 10.0;
mixWeight = 0.8;
break;
case BLOCK_TORCH:
lightColor = vec3(1.0, 0.6, 0.1);
lightRange = 14.0;
mixWeight = 0.8;
break;
case BLOCK_HONEY:
tintColor = vec3(0.984, 0.733, 0.251);
mixWeight = 1.0;
break;
case BLOCK_NETHER_PORTAL:
lightColor = vec3(0.502, 0.165, 0.831);
tintColor = vec3(0.502, 0.165, 0.831);
lightRange = 11.0;
mixWeight = 1.0;
break;
case BLOCK_SLIME:
tintColor = vec3(0.408, 0.725, 0.329);
mixWeight = 1.0;
break;
case BLOCK_GLASS_BLACK:
tintColor = vec3(0.3);
mixWeight = 1.0;
break;
case BLOCK_GLASS_BLUE:
tintColor = vec3(0.1, 0.1, 0.98);
mixWeight = 1.0;
break;
case BLOCK_GLASS_BROWN:
tintColor = vec3(0.566, 0.388, 0.148);
mixWeight = 1.0;
break;
case BLOCK_GLASS_CYAN:
tintColor = vec3(0.082, 0.533, 0.763);
mixWeight = 1.0;
break;
case BLOCK_GLASS_GRAY:
tintColor = vec3(0.4, 0.4, 0.4);
mixWeight = 1.0;
break;
case BLOCK_GLASS_GREEN:
tintColor = vec3(0.125, 0.808, 0.081);
mixWeight = 1.0;
break;
case BLOCK_GLASS_LIGHT_BLUE:
tintColor = vec3(0.320, 0.685, 0.955);
mixWeight = 1.0;
break;
case BLOCK_GLASS_LIGHT_GRAY:
tintColor = vec3(0.7);
mixWeight = 1.0;
break;
case BLOCK_GLASS_LIME:
tintColor = vec3(0.633, 0.924, 0.124);
mixWeight = 1.0;
break;
case BLOCK_GLASS_MAGENTA:
tintColor = vec3(0.698, 0.298, 0.847);
mixWeight = 1.0;
break;
case BLOCK_GLASS_ORANGE:
tintColor = vec3(0.919, 0.586, 0.185);
mixWeight = 1.0;
break;
case BLOCK_GLASS_PINK:
tintColor = vec3(0.949, 0.274, 0.497);
mixWeight = 1.0;
break;
case BLOCK_GLASS_PURPLE:
tintColor = vec3(0.578, 0.170, 0.904);
mixWeight = 1.0;
break;
case BLOCK_GLASS_RED:
tintColor = vec3(0.999, 0.188, 0.188);
mixWeight = 1.0;
break;
case BLOCK_GLASS_WHITE:
tintColor = vec3(0.96, 0.96, 0.96);
mixWeight = 1.0;
break;
case BLOCK_GLASS_YELLOW:
tintColor = vec3(0.965, 0.965, 0.123);
mixWeight = 1.0;
break;
case BLOCK_DOOR_N:
mixMask = BuildLpvMask(0u, 1u, 1u, 1u, 1u, 1u);
mixWeight = 0.8;
break;
case BLOCK_DOOR_E:
mixMask = BuildLpvMask(1u, 0u, 1u, 1u, 1u, 1u);
mixWeight = 0.8;
break;
case BLOCK_DOOR_S:
mixMask = BuildLpvMask(1u, 1u, 0u, 1u, 1u, 1u);
mixWeight = 0.8;
break;
case BLOCK_DOOR_W:
mixMask = BuildLpvMask(1u, 1u, 1u, 0u, 1u, 1u);
mixWeight = 0.8;
break;
case BLOCK_SLAB_TOP:
mixMask = BuildLpvMask(1u, 1u, 1u, 1u, 0u, 1u);
mixWeight = 0.5;
break;
case BLOCK_SLAB_BOTTOM:
mixMask = BuildLpvMask(1u, 1u, 1u, 1u, 1u, 0u);
mixWeight = 0.5;
break;
case BLOCK_TRAPDOOR_BOTTOM:
mixMask = BuildLpvMask(1u, 1u, 1u, 1u, 1u, 0u);
mixWeight = 0.8;
break;
case BLOCK_TRAPDOOR_TOP:
mixMask = BuildLpvMask(1u, 1u, 1u, 1u, 0u, 1u);
mixWeight = 0.8;
break;
case BLOCK_TRAPDOOR_N:
mixMask = BuildLpvMask(0u, 1u, 1u, 1u, 1u, 1u);
mixWeight = 0.8;
break;
case BLOCK_TRAPDOOR_E:
mixMask = BuildLpvMask(1u, 0u, 1u, 1u, 1u, 1u);
mixWeight = 0.8;
break;
case BLOCK_TRAPDOOR_S:
mixMask = BuildLpvMask(1u, 1u, 0u, 1u, 1u, 1u);
mixWeight = 0.8;
break;
case BLOCK_TRAPDOOR_W:
mixMask = BuildLpvMask(1u, 1u, 1u, 0u, 1u, 1u);
mixWeight = 0.8;
break;
}
LpvBlockData block;
block.ColorRange = packUnorm4x8(vec4(lightColor, lightRange/255.0));
block.MaskWeight = BuildBlockLpvData(mixMask, mixWeight);
block.Tint = packUnorm4x8(vec4(tintColor, 0.0));
LpvBlockMap[blockId - LpvBlockMapOffset] = block;
#endif
}

View File

@ -0,0 +1,157 @@
layout (local_size_x = 8, local_size_y = 8, local_size_z = 8) in;
#if LPV_SIZE == 8
const ivec3 workGroups = ivec3(32, 32, 32);
#elif LPV_SIZE == 7
const ivec3 workGroups = ivec3(16, 16, 16);
#elif LPV_SIZE == 6
const ivec3 workGroups = ivec3(8, 8, 8);
#endif
#ifdef IS_LPV_ENABLED
shared vec4 lpvSharedData[10*10*10];
shared uint voxelSharedData[10*10*10];
const vec2 LpvBlockSkyFalloff = vec2(0.96, 0.96);
const ivec3 lpvFlatten = ivec3(1, 10, 100);
#define EPSILON 1e-6
uniform int frameCounter;
uniform vec3 cameraPosition;
uniform vec3 previousCameraPosition;
#include "/lib/hsv.glsl"
#include "/lib/util.glsl"
#include "/lib/blocks.glsl"
#include "/lib/lpv_common.glsl"
#include "/lib/lpv_blocks.glsl"
#include "/lib/voxel_common.glsl"
int sumOf(ivec3 vec) {return vec.x + vec.y + vec.z;}
vec3 Lpv_RgbToHsv(const in vec3 lightColor, const in float lightRange) {
vec3 lightValue = RgbToHsv(lightColor);
lightValue.b = lightRange / LpvBlockSkyRange.x;
return lightValue;
}
vec4 GetLpvValue(in ivec3 texCoord) {
if (clamp(texCoord, ivec3(0), ivec3(LpvSize) - 1) != texCoord) return vec4(0.0);
vec4 lpvSample = (frameCounter % 2) == 0
? imageLoad(imgLpv2, texCoord)
: imageLoad(imgLpv1, texCoord);
lpvSample.ba = exp2(lpvSample.ba * LpvBlockSkyRange) - 1.0;
lpvSample.rgb = HsvToRgb(lpvSample.rgb);
return lpvSample;
}
int getSharedIndex(ivec3 pos) {
return sumOf(pos * lpvFlatten);
}
vec4 sampleShared(ivec3 pos, int mask_index) {
int shared_index = getSharedIndex(pos + 1);
float mixWeight = 1.0;
uint mixMask = 0xFFFF;
uint blockId = voxelSharedData[shared_index];
if (blockId > 0 && blockId != BLOCK_EMPTY)
ParseBlockLpvData(LpvBlockMap[blockId - LpvBlockMapOffset].MaskWeight, mixMask, mixWeight);
return lpvSharedData[shared_index] * ((mixMask >> mask_index) & 1u);// * mixWeight;
}
vec4 mixNeighbours(const in ivec3 fragCoord, const in uint mask) {
vec4 nX1 = sampleShared(fragCoord + ivec3(-1, 0, 0), 1) * ((mask ) & 1u);
vec4 nX2 = sampleShared(fragCoord + ivec3( 1, 0, 0), 0) * ((mask >> 1) & 1u);
vec4 nY1 = sampleShared(fragCoord + ivec3( 0, -1, 0), 3) * ((mask >> 2) & 1u);
vec4 nY2 = sampleShared(fragCoord + ivec3( 0, 1, 0), 2) * ((mask >> 3) & 1u);
vec4 nZ1 = sampleShared(fragCoord + ivec3( 0, 0, -1), 5) * ((mask >> 4) & 1u);
vec4 nZ2 = sampleShared(fragCoord + ivec3( 0, 0, 1), 4) * ((mask >> 5) & 1u);
const vec4 avgFalloff = (1.0/6.0) * LpvBlockSkyFalloff.xxxy;
return (nX1 + nX2 + nY1 + nY2 + nZ1 + nZ2) * avgFalloff;
}
uint GetVoxelBlock(const in ivec3 voxelPos) {
if (clamp(voxelPos, ivec3(0), ivec3(VoxelSize3-1u)) != voxelPos)
return BLOCK_EMPTY;
return imageLoad(imgVoxelMask, voxelPos).r;
}
void PopulateSharedIndex(const in ivec3 imgCoordOffset, const in ivec3 workGroupOffset, const in uint i) {
ivec3 pos = workGroupOffset + ivec3(i / lpvFlatten) % 10;
lpvSharedData[i] = GetLpvValue(imgCoordOffset + pos);
voxelSharedData[i] = GetVoxelBlock(pos);
}
#endif
////////////////////////////// VOID MAIN //////////////////////////////
void main() {
#ifdef IS_LPV_ENABLED
uvec3 chunkPos = gl_WorkGroupID * gl_WorkGroupSize;
if (any(greaterThanEqual(chunkPos, LpvSize3))) return;
uint i = uint(gl_LocalInvocationIndex) * 2u;
if (i < 1000u) {
ivec3 imgCoordOffset = ivec3(floor(cameraPosition) - floor(previousCameraPosition));
ivec3 workGroupOffset = ivec3(gl_WorkGroupID * gl_WorkGroupSize) - 1;
PopulateSharedIndex(imgCoordOffset, workGroupOffset, i);
PopulateSharedIndex(imgCoordOffset, workGroupOffset, i + 1u);
}
barrier();
ivec3 imgCoord = ivec3(gl_GlobalInvocationID);
if (any(greaterThanEqual(imgCoord, LpvSize3))) return;
uint blockId = voxelSharedData[getSharedIndex(ivec3(gl_LocalInvocationID) + 1)];
vec4 lightValue = vec4(0.0);
vec3 tintColor = vec3(1.0);
float mixWeight = 1.0;
uint mixMask = 0xFFFF;
if (blockId > 0u) {
mixWeight = 0.0;
ParseBlockLpvData(LpvBlockMap[blockId - LpvBlockMapOffset].MaskWeight, mixMask, mixWeight);
uint tintData = LpvBlockMap[blockId - LpvBlockMapOffset].Tint;
tintColor = unpackUnorm4x8(tintData).rgb;
}
if (mixWeight > EPSILON) {
vec4 lightMixed = mixNeighbours(ivec3(gl_LocalInvocationID), mixMask);
lightMixed.rgb *= srgbToLinear(tintColor) * mixWeight;
lightValue += lightMixed;
}
lightValue.rgb = RgbToHsv(lightValue.rgb);
lightValue.ba = log2(lightValue.ba + 1.0) / LpvBlockSkyRange;
if (blockId > 0u) {
vec4 lightColorRange = unpackUnorm4x8(LpvBlockMap[blockId - LpvBlockMapOffset].ColorRange);
float lightRange = lightColorRange.a * 255.0;
if (lightRange > EPSILON) {
vec3 lightColor = srgbToLinear(lightColorRange.rgb);
lightValue.rgb = Lpv_RgbToHsv(lightColor, lightRange);
}
}
if (frameCounter % 2 == 0)
imageStore(imgLpv1, imgCoord, lightValue);
else
imageStore(imgLpv2, imgCoord, lightValue);
#endif
}

View File

@ -1,3 +1,5 @@
#define BLOCK_EMPTY 0
#define BLOCK_WATER 8
#define BLOCK_BEACON 1001

View File

@ -1,9 +1,16 @@
// LPV falloff curve
const float LpvBlockPower = 4.0;
// LPV block brightness scale
const float LpvBlockBrightness = 3.0;
vec4 SampleLpvNearest(const in ivec3 lpvPos) {
vec4 lpvSample = (frameCounter % 2) == 0
? imageLoad(imgLpv1, lpvPos)
: imageLoad(imgLpv2, lpvPos);
lpvSample.b = pow(lpvSample.b, 4) * LpvBlockSkyRange.x;
lpvSample.b = pow(lpvSample.b, LpvBlockPower) * LpvBlockSkyRange.x;
lpvSample.rgb = HsvToRgb(lpvSample.rgb);
return lpvSample;
@ -37,7 +44,7 @@ vec4 SampleLpvLinear(const in vec3 lpvPos) {
}
vec3 GetLpvBlockLight(const in vec4 lpvSample) {
return 3.0 * lpvSample.rgb;
return LpvBlockBrightness * lpvSample.rgb;
}
float GetLpvSkyLight(const in vec4 lpvSample) {

View File

@ -4,10 +4,3 @@ const uint VoxelSize = uint(exp2(LPV_SIZE));
const uvec3 VoxelSize3 = uvec3(VoxelSize);
const float voxelDistance = 64.0;
#define BLOCK_EMPTY 0
ivec3 GetVoxelIndex(const in vec3 playerPos) {
vec3 cameraOffset = fract(cameraPosition);
return ivec3(floor(playerPos + cameraOffset) + VoxelSize3/2u);
}

View File

@ -1,6 +0,0 @@
uint GetVoxelBlock(const in ivec3 voxelPos) {
if (clamp(voxelPos, ivec3(0), ivec3(VoxelSize3-1u)) != voxelPos)
return BLOCK_EMPTY;
return imageLoad(imgVoxelMask, voxelPos).r;
}

View File

@ -1,3 +1,8 @@
ivec3 GetVoxelIndex(const in vec3 playerPos) {
vec3 cameraOffset = fract(cameraPosition);
return ivec3(floor(playerPos + cameraOffset) + VoxelSize3/2u);
}
void SetVoxelBlock(const in vec3 playerPos, const in uint blockId) {
ivec3 voxelPos = GetVoxelIndex(playerPos);
if (clamp(voxelPos, ivec3(0), ivec3(VoxelSize-1u)) != voxelPos) return;

View File

@ -19,6 +19,7 @@ iris.features.optional=ENTITY_TRANSLUCENT REVERSED_CULLING COMPUTE_SHADERS CUSTO
#endif
#ifdef LPV_ENABLED
shadow.enabled = true
shadow.culling = reversed
#endif

View File

@ -0,0 +1,7 @@
#version 430 compatibility
#define RENDER_SETUP
#include "/lib/settings.glsl"
#include "/dimensions/setup.csh"

View File

@ -0,0 +1,5 @@
#version 430 compatibility
#include "/lib/settings.glsl"
#include "/dimensions/shadowcomp.csh"

View File

@ -4,316 +4,4 @@
#include "/lib/settings.glsl"
layout (local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
const ivec3 workGroups = ivec3(4, 5, 1);
#ifdef IS_LPV_ENABLED
#include "/lib/blocks.glsl"
#include "/lib/lpv_blocks.glsl"
const vec3 LightColor_Candles = vec3(1.0, 0.4, 0.1);
const vec3 LightColor_SeaPickle = vec3(0.283, 0.394, 0.212);
uint BuildLpvMask(const in uint north, const in uint east, const in uint south, const in uint west, const in uint up, const in uint down) {
return east | (west << 1) | (down << 2) | (up << 3) | (south << 4) | (north << 5);
}
#endif
void main() {
#ifdef IS_LPV_ENABLED
uint blockId = uint(gl_GlobalInvocationID.x + gl_GlobalInvocationID.y * 32 + LpvBlockMapOffset);
//if (blockId >= 1280) return;
vec3 lightColor = vec3(0.0);
float lightRange = 0.0;
float mixWeight = 0.0;
uint mixMask = 0xFFFF;
vec3 tintColor = vec3(1.0);
switch (blockId) {
case BLOCK_BEACON:
lightColor = vec3(1.0);
lightRange = 15.0;
break;
case BLOCK_CANDLES_LIT_1:
lightColor = LightColor_Candles;
lightRange = 3.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_LIT_2:
lightColor = LightColor_Candles;
lightRange = 6.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_LIT_3:
lightColor = LightColor_Candles;
lightRange = 9.0;
mixWeight = 1.0;
break;
case BLOCK_CANDLES_LIT_4:
lightColor = LightColor_Candles;
lightRange = 12.0;
mixWeight = 1.0;
break;
case BLOCK_CAVE_VINE_BERRIES:
lightColor = vec3(0.717, 0.541, 0.188);
lightRange = 14.0;
mixWeight = 1.0;
break;
case BLOCK_CONDUIT:
lightColor = vec3(1.0);
lightRange = 15.0;
break;
case BLOCK_END_GATEWAY:
lightColor = vec3(1.0);
lightRange = 15.0;
break;
case BLOCK_END_ROD:
lightColor = vec3(0.957, 0.929, 0.875);
lightRange = 14.0;
break;
case BLOCK_FIRE:
lightColor = vec3(0.864, 0.598, 0.348);
lightRange = 15.0;
mixWeight = 1.0;
break;
case BLOCK_FROGLIGHT_OCHRE:
lightColor = vec3(0.768, 0.648, 0.108);
lightRange = 15.0;
break;
case BLOCK_FROGLIGHT_PEARLESCENT:
lightColor = vec3(0.737, 0.435, 0.658);
lightRange = 15.0;
break;
case BLOCK_FROGLIGHT_VERDANT:
lightColor = vec3(0.463, 0.763, 0.409);
lightRange = 15.0;
break;
case BLOCK_GLOWSTONE:
lightColor = vec3(0.747, 0.594, 0.326);
lightRange = 15.0;
break;
case BLOCK_JACK_O_LANTERN:
lightColor = vec3(1.0, 0.7, 0.1);
lightRange = 15.0;
break;
case BLOCK_LANTERN:
lightColor = vec3(1.0, 0.7, 0.1);
lightRange = 15.0;
mixWeight = 0.8;
break;
case BLOCK_LAVA:
lightColor = vec3(0.804, 0.424, 0.149);
lightRange = 15.0;
break;
case BLOCK_MAGMA:
lightColor = vec3(0.747, 0.323, 0.110);
lightRange = 3.0;
break;
case BLOCK_REDSTONE_LAMP_LIT:
lightColor = vec3(0.953, 0.796, 0.496);
lightRange = 15.0;
break;
case BLOCK_REDSTONE_TORCH_LIT:
lightColor = vec3(0.939, 0.305, 0.164);
lightRange = 7.0;
break;
case BLOCK_RESPAWN_ANCHOR_4:
lightColor = vec3(1.0, 0.2, 1.0);
lightRange = 15.0;
break;
case BLOCK_SCULK_SENSOR_ACTIVE:
lightColor = vec3(0.1, 0.4, 1.0);
lightRange = 1.0;
break;
case BLOCK_SEA_PICKLE_WET_1:
lightColor = LightColor_SeaPickle;
lightRange = 6.0;
mixWeight = 1.0;
break;
case BLOCK_SEA_PICKLE_WET_2:
lightColor = LightColor_SeaPickle;
lightRange = 9.0;
mixWeight = 1.0;
break;
case BLOCK_SEA_PICKLE_WET_3:
lightColor = LightColor_SeaPickle;
lightRange = 12.0;
mixWeight = 1.0;
break;
case BLOCK_SEA_PICKLE_WET_4:
lightColor = LightColor_SeaPickle;
lightRange = 15.0;
mixWeight = 1.0;
break;
case BLOCK_SEA_LANTERN:
lightColor = vec3(0.553, 0.748, 0.859);
lightRange = 15.0;
break;
case BLOCK_SHROOMLIGHT:
lightColor = vec3(0.848, 0.469, 0.205);
lightRange = 15.0;
break;
case BLOCK_SMOKER_LIT:
lightColor = vec3(0.8, 0.7, 0.1);
lightRange = 13.0;
break;
case BLOCK_SOUL_FIRE:
lightColor = vec3(0.1, 0.6, 1.0);
lightRange = 10.0;
mixWeight = 1.0;
break;
case BLOCK_SOUL_LANTERN:
case BLOCK_SOUL_TORCH:
lightColor = vec3(0.1, 0.6, 1.0);
lightRange = 10.0;
mixWeight = 0.8;
break;
case BLOCK_TORCH:
lightColor = vec3(1.0, 0.6, 0.1);
lightRange = 14.0;
mixWeight = 0.8;
break;
case BLOCK_HONEY:
tintColor = vec3(0.984, 0.733, 0.251);
mixWeight = 1.0;
break;
case BLOCK_NETHER_PORTAL:
lightColor = vec3(0.502, 0.165, 0.831);
tintColor = vec3(0.502, 0.165, 0.831);
lightRange = 11.0;
mixWeight = 1.0;
break;
case BLOCK_SLIME:
tintColor = vec3(0.408, 0.725, 0.329);
mixWeight = 1.0;
break;
case BLOCK_GLASS_BLACK:
tintColor = vec3(0.3);
mixWeight = 1.0;
break;
case BLOCK_GLASS_BLUE:
tintColor = vec3(0.1, 0.1, 0.98);
mixWeight = 1.0;
break;
case BLOCK_GLASS_BROWN:
tintColor = vec3(0.566, 0.388, 0.148);
mixWeight = 1.0;
break;
case BLOCK_GLASS_CYAN:
tintColor = vec3(0.082, 0.533, 0.763);
mixWeight = 1.0;
break;
case BLOCK_GLASS_GRAY:
tintColor = vec3(0.4, 0.4, 0.4);
mixWeight = 1.0;
break;
case BLOCK_GLASS_GREEN:
tintColor = vec3(0.125, 0.808, 0.081);
mixWeight = 1.0;
break;
case BLOCK_GLASS_LIGHT_BLUE:
tintColor = vec3(0.320, 0.685, 0.955);
mixWeight = 1.0;
break;
case BLOCK_GLASS_LIGHT_GRAY:
tintColor = vec3(0.7);
mixWeight = 1.0;
break;
case BLOCK_GLASS_LIME:
tintColor = vec3(0.633, 0.924, 0.124);
mixWeight = 1.0;
break;
case BLOCK_GLASS_MAGENTA:
tintColor = vec3(0.698, 0.298, 0.847);
mixWeight = 1.0;
break;
case BLOCK_GLASS_ORANGE:
tintColor = vec3(0.919, 0.586, 0.185);
mixWeight = 1.0;
break;
case BLOCK_GLASS_PINK:
tintColor = vec3(0.949, 0.274, 0.497);
mixWeight = 1.0;
break;
case BLOCK_GLASS_PURPLE:
tintColor = vec3(0.578, 0.170, 0.904);
mixWeight = 1.0;
break;
case BLOCK_GLASS_RED:
tintColor = vec3(0.999, 0.188, 0.188);
mixWeight = 1.0;
break;
case BLOCK_GLASS_WHITE:
tintColor = vec3(0.96, 0.96, 0.96);
mixWeight = 1.0;
break;
case BLOCK_GLASS_YELLOW:
tintColor = vec3(0.965, 0.965, 0.123);
mixWeight = 1.0;
break;
case BLOCK_DOOR_N:
mixMask = BuildLpvMask(0u, 1u, 1u, 1u, 1u, 1u);
mixWeight = 0.8;
break;
case BLOCK_DOOR_E:
mixMask = BuildLpvMask(1u, 0u, 1u, 1u, 1u, 1u);
mixWeight = 0.8;
break;
case BLOCK_DOOR_S:
mixMask = BuildLpvMask(1u, 1u, 0u, 1u, 1u, 1u);
mixWeight = 0.8;
break;
case BLOCK_DOOR_W:
mixMask = BuildLpvMask(1u, 1u, 1u, 0u, 1u, 1u);
mixWeight = 0.8;
break;
case BLOCK_SLAB_TOP:
mixMask = BuildLpvMask(1u, 1u, 1u, 1u, 0u, 1u);
mixWeight = 0.5;
break;
case BLOCK_SLAB_BOTTOM:
mixMask = BuildLpvMask(1u, 1u, 1u, 1u, 1u, 0u);
mixWeight = 0.5;
break;
case BLOCK_TRAPDOOR_BOTTOM:
mixMask = BuildLpvMask(1u, 1u, 1u, 1u, 1u, 0u);
mixWeight = 0.8;
break;
case BLOCK_TRAPDOOR_TOP:
mixMask = BuildLpvMask(1u, 1u, 1u, 1u, 0u, 1u);
mixWeight = 0.8;
break;
case BLOCK_TRAPDOOR_N:
mixMask = BuildLpvMask(0u, 1u, 1u, 1u, 1u, 1u);
mixWeight = 0.8;
break;
case BLOCK_TRAPDOOR_E:
mixMask = BuildLpvMask(1u, 0u, 1u, 1u, 1u, 1u);
mixWeight = 0.8;
break;
case BLOCK_TRAPDOOR_S:
mixMask = BuildLpvMask(1u, 1u, 0u, 1u, 1u, 1u);
mixWeight = 0.8;
break;
case BLOCK_TRAPDOOR_W:
mixMask = BuildLpvMask(1u, 1u, 1u, 0u, 1u, 1u);
mixWeight = 0.8;
break;
}
LpvBlockData block;
block.ColorRange = packUnorm4x8(vec4(lightColor, lightRange/255.0));
block.MaskWeight = BuildBlockLpvData(mixMask, mixWeight);
block.Tint = packUnorm4x8(vec4(tintColor, 0.0));
LpvBlockMap[blockId - LpvBlockMapOffset] = block;
#endif
}
#include "/dimensions/setup.csh"

View File

@ -2,166 +2,4 @@
#include "/lib/settings.glsl"
layout (local_size_x = 8, local_size_y = 8, local_size_z = 8) in;
#if LPV_SIZE == 8
const ivec3 workGroups = ivec3(32, 32, 32);
#elif LPV_SIZE == 7
const ivec3 workGroups = ivec3(16, 16, 16);
#elif LPV_SIZE == 6
const ivec3 workGroups = ivec3(8, 8, 8);
#endif
#ifdef IS_LPV_ENABLED
shared vec4 lpvSharedData[10*10*10];
shared uint voxelSharedData[10*10*10];
const vec2 LpvBlockSkyFalloff = vec2(0.96, 0.96);
const ivec3 lpvFlatten = ivec3(1, 10, 100);
#define GAMMA 2.2
#define EPSILON 1e-6
uniform int frameCounter;
uniform vec3 cameraPosition;
uniform vec3 previousCameraPosition;
#include "/lib/hsv.glsl"
#include "/lib/blocks.glsl"
#include "/lib/lpv_common.glsl"
#include "/lib/lpv_blocks.glsl"
#include "/lib/voxel_common.glsl"
#include "/lib/voxel_read.glsl"
int sumOf(ivec3 vec) {return vec.x + vec.y + vec.z;}
vec3 RGBToLinear(const in vec3 color) {
return pow(color, vec3(GAMMA));
}
vec3 Lpv_RgbToHsv(const in vec3 lightColor, const in float lightRange) {
vec3 lightValue = RgbToHsv(lightColor);
lightValue.b = lightRange / LpvBlockSkyRange.x;
return lightValue;
}
vec4 GetLpvValue(in ivec3 texCoord) {
if (clamp(texCoord, ivec3(0), ivec3(LpvSize) - 1) != texCoord) return vec4(0.0);
vec4 lpvSample = (frameCounter % 2) == 0
? imageLoad(imgLpv2, texCoord)
: imageLoad(imgLpv1, texCoord);
lpvSample.ba = exp2(lpvSample.ba * LpvBlockSkyRange) - 1.0;
lpvSample.rgb = HsvToRgb(lpvSample.rgb);
return lpvSample;
}
int getSharedCoord(ivec3 pos) {
return sumOf(pos * lpvFlatten);
}
vec4 sampleShared(ivec3 pos) {
return lpvSharedData[getSharedCoord(pos + 1)];
}
vec4 sampleShared(ivec3 pos, int mask_index) {
int shared_index = getSharedCoord(pos + 1);
float mixWeight = 1.0;
uint mixMask = 0xFFFF;
uint blockId = voxelSharedData[shared_index];
if (blockId > 0 && blockId != BLOCK_EMPTY)
ParseBlockLpvData(LpvBlockMap[blockId - LpvBlockMapOffset].MaskWeight, mixMask, mixWeight);
return lpvSharedData[shared_index] * ((mixMask >> mask_index) & 1u);// * mixWeight;
}
vec4 mixNeighbours(const in ivec3 fragCoord, const in uint mask) {
vec4 nX1 = sampleShared(fragCoord + ivec3(-1, 0, 0), 1) * ((mask ) & 1u);
vec4 nX2 = sampleShared(fragCoord + ivec3( 1, 0, 0), 0) * ((mask >> 1) & 1u);
vec4 nY1 = sampleShared(fragCoord + ivec3( 0, -1, 0), 3) * ((mask >> 2) & 1u);
vec4 nY2 = sampleShared(fragCoord + ivec3( 0, 1, 0), 2) * ((mask >> 3) & 1u);
vec4 nZ1 = sampleShared(fragCoord + ivec3( 0, 0, -1), 5) * ((mask >> 4) & 1u);
vec4 nZ2 = sampleShared(fragCoord + ivec3( 0, 0, 1), 4) * ((mask >> 5) & 1u);
const vec4 avgFalloff = (1.0/6.0) * LpvBlockSkyFalloff.xxxy;
return (nX1 + nX2 + nY1 + nY2 + nZ1 + nZ2) * avgFalloff;
}
void PopulateSharedIndex(const in ivec3 imgCoordOffset, const in ivec3 workGroupOffset, const in uint i) {
ivec3 pos = workGroupOffset + ivec3(i / lpvFlatten) % 10;
//ivec3 lpvPos = imgCoordOffset + pos;
lpvSharedData[i] = GetLpvValue(imgCoordOffset + pos);
voxelSharedData[i] = GetVoxelBlock(pos);
}
void PopulateShared() {
uint i = uint(gl_LocalInvocationIndex) * 2u;
if (i >= 1000u) return;
ivec3 imgCoordOffset = ivec3(floor(cameraPosition) - floor(previousCameraPosition));
ivec3 workGroupOffset = ivec3(gl_WorkGroupID * gl_WorkGroupSize) - 1;
PopulateSharedIndex(imgCoordOffset, workGroupOffset, i);
PopulateSharedIndex(imgCoordOffset, workGroupOffset, i + 1u);
}
#endif
////////////////////////////// VOID MAIN //////////////////////////////
void main() {
#ifdef IS_LPV_ENABLED
uvec3 chunkPos = gl_WorkGroupID * gl_WorkGroupSize;
if (any(greaterThanEqual(chunkPos, LpvSize3))) return;
PopulateShared();
barrier();
ivec3 imgCoord = ivec3(gl_GlobalInvocationID);
if (any(greaterThanEqual(imgCoord, LpvSize3))) return;
vec4 lightValue = vec4(0.0);
uint mixMask = 0xFFFF;
uint blockId = voxelSharedData[getSharedCoord(ivec3(gl_LocalInvocationID) + 1)];
float mixWeight = blockId == BLOCK_EMPTY ? 1.0 : 0.0;
vec3 tintColor = vec3(1.0);
if (blockId > 0u) {//&& blockId != BLOCK_EMPTY)
ParseBlockLpvData(LpvBlockMap[blockId - LpvBlockMapOffset].MaskWeight, mixMask, mixWeight);
uint tintData = LpvBlockMap[blockId - LpvBlockMapOffset].Tint;
tintColor = unpackUnorm4x8(tintData).rgb;
}
if (mixWeight > EPSILON) {
vec4 lightMixed = mixNeighbours(ivec3(gl_LocalInvocationID), mixMask);
lightMixed.rgb *= RGBToLinear(tintColor) * mixWeight;
lightValue += lightMixed;
}
lightValue.rgb = RgbToHsv(lightValue.rgb);
lightValue.ba = log2(lightValue.ba + 1.0) / LpvBlockSkyRange;
if (blockId > 0u) {// && blockId != BLOCK_EMPTY) {
vec4 lightColorRange = unpackUnorm4x8(LpvBlockMap[blockId - LpvBlockMapOffset].ColorRange);
float lightRange = lightColorRange.a * 255.0;
if (lightRange > EPSILON) {
vec3 lightColor = RGBToLinear(lightColorRange.rgb);
lightValue.rgb = Lpv_RgbToHsv(lightColor, lightRange);
}
}
if (frameCounter % 2 == 0)
imageStore(imgLpv1, imgCoord, lightValue);
else
imageStore(imgLpv2, imgCoord, lightValue);
#endif
}
#include "/dimensions/shadowcomp.csh"

7
shaders/world1/setup.csh Normal file
View File

@ -0,0 +1,7 @@
#version 430 compatibility
#define RENDER_SETUP
#include "/lib/settings.glsl"
#include "/dimensions/setup.csh"

View File

@ -0,0 +1,5 @@
#version 430 compatibility
#include "/lib/settings.glsl"
#include "/dimensions/shadowcomp.csh"