mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-08-03 11:17:05 -04:00
Prevent signed integer modulo in the animation frame calculation.
fixes #176 This created negative values when the time was negative, resulting in wrong animation frames.
This commit is contained in:
parent
7a640132ff
commit
df075aa7df
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user