diff --git a/assets/cubyz/shaders/animation_pre_processing.glsl b/assets/cubyz/shaders/animation_pre_processing.glsl index 8cc9654d..4d46bfe7 100644 --- a/assets/cubyz/shaders/animation_pre_processing.glsl +++ b/assets/cubyz/shaders/animation_pre_processing.glsl @@ -3,12 +3,12 @@ layout (local_size_x = 64, local_size_y = 1, local_size_z = 1) in; struct AnimationData { - int frames; - int time; + uint frames; + uint time; }; struct TextureData { - int textureIndices[6]; + uint textureIndices[6]; uint absorption; float reflectivity; float fogDensity; @@ -28,14 +28,14 @@ layout(std430, binding = 1) buffer _textureDataOut TextureData textureDataOut[]; }; -uniform int time; -uniform int size; +uniform uint time; +uniform uint size; void main() { uint index = gl_GlobalInvocationID.x; if(index >= size) return; for(int i = 0; i < 6; i++) { - int textureIndex = textureDataIn[index].textureIndices[i]; + uint textureIndex = textureDataIn[index].textureIndices[i]; textureIndex = textureIndex + time / animation[textureIndex].time % animation[textureIndex].frames; textureDataOut[index].textureIndices[i] = textureIndex; } diff --git a/assets/cubyz/shaders/chunks/chunk_fragment.fs b/assets/cubyz/shaders/chunks/chunk_fragment.fs index a7b33d04..d3cdfef0 100644 --- a/assets/cubyz/shaders/chunks/chunk_fragment.fs +++ b/assets/cubyz/shaders/chunks/chunk_fragment.fs @@ -19,7 +19,7 @@ uniform sampler2DArray emissionSampler; layout(location = 0) out vec4 fragColor; struct TextureData { - int textureIndices[6]; + uint textureIndices[6]; uint absorption; float reflectivity; float fogDensity; @@ -79,7 +79,7 @@ vec2 getTextureCoordsNormal(vec3 voxelPosition, int textureDir) { } void main() { - int textureIndex = textureData[blockType].textureIndices[faceNormal]; + uint textureIndex = textureData[blockType].textureIndices[faceNormal]; float normalVariation = normalVariations[faceNormal]; vec3 textureCoords = vec3(getTextureCoordsNormal(startPosition/16, faceNormal), textureIndex); fragColor = texture(texture_sampler, textureCoords)*vec4(light*normalVariation, 1); diff --git a/assets/cubyz/shaders/chunks/transparent_fragment.fs b/assets/cubyz/shaders/chunks/transparent_fragment.fs index a4f9afc7..b0aeda9a 100644 --- a/assets/cubyz/shaders/chunks/transparent_fragment.fs +++ b/assets/cubyz/shaders/chunks/transparent_fragment.fs @@ -28,7 +28,7 @@ struct Fog { }; struct TextureData { - int textureIndices[6]; + uint textureIndices[6]; uint absorption; float reflectivity; float fogDensity; @@ -134,7 +134,7 @@ vec4 fixedCubeMapLookup(vec3 v) { // Taken from http://the-witness.net/news/2012 } void main() { - int textureIndex = textureData[blockType].textureIndices[faceNormal]; + uint textureIndex = textureData[blockType].textureIndices[faceNormal]; vec3 textureCoords = vec3(getTextureCoordsNormal(startPosition/16, faceNormal), textureIndex); float normalVariation = normalVariations[faceNormal]; float densityAdjustment = sqrt(dot(mvVertexPos, mvVertexPos))/abs(mvVertexPos.z); diff --git a/assets/cubyz/shaders/chunks/voxel_model_fragment.fs b/assets/cubyz/shaders/chunks/voxel_model_fragment.fs index 51444492..8f5021ab 100644 --- a/assets/cubyz/shaders/chunks/voxel_model_fragment.fs +++ b/assets/cubyz/shaders/chunks/voxel_model_fragment.fs @@ -27,7 +27,7 @@ struct VoxelModel { }; struct TextureData { - int textureIndices[6]; + uint textureIndices[6]; uint absorption; float reflectivity; float fogDensity; @@ -177,7 +177,7 @@ float perpendicularFwidth(vec3 direction) { // Estimates how big fwidth would be return 16*length(variance); } -vec4 mipMapSample(sampler2DArray texture, ivec2 textureCoords, int textureIndex, float lod) { // TODO: anisotropic filtering? +vec4 mipMapSample(sampler2DArray texture, ivec2 textureCoords, uint textureIndex, float lod) { // TODO: anisotropic filtering? int lowerLod = int(floor(lod)); int higherLod = lowerLod+1; float interpolation = lod - lowerLod; @@ -225,7 +225,7 @@ void main() { result = RayMarchResult(true, faceNormal, faceNormal, ivec3(startPosition) & 15); // At some point it doesn't make sense to even draw the model. } if(!result.hitAThing) discard; - int textureIndex = textureData[blockType].textureIndices[result.textureDir]; + uint textureIndex = textureData[blockType].textureIndices[result.textureDir]; float normalVariation = normalVariations[result.normal]; float lod = getLod(result.voxelPosition, result.normal, direction, variance); ivec2 textureCoords = getTextureCoords(result.voxelPosition, result.textureDir); diff --git a/assets/cubyz/shaders/item_drop.fs b/assets/cubyz/shaders/item_drop.fs index 92a305cb..9e05a85d 100644 --- a/assets/cubyz/shaders/item_drop.fs +++ b/assets/cubyz/shaders/item_drop.fs @@ -43,22 +43,13 @@ struct VoxelModel { uint bitPackedData[modelSize*modelSize*modelSize/8]; }; -struct AnimationData { - int frames; - int time; -}; - struct TextureData { - int textureIndices[6]; + uint textureIndices[6]; uint absorption; float reflectivity; }; -layout(std430, binding = 0) buffer _animation -{ - AnimationData animation[]; -}; layout(std430, binding = 1) buffer _textureData { TextureData textureData[]; @@ -180,7 +171,7 @@ float perpendicularFwidth(vec3 direction) { // Estimates how big fwidth would be return 8*length(variance); } -vec4 mipMapSample(sampler2DArray texture, ivec2 textureCoords, int textureIndex, float lod) { // TODO: anisotropic filtering? +vec4 mipMapSample(sampler2DArray texture, ivec2 textureCoords, uint textureIndex, float lod) { // TODO: anisotropic filtering? int lowerLod = int(floor(lod)); int higherLod = lowerLod+1; float interpolation = lod - lowerLod; @@ -198,8 +189,7 @@ void mainBlockDrop() { result = RayMarchResult(true, faceNormal, faceNormal, ivec3(startPosition)); // At some point it doesn't make sense to even draw the model. } if(!result.hitAThing) discard; - int textureIndex = textureData[blockType].textureIndices[result.textureDir]; - textureIndex = textureIndex + time / animation[textureIndex].time % animation[textureIndex].frames; + uint textureIndex = textureData[blockType].textureIndices[result.textureDir]; float normalVariation = normalVariations[result.normal]; float lod = getLod(result.voxelPosition, result.normal, direction, variance); ivec2 textureCoords = getTextureCoords(result.voxelPosition, result.textureDir); diff --git a/src/blocks.zig b/src/blocks.zig index d267f5f8..11611034 100644 --- a/src/blocks.zig +++ b/src/blocks.zig @@ -565,8 +565,8 @@ pub const meshes = struct { pub fn preProcessAnimationData(time: u32) void { animationShader.bind(); - graphics.c.glUniform1i(animationUniforms.time, @bitCast(time)); - graphics.c.glUniform1i(animationUniforms.size, @intCast(meshes.size)); + graphics.c.glUniform1ui(animationUniforms.time, time); + graphics.c.glUniform1ui(animationUniforms.size, @intCast(meshes.size)); graphics.c.glDispatchCompute(@divFloor(meshes.size + 63, 64), 1, 1); // TODO: Replace with @divCeil once available graphics.c.glMemoryBarrier(graphics.c.GL_SHADER_STORAGE_BARRIER_BIT); }