itemdrop cleanup and some small fixes.

This commit is contained in:
IntegratedQuantum 2023-01-30 17:23:53 +01:00
parent c1fac3ff3e
commit be52c1054d
8 changed files with 9 additions and 188 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 778 B

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@ -1,43 +0,0 @@
#version 430
in vec3 outTexCoord;
in vec3 mvVertexPos;
in vec3 outLight;
out vec4 fragColor;
struct Fog {
bool activ;
vec3 color;
float density;
};
uniform sampler2DArray texture_sampler;
uniform sampler2DArray emissionSampler;
uniform Fog fog;
vec4 ambientC;
void setupColors(vec3 textCoord) {
ambientC = texture(texture_sampler, textCoord);
}
vec4 calcFog(vec3 pos, vec4 color, Fog fog) {
float distance = length(pos);
float fogFactor = 1.0/exp((distance*fog.density)*(distance*fog.density));
fogFactor = clamp(fogFactor, 0.0, 1.0);
vec3 resultColor = mix(fog.color, color.xyz, fogFactor);
return vec4(resultColor.xyz, color.w);
}
void main() {
setupColors(outTexCoord);
fragColor = ambientC*vec4(outLight, 1);
fragColor.rgb += texture(emissionSampler, outTexCoord).rgb;
if (fog.activ) {
fragColor = calcFog(mvVertexPos, fragColor, fog);
}
fragColor.rgb /= 4;
}

View File

@ -1,61 +0,0 @@
#version 430
layout (location=0) in vec3 position;
layout (location=1) in vec2 texCoord;
layout (location=2) in vec3 vertexNormal;
out vec3 outTexCoord;
out vec3 mvVertexPos;
out float outSelected;
out vec3 outLight;
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform int light;
uniform vec3 ambientLight;
uniform vec3 directionalLight;
uniform int texPosX;
uniform int texNegX;
uniform int texPosY;
uniform int texNegY;
uniform int texPosZ;
uniform int texNegZ;
vec3 calcLight(int srgb) {
float s = (srgb >> 24) & 255;
float r = (srgb >> 16) & 255;
float g = (srgb >> 8) & 255;
float b = (srgb >> 0) & 255;
s = s*(1 - dot(directionalLight, vertexNormal));
r = max(s*ambientLight.x, r);
g = max(s*ambientLight.y, g);
b = max(s*ambientLight.z, b);
return vec3(r, g, b);
}
void main()
{
vec4 mvPos = viewMatrix * vec4(position, 1);
gl_Position = projectionMatrix * mvPos;
int texture = 0;
if (vertexNormal == vec3(1, 0, 0)) {
texture = texPosX;
} else if (vertexNormal == vec3(-1, 0, 0)) {
texture = texNegX;
} else if (vertexNormal == vec3(0, 1, 0)) {
texture = texPosY;
} else if (vertexNormal == vec3(0, -1, 0)) {
texture = texNegY;
} else if (vertexNormal == vec3(0, 0, 1)) {
texture = texPosZ;
} else if (vertexNormal == vec3(0, 0, -1)) {
texture = texNegZ;
} else {
texture = texNegX;
}
outLight = calcLight(light)/255;
outTexCoord = vec3(texCoord, float(texture));
mvVertexPos = mvPos.xyz;
}

View File

@ -56,7 +56,7 @@ void main() {
voxelModel = voxelModelIndex;
blockType = block;
startPosition = lower + vec3(upper)*0.999*pos;
startPosition = lower + vec3(upper - lower)*0.999*pos;
vec4 worldSpace = modelMatrix*vec4(pos*(upper - lower)*sizeScale + sizeScale/2, 1);
direction = (transpose(mat3(modelMatrix))*worldSpace.xyz).xyz;

View File

@ -531,25 +531,6 @@ pub const ClientItemDropManager = struct {
};
pub const ItemDropRenderer = struct {
//
// // uniform locations:
// private static ShaderProgram shader;
// public static int loc_projectionMatrix;
// public static int loc_viewMatrix;
// public static int loc_texture_sampler;
// public static int loc_emissionSampler;
// public static int loc_fog_activ;
// public static int loc_fog_color;
// public static int loc_fog_density;
// public static int loc_ambientLight;
// public static int loc_directionalLight;
// public static int loc_light;
// public static int loc_texPosX;
// public static int loc_texNegX;
// public static int loc_texPosY;
// public static int loc_texNegY;
// public static int loc_texPosZ;
// public static int loc_texNegZ;
var itemShader: graphics.Shader = undefined;
var itemUniforms: struct {
projectionMatrix: c_int,
@ -643,12 +624,6 @@ pub const ItemDropRenderer = struct {
};
pub fn init() !void {
// if (shader != null) {
// shader.cleanup();
// }
// shader = new ShaderProgram(Utils.loadResource(shaders + "/block_drop.vs"),
// Utils.loadResource(shaders + "/block_drop.fs"),
// BlockDropRenderer.class);
itemShader = try graphics.Shader.create("assets/cubyz/shaders/item_drop.vs", "assets/cubyz/shaders/item_drop.fs");
itemUniforms = itemShader.bulkGetUniformLocation(@TypeOf(itemUniforms));
itemModelSSBO = graphics.SSBO.init();
@ -793,58 +768,4 @@ pub const ItemDropRenderer = struct {
}
}
}
};
//public final class BlockDropRenderer {
//
// private static void renderBlockDrops(FrustumIntersection frustumInt, Vector3f ambientLight, DirectionalLight directionalLight, Vector3d playerPosition) {
// glActiveTexture(GL_TEXTURE0);
// Meshes.blockTextureArray.bind();
// glActiveTexture(GL_TEXTURE1);
// Meshes.emissionTextureArray.bind();
// shader.bind();
// shader.setUniform(loc_fog_activ, Cubyz.fog.isActive());
// shader.setUniform(loc_fog_color, Cubyz.fog.getColor());
// shader.setUniform(loc_fog_density, Cubyz.fog.getDensity());
// shader.setUniform(loc_projectionMatrix, Window.getProjectionMatrix());
// shader.setUniform(loc_texture_sampler, 0);
// shader.setUniform(loc_emissionSampler, 1);
// shader.setUniform(loc_ambientLight, ambientLight);
// shader.setUniform(loc_directionalLight, directionalLight.getDirection());
// ItemEntityManager manager = Cubyz.world.itemEntityManager;
// for(int ii = 0; ii < manager.size; ii++) {
// int i = manager.indices[ii] & 0xffff;
// if (manager.itemStacks[i].getItem() instanceof ItemBlock) {
// int index = i;
// int index3 = 3*i;
// int x = (int)(manager.posxyz[index3] + 1.0f);
// int y = (int)(manager.posxyz[index3+1] + 1.0f);
// int z = (int)(manager.posxyz[index3+2] + 1.0f);
// int block = ((ItemBlock)manager.itemStacks[i].getItem()).getBlock();
// Mesh mesh = BlockMeshes.mesh(block & Blocks.TYPE_MASK);
// mesh.setTexture(null);
// shader.setUniform(loc_texNegX, BlockMeshes.textureIndices(block)[Neighbors.DIR_NEG_X]);
// shader.setUniform(loc_texPosX, BlockMeshes.textureIndices(block)[Neighbors.DIR_POS_X]);
// shader.setUniform(loc_texNegY, BlockMeshes.textureIndices(block)[Neighbors.DIR_DOWN]);
// shader.setUniform(loc_texPosY, BlockMeshes.textureIndices(block)[Neighbors.DIR_UP]);
// shader.setUniform(loc_texNegZ, BlockMeshes.textureIndices(block)[Neighbors.DIR_NEG_Z]);
// shader.setUniform(loc_texPosZ, BlockMeshes.textureIndices(block)[Neighbors.DIR_POS_Z]);
// if (mesh != null) {
// shader.setUniform(loc_light, Cubyz.world.getLight(x, y, z, ambientLight, ClientSettings.easyLighting));
// Vector3d position = manager.getPosition(index).sub(playerPosition);
// Matrix4f modelMatrix = Transformation.getModelMatrix(new Vector3f((float)position.x, (float)position.y, (float)position.z), manager.getRotation(index), ItemEntityManager.DIAMETER);
// Matrix4f modelViewMatrix = Transformation.getModelViewMatrix(modelMatrix, Camera.getViewMatrix());
// shader.setUniform(loc_viewMatrix, modelViewMatrix);
// glBindVertexArray(mesh.vaoId);
// mesh.render();
// }
// }
// }
// }
//
// public static void render(FrustumIntersection frustumInt, Vector3f ambientLight, DirectionalLight directionalLight, Vector3d playerPosition) {
// ((InterpolatedItemEntityManager)Cubyz.world.itemEntityManager).updateInterpolationData();
// renderBlockDrops(frustumInt, ambientLight, directionalLight, playerPosition);
// renderItemDrops(frustumInt, ambientLight, directionalLight, playerPosition);
// }
//}
};

View File

@ -31,7 +31,7 @@ pub var threadPool: utils.ThreadPool = undefined;
var logFile: std.fs.File = undefined;
// overwrite the log function:
pub const std_options = struct {
pub const log_level = .info;
pub const log_level = .debug;
pub fn logFn(
comptime level: std.log.Level,
comptime _: @Type(.EnumLiteral),

View File

@ -97,6 +97,10 @@ const Address = struct {
ip: u32,
port: u16,
isSymmetricNAT: bool = false,
pub fn format(self: Address, _: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void {
try writer.print("{}.{}.{}.{}:{}", .{self.ip & 255, self.ip >> 8 & 255, self.ip >> 16 & 255, self.ip >> 24, self.port});
}
};
const Request = struct {
@ -280,7 +284,7 @@ const STUN = struct {
continue;
};
if(oldAddress) |other| {
std.log.info("{}.{}.{}.{}:{}", .{result.ip & 255, result.ip >> 8 & 255, result.ip >> 16 & 255, result.ip >> 24, result.port});
std.log.info("{}", .{result});
if(other.ip == result.ip and other.port == result.port) {
return result;
} else {

View File

@ -29,7 +29,7 @@ pub var bloom: bool = true;
pub var playerName: []const u8 = "quanturmdoelvloper";
pub var lastUsedIPAddress: []const u8 = "localhost";
pub var lastUsedIPAddress: []const u8 = "127.0.0.1";
pub fn init() !void {