mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-08-03 11:17:05 -04:00
Add basic lighting for entity rendering.
This commit is contained in:
parent
ae4b60349e
commit
b50ffa5ea7
@ -9,7 +9,7 @@ uniform mat4 projectionMatrix;
|
||||
uniform mat4 viewMatrix;
|
||||
uniform vec3 ambientLight;
|
||||
uniform vec3 directionalLight;
|
||||
uniform int light;
|
||||
uniform uint light;
|
||||
|
||||
struct QuadInfo {
|
||||
vec3 normal;
|
||||
@ -24,15 +24,18 @@ layout(std430, binding = 11) buffer _quads
|
||||
QuadInfo quads[];
|
||||
};
|
||||
|
||||
vec3 calcLight(int srgb) {
|
||||
float s = (srgb >> 24) & 255;
|
||||
float r = (srgb >> 16) & 255;
|
||||
float g = (srgb >> 8) & 255;
|
||||
float b = (srgb >> 0) & 255;
|
||||
r = max(s*ambientLight.x, r);
|
||||
g = max(s*ambientLight.y, g);
|
||||
b = max(s*ambientLight.z, b);
|
||||
return vec3(r, g, b)/255;
|
||||
vec3 calcLight(uint fullLight) {
|
||||
vec3 sunLight = vec3(
|
||||
fullLight >> 25 & 31u,
|
||||
fullLight >> 20 & 31u,
|
||||
fullLight >> 15 & 31u
|
||||
);
|
||||
vec3 blockLight = vec3(
|
||||
fullLight >> 10 & 31u,
|
||||
fullLight >> 5 & 31u,
|
||||
fullLight >> 0 & 31u
|
||||
);
|
||||
return max(sunLight*ambientLight, blockLight)/31;
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
@ -175,7 +175,16 @@ pub const ClientEntityManager = struct {
|
||||
for(entities.items()) |ent| {
|
||||
if(ent.id == game.Player.id) continue; // don't render local player
|
||||
|
||||
c.glUniform1i(uniforms.light, @bitCast(@as(u32, 0xffffffff))); // TODO: Lighting
|
||||
const blockPos: vec.Vec3i = @intFromFloat(@floor(ent.pos));
|
||||
const lightVals: [6]u8 = main.renderer.mesh_storage.getLight(blockPos[0], blockPos[1], blockPos[2]) orelse .{0} ** 6;
|
||||
const light = (@as(u32, lightVals[0] >> 3) << 25 |
|
||||
@as(u32, lightVals[1] >> 3) << 20 |
|
||||
@as(u32, lightVals[2] >> 3) << 15 |
|
||||
@as(u32, lightVals[3] >> 3) << 10 |
|
||||
@as(u32, lightVals[4] >> 3) << 5 |
|
||||
@as(u32, lightVals[5] >> 3) << 0);
|
||||
|
||||
c.glUniform1ui(uniforms.light, @bitCast(@as(u32, light)));
|
||||
|
||||
const pos: Vec3d = ent.getRenderPosition() - playerPos;
|
||||
const modelMatrix = (Mat4f.identity()
|
||||
|
Loading…
x
Reference in New Issue
Block a user