1
0
Fork 0

add shaders, remove multi block layer

This commit is contained in:
Sen 2025-08-28 15:04:19 +02:00
parent 1e7ef94ceb
commit 563f235b2f
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
129 changed files with 1848 additions and 1486 deletions

View file

@ -30,8 +30,7 @@ import javax.imageio.ImageIO;
import javax.swing.JFileChooser;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL13;
import org.lwjgl.opengl.GL46;
import client.audio.AudioInterface;
import client.audio.MidiBank;
@ -63,6 +62,7 @@ import client.network.DummyConnection;
import client.renderer.Drawing;
import client.renderer.EffectRenderer;
import client.renderer.Renderer;
import client.renderer.Shader;
import client.renderer.GlState;
import client.renderer.ItemRenderer;
import client.renderer.blockmodel.ModelManager;
@ -201,7 +201,7 @@ import common.world.World;
Gehäuse : Pappkarton, Bierkasten oder auch gar keins
Tastatur : Hlb fktonrnd odr bsr
Maus : Aus Plastik oder mit extra Quietsch-Effekt
Monitor : Olle Röhre oder gebrochener Flachbild (Mindestens 1280x800)
Monitor : Olle Röhre oder gebrochener Flachbild (Mindestens 800x450)
Stuhl : Interessiert niemanden (sonst siehe Gehäuse)
[[oder einfach einen Toaster mit nem LCD und Maus]]
@ -286,6 +286,12 @@ public class Client implements IThreadListener {
Client.CLIENT.setMidiDebug();
}
}
public static class MaxLightFunction implements IntFunction {
public void apply(IntVar cv, int value) {
Client.CLIENT.lightSetup();
}
}
private interface DebugRunner {
void execute(Keysym key);
@ -654,6 +660,36 @@ public class Client implements IThreadListener {
public boolean midiDebug = false;
@Variable(name = "mid_visualizer", category = CVarCategory.SOUND, display = "Visualisation")
public boolean midiVisualizer = true;
@Variable(name = "gl_light_blend", category = CVarCategory.RENDER, min = 0.0f, max = 1.0f, precision = 2, unit = "%", display = "Lichtüberdeckung")
public float lightBlend = 0.5f;
@Variable(name = "gl_dynlight_maxdist", category = CVarCategory.RENDER, min = 1.0f, max = 10000.0f, display = "Entfernung Lichtq. -> Mitte")
public float lightDistVert = 128.0f;
@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")
public int lightDistance = 8;
// int ldist_chunk_xz;
// int ldist_chunk_y;
// "gl_tex_filter", "Texturfilterung", tex_filter, true
// "gl_tex_mipmaps", "Mipmaps", tex_miptype, MIP_NONE, MIP_NEAREST, MIP_LINEAR, "off", "nearest", "linear", "Keine", "Nächster nachbar", "Linear interpoliert", MIP_LINEAR
// "gl_tex_anisotropic", "Anisotrope Filterung", tex_aniso, 1.0f (1.0f - 16.0f)
// float aniso_max;
// float tex_aniso;
//
// byte tex_miptype;
// byte tex_miplevel;
// byte tex_filter;
public static final Client CLIENT = new Client();
@ -805,22 +841,22 @@ public class Client implements IThreadListener {
this.textureManager.onReload();
this.soundManager = new SoundManager(this);
GlState.enableTexture2D();
GlState.shadeModel(GL11.GL_SMOOTH);
GL11.glClearDepth(1.0D);
GlState.shadeModel(GL46.GL_SMOOTH);
GL46.glClearDepth(1.0D);
GlState.enableDepth();
GlState.depthFunc(GL11.GL_LEQUAL);
GlState.depthFunc(GL46.GL_LEQUAL);
GlState.enableAlpha();
GlState.alphaFunc(GL11.GL_GREATER, 0.1F);
GlState.cullFace(GL11.GL_BACK);
GlState.alphaFunc(GL46.GL_GREATER, 0.1F);
GlState.cullFace(GL46.GL_BACK);
GlState.enableCull();
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL46.glMatrixMode(GL46.GL_PROJECTION);
GL46.glLoadIdentity();
GL46.glMatrixMode(GL46.GL_MODELVIEW);
this.textureMap = new TextureMap();
this.textureManager.loadTexture(TextureMap.BLOCKS, this.textureMap);
this.textureManager.bindTexture(TextureMap.BLOCKS);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
GL46.glTexParameteri(GL46.GL_TEXTURE_2D, GL46.GL_TEXTURE_MIN_FILTER, GL46.GL_NEAREST);
GL46.glTexParameteri(GL46.GL_TEXTURE_2D, GL46.GL_TEXTURE_MAG_FILTER, GL46.GL_NEAREST);
this.modelManager = new ModelManager(this.textureMap);
this.modelManager.onReload();
this.renderItem = new RenderItem(this.textureManager, this.modelManager);
@ -1046,13 +1082,13 @@ public class Client implements IThreadListener {
}
public void render() {
GlState.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GlState.tryBlendFuncSeparate(GL46.GL_SRC_ALPHA, GL46.GL_ONE_MINUS_SRC_ALPHA, GL46.GL_SRC_ALPHA, GL46.GL_ONE_MINUS_SRC_ALPHA);
GlState.enableDepth();
GlState.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
GL46.glClear(GL46.GL_COLOR_BUFFER_BIT | GL46.GL_DEPTH_BUFFER_BIT);
if(this.wireframe) {
GL11.glLineWidth(1.0f);
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
GL46.glLineWidth(1.0f);
GL46.glPolygonMode(GL46.GL_FRONT_AND_BACK, GL46.GL_LINE);
}
if(this.open == null) {
if(this.player != null && this.viewEntity == this.player)
@ -1065,18 +1101,18 @@ public class Client implements IThreadListener {
this.soundManager.setListener(this.player, (float)this.tickFraction);
if(this.player != null && (this.player.isEntityInsideOpaqueBlock() || this.viewEntity != this.player))
this.thirdPersonView = 0;
GL11.glPushMatrix();
GL11.glClear(16640);
GL46.glPushMatrix();
GL46.glClear(16640);
GlState.enableTexture2D();
if(this.world != null)
this.renderer.renderWorld((float)this.tickFraction, System.nanoTime() - this.tickStart);
GL11.glPopMatrix();
GL46.glPopMatrix();
GlState.disableTexture2D();
GlState.disableCull();
GlState.enableBlend();
if(this.wireframe)
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
GL46.glPolygonMode(GL46.GL_FRONT_AND_BACK, GL46.GL_FILL);
}
private int drawStat(int x, int y, String name, int value, int max, int color) {
@ -1273,17 +1309,17 @@ public class Client implements IThreadListener {
}
GlState.bindTexture(0);
GlState.setActiveTexture(GL13.GL_TEXTURE0);
GlState.setActiveTexture(GL46.GL_TEXTURE0);
GlState.enableTexture2D();
if(this.world != null && this.open == null && this.player != null && this.viewEntity == this.player) {
GlState.enableRescaleNormal();
GlState.enableBlend();
GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
ItemRenderer.enableGUIStandardItemLighting();
GL11.glPushMatrix();
GL11.glTranslatef(0.0f, (float)by, 0.0f);
GL46.glPushMatrix();
GL46.glTranslatef(0.0f, (float)by, 0.0f);
if(this.scaleHotbar)
GL11.glScalef(2.0f, 2.0f, 2.0f);
GL46.glScalef(2.0f, 2.0f, 2.0f);
int xPos = xoff;
for(int index = 0; index < size; ++index) {
@ -1291,12 +1327,12 @@ public class Client implements IThreadListener {
if(itemstack != null) {
if(width < 20 && selected != index && selected != index + 1 && index != size - 1) {
this.scissor(xPos * scale, this.fbY - (by + 16 * scale), (width - 1) * scale, 16 * scale);
GL11.glEnable(GL11.GL_SCISSOR_TEST);
GL46.glEnable(GL46.GL_SCISSOR_TEST);
}
GlState.enableDepth();
this.renderItem.renderItemAndEffectIntoGUI(itemstack, xPos, 0);
if(width < 20 && selected != index && selected != index + 1 && index != size - 1)
GL11.glDisable(GL11.GL_SCISSOR_TEST);
GL46.glDisable(GL46.GL_SCISSOR_TEST);
}
xPos += width >= 20 || selected == index || selected == index + 1 ? 20 : width;
}
@ -1308,16 +1344,16 @@ public class Client implements IThreadListener {
else if(this.pointed != null && this.pointed.type == ObjectType.ENTITY && this.pointed.entity != null)
item = this.pointed.entity.getItem();
if(item != null) {
GL11.glPopMatrix();
GL11.glPushMatrix();
GL11.glTranslatef((float)(this.fbX / 2 - 180 + 4 + 1), (float)(this.hudMargin + 20 + 1), 0.0f);
GL11.glScalef(2.0f, 2.0f, 2.0f);
GL46.glPopMatrix();
GL46.glPushMatrix();
GL46.glTranslatef((float)(this.fbX / 2 - 180 + 4 + 1), (float)(this.hudMargin + 20 + 1), 0.0f);
GL46.glScalef(2.0f, 2.0f, 2.0f);
GlState.enableDepth();
this.renderItem.renderItemAndEffectIntoGUI(new ItemStack(item), 0, 0);
}
}
GL11.glPopMatrix();
GL46.glPopMatrix();
ItemRenderer.disableStandardItemLighting();
GlState.disableRescaleNormal();
GlState.disableBlend();
@ -1386,8 +1422,8 @@ public class Client implements IThreadListener {
"Tickrate: %s%.2f" + Color.RESET + " %s [" + Color.GREEN + "%.1f" + Color.RESET + "], %.3f ms, E %d ms" +
"%s%s"
,
GL11.glGetString(GL11.GL_VERSION),
GL11.glGetString(GL11.GL_RENDERER), GL11.glGetString(GL11.GL_VENDOR),
GL46.glGetString(GL46.GL_VERSION),
GL46.glGetString(GL46.GL_RENDERER), GL46.glGetString(GL46.GL_VENDOR),
this.framecode(), this.framerate < 1.0f ? 1.0f / this.framerate : this.framerate, this.framerate < 1.0f ? "SPF" : "FPS",
this.vsync ? Color.DARK_GRAY + "VSYNC" : (this.syncLimited ? Color.GREEN + "" + this.syncLimit : Color.RED + "UNL"),
(float)PerfSection.getTotal(false) / 1000.0f, this.fbRawX, this.fbRawY,
@ -2072,7 +2108,7 @@ public class Client implements IThreadListener {
}
private void fbsize(int x, int y) {
GL11.glViewport(0, 0, x, y);
GL46.glViewport(0, 0, x, y);
this.fbRawX = x;
this.fbRawY = y;
this.rescale();
@ -2209,9 +2245,6 @@ public class Client implements IThreadListener {
case POSITION:
pos(event.param1(), event.param2());
break;
case REDRAW:
// redraw(); disable as it is pretty useless
break;
case RESIZE:
fbsize(event.param1(), event.param2());
break;
@ -2258,22 +2291,22 @@ public class Client implements IThreadListener {
public void setupOverlay() {
GlState.disableDepth();
GlState.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);
GlState.setActiveTexture(GL13.GL_TEXTURE0);
GlState.tryBlendFuncSeparate(GL46.GL_SRC_ALPHA, GL46.GL_ONE_MINUS_SRC_ALPHA, GL46.GL_ONE, GL46.GL_ONE_MINUS_SRC_ALPHA);
GlState.setActiveTexture(GL46.GL_TEXTURE0);
GlState.color(1.0f, 1.0f, 1.0f, 1.0f);
GL11.glClear(256);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0.0D, (double)this.fbRawX, (double)this.fbRawY, 0.0D, 1000.0D, 3000.0D);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glTranslatef(0.0F, 0.0F, -2000.0F);
GL46.glClear(256);
GL46.glMatrixMode(GL46.GL_PROJECTION);
GL46.glLoadIdentity();
GL46.glOrtho(0.0D, (double)this.fbRawX, (double)this.fbRawY, 0.0D, 1000.0D, 3000.0D);
GL46.glMatrixMode(GL46.GL_MODELVIEW);
GL46.glLoadIdentity();
GL46.glTranslatef(0.0F, 0.0F, -2000.0F);
if(this.scale != 1)
GL11.glScalef((float)this.scale, (float)this.scale, 1.0f);
GL46.glScalef((float)this.scale, (float)this.scale, 1.0f);
}
public void scissor(int x, int y, int width, int height) {
GL11.glScissor(x * this.scale, y * this.scale, width * this.scale, height * this.scale);
GL46.glScissor(x * this.scale, y * this.scale, width * this.scale, height * this.scale);
}
private void addFrame(long runningTime)
@ -2312,13 +2345,14 @@ public class Client implements IThreadListener {
public void run(long time) {
if(!Window.createWindow(VERSION, System.getProperty("opengl.debug") != null))
System.exit(1);
if(!GL.getCapabilities().OpenGL15) {
GL.createCapabilities();
if(!GL.getCapabilities().OpenGL46) {
Window.destroyWindow();
Util.panic("Inkompatible OpenGL-Version", "OpenGL 1.5 oder höher ist erforderlich, um dieses Programm auszuführen.");
Util.panic("Inkompatible OpenGL-Version", "OpenGL 4.6 oder höher ist erforderlich, um dieses Programm auszuführen.");
}
Log.SYSTEM.info("OpenGL %s", GL11.glGetString(GL11.GL_VERSION));
Log.SYSTEM.info("GL_VENDOR: %s", GL11.glGetString(GL11.GL_VENDOR));
Log.SYSTEM.info("GL_RENDERER: %s", GL11.glGetString(GL11.GL_RENDERER));
Log.SYSTEM.info("OpenGL %s", GL46.glGetString(GL46.GL_VERSION));
Log.SYSTEM.info("GL_VENDOR: %s", GL46.glGetString(GL46.GL_VENDOR));
Log.SYSTEM.info("GL_RENDERER: %s", GL46.glGetString(GL46.GL_RENDERER));
Log.SYSTEM.info("Starte ...");
this.init();
@ -2328,8 +2362,9 @@ public class Client implements IThreadListener {
Font.loadFonts();
Font.select(this.font);
GlState.enableBlend();
GlState.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GlState.blendFunc(GL46.GL_SRC_ALPHA, GL46.GL_ONE_MINUS_SRC_ALPHA);
this.initConsole();
Shader.loadShaders();
this.startSound(true);
this.vidMode = Window.getDisplayMode();
if(this.vidMode != null && (this.vidMode.width() < MIN_WIDTH || this.vidMode.height() < MIN_HEIGHT))
@ -2358,7 +2393,7 @@ public class Client implements IThreadListener {
Bind.updateBinds();
this.input();
Bind.enableInput();
GlState.setActiveTexture(GL13.GL_TEXTURE0);
GlState.setActiveTexture(GL46.GL_TEXTURE0);
GlState.bindTexture(0);
this.inputGui();
if(this.open != null)
@ -2375,7 +2410,7 @@ public class Client implements IThreadListener {
this.finish();
PerfSection.SWAP.enter();
if(this.glFlush)
GL11.glFlush();
GL46.glFlush();
Window.swapBuffers();
PerfSection.EVENTS.enter();
Log.flushLog();
@ -2399,6 +2434,7 @@ public class Client implements IThreadListener {
Log.flushLog();
this.save();
Font.unloadFonts();
Shader.unloadShaders();
Window.destroyWindow();
Log.SYSTEM.info("Beendet.");
}
@ -2469,7 +2505,7 @@ public class Client implements IThreadListener {
this.saving = true;
final int stride = ((this.fbRawX * 3) & 3) != 0 ? 4 + ((this.fbRawX * 3) & ~3) : (this.fbRawX * 3);
final ByteBuffer data = ByteBuffer.allocateDirect(stride * this.fbRawY).order(ByteOrder.nativeOrder());
GL11.glReadPixels(0, 0, this.fbRawX, this.fbRawY, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, data);
GL46.glReadPixels(0, 0, this.fbRawX, this.fbRawY, GL46.GL_RGB, GL46.GL_UNSIGNED_BYTE, data);
new Thread(new Runnable() {
public void run() {
byte[] pixels = new byte[stride * Client.this.fbRawY];
@ -3209,17 +3245,17 @@ public class Client implements IThreadListener {
private void renderWorldDirections(float partialTicks) {
GlState.enableBlend();
GlState.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
GL11.glLineWidth(1.0F);
GlState.tryBlendFuncSeparate(GL46.GL_SRC_ALPHA, GL46.GL_ONE_MINUS_SRC_ALPHA, GL46.GL_ONE, GL46.GL_ZERO);
GL46.glLineWidth(1.0F);
GlState.disableTexture2D();
GlState.depthMask(false);
GL11.glPushMatrix();
GL11.glTranslatef((float)(this.fbX / 2), (float)(this.fbY / 2), 0.0F);
GL46.glPushMatrix();
GL46.glTranslatef((float)(this.fbX / 2), (float)(this.fbY / 2), 0.0F);
this.renderer.rotateCamera(this.viewEntity, partialTicks, true);
Renderer.drawOutlinedBoundingBox(new BoundingBox(0.0D, 0.0D, 0.0D, 24D, 1D, 1D), 255, 0, 0, 255);
Renderer.drawOutlinedBoundingBox(new BoundingBox(0.0D, 0.0D, 0.0D, 1D, 1D, 24D), 0, 0, 255, 255);
Renderer.drawOutlinedBoundingBox(new BoundingBox(0.0D, 0.0D, 0.0D, 1D, -20D, 1D), 0, 255, 0, 255);
GL11.glPopMatrix();
GL46.glPopMatrix();
GlState.depthMask(true);
GlState.enableTexture2D();
GlState.disableBlend();
@ -3775,6 +3811,14 @@ public class Client implements IThreadListener {
public List<TileEntity> getTiles() {
return this.tiles;
}
public void lightSetup() {
Shader.WORLD.update();
// if(win->world) {
// glNamedBufferData(win->world->light_buf, LIGHT_SSIZE * gdr.light_max, NULL, GL_DYNAMIC_DRAW);
// light_calc(win->world);
// }
}
private static byte[] genTriwave(int w, int h, int color1, int color2, int color3, int color4, int color5, int color6) {
byte[] data = new byte[w * h * 4];