diff --git a/client/src/main/java/client/Client.java b/client/src/main/java/client/Client.java index f1e57cb6..14abeb89 100755 --- a/client/src/main/java/client/Client.java +++ b/client/src/main/java/client/Client.java @@ -668,10 +668,6 @@ public class Client implements IThreadListener { @Variable(name = "gl_dynlight_viewdist", category = CVarCategory.RENDER, min = 1.0f, max = 10000.0f, display = "Entfernung Lichtq. -> Kamera") public float lightDistCam = 256.0f; - public float ambientX = 0.1f; - public float ambientY = -1.0f; - public float ambientZ = 0.2f; - @Variable(name = "gl_dynlight_max", category = CVarCategory.RENDER, min = 0, max = 112, display = "Max. Dyn. Lichtquellen", callback = MaxLightFunction.class) public int lightMaximum = 64; @Variable(name = "gl_dynlight_chunkrange", category = CVarCategory.RENDER, min = 0, max = 64, display = "Lichtq. Sichtweite") @@ -2008,7 +2004,8 @@ public class Client implements IThreadListener { "Licht: " + chunk.getLightSub(pos, 0) + " (" + (this.world.dimension.hasSkyLight() ? + World.getSkyLightFor(pos.getY()) + " Himmel, " : "") + chunk.getLight(pos) + " Blöcke, " + String.format( "%.1f", this.renderer.getSunBrightness(1.0f) * 15.0f) + " Welt), A: " - + String.format("%.1f °", this.world.getCelestialAngle(1.0f)) + "\n" + + + String.format("%.1f ° (%.1f, %.1f)", this.world.getCelestialAngle(1.0f), !this.world.dimension.hasRotation() ? 0.0f : ExtMath.cos((-90.0f + this.world.getCelestialAngle(1.0f)) / 180.0f * (float)Math.PI), + !this.world.dimension.hasRotation() ? -1.0f : ExtMath.sin((-90.0f + this.world.getCelestialAngle(1.0f)) / 180.0f * (float)Math.PI)) + "\n" + String.format("Zeit: %s" + (this.world.dimension.hasRotation() ? ", R %d / %d T" : "") + (this.world.dimension.hasOrbit() ? ", U %d / %d T" : ""), this.world.formatEpochSimple(), this.world.getRotation(), diff --git a/client/src/main/java/client/renderer/MatrixState.java b/client/src/main/java/client/renderer/MatrixState.java index f923383a..42878823 100755 --- a/client/src/main/java/client/renderer/MatrixState.java +++ b/client/src/main/java/client/renderer/MatrixState.java @@ -54,7 +54,7 @@ public class MatrixState { return new Vec3((double)SCREENCOORDS.get(0), (double)SCREENCOORDS.get(1), (double)SCREENCOORDS.get(2)); } - private static Vec3 project(Entity entity, double partial) { + public static Vec3 project(Entity entity, double partial) { double x = entity.prevX + (entity.posX - entity.prevX) * partial; double y = entity.prevY + (entity.posY - entity.prevY) * partial; double z = entity.prevZ + (entity.posZ - entity.prevZ) * partial; diff --git a/client/src/main/java/client/renderer/Renderer.java b/client/src/main/java/client/renderer/Renderer.java index 38789401..b2d9af4d 100755 --- a/client/src/main/java/client/renderer/Renderer.java +++ b/client/src/main/java/client/renderer/Renderer.java @@ -213,6 +213,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 blockColorRed; + private float blockColorGreen; + private float blockColorBlue; public Renderer(Client gm, ModelManager manager) { @@ -253,15 +259,27 @@ public class Renderer { } public float getFogColorRed() { - return this.fogColorRed; + return this.lightColorRed; } public float getFogColorGreen() { - return this.fogColorGreen; + return this.lightColorGreen; } public float getFogColorBlue() { - return this.fogColorBlue; + return this.lightColorBlue; + } + + public float getBlockColorRed() { + return this.blockColorRed; + } + + public float getBlockColorGreen() { + return this.blockColorGreen; + } + + public float getBlockColorBlue() { + return this.blockColorBlue; } public ModelManager getModelManager() @@ -1151,6 +1169,16 @@ public class Renderer { int r = (int)(red * 255.0F); int g = (int)(green * 255.0F); int b = (int)(blue * 255.0F); + if(n == 240) { + this.lightColorRed = red; + this.lightColorGreen = green; + this.lightColorBlue = blue; + } + else if(n == 15) { + this.blockColorRed = red; + this.blockColorGreen = green; + this.blockColorBlue = blue; + } this.lightmapColors[n] = a << 24 | r << 16 | g << 8 | b; } @@ -2576,13 +2604,9 @@ public class Renderer { this.renderChunks.add(renderchunk); } } -// this.gm.renderer.enableLightmap(); GlState.setActiveTexture(GL46.GL_TEXTURE1); GL46.glMatrixMode(GL46.GL_TEXTURE); GL46.glLoadIdentity(); -// float f = 0.00390625F; -// GL46.glScalef(f, f, f); -// GL46.glTranslatef(8.0F, 8.0F, 8.0F); GL46.glMatrixMode(GL46.GL_MODELVIEW); this.gm.getTextureManager().bindTexture(TEX_LIGHTMAP); GL46.glTexParameteri(GL46.GL_TEXTURE_2D, GL46.GL_TEXTURE_MIN_FILTER, GL46.GL_LINEAR); @@ -2593,43 +2617,34 @@ public class Renderer { GlState.enableTexture2D(); GlState.setActiveTexture(GL46.GL_TEXTURE0); -// GL46.glEnableClientState(GL46.GL_VERTEX_ARRAY); -// GL46.glClientActiveTexture(GL46.GL_TEXTURE0); -// GL46.glEnableClientState(GL46.GL_TEXTURE_COORD_ARRAY); -// GL46.glClientActiveTexture(GL46.GL_TEXTURE1); -// GL46.glEnableClientState(GL46.GL_TEXTURE_COORD_ARRAY); -// GL46.glClientActiveTexture(GL46.GL_TEXTURE0); -// GL46.glEnableClientState(GL46.GL_COLOR_ARRAY); - if (this.initialized) { ShaderContext context = Shader.WORLD.use(); + context.bool("sky_light", this.theWorld.dimension.hasSkyLight() && !this.gm.setGamma); for (RenderChunk renderchunk : this.renderChunks) { VertexBuffer vertexbuffer = renderchunk.getVertexBuffer(); BlockPos blockpos = renderchunk.getPosition(); context.vec("offset", (float)((double)blockpos.getX() - this.viewEntityX), (float)((double)blockpos.getY() - this.viewEntityY), (float)((double)blockpos.getZ() - this.viewEntityZ)); + // Vec3 cam = MatrixState.project(Client.CLIENT.getRenderViewEntity(), Client.CLIENT.getTickFraction()); + context.vec("cam_pos", (float)this.viewEntityX, (float)this.viewEntityY + this.gm.player.getEyeHeight(), (float)this.viewEntityZ); context.matrix("model", renderchunk.getModelviewMatrix()); + context.integer("chunk_x", blockpos.getX()); + context.integer("chunk_y", blockpos.getY()); + context.integer("chunk_z", blockpos.getZ()); vertexbuffer.bindBuffer(); GL46.glVertexAttribPointer(0, 3, GL46.GL_FLOAT, false, 28, 0L); GL46.glEnableVertexAttribArray(0); - GL46.glVertexAttribPointer(1, 4, GL46.GL_UNSIGNED_BYTE, true, 28, 12L); + GL46.glVertexAttribPointer(1, 4, GL46.GL_BYTE, true, 28, 12L); GL46.glEnableVertexAttribArray(1); GL46.glVertexAttribPointer(2, 2, GL46.GL_FLOAT, false, 28, 16L); GL46.glEnableVertexAttribArray(2); GL46.glVertexAttribPointer(3, 2, GL46.GL_UNSIGNED_SHORT, true, 28, 24L); GL46.glEnableVertexAttribArray(3); -// GL46.nglVertexPointer(3, GL46.GL_FLOAT, 28, 0L); -// GL46.nglColorPointer(4, GL46.GL_UNSIGNED_BYTE, 28, 12L); -// GL46.glTexCoordPointer(2, GL46.GL_FLOAT, 28, 16L); -// GL46.glClientActiveTexture(GL46.GL_TEXTURE1); -// GL46.glTexCoordPointer(2, GL46.GL_SHORT, 28, 24L); -// GL46.glClientActiveTexture(GL46.GL_TEXTURE0); - vertexbuffer.drawArrays(GL46.GL_QUADS); GL46.glDisableVertexAttribArray(0); @@ -2644,28 +2659,6 @@ public class Renderer { this.renderChunks.clear(); } -// for (VertexFormatElement vertexformatelement : DefaultVertexFormats.BLOCK.getElements()) -// { -// VertexFormatElement.EnumUsage vertexformatelement$enumusage = vertexformatelement.usage(); -// int s = vertexformatelement.index(); -// -// switch (vertexformatelement$enumusage) -// { -// case POSITION: -// GL46.glDisableClientState(GL46.GL_VERTEX_ARRAY); -// break; -// -// case UV: -// GL46.glClientActiveTexture(GL46.GL_TEXTURE0 + s); -// GL46.glDisableClientState(GL46.GL_TEXTURE_COORD_ARRAY); -// GL46.glClientActiveTexture(GL46.GL_TEXTURE0); -// break; -// -// case COLOR: -// GL46.glDisableClientState(GL46.GL_COLOR_ARRAY); -// GlState.resetColor(); -// } -// } this.gm.renderer.disableLightmap(); return l; } @@ -3728,17 +3721,17 @@ public class Renderer { float f24 = f4; float f25 = f4; float f26 = f4; - worldRendererIn.pos(d0 + 0.0D, d1 + (double)f7, d2 + 0.0D).color(f24, f25, f26, 1.0F).tex((double)f13, (double)f17).lightmap(l2, i3).endVertex(); - worldRendererIn.pos(d0 + 0.0D, d1 + (double)f8, d2 + 1.0D).color(f24, f25, f26, 1.0F).tex((double)f14, (double)f18).lightmap(l2, i3).endVertex(); - worldRendererIn.pos(d0 + 1.0D, d1 + (double)f9, d2 + 1.0D).color(f24, f25, f26, 1.0F).tex((double)f15, (double)f19).lightmap(l2, i3).endVertex(); - worldRendererIn.pos(d0 + 1.0D, d1 + (double)f10, d2 + 0.0D).color(f24, f25, f26, 1.0F).tex((double)f16, (double)f20).lightmap(l2, i3).endVertex(); + worldRendererIn.pos(d0 + 0.0D, d1 + (double)f7, d2 + 0.0D).color(f24, f25, f26, 0.5F).tex((double)f13, (double)f17).lightmap(l2, i3).endVertex(); + worldRendererIn.pos(d0 + 0.0D, d1 + (double)f8, d2 + 1.0D).color(f24, f25, f26, 0.5F).tex((double)f14, (double)f18).lightmap(l2, i3).endVertex(); + worldRendererIn.pos(d0 + 1.0D, d1 + (double)f9, d2 + 1.0D).color(f24, f25, f26, 0.5F).tex((double)f15, (double)f19).lightmap(l2, i3).endVertex(); + worldRendererIn.pos(d0 + 1.0D, d1 + (double)f10, d2 + 0.0D).color(f24, f25, f26, 0.5F).tex((double)f16, (double)f20).lightmap(l2, i3).endVertex(); if (blockliquid.shouldRenderSides(blockAccess, blockPosIn.up())) { - worldRendererIn.pos(d0 + 0.0D, d1 + (double)f7, d2 + 0.0D).color(f24, f25, f26, 1.0F).tex((double)f13, (double)f17).lightmap(l2, i3).endVertex(); - worldRendererIn.pos(d0 + 1.0D, d1 + (double)f10, d2 + 0.0D).color(f24, f25, f26, 1.0F).tex((double)f16, (double)f20).lightmap(l2, i3).endVertex(); - worldRendererIn.pos(d0 + 1.0D, d1 + (double)f9, d2 + 1.0D).color(f24, f25, f26, 1.0F).tex((double)f15, (double)f19).lightmap(l2, i3).endVertex(); - worldRendererIn.pos(d0 + 0.0D, d1 + (double)f8, d2 + 1.0D).color(f24, f25, f26, 1.0F).tex((double)f14, (double)f18).lightmap(l2, i3).endVertex(); + worldRendererIn.pos(d0 + 0.0D, d1 + (double)f7, d2 + 0.0D).color(f24, f25, f26, 0.5F).tex((double)f13, (double)f17).lightmap(l2, i3).endVertex(); + worldRendererIn.pos(d0 + 1.0D, d1 + (double)f10, d2 + 0.0D).color(f24, f25, f26, 0.5F).tex((double)f16, (double)f20).lightmap(l2, i3).endVertex(); + worldRendererIn.pos(d0 + 1.0D, d1 + (double)f9, d2 + 1.0D).color(f24, f25, f26, 0.5F).tex((double)f15, (double)f19).lightmap(l2, i3).endVertex(); + worldRendererIn.pos(d0 + 0.0D, d1 + (double)f8, d2 + 1.0D).color(f24, f25, f26, 0.5F).tex((double)f14, (double)f18).lightmap(l2, i3).endVertex(); } } @@ -3751,10 +3744,10 @@ public class Renderer { int l1 = getLightmapValueLiquid(blockAccess, blockPosIn.down()); int i2 = l1 >> 16 & 65535; int j2 = l1 & 65535; - worldRendererIn.pos(d0, d1, d2 + 1.0D).color(f3, f3, f3, 1.0F).tex((double)f35, (double)f38).lightmap(i2, j2).endVertex(); - worldRendererIn.pos(d0, d1, d2).color(f3, f3, f3, 1.0F).tex((double)f35, (double)f37).lightmap(i2, j2).endVertex(); - worldRendererIn.pos(d0 + 1.0D, d1, d2).color(f3, f3, f3, 1.0F).tex((double)f36, (double)f37).lightmap(i2, j2).endVertex(); - worldRendererIn.pos(d0 + 1.0D, d1, d2 + 1.0D).color(f3, f3, f3, 1.0F).tex((double)f36, (double)f38).lightmap(i2, j2).endVertex(); + worldRendererIn.pos(d0, d1, d2 + 1.0D).color(f3, f3, f3, 0.5F).tex((double)f35, (double)f38).lightmap(i2, j2).endVertex(); + worldRendererIn.pos(d0, d1, d2).color(f3, f3, f3, 0.5F).tex((double)f35, (double)f37).lightmap(i2, j2).endVertex(); + worldRendererIn.pos(d0 + 1.0D, d1, d2).color(f3, f3, f3, 0.5F).tex((double)f36, (double)f37).lightmap(i2, j2).endVertex(); + worldRendererIn.pos(d0 + 1.0D, d1, d2 + 1.0D).color(f3, f3, f3, 0.5F).tex((double)f36, (double)f38).lightmap(i2, j2).endVertex(); flag2 = true; } @@ -3845,14 +3838,14 @@ public class Renderer { float f32 = f4 * f31; float f33 = f4 * f31; float f34 = f4 * f31; - worldRendererIn.pos(d3, d1 + (double)f39, d4).color(f32, f33, f34, 1.0F).tex((double)f41, (double)f28).lightmap(k, l).endVertex(); - worldRendererIn.pos(d5, d1 + (double)f40, d6).color(f32, f33, f34, 1.0F).tex((double)f27, (double)f29).lightmap(k, l).endVertex(); - worldRendererIn.pos(d5, d1 + 0.0D, d6).color(f32, f33, f34, 1.0F).tex((double)f27, (double)f30).lightmap(k, l).endVertex(); - worldRendererIn.pos(d3, d1 + 0.0D, d4).color(f32, f33, f34, 1.0F).tex((double)f41, (double)f30).lightmap(k, l).endVertex(); - worldRendererIn.pos(d3, d1 + 0.0D, d4).color(f32, f33, f34, 1.0F).tex((double)f41, (double)f30).lightmap(k, l).endVertex(); - worldRendererIn.pos(d5, d1 + 0.0D, d6).color(f32, f33, f34, 1.0F).tex((double)f27, (double)f30).lightmap(k, l).endVertex(); - worldRendererIn.pos(d5, d1 + (double)f40, d6).color(f32, f33, f34, 1.0F).tex((double)f27, (double)f29).lightmap(k, l).endVertex(); - worldRendererIn.pos(d3, d1 + (double)f39, d4).color(f32, f33, f34, 1.0F).tex((double)f41, (double)f28).lightmap(k, l).endVertex(); + worldRendererIn.pos(d3, d1 + (double)f39, d4).color(f32, f33, f34, 0.5F).tex((double)f41, (double)f28).lightmap(k, l).endVertex(); + worldRendererIn.pos(d5, d1 + (double)f40, d6).color(f32, f33, f34, 0.5F).tex((double)f27, (double)f29).lightmap(k, l).endVertex(); + worldRendererIn.pos(d5, d1 + 0.0D, d6).color(f32, f33, f34, 0.5F).tex((double)f27, (double)f30).lightmap(k, l).endVertex(); + worldRendererIn.pos(d3, d1 + 0.0D, d4).color(f32, f33, f34, 0.5F).tex((double)f41, (double)f30).lightmap(k, l).endVertex(); + worldRendererIn.pos(d3, d1 + 0.0D, d4).color(f32, f33, f34, 0.5F).tex((double)f41, (double)f30).lightmap(k, l).endVertex(); + worldRendererIn.pos(d5, d1 + 0.0D, d6).color(f32, f33, f34, 0.5F).tex((double)f27, (double)f30).lightmap(k, l).endVertex(); + worldRendererIn.pos(d5, d1 + (double)f40, d6).color(f32, f33, f34, 0.5F).tex((double)f27, (double)f29).lightmap(k, l).endVertex(); + worldRendererIn.pos(d3, d1 + (double)f39, d4).color(f32, f33, f34, 0.5F).tex((double)f41, (double)f28).lightmap(k, l).endVertex(); } } diff --git a/client/src/main/java/client/renderer/Shader.java b/client/src/main/java/client/renderer/Shader.java index 477d6204..d9c77703 100644 --- a/client/src/main/java/client/renderer/Shader.java +++ b/client/src/main/java/client/renderer/Shader.java @@ -15,6 +15,7 @@ import client.Client; import client.util.FileUtils; import common.collect.Maps; import common.log.Log; +import common.util.ExtMath; import common.util.Matrix4f; import common.util.Util; import common.util.Vec3; @@ -26,17 +27,24 @@ public enum Shader { context.vec("clip_near", Client.CLIENT.renderer.getNearPlane()); context.vec("clip_far", Client.CLIENT.renderer.getFarPlane()); context.vec("screen", (float)Client.CLIENT.fbRawX, (float)Client.CLIENT.fbRawY); - Vec3 cam = MatrixState.getPosition(); - context.vec("cam_pos", (float)cam.xCoord, (float)cam.yCoord, (float)cam.zCoord); context.matrix("view", MatrixState.getModelView()); context.matrix("projection", MatrixState.getProjection()); - context.vec("dir_direction", Client.CLIENT.ambientX, Client.CLIENT.ambientY, Client.CLIENT.ambientZ); + + 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; + + 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); - context.vec("dir_diffuse", clear_r * 1.25f, clear_g * 1.25f, clear_b * 1.25f); - context.vec("dir_specular", clear_r * 1.5f, clear_g * 1.5f, clear_b * 1.5f); + 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); @@ -259,7 +267,8 @@ public enum Shader { } this.program = pr; if(this.init != null) { - context = this.use(); + GL46.glUseProgram(this.program); + context = new ShaderContext(this.program); this.init.accept(context); context.finish(); } diff --git a/client/src/main/java/client/renderer/blockmodel/FaceBakery.java b/client/src/main/java/client/renderer/blockmodel/FaceBakery.java index 68808bb8..23c04ebe 100755 --- a/client/src/main/java/client/renderer/blockmodel/FaceBakery.java +++ b/client/src/main/java/client/renderer/blockmodel/FaceBakery.java @@ -105,31 +105,49 @@ public class FaceBakery private int getFaceShadeColor(Facing facing) { - float f = this.getFaceBrightness(facing); - int i = ExtMath.clampi((int)(f * 255.0F), 0, 255); - return -16777216 | i << 16 | i << 8 | i; + return this.getFaceBrightness(facing) << 24 | this.getFaceNormal(facing); } - - private float getFaceBrightness(Facing facing) + + private int getFaceNormal(Facing facing) { switch (facing) { case DOWN: - return 0.5F; + default: + return 0x008100; + case UP: + return 0x007f00; + case WEST: + return 0x000081; + case EAST: + return 0x00007f; + case NORTH: + return 0x810000; + case SOUTH: + return 0x7f0000; + } + } + + private int getFaceBrightness(Facing facing) + { + switch (facing) + { + case DOWN: + return 0x3f; case UP: - return 1.0F; + return 0x7f; case NORTH: case SOUTH: - return 0.8F; + return 0x65; case WEST: case EAST: - return 0.6F; + return 0x4c; default: - return 1.0F; + return 0x7f; } } @@ -148,7 +166,7 @@ public class FaceBakery private void fillVertexData(int[] faceData, int vertexIndex, Facing facing, BlockPartFace partFace, float[] p_178402_5_, Sprite sprite, ModelRotation modelRotationIn, BlockPartRotation partRotation, boolean uvLocked, boolean shade) { Facing enumfacing = modelRotationIn.rotateFace(facing); - int i = shade ? this.getFaceShadeColor(enumfacing) : -1; + int i = shade ? this.getFaceShadeColor(enumfacing) : 0x7f000000; VertexInformation enumfacedirection$vertexinformation = EnumFaceDirection.getFacing(facing).getVertexInformation(vertexIndex); Vector3f vector3f = new Vector3f(p_178402_5_[enumfacedirection$vertexinformation.xIndex], p_178402_5_[enumfacedirection$vertexinformation.yIndex], p_178402_5_[enumfacedirection$vertexinformation.zIndex]); this.rotatePart(vector3f, partRotation); diff --git a/client/src/main/resources/shaders/world.fsh b/client/src/main/resources/shaders/world.fsh index bf60a117..97860d45 100644 --- a/client/src/main/resources/shaders/world.fsh +++ b/client/src/main/resources/shaders/world.fsh @@ -10,9 +10,9 @@ struct light_t { in vec3 vertex; in vec3 normal; -in vec4 brightness; in vec2 tex_coord; in vec2 lm_coord; +in float brightness; uniform vec3 cam_pos; uniform sampler2D tex; @@ -24,9 +24,9 @@ uniform float max_cam_dist; uniform float light_factor; uniform vec3 dir_direction; uniform vec3 dir_ambient; -uniform vec3 dir_diffuse; -uniform vec3 dir_specular; +uniform vec3 block_ambient; uniform int n_lights; +uniform bool sky_light; uniform light_block { light_t lights[MAX_LIGHTS]; }; @@ -50,8 +50,8 @@ vec3 calc_dir_light(vec3 norm, vec3 dir, vec3 rgb) { 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_diffuse * diff * rgb; - vec3 specular = dir_specular * spec * specular * rgb; + vec3 diffuse = dir_ambient * 0.125 * diff * rgb; + vec3 specular = dir_ambient * 1.25 * spec * specular * rgb; return (ambient + diffuse + specular); } @@ -75,10 +75,12 @@ vec3 calc_point_light(light_t light, vec3 norm, vec3 dir, vec3 rgb) { void main() { vec3 norm = normalize(normal); vec3 dir = normalize(cam_pos - vertex); - vec4 texel = texture(tex, tex_coord) * brightness; - texel *= texture(lightmap, 0.03125 + lm_coord * 256.0); - vec3 rgb = texel.rgb; - vec3 result = calc_dir_light(norm, dir, rgb); + 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 * lm + calc_dir_light(norm, dir, rgb * sky * (1.0 - block)); // int l = 0; for(int z = 0; z < n_lights; z++) { // if(lights[z].enabled) { @@ -87,5 +89,5 @@ void main() { // l++; // } } - FragColor = texel; // vec4(result, texel.a); + FragColor = vec4(result, texel.a); } diff --git a/client/src/main/resources/shaders/world.vsh b/client/src/main/resources/shaders/world.vsh index 0ceb3b2c..dc02fb54 100644 --- a/client/src/main/resources/shaders/world.vsh +++ b/client/src/main/resources/shaders/world.vsh @@ -1,27 +1,29 @@ layout (location = 0) in vec3 pos; -// layout (location = 1) in vec3 norm; -layout (location = 1) in vec4 color; +layout (location = 1) in vec4 norm; layout (location = 2) in vec2 coord; layout (location = 3) in vec2 light; out vec3 vertex; out vec3 normal; -out vec4 brightness; out vec2 tex_coord; out vec2 lm_coord; +out float brightness; uniform mat4 model; uniform mat4 view; uniform mat4 projection; uniform sampler2D tex; uniform vec3 offset; +uniform int chunk_x; +uniform int chunk_y; +uniform int chunk_z; void main() { - vec3 norm = vec3(0.0, 1.0, 0.0); - vertex = offset + vec3(model * vec4(pos, 1.0)); - normal = mat3(transpose(inverse(model))) * norm; - brightness = color; + vec3 nvertex = vec3(model * vec4(pos, 1.0)); + vertex = vec3(float(chunk_x) + pos.x, float(chunk_y) + pos.y, float(chunk_z) + pos.z); + normal = mat3(transpose(inverse(model))) * norm.rgb; + brightness = norm.a; tex_coord = coord; lm_coord = light; - gl_Position = projection * view * vec4(vertex, 1.0); + gl_Position = projection * view * vec4(offset + nvertex, 1.0); }