improve lighting
This commit is contained in:
parent
401f9dbe34
commit
995bc4c42f
4 changed files with 70 additions and 46 deletions
|
@ -177,9 +177,12 @@ public class Renderer {
|
|||
private double prevRenderSortY;
|
||||
private double prevRenderSortZ;
|
||||
private boolean displayListEntitiesDirty = true;
|
||||
private float lightColorRed;
|
||||
private float lightColorGreen;
|
||||
private float lightColorBlue;
|
||||
private float sunColorRed;
|
||||
private float sunColorGreen;
|
||||
private float sunColorBlue;
|
||||
private float moonColorRed;
|
||||
private float moonColorGreen;
|
||||
private float moonColorBlue;
|
||||
private float blockColorRed;
|
||||
private float blockColorGreen;
|
||||
private float blockColorBlue;
|
||||
|
@ -222,28 +225,28 @@ public class Renderer {
|
|||
return this.farPlaneDistance * SQRT_2;
|
||||
}
|
||||
|
||||
public float getFogColorRed() {
|
||||
return this.lightColorRed;
|
||||
public float getSunColorRed() {
|
||||
return this.sunColorRed;
|
||||
}
|
||||
|
||||
public float getFogColorGreen() {
|
||||
return this.lightColorGreen;
|
||||
public float getSunColorGreen() {
|
||||
return this.sunColorGreen;
|
||||
}
|
||||
|
||||
public float getFogColorBlue() {
|
||||
return this.lightColorBlue;
|
||||
public float getSunColorBlue() {
|
||||
return this.sunColorBlue;
|
||||
}
|
||||
|
||||
public float getBlockColorRed() {
|
||||
return this.blockColorRed;
|
||||
public float getMoonColorRed() {
|
||||
return this.moonColorRed;
|
||||
}
|
||||
|
||||
public float getBlockColorGreen() {
|
||||
return this.blockColorGreen;
|
||||
public float getMoonColorGreen() {
|
||||
return this.moonColorGreen;
|
||||
}
|
||||
|
||||
public float getBlockColorBlue() {
|
||||
return this.blockColorBlue;
|
||||
public float getMoonColorBlue() {
|
||||
return this.moonColorBlue;
|
||||
}
|
||||
|
||||
public ModelManager getModelManager()
|
||||
|
@ -1132,9 +1135,12 @@ public class Renderer {
|
|||
int g = (int)(green * 255.0F);
|
||||
int b = (int)(blue * 255.0F);
|
||||
if(n == 240) {
|
||||
this.lightColorRed = red;
|
||||
this.lightColorGreen = green;
|
||||
this.lightColorBlue = blue;
|
||||
this.sunColorRed = red * (world.dimension.hasSkyLight() ? sun : 1.0f);
|
||||
this.sunColorGreen = green * (world.dimension.hasSkyLight() ? sun : 1.0f);
|
||||
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) {
|
||||
this.blockColorRed = red;
|
||||
|
@ -2578,7 +2584,15 @@ public class Renderer {
|
|||
if (this.initialized)
|
||||
{
|
||||
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("moon_light", moon);
|
||||
for (RenderChunk renderchunk : this.renderChunks)
|
||||
{
|
||||
VertexBuffer vertexbuffer = renderchunk.getVertexBuffer();
|
||||
|
|
|
@ -32,19 +32,24 @@ public enum Shader {
|
|||
|
||||
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 ambientY = !Client.CLIENT.world.dimension.hasRotation() ? -1.0f : ExtMath.sin(angle / 180.0f * (float)Math.PI);
|
||||
float ambientZ = 0.0f;
|
||||
float sunX = !Client.CLIENT.world.dimension.hasRotation() ? 0.0f : ExtMath.cos(angle / 180.0f * (float)Math.PI);
|
||||
float sunY = !Client.CLIENT.world.dimension.hasRotation() ? -1.0f : ExtMath.sin(angle / 180.0f * (float)Math.PI);
|
||||
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("max_vert_dist", Client.CLIENT.lightDistVert);
|
||||
context.vec("max_cam_dist", Client.CLIENT.lightDistCam);
|
||||
|
|
|
@ -20,11 +20,13 @@ uniform vec3 specular;
|
|||
uniform float max_vert_dist;
|
||||
uniform float max_cam_dist;
|
||||
uniform float light_factor;
|
||||
uniform vec3 dir_direction;
|
||||
uniform vec3 dir_ambient;
|
||||
uniform vec3 block_ambient;
|
||||
uniform vec3 sun_direction;
|
||||
uniform vec3 sun_ambient;
|
||||
uniform vec3 moon_direction;
|
||||
uniform vec3 moon_ambient;
|
||||
uniform int n_lights;
|
||||
uniform bool sky_light;
|
||||
uniform bool moon_light;
|
||||
uniform light_block {
|
||||
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 ldir = normalize(-dir_direction);
|
||||
vec3 calc_dir_light(vec3 norm, vec3 dir, vec3 rgb, vec3 direction, vec3 color) {
|
||||
vec3 ldir = normalize(-direction);
|
||||
float diff = max(dot(norm, ldir), 0.0);
|
||||
vec3 rdir = reflect(-ldir, norm);
|
||||
float spec = pow(max(dot(dir, rdir), 0.0), shine);
|
||||
vec3 ambient = dir_ambient * rgb + clamp(vec3(0.0), 0.0, 1.0);
|
||||
vec3 diffuse = dir_ambient * 0.125 * diff * rgb;
|
||||
vec3 specular = dir_ambient * 1.25 * spec * specular * rgb;
|
||||
vec3 ambient = color * rgb + clamp(vec3(0.0), 0.0, 1.0);
|
||||
vec3 diffuse = color * 0.125 * diff * rgb;
|
||||
vec3 specular = color * 1.25 * spec * specular * rgb;
|
||||
return (ambient + diffuse + specular);
|
||||
}
|
||||
|
||||
|
@ -75,17 +77,14 @@ void main() {
|
|||
vec3 dir = normalize(cam_pos - vertex);
|
||||
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 block = clamp(0.03125 + lm_coord.x * 256.0, 0.0, 1.0);
|
||||
// vec3 lm = block * block_ambient;
|
||||
vec3 rgb = texel.rgb; // * brightness;
|
||||
vec3 result = rgb * light_color.rgb + calc_dir_light(norm, dir, rgb * sky * (1.0 - light_color.a * 0.5));
|
||||
// int l = 0;
|
||||
vec3 rgb = texel.rgb;
|
||||
vec3 direct = rgb * sky * (1.0 - light_color.a * 0.5);
|
||||
vec3 result = rgb * light_color.rgb + calc_dir_light(norm, dir, direct, sun_direction, sun_ambient);
|
||||
if(moon_light)
|
||||
result += calc_dir_light(norm, dir, direct, moon_direction, moon_ambient);
|
||||
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)
|
||||
result += calc_point_light(lights[z], norm, dir, rgb);
|
||||
// l++;
|
||||
// }
|
||||
}
|
||||
FragColor = vec4(result, texel.a);
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import common.properties.PropertyInteger;
|
|||
import common.rng.Random;
|
||||
import common.util.BlockPos;
|
||||
import common.util.BoundingBox;
|
||||
import common.util.Clientside;
|
||||
import common.util.ExtMath;
|
||||
import common.util.Facing;
|
||||
import common.util.Pair;
|
||||
|
@ -331,4 +332,9 @@ public abstract class BlockLiquid extends Block
|
|||
protected boolean hasRegisteredItem() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Clientside
|
||||
public float getShinyness() {
|
||||
return 3.0f;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue