mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-08-03 19:28:49 -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 mat4 viewMatrix;
|
||||||
uniform vec3 ambientLight;
|
uniform vec3 ambientLight;
|
||||||
uniform vec3 directionalLight;
|
uniform vec3 directionalLight;
|
||||||
uniform int light;
|
uniform uint light;
|
||||||
|
|
||||||
struct QuadInfo {
|
struct QuadInfo {
|
||||||
vec3 normal;
|
vec3 normal;
|
||||||
@ -24,15 +24,18 @@ layout(std430, binding = 11) buffer _quads
|
|||||||
QuadInfo quads[];
|
QuadInfo quads[];
|
||||||
};
|
};
|
||||||
|
|
||||||
vec3 calcLight(int srgb) {
|
vec3 calcLight(uint fullLight) {
|
||||||
float s = (srgb >> 24) & 255;
|
vec3 sunLight = vec3(
|
||||||
float r = (srgb >> 16) & 255;
|
fullLight >> 25 & 31u,
|
||||||
float g = (srgb >> 8) & 255;
|
fullLight >> 20 & 31u,
|
||||||
float b = (srgb >> 0) & 255;
|
fullLight >> 15 & 31u
|
||||||
r = max(s*ambientLight.x, r);
|
);
|
||||||
g = max(s*ambientLight.y, g);
|
vec3 blockLight = vec3(
|
||||||
b = max(s*ambientLight.z, b);
|
fullLight >> 10 & 31u,
|
||||||
return vec3(r, g, b)/255;
|
fullLight >> 5 & 31u,
|
||||||
|
fullLight >> 0 & 31u
|
||||||
|
);
|
||||||
|
return max(sunLight*ambientLight, blockLight)/31;
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
@ -175,7 +175,16 @@ pub const ClientEntityManager = struct {
|
|||||||
for(entities.items()) |ent| {
|
for(entities.items()) |ent| {
|
||||||
if(ent.id == game.Player.id) continue; // don't render local player
|
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 pos: Vec3d = ent.getRenderPosition() - playerPos;
|
||||||
const modelMatrix = (Mat4f.identity()
|
const modelMatrix = (Mat4f.identity()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user