1
0
Fork 0

improve lighting

This commit is contained in:
Sen 2025-08-29 12:20:34 +02:00
parent 401f9dbe34
commit 995bc4c42f
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
4 changed files with 70 additions and 46 deletions

View file

@ -177,9 +177,12 @@ public class Renderer {
private double prevRenderSortY; private double prevRenderSortY;
private double prevRenderSortZ; private double prevRenderSortZ;
private boolean displayListEntitiesDirty = true; private boolean displayListEntitiesDirty = true;
private float lightColorRed; private float sunColorRed;
private float lightColorGreen; private float sunColorGreen;
private float lightColorBlue; private float sunColorBlue;
private float moonColorRed;
private float moonColorGreen;
private float moonColorBlue;
private float blockColorRed; private float blockColorRed;
private float blockColorGreen; private float blockColorGreen;
private float blockColorBlue; private float blockColorBlue;
@ -222,28 +225,28 @@ public class Renderer {
return this.farPlaneDistance * SQRT_2; return this.farPlaneDistance * SQRT_2;
} }
public float getFogColorRed() { public float getSunColorRed() {
return this.lightColorRed; return this.sunColorRed;
} }
public float getFogColorGreen() { public float getSunColorGreen() {
return this.lightColorGreen; return this.sunColorGreen;
} }
public float getFogColorBlue() { public float getSunColorBlue() {
return this.lightColorBlue; return this.sunColorBlue;
} }
public float getBlockColorRed() { public float getMoonColorRed() {
return this.blockColorRed; return this.moonColorRed;
} }
public float getBlockColorGreen() { public float getMoonColorGreen() {
return this.blockColorGreen; return this.moonColorGreen;
} }
public float getBlockColorBlue() { public float getMoonColorBlue() {
return this.blockColorBlue; return this.moonColorBlue;
} }
public ModelManager getModelManager() public ModelManager getModelManager()
@ -1132,9 +1135,12 @@ public class Renderer {
int g = (int)(green * 255.0F); int g = (int)(green * 255.0F);
int b = (int)(blue * 255.0F); int b = (int)(blue * 255.0F);
if(n == 240) { if(n == 240) {
this.lightColorRed = red; this.sunColorRed = red * (world.dimension.hasSkyLight() ? sun : 1.0f);
this.lightColorGreen = green; this.sunColorGreen = green * (world.dimension.hasSkyLight() ? sun : 1.0f);
this.lightColorBlue = blue; this.sunColorBlue = blue * (world.dimension.hasSkyLight() ? sun : 1.0f);
this.moonColorRed = red * (1.0f - sun);
this.moonColorGreen = green * (1.0f - sun);
this.moonColorBlue = blue * (1.0f - sun);
} }
else if(n == 15) { else if(n == 15) {
this.blockColorRed = red; this.blockColorRed = red;
@ -2578,7 +2584,15 @@ public class Renderer {
if (this.initialized) if (this.initialized)
{ {
ShaderContext context = Shader.WORLD.use(); ShaderContext context = Shader.WORLD.use();
boolean moon = false;
for(int color : this.theWorld.dimension.getMoonColors()) {
if((color & 0xff000000) == 0) {
moon = true;
break;
}
}
context.bool("sky_light", this.theWorld.dimension.hasSkyLight() && !this.gm.setGamma); context.bool("sky_light", this.theWorld.dimension.hasSkyLight() && !this.gm.setGamma);
context.bool("moon_light", moon);
for (RenderChunk renderchunk : this.renderChunks) for (RenderChunk renderchunk : this.renderChunks)
{ {
VertexBuffer vertexbuffer = renderchunk.getVertexBuffer(); VertexBuffer vertexbuffer = renderchunk.getVertexBuffer();

View file

@ -32,19 +32,24 @@ public enum Shader {
float angle = -90.0f + Client.CLIENT.world.getCelestialAngle(Client.CLIENT.getTickFraction()); float angle = -90.0f + Client.CLIENT.world.getCelestialAngle(Client.CLIENT.getTickFraction());
float ambientX = !Client.CLIENT.world.dimension.hasRotation() ? 0.0f : ExtMath.cos(angle / 180.0f * (float)Math.PI); float sunX = !Client.CLIENT.world.dimension.hasRotation() ? 0.0f : ExtMath.cos(angle / 180.0f * (float)Math.PI);
float ambientY = !Client.CLIENT.world.dimension.hasRotation() ? -1.0f : ExtMath.sin(angle / 180.0f * (float)Math.PI); float sunY = !Client.CLIENT.world.dimension.hasRotation() ? -1.0f : ExtMath.sin(angle / 180.0f * (float)Math.PI);
float ambientZ = 0.0f; context.vec("sun_direction", sunX, sunY, 0.0f);
float moonX = !Client.CLIENT.world.dimension.hasRotation() ? 0.0f : ExtMath.cos((180.0f + angle) / 180.0f * (float)Math.PI);
float moonY = !Client.CLIENT.world.dimension.hasRotation() ? -1.0f : ExtMath.sin((180.0f + angle) / 180.0f * (float)Math.PI);
context.vec("moon_direction", moonX, moonY, 0.0f);
float sunRed = Client.CLIENT.renderer.getSunColorRed();
float sunGreen = Client.CLIENT.renderer.getSunColorGreen();
float sunBlue = Client.CLIENT.renderer.getSunColorBlue();
context.vec("sun_ambient", sunRed, sunGreen, sunBlue);
float moonRed = Client.CLIENT.renderer.getMoonColorRed();
float moonGreen = Client.CLIENT.renderer.getMoonColorGreen();
float moonBlue = Client.CLIENT.renderer.getMoonColorBlue();
context.vec("moon_ambient", moonRed, moonGreen, moonBlue);
context.vec("dir_direction", ambientX, ambientY, ambientZ);
float clear_r = Client.CLIENT.renderer.getFogColorRed();
float clear_g = Client.CLIENT.renderer.getFogColorGreen();
float clear_b = Client.CLIENT.renderer.getFogColorBlue();
context.vec("dir_ambient", clear_r, clear_g, clear_b);
float block_r = Client.CLIENT.renderer.getBlockColorRed();
float block_g = Client.CLIENT.renderer.getBlockColorGreen();
float block_b = Client.CLIENT.renderer.getBlockColorBlue();
context.vec("block_ambient", block_r, block_g, block_b);
context.vec("light_factor", Client.CLIENT.lightBlend); context.vec("light_factor", Client.CLIENT.lightBlend);
context.vec("max_vert_dist", Client.CLIENT.lightDistVert); context.vec("max_vert_dist", Client.CLIENT.lightDistVert);
context.vec("max_cam_dist", Client.CLIENT.lightDistCam); context.vec("max_cam_dist", Client.CLIENT.lightDistCam);

View file

@ -20,11 +20,13 @@ uniform vec3 specular;
uniform float max_vert_dist; uniform float max_vert_dist;
uniform float max_cam_dist; uniform float max_cam_dist;
uniform float light_factor; uniform float light_factor;
uniform vec3 dir_direction; uniform vec3 sun_direction;
uniform vec3 dir_ambient; uniform vec3 sun_ambient;
uniform vec3 block_ambient; uniform vec3 moon_direction;
uniform vec3 moon_ambient;
uniform int n_lights; uniform int n_lights;
uniform bool sky_light; uniform bool sky_light;
uniform bool moon_light;
uniform light_block { uniform light_block {
light_t lights[MAX_LIGHTS]; light_t lights[MAX_LIGHTS];
}; };
@ -42,14 +44,14 @@ vec4 pcf_sample(sampler2D stex, vec2 pos) {
} }
*/ */
vec3 calc_dir_light(vec3 norm, vec3 dir, vec3 rgb) { vec3 calc_dir_light(vec3 norm, vec3 dir, vec3 rgb, vec3 direction, vec3 color) {
vec3 ldir = normalize(-dir_direction); vec3 ldir = normalize(-direction);
float diff = max(dot(norm, ldir), 0.0); float diff = max(dot(norm, ldir), 0.0);
vec3 rdir = reflect(-ldir, norm); vec3 rdir = reflect(-ldir, norm);
float spec = pow(max(dot(dir, rdir), 0.0), shine); float spec = pow(max(dot(dir, rdir), 0.0), shine);
vec3 ambient = dir_ambient * rgb + clamp(vec3(0.0), 0.0, 1.0); vec3 ambient = color * rgb + clamp(vec3(0.0), 0.0, 1.0);
vec3 diffuse = dir_ambient * 0.125 * diff * rgb; vec3 diffuse = color * 0.125 * diff * rgb;
vec3 specular = dir_ambient * 1.25 * spec * specular * rgb; vec3 specular = color * 1.25 * spec * specular * rgb;
return (ambient + diffuse + specular); return (ambient + diffuse + specular);
} }
@ -75,17 +77,14 @@ void main() {
vec3 dir = normalize(cam_pos - vertex); vec3 dir = normalize(cam_pos - vertex);
vec4 texel = texture(tex, tex_coord); vec4 texel = texture(tex, tex_coord);
float sky = sky_light ? vertex.y < 0.0 ? 0.0 : (vertex.y < 64.0 ? vertex.y / 64.0 : 1.0) : 1.0; float sky = sky_light ? vertex.y < 0.0 ? 0.0 : (vertex.y < 64.0 ? vertex.y / 64.0 : 1.0) : 1.0;
// float block = clamp(0.03125 + lm_coord.x * 256.0, 0.0, 1.0); vec3 rgb = texel.rgb;
// vec3 lm = block * block_ambient; vec3 direct = rgb * sky * (1.0 - light_color.a * 0.5);
vec3 rgb = texel.rgb; // * brightness; vec3 result = rgb * light_color.rgb + calc_dir_light(norm, dir, direct, sun_direction, sun_ambient);
vec3 result = rgb * light_color.rgb + calc_dir_light(norm, dir, rgb * sky * (1.0 - light_color.a * 0.5)); if(moon_light)
// int l = 0; result += calc_dir_light(norm, dir, direct, moon_direction, moon_ambient);
for(int z = 0; z < n_lights; z++) { for(int z = 0; z < n_lights; z++) {
// if(lights[z].enabled) {
if(distance(vertex, lights[z].position.xyz) <= max_vert_dist && distance(cam_pos, lights[z].position.xyz) <= max_cam_dist) if(distance(vertex, lights[z].position.xyz) <= max_vert_dist && distance(cam_pos, lights[z].position.xyz) <= max_cam_dist)
result += calc_point_light(lights[z], norm, dir, rgb); result += calc_point_light(lights[z], norm, dir, rgb);
// l++;
// }
} }
FragColor = vec4(result, texel.a); FragColor = vec4(result, texel.a);
} }

View file

@ -14,6 +14,7 @@ import common.properties.PropertyInteger;
import common.rng.Random; import common.rng.Random;
import common.util.BlockPos; import common.util.BlockPos;
import common.util.BoundingBox; import common.util.BoundingBox;
import common.util.Clientside;
import common.util.ExtMath; import common.util.ExtMath;
import common.util.Facing; import common.util.Facing;
import common.util.Pair; import common.util.Pair;
@ -331,4 +332,9 @@ public abstract class BlockLiquid extends Block
protected boolean hasRegisteredItem() { protected boolean hasRegisteredItem() {
return false; return false;
} }
@Clientside
public float getShinyness() {
return 3.0f;
}
} }