mirror of
https://github.com/Eaglercraft-Archive/Eaglercraftx-1.8.8-src.git
synced 2025-06-27 18:38:14 -05:00
Update #18 - Final release, added PBR shaders
This commit is contained in:
@ -0,0 +1,99 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IBufferArrayGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IBufferGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.buffer.FloatBuffer;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.FixedFunctionShader.FixedFunctionConstants;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class DrawUtils {
|
||||
|
||||
public static final String vertexShaderPath = "/assets/eagler/glsl/local.vsh";
|
||||
|
||||
public static IBufferArrayGL standardQuad2DVAO = null;
|
||||
public static IBufferArrayGL standardQuad3DVAO = null;
|
||||
public static IBufferGL standardQuadVBO = null;
|
||||
|
||||
public static IShaderGL vshLocal = null;
|
||||
|
||||
static void init() {
|
||||
if(standardQuad2DVAO == null) {
|
||||
standardQuad2DVAO = _wglGenVertexArrays();
|
||||
standardQuad3DVAO = _wglGenVertexArrays();
|
||||
standardQuadVBO = _wglGenBuffers();
|
||||
|
||||
FloatBuffer verts = EagRuntime.allocateFloatBuffer(18);
|
||||
verts.put(new float[] {
|
||||
-1.0f, -1.0f, 0.0f, 1.0f, -1.0f, 0.0f, -1.0f, 1.0f, 0.0f,
|
||||
1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, -1.0f, 1.0f, 0.0f
|
||||
});
|
||||
verts.flip();
|
||||
|
||||
EaglercraftGPU.bindGLArrayBuffer(standardQuadVBO);
|
||||
_wglBufferData(GL_ARRAY_BUFFER, verts, GL_STATIC_DRAW);
|
||||
EagRuntime.freeFloatBuffer(verts);
|
||||
|
||||
EaglercraftGPU.bindGLBufferArray(standardQuad2DVAO);
|
||||
|
||||
_wglEnableVertexAttribArray(0);
|
||||
_wglVertexAttribPointer(0, 2, GL_FLOAT, false, 12, 0);
|
||||
|
||||
EaglercraftGPU.bindGLBufferArray(standardQuad3DVAO);
|
||||
|
||||
_wglEnableVertexAttribArray(0);
|
||||
_wglVertexAttribPointer(0, 3, GL_FLOAT, false, 12, 0);
|
||||
}
|
||||
|
||||
if(vshLocal == null) {
|
||||
String vertexSource = EagRuntime.getResourceString(vertexShaderPath);
|
||||
if(vertexSource == null) {
|
||||
throw new RuntimeException("vertex shader \"" + vertexShaderPath + "\" is missing!");
|
||||
}
|
||||
|
||||
vshLocal = _wglCreateShader(GL_VERTEX_SHADER);
|
||||
|
||||
_wglShaderSource(vshLocal, FixedFunctionConstants.VERSION + "\n" + vertexSource);
|
||||
_wglCompileShader(vshLocal);
|
||||
|
||||
if(_wglGetShaderi(vshLocal, GL_COMPILE_STATUS) != GL_TRUE) {
|
||||
EaglercraftGPU.logger.error("Failed to compile GL_VERTEX_SHADER \"" + vertexShaderPath + "\"!");
|
||||
String log = _wglGetShaderInfoLog(vshLocal);
|
||||
if(log != null) {
|
||||
String[] lines = log.split("(\\r\\n|\\r|\\n)");
|
||||
for(int i = 0; i < lines.length; ++i) {
|
||||
EaglercraftGPU.logger.error("[VERT] {}", lines[i]);
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("Vertex shader \"" + vertexShaderPath + "\" could not be compiled!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawStandardQuad2D() {
|
||||
EaglercraftGPU.bindGLBufferArray(standardQuad2DVAO);
|
||||
_wglDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
}
|
||||
|
||||
public static void drawStandardQuad3D() {
|
||||
EaglercraftGPU.bindGLBufferArray(standardQuad3DVAO);
|
||||
_wglDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
}
|
||||
|
||||
}
|
@ -3,6 +3,9 @@ package net.lax1dude.eaglercraft.v1_8.opengl;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.buffer.FloatBuffer;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.buffer.IntBuffer;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -37,7 +40,9 @@ public class EaglercraftGPU {
|
||||
static final GLObjectMap<ITextureGL> mapTexturesGL = new GLObjectMap(32767);
|
||||
static final GLObjectMap<IQueryGL> mapQueriesGL = new GLObjectMap(32767);
|
||||
static final GLObjectMap<DisplayList> mapDisplayListsGL = new GLObjectMap(32767);
|
||||
|
||||
|
||||
static final Logger logger = LogManager.getLogger("EaglercraftGPU");
|
||||
|
||||
public static final String gluErrorString(int i) {
|
||||
switch(i) {
|
||||
case GL_INVALID_ENUM: return "GL_INVALID_ENUM";
|
||||
@ -123,6 +128,7 @@ public class EaglercraftGPU {
|
||||
_wglDeleteBuffers(dp.vertexBuffer);
|
||||
dp.vertexBuffer = null;
|
||||
}
|
||||
currentList = null;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -239,6 +245,10 @@ public class EaglercraftGPU {
|
||||
int type, IntBuffer pixels) {
|
||||
_wglTexSubImage2D(target, level, x, y, w, h, format, type, pixels);
|
||||
}
|
||||
|
||||
public static final void glTexStorage2D(int target, int levels, int internalFormat, int w, int h) {
|
||||
_wglTexStorage2D(target, levels, internalFormat, w, h);
|
||||
}
|
||||
|
||||
public static final void glLineWidth(float f) {
|
||||
_wglLineWidth(f);
|
||||
@ -293,31 +303,54 @@ public class EaglercraftGPU {
|
||||
|
||||
private static IBufferArrayGL currentBufferArray = null;
|
||||
|
||||
static final void bindGLBufferArray(IBufferArrayGL buffer) {
|
||||
public static final void bindGLBufferArray(IBufferArrayGL buffer) {
|
||||
if(currentBufferArray != buffer) {
|
||||
PlatformOpenGL._wglBindVertexArray(buffer);
|
||||
_wglBindVertexArray(buffer);
|
||||
currentBufferArray = buffer;
|
||||
}
|
||||
}
|
||||
|
||||
private static IBufferGL currentArrayBuffer = null;
|
||||
|
||||
static final void bindGLArrayBuffer(IBufferGL buffer) {
|
||||
public static final void bindGLArrayBuffer(IBufferGL buffer) {
|
||||
if(currentArrayBuffer != buffer) {
|
||||
PlatformOpenGL._wglBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
_wglBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
currentArrayBuffer = buffer;
|
||||
}
|
||||
}
|
||||
|
||||
private static IBufferGL currentUniformBuffer = null;
|
||||
|
||||
public static final void bindGLUniformBuffer(IBufferGL buffer) {
|
||||
if(currentUniformBuffer != buffer) {
|
||||
_wglBindBuffer(0x8A11, buffer);
|
||||
currentUniformBuffer = buffer;
|
||||
}
|
||||
}
|
||||
|
||||
private static IProgramGL currentShaderProgram = null;
|
||||
|
||||
static final void bindGLShaderProgram(IProgramGL prog) {
|
||||
public static final void bindGLShaderProgram(IProgramGL prog) {
|
||||
if(currentShaderProgram != prog) {
|
||||
PlatformOpenGL._wglUseProgram(prog);
|
||||
_wglUseProgram(prog);
|
||||
currentShaderProgram = prog;
|
||||
}
|
||||
}
|
||||
|
||||
private static final IBufferGL[] currentUniformBlockBindings = new IBufferGL[16];
|
||||
private static final int[] currentUniformBlockBindingOffset = new int[16];
|
||||
private static final int[] currentUniformBlockBindingSize = new int[16];
|
||||
|
||||
public static final void bindUniformBufferRange(int index, IBufferGL buffer, int offset, int size) {
|
||||
if(currentUniformBlockBindings[index] != buffer || currentUniformBlockBindingOffset[index] != offset
|
||||
|| currentUniformBlockBindingSize[index] != size) {
|
||||
_wglBindBufferRange(0x8A11, index, buffer, offset, size);
|
||||
currentUniformBlockBindings[index] = buffer;
|
||||
currentUniformBlockBindingOffset[index] = offset;
|
||||
currentUniformBlockBindingSize[index] = size;
|
||||
}
|
||||
}
|
||||
|
||||
public static final int ATTRIB_TEXTURE = 1;
|
||||
public static final int ATTRIB_COLOR = 2;
|
||||
public static final int ATTRIB_NORMAL = 4;
|
||||
@ -349,6 +382,10 @@ public class EaglercraftGPU {
|
||||
}
|
||||
}
|
||||
|
||||
public static final void optimize() {
|
||||
FixedFunctionPipeline.optimize();
|
||||
}
|
||||
|
||||
private static FixedFunctionPipeline lastRender = null;
|
||||
private static int lastMode = 0;
|
||||
private static int lastCount = 0;
|
||||
@ -367,7 +404,7 @@ public class EaglercraftGPU {
|
||||
private static IBufferGL quad32EmulationBuffer = null;
|
||||
private static int quad32EmulationBufferSize = 0;
|
||||
|
||||
static final void attachQuad16EmulationBuffer(int vertexCount, boolean bind) {
|
||||
public static final void attachQuad16EmulationBuffer(int vertexCount, boolean bind) {
|
||||
IBufferGL buf = quad16EmulationBuffer;
|
||||
if(buf == null) {
|
||||
quad16EmulationBuffer = buf = _wglGenBuffers();
|
||||
@ -392,7 +429,7 @@ public class EaglercraftGPU {
|
||||
}
|
||||
}
|
||||
|
||||
static final void attachQuad32EmulationBuffer(int vertexCount, boolean bind) {
|
||||
public static final void attachQuad32EmulationBuffer(int vertexCount, boolean bind) {
|
||||
IBufferGL buf = quad32EmulationBuffer;
|
||||
if(buf == null) {
|
||||
quad32EmulationBuffer = buf = _wglGenBuffers();
|
||||
@ -445,19 +482,132 @@ public class EaglercraftGPU {
|
||||
EagRuntime.freeIntBuffer(buf);
|
||||
}
|
||||
|
||||
public static final void warmUpCache() {
|
||||
EaglercraftGPU.glGetString(7936);
|
||||
EaglercraftGPU.glGetString(7937);
|
||||
EaglercraftGPU.glGetString(7938);
|
||||
SpriteLevelMixer.initialize();
|
||||
InstancedFontRenderer.initialize();
|
||||
InstancedParticleRenderer.initialize();
|
||||
EffectPipelineFXAA.initialize();
|
||||
SpriteLevelMixer.vshLocal.free();
|
||||
}
|
||||
|
||||
public static final ITextureGL getNativeTexture(int tex) {
|
||||
return mapTexturesGL.get(tex);
|
||||
}
|
||||
|
||||
static boolean hasFramebufferHDR16FSupport = false;
|
||||
static boolean hasFramebufferHDR32FSupport = false;
|
||||
|
||||
public static void createFramebufferHDR16FTexture(int target, int level, int w, int h, int format, boolean allow32bitFallback) {
|
||||
createFramebufferHDR16FTexture(target, level, w, h, format, allow32bitFallback, null);
|
||||
}
|
||||
|
||||
public static void createFramebufferHDR16FTexture(int target, int level, int w, int h, int format, ByteBuffer pixelData) {
|
||||
createFramebufferHDR16FTexture(target, level, w, h, format, false, pixelData);
|
||||
}
|
||||
|
||||
private static void createFramebufferHDR16FTexture(int target, int level, int w, int h, int format, boolean allow32bitFallback, ByteBuffer pixelData) {
|
||||
if(hasFramebufferHDR16FSupport) {
|
||||
int internalFormat;
|
||||
switch(format) {
|
||||
case GL_RED:
|
||||
internalFormat = 0x822D; // GL_R16F
|
||||
break;
|
||||
case 0x8227: // GL_RG
|
||||
internalFormat = 0x822F; // GL_RG16F
|
||||
case GL_RGB:
|
||||
throw new UnsupportedOperationException("GL_RGB16F isn't supported specifically in WebGL 2.0 for some goddamn reason");
|
||||
case GL_RGBA:
|
||||
internalFormat = 0x881A; // GL_RGBA16F
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unknown format: " + format);
|
||||
}
|
||||
_wglTexImage2Du16(target, level, internalFormat, w, h, 0, format, 0x140B, pixelData);
|
||||
}else {
|
||||
if(allow32bitFallback) {
|
||||
if(hasFramebufferHDR32FSupport) {
|
||||
createFramebufferHDR32FTexture(target, level, w, h, format, false, null);
|
||||
}else {
|
||||
throw new UnsupportedOperationException("No fallback 32-bit HDR (floating point) texture support is available on this device");
|
||||
}
|
||||
}else {
|
||||
throw new UnsupportedOperationException("16-bit HDR (floating point) textures are not supported on this device");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void createFramebufferHDR32FTexture(int target, int level, int w, int h, int format, boolean allow16bitFallback) {
|
||||
createFramebufferHDR32FTexture(target, level, w, h, format, allow16bitFallback, null);
|
||||
}
|
||||
|
||||
public static void createFramebufferHDR32FTexture(int target, int level, int w, int h, int format, ByteBuffer pixelData) {
|
||||
createFramebufferHDR32FTexture(target, level, w, h, format, false, pixelData);
|
||||
}
|
||||
|
||||
private static void createFramebufferHDR32FTexture(int target, int level, int w, int h, int format, boolean allow16bitFallback, ByteBuffer pixelData) {
|
||||
if(hasFramebufferHDR32FSupport) {
|
||||
int internalFormat;
|
||||
switch(format) {
|
||||
case GL_RED:
|
||||
internalFormat = 0x822E; // GL_R32F
|
||||
break;
|
||||
case 0x8227: // GL_RG
|
||||
internalFormat = 0x822F; // GL_RG32F
|
||||
case GL_RGB:
|
||||
throw new UnsupportedOperationException("GL_RGB32F isn't supported specifically in WebGL 2.0 for some goddamn reason");
|
||||
case GL_RGBA:
|
||||
internalFormat = 0x8814; //GL_RGBA32F
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unknown format: " + format);
|
||||
}
|
||||
_wglTexImage2D(target, level, internalFormat, w, h, 0, format, GL_FLOAT, pixelData);
|
||||
}else {
|
||||
if(allow16bitFallback) {
|
||||
if(hasFramebufferHDR16FSupport) {
|
||||
createFramebufferHDR16FTexture(target, level, w, h, format, false);
|
||||
}else {
|
||||
throw new UnsupportedOperationException("No fallback 16-bit HDR (floating point) texture support is available on this device");
|
||||
}
|
||||
}else {
|
||||
throw new UnsupportedOperationException("32-bit HDR (floating point) textures are not supported on this device");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final void warmUpCache() {
|
||||
EaglercraftGPU.glGetString(7936);
|
||||
EaglercraftGPU.glGetString(7937);
|
||||
EaglercraftGPU.glGetString(7938);
|
||||
hasFramebufferHDR16FSupport = PlatformOpenGL.checkHDRFramebufferSupport(16);
|
||||
if(hasFramebufferHDR16FSupport) {
|
||||
logger.info("16-bit HDR render target support: true");
|
||||
}else {
|
||||
logger.error("16-bit HDR render target support: false");
|
||||
}
|
||||
hasFramebufferHDR32FSupport = PlatformOpenGL.checkHDRFramebufferSupport(32);
|
||||
if(hasFramebufferHDR32FSupport) {
|
||||
logger.info("32-bit HDR render target support: true");
|
||||
}else {
|
||||
logger.error("32-bit HDR render target support: false");
|
||||
}
|
||||
if(!checkHasHDRFramebufferSupport()) {
|
||||
logger.error("No HDR render target support was detected! Shaders will be disabled.");
|
||||
}
|
||||
DrawUtils.init();
|
||||
SpriteLevelMixer.initialize();
|
||||
InstancedFontRenderer.initialize();
|
||||
InstancedParticleRenderer.initialize();
|
||||
EffectPipelineFXAA.initialize();
|
||||
TextureCopyUtil.initialize();
|
||||
DrawUtils.vshLocal.free();
|
||||
DrawUtils.vshLocal = null;
|
||||
}
|
||||
|
||||
public static final boolean checkHDRFramebufferSupport(int bits) {
|
||||
switch(bits) {
|
||||
case 16:
|
||||
return hasFramebufferHDR16FSupport;
|
||||
case 32:
|
||||
return hasFramebufferHDR32FSupport;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static final boolean checkHasHDRFramebufferSupport() {
|
||||
return hasFramebufferHDR16FSupport || hasFramebufferHDR32FSupport;
|
||||
}
|
||||
}
|
||||
|
@ -75,12 +75,12 @@ public class EffectPipelineFXAA {
|
||||
|
||||
shaderProgram = _wglCreateProgram();
|
||||
|
||||
_wglAttachShader(shaderProgram, SpriteLevelMixer.vshLocal);
|
||||
_wglAttachShader(shaderProgram, DrawUtils.vshLocal);
|
||||
_wglAttachShader(shaderProgram, frag);
|
||||
|
||||
_wglLinkProgram(shaderProgram);
|
||||
|
||||
_wglDetachShader(shaderProgram, SpriteLevelMixer.vshLocal);
|
||||
_wglDetachShader(shaderProgram, DrawUtils.vshLocal);
|
||||
_wglDetachShader(shaderProgram, frag);
|
||||
|
||||
_wglDeleteShader(frag);
|
||||
@ -144,14 +144,13 @@ public class EffectPipelineFXAA {
|
||||
public static void end() {
|
||||
_wglBindFramebuffer(_GL_FRAMEBUFFER, null);
|
||||
|
||||
EaglercraftGPU.bindGLBufferArray(SpriteLevelMixer.vertexArray);
|
||||
EaglercraftGPU.bindGLShaderProgram(shaderProgram);
|
||||
|
||||
GlStateManager.bindTexture(framebufferColor);
|
||||
|
||||
_wglUniform2f(u_screenSize2f, 1.0f / currentWidth, 1.0f / currentHeight);
|
||||
|
||||
_wglDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,9 @@ package net.lax1dude.eaglercraft.v1_8.opengl;
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.buffer.FloatBuffer;
|
||||
|
||||
@ -16,11 +19,14 @@ import net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.PlatformRuntime;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.FixedFunctionShader.FixedFunctionConstants;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.StreamBuffer.StreamBufferInstance;
|
||||
import net.lax1dude.eaglercraft.v1_8.vector.Matrix4f;
|
||||
import net.lax1dude.eaglercraft.v1_8.vector.Vector4f;
|
||||
import net.minecraft.util.MathHelper;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.FixedFunctionShader.FixedFunctionState.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.FixedFunctionShader.FixedFunctionConstants.*;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2022-2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
@ -34,23 +40,10 @@ import net.minecraft.util.MathHelper;
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
class FixedFunctionPipeline {
|
||||
public class FixedFunctionPipeline {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger("FixedFunctionPipeline");
|
||||
|
||||
static final int STATE_HAS_ATTRIB_TEXTURE = 1;
|
||||
static final int STATE_HAS_ATTRIB_COLOR = 2;
|
||||
static final int STATE_HAS_ATTRIB_NORMAL = 4;
|
||||
static final int STATE_HAS_ATTRIB_LIGHTMAP = 8;
|
||||
static final int STATE_ENABLE_TEXTURE2D = 16;
|
||||
static final int STATE_ENABLE_LIGHTMAP = 32;
|
||||
static final int STATE_ENABLE_ALPHA_TEST = 64;
|
||||
static final int STATE_ENABLE_MC_LIGHTING = 128;
|
||||
static final int STATE_ENABLE_END_PORTAL = 256;
|
||||
static final int STATE_ENABLE_ANISOTROPIC_FIX = 512;
|
||||
static final int STATE_ENABLE_FOG = 1024;
|
||||
static final int STATE_ENABLE_BLEND_ADD = 2048;
|
||||
|
||||
static final int getFragmentState() {
|
||||
return (GlStateManager.stateTexture[0] ? STATE_ENABLE_TEXTURE2D : 0) |
|
||||
(GlStateManager.stateTexture[1] ? STATE_ENABLE_LIGHTMAP : 0) |
|
||||
@ -66,25 +59,41 @@ class FixedFunctionPipeline {
|
||||
}
|
||||
|
||||
static FixedFunctionPipeline setupDirect(ByteBuffer buffer, int attrib) {
|
||||
FixedFunctionPipeline self = getPipelineInstance(attrib | getFragmentState());
|
||||
|
||||
EaglercraftGPU.bindGLBufferArray(self.vertexArray);
|
||||
EaglercraftGPU.bindGLArrayBuffer(self.vertexBuffer);
|
||||
|
||||
int wantSize = buffer.remaining();
|
||||
if(self.vertexBufferSize < wantSize) {
|
||||
int newSize = (wantSize & 0xFFFFF000) + 0x2000;
|
||||
_wglBufferData(GL_ARRAY_BUFFER, newSize, GL_DYNAMIC_DRAW);
|
||||
self.vertexBufferSize = newSize;
|
||||
FixedFunctionPipeline self;
|
||||
int baseState = attrib | getFragmentState();
|
||||
if(GlStateManager.stateUseExtensionPipeline) {
|
||||
if(extensionProvider != null) {
|
||||
self = getPipelineInstanceExt(baseState, extensionProvider.getCurrentExtensionStateBits(baseState));
|
||||
}else {
|
||||
throw new IllegalStateException("No extension pipeline is available!");
|
||||
}
|
||||
}else {
|
||||
self = getPipelineInstanceCore(baseState);
|
||||
}
|
||||
|
||||
StreamBufferInstance sb = self.streamBuffer.getBuffer(buffer.remaining());
|
||||
self.currentVertexArray = sb;
|
||||
|
||||
EaglercraftGPU.bindGLBufferArray(sb.vertexArray);
|
||||
EaglercraftGPU.bindGLArrayBuffer(sb.vertexBuffer);
|
||||
|
||||
_wglBufferSubData(GL_ARRAY_BUFFER, 0, buffer);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
static void setupDisplayList(DisplayList list) {
|
||||
FixedFunctionPipeline self = getPipelineInstance(list.attribs | getFragmentState());
|
||||
FixedFunctionPipeline self;
|
||||
int baseState = list.attribs | getFragmentState();
|
||||
if(GlStateManager.stateUseExtensionPipeline) {
|
||||
if(extensionProvider != null) {
|
||||
self = getPipelineInstanceExt(baseState, extensionProvider.getCurrentExtensionStateBits(baseState));
|
||||
}else {
|
||||
throw new IllegalStateException("No extension pipeline is available!");
|
||||
}
|
||||
}else {
|
||||
self = getPipelineInstanceCore(baseState);
|
||||
}
|
||||
|
||||
EaglercraftGPU.bindGLBufferArray(list.vertexArray);
|
||||
EaglercraftGPU.bindGLArrayBuffer(list.vertexBuffer);
|
||||
@ -120,7 +129,16 @@ class FixedFunctionPipeline {
|
||||
}
|
||||
|
||||
static FixedFunctionPipeline setupRenderDisplayList(int attribs) {
|
||||
return getPipelineInstance(attribs | getFragmentState());
|
||||
int baseState = attribs | getFragmentState();
|
||||
if(GlStateManager.stateUseExtensionPipeline) {
|
||||
if(extensionProvider != null) {
|
||||
return getPipelineInstanceExt(baseState, extensionProvider.getCurrentExtensionStateBits(baseState));
|
||||
}else {
|
||||
throw new IllegalStateException("No extension pipeline is available!");
|
||||
}
|
||||
}else {
|
||||
return getPipelineInstanceCore(baseState);
|
||||
}
|
||||
}
|
||||
|
||||
void drawArrays(int mode, int offset, int count) {
|
||||
@ -131,10 +149,11 @@ class FixedFunctionPipeline {
|
||||
void drawDirectArrays(int mode, int offset, int count) {
|
||||
EaglercraftGPU.bindGLShaderProgram(shaderProgram);
|
||||
if(mode == GL_QUADS) {
|
||||
StreamBufferInstance sb = currentVertexArray;
|
||||
if(count > 0xFFFF) {
|
||||
if(!bindQuad32) {
|
||||
bindQuad16 = false;
|
||||
bindQuad32 = true;
|
||||
if(!sb.bindQuad32) {
|
||||
sb.bindQuad16 = false;
|
||||
sb.bindQuad32 = true;
|
||||
EaglercraftGPU.attachQuad32EmulationBuffer(count, true);
|
||||
}else {
|
||||
EaglercraftGPU.attachQuad32EmulationBuffer(count, false);
|
||||
@ -142,9 +161,9 @@ class FixedFunctionPipeline {
|
||||
PlatformOpenGL._wglDrawElements(GL_TRIANGLES, count + (count >> 1),
|
||||
GL_UNSIGNED_INT, 0);
|
||||
}else {
|
||||
if(!bindQuad16) {
|
||||
bindQuad16 = true;
|
||||
bindQuad32 = false;
|
||||
if(!sb.bindQuad16) {
|
||||
sb.bindQuad16 = true;
|
||||
sb.bindQuad32 = false;
|
||||
EaglercraftGPU.attachQuad16EmulationBuffer(count, true);
|
||||
}else {
|
||||
EaglercraftGPU.attachQuad16EmulationBuffer(count, false);
|
||||
@ -162,142 +181,203 @@ class FixedFunctionPipeline {
|
||||
PlatformOpenGL._wglDrawElements(mode, count, type, offset);
|
||||
}
|
||||
|
||||
private static final FixedFunctionPipeline[] pipelineStateCache = new FixedFunctionPipeline[4096];
|
||||
private static IExtPipelineCompiler extensionProvider;
|
||||
|
||||
public static void loadExtensionPipeline(IExtPipelineCompiler provider) {
|
||||
flushCache();
|
||||
extensionProvider = provider;
|
||||
}
|
||||
|
||||
private static final FixedFunctionPipeline[] pipelineStateCache = new FixedFunctionPipeline[fixedFunctionStatesBits + 1];
|
||||
private static final FixedFunctionPipeline[][] pipelineExtStateCache = new FixedFunctionPipeline[fixedFunctionStatesBits + 1][];
|
||||
private static final List<FixedFunctionPipeline> pipelineListTracker = new ArrayList(1024);
|
||||
|
||||
private static String shaderSourceCacheVSH = null;
|
||||
private static String shaderSourceCacheFSH = null;
|
||||
|
||||
private static FixedFunctionPipeline getPipelineInstance(int bits) {
|
||||
private static FixedFunctionPipeline getPipelineInstanceCore(int bits) {
|
||||
FixedFunctionPipeline pp = pipelineStateCache[bits];
|
||||
if(pp == null) {
|
||||
if(shaderSourceCacheVSH == null) {
|
||||
shaderSourceCacheVSH = EagRuntime.getResourceString(FixedFunctionConstants.FILENAME_VSH);
|
||||
if(shaderSourceCacheVSH == null) {
|
||||
throw new RuntimeException("Could not load: " + FixedFunctionConstants.FILENAME_VSH);
|
||||
}
|
||||
}
|
||||
if(shaderSourceCacheFSH == null) {
|
||||
shaderSourceCacheFSH = EagRuntime.getResourceString(FixedFunctionConstants.FILENAME_FSH);
|
||||
if(shaderSourceCacheFSH == null) {
|
||||
throw new RuntimeException("Could not load: " + FixedFunctionConstants.FILENAME_FSH);
|
||||
}
|
||||
}
|
||||
|
||||
String macros = FixedFunctionConstants.VERSION + "\n";
|
||||
if((bits & STATE_HAS_ATTRIB_TEXTURE) == STATE_HAS_ATTRIB_TEXTURE) {
|
||||
macros += ("#define " + FixedFunctionConstants.MACRO_ATTRIB_TEXTURE + "\n");
|
||||
}
|
||||
if((bits & STATE_HAS_ATTRIB_COLOR) == STATE_HAS_ATTRIB_COLOR) {
|
||||
macros += ("#define " + FixedFunctionConstants.MACRO_ATTRIB_COLOR + "\n");
|
||||
}
|
||||
if((bits & STATE_HAS_ATTRIB_NORMAL) == STATE_HAS_ATTRIB_NORMAL) {
|
||||
macros += ("#define " + FixedFunctionConstants.MACRO_ATTRIB_NORMAL + "\n");
|
||||
}
|
||||
if((bits & STATE_HAS_ATTRIB_LIGHTMAP) == STATE_HAS_ATTRIB_LIGHTMAP) {
|
||||
macros += ("#define " + FixedFunctionConstants.MACRO_ATTRIB_LIGHTMAP + "\n");
|
||||
}
|
||||
if((bits & STATE_ENABLE_TEXTURE2D) == STATE_ENABLE_TEXTURE2D) {
|
||||
macros += ("#define " + FixedFunctionConstants.MACRO_ENABLE_TEXTURE2D + "\n");
|
||||
}
|
||||
if((bits & STATE_ENABLE_LIGHTMAP) == STATE_ENABLE_LIGHTMAP) {
|
||||
macros += ("#define " + FixedFunctionConstants.MACRO_ENABLE_LIGHTMAP + "\n");
|
||||
}
|
||||
if((bits & STATE_ENABLE_ALPHA_TEST) == STATE_ENABLE_ALPHA_TEST) {
|
||||
macros += ("#define " + FixedFunctionConstants.MACRO_ENABLE_ALPHA_TEST + "\n");
|
||||
}
|
||||
if((bits & STATE_ENABLE_MC_LIGHTING) == STATE_ENABLE_MC_LIGHTING) {
|
||||
macros += ("#define " + FixedFunctionConstants.MACRO_ENABLE_MC_LIGHTING + "\n");
|
||||
}
|
||||
if((bits & STATE_ENABLE_END_PORTAL) == STATE_ENABLE_END_PORTAL) {
|
||||
macros += ("#define " + FixedFunctionConstants.MACRO_ENABLE_END_PORTAL + "\n");
|
||||
}
|
||||
if((bits & STATE_ENABLE_ANISOTROPIC_FIX) == STATE_ENABLE_ANISOTROPIC_FIX) {
|
||||
macros += ("#define " + FixedFunctionConstants.MACRO_ENABLE_ANISOTROPIC_FIX + "\n");
|
||||
}
|
||||
if((bits & STATE_ENABLE_FOG) == STATE_ENABLE_FOG) {
|
||||
macros += ("#define " + FixedFunctionConstants.MACRO_ENABLE_FOG + "\n");
|
||||
}
|
||||
if((bits & STATE_ENABLE_BLEND_ADD) == STATE_ENABLE_BLEND_ADD) {
|
||||
macros += ("#define " + FixedFunctionConstants.MACRO_ENABLE_BLEND_ADD + "\n");
|
||||
}
|
||||
|
||||
macros += ("precision " + FixedFunctionConstants.PRECISION_INT + " int;\n");
|
||||
macros += ("precision " + FixedFunctionConstants.PRECISION_FLOAT + " float;\n");
|
||||
macros += ("precision " + FixedFunctionConstants.PRECISION_SAMPLER + " sampler2D;\n\n");
|
||||
|
||||
IShaderGL vsh = _wglCreateShader(GL_VERTEX_SHADER);
|
||||
|
||||
_wglShaderSource(vsh, macros + shaderSourceCacheVSH);
|
||||
_wglCompileShader(vsh);
|
||||
|
||||
if(_wglGetShaderi(vsh, GL_COMPILE_STATUS) != GL_TRUE) {
|
||||
LOGGER.error("Failed to compile GL_VERTEX_SHADER for state {} !", getStateBits(bits, 11));
|
||||
String log = _wglGetShaderInfoLog(vsh);
|
||||
if(log != null) {
|
||||
String[] lines = log.split("(\\r\\n|\\r|\\n)");
|
||||
for(int i = 0; i < lines.length; ++i) {
|
||||
LOGGER.error("[VERT] {}", lines[i]);
|
||||
}
|
||||
}
|
||||
_wglDeleteShader(vsh);
|
||||
throw new IllegalStateException("Vertex shader could not be compiled!");
|
||||
}
|
||||
|
||||
IShaderGL fsh = _wglCreateShader(GL_FRAGMENT_SHADER);
|
||||
|
||||
_wglShaderSource(fsh, macros + shaderSourceCacheFSH);
|
||||
_wglCompileShader(fsh);
|
||||
|
||||
if(_wglGetShaderi(fsh, GL_COMPILE_STATUS) != GL_TRUE) {
|
||||
LOGGER.error("Failed to compile GL_FRAGMENT_SHADER for state {} !", getStateBits(bits, 11));
|
||||
String log = _wglGetShaderInfoLog(fsh);
|
||||
if(log != null) {
|
||||
String[] lines = log.split("(\\r\\n|\\r|\\n)");
|
||||
for(int i = 0; i < lines.length; ++i) {
|
||||
LOGGER.error("[FRAG] {}", lines[i]);
|
||||
}
|
||||
}
|
||||
_wglDeleteShader(fsh);
|
||||
_wglDeleteShader(vsh);
|
||||
throw new IllegalStateException("Fragment shader could not be compiled!");
|
||||
}
|
||||
|
||||
IProgramGL prog = _wglCreateProgram();
|
||||
|
||||
_wglAttachShader(prog, vsh);
|
||||
_wglAttachShader(prog, fsh);
|
||||
|
||||
IllegalStateException err = null;
|
||||
try {
|
||||
pp = new FixedFunctionPipeline(bits, prog);
|
||||
}catch(IllegalStateException t) {
|
||||
err = t;
|
||||
}
|
||||
|
||||
_wglDetachShader(prog, vsh);
|
||||
_wglDetachShader(prog, fsh);
|
||||
_wglDeleteShader(fsh);
|
||||
_wglDeleteShader(vsh);
|
||||
|
||||
if(err != null) {
|
||||
_wglDeleteProgram(prog);
|
||||
throw err;
|
||||
}else {
|
||||
pipelineStateCache[bits] = pp;
|
||||
}
|
||||
pipelineStateCache[bits] = pp = makeNewPipeline(bits, 0, false);
|
||||
}
|
||||
return pp;
|
||||
}
|
||||
|
||||
private static String getStateBits(int input, int bits) {
|
||||
String out = "";
|
||||
for(int i = bits - 1; i >= 0; --i) {
|
||||
out += (input >> bits) & 1;
|
||||
private static FixedFunctionPipeline getPipelineInstanceExt(int coreBits, int extBits) {
|
||||
coreBits &= (15 | extensionProvider.getCoreStateMask(extBits));
|
||||
FixedFunctionPipeline[] pp = pipelineExtStateCache[coreBits];
|
||||
if(pp == null) {
|
||||
pipelineExtStateCache[coreBits] = pp = new FixedFunctionPipeline[1 << extensionProvider.getExtensionStatesCount()];
|
||||
return pp[extBits] = makeNewPipeline(coreBits, extBits, true);
|
||||
}else {
|
||||
FixedFunctionPipeline ppp = pp[extBits];
|
||||
if(ppp == null) {
|
||||
pp[extBits] = ppp = makeNewPipeline(coreBits, extBits, true);
|
||||
}
|
||||
return ppp;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
private static FixedFunctionPipeline makeNewPipeline(int coreBits, int extBits, boolean enableExt) {
|
||||
String vshSource;
|
||||
String fshSource;
|
||||
|
||||
Object[] extProviderUserPointer = null;
|
||||
if(enableExt) {
|
||||
extProviderUserPointer = new Object[1];
|
||||
String[] extSource = extensionProvider.getShaderSource(coreBits, extBits, extProviderUserPointer);
|
||||
vshSource = extSource[0];
|
||||
fshSource = extSource[1];
|
||||
}else {
|
||||
if(shaderSourceCacheVSH == null) {
|
||||
shaderSourceCacheVSH = EagRuntime.getResourceString(FILENAME_VSH);
|
||||
if(shaderSourceCacheVSH == null) {
|
||||
throw new RuntimeException("Could not load: " + FILENAME_VSH);
|
||||
}
|
||||
}
|
||||
vshSource = shaderSourceCacheVSH;
|
||||
if(shaderSourceCacheFSH == null) {
|
||||
shaderSourceCacheFSH = EagRuntime.getResourceString(FILENAME_FSH);
|
||||
if(shaderSourceCacheFSH == null) {
|
||||
throw new RuntimeException("Could not load: " + FILENAME_FSH);
|
||||
}
|
||||
}
|
||||
fshSource = shaderSourceCacheFSH;
|
||||
}
|
||||
|
||||
StringBuilder macros = new StringBuilder(VERSION + "\n");
|
||||
if((coreBits & STATE_HAS_ATTRIB_TEXTURE) != 0) {
|
||||
macros.append("#define " + MACRO_ATTRIB_TEXTURE + "\n");
|
||||
}
|
||||
if((coreBits & STATE_HAS_ATTRIB_COLOR) != 0) {
|
||||
macros.append("#define " + MACRO_ATTRIB_COLOR + "\n");
|
||||
}
|
||||
if((coreBits & STATE_HAS_ATTRIB_NORMAL) != 0) {
|
||||
macros.append("#define " + MACRO_ATTRIB_NORMAL + "\n");
|
||||
}
|
||||
if((coreBits & STATE_HAS_ATTRIB_LIGHTMAP) != 0) {
|
||||
macros.append("#define " + MACRO_ATTRIB_LIGHTMAP + "\n");
|
||||
}
|
||||
if((coreBits & STATE_ENABLE_TEXTURE2D) != 0) {
|
||||
macros.append("#define " + MACRO_ENABLE_TEXTURE2D + "\n");
|
||||
}
|
||||
if((coreBits & STATE_ENABLE_LIGHTMAP) != 0) {
|
||||
macros.append("#define " + MACRO_ENABLE_LIGHTMAP + "\n");
|
||||
}
|
||||
if((coreBits & STATE_ENABLE_ALPHA_TEST) != 0) {
|
||||
macros.append("#define " + MACRO_ENABLE_ALPHA_TEST + "\n");
|
||||
}
|
||||
if((coreBits & STATE_ENABLE_MC_LIGHTING) != 0) {
|
||||
macros.append("#define " + MACRO_ENABLE_MC_LIGHTING + "\n");
|
||||
}
|
||||
if((coreBits & STATE_ENABLE_END_PORTAL) != 0) {
|
||||
macros.append("#define " + MACRO_ENABLE_END_PORTAL + "\n");
|
||||
}
|
||||
if((coreBits & STATE_ENABLE_ANISOTROPIC_FIX) != 0) {
|
||||
macros.append("#define " + MACRO_ENABLE_ANISOTROPIC_FIX + "\n");
|
||||
}
|
||||
if((coreBits & STATE_ENABLE_FOG) != 0) {
|
||||
macros.append("#define " + MACRO_ENABLE_FOG + "\n");
|
||||
}
|
||||
if((coreBits & STATE_ENABLE_BLEND_ADD) != 0) {
|
||||
macros.append("#define " + MACRO_ENABLE_BLEND_ADD + "\n");
|
||||
}
|
||||
|
||||
macros.append("precision " + PRECISION_INT + " int;\n");
|
||||
macros.append("precision " + PRECISION_FLOAT + " float;\n");
|
||||
macros.append("precision " + PRECISION_SAMPLER + " sampler2D;\n\n");
|
||||
|
||||
IShaderGL vsh = _wglCreateShader(GL_VERTEX_SHADER);
|
||||
|
||||
_wglShaderSource(vsh, macros.toString() + vshSource);
|
||||
_wglCompileShader(vsh);
|
||||
|
||||
if(_wglGetShaderi(vsh, GL_COMPILE_STATUS) != GL_TRUE) {
|
||||
LOGGER.error("Failed to compile GL_VERTEX_SHADER for state {} !", (visualizeBits(coreBits) + (enableExt && extBits != 0 ? " ext " + visualizeBits(extBits) : "")));
|
||||
String log = _wglGetShaderInfoLog(vsh);
|
||||
if(log != null) {
|
||||
String[] lines = log.split("(\\r\\n|\\r|\\n)");
|
||||
for(int i = 0; i < lines.length; ++i) {
|
||||
LOGGER.error("[VERT] {}", lines[i]);
|
||||
}
|
||||
}
|
||||
_wglDeleteShader(vsh);
|
||||
throw new IllegalStateException("Vertex shader could not be compiled!");
|
||||
}
|
||||
|
||||
IShaderGL fsh = _wglCreateShader(GL_FRAGMENT_SHADER);
|
||||
|
||||
_wglShaderSource(fsh, macros.toString() + fshSource);
|
||||
_wglCompileShader(fsh);
|
||||
|
||||
if(_wglGetShaderi(fsh, GL_COMPILE_STATUS) != GL_TRUE) {
|
||||
LOGGER.error("Failed to compile GL_FRAGMENT_SHADER for state {} !", (visualizeBits(coreBits) + (enableExt && extBits != 0 ? " ext " + visualizeBits(extBits) : "")));
|
||||
String log = _wglGetShaderInfoLog(fsh);
|
||||
if(log != null) {
|
||||
String[] lines = log.split("(\\r\\n|\\r|\\n)");
|
||||
for(int i = 0; i < lines.length; ++i) {
|
||||
LOGGER.error("[FRAG] {}", lines[i]);
|
||||
}
|
||||
}
|
||||
_wglDeleteShader(fsh);
|
||||
_wglDeleteShader(vsh);
|
||||
throw new IllegalStateException("Fragment shader could not be compiled!");
|
||||
}
|
||||
|
||||
IProgramGL prog = _wglCreateProgram();
|
||||
|
||||
_wglAttachShader(prog, vsh);
|
||||
_wglAttachShader(prog, fsh);
|
||||
|
||||
FixedFunctionPipeline pp = null;
|
||||
IllegalStateException err = null;
|
||||
try {
|
||||
pp = new FixedFunctionPipeline(coreBits, extBits, prog);
|
||||
}catch(IllegalStateException t) {
|
||||
err = t;
|
||||
}
|
||||
|
||||
_wglDetachShader(prog, vsh);
|
||||
_wglDetachShader(prog, fsh);
|
||||
_wglDeleteShader(fsh);
|
||||
_wglDeleteShader(vsh);
|
||||
|
||||
if(err != null) {
|
||||
_wglDeleteProgram(prog);
|
||||
throw err;
|
||||
}else {
|
||||
if(extProviderUserPointer != null) {
|
||||
pp.extensionPointer = extProviderUserPointer;
|
||||
extensionProvider.initializeNewShader(prog, pp.stateCoreBits, pp.stateExtBits, extProviderUserPointer);
|
||||
}
|
||||
pipelineListTracker.add(pp);
|
||||
return pp;
|
||||
}
|
||||
}
|
||||
|
||||
public static String visualizeBits(int i) {
|
||||
if(i == 0) {
|
||||
return "0";
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int j = 0, k = 0, l = 0;
|
||||
do {
|
||||
k = i & (1 << j);
|
||||
if(k > 0) {
|
||||
if(l++ > 0) {
|
||||
sb.append(' ');
|
||||
}
|
||||
sb.append(k);
|
||||
}
|
||||
++j;
|
||||
}while(i >= (1 << j));
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private final int stateBits;
|
||||
private final int stateCoreBits;
|
||||
private final int stateExtBits;
|
||||
private Object[] extensionPointer;
|
||||
private final boolean stateHasAttribTexture;
|
||||
private final boolean stateHasAttribColor;
|
||||
private final boolean stateHasAttribNormal;
|
||||
@ -401,6 +481,8 @@ class FixedFunctionPipeline {
|
||||
private final IUniformGL stateProjectionMatrixUniformMat4f;
|
||||
private int stateProjectionMatrixSerial = -1;
|
||||
|
||||
private final IUniformGL stateModelProjectionMatrixUniformMat4f;
|
||||
|
||||
// implement only 2 textures
|
||||
private final IUniformGL stateTextureMatrix01UniformMat4f;
|
||||
private final IUniformGL stateTextureMatrix02UniformMat4f;
|
||||
@ -418,34 +500,33 @@ class FixedFunctionPipeline {
|
||||
private float stateAnisotropicFixH = -999.0f;
|
||||
private float stateAnisotropicFixSerial = 0;
|
||||
|
||||
private final IBufferArrayGL vertexArray;
|
||||
private final IBufferGL vertexBuffer;
|
||||
private int vertexBufferSize = -1;
|
||||
|
||||
private boolean bindQuad16 = false;
|
||||
private boolean bindQuad32 = false;
|
||||
|
||||
private final StreamBuffer streamBuffer;
|
||||
private StreamBufferInstance currentVertexArray = null;
|
||||
|
||||
private static FloatBuffer matrixCopyBuffer = null;
|
||||
|
||||
private FixedFunctionPipeline(int bits, IProgramGL compiledProg) {
|
||||
|
||||
private FixedFunctionPipeline(int bits, int extBits, IProgramGL compiledProg) {
|
||||
shaderProgram = compiledProg;
|
||||
|
||||
stateBits = bits;
|
||||
stateHasAttribTexture = (bits & STATE_HAS_ATTRIB_TEXTURE) == STATE_HAS_ATTRIB_TEXTURE;
|
||||
stateHasAttribColor = (bits & STATE_HAS_ATTRIB_COLOR) == STATE_HAS_ATTRIB_COLOR;
|
||||
stateHasAttribNormal = (bits & STATE_HAS_ATTRIB_NORMAL) == STATE_HAS_ATTRIB_NORMAL;
|
||||
stateHasAttribLightmap = (bits & STATE_HAS_ATTRIB_LIGHTMAP) == STATE_HAS_ATTRIB_LIGHTMAP;
|
||||
stateHasAttribTexture = (bits & STATE_HAS_ATTRIB_TEXTURE) != 0;
|
||||
stateHasAttribColor = (bits & STATE_HAS_ATTRIB_COLOR) != 0;
|
||||
stateHasAttribNormal = (bits & STATE_HAS_ATTRIB_NORMAL) != 0;
|
||||
stateHasAttribLightmap = (bits & STATE_HAS_ATTRIB_LIGHTMAP) != 0;
|
||||
|
||||
stateCoreBits = bits;
|
||||
stateExtBits = extBits;
|
||||
|
||||
int index = 0;
|
||||
int stride = 0;
|
||||
|
||||
_wglBindAttribLocation(compiledProg, index, FixedFunctionConstants.ATTRIB_POSITION);
|
||||
_wglBindAttribLocation(compiledProg, index, ATTRIB_POSITION);
|
||||
|
||||
stride += VertexFormat.COMPONENT_POSITION_STRIDE; // vec3f
|
||||
if(stateHasAttribColor) {
|
||||
attribColorIndex = ++index;
|
||||
attribColorOffset = stride;
|
||||
_wglBindAttribLocation(compiledProg, index, FixedFunctionConstants.ATTRIB_COLOR);
|
||||
_wglBindAttribLocation(compiledProg, index, ATTRIB_COLOR);
|
||||
stride += VertexFormat.COMPONENT_COLOR_STRIDE; // vec4b
|
||||
}else {
|
||||
attribColorIndex = -1;
|
||||
@ -454,7 +535,7 @@ class FixedFunctionPipeline {
|
||||
if(stateHasAttribTexture) {
|
||||
attribTextureIndex = ++index;
|
||||
attribTextureOffset = stride;
|
||||
_wglBindAttribLocation(compiledProg, index, FixedFunctionConstants.ATTRIB_TEXTURE);
|
||||
_wglBindAttribLocation(compiledProg, index, ATTRIB_TEXTURE);
|
||||
stride += VertexFormat.COMPONENT_TEX_STRIDE; // vec2f
|
||||
}else {
|
||||
attribTextureIndex = -1;
|
||||
@ -463,7 +544,7 @@ class FixedFunctionPipeline {
|
||||
if(stateHasAttribNormal) {
|
||||
attribNormalIndex = ++index;
|
||||
attribNormalOffset = stride;
|
||||
_wglBindAttribLocation(compiledProg, index, FixedFunctionConstants.ATTRIB_NORMAL);
|
||||
_wglBindAttribLocation(compiledProg, index, ATTRIB_NORMAL);
|
||||
stride += VertexFormat.COMPONENT_NORMAL_STRIDE; // vec4b
|
||||
}else {
|
||||
attribNormalIndex = -1;
|
||||
@ -472,7 +553,7 @@ class FixedFunctionPipeline {
|
||||
if(stateHasAttribLightmap) {
|
||||
attribLightmapIndex = ++index;
|
||||
attribLightmapOffset = stride;
|
||||
_wglBindAttribLocation(compiledProg, index, FixedFunctionConstants.ATTRIB_LIGHTMAP);
|
||||
_wglBindAttribLocation(compiledProg, index, ATTRIB_LIGHTMAP);
|
||||
stride += VertexFormat.COMPONENT_LIGHTMAP_STRIDE; // vec2s
|
||||
}else {
|
||||
attribLightmapIndex = -1;
|
||||
@ -484,7 +565,7 @@ class FixedFunctionPipeline {
|
||||
_wglLinkProgram(compiledProg);
|
||||
|
||||
if(_wglGetProgrami(compiledProg, GL_LINK_STATUS) != GL_TRUE) {
|
||||
LOGGER.error("Program could not be linked for state {} !", getStateBits(bits, 11));
|
||||
LOGGER.error("Program could not be linked for state {} !", (visualizeBits(bits) + (extensionProvider != null && extBits != 0 ? " ext " + visualizeBits(extBits) : "")));
|
||||
String log = _wglGetProgramInfoLog(compiledProg);
|
||||
if(log != null) {
|
||||
String[] lines = log.split("(\\r\\n|\\r|\\n)");
|
||||
@ -495,40 +576,40 @@ class FixedFunctionPipeline {
|
||||
throw new IllegalStateException("Program could not be linked!");
|
||||
}
|
||||
|
||||
vertexArray = PlatformOpenGL._wglGenVertexArrays();
|
||||
vertexBuffer = PlatformOpenGL._wglGenBuffers();
|
||||
streamBuffer = new StreamBuffer(FixedFunctionShader.initialSize, FixedFunctionShader.initialCount,
|
||||
FixedFunctionShader.maxCount, (vertexArray, vertexBuffer) -> {
|
||||
EaglercraftGPU.bindGLBufferArray(vertexArray);
|
||||
EaglercraftGPU.bindGLArrayBuffer(vertexBuffer);
|
||||
|
||||
EaglercraftGPU.bindGLBufferArray(vertexArray);
|
||||
EaglercraftGPU.bindGLArrayBuffer(vertexBuffer);
|
||||
|
||||
_wglEnableVertexAttribArray(0);
|
||||
_wglVertexAttribPointer(0, VertexFormat.COMPONENT_POSITION_SIZE,
|
||||
VertexFormat.COMPONENT_POSITION_FORMAT, false, attribStride, 0);
|
||||
_wglEnableVertexAttribArray(0);
|
||||
_wglVertexAttribPointer(0, VertexFormat.COMPONENT_POSITION_SIZE,
|
||||
VertexFormat.COMPONENT_POSITION_FORMAT, false, attribStride, 0);
|
||||
|
||||
if(attribTextureIndex != -1) {
|
||||
_wglEnableVertexAttribArray(attribTextureIndex);
|
||||
_wglVertexAttribPointer(attribTextureIndex, VertexFormat.COMPONENT_TEX_SIZE,
|
||||
VertexFormat.COMPONENT_TEX_FORMAT, false, attribStride, attribTextureOffset);
|
||||
}
|
||||
|
||||
if(attribColorIndex != -1) {
|
||||
_wglEnableVertexAttribArray(attribColorIndex);
|
||||
_wglVertexAttribPointer(attribColorIndex, VertexFormat.COMPONENT_COLOR_SIZE,
|
||||
VertexFormat.COMPONENT_COLOR_FORMAT, true, attribStride, attribColorOffset);
|
||||
}
|
||||
|
||||
if(attribNormalIndex != -1) {
|
||||
_wglEnableVertexAttribArray(attribNormalIndex);
|
||||
_wglVertexAttribPointer(attribNormalIndex, VertexFormat.COMPONENT_NORMAL_SIZE,
|
||||
VertexFormat.COMPONENT_NORMAL_FORMAT, true, attribStride, attribNormalOffset);
|
||||
}
|
||||
|
||||
if(attribLightmapIndex != -1) {
|
||||
_wglEnableVertexAttribArray(attribLightmapIndex);
|
||||
_wglVertexAttribPointer(attribLightmapIndex, VertexFormat.COMPONENT_LIGHTMAP_SIZE,
|
||||
VertexFormat.COMPONENT_LIGHTMAP_FORMAT, false, attribStride, attribLightmapOffset);
|
||||
}
|
||||
});
|
||||
|
||||
if(attribTextureIndex != -1) {
|
||||
_wglEnableVertexAttribArray(attribTextureIndex);
|
||||
_wglVertexAttribPointer(attribTextureIndex, VertexFormat.COMPONENT_TEX_SIZE,
|
||||
VertexFormat.COMPONENT_TEX_FORMAT, false, attribStride, attribTextureOffset);
|
||||
}
|
||||
|
||||
if(attribColorIndex != -1) {
|
||||
_wglEnableVertexAttribArray(attribColorIndex);
|
||||
_wglVertexAttribPointer(attribColorIndex, VertexFormat.COMPONENT_COLOR_SIZE,
|
||||
VertexFormat.COMPONENT_COLOR_FORMAT, true, attribStride, attribColorOffset);
|
||||
}
|
||||
|
||||
if(attribNormalIndex != -1) {
|
||||
_wglEnableVertexAttribArray(attribNormalIndex);
|
||||
_wglVertexAttribPointer(attribNormalIndex, VertexFormat.COMPONENT_NORMAL_SIZE,
|
||||
VertexFormat.COMPONENT_NORMAL_FORMAT, true, attribStride, attribNormalOffset);
|
||||
}
|
||||
|
||||
if(attribLightmapIndex != -1) {
|
||||
_wglEnableVertexAttribArray(attribLightmapIndex);
|
||||
_wglVertexAttribPointer(attribLightmapIndex, VertexFormat.COMPONENT_LIGHTMAP_SIZE,
|
||||
VertexFormat.COMPONENT_LIGHTMAP_FORMAT, false, attribStride, attribLightmapOffset);
|
||||
}
|
||||
|
||||
stateEnableTexture2D = (bits & STATE_ENABLE_TEXTURE2D) == STATE_ENABLE_TEXTURE2D;
|
||||
stateEnableLightmap = (bits & STATE_ENABLE_LIGHTMAP) == STATE_ENABLE_LIGHTMAP;
|
||||
stateEnableAlphaTest = (bits & STATE_ENABLE_ALPHA_TEST) == STATE_ENABLE_ALPHA_TEST;
|
||||
@ -547,85 +628,87 @@ class FixedFunctionPipeline {
|
||||
}
|
||||
|
||||
stateColorUniform4f = _wglGetUniformLocation(compiledProg,
|
||||
FixedFunctionConstants.UNIFORM_COLOR_NAME);
|
||||
UNIFORM_COLOR_NAME);
|
||||
|
||||
stateAlphaTestUniform1f = stateEnableAlphaTest ? _wglGetUniformLocation(compiledProg,
|
||||
FixedFunctionConstants.UNIFORM_ALPHA_TEST_NAME) : null;
|
||||
UNIFORM_ALPHA_TEST_NAME) : null;
|
||||
|
||||
stateLightsEnabledUniform1i = stateEnableMCLighting ? _wglGetUniformLocation(compiledProg,
|
||||
FixedFunctionConstants.UNIFORM_LIGHTS_ENABLED_NAME) : null;
|
||||
UNIFORM_LIGHTS_ENABLED_NAME) : null;
|
||||
|
||||
if(stateEnableMCLighting) {
|
||||
for(int i = 0; i < stateLightsVectorsArrayUniform4f.length; ++i) {
|
||||
stateLightsVectorsArrayUniform4f[i] =_wglGetUniformLocation(compiledProg,
|
||||
FixedFunctionConstants.UNIFORM_LIGHTS_VECTORS_NAME + "[" + i + "]");
|
||||
UNIFORM_LIGHTS_VECTORS_NAME + "[" + i + "]");
|
||||
}
|
||||
}
|
||||
|
||||
stateLightingAmbientUniform3f = stateEnableMCLighting ? _wglGetUniformLocation(compiledProg,
|
||||
FixedFunctionConstants.UNIFORM_LIGHTS_AMBIENT_NAME) : null;
|
||||
UNIFORM_LIGHTS_AMBIENT_NAME) : null;
|
||||
|
||||
stateNormalUniform3f = (!stateHasAttribNormal && stateEnableMCLighting) ? _wglGetUniformLocation(compiledProg,
|
||||
FixedFunctionConstants.UNIFORM_CONSTANT_NORMAL_NAME) : null;
|
||||
UNIFORM_CONSTANT_NORMAL_NAME) : null;
|
||||
|
||||
stateFogParamUniform4f = stateEnableFog ? _wglGetUniformLocation(compiledProg,
|
||||
FixedFunctionConstants.UNIFORM_FOG_PARAM_NAME) : null;
|
||||
UNIFORM_FOG_PARAM_NAME) : null;
|
||||
|
||||
stateFogColorUniform4f = stateEnableFog ? _wglGetUniformLocation(compiledProg,
|
||||
FixedFunctionConstants.UNIFORM_FOG_COLOR_NAME) : null;
|
||||
UNIFORM_FOG_COLOR_NAME) : null;
|
||||
|
||||
stateTexGenPlaneUniform4i = stateEnableEndPortal ? _wglGetUniformLocation(compiledProg,
|
||||
FixedFunctionConstants.UNIFORM_TEX_GEN_PLANE_NAME) : null;
|
||||
UNIFORM_TEX_GEN_PLANE_NAME) : null;
|
||||
|
||||
stateTexGenSVectorUniform4f = stateEnableEndPortal ? _wglGetUniformLocation(compiledProg,
|
||||
FixedFunctionConstants.UNIFORM_TEX_GEN_S_NAME) : null;
|
||||
UNIFORM_TEX_GEN_S_NAME) : null;
|
||||
|
||||
stateTexGenTVectorUniform4f = stateEnableEndPortal ? _wglGetUniformLocation(compiledProg,
|
||||
FixedFunctionConstants.UNIFORM_TEX_GEN_T_NAME) : null;
|
||||
UNIFORM_TEX_GEN_T_NAME) : null;
|
||||
|
||||
stateTexGenRVectorUniform4f = stateEnableEndPortal ? _wglGetUniformLocation(compiledProg,
|
||||
FixedFunctionConstants.UNIFORM_TEX_GEN_R_NAME) : null;
|
||||
UNIFORM_TEX_GEN_R_NAME) : null;
|
||||
|
||||
stateTexGenQVectorUniform4f = stateEnableEndPortal ? _wglGetUniformLocation(compiledProg,
|
||||
FixedFunctionConstants.UNIFORM_TEX_GEN_Q_NAME) : null;
|
||||
UNIFORM_TEX_GEN_Q_NAME) : null;
|
||||
|
||||
stateModelMatrixUniformMat4f = _wglGetUniformLocation(compiledProg,
|
||||
FixedFunctionConstants.UNIFORM_MODEL_MATRIX_NAME);
|
||||
UNIFORM_MODEL_MATRIX_NAME);
|
||||
|
||||
stateProjectionMatrixUniformMat4f = _wglGetUniformLocation(compiledProg,
|
||||
FixedFunctionConstants.UNIFORM_PROJECTION_MATRIX_NAME);
|
||||
UNIFORM_PROJECTION_MATRIX_NAME);
|
||||
|
||||
stateModelProjectionMatrixUniformMat4f = _wglGetUniformLocation(compiledProg,
|
||||
UNIFORM_MODEL_PROJECTION_MATRIX_NAME);
|
||||
|
||||
stateTextureMatrix01UniformMat4f = (stateEnableEndPortal || stateHasAttribTexture) ? _wglGetUniformLocation(compiledProg,
|
||||
FixedFunctionConstants.UNIFORM_TEXTURE_MATRIX_01_NAME) : null;
|
||||
UNIFORM_TEXTURE_MATRIX_01_NAME) : null;
|
||||
|
||||
stateTextureMatrix02UniformMat4f = stateHasAttribLightmap ? _wglGetUniformLocation(compiledProg,
|
||||
FixedFunctionConstants.UNIFORM_TEXTURE_MATRIX_02_NAME) : null;
|
||||
UNIFORM_TEXTURE_MATRIX_02_NAME) : null;
|
||||
|
||||
stateTextureCoords01Uniform2f = (!stateHasAttribTexture && stateEnableTexture2D) ? _wglGetUniformLocation(
|
||||
compiledProg, FixedFunctionConstants.UNIFORM_TEXTURE_COORDS_01_NAME) : null;
|
||||
compiledProg, UNIFORM_TEXTURE_COORDS_01_NAME) : null;
|
||||
|
||||
stateTextureCoords02Uniform2f = (!stateHasAttribLightmap && stateEnableLightmap) ? _wglGetUniformLocation(
|
||||
compiledProg, FixedFunctionConstants.UNIFORM_TEXTURE_COORDS_02_NAME) : null;
|
||||
compiledProg, UNIFORM_TEXTURE_COORDS_02_NAME) : null;
|
||||
|
||||
stateAnisotropicFix2f = stateEnableAnisotropicFix ? _wglGetUniformLocation(compiledProg,
|
||||
FixedFunctionConstants.UNIFORM_TEXTURE_ANISOTROPIC_FIX) : null;
|
||||
UNIFORM_TEXTURE_ANISOTROPIC_FIX) : null;
|
||||
|
||||
stateShaderBlendSrcColorUniform4f = stateEnableBlendAdd ? _wglGetUniformLocation(compiledProg,
|
||||
FixedFunctionConstants.UNIFORM_BLEND_SRC_COLOR_NAME) : null;
|
||||
UNIFORM_BLEND_SRC_COLOR_NAME) : null;
|
||||
|
||||
stateShaderBlendAddColorUniform4f = stateEnableBlendAdd ? _wglGetUniformLocation(compiledProg,
|
||||
FixedFunctionConstants.UNIFORM_BLEND_ADD_COLOR_NAME) : null;
|
||||
UNIFORM_BLEND_ADD_COLOR_NAME) : null;
|
||||
|
||||
if(stateEnableTexture2D) {
|
||||
EaglercraftGPU.bindGLShaderProgram(compiledProg);
|
||||
_wglUniform1i(_wglGetUniformLocation(compiledProg, FixedFunctionConstants.UNIFORM_TEXTURE_UNIT_01_NAME), 0);
|
||||
_wglUniform1i(_wglGetUniformLocation(compiledProg, UNIFORM_TEXTURE_UNIT_01_NAME), 0);
|
||||
}
|
||||
|
||||
if(stateEnableLightmap) {
|
||||
EaglercraftGPU.bindGLShaderProgram(compiledProg);
|
||||
_wglUniform1i(_wglGetUniformLocation(compiledProg, FixedFunctionConstants.UNIFORM_TEXTURE_UNIT_02_NAME), 1);
|
||||
_wglUniform1i(_wglGetUniformLocation(compiledProg, UNIFORM_TEXTURE_UNIT_02_NAME), 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public FixedFunctionPipeline update() {
|
||||
@ -653,24 +736,48 @@ class FixedFunctionPipeline {
|
||||
matrixCopyBuffer = PlatformRuntime.allocateFloatBuffer(16);
|
||||
}
|
||||
|
||||
int ptr = GlStateManager.modelMatrixStackPointer;
|
||||
serial = GlStateManager.modelMatrixStackAccessSerial[ptr];
|
||||
if(stateModelMatrixSerial != serial) {
|
||||
stateModelMatrixSerial = serial;
|
||||
matrixCopyBuffer.clear();
|
||||
GlStateManager.modelMatrixStack[ptr].store(matrixCopyBuffer);
|
||||
matrixCopyBuffer.flip();
|
||||
_wglUniformMatrix4fv(stateModelMatrixUniformMat4f, false, matrixCopyBuffer);
|
||||
}
|
||||
|
||||
ptr = GlStateManager.projectionMatrixStackPointer;
|
||||
serial = GlStateManager.projectionMatrixStackAccessSerial[ptr];
|
||||
if(stateProjectionMatrixSerial != serial) {
|
||||
stateProjectionMatrixSerial = serial;
|
||||
matrixCopyBuffer.clear();
|
||||
GlStateManager.projectionMatrixStack[ptr].store(matrixCopyBuffer);
|
||||
matrixCopyBuffer.flip();
|
||||
_wglUniformMatrix4fv(stateProjectionMatrixUniformMat4f, false, matrixCopyBuffer);
|
||||
int ptr;
|
||||
if(stateModelProjectionMatrixUniformMat4f == null) {
|
||||
ptr = GlStateManager.modelMatrixStackPointer;
|
||||
serial = GlStateManager.modelMatrixStackAccessSerial[ptr];
|
||||
if(stateModelMatrixSerial != serial) {
|
||||
stateModelMatrixSerial = serial;
|
||||
matrixCopyBuffer.clear();
|
||||
GlStateManager.modelMatrixStack[ptr].store(matrixCopyBuffer);
|
||||
matrixCopyBuffer.flip();
|
||||
_wglUniformMatrix4fv(stateModelMatrixUniformMat4f, false, matrixCopyBuffer);
|
||||
}
|
||||
|
||||
ptr = GlStateManager.projectionMatrixStackPointer;
|
||||
serial = GlStateManager.projectionMatrixStackAccessSerial[ptr];
|
||||
if(stateProjectionMatrixSerial != serial) {
|
||||
stateProjectionMatrixSerial = serial;
|
||||
matrixCopyBuffer.clear();
|
||||
GlStateManager.projectionMatrixStack[ptr].store(matrixCopyBuffer);
|
||||
matrixCopyBuffer.flip();
|
||||
_wglUniformMatrix4fv(stateProjectionMatrixUniformMat4f, false, matrixCopyBuffer);
|
||||
}
|
||||
}else {
|
||||
ptr = GlStateManager.modelMatrixStackPointer;
|
||||
serial = GlStateManager.modelMatrixStackAccessSerial[ptr];
|
||||
int ptr2 = GlStateManager.projectionMatrixStackPointer;
|
||||
int serial2 = GlStateManager.projectionMatrixStackAccessSerial[ptr2];
|
||||
boolean b = stateModelMatrixSerial != serial;
|
||||
if(b || stateProjectionMatrixSerial != serial2) {
|
||||
stateModelMatrixSerial = serial;
|
||||
stateProjectionMatrixSerial = serial2;
|
||||
if(b && stateModelMatrixUniformMat4f != null) {
|
||||
matrixCopyBuffer.clear();
|
||||
GlStateManager.modelMatrixStack[ptr].store(matrixCopyBuffer);
|
||||
matrixCopyBuffer.flip();
|
||||
_wglUniformMatrix4fv(stateModelMatrixUniformMat4f, false, matrixCopyBuffer);
|
||||
}
|
||||
Matrix4f.mul(GlStateManager.projectionMatrixStack[ptr2], GlStateManager.modelMatrixStack[ptr], tmpMatrixForInv);
|
||||
matrixCopyBuffer.clear();
|
||||
tmpMatrixForInv.store(matrixCopyBuffer);
|
||||
matrixCopyBuffer.flip();
|
||||
_wglUniformMatrix4fv(stateModelProjectionMatrixUniformMat4f, false, matrixCopyBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
if(stateEnableAlphaTest) {
|
||||
@ -949,27 +1056,55 @@ class FixedFunctionPipeline {
|
||||
}
|
||||
}
|
||||
|
||||
if(extensionProvider != null && extensionPointer != null) {
|
||||
extensionProvider.updatePipeline(shaderProgram, stateCoreBits, stateExtBits, extensionPointer);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
static void optimize() {
|
||||
FixedFunctionPipeline pp;
|
||||
for(int i = 0, l = pipelineListTracker.size(); i < l; ++i) {
|
||||
pipelineListTracker.get(i).streamBuffer.optimize();
|
||||
}
|
||||
}
|
||||
|
||||
public static void flushCache() {
|
||||
shaderSourceCacheVSH = null;
|
||||
shaderSourceCacheFSH = null;
|
||||
FixedFunctionPipeline pp;
|
||||
for(int i = 0; i < pipelineStateCache.length; ++i) {
|
||||
if(pipelineStateCache[i] != null) {
|
||||
pipelineStateCache[i].destroy();
|
||||
pp = pipelineStateCache[i];
|
||||
if(pp != null) {
|
||||
pp.destroy();
|
||||
pipelineStateCache[i] = null;
|
||||
}
|
||||
}
|
||||
for(int i = 0; i < pipelineExtStateCache.length; ++i) {
|
||||
FixedFunctionPipeline[] ppp = pipelineExtStateCache[i];
|
||||
if(ppp != null) {
|
||||
for(int j = 0; j < ppp.length; ++j) {
|
||||
FixedFunctionPipeline pppp = ppp[j];
|
||||
if(pppp != null) {
|
||||
pppp.destroy();
|
||||
if(extensionProvider != null && pppp.extensionPointer != null) {
|
||||
extensionProvider.destroyPipeline(pppp.shaderProgram, pppp.stateCoreBits, pppp.stateExtBits, pppp.extensionPointer);
|
||||
}
|
||||
}
|
||||
}
|
||||
pipelineExtStateCache[i] = null;
|
||||
}
|
||||
}
|
||||
pipelineListTracker.clear();
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
PlatformOpenGL._wglDeleteProgram(shaderProgram);
|
||||
PlatformOpenGL._wglDeleteVertexArrays(vertexArray);
|
||||
PlatformOpenGL._wglDeleteBuffers(vertexBuffer);
|
||||
streamBuffer.destroy();
|
||||
}
|
||||
|
||||
public IBufferArrayGL getDirectModeBufferArray() {
|
||||
return vertexArray;
|
||||
return currentVertexArray.vertexArray;
|
||||
}
|
||||
}
|
||||
|
@ -13,66 +13,92 @@ package net.lax1dude.eaglercraft.v1_8.opengl;
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
class FixedFunctionShader {
|
||||
public class FixedFunctionShader {
|
||||
|
||||
class FixedFunctionConstants {
|
||||
public static final int initialSize = 0x8000;
|
||||
public static final int initialCount = 3;
|
||||
public static final int maxCount = 8;
|
||||
|
||||
static final String VERSION = "#version 300 es";
|
||||
static final String FILENAME_VSH = "/assets/eagler/glsl/core.vsh";
|
||||
static final String FILENAME_FSH = "/assets/eagler/glsl/core.fsh";
|
||||
public class FixedFunctionState {
|
||||
|
||||
static final String PRECISION_INT = "lowp";
|
||||
static final String PRECISION_FLOAT = "mediump";
|
||||
static final String PRECISION_SAMPLER = "lowp";
|
||||
|
||||
static final String MACRO_ATTRIB_TEXTURE = "COMPILE_TEXTURE_ATTRIB";
|
||||
static final String MACRO_ATTRIB_COLOR = "COMPILE_COLOR_ATTRIB";
|
||||
static final String MACRO_ATTRIB_NORMAL = "COMPILE_NORMAL_ATTRIB";
|
||||
static final String MACRO_ATTRIB_LIGHTMAP = "COMPILE_LIGHTMAP_ATTRIB";
|
||||
|
||||
static final String MACRO_ENABLE_TEXTURE2D = "COMPILE_ENABLE_TEXTURE2D";
|
||||
static final String MACRO_ENABLE_LIGHTMAP = "COMPILE_ENABLE_LIGHTMAP";
|
||||
static final String MACRO_ENABLE_ALPHA_TEST = "COMPILE_ENABLE_ALPHA_TEST";
|
||||
static final String MACRO_ENABLE_MC_LIGHTING = "COMPILE_ENABLE_MC_LIGHTING";
|
||||
static final String MACRO_ENABLE_END_PORTAL = "COMPILE_ENABLE_TEX_GEN";
|
||||
static final String MACRO_ENABLE_ANISOTROPIC_FIX = "COMPILE_ENABLE_ANISOTROPIC_FIX";
|
||||
static final String MACRO_ENABLE_FOG = "COMPILE_ENABLE_FOG";
|
||||
static final String MACRO_ENABLE_BLEND_ADD = "COMPILE_BLEND_ADD";
|
||||
public static final int fixedFunctionStatesCount = 12;
|
||||
public static final int fixedFunctionStatesBits = (1 << 12) - 1;
|
||||
public static final int extentionStateBits = fixedFunctionStatesBits ^ 0xFFFFFFFF;
|
||||
|
||||
static final String ATTRIB_POSITION = "a_position3f";
|
||||
static final String ATTRIB_TEXTURE = "a_texture2f";
|
||||
static final String ATTRIB_COLOR = "a_color4f";
|
||||
static final String ATTRIB_NORMAL = "a_normal4f";
|
||||
static final String ATTRIB_LIGHTMAP = "a_lightmap2f";
|
||||
public static final int STATE_HAS_ATTRIB_TEXTURE = 1;
|
||||
public static final int STATE_HAS_ATTRIB_COLOR = 2;
|
||||
public static final int STATE_HAS_ATTRIB_NORMAL = 4;
|
||||
public static final int STATE_HAS_ATTRIB_LIGHTMAP = 8;
|
||||
public static final int STATE_ENABLE_TEXTURE2D = 16;
|
||||
public static final int STATE_ENABLE_LIGHTMAP = 32;
|
||||
public static final int STATE_ENABLE_ALPHA_TEST = 64;
|
||||
public static final int STATE_ENABLE_MC_LIGHTING = 128;
|
||||
public static final int STATE_ENABLE_END_PORTAL = 256;
|
||||
public static final int STATE_ENABLE_ANISOTROPIC_FIX = 512;
|
||||
public static final int STATE_ENABLE_FOG = 1024;
|
||||
public static final int STATE_ENABLE_BLEND_ADD = 2048;
|
||||
|
||||
static final String UNIFORM_COLOR_NAME = "u_color4f";
|
||||
static final String UNIFORM_BLEND_SRC_COLOR_NAME = "u_colorBlendSrc4f";
|
||||
static final String UNIFORM_BLEND_ADD_COLOR_NAME = "u_colorBlendAdd4f";
|
||||
static final String UNIFORM_ALPHA_TEST_NAME = "u_alphaTestRef1f";
|
||||
static final String UNIFORM_LIGHTS_ENABLED_NAME = "u_lightsEnabled1i";
|
||||
static final String UNIFORM_LIGHTS_VECTORS_NAME = "u_lightsDirections4fv";
|
||||
static final String UNIFORM_LIGHTS_AMBIENT_NAME = "u_lightsAmbient3f";
|
||||
static final String UNIFORM_CONSTANT_NORMAL_NAME = "u_uniformNormal3f";
|
||||
static final String UNIFORM_FOG_PARAM_NAME = "u_fogParameters4f";
|
||||
static final String UNIFORM_FOG_COLOR_NAME = "u_fogColor4f";
|
||||
static final String UNIFORM_TEX_GEN_S_NAME = "u_texGenS4f";
|
||||
static final String UNIFORM_TEX_GEN_T_NAME = "u_texGenT4f";
|
||||
static final String UNIFORM_TEX_GEN_R_NAME = "u_texGenR4f";
|
||||
static final String UNIFORM_TEX_GEN_Q_NAME = "u_texGenQ4f";
|
||||
static final String UNIFORM_MODEL_MATRIX_NAME = "u_modelviewMat4f";
|
||||
static final String UNIFORM_TEX_GEN_PLANE_NAME = "u_texGenPlane4i";
|
||||
static final String UNIFORM_PROJECTION_MATRIX_NAME = "u_projectionMat4f";
|
||||
static final String UNIFORM_TEXTURE_COORDS_01_NAME = "u_textureCoords01";
|
||||
static final String UNIFORM_TEXTURE_MATRIX_01_NAME = "u_textureMat4f01";
|
||||
static final String UNIFORM_TEXTURE_COORDS_02_NAME = "u_textureCoords02";
|
||||
static final String UNIFORM_TEXTURE_MATRIX_02_NAME = "u_textureMat4f02";
|
||||
static final String UNIFORM_TEXTURE_ANISOTROPIC_FIX = "u_textureAnisotropicFix";
|
||||
|
||||
static final String UNIFORM_TEXTURE_UNIT_01_NAME = "u_samplerTexture";
|
||||
static final String UNIFORM_TEXTURE_UNIT_02_NAME = "u_samplerLightmap";
|
||||
|
||||
static final String OUTPUT_COLOR = "output4f";
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class FixedFunctionConstants {
|
||||
|
||||
public static final String VERSION = "#version 300 es";
|
||||
public static final String FILENAME_VSH = "/assets/eagler/glsl/core.vsh";
|
||||
public static final String FILENAME_FSH = "/assets/eagler/glsl/core.fsh";
|
||||
|
||||
public static final String PRECISION_INT = "lowp";
|
||||
public static final String PRECISION_FLOAT = "highp";
|
||||
public static final String PRECISION_SAMPLER = "mediump";
|
||||
|
||||
public static final String MACRO_ATTRIB_TEXTURE = "COMPILE_TEXTURE_ATTRIB";
|
||||
public static final String MACRO_ATTRIB_COLOR = "COMPILE_COLOR_ATTRIB";
|
||||
public static final String MACRO_ATTRIB_NORMAL = "COMPILE_NORMAL_ATTRIB";
|
||||
public static final String MACRO_ATTRIB_LIGHTMAP = "COMPILE_LIGHTMAP_ATTRIB";
|
||||
|
||||
public static final String MACRO_ENABLE_TEXTURE2D = "COMPILE_ENABLE_TEXTURE2D";
|
||||
public static final String MACRO_ENABLE_LIGHTMAP = "COMPILE_ENABLE_LIGHTMAP";
|
||||
public static final String MACRO_ENABLE_ALPHA_TEST = "COMPILE_ENABLE_ALPHA_TEST";
|
||||
public static final String MACRO_ENABLE_MC_LIGHTING = "COMPILE_ENABLE_MC_LIGHTING";
|
||||
public static final String MACRO_ENABLE_END_PORTAL = "COMPILE_ENABLE_TEX_GEN";
|
||||
public static final String MACRO_ENABLE_ANISOTROPIC_FIX = "COMPILE_ENABLE_ANISOTROPIC_FIX";
|
||||
public static final String MACRO_ENABLE_FOG = "COMPILE_ENABLE_FOG";
|
||||
public static final String MACRO_ENABLE_BLEND_ADD = "COMPILE_BLEND_ADD";
|
||||
|
||||
public static final String ATTRIB_POSITION = "a_position3f";
|
||||
public static final String ATTRIB_TEXTURE = "a_texture2f";
|
||||
public static final String ATTRIB_COLOR = "a_color4f";
|
||||
public static final String ATTRIB_NORMAL = "a_normal4f";
|
||||
public static final String ATTRIB_LIGHTMAP = "a_lightmap2f";
|
||||
|
||||
public static final String UNIFORM_COLOR_NAME = "u_color4f";
|
||||
public static final String UNIFORM_BLEND_SRC_COLOR_NAME = "u_colorBlendSrc4f";
|
||||
public static final String UNIFORM_BLEND_ADD_COLOR_NAME = "u_colorBlendAdd4f";
|
||||
public static final String UNIFORM_ALPHA_TEST_NAME = "u_alphaTestRef1f";
|
||||
public static final String UNIFORM_LIGHTS_ENABLED_NAME = "u_lightsEnabled1i";
|
||||
public static final String UNIFORM_LIGHTS_VECTORS_NAME = "u_lightsDirections4fv";
|
||||
public static final String UNIFORM_LIGHTS_AMBIENT_NAME = "u_lightsAmbient3f";
|
||||
public static final String UNIFORM_CONSTANT_NORMAL_NAME = "u_uniformNormal3f";
|
||||
public static final String UNIFORM_FOG_PARAM_NAME = "u_fogParameters4f";
|
||||
public static final String UNIFORM_FOG_COLOR_NAME = "u_fogColor4f";
|
||||
public static final String UNIFORM_TEX_GEN_S_NAME = "u_texGenS4f";
|
||||
public static final String UNIFORM_TEX_GEN_T_NAME = "u_texGenT4f";
|
||||
public static final String UNIFORM_TEX_GEN_R_NAME = "u_texGenR4f";
|
||||
public static final String UNIFORM_TEX_GEN_Q_NAME = "u_texGenQ4f";
|
||||
public static final String UNIFORM_MODEL_MATRIX_NAME = "u_modelviewMat4f";
|
||||
public static final String UNIFORM_TEX_GEN_PLANE_NAME = "u_texGenPlane4i";
|
||||
public static final String UNIFORM_PROJECTION_MATRIX_NAME = "u_projectionMat4f";
|
||||
public static final String UNIFORM_MODEL_PROJECTION_MATRIX_NAME = "u_modelviewProjMat4f";
|
||||
public static final String UNIFORM_TEXTURE_COORDS_01_NAME = "u_textureCoords01";
|
||||
public static final String UNIFORM_TEXTURE_MATRIX_01_NAME = "u_textureMat4f01";
|
||||
public static final String UNIFORM_TEXTURE_COORDS_02_NAME = "u_textureCoords02";
|
||||
public static final String UNIFORM_TEXTURE_MATRIX_02_NAME = "u_textureMat4f02";
|
||||
public static final String UNIFORM_TEXTURE_ANISOTROPIC_FIX = "u_textureAnisotropicFix";
|
||||
|
||||
public static final String UNIFORM_TEXTURE_UNIT_01_NAME = "u_samplerTexture";
|
||||
public static final String UNIFORM_TEXTURE_UNIT_02_NAME = "u_samplerLightmap";
|
||||
|
||||
public static final String OUTPUT_COLOR = "output4f";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -54,13 +54,14 @@ public class GlStateManager {
|
||||
static float stateShaderBlendAddColorA = 0.0f;
|
||||
static int stateShaderBlendColorSerial = 0;
|
||||
static boolean stateEnableShaderBlendColor = false;
|
||||
|
||||
|
||||
static boolean stateBlend = false;
|
||||
static boolean stateGlobalBlend = true;
|
||||
static int stateBlendEquation = -1;
|
||||
static int stateBlendSRC = -1;
|
||||
static int stateBlendDST = -1;
|
||||
static boolean stateEnableOverlayFramebufferBlending = false;
|
||||
|
||||
|
||||
static boolean stateAlphaTest = false;
|
||||
static float stateAlphaTestRef = 0.1f;
|
||||
|
||||
@ -127,7 +128,12 @@ public class GlStateManager {
|
||||
Vector4f vector = new Vector4f();
|
||||
|
||||
}
|
||||
|
||||
|
||||
static float blendConstantR = -999.0f;
|
||||
static float blendConstantG = -999.0f;
|
||||
static float blendConstantB = -999.0f;
|
||||
static float blendConstantA = -999.0f;
|
||||
|
||||
static int stateTexGenSerial = 0;
|
||||
|
||||
static int stateMatrixMode = GL_MODELVIEW;
|
||||
@ -151,6 +157,8 @@ public class GlStateManager {
|
||||
static int[] textureMatrixAccessSerial = new int[8];
|
||||
static int[] textureMatrixStackPointer = new int[8];
|
||||
|
||||
static boolean stateUseExtensionPipeline = false;
|
||||
|
||||
private static final Matrix4f tmpInvertedMatrix = new Matrix4f();
|
||||
|
||||
static {
|
||||
@ -237,7 +245,19 @@ public class GlStateManager {
|
||||
public static final void disableLighting() {
|
||||
stateLighting = false;
|
||||
}
|
||||
|
||||
|
||||
public static final void enableExtensionPipeline() {
|
||||
stateUseExtensionPipeline = true;
|
||||
}
|
||||
|
||||
public static final void disableExtensionPipeline() {
|
||||
stateUseExtensionPipeline = false;
|
||||
}
|
||||
|
||||
public static final boolean isExtensionPipeline() {
|
||||
return stateUseExtensionPipeline;
|
||||
}
|
||||
|
||||
private static final Vector4f paramVector4 = new Vector4f();
|
||||
public static final void enableMCLight(int light, float diffuse, double dirX,
|
||||
double dirY, double dirZ, double dirW) {
|
||||
@ -324,18 +344,32 @@ public class GlStateManager {
|
||||
|
||||
public static final void disableBlend() {
|
||||
if(stateBlend) {
|
||||
_wglDisable(GL_BLEND);
|
||||
if(stateGlobalBlend) _wglDisable(GL_BLEND);
|
||||
stateBlend = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static final void enableBlend() {
|
||||
if(!stateBlend) {
|
||||
_wglEnable(GL_BLEND);
|
||||
if(stateGlobalBlend) _wglEnable(GL_BLEND);
|
||||
stateBlend = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static final void globalDisableBlend() {
|
||||
if(stateBlend) {
|
||||
_wglDisable(GL_BLEND);
|
||||
}
|
||||
stateGlobalBlend = false;
|
||||
}
|
||||
|
||||
public static final void globalEnableBlend() {
|
||||
if(stateBlend) {
|
||||
_wglEnable(GL_BLEND);
|
||||
}
|
||||
stateGlobalBlend = true;
|
||||
}
|
||||
|
||||
public static final void blendFunc(int srcFactor, int dstFactor) {
|
||||
if(stateEnableOverlayFramebufferBlending) {
|
||||
tryBlendFuncSeparate(srcFactor, dstFactor, 0, 1);
|
||||
@ -396,6 +430,16 @@ public class GlStateManager {
|
||||
stateEnableShaderBlendColor = false;
|
||||
}
|
||||
|
||||
public static final void setBlendConstants(float r, float g, float b, float a) {
|
||||
if(r != blendConstantR || g != blendConstantG || b != blendConstantB || a != blendConstantA) {
|
||||
_wglBlendColor(r, g, b, a);
|
||||
blendConstantR = r;
|
||||
blendConstantG = g;
|
||||
blendConstantB = b;
|
||||
blendConstantA = a;
|
||||
}
|
||||
}
|
||||
|
||||
public static final void enableFog() {
|
||||
stateFog = true;
|
||||
}
|
||||
@ -468,7 +512,7 @@ public class GlStateManager {
|
||||
}
|
||||
|
||||
public static final void enableColorLogic() {
|
||||
System.err.println("TODO: rewrite text field cursor to use blending");
|
||||
throw new UnsupportedOperationException("Color logic op is not supported in OpenGL ES!");
|
||||
}
|
||||
|
||||
public static final void disableColorLogic() {
|
||||
@ -523,6 +567,20 @@ public class GlStateManager {
|
||||
textureCoordsY[activeTexture] = y;
|
||||
++textureCoordsAccessSerial[activeTexture];
|
||||
}
|
||||
|
||||
public static final void texCoords2DDirect(int tex, float x, float y) {
|
||||
textureCoordsX[tex] = x;
|
||||
textureCoordsY[tex] = y;
|
||||
++textureCoordsAccessSerial[tex];
|
||||
}
|
||||
|
||||
public static final float getTexCoordX(int tex) {
|
||||
return textureCoordsX[tex];
|
||||
}
|
||||
|
||||
public static final float getTexCoordY(int tex) {
|
||||
return textureCoordsY[tex];
|
||||
}
|
||||
|
||||
public static final int generateTexture() {
|
||||
return EaglercraftGPU.mapTexturesGL.register(_wglGenTextures());
|
||||
@ -530,6 +588,19 @@ public class GlStateManager {
|
||||
|
||||
public static final void deleteTexture(int texture) {
|
||||
_wglDeleteTextures(EaglercraftGPU.mapTexturesGL.free(texture));
|
||||
boolean f = false;
|
||||
for(int i = 0; i < boundTexture.length; ++i) {
|
||||
if(boundTexture[i] == texture) {
|
||||
_wglActiveTexture(GL_TEXTURE0 + i);
|
||||
_wglBindTexture(GL_TEXTURE_2D, null);
|
||||
_wglBindTexture(GL_TEXTURE_3D, null);
|
||||
boundTexture[i] = -1;
|
||||
f = true;
|
||||
}
|
||||
}
|
||||
if(f) {
|
||||
_wglActiveTexture(GL_TEXTURE0 + activeTexture);
|
||||
}
|
||||
}
|
||||
|
||||
public static final void bindTexture(int texture) {
|
||||
@ -539,8 +610,25 @@ public class GlStateManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static final int getTextureBound() {
|
||||
return boundTexture[activeTexture];
|
||||
public static final void bindTexture3D(int texture) {
|
||||
if(texture != boundTexture[activeTexture]) {
|
||||
_wglBindTexture(GL_TEXTURE_3D, EaglercraftGPU.mapTexturesGL.get(texture));
|
||||
boundTexture[activeTexture] = texture;
|
||||
}
|
||||
}
|
||||
|
||||
public static final void quickBindTexture(int unit, int texture) {
|
||||
int unitBase = unit - GL_TEXTURE0;
|
||||
if(texture != boundTexture[unitBase]) {
|
||||
if(unitBase != activeTexture) {
|
||||
_wglActiveTexture(unit);
|
||||
}
|
||||
_wglBindTexture(GL_TEXTURE_2D, EaglercraftGPU.mapTexturesGL.get(texture));
|
||||
boundTexture[unitBase] = texture;
|
||||
if(unitBase != activeTexture) {
|
||||
_wglActiveTexture(GL_TEXTURE0 + activeTexture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final void shadeModel(int mode) {
|
||||
@ -730,22 +818,23 @@ public class GlStateManager {
|
||||
++textureMatrixAccessSerial[activeTexture];
|
||||
break;
|
||||
}
|
||||
matrix.m00 = 2.0f / (float)(right - left);
|
||||
matrix.m01 = 0.0f;
|
||||
matrix.m02 = 0.0f;
|
||||
matrix.m03 = 0.0f;
|
||||
matrix.m10 = 0.0f;
|
||||
matrix.m11 = 2.0f / (float)(top - bottom);
|
||||
matrix.m12 = 0.0f;
|
||||
matrix.m13 = 0.0f;
|
||||
matrix.m20 = 0.0f;
|
||||
matrix.m21 = 0.0f;
|
||||
matrix.m22 = 2.0f / (float)(zFar - zNear);
|
||||
matrix.m23 = 0.0f;
|
||||
matrix.m30 = (float)(-(right + left) / (right - left));
|
||||
matrix.m31 = (float)(-(top + bottom) / (top - bottom));
|
||||
matrix.m32 = (float)((zFar + zNear) / (zFar - zNear));
|
||||
matrix.m33 = 1.0f;
|
||||
paramMatrix.m00 = 2.0f / (float)(right - left);
|
||||
paramMatrix.m01 = 0.0f;
|
||||
paramMatrix.m02 = 0.0f;
|
||||
paramMatrix.m03 = 0.0f;
|
||||
paramMatrix.m10 = 0.0f;
|
||||
paramMatrix.m11 = 2.0f / (float)(top - bottom);
|
||||
paramMatrix.m12 = 0.0f;
|
||||
paramMatrix.m13 = 0.0f;
|
||||
paramMatrix.m20 = 0.0f;
|
||||
paramMatrix.m21 = 0.0f;
|
||||
paramMatrix.m22 = 2.0f / (float)(zFar - zNear);
|
||||
paramMatrix.m23 = 0.0f;
|
||||
paramMatrix.m30 = (float)(-(right + left) / (right - left));
|
||||
paramMatrix.m31 = (float)(-(top + bottom) / (top - bottom));
|
||||
paramMatrix.m32 = (float)((zFar + zNear) / (zFar - zNear));
|
||||
paramMatrix.m33 = 1.0f;
|
||||
Matrix4f.mul(matrix, paramMatrix, matrix);
|
||||
}
|
||||
|
||||
private static final Vector3f paramVector = new Vector3f();
|
||||
@ -940,22 +1029,98 @@ public class GlStateManager {
|
||||
break;
|
||||
}
|
||||
float cotangent = (float) Math.cos(fovy * toRad * 0.5f) / (float) Math.sin(fovy * toRad * 0.5f);
|
||||
matrix.m00 = cotangent / aspect;
|
||||
matrix.m01 = 0.0f;
|
||||
matrix.m02 = 0.0f;
|
||||
matrix.m03 = 0.0f;
|
||||
matrix.m10 = 0.0f;
|
||||
matrix.m11 = cotangent;
|
||||
matrix.m12 = 0.0f;
|
||||
matrix.m13 = 0.0f;
|
||||
matrix.m20 = 0.0f;
|
||||
matrix.m21 = 0.0f;
|
||||
matrix.m22 = (zFar + zNear) / (zFar - zNear);
|
||||
matrix.m23 = -1.0f;
|
||||
matrix.m30 = 0.0f;
|
||||
matrix.m31 = 0.0f;
|
||||
matrix.m32 = 2.0f * zFar * zNear / (zFar - zNear);
|
||||
matrix.m33 = 0.0f;
|
||||
paramMatrix.m00 = cotangent / aspect;
|
||||
paramMatrix.m01 = 0.0f;
|
||||
paramMatrix.m02 = 0.0f;
|
||||
paramMatrix.m03 = 0.0f;
|
||||
paramMatrix.m10 = 0.0f;
|
||||
paramMatrix.m11 = cotangent;
|
||||
paramMatrix.m12 = 0.0f;
|
||||
paramMatrix.m13 = 0.0f;
|
||||
paramMatrix.m20 = 0.0f;
|
||||
paramMatrix.m21 = 0.0f;
|
||||
paramMatrix.m22 = (zFar + zNear) / (zFar - zNear);
|
||||
paramMatrix.m23 = -1.0f;
|
||||
paramMatrix.m30 = 0.0f;
|
||||
paramMatrix.m31 = 0.0f;
|
||||
paramMatrix.m32 = 2.0f * zFar * zNear / (zFar - zNear);
|
||||
paramMatrix.m33 = 0.0f;
|
||||
Matrix4f.mul(matrix, paramMatrix, matrix);
|
||||
}
|
||||
|
||||
public static final void gluLookAt(Vector3f eye, Vector3f center, Vector3f up) {
|
||||
Matrix4f matrix;
|
||||
switch(stateMatrixMode) {
|
||||
case GL_MODELVIEW:
|
||||
matrix = modelMatrixStack[modelMatrixStackPointer];
|
||||
modelMatrixStackAccessSerial[modelMatrixStackPointer] = ++modelMatrixAccessSerial;
|
||||
break;
|
||||
case GL_PROJECTION:
|
||||
default:
|
||||
matrix = projectionMatrixStack[projectionMatrixStackPointer];
|
||||
projectionMatrixStackAccessSerial[projectionMatrixStackPointer] = ++projectionMatrixAccessSerial;
|
||||
break;
|
||||
case GL_TEXTURE:
|
||||
int ptr = textureMatrixStackPointer[activeTexture];
|
||||
matrix = textureMatrixStack[activeTexture][ptr];
|
||||
textureMatrixStackAccessSerial[activeTexture][textureMatrixStackPointer[activeTexture]] =
|
||||
++textureMatrixAccessSerial[activeTexture];
|
||||
break;
|
||||
}
|
||||
float x = center.x - eye.x;
|
||||
float y = center.y - eye.y;
|
||||
float z = center.z - eye.z;
|
||||
float xyzLen = (float) Math.sqrt(x * x + y * y + z * z);
|
||||
x /= xyzLen;
|
||||
y /= xyzLen;
|
||||
z /= xyzLen;
|
||||
float ux = up.x;
|
||||
float uy = up.y;
|
||||
float uz = up.z;
|
||||
xyzLen = (float) Math.sqrt(ux * ux + uy * uy + uz * uz);
|
||||
ux /= xyzLen;
|
||||
uy /= xyzLen;
|
||||
uz /= xyzLen;
|
||||
float lxx = y * uz - z * uy;
|
||||
float lxy = ux * z - uz * x;
|
||||
float lxz = x * uy - y * ux;
|
||||
float lyx = lxy * z - lxz * y;
|
||||
float lyy = x * lxz - z * lxx;
|
||||
float lyz = lxx * y - lxy * x;
|
||||
paramMatrix.m00 = lxx;
|
||||
paramMatrix.m01 = lyx;
|
||||
paramMatrix.m02 = -x;
|
||||
paramMatrix.m03 = 0.0f;
|
||||
paramMatrix.m10 = lxy;
|
||||
paramMatrix.m11 = lyy;
|
||||
paramMatrix.m12 = -y;
|
||||
paramMatrix.m13 = 0.0f;
|
||||
paramMatrix.m20 = lxz;
|
||||
paramMatrix.m21 = lyz;
|
||||
paramMatrix.m22 = -z;
|
||||
paramMatrix.m23 = 0.0f;
|
||||
paramMatrix.m30 = -eye.x;
|
||||
paramMatrix.m31 = -eye.y;
|
||||
paramMatrix.m32 = -eye.z;
|
||||
paramMatrix.m33 = 1.0f;
|
||||
Matrix4f.mul(matrix, paramMatrix, matrix);
|
||||
}
|
||||
|
||||
public static final void transform(Vector4f vecIn, Vector4f vecOut) {
|
||||
Matrix4f matrix;
|
||||
switch(stateMatrixMode) {
|
||||
case GL_MODELVIEW:
|
||||
matrix = modelMatrixStack[modelMatrixStackPointer];
|
||||
break;
|
||||
case GL_PROJECTION:
|
||||
default:
|
||||
matrix = projectionMatrixStack[projectionMatrixStackPointer];
|
||||
break;
|
||||
case GL_TEXTURE:
|
||||
matrix = textureMatrixStack[activeTexture][textureMatrixStackPointer[activeTexture]];
|
||||
break;
|
||||
}
|
||||
Matrix4f.transform(matrix, vecIn, vecOut);
|
||||
}
|
||||
|
||||
private static final Matrix4f unprojA = new Matrix4f();
|
||||
@ -975,6 +1140,47 @@ public class GlStateManager {
|
||||
objectcoords[2] = unprojC.z / unprojC.w;
|
||||
}
|
||||
|
||||
public static final void getMatrix(Matrix4f mat) {
|
||||
switch(stateMatrixMode) {
|
||||
case GL_MODELVIEW:
|
||||
mat.load(modelMatrixStack[modelMatrixStackPointer]);
|
||||
break;
|
||||
case GL_PROJECTION:
|
||||
default:
|
||||
mat.load(projectionMatrixStack[projectionMatrixStackPointer]);
|
||||
break;
|
||||
case GL_TEXTURE:
|
||||
mat.load(textureMatrixStack[activeTexture][textureMatrixStackPointer[activeTexture]]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static final void loadMatrix(Matrix4f mat) {
|
||||
switch(stateMatrixMode) {
|
||||
case GL_MODELVIEW:
|
||||
modelMatrixStack[modelMatrixStackPointer].load(mat);
|
||||
modelMatrixStackAccessSerial[modelMatrixStackPointer] = ++modelMatrixAccessSerial;
|
||||
break;
|
||||
case GL_PROJECTION:
|
||||
default:
|
||||
projectionMatrixStack[projectionMatrixStackPointer].load(mat);
|
||||
projectionMatrixStackAccessSerial[projectionMatrixStackPointer] = ++projectionMatrixAccessSerial;
|
||||
break;
|
||||
case GL_TEXTURE:
|
||||
textureMatrixStack[activeTexture][textureMatrixStackPointer[activeTexture]].load(mat);
|
||||
textureMatrixStackAccessSerial[activeTexture][textureMatrixStackPointer[activeTexture]] = ++textureMatrixAccessSerial[activeTexture];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static final int getModelViewSerial() {
|
||||
return modelMatrixStackAccessSerial[modelMatrixStackPointer];
|
||||
}
|
||||
|
||||
public static final Matrix4f getModelViewReference() {
|
||||
return modelMatrixStack[modelMatrixStackPointer];
|
||||
}
|
||||
|
||||
public static void recompileShaders() {
|
||||
FixedFunctionPipeline.flushCache();
|
||||
}
|
||||
|
@ -0,0 +1,37 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public interface IExtPipelineCompiler {
|
||||
|
||||
/**
|
||||
* @return new String[] { vshSource, fshSource }
|
||||
*/
|
||||
String[] getShaderSource(int stateCoreBits, int stateExtBits, Object[] userPointer);
|
||||
|
||||
int getExtensionStatesCount();
|
||||
|
||||
int getCurrentExtensionStateBits(int stateCoreBits);
|
||||
|
||||
int getCoreStateMask(int stateExtBits);
|
||||
|
||||
void initializeNewShader(IProgramGL compiledProg, int stateCoreBits, int stateExtBits, Object[] userPointer);
|
||||
|
||||
void updatePipeline(IProgramGL compiledProg, int stateCoreBits, int stateExtBits, Object[] userPointer);
|
||||
|
||||
void destroyPipeline(IProgramGL shaderProgram, int stateCoreBits, int stateExtBits, Object[] userPointer);
|
||||
|
||||
}
|
@ -14,6 +14,7 @@ import net.lax1dude.eaglercraft.v1_8.internal.buffer.FloatBuffer;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.FixedFunctionShader.FixedFunctionConstants;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.DeferredStateManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.vector.Matrix4f;
|
||||
import net.lax1dude.eaglercraft.v1_8.vector.Vector4f;
|
||||
|
||||
@ -276,7 +277,7 @@ public class InstancedFontRenderer {
|
||||
_wglUniformMatrix4fv(u_matrixTransform, false, matrixCopyBuffer);
|
||||
}
|
||||
|
||||
if(!fogEnabled) {
|
||||
if(!fogEnabled || DeferredStateManager.isInDeferredPass()) {
|
||||
int serial = GlStateManager.stateColorSerial;
|
||||
if(stateColorSerial != serial) {
|
||||
stateColorSerial = serial;
|
||||
|
@ -32,13 +32,8 @@ public class SpriteLevelMixer {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger("SpriteLevelMixer");
|
||||
|
||||
public static final String vertexShaderPath = "/assets/eagler/glsl/local.vsh";
|
||||
public static final String fragmentShaderPath = "/assets/eagler/glsl/texture_mix.fsh";
|
||||
|
||||
public static IShaderGL vshLocal = null;
|
||||
|
||||
private static IBufferGL vertexBuffer = null;
|
||||
public static IBufferArrayGL vertexArray = null;
|
||||
private static IProgramGL shaderProgram = null;
|
||||
|
||||
private static IUniformGL u_textureLod1f = null;
|
||||
@ -67,34 +62,13 @@ public class SpriteLevelMixer {
|
||||
|
||||
static void initialize() {
|
||||
|
||||
String vertexSource = EagRuntime.getResourceString(vertexShaderPath);
|
||||
if(vertexSource == null) {
|
||||
throw new RuntimeException("SpriteLevelMixer shader \"" + vertexShaderPath + "\" is missing!");
|
||||
}
|
||||
|
||||
String fragmentSource = EagRuntime.getResourceString(fragmentShaderPath);
|
||||
if(fragmentSource == null) {
|
||||
throw new RuntimeException("SpriteLevelMixer shader \"" + fragmentShaderPath + "\" is missing!");
|
||||
}
|
||||
|
||||
vshLocal = _wglCreateShader(GL_VERTEX_SHADER);
|
||||
IShaderGL frag = _wglCreateShader(GL_FRAGMENT_SHADER);
|
||||
|
||||
_wglShaderSource(vshLocal, FixedFunctionConstants.VERSION + "\n" + vertexSource);
|
||||
_wglCompileShader(vshLocal);
|
||||
|
||||
if(_wglGetShaderi(vshLocal, GL_COMPILE_STATUS) != GL_TRUE) {
|
||||
LOGGER.error("Failed to compile GL_VERTEX_SHADER \"" + vertexShaderPath + "\" for SpriteLevelMixer!");
|
||||
String log = _wglGetShaderInfoLog(vshLocal);
|
||||
if(log != null) {
|
||||
String[] lines = log.split("(\\r\\n|\\r|\\n)");
|
||||
for(int i = 0; i < lines.length; ++i) {
|
||||
LOGGER.error("[VERT] {}", lines[i]);
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("Vertex shader \"" + vertexShaderPath + "\" could not be compiled!");
|
||||
}
|
||||
|
||||
_wglShaderSource(frag, FixedFunctionConstants.VERSION + "\n" + fragmentSource);
|
||||
_wglCompileShader(frag);
|
||||
|
||||
@ -112,12 +86,12 @@ public class SpriteLevelMixer {
|
||||
|
||||
shaderProgram = _wglCreateProgram();
|
||||
|
||||
_wglAttachShader(shaderProgram, vshLocal);
|
||||
_wglAttachShader(shaderProgram, DrawUtils.vshLocal);
|
||||
_wglAttachShader(shaderProgram, frag);
|
||||
|
||||
_wglLinkProgram(shaderProgram);
|
||||
|
||||
_wglDetachShader(shaderProgram, vshLocal);
|
||||
_wglDetachShader(shaderProgram, DrawUtils.vshLocal);
|
||||
_wglDetachShader(shaderProgram, frag);
|
||||
|
||||
_wglDeleteShader(frag);
|
||||
@ -145,26 +119,6 @@ public class SpriteLevelMixer {
|
||||
|
||||
_wglUniform1i(_wglGetUniformLocation(shaderProgram, "u_inputTexture"), 0);
|
||||
|
||||
vertexArray = _wglGenVertexArrays();
|
||||
vertexBuffer = _wglGenBuffers();
|
||||
|
||||
FloatBuffer verts = EagRuntime.allocateFloatBuffer(12);
|
||||
verts.put(new float[] {
|
||||
0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
|
||||
1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f
|
||||
});
|
||||
verts.flip();
|
||||
|
||||
EaglercraftGPU.bindGLBufferArray(vertexArray);
|
||||
|
||||
EaglercraftGPU.bindGLArrayBuffer(vertexBuffer);
|
||||
_wglBufferData(GL_ARRAY_BUFFER, verts, GL_STATIC_DRAW);
|
||||
|
||||
EagRuntime.freeFloatBuffer(verts);
|
||||
|
||||
_wglEnableVertexAttribArray(0);
|
||||
_wglVertexAttribPointer(0, 2, GL_FLOAT, false, 8, 0);
|
||||
|
||||
}
|
||||
|
||||
public static void setBlendColor(float r, float g, float b, float a) {
|
||||
@ -206,7 +160,7 @@ public class SpriteLevelMixer {
|
||||
if(blendColorChanged) {
|
||||
_wglUniform4f(u_blendFactor4f, blendColorR, blendColorG, blendColorB, blendColorA);
|
||||
blendColorChanged = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(biasColorChanged) {
|
||||
_wglUniform4f(u_blendBias4f, biasColorR, biasColorG, biasColorB, biasColorA);
|
||||
@ -221,9 +175,7 @@ public class SpriteLevelMixer {
|
||||
matrixChanged = false;
|
||||
}
|
||||
|
||||
EaglercraftGPU.bindGLBufferArray(vertexArray);
|
||||
|
||||
_wglDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,148 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IBufferArrayGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IBufferGL;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class StreamBuffer {
|
||||
|
||||
public final int initialSize;
|
||||
public final int initialCount;
|
||||
public final int maxCount;
|
||||
|
||||
protected StreamBufferInstance[] buffers;
|
||||
|
||||
protected int currentBufferId = 0;
|
||||
protected int overflowCounter = 0;
|
||||
|
||||
protected final IStreamBufferInitializer initializer;
|
||||
|
||||
public static class StreamBufferInstance {
|
||||
|
||||
protected IBufferArrayGL vertexArray = null;
|
||||
protected IBufferGL vertexBuffer = null;
|
||||
protected int vertexBufferSize = 0;
|
||||
|
||||
public boolean bindQuad16 = false;
|
||||
public boolean bindQuad32 = false;
|
||||
|
||||
public IBufferArrayGL getVertexArray() {
|
||||
return vertexArray;
|
||||
}
|
||||
|
||||
public IBufferGL getVertexBuffer() {
|
||||
return vertexBuffer;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static interface IStreamBufferInitializer {
|
||||
void initialize(IBufferArrayGL vertexArray, IBufferGL vertexBuffer);
|
||||
}
|
||||
|
||||
public StreamBuffer(int initialSize, int initialCount, int maxCount, IStreamBufferInitializer initializer) {
|
||||
this.buffers = new StreamBufferInstance[initialCount];
|
||||
for(int i = 0; i < this.buffers.length; ++i) {
|
||||
this.buffers[i] = new StreamBufferInstance();
|
||||
}
|
||||
this.initialSize = initialSize;
|
||||
this.initialCount = initialCount;
|
||||
this.maxCount = maxCount;
|
||||
this.initializer = initializer;
|
||||
}
|
||||
|
||||
public StreamBufferInstance getBuffer(int requiredMemory) {
|
||||
StreamBufferInstance next = buffers[(currentBufferId++) % buffers.length];
|
||||
if(next.vertexBuffer == null) {
|
||||
next.vertexBuffer = _wglGenBuffers();
|
||||
}
|
||||
if(next.vertexArray == null) {
|
||||
next.vertexArray = _wglGenVertexArrays();
|
||||
initializer.initialize(next.vertexArray, next.vertexBuffer);
|
||||
}
|
||||
if(next.vertexBufferSize < requiredMemory) {
|
||||
int newSize = (requiredMemory & 0xFFFFF000) + 0x2000;
|
||||
EaglercraftGPU.bindGLArrayBuffer(next.vertexBuffer);
|
||||
_wglBufferData(GL_ARRAY_BUFFER, newSize, GL_STREAM_DRAW);
|
||||
next.vertexBufferSize = newSize;
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
public void optimize() {
|
||||
overflowCounter += currentBufferId - buffers.length;
|
||||
if(overflowCounter < -25) {
|
||||
int newCount = buffers.length - 1 + ((overflowCounter + 25) / 5);
|
||||
if(newCount < initialCount) {
|
||||
newCount = initialCount;
|
||||
}
|
||||
if(newCount < buffers.length) {
|
||||
StreamBufferInstance[] newArray = new StreamBufferInstance[newCount];
|
||||
for(int i = 0; i < buffers.length; ++i) {
|
||||
if(i < newArray.length) {
|
||||
newArray[i] = buffers[i];
|
||||
}else {
|
||||
if(buffers[i].vertexArray != null) {
|
||||
_wglDeleteVertexArrays(buffers[i].vertexArray);
|
||||
}
|
||||
if(buffers[i].vertexBuffer != null) {
|
||||
_wglDeleteBuffers(buffers[i].vertexBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
buffers = newArray;
|
||||
}
|
||||
overflowCounter = 0;
|
||||
}else if(overflowCounter > 15) {
|
||||
int newCount = buffers.length + 1 + ((overflowCounter - 15) / 5);
|
||||
if(newCount > maxCount) {
|
||||
newCount = maxCount;
|
||||
}
|
||||
if(newCount > buffers.length) {
|
||||
StreamBufferInstance[] newArray = new StreamBufferInstance[newCount];
|
||||
for(int i = 0; i < newArray.length; ++i) {
|
||||
if(i < buffers.length) {
|
||||
newArray[i] = buffers[i];
|
||||
}else {
|
||||
newArray[i] = new StreamBufferInstance();
|
||||
}
|
||||
}
|
||||
buffers = newArray;
|
||||
}
|
||||
overflowCounter = 0;
|
||||
}
|
||||
currentBufferId = 0;
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
for(int i = 0; i < buffers.length; ++i) {
|
||||
StreamBufferInstance next = buffers[i];
|
||||
if(next.vertexArray != null) {
|
||||
_wglDeleteVertexArrays(next.vertexArray);
|
||||
}
|
||||
if(next.vertexBuffer != null) {
|
||||
_wglDeleteBuffers(next.vertexBuffer);
|
||||
}
|
||||
}
|
||||
buffers = new StreamBufferInstance[initialCount];
|
||||
for(int i = 0; i < buffers.length; ++i) {
|
||||
buffers[i] = new StreamBufferInstance();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,352 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.FixedFunctionShader.FixedFunctionConstants;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class TextureCopyUtil {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger("TextureCopyUtil");
|
||||
|
||||
public static final String vertexShaderPath = "/assets/eagler/glsl/texture_blit.vsh";
|
||||
public static final String fragmentShaderPath = "/assets/eagler/glsl/texture_blit.fsh";
|
||||
|
||||
private static String vshSource = null;
|
||||
private static String fshSource = null;
|
||||
|
||||
private static IShaderGL vshShader = null;
|
||||
|
||||
private static class TextureCopyShader {
|
||||
private IProgramGL shaderProgram = null;
|
||||
private IUniformGL u_srcCoords4f = null;
|
||||
private IUniformGL u_dstCoords4f = null;
|
||||
private IUniformGL u_textureLod1f = null;
|
||||
private IUniformGL u_pixelAlignmentSizes4f = null;
|
||||
private IUniformGL u_pixelAlignmentOffset2f = null;
|
||||
private TextureCopyShader(IProgramGL shaderProgram) {
|
||||
this.shaderProgram = shaderProgram;
|
||||
EaglercraftGPU.bindGLShaderProgram(shaderProgram);
|
||||
this.u_srcCoords4f = _wglGetUniformLocation(shaderProgram, "u_srcCoords4f");
|
||||
this.u_dstCoords4f = _wglGetUniformLocation(shaderProgram, "u_dstCoords4f");
|
||||
this.u_textureLod1f = _wglGetUniformLocation(shaderProgram, "u_textureLod1f");
|
||||
this.u_pixelAlignmentSizes4f = _wglGetUniformLocation(shaderProgram, "u_pixelAlignmentSizes4f");
|
||||
this.u_pixelAlignmentOffset2f = _wglGetUniformLocation(shaderProgram, "u_pixelAlignmentOffset2f");
|
||||
}
|
||||
}
|
||||
|
||||
private static TextureCopyShader textureBlit = null;
|
||||
private static TextureCopyShader textureBlitAligned = null;
|
||||
private static TextureCopyShader textureBlitDepth = null;
|
||||
private static TextureCopyShader textureBlitDepthAligned = null;
|
||||
|
||||
private static float srcViewW = 100.0f;
|
||||
private static float srcViewH = 100.0f;
|
||||
|
||||
private static float dstViewW = 50.0f;
|
||||
private static float dstViewH = 50.0f;
|
||||
|
||||
private static boolean isAligned = false;
|
||||
private static int alignW = 0;
|
||||
private static int alignH = 0;
|
||||
private static float alignOffsetX = 0.0f;
|
||||
private static float alignOffsetY = 0.0f;
|
||||
|
||||
static void initialize() {
|
||||
vshSource = EagRuntime.getResourceString(vertexShaderPath);
|
||||
if(vshSource == null) {
|
||||
throw new RuntimeException("TextureCopyUtil shader \"" + vertexShaderPath + "\" is missing!");
|
||||
}
|
||||
|
||||
fshSource = EagRuntime.getResourceString(fragmentShaderPath);
|
||||
if(fshSource == null) {
|
||||
throw new RuntimeException("TextureCopyUtil shader \"" + fragmentShaderPath + "\" is missing!");
|
||||
}
|
||||
|
||||
vshShader = _wglCreateShader(GL_VERTEX_SHADER);
|
||||
|
||||
_wglShaderSource(vshShader, FixedFunctionConstants.VERSION + "\n" + vshSource);
|
||||
_wglCompileShader(vshShader);
|
||||
|
||||
if(_wglGetShaderi(vshShader, GL_COMPILE_STATUS) != GL_TRUE) {
|
||||
LOGGER.error("Failed to compile GL_VERTEX_SHADER \"" + vertexShaderPath + "\" for TextureCopyUtil!");
|
||||
String log = _wglGetShaderInfoLog(vshShader);
|
||||
if(log != null) {
|
||||
String[] lines = log.split("(\\r\\n|\\r|\\n)");
|
||||
for(int i = 0; i < lines.length; ++i) {
|
||||
LOGGER.error("[VERT] {}", lines[i]);
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("Vertex shader \"" + vertexShaderPath + "\" could not be compiled!");
|
||||
}
|
||||
}
|
||||
|
||||
private static TextureCopyShader compileShader(boolean align, boolean depth) {
|
||||
IShaderGL frag = _wglCreateShader(GL_FRAGMENT_SHADER);
|
||||
|
||||
_wglShaderSource(frag,
|
||||
FixedFunctionConstants.VERSION + "\n" + (align ? "#define COMPILE_PIXEL_ALIGNMENT\n" : "")
|
||||
+ (depth ? "#define COMPILE_BLIT_DEPTH\n" : "") + fshSource);
|
||||
_wglCompileShader(frag);
|
||||
|
||||
if(_wglGetShaderi(frag, GL_COMPILE_STATUS) != GL_TRUE) {
|
||||
LOGGER.error("Failed to compile GL_FRAGMENT_SHADER \"" + fragmentShaderPath + "\" for TextureCopyUtil!");
|
||||
String log = _wglGetShaderInfoLog(frag);
|
||||
if(log != null) {
|
||||
String[] lines = log.split("(\\r\\n|\\r|\\n)");
|
||||
for(int i = 0; i < lines.length; ++i) {
|
||||
LOGGER.error("[FRAG] {}", lines[i]);
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("Fragment shader \"" + fragmentShaderPath + "\" could not be compiled!");
|
||||
}
|
||||
|
||||
IProgramGL shaderProgram = _wglCreateProgram();
|
||||
|
||||
_wglAttachShader(shaderProgram, vshShader);
|
||||
_wglAttachShader(shaderProgram, frag);
|
||||
|
||||
_wglLinkProgram(shaderProgram);
|
||||
|
||||
_wglDetachShader(shaderProgram, vshShader);
|
||||
_wglDetachShader(shaderProgram, frag);
|
||||
|
||||
_wglDeleteShader(frag);
|
||||
|
||||
if(_wglGetProgrami(shaderProgram, GL_LINK_STATUS) != GL_TRUE) {
|
||||
LOGGER.error("Failed to link shader program for TextureCopyUtil!");
|
||||
String log = _wglGetProgramInfoLog(shaderProgram);
|
||||
if(log != null) {
|
||||
String[] lines = log.split("(\\r\\n|\\r|\\n)");
|
||||
for(int i = 0; i < lines.length; ++i) {
|
||||
LOGGER.error("[LINK] {}", lines[i]);
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("Shader program for TextureCopyUtil could not be linked!");
|
||||
}
|
||||
|
||||
return new TextureCopyShader(shaderProgram);
|
||||
}
|
||||
|
||||
private static TextureCopyShader getShaderObj(boolean align, boolean depth) {
|
||||
if(align) {
|
||||
if(depth) {
|
||||
if(textureBlitDepthAligned == null) textureBlitDepthAligned = compileShader(true, true);
|
||||
return textureBlitDepthAligned;
|
||||
}else {
|
||||
if(textureBlitAligned == null) textureBlitAligned = compileShader(true, false);
|
||||
return textureBlitAligned;
|
||||
}
|
||||
}else {
|
||||
if(depth) {
|
||||
if(textureBlitDepth == null) textureBlitDepth = compileShader(false, true);
|
||||
return textureBlitDepth;
|
||||
}else {
|
||||
if(textureBlit == null) textureBlit = compileShader(false, false);
|
||||
return textureBlit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void srcSize(int w, int h) {
|
||||
srcViewW = w;
|
||||
srcViewH = h;
|
||||
}
|
||||
|
||||
public static void dstSize(int w, int h) {
|
||||
dstViewW = w * 0.5f;
|
||||
dstViewH = h * 0.5f;
|
||||
}
|
||||
|
||||
public static void srcDstSize(int w, int h) {
|
||||
srcViewW = w;
|
||||
srcViewH = h;
|
||||
dstViewW = w * 0.5f;
|
||||
dstViewH = h * 0.5f;
|
||||
}
|
||||
|
||||
/**
|
||||
* this is reset after every blit
|
||||
*/
|
||||
public static void alignPixels(int dstW, int dstH, float alignX, float alignY) {
|
||||
isAligned = true;
|
||||
alignW = dstW;
|
||||
alignH = dstH;
|
||||
alignOffsetX = alignX;
|
||||
alignOffsetY = alignY;
|
||||
}
|
||||
|
||||
/**
|
||||
* this is reset after every blit
|
||||
*/
|
||||
public static void alignPixelsTopLeft(int srcW, int srcH, int dstW, int dstH) {
|
||||
alignPixels(dstW, dstH, (0.5f * dstW) / srcW, (0.5f * dstH) / srcH);
|
||||
}
|
||||
|
||||
public static void disableAlign() {
|
||||
isAligned = false;
|
||||
}
|
||||
|
||||
public static void blitTexture(int srcX, int srcY, int dstX, int dstY, int w, int h) {
|
||||
blitTexture(0, srcX, srcY, w, h, dstX, dstY, w, h);
|
||||
}
|
||||
|
||||
public static void blitTexture(int lvl, int srcX, int srcY, int dstX, int dstY, int w, int h) {
|
||||
blitTexture(lvl, srcX, srcY, w, h, dstX, dstY, w, h);
|
||||
}
|
||||
|
||||
public static void blitTexture(int srcX, int srcY, int srcW, int srcH, int dstX, int dstY, int dstW, int dstH) {
|
||||
blitTexture(0, srcX, srcY, srcW, srcH, dstX, dstY, dstW, dstH);
|
||||
}
|
||||
|
||||
public static void blitTexture(int lvl, int srcX, int srcY, int srcW, int srcH, int dstX, int dstY, int dstW, int dstH) {
|
||||
TextureCopyShader shaderObj = getShaderObj(isAligned, false);
|
||||
EaglercraftGPU.bindGLShaderProgram(shaderObj.shaderProgram);
|
||||
_wglUniform4f(shaderObj.u_srcCoords4f, (float)srcX / srcViewW, (float)srcY / srcViewH, (float)srcW / srcViewW, (float)srcH / srcViewH);
|
||||
_wglUniform4f(shaderObj.u_dstCoords4f, (float) dstX / dstViewW - 1.0f, (float) dstY / dstViewH - 1.0f,
|
||||
(float) dstW / dstViewW, (float) dstH / dstViewH);
|
||||
_wglUniform1f(shaderObj.u_textureLod1f, lvl);
|
||||
if(isAligned) {
|
||||
_wglUniform4f(shaderObj.u_pixelAlignmentSizes4f, alignW, alignH, 1.0f / alignW, 1.0f / alignH);
|
||||
_wglUniform2f(shaderObj.u_pixelAlignmentOffset2f, alignOffsetX, alignOffsetY);
|
||||
isAligned = false;
|
||||
}
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
}
|
||||
|
||||
public static void blitTexture() {
|
||||
blitTexture(0);
|
||||
}
|
||||
|
||||
public static void blitTexture(int lvl) {
|
||||
TextureCopyShader shaderObj = getShaderObj(isAligned, false);
|
||||
EaglercraftGPU.bindGLShaderProgram(shaderObj.shaderProgram);
|
||||
_wglUniform4f(shaderObj.u_srcCoords4f, 0.0f, 0.0f, 1.0f, 1.0f);
|
||||
_wglUniform4f(shaderObj.u_dstCoords4f, -1.0f, -1.0f, 2.0f, 2.0f);
|
||||
_wglUniform1f(shaderObj.u_textureLod1f, lvl);
|
||||
if(isAligned) {
|
||||
_wglUniform4f(shaderObj.u_pixelAlignmentSizes4f, alignW, alignH, 1.0f / alignW, 1.0f / alignH);
|
||||
_wglUniform2f(shaderObj.u_pixelAlignmentOffset2f, alignOffsetX, alignOffsetY);
|
||||
isAligned = false;
|
||||
}
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
}
|
||||
|
||||
public static void blitTextureUsingViewports(int srcX, int srcY, int dstX, int dstY, int w, int h) {
|
||||
blitTextureUsingViewports(0, srcX, srcY, w, h, dstX, dstY, w, h);
|
||||
}
|
||||
|
||||
public static void blitTextureUsingViewports(int lvl, int srcX, int srcY, int dstX, int dstY, int w, int h) {
|
||||
blitTextureUsingViewports(lvl, srcX, srcY, w, h, dstX, dstY, w, h);
|
||||
}
|
||||
|
||||
public static void blitTextureUsingViewports(int srcX, int srcY, int srcW, int srcH, int dstX, int dstY, int dstW, int dstH) {
|
||||
blitTextureUsingViewports(0, srcX, srcY, srcW, srcH, dstX, dstY, dstW, dstH);
|
||||
}
|
||||
|
||||
public static void blitTextureUsingViewports(int lvl, int srcX, int srcY, int srcW, int srcH, int dstX, int dstY, int dstW, int dstH) {
|
||||
TextureCopyShader shaderObj = getShaderObj(isAligned, false);
|
||||
EaglercraftGPU.bindGLShaderProgram(shaderObj.shaderProgram);
|
||||
GlStateManager.viewport(dstX, dstY, dstW, dstH);
|
||||
_wglUniform4f(shaderObj.u_srcCoords4f, (float)srcX / srcViewW, (float)srcY / srcViewH, (float)srcW / srcViewW, (float)srcH / srcViewH);
|
||||
_wglUniform4f(shaderObj.u_dstCoords4f, -1.0f, -1.0f, 2.0f, 2.0f);
|
||||
_wglUniform1f(shaderObj.u_textureLod1f, lvl);
|
||||
if(isAligned) {
|
||||
_wglUniform4f(shaderObj.u_pixelAlignmentSizes4f, alignW, alignH, 1.0f / alignW, 1.0f / alignH);
|
||||
_wglUniform2f(shaderObj.u_pixelAlignmentOffset2f, alignOffsetX, alignOffsetY);
|
||||
isAligned = false;
|
||||
}
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
}
|
||||
|
||||
public static void blitTextureDepth(int srcX, int srcY, int dstX, int dstY, int w, int h) {
|
||||
blitTextureDepth(0, srcX, srcY, w, h, dstX, dstY, w, h);
|
||||
}
|
||||
|
||||
public static void blitTextureDepth(int lvl, int srcX, int srcY, int dstX, int dstY, int w, int h) {
|
||||
blitTextureDepth(lvl, srcX, srcY, w, h, dstX, dstY, w, h);
|
||||
}
|
||||
|
||||
public static void blitTextureDepth(int srcX, int srcY, int srcW, int srcH, int dstX, int dstY, int dstW, int dstH) {
|
||||
blitTextureDepth(0, srcX, srcY, srcW, srcH, dstX, dstY, dstW, dstH);
|
||||
}
|
||||
|
||||
public static void blitTextureDepth(int lvl, int srcX, int srcY, int srcW, int srcH, int dstX, int dstY, int dstW, int dstH) {
|
||||
TextureCopyShader shaderObj = getShaderObj(isAligned, true);
|
||||
EaglercraftGPU.bindGLShaderProgram(shaderObj.shaderProgram);
|
||||
_wglUniform4f(shaderObj.u_srcCoords4f, (float)srcX / srcViewW, (float)srcY / srcViewH, (float)srcW / srcViewW, (float)srcH / srcViewH);
|
||||
_wglUniform4f(shaderObj.u_dstCoords4f, (float) dstX / dstViewW - 1.0f, (float) dstY / dstViewH - 1.0f,
|
||||
(float) dstW / dstViewW, (float) dstH / dstViewH);
|
||||
_wglUniform1f(shaderObj.u_textureLod1f, lvl);
|
||||
if(isAligned) {
|
||||
_wglUniform4f(shaderObj.u_pixelAlignmentSizes4f, alignW, alignH, 1.0f / alignW, 1.0f / alignH);
|
||||
_wglUniform2f(shaderObj.u_pixelAlignmentOffset2f, alignOffsetX, alignOffsetY);
|
||||
isAligned = false;
|
||||
}
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
}
|
||||
|
||||
public static void blitTextureDepth() {
|
||||
blitTextureDepth(0);
|
||||
}
|
||||
|
||||
public static void blitTextureDepth(int lvl) {
|
||||
TextureCopyShader shaderObj = getShaderObj(isAligned, true);
|
||||
EaglercraftGPU.bindGLShaderProgram(shaderObj.shaderProgram);
|
||||
_wglUniform4f(shaderObj.u_srcCoords4f, 0.0f, 0.0f, 1.0f, 1.0f);
|
||||
_wglUniform4f(shaderObj.u_dstCoords4f, -1.0f, -1.0f, 2.0f, 2.0f);
|
||||
_wglUniform1f(shaderObj.u_textureLod1f, lvl);
|
||||
if(isAligned) {
|
||||
_wglUniform4f(shaderObj.u_pixelAlignmentSizes4f, alignW, alignH, 1.0f / alignW, 1.0f / alignH);
|
||||
_wglUniform2f(shaderObj.u_pixelAlignmentOffset2f, alignOffsetX, alignOffsetY);
|
||||
isAligned = false;
|
||||
}
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
}
|
||||
|
||||
public static void blitTextureDepthUsingViewports(int srcX, int srcY, int dstX, int dstY, int w, int h) {
|
||||
blitTextureDepthUsingViewports(0, srcX, srcY, w, h, dstX, dstY, w, h);
|
||||
}
|
||||
|
||||
public static void blitTextureDepthUsingViewports(int lvl, int srcX, int srcY, int dstX, int dstY, int w, int h) {
|
||||
blitTextureDepthUsingViewports(lvl, srcX, srcY, w, h, dstX, dstY, w, h);
|
||||
}
|
||||
|
||||
public static void blitTextureDepthUsingViewports(int srcX, int srcY, int srcW, int srcH, int dstX, int dstY, int dstW, int dstH) {
|
||||
blitTextureDepthUsingViewports(0, srcX, srcY, srcW, srcH, dstX, dstY, dstW, dstH);
|
||||
}
|
||||
|
||||
public static void blitTextureDepthUsingViewports(int lvl, int srcX, int srcY, int srcW, int srcH, int dstX, int dstY, int dstW, int dstH) {
|
||||
TextureCopyShader shaderObj = getShaderObj(isAligned, true);
|
||||
EaglercraftGPU.bindGLShaderProgram(shaderObj.shaderProgram);
|
||||
GlStateManager.viewport(dstX, dstY, dstW, dstH);
|
||||
_wglUniform4f(shaderObj.u_srcCoords4f, (float)srcX / srcViewW, (float)srcY / srcViewH, (float)srcW / srcViewW, (float)srcH / srcViewH);
|
||||
_wglUniform4f(shaderObj.u_dstCoords4f, -1.0f, -1.0f, 2.0f, 2.0f);
|
||||
_wglUniform1f(shaderObj.u_textureLod1f, lvl);
|
||||
if(isAligned) {
|
||||
_wglUniform4f(shaderObj.u_pixelAlignmentSizes4f, alignW, alignH, 1.0f / alignW, 1.0f / alignH);
|
||||
_wglUniform2f(shaderObj.u_pixelAlignmentOffset2f, alignOffsetX, alignOffsetY);
|
||||
isAligned = false;
|
||||
}
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@ import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
public enum VertexFormat {
|
||||
|
||||
BLOCK(true, true, false, true),
|
||||
BLOCK_SHADERS(true, true, true, true),
|
||||
ITEM(true, true, true, false),
|
||||
OLDMODEL_POSITION_TEX_NORMAL(true, false, true, false),
|
||||
PARTICLE_POSITION_TEX_COLOR_LMAP(true, true, true, true),
|
||||
@ -107,7 +108,6 @@ public enum VertexFormat {
|
||||
attribPositionFormat = COMPONENT_POSITION_FORMAT;
|
||||
attribPositionNormalized = false;
|
||||
attribPositionSize = COMPONENT_POSITION_SIZE;
|
||||
attribPositionStride = COMPONENT_POSITION_STRIDE;
|
||||
bytes += COMPONENT_POSITION_STRIDE;
|
||||
|
||||
if(color) {
|
||||
@ -117,7 +117,6 @@ public enum VertexFormat {
|
||||
attribColorFormat = COMPONENT_COLOR_FORMAT;
|
||||
attribColorNormalized = true;
|
||||
attribColorSize = COMPONENT_COLOR_SIZE;
|
||||
attribColorStride = COMPONENT_COLOR_STRIDE;
|
||||
bytes += COMPONENT_COLOR_STRIDE;
|
||||
bitfield |= EaglercraftGPU.ATTRIB_COLOR;
|
||||
}else {
|
||||
@ -127,7 +126,6 @@ public enum VertexFormat {
|
||||
attribColorFormat = -1;
|
||||
attribColorNormalized = false;
|
||||
attribColorSize = -1;
|
||||
attribColorStride = -1;
|
||||
}
|
||||
|
||||
if(texture) {
|
||||
@ -137,7 +135,6 @@ public enum VertexFormat {
|
||||
attribTextureFormat = COMPONENT_TEX_FORMAT;
|
||||
attribTextureNormalized = false;
|
||||
attribTextureSize = COMPONENT_TEX_SIZE;
|
||||
attribTextureStride = COMPONENT_TEX_STRIDE;
|
||||
bytes += COMPONENT_TEX_STRIDE;
|
||||
bitfield |= EaglercraftGPU.ATTRIB_TEXTURE;
|
||||
}else {
|
||||
@ -147,7 +144,6 @@ public enum VertexFormat {
|
||||
attribTextureFormat = -1;
|
||||
attribTextureNormalized = false;
|
||||
attribTextureSize = -1;
|
||||
attribTextureStride = -1;
|
||||
}
|
||||
|
||||
if(normal) {
|
||||
@ -157,7 +153,6 @@ public enum VertexFormat {
|
||||
attribNormalFormat = COMPONENT_NORMAL_FORMAT;
|
||||
attribNormalNormalized = true;
|
||||
attribNormalSize = COMPONENT_NORMAL_SIZE;
|
||||
attribNormalStride = COMPONENT_NORMAL_STRIDE;
|
||||
bytes += COMPONENT_NORMAL_STRIDE;
|
||||
bitfield |= EaglercraftGPU.ATTRIB_NORMAL;
|
||||
}else {
|
||||
@ -167,7 +162,6 @@ public enum VertexFormat {
|
||||
attribNormalFormat = -1;
|
||||
attribNormalNormalized = false;
|
||||
attribNormalSize = -1;
|
||||
attribNormalStride = -1;
|
||||
}
|
||||
|
||||
if(lightmap) {
|
||||
@ -177,7 +171,6 @@ public enum VertexFormat {
|
||||
attribLightmapFormat = COMPONENT_LIGHTMAP_FORMAT;
|
||||
attribLightmapNormalized = false;
|
||||
attribLightmapSize = COMPONENT_LIGHTMAP_SIZE;
|
||||
attribLightmapStride = COMPONENT_LIGHTMAP_STRIDE;
|
||||
bytes += COMPONENT_LIGHTMAP_STRIDE;
|
||||
bitfield |= EaglercraftGPU.ATTRIB_LIGHTMAP;
|
||||
}else {
|
||||
@ -187,11 +180,14 @@ public enum VertexFormat {
|
||||
attribLightmapFormat = -1;
|
||||
attribLightmapNormalized = false;
|
||||
attribLightmapSize = -1;
|
||||
attribLightmapStride = -1;
|
||||
}
|
||||
|
||||
attribCount = index;
|
||||
attribStride = bytes;
|
||||
attribStride = attribPositionStride = bytes;
|
||||
attribColorStride = color ? bytes : -1;
|
||||
attribTextureStride = texture ? bytes : -1;
|
||||
attribNormalStride = normal ? bytes : -1;
|
||||
attribLightmapStride = lightmap ? bytes : -1;
|
||||
eaglercraftAttribBits = bitfield;
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import java.util.Comparator;
|
||||
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.PlatformBufferFunctions;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.vector.Vector3f;
|
||||
import net.minecraft.client.renderer.GLAllocation;
|
||||
import net.minecraft.util.MathHelper;
|
||||
|
||||
@ -150,9 +151,6 @@ public class WorldRenderer {
|
||||
return new WorldRenderer.State(aint, fmt);
|
||||
}
|
||||
|
||||
/**
|
||||
* MOST LIKELY A SLOW AND RETARDED WAY TO GET THE DISTANCE TO A QUAD
|
||||
*/
|
||||
private static float func_181665_a(FloatBuffer parFloatBuffer, float parFloat1, float parFloat2, float parFloat3,
|
||||
int parInt1, int parInt2) {
|
||||
float f = parFloatBuffer.get(parInt2 + parInt1 * 0 + 0);
|
||||
@ -379,6 +377,20 @@ public class WorldRenderer {
|
||||
this.byteBuffer.putInt(j1 + i1 * 3, l);
|
||||
}
|
||||
|
||||
public void putNormal(float x, float y, float z, int id) {
|
||||
int i = (byte) ((int) (x * 127.0F)) & 255;
|
||||
int j = (byte) ((int) (y * 127.0F)) & 255;
|
||||
int k = (byte) ((int) (z * 127.0F)) & 255;
|
||||
int l = i | j << 8 | k << 16 | ((byte)id) << 24;
|
||||
VertexFormat fmt = this.vertexFormat;
|
||||
int i1 = fmt.attribStride;
|
||||
int j1 = (this.vertexCount - 4) * i1 + fmt.attribNormalOffset;
|
||||
this.byteBuffer.putInt(j1, l);
|
||||
this.byteBuffer.putInt(j1 + i1, l);
|
||||
this.byteBuffer.putInt(j1 + i1 * 2, l);
|
||||
this.byteBuffer.putInt(j1 + i1 * 3, l);
|
||||
}
|
||||
|
||||
/**
|
||||
* set normal of current vertex
|
||||
*/
|
||||
@ -391,6 +403,67 @@ public class WorldRenderer {
|
||||
return this;
|
||||
}
|
||||
|
||||
private final Vector3f tmpVec1 = new Vector3f();
|
||||
private final Vector3f tmpVec2 = new Vector3f();
|
||||
private final Vector3f tmpVec3 = new Vector3f();
|
||||
private final Vector3f tmpVec4 = new Vector3f();
|
||||
private final Vector3f tmpVec5 = new Vector3f();
|
||||
private final Vector3f tmpVec6 = new Vector3f();
|
||||
|
||||
public void genNormals(boolean b, int vertId) {
|
||||
VertexFormat fmt = this.vertexFormat;
|
||||
int i1 = fmt.attribStride;
|
||||
int j1 = (this.vertexCount - 4) * i1;
|
||||
tmpVec1.x = this.byteBuffer.getFloat(j1);
|
||||
tmpVec1.y = this.byteBuffer.getFloat(j1 + 4);
|
||||
tmpVec1.z = this.byteBuffer.getFloat(j1 + 8);
|
||||
j1 += i1;
|
||||
tmpVec2.x = this.byteBuffer.getFloat(j1);
|
||||
tmpVec2.y = this.byteBuffer.getFloat(j1 + 4);
|
||||
tmpVec2.z = this.byteBuffer.getFloat(j1 + 8);
|
||||
j1 += i1 * 2;
|
||||
tmpVec3.x = this.byteBuffer.getFloat(j1);
|
||||
tmpVec3.y = this.byteBuffer.getFloat(j1 + 4);
|
||||
tmpVec3.z = this.byteBuffer.getFloat(j1 + 8);
|
||||
Vector3f.sub(tmpVec1, tmpVec2, tmpVec4);
|
||||
Vector3f.sub(tmpVec3, tmpVec2, tmpVec5);
|
||||
Vector3f.cross(tmpVec5, tmpVec4, tmpVec6);
|
||||
float f = (float) Math
|
||||
.sqrt((double) (tmpVec6.x * tmpVec6.x + tmpVec6.y * tmpVec6.y + tmpVec6.z * tmpVec6.z));
|
||||
tmpVec6.x /= f;
|
||||
tmpVec6.y /= f;
|
||||
tmpVec6.z /= f;
|
||||
int i = (byte) ((int) (tmpVec6.x * 127.0F)) & 255;
|
||||
int j = (byte) ((int) (tmpVec6.y * 127.0F)) & 255;
|
||||
int k = (byte) ((int) (tmpVec6.z * 127.0F)) & 255;
|
||||
int l = i | j << 8 | k << 16 | vertId << 24;
|
||||
int jj1 = (this.vertexCount - 4) * i1 + fmt.attribNormalOffset;
|
||||
this.byteBuffer.putInt(jj1, l);
|
||||
this.byteBuffer.putInt(jj1 + i1, l);
|
||||
if(!b) {
|
||||
this.byteBuffer.putInt(jj1 + i1 * 2, l);
|
||||
}
|
||||
this.byteBuffer.putInt(jj1 + i1 * 3, l);
|
||||
if(b) {
|
||||
j1 = (this.vertexCount - 2) * i1;
|
||||
tmpVec1.x = this.byteBuffer.getFloat(j1);
|
||||
tmpVec1.y = this.byteBuffer.getFloat(j1 + 4);
|
||||
tmpVec1.z = this.byteBuffer.getFloat(j1 + 8);
|
||||
Vector3f.sub(tmpVec2, tmpVec1, tmpVec4);
|
||||
Vector3f.sub(tmpVec3, tmpVec1, tmpVec5);
|
||||
Vector3f.cross(tmpVec5, tmpVec4, tmpVec6);
|
||||
f = (float) Math.sqrt((double) (tmpVec6.x * tmpVec6.x + tmpVec6.y * tmpVec6.y + tmpVec6.z * tmpVec6.z));
|
||||
tmpVec6.x /= f;
|
||||
tmpVec6.y /= f;
|
||||
tmpVec6.z /= f;
|
||||
i = (byte) ((int) (tmpVec6.x * 127.0F)) & 255;
|
||||
j = (byte) ((int) (tmpVec6.y * 127.0F)) & 255;
|
||||
k = (byte) ((int) (tmpVec6.z * 127.0F)) & 255;
|
||||
l = i | j << 8 | k << 16 | vertId << 24;
|
||||
this.byteBuffer.putInt(jj1 + i1 * 2, l);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sets translation applied to all positions set by functions
|
||||
*/
|
||||
|
@ -0,0 +1,49 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.minecraft.IAcceleratedParticleEngine;
|
||||
import net.minecraft.client.particle.EntityFX;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractAcceleratedEffectRenderer implements IAcceleratedParticleEngine {
|
||||
|
||||
public float partialTicks;
|
||||
|
||||
@Override
|
||||
public void drawParticle(Entity entityIn, int particleIndexX, int particleIndexY, int lightMapData,
|
||||
int texSize, float particleSize, float r, float g, float b, float a) {
|
||||
float xx = (float) (entityIn.prevPosX + (entityIn.posX - entityIn.prevPosX) * (double) partialTicks - EntityFX.interpPosX);
|
||||
float yy = (float) (entityIn.prevPosY + (entityIn.posY - entityIn.prevPosY) * (double) partialTicks - EntityFX.interpPosY);
|
||||
float zz = (float) (entityIn.prevPosZ + (entityIn.posZ - entityIn.prevPosZ) * (double) partialTicks - EntityFX.interpPosZ);
|
||||
drawParticle(xx, yy, zz, particleIndexX, particleIndexY, lightMapData, texSize, particleSize, r, g, b, a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawParticle(Entity entityIn, int particleIndexX, int particleIndexY, int lightMapData,
|
||||
int texSize, float particleSize, int rgba) {
|
||||
float xx = (float) (entityIn.prevPosX + (entityIn.posX - entityIn.prevPosX) * (double) partialTicks - EntityFX.interpPosX);
|
||||
float yy = (float) (entityIn.prevPosY + (entityIn.posY - entityIn.prevPosY) * (double) partialTicks - EntityFX.interpPosY);
|
||||
float zz = (float) (entityIn.prevPosZ + (entityIn.posZ - entityIn.prevPosZ) * (double) partialTicks - EntityFX.interpPosZ);
|
||||
drawParticle(xx, yy, zz, particleIndexX, particleIndexY, lightMapData, texSize, particleSize, rgba);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawParticle(float posX, float posY, float posZ, int particleIndexX, int particleIndexY,
|
||||
int lightMapData, int texSize, float particleSize, float r, float g, float b, float a) {
|
||||
int color = ((int)(a * 255.0f) << 24) | ((int)(r * 255.0f) << 16) | ((int)(g * 255.0f) << 8) | (int)(b * 255.0f);
|
||||
drawParticle(posX, posY, posZ, particleIndexX, particleIndexY, lightMapData, texSize, particleSize, color);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class ArrayListSerial<E> extends ArrayList<E> implements ListSerial<E> {
|
||||
|
||||
protected int modCountEagler = 0;
|
||||
protected int mark = 0;
|
||||
|
||||
public ArrayListSerial() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ArrayListSerial(int initialSize) {
|
||||
super(initialSize);
|
||||
}
|
||||
|
||||
public E set(int index, E element) {
|
||||
++modCountEagler;
|
||||
return super.set(index, element);
|
||||
}
|
||||
|
||||
public int getEaglerSerial() {
|
||||
return (modCount << 8) + modCountEagler;
|
||||
}
|
||||
|
||||
public void eaglerIncrSerial() {
|
||||
++modCountEagler;
|
||||
}
|
||||
|
||||
public void eaglerResetCheck() {
|
||||
mark = getEaglerSerial();
|
||||
}
|
||||
|
||||
public boolean eaglerCheck() {
|
||||
return mark != getEaglerSerial();
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,74 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.resources.IResourceManagerReloadListener;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class BlockVertexIDs implements IResourceManagerReloadListener {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger("BlockVertexIDsCSV");
|
||||
|
||||
public static final Map<String,Integer> modelToID = new HashMap();
|
||||
|
||||
public static int builtin_water_still_vertex_id = 0;
|
||||
public static int builtin_water_flow_vertex_id = 0;
|
||||
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager var1) {
|
||||
try {
|
||||
IResource itemsCsv = var1.getResource(new ResourceLocation("eagler:glsl/deferred/vertex_ids.csv"));
|
||||
try (BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(itemsCsv.getInputStream(), StandardCharsets.UTF_8))) {
|
||||
modelToID.clear();
|
||||
String line;
|
||||
boolean firstLine = true;
|
||||
while((line = reader.readLine()) != null) {
|
||||
if((line = line.trim()).length() > 0) {
|
||||
if(firstLine) {
|
||||
firstLine = false;
|
||||
continue;
|
||||
}
|
||||
String[] split = line.split(",");
|
||||
if(split.length == 2) {
|
||||
try {
|
||||
int i = Integer.parseInt(split[1]);
|
||||
if(i <= 0 || i > 254) {
|
||||
logger.error("Error: {}: Only IDs 1 to 254 are configurable!", split[0]);
|
||||
throw new NumberFormatException();
|
||||
}
|
||||
i -= 127;
|
||||
modelToID.put(split[0], i);
|
||||
switch(split[0]) {
|
||||
case "eagler:builtin/water_still_vertex_id":
|
||||
builtin_water_still_vertex_id = i;
|
||||
break;
|
||||
case "eagler:builtin/water_flow_vertex_id":
|
||||
builtin_water_flow_vertex_id = i;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}catch(NumberFormatException ex) {
|
||||
}
|
||||
}
|
||||
logger.error("Skipping bad vertex id entry: {}", line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch(Throwable t) {
|
||||
logger.error("Could not load list of vertex ids!");
|
||||
logger.error(t);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,607 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.ExtGLEnums.*;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
|
||||
import net.lax1dude.eaglercraft.v1_8.EaglercraftRandom;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IFramebufferGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.buffer.FloatBuffer;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.DrawUtils;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.EaglercraftGPU;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.GlStateManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.TextureCopyUtil;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program.PipelineShaderCloudsNoise3D;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program.PipelineShaderCloudsSample;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program.PipelineShaderCloudsShapes;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program.PipelineShaderCloudsSunOcclusion;
|
||||
import net.lax1dude.eaglercraft.v1_8.vector.Matrix3f;
|
||||
import net.lax1dude.eaglercraft.v1_8.vector.Matrix4f;
|
||||
import net.lax1dude.eaglercraft.v1_8.vector.Vector3f;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.util.MathHelper;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class CloudRenderWorker {
|
||||
|
||||
static PipelineShaderCloudsNoise3D shader_clouds_noise3d = null;
|
||||
static PipelineShaderCloudsShapes shader_clouds_shapes = null;
|
||||
static PipelineShaderCloudsSample shader_clouds_sample = null;
|
||||
static PipelineShaderCloudsSunOcclusion shader_clouds_sun_occlusion = null;
|
||||
|
||||
static int cloudNoiseTexture = -1;
|
||||
|
||||
static int cloud3DSamplesTextureSizeX = 256;
|
||||
static int cloud3DSamplesTextureSizeY = 256;
|
||||
static int cloud3DSamplesTextureSizeZ = 64;
|
||||
|
||||
static int cloudParaboloidTextureSize = 512;
|
||||
|
||||
static int cloud3DSamplesTexture = -1;
|
||||
static IFramebufferGL[] cloud3DSamplesSlices = null;
|
||||
|
||||
static IFramebufferGL[] cloudNoiseSampleParaboloidFramebuffer = new IFramebufferGL[4];
|
||||
static int[] cloudNoiseSampleParaboloidTexture = new int[] { -1, -1, -1, -1 };
|
||||
|
||||
static IFramebufferGL cloudOcclusionFramebuffer = null;
|
||||
static int cloudOcclusionTexture = -1;
|
||||
|
||||
static int cloudSpecialShapeTexture = -1;
|
||||
|
||||
static float renderViewX = 0.0f;
|
||||
static float renderViewY = 0.0f;
|
||||
static float renderViewZ = 0.0f;
|
||||
|
||||
private static final Matrix4f tmpMatrix1 = new Matrix4f();
|
||||
private static final Matrix3f tmpMatrix2 = new Matrix3f();
|
||||
private static final Matrix3f tmpMatrix3 = new Matrix3f();
|
||||
private static final Vector3f tmpVector1 = new Vector3f();
|
||||
private static final Vector3f tmpVector2 = new Vector3f();
|
||||
private static final Vector3f tmpVector3 = new Vector3f();
|
||||
|
||||
private static long cloudStartTimer = 0l;
|
||||
static int cloudRenderProgress = 0;
|
||||
static int cloudRenderPeriod = 500;
|
||||
static int cloudRenderPhase = 0;
|
||||
|
||||
static float cloudColorR = 0.0f;
|
||||
static float cloudColorG = 0.0f;
|
||||
static float cloudColorB = 0.0f;
|
||||
|
||||
static boolean isDrawingCloudShapes = false;
|
||||
|
||||
static int shapePosX = 100;
|
||||
static int shapeSizeX = 32;
|
||||
static int shapePosY = 80;
|
||||
static int shapeSizeY = 16;
|
||||
static int shapePosZ = 20;
|
||||
static int shapeSizeZ = 24;
|
||||
static float shapeRotate = 45.0f;
|
||||
|
||||
static long shapeUpdateTimer = 0l;
|
||||
static long nextShapeAppearance = 0l;
|
||||
|
||||
static EaglercraftRandom rand = new EaglercraftRandom();
|
||||
|
||||
static void initialize() {
|
||||
destroy();
|
||||
|
||||
cloudStartTimer = System.currentTimeMillis();
|
||||
cloudRenderProgress = 0;
|
||||
cloudRenderPeriod = 500;
|
||||
cloudRenderPhase = 0;
|
||||
cloudColorR = 0.0f;
|
||||
cloudColorG = 0.0f;
|
||||
cloudColorB = 0.0f;
|
||||
|
||||
shapeUpdateTimer = cloudStartTimer;
|
||||
nextShapeAppearance = cloudStartTimer + rand.nextInt(1800000);
|
||||
|
||||
cloudNoiseTexture = GlStateManager.generateTexture();
|
||||
GlStateManager.bindTexture(cloudNoiseTexture);
|
||||
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
int cloudNoiseW = 64, cloudNoiseH = 64, cloudNoiseLen = 4096;
|
||||
byte[] cloudNoiseDat = new byte[cloudNoiseLen];
|
||||
(new EaglercraftRandom(696969l)).nextBytes(cloudNoiseDat);
|
||||
ByteBuffer cloudNoiseDatBuffer = EagRuntime.allocateByteBuffer(cloudNoiseDat.length);
|
||||
cloudNoiseDatBuffer.put(cloudNoiseDat);
|
||||
cloudNoiseDatBuffer.flip();
|
||||
_wglTexImage2D(GL_TEXTURE_2D, 0, _GL_R8, cloudNoiseW, cloudNoiseH, 0, GL_RED, GL_UNSIGNED_BYTE, cloudNoiseDatBuffer);
|
||||
EagRuntime.freeByteBuffer(cloudNoiseDatBuffer);
|
||||
|
||||
cloud3DSamplesTexture = GlStateManager.generateTexture();
|
||||
GlStateManager.bindTexture3D(cloud3DSamplesTexture);
|
||||
_wglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
_wglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
_wglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||
_wglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
_wglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
_wglTexImage3D(GL_TEXTURE_3D, 0, _GL_R8, cloud3DSamplesTextureSizeX, cloud3DSamplesTextureSizeY,
|
||||
cloud3DSamplesTextureSizeZ, 0, GL_RED, GL_UNSIGNED_BYTE, (ByteBuffer) null);
|
||||
|
||||
cloud3DSamplesSlices = new IFramebufferGL[cloud3DSamplesTextureSizeZ];
|
||||
for(int i = 0; i < cloud3DSamplesTextureSizeZ; ++i) {
|
||||
cloud3DSamplesSlices[i] = _wglCreateFramebuffer();
|
||||
_wglBindFramebuffer(_GL_FRAMEBUFFER, cloud3DSamplesSlices[i]);
|
||||
_wglFramebufferTextureLayer(_GL_FRAMEBUFFER, _GL_COLOR_ATTACHMENT0, EaglercraftGPU.getNativeTexture(cloud3DSamplesTexture), 0, i);
|
||||
}
|
||||
|
||||
GlStateManager.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
for(int i = 0; i < 4; ++i) {
|
||||
cloudNoiseSampleParaboloidFramebuffer[i] = _wglCreateFramebuffer();
|
||||
_wglBindFramebuffer(_GL_FRAMEBUFFER, cloudNoiseSampleParaboloidFramebuffer[i]);
|
||||
cloudNoiseSampleParaboloidTexture[i] = GlStateManager.generateTexture();
|
||||
GlStateManager.bindTexture(cloudNoiseSampleParaboloidTexture[i]);
|
||||
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, i == 3 ? GL_LINEAR : GL_NEAREST);
|
||||
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, i == 3 ? GL_LINEAR : GL_NEAREST);
|
||||
EaglercraftGPU.createFramebufferHDR16FTexture(GL_TEXTURE_2D, 0, cloudParaboloidTextureSize, cloudParaboloidTextureSize, GL_RGBA, true);
|
||||
_wglFramebufferTexture2D(_GL_FRAMEBUFFER, _GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, EaglercraftGPU.getNativeTexture(cloudNoiseSampleParaboloidTexture[i]), 0);
|
||||
GlStateManager.clear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
cloudSpecialShapeTexture = GlStateManager.generateTexture();
|
||||
GlStateManager.bindTexture3D(cloudSpecialShapeTexture);
|
||||
_wglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
_wglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
_wglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||
_wglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
_wglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
byte[] cloudShapeTexture = EagRuntime.getResourceBytes("/assets/eagler/glsl/deferred/clouds_shapes.bmp");
|
||||
cloudNoiseDatBuffer = EagRuntime.allocateByteBuffer(cloudShapeTexture.length);
|
||||
cloudNoiseDatBuffer.put(cloudShapeTexture);
|
||||
cloudNoiseDatBuffer.flip();
|
||||
_wglTexImage3D(GL_TEXTURE_3D, 0, _GL_R8, 32, 16, 24, 0, GL_RED, GL_UNSIGNED_BYTE, (ByteBuffer) cloudNoiseDatBuffer);
|
||||
EagRuntime.freeByteBuffer(cloudNoiseDatBuffer);
|
||||
|
||||
shader_clouds_noise3d = PipelineShaderCloudsNoise3D.compile();
|
||||
shader_clouds_noise3d.loadUniforms();
|
||||
shader_clouds_shapes = PipelineShaderCloudsShapes.compile();
|
||||
shader_clouds_shapes.loadUniforms();
|
||||
shader_clouds_sample = PipelineShaderCloudsSample.compile();
|
||||
shader_clouds_sample.loadUniforms();
|
||||
shader_clouds_sun_occlusion = PipelineShaderCloudsSunOcclusion.compile();
|
||||
shader_clouds_sun_occlusion.loadUniforms();
|
||||
|
||||
cloudOcclusionFramebuffer = _wglCreateFramebuffer();
|
||||
_wglBindFramebuffer(_GL_FRAMEBUFFER, cloudOcclusionFramebuffer);
|
||||
cloudOcclusionTexture = GlStateManager.generateTexture();
|
||||
GlStateManager.bindTexture(cloudOcclusionTexture);
|
||||
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
_wglTexImage2D(GL_TEXTURE_2D, 0, _GL_R8, 1, 1, 0, GL_RED, GL_UNSIGNED_BYTE, (ByteBuffer)null);
|
||||
_wglFramebufferTexture2D(_GL_FRAMEBUFFER, _GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, EaglercraftGPU.getNativeTexture(cloudOcclusionTexture), 0);
|
||||
}
|
||||
|
||||
static void setPosition(float x, float y, float z) {
|
||||
renderViewX = x;
|
||||
renderViewY = y;
|
||||
renderViewZ = z;
|
||||
}
|
||||
|
||||
static void bindParaboloid() {
|
||||
GlStateManager.bindTexture(cloudNoiseSampleParaboloidTexture[3]);
|
||||
}
|
||||
|
||||
static void update() {
|
||||
long millis = System.currentTimeMillis();
|
||||
int cloudProgress = (int)(millis - cloudStartTimer);
|
||||
int totalCloudSteps = 32 + 32 - 1;
|
||||
int currentCloudStep = cloudProgress * totalCloudSteps / cloudRenderPeriod;
|
||||
boolean b = false;
|
||||
if(currentCloudStep > totalCloudSteps) {
|
||||
currentCloudStep = totalCloudSteps;
|
||||
b = true;
|
||||
}
|
||||
|
||||
float playerCoordsNoiseMapScale = 0.02f;
|
||||
FloatBuffer matrixCopyBuffer = EaglerDeferredPipeline.matrixCopyBuffer;
|
||||
|
||||
WorldClient wc = Minecraft.getMinecraft().theWorld;
|
||||
float rain = wc.getRainStrength(0.0f);
|
||||
if(cloudRenderProgress == 0) {
|
||||
shader_clouds_noise3d.useProgram();
|
||||
_wglUniform2f(shader_clouds_noise3d.uniforms.u_textureSize2f, 1.0f / cloud3DSamplesTextureSizeX, 1.0f / cloud3DSamplesTextureSizeY);
|
||||
float m = (float)((millis % 1200000l) * 0.00002);
|
||||
_wglUniform3f(shader_clouds_noise3d.uniforms.u_cloudMovement3f, m, 0.0f, m);//2.213f, 0.0f, 2.213f);
|
||||
|
||||
tmpMatrix1.setIdentity();
|
||||
tmpVector1.set(renderViewX * playerCoordsNoiseMapScale, 0.0f, renderViewZ * playerCoordsNoiseMapScale);
|
||||
Matrix4f.translate(tmpVector1, tmpMatrix1, tmpMatrix1);
|
||||
float s = 1500.0f;
|
||||
tmpVector1.set(s, s * 0.0015f, s);
|
||||
Matrix4f.scale(tmpVector1, tmpMatrix1, tmpMatrix1);
|
||||
matrixCopyBuffer.clear();
|
||||
matrixCopyBuffer.put(tmpMatrix1.m00);
|
||||
matrixCopyBuffer.put(tmpMatrix1.m01);
|
||||
matrixCopyBuffer.put(tmpMatrix1.m02);
|
||||
matrixCopyBuffer.put(tmpMatrix1.m10);
|
||||
matrixCopyBuffer.put(tmpMatrix1.m11);
|
||||
matrixCopyBuffer.put(tmpMatrix1.m12);
|
||||
matrixCopyBuffer.put(tmpMatrix1.m20);
|
||||
matrixCopyBuffer.put(tmpMatrix1.m21);
|
||||
matrixCopyBuffer.put(tmpMatrix1.m22);
|
||||
matrixCopyBuffer.put(tmpMatrix1.m30);
|
||||
matrixCopyBuffer.put(tmpMatrix1.m31);
|
||||
matrixCopyBuffer.put(tmpMatrix1.m32);
|
||||
matrixCopyBuffer.flip();
|
||||
_wglUniformMatrix4x3fv(shader_clouds_noise3d.uniforms.u_sampleOffsetMatrix4f, false, matrixCopyBuffer);
|
||||
|
||||
shader_clouds_sample.useProgram();
|
||||
_wglUniform1f(shader_clouds_sample.uniforms.u_rainStrength1f, 0.0f);
|
||||
_wglUniform1f(shader_clouds_sample.uniforms.u_cloudTimer1f, 0.0f);
|
||||
_wglUniform3f(shader_clouds_sample.uniforms.u_cloudOffset3f, renderViewX, renderViewY, renderViewZ);
|
||||
Vector3f currentSunAngle = DeferredStateManager.currentSunLightAngle;
|
||||
_wglUniform3f(shader_clouds_sample.uniforms.u_sunDirection3f, -currentSunAngle.x, -currentSunAngle.y, -currentSunAngle.z);
|
||||
currentSunAngle = tmpVector1;
|
||||
currentSunAngle.set(DeferredStateManager.currentSunLightColor);
|
||||
float luma = currentSunAngle.x * 0.299f + currentSunAngle.y * 0.587f + currentSunAngle.z * 0.114f;
|
||||
float sat = 0.65f; // desaturate sun a bit
|
||||
currentSunAngle.x = (currentSunAngle.x - luma) * sat + luma;
|
||||
currentSunAngle.y = (currentSunAngle.y - luma) * sat + luma;
|
||||
currentSunAngle.z = (currentSunAngle.z - luma) * sat + luma;
|
||||
cloudColorR += (currentSunAngle.x - cloudColorR) * 0.1f;
|
||||
cloudColorG += (currentSunAngle.y - cloudColorG) * 0.1f;
|
||||
cloudColorB += (currentSunAngle.z - cloudColorB) * 0.1f;
|
||||
_wglUniform3f(shader_clouds_sample.uniforms.u_sunColor3f, cloudColorR, cloudColorG, cloudColorB);
|
||||
|
||||
float cloudDensityTimer = (float)((System.currentTimeMillis() % 10000000l) * 0.001);
|
||||
cloudDensityTimer += MathHelper.sin(cloudDensityTimer * 1.5f) * 1.5f;
|
||||
float x = cloudDensityTimer * 0.004f;
|
||||
float f1 = MathHelper.sin(x + 0.322f) * 0.544f + MathHelper.sin(x * 4.5f + 1.843f) * 0.69f + MathHelper.sin(x * 3.4f + 0.8f) * 0.6f + MathHelper.sin(x * 6.1f + 1.72f) * 0.7f;
|
||||
x = cloudDensityTimer * 0.002f;
|
||||
float f2 = MathHelper.cos(x + 2.7f) + MathHelper.cos(x * 1.28f + 1.3f) * 0.4f + MathHelper.cos(x * 4.0f + 2.5f) * 0.3f + MathHelper.cos(x * 2.3f + 1.07f);
|
||||
float rain2 = rain + wc.getThunderStrength(0.0f);
|
||||
_wglUniform4f(shader_clouds_sample.uniforms.u_densityModifier4f, 0.015f + f1 * 0.0021f * (1.0f - rain2 * 0.35f) + rain2 * 0.00023f, 0.0325f, -0.0172f + f2 * 0.00168f * (1.0f - rain2 * 0.35f) + rain * 0.0015f, 0.0f);
|
||||
}
|
||||
|
||||
if(cloudRenderProgress < 32 && currentCloudStep > cloudRenderProgress) {
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(cloudNoiseTexture);
|
||||
|
||||
GlStateManager.viewport(0, 0, cloud3DSamplesTextureSizeX, cloud3DSamplesTextureSizeY);
|
||||
|
||||
updateShape();
|
||||
boolean shapeAllow = isDrawingCloudShapes;
|
||||
boolean shapeInit = false;
|
||||
|
||||
for(int i = cloudRenderProgress, j = currentCloudStep < 32 ? currentCloudStep : 32; i < j; ++i) {
|
||||
int ccl = i * 2;
|
||||
|
||||
boolean drawShape = false;
|
||||
if(isDrawingCloudShapes && shapeAllow) {
|
||||
if(ccl >= shapePosZ && ccl < shapePosZ + shapeSizeZ) {
|
||||
drawShape = true;
|
||||
if(!shapeInit) {
|
||||
shapeInit = true;
|
||||
Matrix3f mat = tmpMatrix2;
|
||||
mat.setIdentity();
|
||||
mat.m00 = MathHelper.cos(shapeRotate * 0.0174532f);
|
||||
mat.m01 = MathHelper.sin(shapeRotate * 0.0174532f);
|
||||
mat.m10 = -mat.m01;
|
||||
mat.m11 = mat.m00;
|
||||
mat = tmpMatrix3;
|
||||
mat.setIdentity();
|
||||
mat.m00 = (float)shapeSizeX * 0.5f;
|
||||
mat.m11 = (float)shapeSizeY * 0.5f;
|
||||
Matrix3f.mul(tmpMatrix2, mat, tmpMatrix2);
|
||||
tmpMatrix2.m20 = shapePosX - renderViewX * playerCoordsNoiseMapScale * 128.0f;
|
||||
tmpMatrix2.m21 = shapePosY - renderViewZ * playerCoordsNoiseMapScale * 128.0f;
|
||||
mat.setIdentity();
|
||||
mat.m00 = 2.0f / cloud3DSamplesTextureSizeX;
|
||||
mat.m11 = 2.0f / cloud3DSamplesTextureSizeY;
|
||||
Matrix3f.mul(mat, tmpMatrix2, tmpMatrix2);
|
||||
mat = tmpMatrix2;
|
||||
mat.m20 -= 1.0f;
|
||||
mat.m21 -= 1.0f;
|
||||
if(!checkFrustum(mat)) {
|
||||
drawShape = false;
|
||||
shapeAllow = false;
|
||||
}else {
|
||||
matrixCopyBuffer.clear();
|
||||
matrixCopyBuffer.put(mat.m00);
|
||||
matrixCopyBuffer.put(mat.m01);
|
||||
matrixCopyBuffer.put(mat.m10);
|
||||
matrixCopyBuffer.put(mat.m11);
|
||||
matrixCopyBuffer.put(mat.m20);
|
||||
matrixCopyBuffer.put(mat.m21);
|
||||
matrixCopyBuffer.flip();
|
||||
shader_clouds_shapes.useProgram();
|
||||
_wglUniformMatrix3x2fv(shader_clouds_shapes.uniforms.u_transformMatrix3x2f, false, matrixCopyBuffer);
|
||||
_wglUniform1f(shader_clouds_shapes.uniforms.u_textureLod1f, 0.0f);
|
||||
_wglUniform2f(shader_clouds_shapes.uniforms.u_sampleWeights2f, 0.35f, 0.55f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
shader_clouds_noise3d.useProgram();
|
||||
|
||||
_wglBindFramebuffer(_GL_FRAMEBUFFER, cloud3DSamplesSlices[ccl]);
|
||||
_wglUniform1f(shader_clouds_noise3d.uniforms.u_textureSlice1f, (float)(ccl / (float)cloud3DSamplesTextureSizeZ));
|
||||
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
|
||||
if(drawShape) {
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.blendFunc(GL_ONE, GL_SRC_ALPHA);
|
||||
shader_clouds_shapes.useProgram();
|
||||
_wglUniform1f(shader_clouds_shapes.uniforms.u_textureLevel1f, (float)(ccl - shapePosZ + 0.5f) / (float)shapeSizeZ);
|
||||
GlStateManager.bindTexture3D(cloudSpecialShapeTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
GlStateManager.disableBlend();
|
||||
shader_clouds_noise3d.useProgram();
|
||||
GlStateManager.bindTexture(cloudNoiseTexture);
|
||||
}
|
||||
|
||||
_wglBindFramebuffer(_GL_FRAMEBUFFER, cloud3DSamplesSlices[ccl + 1]);
|
||||
_wglUniform1f(shader_clouds_noise3d.uniforms.u_textureSlice1f, (float)((ccl + 1) / (float)cloud3DSamplesTextureSizeZ));
|
||||
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
|
||||
if(drawShape && ccl + 1 < shapePosZ + shapeSizeZ) {
|
||||
GlStateManager.enableBlend();
|
||||
shader_clouds_shapes.useProgram();
|
||||
_wglUniform1f(shader_clouds_shapes.uniforms.u_textureLevel1f, (float)((ccl + 1) - shapePosZ + 0.5f) / (float)shapeSizeZ);
|
||||
GlStateManager.bindTexture3D(cloudSpecialShapeTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
GlStateManager.disableBlend();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(currentCloudStep >= 32 && currentCloudStep > cloudRenderProgress) {
|
||||
_wglBindFramebuffer(_GL_FRAMEBUFFER, cloudNoiseSampleParaboloidFramebuffer[cloudRenderPhase]);
|
||||
GlStateManager.viewport(0, 0, cloudParaboloidTextureSize, cloudParaboloidTextureSize);
|
||||
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE1);
|
||||
GlStateManager.bindTexture(EaglerDeferredPipeline.instance.atmosphereIrradianceTexture);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture3D(cloud3DSamplesTexture);
|
||||
shader_clouds_sample.useProgram();
|
||||
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.tryBlendFuncSeparate(GL_DST_ALPHA, GL_ONE, GL_DST_ALPHA, GL_ZERO);
|
||||
|
||||
for(int i = cloudRenderProgress > 32 ? cloudRenderProgress - 32 : 0, j = currentCloudStep - 31; i < j; ++i) {
|
||||
if(i == 0) {
|
||||
GlStateManager.clearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
GlStateManager.clear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
_wglUniform1f(shader_clouds_sample.uniforms.u_sampleStep1f, i * 2);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
|
||||
_wglUniform1f(shader_clouds_sample.uniforms.u_sampleStep1f, i * 2 + 1);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
}
|
||||
|
||||
GlStateManager.disableBlend();
|
||||
}
|
||||
|
||||
if(b) {
|
||||
cloudRenderProgress = 0;
|
||||
cloudStartTimer = System.currentTimeMillis();
|
||||
cloudProgress = 0;
|
||||
cloudRenderPhase = (cloudRenderPhase + 1) % 3;
|
||||
}else {
|
||||
cloudRenderProgress = currentCloudStep;
|
||||
}
|
||||
|
||||
_wglBindFramebuffer(_GL_FRAMEBUFFER, cloudNoiseSampleParaboloidFramebuffer[3]);
|
||||
GlStateManager.viewport(0, 0, cloudParaboloidTextureSize, cloudParaboloidTextureSize);
|
||||
|
||||
float fadeFactor = cloudProgress / (float)cloudRenderPeriod;
|
||||
if(fadeFactor > 1.0f) fadeFactor = 1.0f;
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(cloudNoiseSampleParaboloidTexture[(cloudRenderPhase + 1) % 3]);
|
||||
TextureCopyUtil.blitTexture();
|
||||
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.blendFunc(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA);
|
||||
GlStateManager.setBlendConstants(0.0f, 0.0f, 0.0f, fadeFactor);
|
||||
GlStateManager.bindTexture(cloudNoiseSampleParaboloidTexture[(cloudRenderPhase + 2) % 3]);
|
||||
TextureCopyUtil.blitTexture();
|
||||
GlStateManager.disableBlend();
|
||||
|
||||
_wglBindFramebuffer(_GL_FRAMEBUFFER, cloudOcclusionFramebuffer);
|
||||
GlStateManager.viewport(0, 0, 1, 1);
|
||||
if(rain >= 1.0f) {
|
||||
GlStateManager.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
GlStateManager.clear(GL_COLOR_BUFFER_BIT);
|
||||
}else if(DeferredStateManager.currentSunLightAngle.y < 0.0f) {
|
||||
shader_clouds_sun_occlusion.useProgram();
|
||||
GlStateManager.bindTexture(cloudNoiseSampleParaboloidTexture[3]);
|
||||
matrixCopyBuffer.clear();
|
||||
|
||||
tmpVector1.set(0.0f, 1.0f, 0.0f);
|
||||
Vector3f vec33 = tmpVector3;
|
||||
vec33.set(DeferredStateManager.currentSunLightAngle);
|
||||
vec33.x = -vec33.x;
|
||||
vec33.y = -vec33.y;
|
||||
vec33.z = -vec33.z;
|
||||
Vector3f.cross(tmpVector1, vec33, tmpVector1);
|
||||
Vector3f.cross(vec33, tmpVector1, tmpVector2);
|
||||
|
||||
float rad = 0.1f;
|
||||
|
||||
matrixCopyBuffer.put(tmpVector1.x * rad);
|
||||
matrixCopyBuffer.put(tmpVector2.x * rad);
|
||||
matrixCopyBuffer.put(vec33.x * rad);
|
||||
|
||||
matrixCopyBuffer.put(tmpVector1.y * rad);
|
||||
matrixCopyBuffer.put(tmpVector2.y * rad);
|
||||
matrixCopyBuffer.put(vec33.y * rad);
|
||||
|
||||
matrixCopyBuffer.put(tmpVector1.z * rad);
|
||||
matrixCopyBuffer.put(tmpVector2.z * rad);
|
||||
matrixCopyBuffer.put(vec33.z * rad);
|
||||
|
||||
rad = 1.0f - rad;
|
||||
matrixCopyBuffer.put(vec33.x * rad);
|
||||
matrixCopyBuffer.put(vec33.y * rad);
|
||||
matrixCopyBuffer.put(vec33.z * rad);
|
||||
|
||||
matrixCopyBuffer.flip();
|
||||
_wglUniformMatrix4x3fv(shader_clouds_sun_occlusion.uniforms.u_sampleMatrix4x3f, false, matrixCopyBuffer);
|
||||
|
||||
if(rain > 0.0f) {
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.blendFunc(GL_CONSTANT_ALPHA, GL_ZERO);
|
||||
GlStateManager.setBlendConstants(0.0f, 0.0f, 0.0f, 1.0f - rain);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
GlStateManager.disableBlend();
|
||||
}else {
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
}
|
||||
}else {
|
||||
GlStateManager.clearColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
GlStateManager.clear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
static void destroy() {
|
||||
if(cloudNoiseTexture != -1) {
|
||||
GlStateManager.deleteTexture(cloudNoiseTexture);
|
||||
cloudNoiseTexture = -1;
|
||||
}
|
||||
for(int i = 0; i < 4; ++i) {
|
||||
if(cloudNoiseSampleParaboloidFramebuffer[i] != null) {
|
||||
_wglDeleteFramebuffer(cloudNoiseSampleParaboloidFramebuffer[i]);
|
||||
cloudNoiseSampleParaboloidFramebuffer[i] = null;
|
||||
}
|
||||
if(cloudNoiseSampleParaboloidTexture[i] != -1) {
|
||||
GlStateManager.deleteTexture(cloudNoiseSampleParaboloidTexture[i]);
|
||||
cloudNoiseSampleParaboloidTexture[i] = -1;
|
||||
}
|
||||
}
|
||||
if(cloud3DSamplesTexture != -1) {
|
||||
GlStateManager.deleteTexture(cloud3DSamplesTexture);
|
||||
cloud3DSamplesTexture = -1;
|
||||
}
|
||||
if(cloud3DSamplesSlices != null) {
|
||||
for(int i = 0; i < cloud3DSamplesSlices.length; ++i) {
|
||||
_wglDeleteFramebuffer(cloud3DSamplesSlices[i]);
|
||||
}
|
||||
cloud3DSamplesSlices = null;
|
||||
}
|
||||
if(cloudSpecialShapeTexture != -1) {
|
||||
GlStateManager.deleteTexture(cloudSpecialShapeTexture);
|
||||
cloudSpecialShapeTexture = -1;
|
||||
}
|
||||
if(cloudOcclusionFramebuffer != null) {
|
||||
_wglDeleteFramebuffer(cloudOcclusionFramebuffer);
|
||||
cloudOcclusionFramebuffer = null;
|
||||
}
|
||||
if(cloudOcclusionTexture != -1) {
|
||||
GlStateManager.deleteTexture(cloudOcclusionTexture);
|
||||
cloudOcclusionTexture = -1;
|
||||
}
|
||||
if(shader_clouds_noise3d != null) {
|
||||
shader_clouds_noise3d.destroy();
|
||||
shader_clouds_noise3d = null;
|
||||
}
|
||||
if(shader_clouds_shapes != null) {
|
||||
shader_clouds_shapes.destroy();
|
||||
shader_clouds_shapes = null;
|
||||
}
|
||||
if(shader_clouds_sample != null) {
|
||||
shader_clouds_sample.destroy();
|
||||
shader_clouds_sample = null;
|
||||
}
|
||||
if(shader_clouds_sun_occlusion != null) {
|
||||
shader_clouds_sun_occlusion.destroy();
|
||||
shader_clouds_sun_occlusion = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static void updateShape() {
|
||||
long millis = System.currentTimeMillis();
|
||||
float dt = (float)((millis - shapeUpdateTimer) * 0.001);
|
||||
shapeUpdateTimer = millis;
|
||||
if(millis > nextShapeAppearance) {
|
||||
float playerCoordsNoiseMapScale = 0.02f * 128.0f;
|
||||
if(!isDrawingCloudShapes) {
|
||||
float shapeScaleBase = rand.nextFloat() * 3.0f + 2.0f;
|
||||
shapeSizeX = (int)(32 * shapeScaleBase * (0.9f + rand.nextFloat() * 0.2f));
|
||||
shapeSizeY = (int)(16 * shapeScaleBase * (0.95f + rand.nextFloat() * 0.1f));
|
||||
shapeSizeZ = (int)(24 * shapeScaleBase * (0.48f + rand.nextFloat() * 0.04f));
|
||||
do {
|
||||
shapePosX = (int)(cloud3DSamplesTextureSizeX * (rand.nextFloat() * 1.5f - 0.75f));
|
||||
shapePosY = (int)(cloud3DSamplesTextureSizeY * (rand.nextFloat() * 1.5f - 0.75f));
|
||||
}while(shapePosX > -192 && shapePosY > -192 && shapePosX < 192 && shapePosY < 192);
|
||||
float l = -MathHelper.sqrt_float(shapePosX * shapePosX + shapePosY * shapePosY);
|
||||
shapeRotate = (float)Math.atan2(shapePosY / l, shapePosX / l) / 0.0174532f;
|
||||
shapeRotate += (rand.nextFloat() - 0.5f) * 90.0f;
|
||||
shapePosX += renderViewX * playerCoordsNoiseMapScale + cloud3DSamplesTextureSizeX * 0.5f;
|
||||
shapePosY += renderViewZ * playerCoordsNoiseMapScale + cloud3DSamplesTextureSizeY * 0.5f;
|
||||
shapePosZ = (int)((cloud3DSamplesTextureSizeZ - shapeSizeZ) * (rand.nextFloat() * 0.5f + 0.25f));
|
||||
isDrawingCloudShapes = true;
|
||||
}else {
|
||||
float dx = MathHelper.cos(-shapeRotate * 0.0174532f);
|
||||
float dy = MathHelper.sin(-shapeRotate * 0.0174532f);
|
||||
shapePosX += (int)(dx * 10.0f * dt);
|
||||
shapePosY -= (int)(dy * 10.0f * dt);
|
||||
if(MathHelper.abs(shapePosX - renderViewX * playerCoordsNoiseMapScale - cloud3DSamplesTextureSizeX * 0.5f) > 300.0f ||
|
||||
MathHelper.abs(shapePosY - renderViewZ * playerCoordsNoiseMapScale - cloud3DSamplesTextureSizeY * 0.5f) > 300.0f) {
|
||||
nextShapeAppearance = millis + 300000l + rand.nextInt(1500000);
|
||||
isDrawingCloudShapes = false;
|
||||
}
|
||||
}
|
||||
}else {
|
||||
isDrawingCloudShapes = false;
|
||||
}
|
||||
}
|
||||
|
||||
static boolean checkFrustum(Matrix3f mat) {
|
||||
Vector3f tmp = tmpVector1;
|
||||
tmp.x = -1.0f;
|
||||
tmp.y = -1.0f;
|
||||
tmp.z = 1.0f;
|
||||
Matrix3f.transform(mat, tmp, tmp);
|
||||
if(tmp.x >= -1.0f && tmp.x <= 1.0f && tmp.y >= -1.0f && tmp.y <= 1.0f) {
|
||||
return true;
|
||||
}
|
||||
tmp.x = 1.0f;
|
||||
tmp.y = -1.0f;
|
||||
Matrix3f.transform(mat, tmp, tmp);
|
||||
if(tmp.x >= -1.0f && tmp.x <= 1.0f && tmp.y >= -1.0f && tmp.y <= 1.0f) {
|
||||
return true;
|
||||
}
|
||||
tmp.x = 1.0f;
|
||||
tmp.y = 1.0f;
|
||||
Matrix3f.transform(mat, tmp, tmp);
|
||||
if(tmp.x >= -1.0f && tmp.x <= 1.0f && tmp.y >= -1.0f && tmp.y <= 1.0f) {
|
||||
return true;
|
||||
}
|
||||
tmp.x = -1.0f;
|
||||
tmp.y = 1.0f;
|
||||
Matrix3f.transform(mat, tmp, tmp);
|
||||
if(tmp.x >= -1.0f && tmp.x <= 1.0f && tmp.y >= -1.0f && tmp.y <= 1.0f) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,528 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.DrawUtils;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.GlStateManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program.PipelineShaderGBufferDebugView;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.ExtGLEnums.*;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class DebugFramebufferView {
|
||||
|
||||
public static boolean debugViewShown = false;
|
||||
private static long debugViewNameTimer = 0l;
|
||||
private static int currentDebugView = 0;
|
||||
|
||||
public static final List<DebugFramebufferView> views = Arrays.asList(
|
||||
(new DebugFramebufferView("GBuffer: Diffuse Color", (pipeline) -> {
|
||||
pipeline.useDebugViewShader(0);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.gBufferDiffuseTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("GBuffer: Normal Vectors", (pipeline) -> {
|
||||
PipelineShaderGBufferDebugView dbv = pipeline.useDebugViewShader(1);
|
||||
EaglerDeferredPipeline.uniformMatrixHelper(dbv.uniforms.u_inverseViewMatrix, DeferredStateManager.inverseViewMatrix);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.gBufferNormalsTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("GBuffer: Block/Sky Light Values", (pipeline) -> {
|
||||
pipeline.useDebugViewShader(2);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE1);
|
||||
GlStateManager.bindTexture(pipeline.gBufferNormalsTexture);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.gBufferDiffuseTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("GBuffer: Material Params (1)", (pipeline) -> {
|
||||
pipeline.useDebugViewShader(0);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.gBufferMaterialTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("GBuffer: Material Params (2)", (pipeline) -> {
|
||||
pipeline.useDebugViewShader(3);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.gBufferMaterialTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("GBuffer: Depth Buffer", (pipeline) -> {
|
||||
float depthStart = 0.001f;
|
||||
float depthScale = 25.0f;
|
||||
PipelineShaderGBufferDebugView dbv = pipeline.useDebugViewShader(4);
|
||||
_wglUniform2f(dbv.uniforms.u_depthSliceStartEnd2f, depthStart, depthScale);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.gBufferDepthTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Sun Shadow Depth: LOD 1", (pipeline) -> {
|
||||
if(pipeline.config.is_rendering_shadowsSun_clamped < 1) throw new NoDataException();
|
||||
PipelineShaderGBufferDebugView dbv = pipeline.useDebugViewShader(5);
|
||||
_wglUniform2f(dbv.uniforms.u_depthSliceStartEnd2f, 1.0f / pipeline.config.is_rendering_shadowsSun_clamped, 0.0f);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.sunShadowDepthBuffer);
|
||||
_wglTexParameteri(GL_TEXTURE_2D, _GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
_wglTexParameteri(GL_TEXTURE_2D, _GL_TEXTURE_COMPARE_MODE, _GL_COMPARE_REF_TO_TEXTURE);
|
||||
})),
|
||||
(new DebugFramebufferView("Sun Shadow Color: LOD 1", (pipeline) -> {
|
||||
if(pipeline.config.is_rendering_shadowsSun_clamped < 1 || !pipeline.config.is_rendering_shadowsColored) throw new NoDataException();
|
||||
PipelineShaderGBufferDebugView dbv = pipeline.useDebugViewShader(10);
|
||||
_wglUniform2f(dbv.uniforms.u_depthSliceStartEnd2f, 1.0f / pipeline.config.is_rendering_shadowsSun_clamped, 0.0f);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE1);
|
||||
GlStateManager.bindTexture(pipeline.sunShadowColorBuffer);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.sunShadowDepthBuffer);
|
||||
_wglTexParameteri(GL_TEXTURE_2D, _GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
_wglTexParameteri(GL_TEXTURE_2D, _GL_TEXTURE_COMPARE_MODE, _GL_COMPARE_REF_TO_TEXTURE);
|
||||
})),
|
||||
(new DebugFramebufferView("Sun Shadow Depth: LOD 2", (pipeline) -> {
|
||||
if(pipeline.config.is_rendering_shadowsSun_clamped < 2) throw new NoDataException();
|
||||
PipelineShaderGBufferDebugView dbv = pipeline.useDebugViewShader(5);
|
||||
_wglUniform2f(dbv.uniforms.u_depthSliceStartEnd2f, 1.0f / pipeline.config.is_rendering_shadowsSun_clamped, 1.0f);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.sunShadowDepthBuffer);
|
||||
_wglTexParameteri(GL_TEXTURE_2D, _GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
_wglTexParameteri(GL_TEXTURE_2D, _GL_TEXTURE_COMPARE_MODE, _GL_COMPARE_REF_TO_TEXTURE);
|
||||
})),
|
||||
(new DebugFramebufferView("Sun Shadow Color: LOD 2", (pipeline) -> {
|
||||
if(pipeline.config.is_rendering_shadowsSun_clamped < 2 || !pipeline.config.is_rendering_shadowsColored) throw new NoDataException();
|
||||
PipelineShaderGBufferDebugView dbv = pipeline.useDebugViewShader(10);
|
||||
_wglUniform2f(dbv.uniforms.u_depthSliceStartEnd2f, 1.0f / pipeline.config.is_rendering_shadowsSun_clamped, 1.0f);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE1);
|
||||
GlStateManager.bindTexture(pipeline.sunShadowColorBuffer);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.sunShadowDepthBuffer);
|
||||
_wglTexParameteri(GL_TEXTURE_2D, _GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
_wglTexParameteri(GL_TEXTURE_2D, _GL_TEXTURE_COMPARE_MODE, _GL_COMPARE_REF_TO_TEXTURE);
|
||||
})),
|
||||
(new DebugFramebufferView("Sun Shadow Depth: LOD 3", (pipeline) -> {
|
||||
if(pipeline.config.is_rendering_shadowsSun_clamped < 3) throw new NoDataException();
|
||||
PipelineShaderGBufferDebugView dbv = pipeline.useDebugViewShader(5);
|
||||
_wglUniform2f(dbv.uniforms.u_depthSliceStartEnd2f, 1.0f / pipeline.config.is_rendering_shadowsSun_clamped, 2.0f);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.sunShadowDepthBuffer);
|
||||
_wglTexParameteri(GL_TEXTURE_2D, _GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
_wglTexParameteri(GL_TEXTURE_2D, _GL_TEXTURE_COMPARE_MODE, _GL_COMPARE_REF_TO_TEXTURE);
|
||||
})),
|
||||
(new DebugFramebufferView("GBuffer Shadow Values", (pipeline) -> {
|
||||
if(pipeline.config.is_rendering_shadowsSun_clamped < 1) throw new NoDataException();
|
||||
if(pipeline.config.is_rendering_shadowsColored) {
|
||||
pipeline.useDebugViewShader(0);
|
||||
}else {
|
||||
pipeline.useDebugViewShader(6);
|
||||
}
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.sunLightingShadowTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Light Shafts Buffer", (pipeline) -> {
|
||||
if(!pipeline.config.is_rendering_lightShafts) throw new NoDataException();
|
||||
pipeline.useDebugViewShader(6);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.lightShaftsTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Forward Render Mask", (pipeline) -> {
|
||||
pipeline.useDebugViewShader(7);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.lightingHDRFramebufferColorTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Final HDR Color Buffer", (pipeline) -> {
|
||||
pipeline.useDebugViewShader(8);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.lightingHDRFramebufferColorTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Final Depth Buffer", (pipeline) -> {
|
||||
float depthStart = 0.001f;
|
||||
float depthScale = 25.0f;
|
||||
PipelineShaderGBufferDebugView dbv = pipeline.useDebugViewShader(4);
|
||||
_wglUniform2f(dbv.uniforms.u_depthSliceStartEnd2f, depthStart, depthScale);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.lightingHDRFramebufferDepthTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Last Frame Color Buffer", (pipeline) -> {
|
||||
if(!pipeline.reprojectionEngineEnable && !pipeline.config.is_rendering_realisticWater) throw new NoDataException();
|
||||
pipeline.useDebugViewShader(8);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.lastFrameColorTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Last Frame Depth Buffer", (pipeline) -> {
|
||||
if(!pipeline.reprojectionEngineEnable && !pipeline.config.is_rendering_realisticWater) throw new NoDataException();
|
||||
float depthStart = 0.001f;
|
||||
float depthScale = 25.0f;
|
||||
PipelineShaderGBufferDebugView dbv = pipeline.useDebugViewShader(4);
|
||||
_wglUniform2f(dbv.uniforms.u_depthSliceStartEnd2f, depthStart, depthScale);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.lastFrameDepthTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("SSAO: Raw GBuffer Samples", (pipeline) -> {
|
||||
if(!pipeline.config.is_rendering_ssao) throw new NoDataException();
|
||||
pipeline.useDebugViewShader(6);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.ssaoGenerateTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("SSAO: Reprojected Samples", (pipeline) -> {
|
||||
if(!pipeline.config.is_rendering_ssao) throw new NoDataException();
|
||||
pipeline.useDebugViewShader(9);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.reprojectionControlSSAOTexture[pipeline.reprojectionPhase]);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("SSAO: History Buffer", (pipeline) -> {
|
||||
if(!pipeline.config.is_rendering_ssao) throw new NoDataException();
|
||||
pipeline.useDebugViewShader(6);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.reprojectionControlSSAOTexture[pipeline.reprojectionPhase]);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("SSR: Reflection Buffer", (pipeline) -> {
|
||||
if(!pipeline.config.is_rendering_raytracing) throw new NoDataException();
|
||||
pipeline.useDebugViewShader(8);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.reprojectionSSRTexture[1]);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("SSR: Reflection Traces", (pipeline) -> {
|
||||
if(!pipeline.config.is_rendering_raytracing) throw new NoDataException();
|
||||
pipeline.useDebugViewShader(11);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.reprojectionSSRTexture[1]);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("SSR: Reflection Hit Vectors", (pipeline) -> {
|
||||
if(!pipeline.config.is_rendering_raytracing) throw new NoDataException();
|
||||
pipeline.useDebugViewShader(12);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.reprojectionSSRHitVector[1]);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("SSR: Reflection Hit Mask", (pipeline) -> {
|
||||
if(!pipeline.config.is_rendering_raytracing) throw new NoDataException();
|
||||
pipeline.useDebugViewShader(13);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.reprojectionSSRHitVector[1]);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("SSR: History Buffer", (pipeline) -> {
|
||||
if(!pipeline.config.is_rendering_raytracing) throw new NoDataException();
|
||||
pipeline.useDebugViewShader(11);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.reprojectionSSRHitVector[1]);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Clouds 3D Noise Map", (pipeline) -> {
|
||||
PipelineShaderGBufferDebugView dbg = pipeline.useDebugViewShader(18);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture3D(CloudRenderWorker.cloud3DSamplesTexture);
|
||||
_wglUniform1f(_wglGetUniformLocation(dbg.program, "u_fuckU1f"), (float)((System.currentTimeMillis() % 5000l) / 5000.0));
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Clouds Back Buffer", (pipeline) -> {
|
||||
pipeline.useDebugViewShader(0);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(CloudRenderWorker.cloudNoiseSampleParaboloidTexture[CloudRenderWorker.cloudRenderPhase]);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Clouds Front Buffer", (pipeline) -> {
|
||||
pipeline.useDebugViewShader(0);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
CloudRenderWorker.bindParaboloid();
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Cached Atmosphere Colors", (pipeline) -> {
|
||||
pipeline.useDebugViewShader(8);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.atmosphereHDRFramebufferColorTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Dual Paraboloid Map: Atmosphere", (pipeline) -> {
|
||||
pipeline.useDebugViewShader(14);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.envMapAtmosphereTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Dual Paraboloid Map: Skybox", (pipeline) -> {
|
||||
pipeline.useDebugViewShader(14);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.envMapSkyTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Dual Paraboloid Map: Terrain", (pipeline) -> {
|
||||
if(!pipeline.config.is_rendering_useEnvMap) throw new NoDataException();
|
||||
pipeline.useDebugViewShader(14);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.envMapColorTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Dual Paraboloid Map: Mask", (pipeline) -> {
|
||||
if(!pipeline.config.is_rendering_useEnvMap) throw new NoDataException();
|
||||
pipeline.useDebugViewShader(15);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.envMapColorTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Skybox Irradiance Map", (pipeline) -> {
|
||||
pipeline.useDebugViewShader(14);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.skyIrradianceTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Atmosphere Irradiance Map", (pipeline) -> {
|
||||
pipeline.useDebugViewShader(14);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.atmosphereIrradianceTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Water: Surface Normals", (pipeline) -> {
|
||||
if(!pipeline.config.is_rendering_realisticWater) throw new NoDataException();
|
||||
PipelineShaderGBufferDebugView dbv = pipeline.useDebugViewShader(1);
|
||||
EaglerDeferredPipeline.uniformMatrixHelper(dbv.uniforms.u_inverseViewMatrix, DeferredStateManager.inverseViewMatrix);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.realisticWaterMaskTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Water: Surface Depth", (pipeline) -> {
|
||||
if(!pipeline.config.is_rendering_realisticWater) throw new NoDataException();
|
||||
float depthStart = 0.001f;
|
||||
float depthScale = 25.0f;
|
||||
PipelineShaderGBufferDebugView dbv = pipeline.useDebugViewShader(4);
|
||||
_wglUniform2f(dbv.uniforms.u_depthSliceStartEnd2f, depthStart, depthScale);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.realisticWaterDepthBuffer);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Water: Distortion Map", (pipeline) -> {
|
||||
if(!pipeline.config.is_rendering_realisticWater) throw new NoDataException();
|
||||
pipeline.useDebugViewShader(16);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.realisticWaterNormalMapTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Water: Refraction Buffer", (pipeline) -> {
|
||||
if(!pipeline.config.is_rendering_realisticWater) throw new NoDataException();
|
||||
pipeline.useDebugViewShader(8);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.realisticWaterRefractionTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Water: SSR Reflect Buffer", (pipeline) -> {
|
||||
if(!pipeline.config.is_rendering_realisticWater) throw new NoDataException();
|
||||
pipeline.useDebugViewShader(8);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.realisticWaterControlReflectionTexture[1]);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Water: SSR Reflect Traces", (pipeline) -> {
|
||||
if(!pipeline.config.is_rendering_realisticWater) throw new NoDataException();
|
||||
pipeline.useDebugViewShader(11);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.realisticWaterControlReflectionTexture[1]);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Water: SSR Reflect Hit Vectors", (pipeline) -> {
|
||||
if(!pipeline.config.is_rendering_realisticWater) throw new NoDataException();
|
||||
pipeline.useDebugViewShader(12);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.realisticWaterControlHitVectorTexture[1]);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Water: SSR Reflect Hit Mask", (pipeline) -> {
|
||||
if(!pipeline.config.is_rendering_realisticWater) throw new NoDataException();
|
||||
pipeline.useDebugViewShader(13);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.realisticWaterControlHitVectorTexture[1]);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Water: SSR Reflect History", (pipeline) -> {
|
||||
if(!pipeline.config.is_rendering_realisticWater) throw new NoDataException();
|
||||
pipeline.useDebugViewShader(11);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.realisticWaterControlHitVectorTexture[1]);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Exposure Average -2", (pipeline) -> {
|
||||
pipeline.useDebugViewShader(17);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.lumaAvgDownscaleTexture[pipeline.lumaAvgDownscaleFramebuffers.length - 2]);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Exposure Average -1", (pipeline) -> {
|
||||
pipeline.useDebugViewShader(17);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.lumaAvgDownscaleTexture[pipeline.lumaAvgDownscaleFramebuffers.length - 1]);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Dynamic Exposure Value", (pipeline) -> {
|
||||
pipeline.useDebugViewShader(17);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.exposureBlendTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Bloom Bright Pass", (pipeline) -> {
|
||||
if(!pipeline.config.is_rendering_bloom) throw new NoDataException();
|
||||
pipeline.useDebugViewShader(8);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.bloomBrightPassTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Bloom Horz. Blur", (pipeline) -> {
|
||||
if(!pipeline.config.is_rendering_bloom) throw new NoDataException();
|
||||
pipeline.useDebugViewShader(8);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.bloomHBlurTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Bloom Vert. Blur", (pipeline) -> {
|
||||
if(!pipeline.config.is_rendering_bloom) throw new NoDataException();
|
||||
pipeline.useDebugViewShader(8);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.bloomVBlurTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Sun Occlusion: World", (pipeline) -> {
|
||||
pipeline.useDebugViewShader(6);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(CloudRenderWorker.cloudOcclusionTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("Sun Occlusion: Screen", (pipeline) -> {
|
||||
pipeline.useDebugViewShader(6);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.sunOcclusionValueTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
})),
|
||||
(new DebugFramebufferView("FXAA Luma Values", (pipeline) -> {
|
||||
if(!pipeline.config.is_rendering_fxaa) throw new NoDataException();
|
||||
pipeline.useDebugViewShader(6);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(pipeline.tonemapOutputTexture);
|
||||
DrawUtils.drawStandardQuad2D();
|
||||
}))
|
||||
);
|
||||
|
||||
private static class NoDataException extends RuntimeException {
|
||||
}
|
||||
|
||||
public static void renderDebugView() {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
boolean noData = false;
|
||||
DebugFramebufferView view = views.get(currentDebugView);
|
||||
try {
|
||||
view.renderHandler.accept(EaglerDeferredPipeline.instance);
|
||||
}catch(NoDataException ex) {
|
||||
GlStateManager.clearColor(0.0f, 0.0f, 0.1f, 0.0f);
|
||||
GlStateManager.clear(GL_COLOR_BUFFER_BIT);
|
||||
noData = true;
|
||||
}
|
||||
long millis = System.currentTimeMillis();
|
||||
long elapsed = millis - debugViewNameTimer;
|
||||
if(elapsed < 2000l || noData) {
|
||||
GlStateManager.matrixMode(GL_PROJECTION);
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.matrixMode(GL_MODELVIEW);
|
||||
GlStateManager.pushMatrix();
|
||||
ScaledResolution scaledresolution = new ScaledResolution(mc);
|
||||
int w = scaledresolution.getScaledWidth();
|
||||
mc.entityRenderer.setupOverlayRendering();
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
int h = scaledresolution.getScaledHeight() / 2;
|
||||
|
||||
if(noData) {
|
||||
String noDataTxt = "No Data";
|
||||
mc.entityRenderer.setupOverlayRendering();
|
||||
int viewNameWidth = mc.fontRendererObj.getStringWidth(noDataTxt) * 2;
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate((w - viewNameWidth) * 0.5f, h - 70.0f, 0.0f);
|
||||
GlStateManager.scale(2.0f, 2.0f, 2.0f);
|
||||
mc.fontRendererObj.drawStringWithShadow(noDataTxt, 0, 0, 0xFFFFFFFF);
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
if(elapsed < 2000l) {
|
||||
for(int i = 0; i < 9; ++i) {
|
||||
int i2 = currentDebugView - 4 + i;
|
||||
if(i2 >= 0 && i2 < views.size()) {
|
||||
String str = views.get(i2).name;
|
||||
int j = mc.fontRendererObj.getStringWidth(str);
|
||||
float alphaF = ((i == 0 || i == 8) ? 0.25f : ((i == 1 || i == 7) ? 0.65f : 1.0f));
|
||||
int x = 5;
|
||||
if(elapsed > 1800l) {
|
||||
x -= (int)(elapsed - 1800l);
|
||||
alphaF *= (1.0f - (float)(elapsed - 1800l) / 190.0f);
|
||||
}
|
||||
int y = h + (i - 5) * 11;
|
||||
Gui.drawRect(x, y, x + j + 2, y + 10, (int)(alphaF * 127.0f) << 24);
|
||||
mc.fontRendererObj.drawStringWithShadow(str, x + 1, y + 1, (i == 4 ? 0xFFFF00 : 0xFFFFFF) | ((int)(alphaF * 255.0f) << 24));
|
||||
}
|
||||
}
|
||||
|
||||
mc.fontRendererObj.drawStringWithShadow("Use arrow keys to select framebuffers", 5, 23, 0xFFFFFF);
|
||||
mc.fontRendererObj.drawStringWithShadow("Press F+4 to exit", 5, 33, 0xFFFFFF);
|
||||
}
|
||||
|
||||
GlStateManager.disableBlend();
|
||||
GlStateManager.matrixMode(GL_PROJECTION);
|
||||
GlStateManager.popMatrix();
|
||||
GlStateManager.matrixMode(GL_MODELVIEW);
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
public static void toggleDebugView() {
|
||||
debugViewShown = !debugViewShown;
|
||||
if(debugViewShown) {
|
||||
debugViewNameTimer = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
public static void switchView(int dir) {
|
||||
if(!debugViewShown) return;
|
||||
debugViewNameTimer = System.currentTimeMillis();
|
||||
currentDebugView += dir;
|
||||
if(currentDebugView < 0) currentDebugView = views.size() - 1;
|
||||
if(currentDebugView >= views.size()) currentDebugView = 0;
|
||||
}
|
||||
|
||||
protected final String name;
|
||||
protected final Consumer<EaglerDeferredPipeline> renderHandler;
|
||||
|
||||
protected DebugFramebufferView(String name, Consumer<EaglerDeferredPipeline> renderHandler) {
|
||||
this.name = name;
|
||||
this.renderHandler = renderHandler;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,496 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.GlStateManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.vector.Matrix4f;
|
||||
import net.lax1dude.eaglercraft.v1_8.vector.Vector3f;
|
||||
import net.lax1dude.eaglercraft.v1_8.vector.Vector4f;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.MathHelper;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.EaglercraftGPU;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class DeferredStateManager {
|
||||
|
||||
public static float sunAngle = 45.0f; // realistic: 23.5f
|
||||
|
||||
static boolean enableMaterialMapTexture = false;
|
||||
static boolean enableForwardRender = false;
|
||||
static boolean enableParaboloidRender = false;
|
||||
static boolean enableShadowRender = false;
|
||||
static boolean enableClipPlane = false;
|
||||
static boolean enableDrawWavingBlocks = false;
|
||||
static boolean enableDrawRealisticWaterMask = false;
|
||||
static boolean enableDrawRealisticWaterRender = false;
|
||||
static boolean enableDrawGlassHighlightsRender = false;
|
||||
|
||||
static int materialConstantsSerial = 0;
|
||||
static float materialConstantsRoughness = 0.5f;
|
||||
static float materialConstantsMetalness = 0.02f;
|
||||
static float materialConstantsEmission = 0.0f;
|
||||
static boolean materialConstantsUseEnvMap = false;
|
||||
|
||||
static int wavingBlockOffsetSerial = 0;
|
||||
static float wavingBlockOffsetX = 0.0f;
|
||||
static float wavingBlockOffsetY = 0.0f;
|
||||
static float wavingBlockOffsetZ = 0.0f;
|
||||
|
||||
static int wavingBlockParamSerial = 0;
|
||||
static float wavingBlockParamX = 0.0f;
|
||||
static float wavingBlockParamY = 0.0f;
|
||||
static float wavingBlockParamZ = 0.0f;
|
||||
static float wavingBlockParamW = 0.0f;
|
||||
|
||||
static int constantBlock = 0;
|
||||
|
||||
static float clipPlaneY = 0.0f;
|
||||
|
||||
static AxisAlignedBB shadowMapBounds = new AxisAlignedBB(-1, -1, -1, 1, 1, 1);
|
||||
|
||||
static float gbufferNearPlane = 0.01f;
|
||||
static float gbufferFarPlane = 128.0f;
|
||||
|
||||
static final Vector3f currentSunAngle = new Vector3f();
|
||||
static final Vector3f currentSunLightAngle = new Vector3f();
|
||||
static final Vector3f currentSunLightColor = new Vector3f();
|
||||
|
||||
static int waterWindOffsetSerial = 0;
|
||||
static final Vector4f u_waterWindOffset4f = new Vector4f();
|
||||
|
||||
private static final float[] matrixCopyBuffer = new float[16];
|
||||
static int viewMatrixSerial = -1;
|
||||
static int projMatrixSerial = -1;
|
||||
static int passViewMatrixSerial = -1;
|
||||
static int passProjMatrixSerial = -1;
|
||||
static boolean isShadowPassMatrixLoaded = false;
|
||||
static final Matrix4f viewMatrix = new Matrix4f();
|
||||
static final Matrix4f projMatrix = new Matrix4f();
|
||||
static final Matrix4f inverseViewMatrix = new Matrix4f();
|
||||
static final Matrix4f inverseProjMatrix = new Matrix4f();
|
||||
static final Matrix4f passViewMatrix = new Matrix4f();
|
||||
static final Matrix4f passProjMatrix = new Matrix4f();
|
||||
static final Matrix4f passInverseViewMatrix = new Matrix4f();
|
||||
static final Matrix4f passInverseProjMatrix = new Matrix4f();
|
||||
static final Matrix4f sunShadowMatrix0 = new Matrix4f();
|
||||
static final Matrix4f sunShadowMatrix1 = new Matrix4f();
|
||||
static final Matrix4f sunShadowMatrix2 = new Matrix4f();
|
||||
static final BetterFrustum currentGBufferFrustum = new BetterFrustum();
|
||||
static final Matrix4f paraboloidTopViewMatrix = new Matrix4f().rotate(-1.57f, new Vector3f(1.0f, 0.0f, 0.0f));
|
||||
static final Matrix4f paraboloidBottomViewMatrix = new Matrix4f().rotate(1.57f, new Vector3f(1.0f, 0.0f, 0.0f));
|
||||
|
||||
public static ForwardRenderCallbackHandler forwardCallbackHandler = null;
|
||||
|
||||
public static final ForwardRenderCallbackHandler forwardCallbackGBuffer = new ForwardRenderCallbackHandler();
|
||||
public static final ForwardRenderCallbackHandler forwardCallbackSun = new ForwardRenderCallbackHandler();
|
||||
|
||||
public static boolean doCheckErrors = false;
|
||||
|
||||
public static final boolean isDeferredRenderer() {
|
||||
return EaglerDeferredPipeline.instance != null;
|
||||
}
|
||||
|
||||
public static final boolean isInDeferredPass() {
|
||||
return GlStateManager.isExtensionPipeline();
|
||||
}
|
||||
|
||||
public static final boolean isInForwardPass() {
|
||||
return enableForwardRender && !enableShadowRender;
|
||||
}
|
||||
|
||||
public static final boolean isInParaboloidPass() {
|
||||
return enableParaboloidRender;
|
||||
}
|
||||
|
||||
public static final boolean isRenderingRealisticWater() {
|
||||
return EaglerDeferredPipeline.instance != null && EaglerDeferredPipeline.instance.config.is_rendering_realisticWater;
|
||||
}
|
||||
|
||||
public static final boolean isRenderingGlassHighlights() {
|
||||
return EaglerDeferredPipeline.instance != null && EaglerDeferredPipeline.instance.config.is_rendering_useEnvMap;
|
||||
}
|
||||
|
||||
public static final void setDefaultMaterialConstants() {
|
||||
materialConstantsRoughness = 0.5f;
|
||||
materialConstantsMetalness = 0.02f;
|
||||
materialConstantsEmission = 0.0f;
|
||||
++materialConstantsSerial;
|
||||
}
|
||||
|
||||
public static final void startUsingEnvMap() {
|
||||
materialConstantsUseEnvMap = true;
|
||||
}
|
||||
|
||||
public static final void endUsingEnvMap() {
|
||||
materialConstantsUseEnvMap = false;
|
||||
}
|
||||
|
||||
public static final void reportForwardRenderObjectPosition(int centerX, int centerY, int centerZ) {
|
||||
EaglerDeferredPipeline instance = EaglerDeferredPipeline.instance;
|
||||
if(instance != null && enableForwardRender) {
|
||||
EaglerDeferredConfig cfg = instance.config;
|
||||
if(!cfg.is_rendering_dynamicLights || !cfg.shaderPackInfo.DYNAMIC_LIGHTS) {
|
||||
return;
|
||||
}
|
||||
instance.loadLightSourceBucket(centerX, centerY, centerZ);
|
||||
}
|
||||
}
|
||||
|
||||
public static final void reportForwardRenderObjectPosition2(float x, float y, float z) {
|
||||
float posX = (float)((x + TileEntityRendererDispatcher.staticPlayerX) - (MathHelper.floor_double(TileEntityRendererDispatcher.staticPlayerX / 16.0) << 4));
|
||||
float posY = (float)((y + TileEntityRendererDispatcher.staticPlayerY) - (MathHelper.floor_double(TileEntityRendererDispatcher.staticPlayerY / 16.0) << 4));
|
||||
float posZ = (float)((z + TileEntityRendererDispatcher.staticPlayerZ) - (MathHelper.floor_double(TileEntityRendererDispatcher.staticPlayerZ / 16.0) << 4));
|
||||
reportForwardRenderObjectPosition((int)posX, (int)posY, (int)posZ);
|
||||
}
|
||||
|
||||
public static final void setHDRTranslucentPassBlendFunc() {
|
||||
GlStateManager.tryBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ZERO);
|
||||
}
|
||||
|
||||
public static final void enableMaterialTexture() {
|
||||
enableMaterialMapTexture = true;
|
||||
}
|
||||
|
||||
public static final void disableMaterialTexture() {
|
||||
enableMaterialMapTexture = false;
|
||||
}
|
||||
|
||||
public static final void enableForwardRender() {
|
||||
enableForwardRender = true;
|
||||
}
|
||||
|
||||
public static final void disableForwardRender() {
|
||||
enableForwardRender = false;
|
||||
}
|
||||
|
||||
public static final void enableParaboloidRender() {
|
||||
enableParaboloidRender = true;
|
||||
}
|
||||
|
||||
public static final void disableParaboloidRender() {
|
||||
enableParaboloidRender = false;
|
||||
}
|
||||
|
||||
public static final void enableShadowRender() {
|
||||
enableShadowRender = true;
|
||||
}
|
||||
|
||||
public static final void disableShadowRender() {
|
||||
enableShadowRender = false;
|
||||
}
|
||||
|
||||
public static final boolean isEnableShadowRender() {
|
||||
return enableShadowRender;
|
||||
}
|
||||
|
||||
public static final void enableClipPlane() {
|
||||
enableClipPlane = true;
|
||||
}
|
||||
|
||||
public static final void disableClipPlane() {
|
||||
enableClipPlane = false;
|
||||
}
|
||||
|
||||
public static final void setClipPlaneY(float yValue) {
|
||||
clipPlaneY = yValue;
|
||||
}
|
||||
|
||||
public static final void enableDrawWavingBlocks() {
|
||||
enableDrawWavingBlocks = true;
|
||||
}
|
||||
|
||||
public static final void disableDrawWavingBlocks() {
|
||||
enableDrawWavingBlocks = false;
|
||||
}
|
||||
|
||||
public static final boolean isEnableDrawWavingBlocks() {
|
||||
return enableDrawWavingBlocks;
|
||||
}
|
||||
|
||||
public static final void enableDrawRealisticWaterMask() {
|
||||
enableDrawRealisticWaterMask = true;
|
||||
}
|
||||
|
||||
public static final void disableDrawRealisticWaterMask() {
|
||||
enableDrawRealisticWaterMask = false;
|
||||
}
|
||||
|
||||
public static final boolean isDrawRealisticWaterMask() {
|
||||
return enableDrawRealisticWaterMask;
|
||||
}
|
||||
|
||||
public static final void enableDrawRealisticWaterRender() {
|
||||
enableDrawRealisticWaterRender = true;
|
||||
}
|
||||
|
||||
public static final void disableDrawRealisticWaterRender() {
|
||||
enableDrawRealisticWaterRender = false;
|
||||
}
|
||||
|
||||
public static final boolean isDrawRealisticWaterRender() {
|
||||
return enableDrawRealisticWaterRender;
|
||||
}
|
||||
|
||||
public static final void enableDrawGlassHighlightsRender() {
|
||||
enableDrawGlassHighlightsRender = true;
|
||||
}
|
||||
|
||||
public static final void disableDrawGlassHighlightsRender() {
|
||||
enableDrawGlassHighlightsRender = false;
|
||||
}
|
||||
|
||||
public static final boolean isDrawGlassHighlightsRender() {
|
||||
return enableDrawGlassHighlightsRender;
|
||||
}
|
||||
|
||||
public static final void setWavingBlockOffset(float x, float y, float z) {
|
||||
wavingBlockOffsetX = x;
|
||||
wavingBlockOffsetY = y;
|
||||
wavingBlockOffsetZ = z;
|
||||
++wavingBlockOffsetSerial;
|
||||
}
|
||||
|
||||
public static final void setWavingBlockParams(float x, float y, float z, float w) {
|
||||
wavingBlockParamX = x;
|
||||
wavingBlockParamY = y;
|
||||
wavingBlockParamZ = z;
|
||||
wavingBlockParamW = w;
|
||||
++wavingBlockParamSerial;
|
||||
}
|
||||
|
||||
public static final void setRoughnessConstant(float roughness) {
|
||||
materialConstantsRoughness = roughness;
|
||||
++materialConstantsSerial;
|
||||
}
|
||||
|
||||
public static final void setMetalnessConstant(float metalness) {
|
||||
materialConstantsMetalness = metalness;
|
||||
++materialConstantsSerial;
|
||||
}
|
||||
|
||||
public static final void setEmissionConstant(float emission) {
|
||||
materialConstantsEmission = emission;
|
||||
++materialConstantsSerial;
|
||||
}
|
||||
|
||||
public static final void setBlockConstant(int blockId) {
|
||||
constantBlock = blockId;
|
||||
}
|
||||
|
||||
public static final AxisAlignedBB getShadowMapBounds() {
|
||||
return shadowMapBounds;
|
||||
}
|
||||
|
||||
public static final void setShadowMapBounds(AxisAlignedBB newShadowMapBounds) {
|
||||
shadowMapBounds = newShadowMapBounds;
|
||||
}
|
||||
|
||||
public static final void loadGBufferViewMatrix() {
|
||||
loadPassViewMatrix();
|
||||
viewMatrix.load(passViewMatrix);
|
||||
inverseViewMatrix.load(passInverseViewMatrix);
|
||||
viewMatrixSerial = passViewMatrixSerial;
|
||||
}
|
||||
|
||||
public static void loadGBufferProjectionMatrix() {
|
||||
loadPassProjectionMatrix();
|
||||
projMatrix.load(passProjMatrix);
|
||||
inverseProjMatrix.load(passInverseProjMatrix);
|
||||
projMatrixSerial = passProjMatrixSerial;
|
||||
}
|
||||
|
||||
public static final void loadPassViewMatrix() {
|
||||
GlStateManager.getFloat(GL_MODELVIEW_MATRIX, matrixCopyBuffer);
|
||||
passViewMatrix.load(matrixCopyBuffer);
|
||||
Matrix4f.invert(passViewMatrix, passInverseViewMatrix);
|
||||
++passViewMatrixSerial;
|
||||
isShadowPassMatrixLoaded = false;
|
||||
}
|
||||
|
||||
public static void loadPassProjectionMatrix() {
|
||||
GlStateManager.getFloat(GL_PROJECTION_MATRIX, matrixCopyBuffer);
|
||||
passProjMatrix.load(matrixCopyBuffer);
|
||||
Matrix4f.invert(passProjMatrix, passInverseProjMatrix);
|
||||
++passProjMatrixSerial;
|
||||
}
|
||||
|
||||
public static final void loadShadowPassViewMatrix() {
|
||||
GlStateManager.getFloat(GL_PROJECTION_MATRIX, matrixCopyBuffer);
|
||||
passViewMatrix.load(matrixCopyBuffer);
|
||||
Matrix4f.invert(passViewMatrix, passInverseViewMatrix);
|
||||
passProjMatrix.setIdentity();
|
||||
++passViewMatrixSerial;
|
||||
isShadowPassMatrixLoaded = true;
|
||||
}
|
||||
|
||||
public static final void setPassMatrixToGBuffer() {
|
||||
passViewMatrix.load(viewMatrix);
|
||||
passInverseViewMatrix.load(inverseViewMatrix);
|
||||
passProjMatrix.load(projMatrix);
|
||||
passInverseProjMatrix.load(inverseProjMatrix);
|
||||
++passViewMatrixSerial;
|
||||
++passProjMatrixSerial;
|
||||
}
|
||||
|
||||
public static void setCurrentSunAngle(Vector3f vec) {
|
||||
currentSunAngle.set(vec);
|
||||
if(vec.y > 0.05f) {
|
||||
currentSunLightAngle.x = -vec.x;
|
||||
currentSunLightAngle.y = -vec.y;
|
||||
currentSunLightAngle.z = -vec.z;
|
||||
}else {
|
||||
currentSunLightAngle.set(vec);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setCurrentSunAngle(Vector4f vec) {
|
||||
currentSunAngle.set(vec);
|
||||
if(vec.y > 0.05f) {
|
||||
currentSunLightAngle.x = -vec.x;
|
||||
currentSunLightAngle.y = -vec.y;
|
||||
currentSunLightAngle.z = -vec.z;
|
||||
}else {
|
||||
currentSunLightAngle.set(vec);
|
||||
}
|
||||
}
|
||||
|
||||
public static final void loadSunShadowMatrixLOD0() {
|
||||
GlStateManager.getFloat(GL_PROJECTION_MATRIX, matrixCopyBuffer);
|
||||
sunShadowMatrix0.load(matrixCopyBuffer);
|
||||
}
|
||||
|
||||
public static final void loadSunShadowMatrixLOD1() {
|
||||
GlStateManager.getFloat(GL_PROJECTION_MATRIX, matrixCopyBuffer);
|
||||
sunShadowMatrix1.load(matrixCopyBuffer);
|
||||
}
|
||||
|
||||
public static final void loadSunShadowMatrixLOD2() {
|
||||
GlStateManager.getFloat(GL_PROJECTION_MATRIX, matrixCopyBuffer);
|
||||
sunShadowMatrix2.load(matrixCopyBuffer);
|
||||
}
|
||||
|
||||
public static final Matrix4f getSunShadowMatrixLOD0() {
|
||||
return sunShadowMatrix0;
|
||||
}
|
||||
|
||||
public static final Matrix4f getSunShadowMatrixLOD1() {
|
||||
return sunShadowMatrix1;
|
||||
}
|
||||
|
||||
public static final Matrix4f getSunShadowMatrixLOD2() {
|
||||
return sunShadowMatrix2;
|
||||
}
|
||||
|
||||
public static final void setGBufferNearFarPlanes(float zNear, float zFar) {
|
||||
gbufferNearPlane = zNear;
|
||||
gbufferFarPlane = zFar;
|
||||
}
|
||||
|
||||
public static final void setWaterWindOffset(float sx, float sy, float fx, float fy) {
|
||||
++waterWindOffsetSerial;
|
||||
u_waterWindOffset4f.x = sx;
|
||||
u_waterWindOffset4f.y = sy;
|
||||
u_waterWindOffset4f.z = fx;
|
||||
u_waterWindOffset4f.w = fy;
|
||||
}
|
||||
|
||||
static int fogLinearExp = 0;
|
||||
|
||||
static float fogNear = 0.0f;
|
||||
static float fogFar = 100.0f;
|
||||
|
||||
static float fogDensity = 0.0f;
|
||||
|
||||
static float fogColorLightR = 1.0f;
|
||||
static float fogColorLightG = 1.0f;
|
||||
static float fogColorLightB = 1.0f;
|
||||
static float fogColorLightA = 1.0f;
|
||||
|
||||
static float fogColorDarkR = 1.0f;
|
||||
static float fogColorDarkG = 1.0f;
|
||||
static float fogColorDarkB = 1.0f;
|
||||
static float fogColorDarkA = 1.0f;
|
||||
|
||||
public static final void enableFogLinear(float near, float far, boolean atmosphere, float colorLightR,
|
||||
float colorLightG, float colorLightB, float colorLightA, float colorDarkR, float colorDarkG,
|
||||
float colorDarkB, float colorDarkA) {
|
||||
fogLinearExp = atmosphere ? 5 : 1;
|
||||
fogNear = near;
|
||||
fogFar = far;
|
||||
fogColorLightR = colorLightR;
|
||||
fogColorLightG = colorLightG;
|
||||
fogColorLightB = colorLightB;
|
||||
fogColorLightA = colorLightA;
|
||||
fogColorDarkR = colorDarkR;
|
||||
fogColorDarkG = colorDarkG;
|
||||
fogColorDarkB = colorDarkB;
|
||||
fogColorDarkA = colorDarkA;
|
||||
}
|
||||
|
||||
public static final void enableFogExp(float density, boolean atmosphere, float colorLightR, float colorLightG,
|
||||
float colorLightB, float colorLightA, float colorDarkR, float colorDarkG, float colorDarkB,
|
||||
float colorDarkA) {
|
||||
fogLinearExp = atmosphere ? 6 : 2;
|
||||
fogDensity = density;
|
||||
fogColorLightR = colorLightR;
|
||||
fogColorLightG = colorLightG;
|
||||
fogColorLightB = colorLightB;
|
||||
fogColorLightA = colorLightA;
|
||||
fogColorDarkR = colorDarkR;
|
||||
fogColorDarkG = colorDarkG;
|
||||
fogColorDarkB = colorDarkB;
|
||||
fogColorDarkA = colorDarkA;
|
||||
}
|
||||
|
||||
public static final void disableFog() {
|
||||
fogLinearExp = 0;
|
||||
}
|
||||
|
||||
public static final void disableAll() {
|
||||
enableMaterialMapTexture = false;
|
||||
materialConstantsUseEnvMap = false;
|
||||
enableForwardRender = false;
|
||||
enableParaboloidRender = false;
|
||||
enableShadowRender = false;
|
||||
enableClipPlane = false;
|
||||
enableDrawWavingBlocks = false;
|
||||
fogLinearExp = 0;
|
||||
fogNear = 0.0f;
|
||||
fogFar = 100.0f;
|
||||
forwardCallbackHandler = null;
|
||||
}
|
||||
|
||||
public static float getSunHeight() {
|
||||
return -currentSunAngle.y;
|
||||
}
|
||||
|
||||
public static void checkGLError(String section) {
|
||||
if(!doCheckErrors) {
|
||||
return;
|
||||
}
|
||||
int i = EaglercraftGPU.glGetError();
|
||||
if(i != 0) {
|
||||
EaglerDeferredPipeline.logger.error("########## GL ERROR ##########");
|
||||
EaglerDeferredPipeline.logger.error("@ {}", section);
|
||||
do {
|
||||
EaglerDeferredPipeline.logger.error("#{} - {}", i, EaglercraftGPU.gluErrorString(i));
|
||||
}while((i = EaglercraftGPU.glGetError()) != 0);
|
||||
EaglerDeferredPipeline.logger.error("##############################");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
class DynamicLightInstance {
|
||||
|
||||
public final String lightName;
|
||||
public final boolean shadow;
|
||||
long lastCacheHit = 0l;
|
||||
|
||||
double posX;
|
||||
double posY;
|
||||
double posZ;
|
||||
float red;
|
||||
float green;
|
||||
float blue;
|
||||
float radius;
|
||||
|
||||
public DynamicLightInstance(String lightName, boolean shadow) {
|
||||
this.lightName = lightName;
|
||||
this.shadow = shadow;
|
||||
}
|
||||
|
||||
public void updateLight(double posX, double posY, double posZ, float red, float green, float blue) {
|
||||
this.lastCacheHit = System.currentTimeMillis();
|
||||
this.posX = posX;
|
||||
this.posY = posY;
|
||||
this.posZ = posZ;
|
||||
this.red = red;
|
||||
this.green = green;
|
||||
this.blue = blue;
|
||||
this.radius = (float)(Math.sqrt(red + green + blue) * 3.0 + 0.5);
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
|
||||
}
|
||||
|
||||
public float getRadiusInWorld() {
|
||||
return radius;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class DynamicLightManager {
|
||||
|
||||
static final Map<String, DynamicLightInstance> lightRenderers = new HashMap();
|
||||
static final List<DynamicLightInstance> lightRenderList = new LinkedList();
|
||||
static long renderTimeout = 5000l;
|
||||
static boolean isRenderLightsPass = false;
|
||||
|
||||
private static long lastTick = 0l;
|
||||
|
||||
public static void renderDynamicLight(String lightName, double posX, double posY, double posZ, float red,
|
||||
float green, float blue, boolean shadows) {
|
||||
if(isRenderLightsPass) {
|
||||
DynamicLightInstance dl = lightRenderers.get(lightName);
|
||||
if(dl == null) {
|
||||
lightRenderers.put(lightName, dl = new DynamicLightInstance(lightName, shadows));
|
||||
}
|
||||
dl.updateLight(posX, posY, posZ, red, green, blue);
|
||||
lightRenderList.add(dl);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isRenderingLights() {
|
||||
return isRenderLightsPass;
|
||||
}
|
||||
|
||||
public static void setIsRenderingLights(boolean b) {
|
||||
isRenderLightsPass = b;
|
||||
}
|
||||
|
||||
static void updateTimers() {
|
||||
long millis = System.currentTimeMillis();
|
||||
if(millis - lastTick > 1000l) {
|
||||
lastTick = millis;
|
||||
Iterator<DynamicLightInstance> itr = lightRenderers.values().iterator();
|
||||
while(itr.hasNext()) {
|
||||
DynamicLightInstance dl = itr.next();
|
||||
if(millis - dl.lastCacheHit > renderTimeout) {
|
||||
dl.destroy();
|
||||
itr.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void destroyAll() {
|
||||
Iterator<DynamicLightInstance> itr = lightRenderers.values().iterator();
|
||||
while(itr.hasNext()) {
|
||||
itr.next().destroy();
|
||||
}
|
||||
lightRenderers.clear();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,161 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.EaglerInputStream;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class EaglerDeferredConfig {
|
||||
|
||||
public static final ResourceLocation shaderPackInfoFile = new ResourceLocation("eagler:glsl/deferred/shader_pack_info.json");
|
||||
|
||||
public ShaderPackInfo shaderPackInfo = null;
|
||||
|
||||
public boolean wavingBlocks = true;
|
||||
public boolean dynamicLights = true;
|
||||
public boolean ssao = true;
|
||||
public int shadowsSun = 3;
|
||||
public boolean shadowsColored = false;
|
||||
public boolean shadowsSmoothed = true;
|
||||
public boolean useEnvMap = true;
|
||||
public boolean realisticWater = true;
|
||||
public boolean lightShafts = false;
|
||||
public boolean raytracing = true;
|
||||
public boolean lensDistortion = false;
|
||||
public boolean lensFlares = true;
|
||||
public boolean bloom = false;
|
||||
public boolean fxaa = true;
|
||||
|
||||
public boolean is_rendering_wavingBlocks = true;
|
||||
public boolean is_rendering_dynamicLights = true;
|
||||
public boolean is_rendering_ssao = true;
|
||||
public int is_rendering_shadowsSun = 3;
|
||||
public int is_rendering_shadowsSun_clamped = 3;
|
||||
public boolean is_rendering_shadowsColored = false;
|
||||
public boolean is_rendering_shadowsSmoothed = true;
|
||||
public boolean is_rendering_useEnvMap = true;
|
||||
public boolean is_rendering_realisticWater = true;
|
||||
public boolean is_rendering_lightShafts = false;
|
||||
public boolean is_rendering_raytracing = true;
|
||||
public boolean is_rendering_lensDistortion = false;
|
||||
public boolean is_rendering_lensFlares = true;
|
||||
public boolean is_rendering_bloom = false;
|
||||
public boolean is_rendering_fxaa = true;
|
||||
|
||||
public void readOption(String key, String value) {
|
||||
switch(key) {
|
||||
case "shaders_deferred_wavingBlocks":
|
||||
wavingBlocks = value.equals("true");
|
||||
break;
|
||||
case "shaders_deferred_dynamicLights":
|
||||
dynamicLights = value.equals("true");
|
||||
break;
|
||||
case "shaders_deferred_ssao":
|
||||
ssao = value.equals("true");
|
||||
break;
|
||||
case "shaders_deferred_shadowsSun":
|
||||
shadowsSun = Integer.parseInt(value);
|
||||
break;
|
||||
case "shaders_deferred_shadowsColored":
|
||||
shadowsColored = value.equals("true");
|
||||
break;
|
||||
case "shaders_deferred_shadowsSmoothed":
|
||||
shadowsSmoothed = value.equals("true");
|
||||
break;
|
||||
case "shaders_deferred_useEnvMap":
|
||||
useEnvMap = value.equals("true");
|
||||
break;
|
||||
case "shaders_deferred_realisticWater":
|
||||
realisticWater = value.equals("true");
|
||||
break;
|
||||
case "shaders_deferred_lightShafts":
|
||||
lightShafts = value.equals("true");
|
||||
break;
|
||||
case "shaders_deferred_raytracing":
|
||||
raytracing = value.equals("true");
|
||||
break;
|
||||
case "shaders_deferred_lensDistortion":
|
||||
lensDistortion = value.equals("true");
|
||||
break;
|
||||
case "shaders_deferred_lensFlares":
|
||||
lensFlares = value.equals("true");
|
||||
break;
|
||||
case "shaders_deferred_bloom":
|
||||
bloom = value.equals("true");
|
||||
break;
|
||||
case "shaders_deferred_fxaa":
|
||||
fxaa = value.equals("true");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void writeOptions(PrintWriter output) {
|
||||
output.println("shaders_deferred_wavingBlocks:" + wavingBlocks);
|
||||
output.println("shaders_deferred_dynamicLights:" + dynamicLights);
|
||||
output.println("shaders_deferred_ssao:" + ssao);
|
||||
output.println("shaders_deferred_shadowsSun:" + shadowsSun);
|
||||
output.println("shaders_deferred_shadowsColored:" + shadowsColored);
|
||||
output.println("shaders_deferred_shadowsSmoothed:" + shadowsSmoothed);
|
||||
output.println("shaders_deferred_useEnvMap:" + useEnvMap);
|
||||
output.println("shaders_deferred_realisticWater:" + realisticWater);
|
||||
output.println("shaders_deferred_lightShafts:" + lightShafts);
|
||||
output.println("shaders_deferred_raytracing:" + raytracing);
|
||||
output.println("shaders_deferred_lensDistortion:" + lensDistortion);
|
||||
output.println("shaders_deferred_lensFlares:" + lensFlares);
|
||||
output.println("shaders_deferred_bloom:" + bloom);
|
||||
output.println("shaders_deferred_fxaa:" + fxaa);
|
||||
}
|
||||
|
||||
public void reloadShaderPackInfo(IResourceManager mgr) throws IOException {
|
||||
IResource res = mgr.getResource(shaderPackInfoFile);
|
||||
try(InputStream is = res.getInputStream()) {
|
||||
try {
|
||||
JSONObject shaderInfoJSON = new JSONObject(new String(EaglerInputStream.inputStreamToBytes(is), StandardCharsets.UTF_8));
|
||||
shaderPackInfo = new ShaderPackInfo(shaderInfoJSON);
|
||||
}catch(JSONException ex) {
|
||||
throw new IOException("Invalid shader pack info json!", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateConfig() {
|
||||
is_rendering_wavingBlocks = wavingBlocks && shaderPackInfo.WAVING_BLOCKS;
|
||||
is_rendering_dynamicLights = dynamicLights && shaderPackInfo.DYNAMIC_LIGHTS;
|
||||
is_rendering_ssao = ssao && shaderPackInfo.GLOBAL_AMBIENT_OCCLUSION;
|
||||
is_rendering_shadowsSun = is_rendering_shadowsSun_clamped = shaderPackInfo.SHADOWS_SUN ? shadowsSun : 0;
|
||||
is_rendering_shadowsColored = shadowsColored && shaderPackInfo.SHADOWS_COLORED;
|
||||
is_rendering_shadowsSmoothed = shadowsSmoothed && shaderPackInfo.SHADOWS_SMOOTHED;
|
||||
is_rendering_useEnvMap = useEnvMap && shaderPackInfo.REFLECTIONS_PARABOLOID;
|
||||
is_rendering_realisticWater = realisticWater && shaderPackInfo.REALISTIC_WATER;
|
||||
is_rendering_lightShafts = is_rendering_shadowsSun_clamped > 0 && lightShafts && shaderPackInfo.LIGHT_SHAFTS;
|
||||
is_rendering_raytracing = shaderPackInfo.SCREEN_SPACE_REFLECTIONS && raytracing;
|
||||
is_rendering_lensDistortion = lensDistortion && shaderPackInfo.POST_LENS_DISTORION;
|
||||
is_rendering_lensFlares = lensFlares && shaderPackInfo.POST_LENS_FLARES;
|
||||
is_rendering_bloom = bloom && shaderPackInfo.POST_BLOOM;
|
||||
is_rendering_fxaa = fxaa && shaderPackInfo.POST_FXAA;
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,40 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class ExtGLEnums {
|
||||
|
||||
public static final int _GL_FRAMEBUFFER = 0x8D40;
|
||||
public static final int _GL_READ_FRAMEBUFFER = 0x8CA8;
|
||||
public static final int _GL_DRAW_FRAMEBUFFER = 0x8CA9;
|
||||
public static final int _GL_RENDERBUFFER = 0x8D41;
|
||||
public static final int _GL_COLOR_ATTACHMENT0 = 0x8CE0;
|
||||
public static final int _GL_COLOR_ATTACHMENT1 = 0x8CE1;
|
||||
public static final int _GL_COLOR_ATTACHMENT2 = 0x8CE2;
|
||||
public static final int _GL_COLOR_ATTACHMENT3 = 0x8CE3;
|
||||
public static final int _GL_DEPTH_ATTACHMENT = 0x8D00;
|
||||
public static final int _GL_DEPTH_COMPONENT = 0x1902;
|
||||
public static final int _GL_DEPTH_COMPONENT24 = 0x81A6;
|
||||
public static final int _GL_DEPTH_COMPONENT32F = 0x8CAC;
|
||||
public static final int _GL_R8 = 0x8229;
|
||||
public static final int _GL_RG = 0x8227;
|
||||
public static final int _GL_RG8 = 0x822B;
|
||||
public static final int _GL_RGB16F = 0x881B;
|
||||
public static final int _GL_HALF_FLOAT = 0x140B;
|
||||
public static final int _GL_UNIFORM_BUFFER = 0x8A11;
|
||||
public static final int _GL_TEXTURE_COMPARE_MODE = 0x884C;
|
||||
public static final int _GL_TEXTURE_COMPARE_FUNC = 0x884D;
|
||||
public static final int _GL_COMPARE_REF_TO_TEXTURE = 0x884E;
|
||||
|
||||
}
|
@ -0,0 +1,218 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IBufferArrayGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IBufferGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.buffer.FloatBuffer;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.EaglercraftGPU;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program.PipelineShaderAccelParticleForward;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program.PipelineShaderAccelParticleGBuffer;
|
||||
import net.lax1dude.eaglercraft.v1_8.vector.Matrix4f;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class ForwardAcceleratedEffectRenderer extends AbstractAcceleratedEffectRenderer {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger("ForwardAcceleratedEffectRenderer");
|
||||
|
||||
private ByteBuffer particleBuffer = null;
|
||||
private int particleCount = 0;
|
||||
private boolean particlesHasOverflowed = false;
|
||||
|
||||
private static final int BYTES_PER_PARTICLE = 24;
|
||||
private static final int PARTICLE_LIMIT = 5461;
|
||||
|
||||
private PipelineShaderAccelParticleForward shaderProgram = null;
|
||||
|
||||
private IBufferArrayGL vertexArray = null;
|
||||
private IBufferGL vertexBuffer = null;
|
||||
|
||||
private IBufferGL instancesBuffer = null;
|
||||
|
||||
private static final Matrix4f tmpMatrix = new Matrix4f();
|
||||
|
||||
private float f1;
|
||||
private float f2;
|
||||
private float f3;
|
||||
private float f4;
|
||||
private float f5;
|
||||
|
||||
public static boolean isMaterialNormalTexture = false;
|
||||
|
||||
public void initialize(boolean dynamicLights, int sunShadows) {
|
||||
destroy();
|
||||
|
||||
shaderProgram = PipelineShaderAccelParticleForward.compile(dynamicLights, sunShadows);
|
||||
shaderProgram.loadUniforms();
|
||||
|
||||
particleBuffer = EagRuntime.allocateByteBuffer(PARTICLE_LIMIT * BYTES_PER_PARTICLE);
|
||||
|
||||
vertexArray = _wglGenVertexArrays();
|
||||
vertexBuffer = _wglGenBuffers();
|
||||
instancesBuffer = _wglGenBuffers();
|
||||
|
||||
FloatBuffer verts = EagRuntime.allocateFloatBuffer(12);
|
||||
verts.put(new float[] {
|
||||
-1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f,
|
||||
-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f
|
||||
});
|
||||
verts.flip();
|
||||
|
||||
EaglercraftGPU.bindGLBufferArray(vertexArray);
|
||||
|
||||
EaglercraftGPU.bindGLArrayBuffer(vertexBuffer);
|
||||
_wglBufferData(GL_ARRAY_BUFFER, verts, GL_STATIC_DRAW);
|
||||
|
||||
EagRuntime.freeFloatBuffer(verts);
|
||||
|
||||
_wglEnableVertexAttribArray(0);
|
||||
_wglVertexAttribPointer(0, 2, GL_FLOAT, false, 8, 0);
|
||||
_wglVertexAttribDivisor(0, 0);
|
||||
|
||||
EaglercraftGPU.bindGLArrayBuffer(instancesBuffer);
|
||||
_wglBufferData(GL_ARRAY_BUFFER, particleBuffer.remaining(), GL_STATIC_DRAW);
|
||||
|
||||
_wglEnableVertexAttribArray(1);
|
||||
_wglVertexAttribPointer(1, 3, GL_FLOAT, false, 24, 0);
|
||||
_wglVertexAttribDivisor(1, 1);
|
||||
|
||||
_wglEnableVertexAttribArray(2);
|
||||
_wglVertexAttribPointer(2, 2, GL_UNSIGNED_SHORT, false, 24, 12);
|
||||
_wglVertexAttribDivisor(2, 1);
|
||||
|
||||
_wglEnableVertexAttribArray(3);
|
||||
_wglVertexAttribPointer(3, 2, GL_UNSIGNED_BYTE, true, 24, 16);
|
||||
_wglVertexAttribDivisor(3, 1);
|
||||
|
||||
_wglEnableVertexAttribArray(4);
|
||||
_wglVertexAttribPointer(4, 2, GL_UNSIGNED_BYTE, false, 24, 18);
|
||||
_wglVertexAttribDivisor(4, 1);
|
||||
|
||||
_wglEnableVertexAttribArray(5);
|
||||
_wglVertexAttribPointer(5, 4, GL_UNSIGNED_BYTE, true, 24, 20);
|
||||
_wglVertexAttribDivisor(5, 1);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(float texCoordWidth, float texCoordHeight) {
|
||||
if(particleCount == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
shaderProgram.useProgram();
|
||||
|
||||
_wglUniform3f(shaderProgram.uniforms.u_texCoordSize2f_particleSize1f, texCoordWidth, texCoordHeight, 0.0625f);
|
||||
_wglUniform4f(shaderProgram.uniforms.u_transformParam_1_2_3_4_f, f1, f5, f2, f3);
|
||||
_wglUniform1f(shaderProgram.uniforms.u_transformParam_5_f, f4);
|
||||
if(isMaterialNormalTexture) {
|
||||
_wglUniform2f(shaderProgram.uniforms.u_textureYScale2f, 0.5f, 0.5f);
|
||||
}else {
|
||||
_wglUniform2f(shaderProgram.uniforms.u_textureYScale2f, 1.0f, 0.0f);
|
||||
}
|
||||
|
||||
EaglerDeferredPipeline.uniformMatrixHelper(shaderProgram.uniforms.u_modelViewMatrix4f, DeferredStateManager.passViewMatrix);
|
||||
EaglerDeferredPipeline.uniformMatrixHelper(shaderProgram.uniforms.u_projectionMatrix4f, DeferredStateManager.passProjMatrix);
|
||||
EaglerDeferredPipeline.uniformMatrixHelper(shaderProgram.uniforms.u_inverseViewMatrix4f, DeferredStateManager.passInverseViewMatrix);
|
||||
|
||||
EaglercraftGPU.bindGLArrayBuffer(instancesBuffer);
|
||||
EaglercraftGPU.bindGLBufferArray(vertexArray);
|
||||
|
||||
int p = particleBuffer.position();
|
||||
int l = particleBuffer.limit();
|
||||
|
||||
particleBuffer.flip();
|
||||
_wglBufferSubData(GL_ARRAY_BUFFER, 0, particleBuffer);
|
||||
|
||||
particleBuffer.position(p);
|
||||
particleBuffer.limit(l);
|
||||
|
||||
_wglDrawArraysInstanced(GL_TRIANGLES, 0, 6, particleCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void begin(float partialTicks) {
|
||||
this.partialTicks = partialTicks;
|
||||
|
||||
particleBuffer.clear();
|
||||
particleCount = 0;
|
||||
particlesHasOverflowed = false;
|
||||
|
||||
Entity et = Minecraft.getMinecraft().getRenderViewEntity();
|
||||
if(et != null) {
|
||||
f1 = MathHelper.cos(et.rotationYaw * 0.017453292F);
|
||||
f2 = MathHelper.sin(et.rotationYaw * 0.017453292F);
|
||||
f3 = -f2 * MathHelper.sin(et.rotationPitch * 0.017453292F);
|
||||
f4 = f1 * MathHelper.sin(et.rotationPitch * 0.017453292F);
|
||||
f5 = MathHelper.cos(et.rotationPitch * 0.017453292F);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawParticle(float posX, float posY, float posZ, int particleIndexX, int particleIndexY,
|
||||
int lightMapData, int texSize, float particleSize, int rgba) {
|
||||
if(particlesHasOverflowed) {
|
||||
return;
|
||||
}
|
||||
if(particleCount >= PARTICLE_LIMIT) {
|
||||
particlesHasOverflowed = true;
|
||||
logger.error("Particle buffer has overflowed! Exceeded {} particles, no more particles will be rendered.", PARTICLE_LIMIT);
|
||||
return;
|
||||
}
|
||||
++particleCount;
|
||||
ByteBuffer buf = particleBuffer;
|
||||
buf.putFloat(posX);
|
||||
buf.putFloat(posY);
|
||||
buf.putFloat(posZ);
|
||||
buf.putShort((short)particleIndexX);
|
||||
buf.putShort((short)particleIndexY);
|
||||
buf.put((byte)(lightMapData & 0xFF));
|
||||
buf.put((byte)((lightMapData >> 16) & 0xFF));
|
||||
buf.put((byte)(particleSize * 16.0f));
|
||||
buf.put((byte)texSize);
|
||||
buf.putInt(rgba);
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
if(particleBuffer != null) {
|
||||
EagRuntime.freeByteBuffer(particleBuffer);
|
||||
particleBuffer = null;
|
||||
}
|
||||
if(shaderProgram != null) {
|
||||
shaderProgram.destroy();
|
||||
shaderProgram = null;
|
||||
}
|
||||
if(vertexArray != null) {
|
||||
_wglDeleteVertexArrays(vertexArray);
|
||||
vertexArray = null;
|
||||
}
|
||||
if(vertexBuffer != null) {
|
||||
_wglDeleteBuffers(vertexBuffer);
|
||||
vertexBuffer = null;
|
||||
}
|
||||
if(instancesBuffer != null) {
|
||||
_wglDeleteBuffers(instancesBuffer);
|
||||
instancesBuffer = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class ForwardRenderCallbackHandler {
|
||||
|
||||
public final List<ShadersRenderPassFuture> renderPassList = new ArrayList(1024);
|
||||
|
||||
public void push(ShadersRenderPassFuture f) {
|
||||
renderPassList.add(f);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
renderPassList.clear();
|
||||
}
|
||||
|
||||
public void sort(float x, float y, float z) {
|
||||
if(renderPassList.size() == 0) return;
|
||||
ShadersRenderPassFuture rp;
|
||||
float dx, dy, dz;
|
||||
for(int i = 0, l = renderPassList.size(); i < l; ++i) {
|
||||
rp = renderPassList.get(i);
|
||||
dx = rp.getX() - x;
|
||||
dy = rp.getY() - y;
|
||||
dz = rp.getZ() - z;
|
||||
rp.tmpValue()[0] = dx * dx + dy * dy + dz * dz;
|
||||
}
|
||||
Collections.sort(renderPassList, new Comparator<ShadersRenderPassFuture>() {
|
||||
@Override
|
||||
public int compare(ShadersRenderPassFuture o1, ShadersRenderPassFuture o2) {
|
||||
float a = o1.tmpValue()[0], b = o2.tmpValue()[0];
|
||||
return a < b ? 1 : (a > b ? -1 : 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,216 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IBufferArrayGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IBufferGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.buffer.FloatBuffer;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.EaglercraftGPU;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program.PipelineShaderAccelParticleGBuffer;
|
||||
import net.lax1dude.eaglercraft.v1_8.vector.Matrix4f;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class GBufferAcceleratedEffectRenderer extends AbstractAcceleratedEffectRenderer {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger("GBufferAcceleratedEffectRenderer");
|
||||
|
||||
private ByteBuffer particleBuffer = null;
|
||||
private int particleCount = 0;
|
||||
private boolean particlesHasOverflowed = false;
|
||||
|
||||
private static final int BYTES_PER_PARTICLE = 24;
|
||||
private static final int PARTICLE_LIMIT = 5461;
|
||||
|
||||
private PipelineShaderAccelParticleGBuffer shaderProgram = null;
|
||||
|
||||
private IBufferArrayGL vertexArray = null;
|
||||
private IBufferGL vertexBuffer = null;
|
||||
|
||||
private IBufferGL instancesBuffer = null;
|
||||
|
||||
private static final Matrix4f tmpMatrix = new Matrix4f();
|
||||
|
||||
private float f1;
|
||||
private float f2;
|
||||
private float f3;
|
||||
private float f4;
|
||||
private float f5;
|
||||
|
||||
public static boolean isMaterialNormalTexture = false;
|
||||
|
||||
public void initialize() {
|
||||
destroy();
|
||||
|
||||
shaderProgram = PipelineShaderAccelParticleGBuffer.compile();
|
||||
shaderProgram.loadUniforms();
|
||||
|
||||
particleBuffer = EagRuntime.allocateByteBuffer(PARTICLE_LIMIT * BYTES_PER_PARTICLE);
|
||||
|
||||
vertexArray = _wglGenVertexArrays();
|
||||
vertexBuffer = _wglGenBuffers();
|
||||
instancesBuffer = _wglGenBuffers();
|
||||
|
||||
FloatBuffer verts = EagRuntime.allocateFloatBuffer(12);
|
||||
verts.put(new float[] {
|
||||
-1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f,
|
||||
-1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f
|
||||
});
|
||||
verts.flip();
|
||||
|
||||
EaglercraftGPU.bindGLBufferArray(vertexArray);
|
||||
|
||||
EaglercraftGPU.bindGLArrayBuffer(vertexBuffer);
|
||||
_wglBufferData(GL_ARRAY_BUFFER, verts, GL_STATIC_DRAW);
|
||||
|
||||
EagRuntime.freeFloatBuffer(verts);
|
||||
|
||||
_wglEnableVertexAttribArray(0);
|
||||
_wglVertexAttribPointer(0, 2, GL_FLOAT, false, 8, 0);
|
||||
_wglVertexAttribDivisor(0, 0);
|
||||
|
||||
EaglercraftGPU.bindGLArrayBuffer(instancesBuffer);
|
||||
_wglBufferData(GL_ARRAY_BUFFER, particleBuffer.remaining(), GL_STATIC_DRAW);
|
||||
|
||||
_wglEnableVertexAttribArray(1);
|
||||
_wglVertexAttribPointer(1, 3, GL_FLOAT, false, 24, 0);
|
||||
_wglVertexAttribDivisor(1, 1);
|
||||
|
||||
_wglEnableVertexAttribArray(2);
|
||||
_wglVertexAttribPointer(2, 2, GL_UNSIGNED_SHORT, false, 24, 12);
|
||||
_wglVertexAttribDivisor(2, 1);
|
||||
|
||||
_wglEnableVertexAttribArray(3);
|
||||
_wglVertexAttribPointer(3, 2, GL_UNSIGNED_BYTE, true, 24, 16);
|
||||
_wglVertexAttribDivisor(3, 1);
|
||||
|
||||
_wglEnableVertexAttribArray(4);
|
||||
_wglVertexAttribPointer(4, 2, GL_UNSIGNED_BYTE, false, 24, 18);
|
||||
_wglVertexAttribDivisor(4, 1);
|
||||
|
||||
_wglEnableVertexAttribArray(5);
|
||||
_wglVertexAttribPointer(5, 4, GL_UNSIGNED_BYTE, true, 24, 20);
|
||||
_wglVertexAttribDivisor(5, 1);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(float texCoordWidth, float texCoordHeight) {
|
||||
if(particleCount == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
shaderProgram.useProgram();
|
||||
|
||||
_wglUniform3f(shaderProgram.uniforms.u_texCoordSize2f_particleSize1f, texCoordWidth, texCoordHeight, 0.0625f);
|
||||
_wglUniform4f(shaderProgram.uniforms.u_transformParam_1_2_3_4_f, f1, f5, f2, f3);
|
||||
_wglUniform1f(shaderProgram.uniforms.u_transformParam_5_f, f4);
|
||||
if(isMaterialNormalTexture) {
|
||||
_wglUniform2f(shaderProgram.uniforms.u_textureYScale2f, 0.5f, 0.5f);
|
||||
}else {
|
||||
_wglUniform2f(shaderProgram.uniforms.u_textureYScale2f, 1.0f, 0.0f);
|
||||
}
|
||||
|
||||
Matrix4f.mul(DeferredStateManager.passProjMatrix, DeferredStateManager.passViewMatrix, tmpMatrix);
|
||||
EaglerDeferredPipeline.uniformMatrixHelper(shaderProgram.uniforms.u_matrixTransform, tmpMatrix);
|
||||
|
||||
EaglercraftGPU.bindGLArrayBuffer(instancesBuffer);
|
||||
EaglercraftGPU.bindGLBufferArray(vertexArray);
|
||||
|
||||
int p = particleBuffer.position();
|
||||
int l = particleBuffer.limit();
|
||||
|
||||
particleBuffer.flip();
|
||||
_wglBufferSubData(GL_ARRAY_BUFFER, 0, particleBuffer);
|
||||
|
||||
particleBuffer.position(p);
|
||||
particleBuffer.limit(l);
|
||||
|
||||
_wglDrawArraysInstanced(GL_TRIANGLES, 0, 6, particleCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void begin(float partialTicks) {
|
||||
this.partialTicks = partialTicks;
|
||||
|
||||
particleBuffer.clear();
|
||||
particleCount = 0;
|
||||
particlesHasOverflowed = false;
|
||||
|
||||
Entity et = Minecraft.getMinecraft().getRenderViewEntity();
|
||||
if(et != null) {
|
||||
f1 = MathHelper.cos(et.rotationYaw * 0.017453292F);
|
||||
f2 = MathHelper.sin(et.rotationYaw * 0.017453292F);
|
||||
f3 = -f2 * MathHelper.sin(et.rotationPitch * 0.017453292F);
|
||||
f4 = f1 * MathHelper.sin(et.rotationPitch * 0.017453292F);
|
||||
f5 = MathHelper.cos(et.rotationPitch * 0.017453292F);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawParticle(float posX, float posY, float posZ, int particleIndexX, int particleIndexY,
|
||||
int lightMapData, int texSize, float particleSize, int rgba) {
|
||||
if(particlesHasOverflowed) {
|
||||
return;
|
||||
}
|
||||
if(particleCount >= PARTICLE_LIMIT) {
|
||||
particlesHasOverflowed = true;
|
||||
logger.error("Particle buffer has overflowed! Exceeded {} particles, no more particles will be rendered.", PARTICLE_LIMIT);
|
||||
return;
|
||||
}
|
||||
++particleCount;
|
||||
ByteBuffer buf = particleBuffer;
|
||||
buf.putFloat(posX);
|
||||
buf.putFloat(posY);
|
||||
buf.putFloat(posZ);
|
||||
buf.putShort((short)particleIndexX);
|
||||
buf.putShort((short)particleIndexY);
|
||||
buf.put((byte)(lightMapData & 0xFF));
|
||||
buf.put((byte)((lightMapData >> 16) & 0xFF));
|
||||
buf.put((byte)(particleSize * 16.0f));
|
||||
buf.put((byte)texSize);
|
||||
buf.putInt(rgba);
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
if(particleBuffer != null) {
|
||||
EagRuntime.freeByteBuffer(particleBuffer);
|
||||
particleBuffer = null;
|
||||
}
|
||||
if(shaderProgram != null) {
|
||||
shaderProgram.destroy();
|
||||
shaderProgram = null;
|
||||
}
|
||||
if(vertexArray != null) {
|
||||
_wglDeleteVertexArrays(vertexArray);
|
||||
vertexArray = null;
|
||||
}
|
||||
if(vertexBuffer != null) {
|
||||
_wglDeleteBuffers(vertexBuffer);
|
||||
vertexBuffer = null;
|
||||
}
|
||||
if(instancesBuffer != null) {
|
||||
_wglDeleteBuffers(instancesBuffer);
|
||||
instancesBuffer = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,389 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.buffer.FloatBuffer;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.EaglercraftGPU;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.FixedFunctionPipeline;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.FixedFunctionShader;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.GlStateManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.IExtPipelineCompiler;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program.GBufferExtPipelineShader;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program.ShaderSource;
|
||||
import net.lax1dude.eaglercraft.v1_8.vector.Matrix4f;
|
||||
import net.lax1dude.eaglercraft.v1_8.vector.Vector4f;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GLAllocation;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class GBufferPipelineCompiler implements IExtPipelineCompiler {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger("DeferredGBufferPipelineCompiler");
|
||||
|
||||
public static final int STATE_MATERIAL_TEXTURE = 1;
|
||||
public static final int STATE_FORWARD_RENDER = 2;
|
||||
public static final int STATE_PARABOLOID_RENDER = 4;
|
||||
public static final int STATE_SHADOW_RENDER = 8;
|
||||
public static final int STATE_CLIP_PLANE = 16;
|
||||
public static final int STATE_WAVING_BLOCKS = 32;
|
||||
public static final int STATE_REALISTIC_WATER_MASK = 64;
|
||||
public static final int STATE_REALISTIC_WATER_RENDER = 128;
|
||||
public static final int STATE_GLASS_HIGHLIGHTS = 256;
|
||||
|
||||
private static FloatBuffer matrixCopyBuffer = null;
|
||||
private static final Matrix4f tmpMatrix = new Matrix4f();
|
||||
|
||||
@Override
|
||||
public String[] getShaderSource(int stateCoreBits, int stateExtBits, Object[] userPointer) {
|
||||
if(matrixCopyBuffer == null) {
|
||||
matrixCopyBuffer = GLAllocation.createDirectFloatBuffer(16);
|
||||
}
|
||||
userPointer[0] = new GBufferPipelineProgramInstance(stateCoreBits, stateExtBits);
|
||||
EaglerDeferredConfig conf = Minecraft.getMinecraft().gameSettings.deferredShaderConf;
|
||||
StringBuilder macros = new StringBuilder();
|
||||
if((stateExtBits & STATE_SHADOW_RENDER) != 0) {
|
||||
if((stateExtBits & STATE_CLIP_PLANE) != 0) {
|
||||
macros.append("#define STATE_CLIP_PLANE\n");
|
||||
}
|
||||
if((stateExtBits & STATE_WAVING_BLOCKS) != 0) {
|
||||
macros.append("#define COMPILE_STATE_WAVING_BLOCKS\n");
|
||||
}
|
||||
if((stateExtBits & STATE_FORWARD_RENDER) != 0) {
|
||||
macros.append("#define COMPILE_COLORED_SHADOWS\n");
|
||||
}
|
||||
logger.info("Compiling program for core state: {}, ext state: {}", visualizeBits(stateCoreBits), visualizeBits(stateExtBits));
|
||||
logger.info(" - {}", ShaderSource.deferred_shadow_vsh);
|
||||
logger.info(" - {}", ShaderSource.deferred_shadow_fsh);
|
||||
return new String[] { macros.toString() + ShaderSource.getSourceFor(ShaderSource.deferred_shadow_vsh),
|
||||
macros.toString() + ShaderSource.getSourceFor(ShaderSource.deferred_shadow_fsh) };
|
||||
}else if((stateExtBits & STATE_REALISTIC_WATER_RENDER) != 0) {
|
||||
if(conf.is_rendering_dynamicLights) {
|
||||
macros.append("#define COMPILE_DYNAMIC_LIGHTS\n");
|
||||
}
|
||||
if(conf.is_rendering_shadowsSun_clamped > 0) {
|
||||
int lods = conf.is_rendering_shadowsSun_clamped - 1;
|
||||
if(lods > 2) {
|
||||
lods = 2;
|
||||
}
|
||||
macros.append("#define COMPILE_SUN_SHADOW_LOD" + lods + "\n");
|
||||
if(conf.is_rendering_shadowsSmoothed) {
|
||||
macros.append("#define COMPILE_SUN_SHADOW_SMOOTH\n");
|
||||
}
|
||||
}
|
||||
if(conf.is_rendering_lightShafts) {
|
||||
macros.append("#define COMPILE_FOG_LIGHT_SHAFTS\n");
|
||||
}
|
||||
logger.info("Compiling program for core state: {}, ext state: {}", visualizeBits(stateCoreBits), visualizeBits(stateExtBits));
|
||||
logger.info(" - {}", ShaderSource.realistic_water_render_vsh);
|
||||
logger.info(" - {}", ShaderSource.realistic_water_render_fsh);
|
||||
return new String[] { macros.toString() + ShaderSource.getSourceFor(ShaderSource.realistic_water_render_vsh),
|
||||
macros.toString() + ShaderSource.getSourceFor(ShaderSource.realistic_water_render_fsh) };
|
||||
}else if((stateExtBits & STATE_GLASS_HIGHLIGHTS) != 0) {
|
||||
if(conf.is_rendering_dynamicLights) {
|
||||
macros.append("#define COMPILE_DYNAMIC_LIGHTS\n");
|
||||
}
|
||||
if(conf.is_rendering_shadowsSun_clamped > 0) {
|
||||
int lods = conf.is_rendering_shadowsSun_clamped - 1;
|
||||
if(lods > 2) {
|
||||
lods = 2;
|
||||
}
|
||||
macros.append("#define COMPILE_SUN_SHADOW_LOD" + lods + "\n");
|
||||
if(conf.is_rendering_shadowsSmoothed) {
|
||||
macros.append("#define COMPILE_SUN_SHADOW_SMOOTH\n");
|
||||
}
|
||||
}
|
||||
logger.info("Compiling program for core state: {}, ext state: {}", visualizeBits(stateCoreBits), visualizeBits(stateExtBits));
|
||||
logger.info(" - {}", ShaderSource.forward_glass_highlights_vsh);
|
||||
logger.info(" - {}", ShaderSource.forward_glass_highlights_fsh);
|
||||
return new String[] { macros.toString() + ShaderSource.getSourceFor(ShaderSource.forward_glass_highlights_vsh),
|
||||
macros.toString() + ShaderSource.getSourceFor(ShaderSource.forward_glass_highlights_fsh) };
|
||||
}else if((stateExtBits & (STATE_FORWARD_RENDER | STATE_PARABOLOID_RENDER)) != 0) {
|
||||
if((stateExtBits & STATE_MATERIAL_TEXTURE) != 0) {
|
||||
macros.append("#define COMPILE_NORMAL_MATERIAL_TEXTURE\n");
|
||||
}
|
||||
if((stateExtBits & STATE_CLIP_PLANE) != 0) {
|
||||
macros.append("#define STATE_CLIP_PLANE\n");
|
||||
}
|
||||
if((stateExtBits & STATE_PARABOLOID_RENDER) != 0) {
|
||||
macros.append("#define COMPILE_PARABOLOID\n");
|
||||
}else {
|
||||
if(conf.is_rendering_useEnvMap) {
|
||||
macros.append("#define COMPILE_PARABOLOID_ENV_MAP\n");
|
||||
}
|
||||
}
|
||||
if(conf.is_rendering_dynamicLights) {
|
||||
macros.append("#define COMPILE_DYNAMIC_LIGHTS\n");
|
||||
}
|
||||
if(conf.is_rendering_shadowsSun_clamped > 0) {
|
||||
int lods = conf.is_rendering_shadowsSun_clamped - 1;
|
||||
if(lods > 2) {
|
||||
lods = 2;
|
||||
}
|
||||
macros.append("#define COMPILE_SUN_SHADOW_LOD" + lods + "\n");
|
||||
if(conf.is_rendering_shadowsSmoothed) {
|
||||
macros.append("#define COMPILE_SUN_SHADOW_SMOOTH\n");
|
||||
}
|
||||
}
|
||||
if(conf.is_rendering_lightShafts) {
|
||||
macros.append("#define COMPILE_FOG_LIGHT_SHAFTS\n");
|
||||
}
|
||||
logger.info("Compiling program for core state: {}, ext state: {}", visualizeBits(stateCoreBits), visualizeBits(stateExtBits));
|
||||
logger.info(" - {}", ShaderSource.forward_core_vsh);
|
||||
logger.info(" - {}", ShaderSource.forward_core_fsh);
|
||||
return new String[] { macros.toString() + ShaderSource.getSourceFor(ShaderSource.forward_core_vsh),
|
||||
macros.toString() + ShaderSource.getSourceFor(ShaderSource.forward_core_fsh) };
|
||||
}else if((stateExtBits & STATE_REALISTIC_WATER_MASK) != 0) {
|
||||
logger.info("Compiling program for core state: {}, ext state: {}", visualizeBits(stateCoreBits), visualizeBits(stateExtBits));
|
||||
logger.info(" - {}", ShaderSource.realistic_water_mask_vsh);
|
||||
logger.info(" - {}", ShaderSource.realistic_water_mask_fsh);
|
||||
return new String[] { ShaderSource.getSourceFor(ShaderSource.realistic_water_mask_vsh),
|
||||
ShaderSource.getSourceFor(ShaderSource.realistic_water_mask_fsh) };
|
||||
}else {
|
||||
if((stateExtBits & STATE_MATERIAL_TEXTURE) != 0) {
|
||||
macros.append("#define COMPILE_NORMAL_MATERIAL_TEXTURE\n");
|
||||
}
|
||||
if((stateExtBits & STATE_CLIP_PLANE) != 0) {
|
||||
macros.append("#define COMPILE_STATE_CLIP_PLANE\n");
|
||||
}
|
||||
if((stateExtBits & STATE_WAVING_BLOCKS) != 0) {
|
||||
macros.append("#define COMPILE_STATE_WAVING_BLOCKS\n");
|
||||
}
|
||||
|
||||
logger.info("Compiling program for core state: {}, ext state: {}", visualizeBits(stateCoreBits), visualizeBits(stateExtBits));
|
||||
logger.info(" - {}", ShaderSource.deferred_core_vsh);
|
||||
logger.info(" - {}", ShaderSource.deferred_core_gbuffer_fsh);
|
||||
|
||||
return new String[] { macros.toString() + ShaderSource.getSourceFor(ShaderSource.deferred_core_vsh),
|
||||
macros.toString() + ShaderSource.getSourceFor(ShaderSource.deferred_core_gbuffer_fsh) };
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getExtensionStatesCount() {
|
||||
return 9;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCoreStateMask(int stateExtBits) {
|
||||
return DeferredStateManager.enableShadowRender
|
||||
? (FixedFunctionShader.FixedFunctionState.STATE_ENABLE_TEXTURE2D
|
||||
| FixedFunctionShader.FixedFunctionState.STATE_ENABLE_ALPHA_TEST
|
||||
| (DeferredStateManager.enableDrawWavingBlocks
|
||||
? FixedFunctionShader.FixedFunctionState.STATE_ENABLE_LIGHTMAP
|
||||
: 0))
|
||||
: ((DeferredStateManager.enableDrawRealisticWaterMask) ? FixedFunctionShader.FixedFunctionState.STATE_ENABLE_LIGHTMAP
|
||||
: (DeferredStateManager.enableDrawRealisticWaterRender
|
||||
? (FixedFunctionShader.FixedFunctionState.STATE_ENABLE_LIGHTMAP
|
||||
| FixedFunctionShader.FixedFunctionState.STATE_ENABLE_TEXTURE2D)
|
||||
: (2943)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCurrentExtensionStateBits(int stateCoreBits) {
|
||||
return ((DeferredStateManager.enableMaterialMapTexture && !DeferredStateManager.enableShadowRender
|
||||
&& !DeferredStateManager.enableDrawRealisticWaterMask
|
||||
&& !DeferredStateManager.enableDrawRealisticWaterRender) ? STATE_MATERIAL_TEXTURE : 0) |
|
||||
(DeferredStateManager.enableForwardRender ? STATE_FORWARD_RENDER : 0) |
|
||||
(DeferredStateManager.enableParaboloidRender ? STATE_PARABOLOID_RENDER : 0) |
|
||||
(DeferredStateManager.enableShadowRender ? STATE_SHADOW_RENDER : 0) |
|
||||
(DeferredStateManager.enableClipPlane ? STATE_CLIP_PLANE : 0) |
|
||||
(DeferredStateManager.enableDrawWavingBlocks ? STATE_WAVING_BLOCKS : 0) |
|
||||
(DeferredStateManager.enableDrawRealisticWaterMask ? STATE_REALISTIC_WATER_MASK : 0) |
|
||||
(DeferredStateManager.enableDrawRealisticWaterRender ? STATE_REALISTIC_WATER_RENDER : 0) |
|
||||
(DeferredStateManager.enableDrawGlassHighlightsRender ? STATE_GLASS_HIGHLIGHTS : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeNewShader(IProgramGL compiledProg, int stateCoreBits, int stateExtBits,
|
||||
Object[] userPointer) {
|
||||
EaglercraftGPU.bindGLShaderProgram(compiledProg);
|
||||
GBufferExtPipelineShader newShader = new GBufferExtPipelineShader(compiledProg, stateCoreBits, stateExtBits);
|
||||
((GBufferPipelineProgramInstance)userPointer[0]).shaderObject = newShader;
|
||||
newShader.loadUniforms();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePipeline(IProgramGL compiledProg, int stateCoreBits, int stateExtBits, Object[] userPointer) {
|
||||
int serial;
|
||||
GBufferExtPipelineShader.Uniforms uniforms = null;
|
||||
if((stateExtBits & STATE_MATERIAL_TEXTURE) == 0) {
|
||||
uniforms = ((GBufferPipelineProgramInstance)userPointer[0]).shaderObject.uniforms;
|
||||
serial = DeferredStateManager.materialConstantsSerial;
|
||||
if(uniforms.materialConstantsSerial != serial) {
|
||||
uniforms.materialConstantsSerial = serial;
|
||||
float roughness = 1.0f - DeferredStateManager.materialConstantsRoughness;
|
||||
float metalness = DeferredStateManager.materialConstantsMetalness;
|
||||
float emission = DeferredStateManager.materialConstantsEmission;
|
||||
if(uniforms.materialConstantsRoughness != roughness || uniforms.materialConstantsMetalness != metalness
|
||||
|| uniforms.materialConstantsEmission != emission) {
|
||||
uniforms.materialConstantsRoughness = roughness;
|
||||
uniforms.materialConstantsMetalness = metalness;
|
||||
uniforms.materialConstantsEmission = emission;
|
||||
_wglUniform3f(uniforms.u_materialConstants3f, roughness, metalness, emission);
|
||||
}
|
||||
}
|
||||
}
|
||||
if((stateCoreBits & FixedFunctionShader.FixedFunctionState.STATE_HAS_ATTRIB_NORMAL) == 0) {
|
||||
if(uniforms == null) {
|
||||
uniforms = ((GBufferPipelineProgramInstance)userPointer[0]).shaderObject.uniforms;
|
||||
}
|
||||
int blockId = DeferredStateManager.constantBlock;
|
||||
if(uniforms.constantBlock != blockId) {
|
||||
uniforms.constantBlock = blockId;
|
||||
_wglUniform1f(uniforms.u_blockConstant1f, (blockId - 127) * 0.007874f);
|
||||
}
|
||||
}
|
||||
if((stateExtBits & STATE_CLIP_PLANE) != 0) {
|
||||
if(uniforms == null) {
|
||||
uniforms = ((GBufferPipelineProgramInstance)userPointer[0]).shaderObject.uniforms;
|
||||
}
|
||||
float clipPlaneYState = DeferredStateManager.clipPlaneY;
|
||||
if(uniforms.clipPlaneY != clipPlaneYState) {
|
||||
uniforms.clipPlaneY = clipPlaneYState;
|
||||
_wglUniform1f(uniforms.u_clipPlaneY1f, clipPlaneYState);
|
||||
}
|
||||
}
|
||||
if((stateExtBits & STATE_WAVING_BLOCKS) != 0) {
|
||||
if(uniforms == null) {
|
||||
uniforms = ((GBufferPipelineProgramInstance)userPointer[0]).shaderObject.uniforms;
|
||||
}
|
||||
serial = DeferredStateManager.passViewMatrixSerial;
|
||||
boolean modelDirty = false;
|
||||
if(serial != uniforms.viewMatrixSerial) {
|
||||
uniforms.viewMatrixSerial = serial;
|
||||
matrixCopyBuffer.clear();
|
||||
DeferredStateManager.passViewMatrix.store(matrixCopyBuffer);
|
||||
matrixCopyBuffer.flip();
|
||||
_wglUniformMatrix4fv(uniforms.u_viewMatrix4f, false, matrixCopyBuffer);
|
||||
modelDirty = true;
|
||||
}
|
||||
serial = GlStateManager.getModelViewSerial();
|
||||
if(uniforms.modelMatrixSerial != serial || modelDirty) {
|
||||
uniforms.modelMatrixSerial = serial;
|
||||
Matrix4f mat = GlStateManager.getModelViewReference();
|
||||
matrixCopyBuffer.clear();
|
||||
if(!DeferredStateManager.isShadowPassMatrixLoaded) {
|
||||
Matrix4f.mul(DeferredStateManager.passInverseViewMatrix, mat, tmpMatrix);
|
||||
tmpMatrix.store(matrixCopyBuffer);
|
||||
}else {
|
||||
mat.store(matrixCopyBuffer);
|
||||
}
|
||||
matrixCopyBuffer.flip();
|
||||
_wglUniformMatrix4fv(uniforms.u_modelMatrix4f, false, matrixCopyBuffer);
|
||||
}
|
||||
serial = DeferredStateManager.wavingBlockOffsetSerial;
|
||||
if(serial != uniforms.wavingBlockOffsetSerial) {
|
||||
uniforms.wavingBlockOffsetSerial = serial;
|
||||
float x = DeferredStateManager.wavingBlockOffsetX;
|
||||
float y = DeferredStateManager.wavingBlockOffsetY;
|
||||
float z = DeferredStateManager.wavingBlockOffsetZ;
|
||||
if(uniforms.wavingBlockOffsetX != x || uniforms.wavingBlockOffsetY != y || uniforms.wavingBlockOffsetZ != z) {
|
||||
uniforms.wavingBlockOffsetX = x;
|
||||
uniforms.wavingBlockOffsetY = y;
|
||||
uniforms.wavingBlockOffsetZ = z;
|
||||
_wglUniform3f(uniforms.u_wavingBlockOffset3f, x, y, z);
|
||||
}
|
||||
}
|
||||
serial = DeferredStateManager.wavingBlockParamSerial;
|
||||
if(serial != uniforms.wavingBlockParamSerial) {
|
||||
uniforms.wavingBlockParamSerial = serial;
|
||||
float x = DeferredStateManager.wavingBlockParamX;
|
||||
float y = DeferredStateManager.wavingBlockParamY;
|
||||
float z = DeferredStateManager.wavingBlockParamZ;
|
||||
float w = DeferredStateManager.wavingBlockParamW;
|
||||
if(uniforms.wavingBlockParamX != x || uniforms.wavingBlockParamY != y || uniforms.wavingBlockParamZ != z || uniforms.wavingBlockParamW != w) {
|
||||
uniforms.wavingBlockParamX = x;
|
||||
uniforms.wavingBlockParamY = y;
|
||||
uniforms.wavingBlockParamZ = z;
|
||||
uniforms.wavingBlockParamW = w;
|
||||
_wglUniform4f(uniforms.u_wavingBlockParam4f, x, y, z, w);
|
||||
}
|
||||
}
|
||||
}
|
||||
if((stateExtBits & STATE_FORWARD_RENDER) != 0) {
|
||||
if(uniforms == null) {
|
||||
uniforms = ((GBufferPipelineProgramInstance)userPointer[0]).shaderObject.uniforms;
|
||||
}
|
||||
serial = DeferredStateManager.passViewMatrixSerial;
|
||||
if(serial != uniforms.inverseViewMatrixSerial) {
|
||||
uniforms.inverseViewMatrixSerial = serial;
|
||||
matrixCopyBuffer.clear();
|
||||
DeferredStateManager.passInverseViewMatrix.store(matrixCopyBuffer);
|
||||
matrixCopyBuffer.flip();
|
||||
_wglUniformMatrix4fv(uniforms.u_inverseViewMatrix4f, false, matrixCopyBuffer);
|
||||
}
|
||||
if((stateExtBits & STATE_PARABOLOID_RENDER) != 0) {
|
||||
float farPlane = DeferredStateManager.gbufferFarPlane * 0.125f; //TODO
|
||||
if(farPlane != uniforms.farPlane1f) {
|
||||
uniforms.farPlane1f = farPlane;
|
||||
_wglUniform1f(uniforms.u_farPlane1f, farPlane);
|
||||
}
|
||||
}
|
||||
if((stateExtBits & STATE_REALISTIC_WATER_RENDER) != 0) {
|
||||
serial = DeferredStateManager.passViewMatrixSerial * 87917 + DeferredStateManager.passProjMatrixSerial;
|
||||
if(serial != uniforms.modelViewProjMatrixAltSerial) {
|
||||
uniforms.modelViewProjMatrixAltSerial = serial;
|
||||
Matrix4f.mul(DeferredStateManager.passProjMatrix, DeferredStateManager.passViewMatrix, tmpMatrix);
|
||||
matrixCopyBuffer.clear();
|
||||
tmpMatrix.store(matrixCopyBuffer);
|
||||
matrixCopyBuffer.flip();
|
||||
_wglUniformMatrix4fv(uniforms.u_modelViewProjMat4f_, false, matrixCopyBuffer);
|
||||
}
|
||||
serial = DeferredStateManager.waterWindOffsetSerial;
|
||||
if(serial != uniforms.waterWindOffsetSerial) {
|
||||
uniforms.waterWindOffsetSerial = serial;
|
||||
Vector4f vec = DeferredStateManager.u_waterWindOffset4f;
|
||||
_wglUniform4f(uniforms.u_waterWindOffset4f, vec.x, vec.y, vec.z, vec.w);
|
||||
}
|
||||
serial = DeferredStateManager.wavingBlockOffsetSerial;
|
||||
if(serial != uniforms.wavingBlockOffsetSerial) {
|
||||
uniforms.wavingBlockOffsetSerial = serial;
|
||||
float x = DeferredStateManager.wavingBlockOffsetX;
|
||||
float y = DeferredStateManager.wavingBlockOffsetY;
|
||||
float z = DeferredStateManager.wavingBlockOffsetZ;
|
||||
if(uniforms.wavingBlockOffsetX != x || uniforms.wavingBlockOffsetY != y || uniforms.wavingBlockOffsetZ != z) {
|
||||
uniforms.wavingBlockOffsetX = x;
|
||||
uniforms.wavingBlockOffsetY = y;
|
||||
uniforms.wavingBlockOffsetZ = z;
|
||||
_wglUniform3f(uniforms.u_wavingBlockOffset3f, x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}else if((stateExtBits & (STATE_SHADOW_RENDER | STATE_REALISTIC_WATER_MASK)) == 0) {
|
||||
if(uniforms == null) {
|
||||
uniforms = ((GBufferPipelineProgramInstance)userPointer[0]).shaderObject.uniforms;
|
||||
}
|
||||
if(uniforms.u_useEnvMap1f != null) {
|
||||
float use = DeferredStateManager.materialConstantsUseEnvMap ? 1.0f : 0.0f;
|
||||
if(uniforms.materialConstantsUseEnvMap != use) {
|
||||
uniforms.materialConstantsUseEnvMap = use;
|
||||
_wglUniform1f(uniforms.u_useEnvMap1f, use);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyPipeline(IProgramGL shaderProgram, int stateCoreBits, int stateExtBits, Object[] userPointer) {
|
||||
|
||||
}
|
||||
|
||||
private static String visualizeBits(int bits) {
|
||||
return FixedFunctionPipeline.visualizeBits(bits);
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program.GBufferExtPipelineShader;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class GBufferPipelineProgramInstance {
|
||||
|
||||
public final int coreState;
|
||||
public final int extState;
|
||||
|
||||
public GBufferExtPipelineShader shaderObject = null;
|
||||
|
||||
public GBufferPipelineProgramInstance(int coreState, int extState) {
|
||||
this.coreState = coreState;
|
||||
this.extState = extState;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,375 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.ExtGLEnums.*;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
|
||||
import net.lax1dude.eaglercraft.v1_8.EaglercraftRandom;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IBufferArrayGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IBufferGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.DrawUtils;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.EaglercraftGPU;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.GlStateManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program.PipelineShaderLensFlares;
|
||||
import net.lax1dude.eaglercraft.v1_8.vector.Matrix3f;
|
||||
import net.lax1dude.eaglercraft.v1_8.vector.Vector3f;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.MathHelper;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class LensFlareMeshRenderer {
|
||||
|
||||
public static final String streaksTextureLocation ="assets/eagler/glsl/deferred/lens_streaks.bmp";
|
||||
public static final String ghostsTextureLocation = "assets/eagler/glsl/deferred/lens_ghosts.bmp";
|
||||
public static final int ghostsSpriteCount = 4;
|
||||
|
||||
static IBufferArrayGL streaksVertexArray = null;
|
||||
static IBufferGL streaksVertexBuffer = null;
|
||||
|
||||
static IBufferArrayGL ghostsVertexArray = null;
|
||||
static IBufferGL ghostsVertexBuffer = null;
|
||||
|
||||
static PipelineShaderLensFlares streaksProgram = null;
|
||||
static PipelineShaderLensFlares ghostsProgram = null;
|
||||
|
||||
static int streaksTexture = -1;
|
||||
static int ghostsTexture = -1;
|
||||
|
||||
static int streaksVertexCount = 0;
|
||||
static int ghostsInstanceCount = 0;
|
||||
|
||||
static final Matrix3f tmpMat = new Matrix3f();
|
||||
static final Matrix3f tmpMat2 = new Matrix3f();
|
||||
static final Vector3f tmpVec = new Vector3f();
|
||||
|
||||
static void initialize() {
|
||||
destroy();
|
||||
|
||||
streaksProgram = PipelineShaderLensFlares.compileStreaks();
|
||||
streaksProgram.loadUniforms();
|
||||
|
||||
ghostsProgram = PipelineShaderLensFlares.compileGhosts();
|
||||
ghostsProgram.loadUniforms();
|
||||
|
||||
ByteBuffer copyBuffer = EagRuntime.allocateByteBuffer(16384);
|
||||
|
||||
for(int i = 0; i < 4; ++i) {
|
||||
pushStreakQuad(copyBuffer, 0.0f, 0.0f, 1.0f, 10.0f, 0.0f, 0.0f, 1.0f, 1.0f, (i * 3.14159f / 4.0f));
|
||||
pushStreakQuad(copyBuffer, 0.0f, 0.0f, 1.5f, 5.0f, 0.0f, 0.0f, 1.0f, 1.0f, ((i + 0.25f) * 3.14159f / 4.0f));
|
||||
pushStreakQuad(copyBuffer, 0.0f, 0.0f, 0.5f, 7.0f, 0.0f, 0.0f, 1.0f, 1.0f, ((i + 0.5f) * 3.14159f / 4.0f));
|
||||
pushStreakQuad(copyBuffer, 0.0f, 0.0f, 1.5f, 5.0f, 0.0f, 0.0f, 1.0f, 1.0f, ((i + 0.75f) * 3.14159f / 4.0f));
|
||||
}
|
||||
|
||||
copyBuffer.flip();
|
||||
streaksVertexCount = 64;
|
||||
|
||||
streaksVertexBuffer = _wglGenBuffers();
|
||||
EaglercraftGPU.bindGLArrayBuffer(streaksVertexBuffer);
|
||||
_wglBufferData(GL_ARRAY_BUFFER, copyBuffer, GL_STATIC_DRAW);
|
||||
|
||||
streaksVertexArray = _wglGenVertexArrays();
|
||||
EaglercraftGPU.bindGLBufferArray(streaksVertexArray);
|
||||
EaglercraftGPU.attachQuad16EmulationBuffer(16, true);
|
||||
|
||||
_wglEnableVertexAttribArray(0);
|
||||
_wglVertexAttribPointer(0, 2, GL_FLOAT, false, 16, 0);
|
||||
|
||||
_wglEnableVertexAttribArray(1);
|
||||
_wglVertexAttribPointer(1, 2, GL_FLOAT, false, 16, 8);
|
||||
|
||||
copyBuffer.clear();
|
||||
|
||||
ghostsInstanceCount = 0;
|
||||
|
||||
float streakIntensity2 = 10.0f;
|
||||
float scale = 5.0f;
|
||||
|
||||
pushGhostQuadAbberated(copyBuffer, 0.4f, 0.15f * scale, 2, 0.5f, 0.9f, 0.2f, 0.04f * streakIntensity2);
|
||||
pushGhostQuadAbberated(copyBuffer, 0.45f, 0.15f * scale, 2, 0.5f, 0.9f, 0.2f, 0.04f * streakIntensity2);
|
||||
|
||||
pushGhostQuadAbberated(copyBuffer, 0.6f, 0.1f * scale, 0, 0.5f, 0.9f, 0.2f, 0.045f * streakIntensity2);
|
||||
|
||||
pushGhostQuadAbberated(copyBuffer, 0.67f, 0.1f * scale, 0, 0.5f, 0.9f, 0.2f, 0.2f * streakIntensity2);
|
||||
pushGhostQuadAbberated(copyBuffer, 0.78f, 0.15f * scale, 1, 0.5f, 0.9f, 0.7f, 0.2f * streakIntensity2);
|
||||
|
||||
pushGhostQuadAbberated(copyBuffer, 1.0f, 0.15f * scale, 1, 0.5f, 0.9f, 0.7f, 0.1f * streakIntensity2);
|
||||
pushGhostQuadAbberated(copyBuffer, 1.04f, 0.15f * scale, 3, 0.5f, 0.5f, 0.7f, 0.1f * streakIntensity2);
|
||||
pushGhostQuadAbberated(copyBuffer, 1.07f, 0.1f * scale, 1, 0.7f, 0.7f, 0.7f, 0.2f * streakIntensity2);
|
||||
pushGhostQuad(copyBuffer, 1.11f, 0.1f * scale, 2, 0.2f, 0.2f, 0.7f, 0.05f * streakIntensity2);
|
||||
pushGhostQuad(copyBuffer, 1.11f, 0.3f * scale, 2, 0.2f, 0.7f, 0.2f, 0.05f * streakIntensity2);
|
||||
|
||||
pushGhostQuadAbberated(copyBuffer, 1.25f, 0.2f * scale, 0, 0.4f, 0.7f, 0.2f, 0.02f * streakIntensity2);
|
||||
pushGhostQuadAbberated(copyBuffer, 1.22f, 0.1f * scale, 2, 0.3f, 0.7f, 0.7f, 0.05f * streakIntensity2);
|
||||
pushGhostQuadAbberated(copyBuffer, 1.27f, 0.1f * scale, 0, 0.5f, 0.7f, 0.5f, 0.15f * streakIntensity2);
|
||||
pushGhostQuadAbberated(copyBuffer, 1.30f, 0.08f * scale, 0, 0.7f, 0.7f, 0.7f, 0.15f * streakIntensity2);
|
||||
|
||||
pushGhostQuadAbberated(copyBuffer, 1.45f, 0.3f * scale, 2, 0.3f, 0.7f, 0.2f, 0.02f * streakIntensity2);
|
||||
pushGhostQuadAbberated(copyBuffer, 1.55f, 0.1f * scale, 2, 0.3f, 0.7f, 0.7f, 0.05f * streakIntensity2);
|
||||
pushGhostQuadAbberated(copyBuffer, 1.59f, 0.1f * scale, 0, 0.5f, 0.7f, 0.5f, 0.15f * streakIntensity2);
|
||||
pushGhostQuadAbberated(copyBuffer, 2.0f, 0.3f * scale, 3, 0.3f, 0.7f, 0.2f, 0.03f * streakIntensity2);
|
||||
pushGhostQuadAbberated(copyBuffer, 1.98f, 0.2f * scale, 1, 0.3f, 0.7f, 0.2f, 0.04f * streakIntensity2);
|
||||
pushGhostQuadAbberated(copyBuffer, 2.02f, 0.2f * scale, 1, 0.3f, 0.7f, 0.2f, 0.04f * streakIntensity2);
|
||||
|
||||
copyBuffer.flip();
|
||||
|
||||
ghostsVertexArray = _wglGenVertexArrays();
|
||||
EaglercraftGPU.bindGLBufferArray(ghostsVertexArray);
|
||||
EaglercraftGPU.bindGLArrayBuffer(DrawUtils.standardQuadVBO);
|
||||
|
||||
_wglEnableVertexAttribArray(0);
|
||||
_wglVertexAttribPointer(0, 2, GL_FLOAT, false, 12, 0);
|
||||
_wglVertexAttribDivisor(0, 0);
|
||||
|
||||
ghostsVertexBuffer = _wglGenBuffers();
|
||||
EaglercraftGPU.bindGLArrayBuffer(ghostsVertexBuffer);
|
||||
_wglBufferData(GL_ARRAY_BUFFER, copyBuffer, GL_STATIC_DRAW);
|
||||
|
||||
_wglEnableVertexAttribArray(1);
|
||||
_wglVertexAttribPointer(1, 2, GL_FLOAT, false, 36, 0);
|
||||
_wglVertexAttribDivisor(1, 1);
|
||||
|
||||
_wglEnableVertexAttribArray(2);
|
||||
_wglVertexAttribPointer(2, 4, GL_FLOAT, false, 36, 8);
|
||||
_wglVertexAttribDivisor(2, 1);
|
||||
|
||||
_wglEnableVertexAttribArray(3);
|
||||
_wglVertexAttribPointer(3, 3, GL_FLOAT, false, 36, 24);
|
||||
_wglVertexAttribDivisor(3, 1);
|
||||
|
||||
streaksTexture = GlStateManager.generateTexture();
|
||||
GlStateManager.bindTexture(streaksTexture);
|
||||
byte[] flareTex = EagRuntime.getResourceBytes(streaksTextureLocation);
|
||||
if(flareTex == null) {
|
||||
throw new RuntimeException("Could not locate: " + streaksTextureLocation);
|
||||
}
|
||||
try(DataInputStream dis = new DataInputStream(new ByteArrayInputStream(flareTex))) {
|
||||
loadFlareTexture(copyBuffer, dis);
|
||||
}catch(IOException ex) {
|
||||
EagRuntime.freeByteBuffer(copyBuffer);
|
||||
throw new RuntimeException("Could not load: " + streaksTextureLocation, ex);
|
||||
}
|
||||
|
||||
ghostsTexture = GlStateManager.generateTexture();
|
||||
GlStateManager.bindTexture(ghostsTexture);
|
||||
flareTex = EagRuntime.getResourceBytes(ghostsTextureLocation);
|
||||
if(flareTex == null) {
|
||||
throw new RuntimeException("Could not locate: " + ghostsTextureLocation);
|
||||
}
|
||||
try(DataInputStream dis = new DataInputStream(new ByteArrayInputStream(flareTex))) {
|
||||
loadFlareTexture(copyBuffer, dis);
|
||||
}catch(IOException ex) {
|
||||
EagRuntime.freeByteBuffer(copyBuffer);
|
||||
throw new RuntimeException("Could not load: " + ghostsTextureLocation, ex);
|
||||
}
|
||||
|
||||
EagRuntime.freeByteBuffer(copyBuffer);
|
||||
}
|
||||
|
||||
static void loadFlareTexture(ByteBuffer copyBuffer, DataInputStream dis) throws IOException {
|
||||
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
||||
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
_wglPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
int mip = 0;
|
||||
while(dis.read() == 'E') {
|
||||
int w = dis.readShort();
|
||||
int h = dis.readShort();
|
||||
copyBuffer.clear();
|
||||
for(int i = 0, l = w * h; i < l; ++i) {
|
||||
copyBuffer.put((byte)dis.read());
|
||||
}
|
||||
copyBuffer.flip();
|
||||
_wglTexImage2D(GL_TEXTURE_2D, mip++, _GL_R8, w, h, 0, GL_RED, GL_UNSIGNED_BYTE, copyBuffer);
|
||||
}
|
||||
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, mip - 1);
|
||||
_wglPixelStorei(GL_UNPACK_ALIGNMENT, 4);
|
||||
}
|
||||
|
||||
static void pushStreakQuad(ByteBuffer copyBuffer, float x, float y, float w, float h, float tx, float ty, float tw,
|
||||
float th, float rotation) {
|
||||
tmpMat.m00 = MathHelper.cos(rotation);
|
||||
tmpMat.m01 = MathHelper.sin(rotation);
|
||||
tmpMat.m10 = -tmpMat.m01;
|
||||
tmpMat.m11 = tmpMat.m00;
|
||||
tmpMat.m20 = x;
|
||||
tmpMat.m21 = y;
|
||||
|
||||
tmpVec.x = -w;
|
||||
tmpVec.y = -h;
|
||||
tmpVec.z = 1.0f;
|
||||
Matrix3f.transform(tmpMat, tmpVec, tmpVec);
|
||||
|
||||
copyBuffer.putFloat(tmpVec.x);
|
||||
copyBuffer.putFloat(tmpVec.y);
|
||||
copyBuffer.putFloat(tx);
|
||||
copyBuffer.putFloat(ty);
|
||||
|
||||
tmpVec.x = w;
|
||||
tmpVec.y = -h;
|
||||
tmpVec.z = 1.0f;
|
||||
Matrix3f.transform(tmpMat, tmpVec, tmpVec);
|
||||
|
||||
copyBuffer.putFloat(tmpVec.x);
|
||||
copyBuffer.putFloat(tmpVec.y);
|
||||
copyBuffer.putFloat(tx + tw);
|
||||
copyBuffer.putFloat(ty);
|
||||
|
||||
tmpVec.x = w;
|
||||
tmpVec.y = h;
|
||||
tmpVec.z = 1.0f;
|
||||
Matrix3f.transform(tmpMat, tmpVec, tmpVec);
|
||||
|
||||
copyBuffer.putFloat(tmpVec.x);
|
||||
copyBuffer.putFloat(tmpVec.y);
|
||||
copyBuffer.putFloat(tx + tw);
|
||||
copyBuffer.putFloat(ty + th);
|
||||
|
||||
tmpVec.x = -w;
|
||||
tmpVec.y = h;
|
||||
tmpVec.z = 1.0f;
|
||||
Matrix3f.transform(tmpMat, tmpVec, tmpVec);
|
||||
|
||||
copyBuffer.putFloat(tmpVec.x);
|
||||
copyBuffer.putFloat(tmpVec.y);
|
||||
copyBuffer.putFloat(tx);
|
||||
copyBuffer.putFloat(ty + th);
|
||||
}
|
||||
|
||||
static void pushGhostQuadAbberated(ByteBuffer copyBuffer, float offset, float scale, int sprite, float r, float g, float b, float a) {
|
||||
pushGhostQuad(copyBuffer, offset, scale, sprite, 0.0f, g, b, a);
|
||||
pushGhostQuad(copyBuffer, offset + 0.005f, scale, sprite, r, 0.0f, 0.0f, a);
|
||||
}
|
||||
|
||||
static void pushGhostQuad(ByteBuffer copyBuffer, float offset, float scale, int sprite, float r, float g, float b, float a) {
|
||||
copyBuffer.putFloat(offset);
|
||||
copyBuffer.putFloat(scale);
|
||||
copyBuffer.putFloat(0.0f);
|
||||
copyBuffer.putFloat((float)sprite / ghostsSpriteCount);
|
||||
copyBuffer.putFloat(1.0f);
|
||||
copyBuffer.putFloat(1.0f / ghostsSpriteCount);
|
||||
copyBuffer.putFloat(r * a);
|
||||
copyBuffer.putFloat(g * a);
|
||||
copyBuffer.putFloat(b * a);
|
||||
++ghostsInstanceCount;
|
||||
}
|
||||
|
||||
static void drawLensFlares(float sunScreenX, float sunScreenY) {
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.blendFunc(GL_ONE, GL_ONE);
|
||||
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE2);
|
||||
GlStateManager.bindTexture(EaglerDeferredPipeline.instance.sunOcclusionValueTexture);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE1);
|
||||
GlStateManager.bindTexture(EaglerDeferredPipeline.instance.exposureBlendTexture);
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(streaksTexture);
|
||||
|
||||
streaksProgram.useProgram();
|
||||
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
float aspectRatio = (float)mc.displayHeight / (float)mc.displayWidth;
|
||||
|
||||
float fov = 90.0f / mc.entityRenderer.getFOVModifier(EaglerDeferredPipeline.instance.getPartialTicks(), true);
|
||||
float size = 0.075f * fov * (1.0f + MathHelper.sqrt_float(sunScreenX * sunScreenX + sunScreenY * sunScreenY));
|
||||
|
||||
tmpMat.setIdentity();
|
||||
tmpMat.m00 = aspectRatio * 2.0f * size;
|
||||
tmpMat.m11 = size;
|
||||
tmpMat.m20 = sunScreenX;
|
||||
tmpMat.m21 = sunScreenY;
|
||||
|
||||
float rotation = sunScreenX * sunScreenX * Math.signum(sunScreenX) + sunScreenY * sunScreenY * Math.signum(sunScreenY);
|
||||
|
||||
tmpMat2.setIdentity();
|
||||
tmpMat2.m00 = MathHelper.cos(rotation);
|
||||
tmpMat2.m01 = MathHelper.sin(rotation);
|
||||
tmpMat2.m10 = -tmpMat2.m01;
|
||||
tmpMat2.m11 = tmpMat2.m00;
|
||||
Matrix3f.mul(tmpMat, tmpMat2, tmpMat);
|
||||
|
||||
EaglerDeferredPipeline.uniformMatrixHelper(streaksProgram.uniforms.u_sunFlareMatrix3f, tmpMat);
|
||||
|
||||
Vector3f v = DeferredStateManager.currentSunLightColor;
|
||||
float mag = 1.0f + DeferredStateManager.currentSunAngle.y * 0.8f;
|
||||
if(mag > 1.0f) {
|
||||
mag = 1.0f - (mag - 1.0f) * 20.0f;
|
||||
if(mag < 0.0f) {
|
||||
mag = 0.0f;
|
||||
}
|
||||
}
|
||||
mag = 0.003f * (1.0f + mag * mag * mag * 4.0f);
|
||||
_wglUniform3f(streaksProgram.uniforms.u_flareColor3f, v.x * mag * 0.5f, v.y * mag * 0.5f, v.z * mag * 0.5f);
|
||||
|
||||
EaglercraftGPU.bindGLBufferArray(streaksVertexArray);
|
||||
_wglDrawElements(GL_TRIANGLES, streaksVertexCount + (streaksVertexCount >> 1), GL_UNSIGNED_SHORT, 0);
|
||||
|
||||
ghostsProgram.useProgram();
|
||||
|
||||
GlStateManager.setActiveTexture(GL_TEXTURE0);
|
||||
GlStateManager.bindTexture(ghostsTexture);
|
||||
|
||||
_wglUniform3f(ghostsProgram.uniforms.u_flareColor3f, v.x * mag, v.y * mag, v.z * mag);
|
||||
_wglUniform1f(ghostsProgram.uniforms.u_aspectRatio1f, aspectRatio);
|
||||
_wglUniform2f(ghostsProgram.uniforms.u_sunPosition2f, sunScreenX, sunScreenY);
|
||||
_wglUniform1f(ghostsProgram.uniforms.u_baseScale1f, fov);
|
||||
|
||||
EaglercraftGPU.bindGLBufferArray(ghostsVertexArray);
|
||||
_wglDrawArraysInstanced(GL_TRIANGLES, 0, 6, ghostsInstanceCount);
|
||||
|
||||
GlStateManager.disableBlend();
|
||||
}
|
||||
|
||||
static void destroy() {
|
||||
if(streaksVertexArray != null) {
|
||||
_wglDeleteVertexArrays(streaksVertexArray);
|
||||
streaksVertexArray = null;
|
||||
}
|
||||
if(streaksVertexBuffer != null) {
|
||||
_wglDeleteBuffers(streaksVertexBuffer);
|
||||
streaksVertexBuffer = null;
|
||||
}
|
||||
if(ghostsVertexArray != null) {
|
||||
_wglDeleteVertexArrays(ghostsVertexArray);
|
||||
ghostsVertexArray = null;
|
||||
}
|
||||
if(ghostsVertexBuffer != null) {
|
||||
_wglDeleteBuffers(ghostsVertexBuffer);
|
||||
ghostsVertexBuffer = null;
|
||||
}
|
||||
if(streaksTexture != -1) {
|
||||
GlStateManager.deleteTexture(streaksTexture);
|
||||
streaksTexture = -1;
|
||||
}
|
||||
if(ghostsTexture != -1) {
|
||||
GlStateManager.deleteTexture(ghostsTexture);
|
||||
ghostsTexture = -1;
|
||||
}
|
||||
if(streaksProgram != null) {
|
||||
streaksProgram.destroy();
|
||||
streaksProgram = null;
|
||||
}
|
||||
if(ghostsProgram != null) {
|
||||
ghostsProgram.destroy();
|
||||
ghostsProgram = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,135 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.ExtGLEnums.*;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IBufferArrayGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IBufferGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.EaglercraftGPU;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class LightSourceMesh {
|
||||
|
||||
public final ResourceLocation meshLocation;
|
||||
private final byte[] typeBytes;
|
||||
|
||||
private IBufferGL meshVBO = null;
|
||||
private IBufferGL meshIBO = null;
|
||||
private IBufferArrayGL meshVAO = null;
|
||||
|
||||
private int meshIndexType = -1;
|
||||
private int meshIndexCount = -1;
|
||||
|
||||
public LightSourceMesh(ResourceLocation is, String type) {
|
||||
meshLocation = is;
|
||||
typeBytes = type.getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public void load() throws IOException {
|
||||
destroy();
|
||||
try (DataInputStream is = new DataInputStream(
|
||||
Minecraft.getMinecraft().getResourceManager().getResource(meshLocation).getInputStream())) {
|
||||
if(is.read() != 0xEE || is.read() != 0xAA || is.read() != 0x66 || is.read() != '%') {
|
||||
throw new IOException("Bad file type for: " + meshLocation.toString());
|
||||
}
|
||||
byte[] bb = new byte[is.read()];
|
||||
is.read(bb);
|
||||
if(!Arrays.equals(bb, typeBytes)) {
|
||||
throw new IOException("Bad file type \"" + new String(bb, StandardCharsets.UTF_8) + "\" for: " + meshLocation.toString());
|
||||
}
|
||||
|
||||
int vboLength = is.readInt() * 6;
|
||||
byte[] readBuffer = new byte[vboLength];
|
||||
is.read(readBuffer);
|
||||
|
||||
ByteBuffer buf = EagRuntime.allocateByteBuffer(readBuffer.length);
|
||||
buf.put(readBuffer);
|
||||
buf.flip();
|
||||
|
||||
meshVBO = _wglGenBuffers();
|
||||
EaglercraftGPU.bindGLArrayBuffer(meshVBO);
|
||||
_wglBufferData(GL_ARRAY_BUFFER, buf, GL_STATIC_DRAW);
|
||||
|
||||
EagRuntime.freeByteBuffer(buf);
|
||||
|
||||
int iboLength = meshIndexCount = is.readInt();
|
||||
int iboType = is.read();
|
||||
iboLength *= iboType;
|
||||
switch(iboType) {
|
||||
case 1:
|
||||
meshIndexType = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
case 2:
|
||||
meshIndexType = GL_UNSIGNED_SHORT;
|
||||
break;
|
||||
case 4:
|
||||
meshIndexType = GL_UNSIGNED_INT;
|
||||
break;
|
||||
default:
|
||||
throw new IOException("Unsupported index buffer type: " + iboType);
|
||||
}
|
||||
|
||||
readBuffer = new byte[iboLength];
|
||||
is.read(readBuffer);
|
||||
|
||||
buf = EagRuntime.allocateByteBuffer(readBuffer.length);
|
||||
buf.put(readBuffer);
|
||||
buf.flip();
|
||||
|
||||
meshVAO = _wglGenVertexArrays();
|
||||
EaglercraftGPU.bindGLBufferArray(meshVAO);
|
||||
|
||||
meshIBO = _wglGenBuffers();
|
||||
_wglBindBuffer(GL_ELEMENT_ARRAY_BUFFER, meshIBO);
|
||||
_wglBufferData(GL_ELEMENT_ARRAY_BUFFER, buf, GL_STATIC_DRAW);
|
||||
EagRuntime.freeByteBuffer(buf);
|
||||
|
||||
EaglercraftGPU.bindGLArrayBuffer(meshVBO);
|
||||
|
||||
_wglEnableVertexAttribArray(0);
|
||||
_wglVertexAttribPointer(0, 3, _GL_HALF_FLOAT, false, 6, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawMeshVAO() {
|
||||
EaglercraftGPU.bindGLBufferArray(meshVAO);
|
||||
_wglDrawElements(GL_TRIANGLES, meshIndexCount, meshIndexType, 0);
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
if(meshVBO != null) {
|
||||
_wglDeleteBuffers(meshVBO);
|
||||
meshVBO = null;
|
||||
}
|
||||
if(meshIBO != null) {
|
||||
_wglDeleteBuffers(meshIBO);
|
||||
meshIBO = null;
|
||||
}
|
||||
if(meshVAO != null) {
|
||||
_wglDeleteVertexArrays(meshVAO);
|
||||
meshVAO = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public interface ListSerial<E> extends List<E> {
|
||||
|
||||
int getEaglerSerial();
|
||||
|
||||
void eaglerIncrSerial();
|
||||
|
||||
void eaglerResetCheck();
|
||||
|
||||
boolean eaglerCheck();
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class NameTagRenderer {
|
||||
|
||||
public static boolean doRenderNameTags = false;
|
||||
public static final NameTagRenderer[] nameTagsThisFrame = new NameTagRenderer[256];
|
||||
public static int nameTagsCount = 0;
|
||||
|
||||
static {
|
||||
for(int i = 0; i < nameTagsThisFrame.length; ++i) {
|
||||
nameTagsThisFrame[i] = new NameTagRenderer();
|
||||
}
|
||||
}
|
||||
|
||||
public Entity entityIn;
|
||||
public String str;
|
||||
public double x;
|
||||
public double y;
|
||||
public double z;
|
||||
public int maxDistance;
|
||||
public double dst2;
|
||||
|
||||
public static void renderNameTag(Entity entityIn, String str, double x, double y, double z, int maxDistance) {
|
||||
if(!doRenderNameTags || nameTagsCount >= nameTagsThisFrame.length) {
|
||||
return;
|
||||
}
|
||||
NameTagRenderer n = nameTagsThisFrame[nameTagsCount++];
|
||||
n.entityIn = entityIn;
|
||||
n.str = str;
|
||||
n.x = x;
|
||||
n.y = y;
|
||||
n.z = z;
|
||||
n.dst2 = x * x + y * y + z * z;
|
||||
n.maxDistance = maxDistance;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class ShaderPackInfo {
|
||||
|
||||
public final String name;
|
||||
public final String desc;
|
||||
public final String vers;
|
||||
public final String author;
|
||||
public final int apiVers;
|
||||
public final Set<String> supportedFeatures;
|
||||
|
||||
public final boolean WAVING_BLOCKS;
|
||||
public final boolean DYNAMIC_LIGHTS;
|
||||
public final boolean GLOBAL_AMBIENT_OCCLUSION;
|
||||
public final boolean SHADOWS_SUN;
|
||||
public final boolean SHADOWS_COLORED;
|
||||
public final boolean SHADOWS_SMOOTHED;
|
||||
public final boolean REFLECTIONS_PARABOLOID;
|
||||
public final boolean REALISTIC_WATER;
|
||||
public final boolean LIGHT_SHAFTS;
|
||||
public final boolean SCREEN_SPACE_REFLECTIONS;
|
||||
public final boolean POST_LENS_DISTORION;
|
||||
public final boolean POST_LENS_FLARES;
|
||||
public final boolean POST_BLOOM;
|
||||
public final boolean POST_FXAA;
|
||||
|
||||
public ShaderPackInfo(JSONObject json) {
|
||||
name = json.optString("name", "Untitled");
|
||||
desc = json.optString("desc", "No Description");
|
||||
vers = json.optString("vers", "Unknown");
|
||||
author = json.optString("author", "Unknown");
|
||||
apiVers = json.optInt("api_vers", -1);
|
||||
supportedFeatures = new HashSet();
|
||||
JSONArray features = json.getJSONArray("features");
|
||||
if(features.length() == 0) {
|
||||
throw new JSONException("No supported features list has been defined for this shader pack!");
|
||||
}
|
||||
for(int i = 0, l = features.length(); i < l; ++i) {
|
||||
supportedFeatures.add(features.getString(i));
|
||||
}
|
||||
WAVING_BLOCKS = supportedFeatures.contains("WAVING_BLOCKS");
|
||||
DYNAMIC_LIGHTS = supportedFeatures.contains("DYNAMIC_LIGHTS");
|
||||
GLOBAL_AMBIENT_OCCLUSION = supportedFeatures.contains("GLOBAL_AMBIENT_OCCLUSION");
|
||||
SHADOWS_SUN = supportedFeatures.contains("SHADOWS_SUN");
|
||||
SHADOWS_COLORED = supportedFeatures.contains("SHADOWS_COLORED");
|
||||
SHADOWS_SMOOTHED = supportedFeatures.contains("SHADOWS_SMOOTHED");
|
||||
REFLECTIONS_PARABOLOID = supportedFeatures.contains("REFLECTIONS_PARABOLOID");
|
||||
REALISTIC_WATER = supportedFeatures.contains("REALISTIC_WATER");
|
||||
LIGHT_SHAFTS = supportedFeatures.contains("LIGHT_SHAFTS");
|
||||
SCREEN_SPACE_REFLECTIONS = supportedFeatures.contains("SCREEN_SPACE_REFLECTIONS");
|
||||
POST_LENS_DISTORION = supportedFeatures.contains("POST_LENS_DISTORION");
|
||||
POST_LENS_FLARES = supportedFeatures.contains("POST_LENS_FLARES");
|
||||
POST_BLOOM = supportedFeatures.contains("POST_BLOOM");
|
||||
POST_FXAA = supportedFeatures.contains("POST_FXAA");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.resources.IResourceManagerReloadListener;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class ShaderPackInfoReloadListener implements IResourceManagerReloadListener {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger();
|
||||
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager mcResourceManager) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
try {
|
||||
mc.gameSettings.deferredShaderConf.reloadShaderPackInfo(mcResourceManager);
|
||||
}catch(IOException ex) {
|
||||
logger.info("Could not reload shader pack info!");
|
||||
logger.info(ex);
|
||||
logger.info("Shaders have been disabled");
|
||||
mc.gameSettings.shaders = false;
|
||||
}
|
||||
TextureMap tm = mc.getTextureMapBlocks();
|
||||
if(tm != null) {
|
||||
mc.getTextureMapBlocks().setEnablePBREagler(mc.gameSettings.shaders);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred;
|
||||
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public abstract class ShadersRenderPassFuture {
|
||||
|
||||
public static enum PassType {
|
||||
MAIN, SHADOW
|
||||
}
|
||||
|
||||
protected float x;
|
||||
protected float y;
|
||||
protected float z;
|
||||
protected float partialTicks;
|
||||
|
||||
public float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public float getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public float getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public ShadersRenderPassFuture(float x, float y, float z, float partialTicks) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.partialTicks = partialTicks;
|
||||
}
|
||||
|
||||
public ShadersRenderPassFuture(Entity e, float partialTicks) {
|
||||
this.x = (float)((e.posX - e.prevPosX) * partialTicks + e.prevPosX - TileEntityRendererDispatcher.staticPlayerX);
|
||||
this.y = (float)((e.posY - e.prevPosY) * partialTicks + e.prevPosY - TileEntityRendererDispatcher.staticPlayerY);
|
||||
this.z = (float)((e.posZ - e.prevPosZ) * partialTicks + e.prevPosZ - TileEntityRendererDispatcher.staticPlayerZ);
|
||||
}
|
||||
|
||||
public ShadersRenderPassFuture(Entity e) {
|
||||
this(e, EaglerDeferredPipeline.instance.getPartialTicks());
|
||||
}
|
||||
|
||||
public abstract void draw(PassType pass);
|
||||
|
||||
private final float[] tmp = new float[1];
|
||||
|
||||
public float[] tmpValue() {
|
||||
return tmp;
|
||||
}
|
||||
}
|
@ -0,0 +1,199 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.ExtGLEnums.*;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IBufferArrayGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IBufferGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.EaglercraftGPU;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.GlStateManager;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class SkyboxRenderer {
|
||||
|
||||
public final ResourceLocation skyboxLocation;
|
||||
|
||||
private IBufferGL skyboxVBO = null;
|
||||
private IBufferGL skyboxIBO = null;
|
||||
private IBufferArrayGL skyboxVAO = null;
|
||||
private int normalsLUT = -1;
|
||||
private int atmosphereLUTWidth = -1;
|
||||
private int atmosphereLUTHeight = -1;
|
||||
|
||||
private int skyboxIndexType = -1;
|
||||
private int skyboxIndexStride = -1;
|
||||
private int skyboxIndexCount = -1;
|
||||
|
||||
private int skyboxTopIndexOffset = -1;
|
||||
private int skyboxTopIndexCount = -1;
|
||||
|
||||
private int skyboxBottomIndexOffset = -1;
|
||||
private int skyboxBottomIndexCount = -1;
|
||||
|
||||
public SkyboxRenderer(ResourceLocation is) {
|
||||
skyboxLocation = is;
|
||||
}
|
||||
|
||||
public void load() throws IOException {
|
||||
destroy();
|
||||
try (DataInputStream is = new DataInputStream(
|
||||
Minecraft.getMinecraft().getResourceManager().getResource(skyboxLocation).getInputStream())) {
|
||||
if(is.read() != 0xEE || is.read() != 0xAA || is.read() != 0x66 || is.read() != '%') {
|
||||
throw new IOException("Bad file type for: " + skyboxLocation.toString());
|
||||
}
|
||||
byte[] bb = new byte[is.read()];
|
||||
is.read(bb);
|
||||
if(!Arrays.equals(bb, new byte[] { 's', 'k', 'y', 'b', 'o', 'x' })) {
|
||||
throw new IOException("Bad file type \"" + new String(bb, StandardCharsets.UTF_8) + "\" for: " + skyboxLocation.toString());
|
||||
}
|
||||
atmosphereLUTWidth = is.readUnsignedShort();
|
||||
atmosphereLUTHeight = is.readUnsignedShort();
|
||||
byte[] readBuffer = new byte[atmosphereLUTWidth * atmosphereLUTHeight * 4];
|
||||
is.read(readBuffer);
|
||||
|
||||
ByteBuffer buf = EagRuntime.allocateByteBuffer(readBuffer.length);
|
||||
buf.put(readBuffer);
|
||||
buf.flip();
|
||||
|
||||
normalsLUT = GlStateManager.generateTexture();
|
||||
GlStateManager.bindTexture(normalsLUT);
|
||||
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
_wglTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, atmosphereLUTWidth, atmosphereLUTHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf);
|
||||
|
||||
EagRuntime.freeByteBuffer(buf);
|
||||
|
||||
skyboxTopIndexOffset = is.readInt();
|
||||
skyboxTopIndexCount = is.readInt();
|
||||
skyboxBottomIndexOffset = is.readInt();
|
||||
skyboxBottomIndexCount = is.readInt();
|
||||
|
||||
int vboLength = is.readInt() * 8;
|
||||
readBuffer = new byte[vboLength];
|
||||
is.read(readBuffer);
|
||||
|
||||
buf = EagRuntime.allocateByteBuffer(readBuffer.length);
|
||||
buf.put(readBuffer);
|
||||
buf.flip();
|
||||
|
||||
skyboxVBO = _wglGenBuffers();
|
||||
EaglercraftGPU.bindGLArrayBuffer(skyboxVBO);
|
||||
_wglBufferData(GL_ARRAY_BUFFER, buf, GL_STATIC_DRAW);
|
||||
|
||||
EagRuntime.freeByteBuffer(buf);
|
||||
|
||||
int iboLength = skyboxIndexCount = is.readInt();
|
||||
int iboType = is.read();
|
||||
iboLength *= iboType;
|
||||
switch(iboType) {
|
||||
case 1:
|
||||
skyboxIndexType = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
case 2:
|
||||
skyboxIndexType = GL_UNSIGNED_SHORT;
|
||||
break;
|
||||
case 4:
|
||||
skyboxIndexType = GL_UNSIGNED_INT;
|
||||
break;
|
||||
default:
|
||||
throw new IOException("Unsupported index buffer type: " + iboType);
|
||||
}
|
||||
|
||||
skyboxIndexStride = iboType;
|
||||
|
||||
readBuffer = new byte[iboLength];
|
||||
is.read(readBuffer);
|
||||
|
||||
buf = EagRuntime.allocateByteBuffer(readBuffer.length);
|
||||
buf.put(readBuffer);
|
||||
buf.flip();
|
||||
|
||||
skyboxVAO = _wglGenVertexArrays();
|
||||
EaglercraftGPU.bindGLBufferArray(skyboxVAO);
|
||||
|
||||
skyboxIBO = _wglGenBuffers();
|
||||
_wglBindBuffer(GL_ELEMENT_ARRAY_BUFFER, skyboxIBO);
|
||||
_wglBufferData(GL_ELEMENT_ARRAY_BUFFER, buf, GL_STATIC_DRAW);
|
||||
EagRuntime.freeByteBuffer(buf);
|
||||
|
||||
EaglercraftGPU.bindGLArrayBuffer(skyboxVBO);
|
||||
|
||||
_wglEnableVertexAttribArray(0);
|
||||
_wglVertexAttribPointer(0, 3, _GL_HALF_FLOAT, false, 8, 0);
|
||||
|
||||
_wglEnableVertexAttribArray(1);
|
||||
_wglVertexAttribPointer(1, 2, GL_UNSIGNED_BYTE, true, 8, 6);
|
||||
}
|
||||
}
|
||||
|
||||
public int getNormalsLUT() {
|
||||
return normalsLUT;
|
||||
}
|
||||
|
||||
public int getAtmosLUTWidth() {
|
||||
return atmosphereLUTWidth;
|
||||
}
|
||||
|
||||
public int getAtmosLUTHeight() {
|
||||
return atmosphereLUTHeight;
|
||||
}
|
||||
|
||||
public void drawTop() {
|
||||
EaglercraftGPU.bindGLBufferArray(skyboxVAO);
|
||||
_wglDrawElements(GL_TRIANGLES, skyboxTopIndexCount, skyboxIndexType, skyboxTopIndexOffset * skyboxIndexStride);
|
||||
}
|
||||
|
||||
public void drawBottom() {
|
||||
EaglercraftGPU.bindGLBufferArray(skyboxVAO);
|
||||
_wglDrawElements(GL_TRIANGLES, skyboxBottomIndexCount, skyboxIndexType, skyboxBottomIndexOffset * skyboxIndexStride);
|
||||
}
|
||||
|
||||
public void drawFull() {
|
||||
EaglercraftGPU.bindGLBufferArray(skyboxVAO);
|
||||
_wglDrawElements(GL_TRIANGLES, skyboxIndexCount, skyboxIndexType, 0);
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
if(skyboxVBO != null) {
|
||||
_wglDeleteBuffers(skyboxVBO);
|
||||
skyboxVBO = null;
|
||||
}
|
||||
if(skyboxIBO != null) {
|
||||
_wglDeleteBuffers(skyboxIBO);
|
||||
skyboxVBO = null;
|
||||
}
|
||||
if(skyboxVAO != null) {
|
||||
_wglDeleteVertexArrays(skyboxVAO);
|
||||
skyboxVBO = null;
|
||||
}
|
||||
if(normalsLUT != -1) {
|
||||
GlStateManager.deleteTexture(normalsLUT);
|
||||
normalsLUT = -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class VertexMarkerState {
|
||||
|
||||
public static float localCoordDeriveHackX = 1.0f;
|
||||
public static float localCoordDeriveHackY = 1.001f;
|
||||
public static float localCoordDeriveHackZ = 1.0f;
|
||||
public static int markId = 0;
|
||||
|
||||
}
|
@ -0,0 +1,133 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.gui;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program.ShaderSource;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class GuiShaderConfig extends GuiScreen {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger();
|
||||
|
||||
boolean shaderStartState = false;
|
||||
|
||||
private final GuiScreen parent;
|
||||
private GuiShaderConfigList listView;
|
||||
|
||||
private String title;
|
||||
private GuiButton enableDisableButton;
|
||||
|
||||
public GuiShaderConfig(GuiScreen parent) {
|
||||
this.parent = parent;
|
||||
this.shaderStartState = Minecraft.getMinecraft().gameSettings.shaders;
|
||||
}
|
||||
|
||||
public void initGui() {
|
||||
this.title = I18n.format("shaders.gui.title");
|
||||
this.buttonList.clear();
|
||||
this.buttonList.add(enableDisableButton = new GuiButton(0, width / 2 - 155, height - 30, 150, 20, I18n.format("shaders.gui.enable")
|
||||
+ ": " + (mc.gameSettings.shaders ? I18n.format("gui.yes") : I18n.format("gui.no"))));
|
||||
this.buttonList.add(new GuiButton(1, width / 2 + 5, height - 30, 150, 20, I18n.format("gui.done")));
|
||||
if(listView == null) {
|
||||
this.listView = new GuiShaderConfigList(this, mc);
|
||||
}else {
|
||||
this.listView.resize();
|
||||
}
|
||||
}
|
||||
|
||||
protected void actionPerformed(GuiButton btn) {
|
||||
if(btn.id == 0) {
|
||||
mc.gameSettings.shaders = !mc.gameSettings.shaders;
|
||||
listView.setAllDisabled(!mc.gameSettings.shaders);
|
||||
enableDisableButton.displayString = I18n.format("shaders.gui.enable") + ": "
|
||||
+ (mc.gameSettings.shaders ? I18n.format("gui.yes") : I18n.format("gui.no"));
|
||||
}else if(btn.id == 1) {
|
||||
mc.displayGuiScreen(parent);
|
||||
}
|
||||
}
|
||||
|
||||
public void onGuiClosed() {
|
||||
if(shaderStartState != mc.gameSettings.shaders || listView.isDirty()) {
|
||||
mc.gameSettings.saveOptions();
|
||||
if(shaderStartState != mc.gameSettings.shaders) {
|
||||
mc.loadingScreen.eaglerShowRefreshResources();
|
||||
mc.refreshResources();
|
||||
}else {
|
||||
logger.info("Reloading shaders...");
|
||||
try {
|
||||
mc.gameSettings.deferredShaderConf.reloadShaderPackInfo(mc.getResourceManager());
|
||||
}catch(IOException ex) {
|
||||
logger.info("Could not reload shader pack info!");
|
||||
logger.info(ex);
|
||||
logger.info("Shaders have been disabled");
|
||||
mc.gameSettings.shaders = false;
|
||||
mc.refreshResources();
|
||||
return;
|
||||
}
|
||||
|
||||
if(mc.gameSettings.shaders) {
|
||||
ShaderSource.clearCache();
|
||||
}
|
||||
|
||||
if (mc.renderGlobal != null) {
|
||||
mc.renderGlobal.loadRenderers();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void handleMouseInput() throws IOException {
|
||||
super.handleMouseInput();
|
||||
listView.handleMouseInput();
|
||||
}
|
||||
|
||||
protected void mouseClicked(int parInt1, int parInt2, int parInt3) {
|
||||
super.mouseClicked(parInt1, parInt2, parInt3);
|
||||
listView.mouseClicked(parInt1, parInt2, parInt3);
|
||||
}
|
||||
|
||||
protected void mouseReleased(int i, int j, int k) {
|
||||
super.mouseReleased(i, j, k);
|
||||
listView.mouseReleased(i, j, k);
|
||||
}
|
||||
|
||||
public void drawScreen(int i, int j, float f) {
|
||||
this.drawBackground(0);
|
||||
listView.drawScreen(i, j, f);
|
||||
drawCenteredString(this.fontRendererObj, title, this.width / 2, 15, 16777215);
|
||||
super.drawScreen(i, j, f);
|
||||
listView.postRender(i, j, f);
|
||||
}
|
||||
|
||||
void renderTooltip(List<String> txt, int x, int y) {
|
||||
drawHoveringText(txt, x, y);
|
||||
}
|
||||
|
||||
FontRenderer getFontRenderer() {
|
||||
return fontRendererObj;
|
||||
}
|
||||
|
||||
Minecraft getMinecraft() {
|
||||
return mc;
|
||||
}
|
||||
}
|
@ -0,0 +1,657 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.GlStateManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.EaglerDeferredConfig;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.ShaderPackInfo;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiListExtended;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class GuiShaderConfigList extends GuiListExtended {
|
||||
|
||||
public static final ResourceLocation shaderPackIcon = new ResourceLocation("eagler:glsl/deferred/shader_pack_icon.png");
|
||||
|
||||
private final GuiShaderConfig screen;
|
||||
|
||||
private final List<IGuiListEntry> list = new ArrayList();
|
||||
|
||||
private static abstract class ShaderOption {
|
||||
|
||||
private final String label;
|
||||
private final List<String> desc;
|
||||
|
||||
private ShaderOption(String label, List<String> desc) {
|
||||
this.label = label;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
protected abstract String getDisplayValue();
|
||||
|
||||
protected abstract void toggleOption(GuiButton button, int dir);
|
||||
|
||||
protected abstract boolean getDirty();
|
||||
|
||||
}
|
||||
|
||||
private static List<String> loadDescription(String key) {
|
||||
List<String> ret = new ArrayList();
|
||||
String msg;
|
||||
int i = 0;
|
||||
while(true) {
|
||||
if((msg = I18n.format(key + '.' + i)).equals(key + '.' + i)) {
|
||||
if(!I18n.format(key + '.' + (i + 1)).equals(key + '.' + (i + 1))) {
|
||||
msg = "";
|
||||
}else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
ret.add(msg);
|
||||
++i;
|
||||
}
|
||||
if(ret.size() == 0) {
|
||||
ret.add("" + EnumChatFormatting.GRAY + EnumChatFormatting.ITALIC + "(no description found)");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static String loadShaderLbl(String key) {
|
||||
return I18n.format("shaders.gui.option." + key + ".label");
|
||||
}
|
||||
|
||||
private static List<String> loadShaderDesc(String key) {
|
||||
return loadDescription("shaders.gui.option." + key + ".desc");
|
||||
}
|
||||
|
||||
private static String getColoredOnOff(boolean state, EnumChatFormatting on, EnumChatFormatting off) {
|
||||
return state ? "" + on + I18n.format("options.on") : "" + off + I18n.format("options.off");
|
||||
}
|
||||
|
||||
private void addAllOptions(List<ShaderOption> opts) {
|
||||
for(int i = 0, l = opts.size(); i < l; ++i) {
|
||||
ShaderOption opt1 = opts.get(i);
|
||||
if(++i >= l) {
|
||||
list.add(new ListEntryButtonRow(opt1, null, null));
|
||||
break;
|
||||
}
|
||||
ShaderOption opt2 = opts.get(i);
|
||||
if(++i >= l) {
|
||||
list.add(new ListEntryButtonRow(opt1, opt2, null));
|
||||
break;
|
||||
}
|
||||
list.add(new ListEntryButtonRow(opt1, opt2, opts.get(i)));
|
||||
}
|
||||
}
|
||||
|
||||
public GuiShaderConfigList(GuiShaderConfig screen, Minecraft mcIn) {
|
||||
super(mcIn, screen.width, screen.height, 32, screen.height - 40, 30);
|
||||
this.screen = screen;
|
||||
this.list.add(new ListEntryHeader("Current Shader Pack:"));
|
||||
this.list.add(new ListEntryPackInfo());
|
||||
this.list.add(new ListEntrySpacing());
|
||||
this.list.add(new ListEntrySpacing());
|
||||
this.list.add(new ListEntryHeader(I18n.format("shaders.gui.headerTier1")));
|
||||
List<ShaderOption> opts = new ArrayList();
|
||||
EaglerDeferredConfig conf = mcIn.gameSettings.deferredShaderConf;
|
||||
if(conf.shaderPackInfo.WAVING_BLOCKS) {
|
||||
opts.add(new ShaderOption(loadShaderLbl("WAVING_BLOCKS"), loadShaderDesc("WAVING_BLOCKS")) {
|
||||
private final boolean originalValue = conf.wavingBlocks;
|
||||
@Override
|
||||
protected String getDisplayValue() {
|
||||
return getColoredOnOff(conf.wavingBlocks, EnumChatFormatting.GREEN, EnumChatFormatting.RED);
|
||||
}
|
||||
@Override
|
||||
protected void toggleOption(GuiButton button, int dir) {
|
||||
conf.wavingBlocks = !conf.wavingBlocks;
|
||||
}
|
||||
@Override
|
||||
protected boolean getDirty() {
|
||||
return conf.wavingBlocks != originalValue;
|
||||
}
|
||||
});
|
||||
}
|
||||
if(conf.shaderPackInfo.DYNAMIC_LIGHTS) {
|
||||
opts.add(new ShaderOption(loadShaderLbl("DYNAMIC_LIGHTS"), loadShaderDesc("DYNAMIC_LIGHTS")) {
|
||||
private final boolean originalValue = conf.dynamicLights;
|
||||
@Override
|
||||
protected String getDisplayValue() {
|
||||
return getColoredOnOff(conf.dynamicLights, EnumChatFormatting.GREEN, EnumChatFormatting.RED);
|
||||
}
|
||||
@Override
|
||||
protected void toggleOption(GuiButton button, int dir) {
|
||||
conf.dynamicLights = !conf.dynamicLights;
|
||||
}
|
||||
@Override
|
||||
protected boolean getDirty() {
|
||||
return conf.dynamicLights != originalValue;
|
||||
}
|
||||
});
|
||||
}
|
||||
if(conf.shaderPackInfo.GLOBAL_AMBIENT_OCCLUSION) {
|
||||
opts.add(new ShaderOption(loadShaderLbl("GLOBAL_AMBIENT_OCCLUSION"), loadShaderDesc("GLOBAL_AMBIENT_OCCLUSION")) {
|
||||
private final boolean originalValue = conf.ssao;
|
||||
@Override
|
||||
protected String getDisplayValue() {
|
||||
return getColoredOnOff(conf.ssao, EnumChatFormatting.GREEN, EnumChatFormatting.RED);
|
||||
}
|
||||
@Override
|
||||
protected void toggleOption(GuiButton button, int dir) {
|
||||
conf.ssao = !conf.ssao;
|
||||
}
|
||||
@Override
|
||||
protected boolean getDirty() {
|
||||
return conf.ssao != originalValue;
|
||||
}
|
||||
});
|
||||
}
|
||||
if(conf.shaderPackInfo.SHADOWS_SUN) {
|
||||
opts.add(new ShaderOption(loadShaderLbl("SHADOWS_SUN"), loadShaderDesc("SHADOWS_SUN")) {
|
||||
private final int originalValue = conf.shadowsSun;
|
||||
@Override
|
||||
protected String getDisplayValue() {
|
||||
return conf.shadowsSun == 0 ? "" + EnumChatFormatting.RED + "0" : "" + EnumChatFormatting.YELLOW + (1 << (conf.shadowsSun + 3));
|
||||
}
|
||||
@Override
|
||||
protected void toggleOption(GuiButton button, int dir) {
|
||||
conf.shadowsSun = (conf.shadowsSun + dir + 5) % 5;
|
||||
}
|
||||
@Override
|
||||
protected boolean getDirty() {
|
||||
return conf.shadowsSun != originalValue;
|
||||
}
|
||||
});
|
||||
}
|
||||
if(conf.shaderPackInfo.REFLECTIONS_PARABOLOID) {
|
||||
opts.add(new ShaderOption(loadShaderLbl("REFLECTIONS_PARABOLOID"), loadShaderDesc("REFLECTIONS_PARABOLOID")) {
|
||||
private final boolean originalValue = conf.useEnvMap;
|
||||
@Override
|
||||
protected String getDisplayValue() {
|
||||
return getColoredOnOff(conf.useEnvMap, EnumChatFormatting.GREEN, EnumChatFormatting.RED);
|
||||
}
|
||||
@Override
|
||||
protected void toggleOption(GuiButton button, int dir) {
|
||||
conf.useEnvMap = !conf.useEnvMap;
|
||||
}
|
||||
@Override
|
||||
protected boolean getDirty() {
|
||||
return conf.useEnvMap != originalValue;
|
||||
}
|
||||
});
|
||||
}
|
||||
if(conf.shaderPackInfo.POST_LENS_DISTORION) {
|
||||
opts.add(new ShaderOption(loadShaderLbl("POST_LENS_DISTORION"), loadShaderDesc("POST_LENS_DISTORION")) {
|
||||
private final boolean originalValue = conf.lensDistortion;
|
||||
@Override
|
||||
protected String getDisplayValue() {
|
||||
return getColoredOnOff(conf.lensDistortion, EnumChatFormatting.GREEN, EnumChatFormatting.RED);
|
||||
}
|
||||
@Override
|
||||
protected void toggleOption(GuiButton button, int dir) {
|
||||
conf.lensDistortion = !conf.lensDistortion;
|
||||
}
|
||||
@Override
|
||||
protected boolean getDirty() {
|
||||
return conf.lensDistortion != originalValue;
|
||||
}
|
||||
});
|
||||
}
|
||||
if(conf.shaderPackInfo.POST_LENS_FLARES) {
|
||||
opts.add(new ShaderOption(loadShaderLbl("POST_LENS_FLARES"), loadShaderDesc("POST_LENS_FLARES")) {
|
||||
private final boolean originalValue = conf.lensFlares;
|
||||
@Override
|
||||
protected String getDisplayValue() {
|
||||
return getColoredOnOff(conf.lensFlares, EnumChatFormatting.GREEN, EnumChatFormatting.RED);
|
||||
}
|
||||
@Override
|
||||
protected void toggleOption(GuiButton button, int dir) {
|
||||
conf.lensFlares = !conf.lensFlares;
|
||||
}
|
||||
@Override
|
||||
protected boolean getDirty() {
|
||||
return conf.lensFlares != originalValue;
|
||||
}
|
||||
});
|
||||
}
|
||||
if(conf.shaderPackInfo.POST_FXAA) {
|
||||
opts.add(new ShaderOption(loadShaderLbl("POST_FXAA"), loadShaderDesc("POST_FXAA")) {
|
||||
private final boolean originalValue = conf.fxaa;
|
||||
@Override
|
||||
protected String getDisplayValue() {
|
||||
return getColoredOnOff(conf.fxaa, EnumChatFormatting.GREEN, EnumChatFormatting.RED);
|
||||
}
|
||||
@Override
|
||||
protected void toggleOption(GuiButton button, int dir) {
|
||||
conf.fxaa = !conf.fxaa;
|
||||
}
|
||||
@Override
|
||||
protected boolean getDirty() {
|
||||
return conf.fxaa != originalValue;
|
||||
}
|
||||
});
|
||||
}
|
||||
this.addAllOptions(opts);
|
||||
opts.clear();
|
||||
this.list.add(new ListEntryHeader(I18n.format("shaders.gui.headerTier2")));
|
||||
if(conf.shaderPackInfo.SHADOWS_COLORED) {
|
||||
opts.add(new ShaderOption(loadShaderLbl("SHADOWS_COLORED"), loadShaderDesc("SHADOWS_COLORED")) {
|
||||
private final boolean originalValue = conf.shadowsColored;
|
||||
@Override
|
||||
protected String getDisplayValue() {
|
||||
return getColoredOnOff(conf.shadowsColored, EnumChatFormatting.GREEN, EnumChatFormatting.RED);
|
||||
}
|
||||
@Override
|
||||
protected void toggleOption(GuiButton button, int dir) {
|
||||
conf.shadowsColored = !conf.shadowsColored;
|
||||
}
|
||||
@Override
|
||||
protected boolean getDirty() {
|
||||
return conf.shadowsColored != originalValue;
|
||||
}
|
||||
});
|
||||
}
|
||||
if(conf.shaderPackInfo.SHADOWS_SMOOTHED) {
|
||||
opts.add(new ShaderOption(loadShaderLbl("SHADOWS_SMOOTHED"), loadShaderDesc("SHADOWS_SMOOTHED")) {
|
||||
private final boolean originalValue = conf.shadowsSmoothed;
|
||||
@Override
|
||||
protected String getDisplayValue() {
|
||||
return getColoredOnOff(conf.shadowsSmoothed, EnumChatFormatting.GREEN, EnumChatFormatting.RED);
|
||||
}
|
||||
@Override
|
||||
protected void toggleOption(GuiButton button, int dir) {
|
||||
conf.shadowsSmoothed = !conf.shadowsSmoothed;
|
||||
}
|
||||
@Override
|
||||
protected boolean getDirty() {
|
||||
return conf.shadowsSmoothed != originalValue;
|
||||
}
|
||||
});
|
||||
}
|
||||
if(conf.shaderPackInfo.REALISTIC_WATER) {
|
||||
opts.add(new ShaderOption(loadShaderLbl("REALISTIC_WATER"), loadShaderDesc("REALISTIC_WATER")) {
|
||||
private final boolean originalValue = conf.realisticWater;
|
||||
@Override
|
||||
protected String getDisplayValue() {
|
||||
return getColoredOnOff(conf.realisticWater, EnumChatFormatting.GREEN, EnumChatFormatting.RED);
|
||||
}
|
||||
@Override
|
||||
protected void toggleOption(GuiButton button, int dir) {
|
||||
conf.realisticWater = !conf.realisticWater;
|
||||
}
|
||||
@Override
|
||||
protected boolean getDirty() {
|
||||
return conf.realisticWater != originalValue;
|
||||
}
|
||||
});
|
||||
}
|
||||
if(conf.shaderPackInfo.POST_BLOOM) {
|
||||
opts.add(new ShaderOption(loadShaderLbl("POST_BLOOM"), loadShaderDesc("POST_BLOOM")) {
|
||||
private final boolean originalValue = conf.bloom;
|
||||
@Override
|
||||
protected String getDisplayValue() {
|
||||
return getColoredOnOff(conf.bloom, EnumChatFormatting.GREEN, EnumChatFormatting.RED);
|
||||
}
|
||||
@Override
|
||||
protected void toggleOption(GuiButton button, int dir) {
|
||||
conf.bloom = !conf.bloom;
|
||||
}
|
||||
@Override
|
||||
protected boolean getDirty() {
|
||||
return conf.bloom != originalValue;
|
||||
}
|
||||
});
|
||||
}
|
||||
if(conf.shaderPackInfo.LIGHT_SHAFTS) {
|
||||
opts.add(new ShaderOption(loadShaderLbl("LIGHT_SHAFTS"), loadShaderDesc("LIGHT_SHAFTS")) {
|
||||
private final boolean originalValue = conf.lightShafts;
|
||||
@Override
|
||||
protected String getDisplayValue() {
|
||||
return getColoredOnOff(conf.lightShafts, EnumChatFormatting.GREEN, EnumChatFormatting.RED);
|
||||
}
|
||||
@Override
|
||||
protected void toggleOption(GuiButton button, int dir) {
|
||||
conf.lightShafts = !conf.lightShafts;
|
||||
}
|
||||
@Override
|
||||
protected boolean getDirty() {
|
||||
return conf.lightShafts != originalValue;
|
||||
}
|
||||
});
|
||||
}
|
||||
if(conf.shaderPackInfo.SCREEN_SPACE_REFLECTIONS) {
|
||||
opts.add(new ShaderOption(loadShaderLbl("SCREEN_SPACE_REFLECTIONS"), loadShaderDesc("SCREEN_SPACE_REFLECTIONS")) {
|
||||
private final boolean originalValue = conf.raytracing;
|
||||
@Override
|
||||
protected String getDisplayValue() {
|
||||
return getColoredOnOff(conf.raytracing, EnumChatFormatting.GREEN, EnumChatFormatting.RED);
|
||||
}
|
||||
@Override
|
||||
protected void toggleOption(GuiButton button, int dir) {
|
||||
conf.raytracing = !conf.raytracing;
|
||||
}
|
||||
@Override
|
||||
protected boolean getDirty() {
|
||||
return conf.raytracing != originalValue;
|
||||
}
|
||||
});
|
||||
}
|
||||
this.addAllOptions(opts);
|
||||
setAllDisabled(!mcIn.gameSettings.shaders);
|
||||
}
|
||||
|
||||
public void setAllDisabled(boolean disable) {
|
||||
for(int i = 0, l = list.size(); i < l; ++i) {
|
||||
IGuiListEntry etr = list.get(i);
|
||||
if(etr instanceof ListEntryButtonRow) {
|
||||
ListEntryButtonRow etr2 = (ListEntryButtonRow)etr;
|
||||
if(etr2.button1 != null) {
|
||||
etr2.button1.enabled = !disable;
|
||||
}
|
||||
if(etr2.button2 != null) {
|
||||
etr2.button2.enabled = !disable;
|
||||
}
|
||||
if(etr2.button3 != null) {
|
||||
etr2.button3.enabled = !disable;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGuiListEntry getListEntry(int var1) {
|
||||
return list.get(var1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSize() {
|
||||
return list.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getListWidth() {
|
||||
return 225;
|
||||
}
|
||||
|
||||
private class ListEntryPackInfo implements IGuiListEntry {
|
||||
|
||||
@Override
|
||||
public void drawEntry(int entryID, int x, int y, int getListWidth, int var5, int var6, int var7, boolean var8) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
ShaderPackInfo info = mc.gameSettings.deferredShaderConf.shaderPackInfo;
|
||||
String packNameString = info.name;
|
||||
int strWidth = mc.fontRendererObj.getStringWidth(packNameString) + 40;
|
||||
if(strWidth < 210) {
|
||||
strWidth = 210;
|
||||
}
|
||||
int x2 = strWidth > getListWidth * 2 ? x : x + (getListWidth - strWidth) / 2;
|
||||
screen.drawString(mc.fontRendererObj, packNameString, x2 + 38, y + 3, 0xFFFFFF);
|
||||
screen.drawString(mc.fontRendererObj, "Author: " + info.author, x2 + 38, y + 14, 0xBBBBBB);
|
||||
screen.drawString(mc.fontRendererObj, "Version: " + info.vers, x2 + 38, y + 25, 0x888888);
|
||||
List<String> descLines = mc.fontRendererObj.listFormattedStringToWidth(info.desc, strWidth);
|
||||
for(int i = 0, l = descLines.size(); i < l; ++i) {
|
||||
screen.drawString(mc.fontRendererObj, descLines.get(i), x2, y + 43 + i * 9, 0xBBBBBB);
|
||||
}
|
||||
mc.getTextureManager().bindTexture(shaderPackIcon);
|
||||
GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
Gui.drawModalRectWithCustomSizedTexture(x2, y + 2, 0, 0, 32, 32, 32, 32);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(int var1, int var2, int var3) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(int var1, int var2, int var3, int var4, int var5, int var6) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int var1, int var2, int var3, int var4, int var5, int var6) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class ListEntrySpacing implements IGuiListEntry {
|
||||
|
||||
@Override
|
||||
public void setSelected(int var1, int var2, int var3) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEntry(int var1, int var2, int var3, int var4, int var5, int var6, int var7, boolean var8) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(int var1, int var2, int var3, int var4, int var5, int var6) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int var1, int var2, int var3, int var4, int var5, int var6) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class ListEntryHeader implements IGuiListEntry {
|
||||
|
||||
private final String text;
|
||||
|
||||
private ListEntryHeader(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(int var1, int var2, int var3) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEntry(int entryID, int x, int y, int getListWidth, int var5, int var6, int var7, boolean var8) {
|
||||
screen.drawString(screen.getFontRenderer(), text, x, y + 10, 0xFFFFFF);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(int var1, int var2, int var3, int var4, int var5, int var6) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int var1, int var2, int var3, int var4, int var5, int var6) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class ListEntryButtonRow implements IGuiListEntry {
|
||||
|
||||
private final ShaderOption opt1;
|
||||
private final ShaderOption opt2;
|
||||
private final ShaderOption opt3;
|
||||
|
||||
private GuiButton button1;
|
||||
private GuiButton button2;
|
||||
private GuiButton button3;
|
||||
|
||||
private ListEntryButtonRow(ShaderOption opt1, ShaderOption opt2, ShaderOption opt3) {
|
||||
this.opt1 = opt1;
|
||||
this.opt2 = opt2;
|
||||
this.opt3 = opt3;
|
||||
if(this.opt1 != null) {
|
||||
this.button1 = new GuiButton(0, 0, 0, 73, 20, this.opt1.label + ": " + this.opt1.getDisplayValue());
|
||||
this.button1.fontScale = 0.78f - (this.opt1.label.length() * 0.01f);
|
||||
}
|
||||
if(this.opt2 != null) {
|
||||
this.button2 = new GuiButton(0, 0, 0, 73, 20, this.opt2.label + ": " + this.opt2.getDisplayValue());
|
||||
this.button2.fontScale = 0.78f - (this.opt2.label.length() * 0.01f);
|
||||
}
|
||||
if(this.opt3 != null) {
|
||||
this.button3 = new GuiButton(0, 0, 0, 73, 20, this.opt3.label + ": " + this.opt3.getDisplayValue());
|
||||
this.button3.fontScale = 0.78f - (this.opt3.label.length() * 0.01f);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(int var1, int var2, int var3) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEntry(int entryID, int x, int y, int getListWidth, int var5, int var6, int var7, boolean var8) {
|
||||
if(this.button1 != null) {
|
||||
this.button1.xPosition = x;
|
||||
this.button1.yPosition = y;
|
||||
this.button1.drawButton(mc, var6, var7);
|
||||
if(this.button1.isMouseOver() && this.button1.yPosition + 10 < bottom && this.button1.yPosition + 10 > top) {
|
||||
renderTooltip(var6, var7 + 15, this.opt1.desc);
|
||||
}
|
||||
}
|
||||
if(this.button2 != null) {
|
||||
this.button2.xPosition = x + 75;
|
||||
this.button2.yPosition = y;
|
||||
this.button2.drawButton(mc, var6, var7);
|
||||
if(this.button2.isMouseOver() && this.button2.yPosition + 10 < bottom && this.button2.yPosition + 10 > top) {
|
||||
renderTooltip(var6, var7 + 15, this.opt2.desc);
|
||||
}
|
||||
}
|
||||
if(this.button3 != null) {
|
||||
this.button3.xPosition = x + 150;
|
||||
this.button3.yPosition = y;
|
||||
this.button3.drawButton(mc, var6, var7);
|
||||
if(this.button3.isMouseOver() && this.button3.yPosition + 10 < bottom && this.button3.yPosition + 10 > top) {
|
||||
renderTooltip(var6, var7 + 15, this.opt3.desc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(int var1, int var2, int var3, int var4, int var5, int var6) {
|
||||
if(this.button1 != null) {
|
||||
if(this.button1.yPosition + 15 < bottom && this.button1.yPosition + 5 > top) {
|
||||
if(this.button1.mousePressed(mc, var2, var3)) {
|
||||
this.opt1.toggleOption(this.button1, var4 == 1 ? -1 : 1);
|
||||
this.button1.displayString = (this.opt1.getDirty() ? "*" : "") + this.opt1.label + ": " + this.opt1.getDisplayValue();
|
||||
this.button1.playPressSound(mc.getSoundHandler());
|
||||
}
|
||||
}
|
||||
}
|
||||
if(this.button2 != null) {
|
||||
if(this.button2.yPosition + 15 < bottom && this.button2.yPosition + 5 > top) {
|
||||
if(this.button2.mousePressed(mc, var2, var3)) {
|
||||
this.opt2.toggleOption(this.button2, var4 == 1 ? -1 : 1);
|
||||
this.button2.displayString = (this.opt2.getDirty() ? "*" : "") + this.opt2.label + ": " + this.opt2.getDisplayValue();
|
||||
this.button2.playPressSound(mc.getSoundHandler());
|
||||
}
|
||||
}
|
||||
}
|
||||
if(this.button3 != null) {
|
||||
if(this.button3.yPosition + 15 < bottom && this.button3.yPosition + 5 > top) {
|
||||
if(this.button3.mousePressed(mc, var2, var3)) {
|
||||
this.opt3.toggleOption(this.button3, var4 == 1 ? -1 : 1);
|
||||
this.button3.displayString = (this.opt3.getDirty() ? "*" : "") + this.opt3.label + ": " + this.opt3.getDisplayValue();
|
||||
this.button3.playPressSound(mc.getSoundHandler());
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int var1, int var2, int var3, int var4, int var5, int var6) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private List<String> tooltipToShow = null;
|
||||
private int tooltipToShowX = 0;
|
||||
private int tooltipToShowY = 0;
|
||||
|
||||
public void postRender(int mx, int my, float partialTicks) {
|
||||
if(tooltipToShow != null) {
|
||||
screen.width *= 2;
|
||||
screen.height *= 2;
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.scale(0.5f, 0.5f, 0.5f);
|
||||
screen.renderTooltip(tooltipToShow, tooltipToShowX * 2, tooltipToShowY * 2);
|
||||
GlStateManager.popMatrix();
|
||||
screen.width /= 2;
|
||||
screen.height /= 2;
|
||||
tooltipToShow = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void renderTooltip(int x, int y, List<String> msg) {
|
||||
renderTooltip(x, y, 250, msg);
|
||||
}
|
||||
|
||||
private void renderTooltip(int x, int y, int width, List<String> msg) {
|
||||
ArrayList tooltipList = new ArrayList(msg.size() * 2);
|
||||
for(int i = 0, l = msg.size(); i < l; ++i) {
|
||||
String s = msg.get(i);
|
||||
if(s.length() > 0) {
|
||||
tooltipList.addAll(screen.getFontRenderer().listFormattedStringToWidth(s, width));
|
||||
}else {
|
||||
tooltipList.add("");
|
||||
}
|
||||
}
|
||||
tooltipToShow = tooltipList;
|
||||
tooltipToShowX = x;
|
||||
tooltipToShowY = y;
|
||||
}
|
||||
|
||||
public boolean isDirty() {
|
||||
for(int i = 0, l = list.size(); i < l; ++i) {
|
||||
IGuiListEntry etr = list.get(i);
|
||||
if(etr instanceof ListEntryButtonRow) {
|
||||
ListEntryButtonRow etr2 = (ListEntryButtonRow)etr;
|
||||
if(etr2.opt1 != null) {
|
||||
if(etr2.opt1.getDirty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if(etr2.opt2 != null) {
|
||||
if(etr2.opt2.getDirty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if(etr2.opt3 != null) {
|
||||
if(etr2.opt3.getDirty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void resize() {
|
||||
width = screen.width;
|
||||
height = screen.height;
|
||||
top = 32;
|
||||
bottom = screen.height - 40;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.gui;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class GuiShadersNotSupported extends GuiScreen {
|
||||
|
||||
private GuiScreen parent;
|
||||
private String reason;
|
||||
|
||||
public GuiShadersNotSupported(GuiScreen parent, String reason) {
|
||||
this.parent = parent;
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
public void initGui() {
|
||||
this.buttonList.clear();
|
||||
this.buttonList.add(new GuiButton(0, width / 2 - 100, height / 2 + 10, I18n.format("gui.back")));
|
||||
}
|
||||
|
||||
public void drawScreen(int i, int j, float var3) {
|
||||
this.drawBackground(0);
|
||||
drawCenteredString(fontRendererObj, I18n.format("shaders.gui.unsupported.title"), width / 2, height / 2 - 30, 0xFFFFFF);
|
||||
drawCenteredString(fontRendererObj, reason, width / 2, height / 2 - 10, 11184810);
|
||||
super.drawScreen(i, j, var3);
|
||||
}
|
||||
|
||||
protected void actionPerformed(GuiButton parGuiButton) {
|
||||
if(parGuiButton.id == 0) {
|
||||
mc.displayGuiScreen(parent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,130 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class GBufferExtPipelineShader extends ShaderProgram<GBufferExtPipelineShader.Uniforms> {
|
||||
|
||||
public final int coreState;
|
||||
public final int extState;
|
||||
|
||||
public GBufferExtPipelineShader(IProgramGL program, int coreState, int extState) {
|
||||
super(program, new Uniforms());
|
||||
this.coreState = coreState;
|
||||
this.extState = extState;
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public int materialConstantsSerial = -1;
|
||||
|
||||
public float materialConstantsRoughness = -999.0f;
|
||||
public float materialConstantsMetalness = -999.0f;
|
||||
public float materialConstantsEmission = -999.0f;
|
||||
public float materialConstantsUseEnvMap = -999.0f;
|
||||
|
||||
public IUniformGL u_materialConstants3f = null;
|
||||
public IUniformGL u_useEnvMap1f = null;
|
||||
|
||||
public int constantBlock = -999;
|
||||
public float clipPlaneY = -999.0f;
|
||||
|
||||
public IUniformGL u_blockConstant1f = null;
|
||||
public IUniformGL u_clipPlaneY1f = null;
|
||||
|
||||
public int modelMatrixSerial = -1;
|
||||
public int viewMatrixSerial = -1;
|
||||
public int inverseViewMatrixSerial = -1;
|
||||
public int modelViewProjMatrixAltSerial = -1;
|
||||
public IUniformGL u_modelMatrix4f = null;
|
||||
public IUniformGL u_viewMatrix4f = null;
|
||||
public IUniformGL u_inverseViewMatrix4f = null;
|
||||
public IUniformGL u_modelViewProjMat4f_ = null;
|
||||
|
||||
public int waterWindOffsetSerial = -1;
|
||||
public IUniformGL u_waterWindOffset4f = null;
|
||||
|
||||
public int wavingBlockOffsetSerial = -1;
|
||||
|
||||
public float wavingBlockOffsetX = -999.0f;
|
||||
public float wavingBlockOffsetY = -999.0f;
|
||||
public float wavingBlockOffsetZ = -999.0f;
|
||||
|
||||
public IUniformGL u_wavingBlockOffset3f = null;
|
||||
|
||||
public int wavingBlockParamSerial = -1;
|
||||
|
||||
public float wavingBlockParamX = -999.0f;
|
||||
public float wavingBlockParamY = -999.0f;
|
||||
public float wavingBlockParamZ = -999.0f;
|
||||
public float wavingBlockParamW = -999.0f;
|
||||
|
||||
public IUniformGL u_wavingBlockParam4f = null;
|
||||
|
||||
public int u_chunkLightingDataBlockBinding = -1;
|
||||
public int u_worldLightingDataBlockBinding = -1;
|
||||
|
||||
public IUniformGL u_farPlane1f = null;
|
||||
public float farPlane1f = -1.0f;
|
||||
|
||||
Uniforms() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
u_materialConstants3f = _wglGetUniformLocation(prog, "u_materialConstants3f");
|
||||
u_useEnvMap1f = _wglGetUniformLocation(prog, "u_useEnvMap1f");
|
||||
u_blockConstant1f = _wglGetUniformLocation(prog, "u_blockConstant1f");
|
||||
u_clipPlaneY1f = _wglGetUniformLocation(prog, "u_clipPlaneY1f");
|
||||
u_modelMatrix4f = _wglGetUniformLocation(prog, "u_modelMatrix4f");
|
||||
u_viewMatrix4f = _wglGetUniformLocation(prog, "u_viewMatrix4f");
|
||||
u_inverseViewMatrix4f = _wglGetUniformLocation(prog, "u_inverseViewMatrix4f");
|
||||
u_modelViewProjMat4f_ = _wglGetUniformLocation(prog, "u_modelViewProjMat4f_");
|
||||
u_wavingBlockOffset3f = _wglGetUniformLocation(prog, "u_wavingBlockOffset3f");
|
||||
u_wavingBlockParam4f = _wglGetUniformLocation(prog, "u_wavingBlockParam4f");
|
||||
u_farPlane1f = _wglGetUniformLocation(prog, "u_farPlane1f");
|
||||
u_waterWindOffset4f = _wglGetUniformLocation(prog, "u_waterWindOffset4f");
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_samplerNormalMaterial"), 2);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_metalsLUT"), 3);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_sunShadowDepthTexture"), 4);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_environmentMap"), 5);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_brdfLUT"), 6);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_reflectionMap"), 7);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_refractionMap"), 8);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_normalMap"), 9);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_irradianceMap"), 10);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_lightShaftsTexture"), 11);
|
||||
int blockIndex = _wglGetUniformBlockIndex(prog, "u_worldLightingData");
|
||||
if(blockIndex != -1) {
|
||||
_wglUniformBlockBinding(prog, blockIndex, 0);
|
||||
u_worldLightingDataBlockBinding = 0;
|
||||
}else {
|
||||
u_worldLightingDataBlockBinding = -1;
|
||||
}
|
||||
blockIndex = _wglGetUniformBlockIndex(prog, "u_chunkLightingData");
|
||||
if(blockIndex != -1) {
|
||||
_wglUniformBlockBinding(prog, blockIndex, 1);
|
||||
u_chunkLightingDataBlockBinding = 1;
|
||||
}else {
|
||||
u_chunkLightingDataBlockBinding = -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public interface IProgramUniforms {
|
||||
|
||||
void loadUniforms(IProgramGL prog);
|
||||
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderAccelParticleForward extends ShaderProgram<PipelineShaderAccelParticleForward.Uniforms> {
|
||||
|
||||
public static PipelineShaderAccelParticleForward compile(boolean dynamicLights, int sunShadows) {
|
||||
IShaderGL accelParticleVSH = ShaderCompiler.compileShader("accel_particle_forward", GL_VERTEX_SHADER,
|
||||
ShaderSource.accel_particle_vsh, "COMPILE_FORWARD_VSH");
|
||||
IShaderGL accelParticleFSH = null;
|
||||
try {
|
||||
List<String> lst = new ArrayList(2);
|
||||
if(dynamicLights) {
|
||||
lst.add("COMPILE_DYNAMIC_LIGHTS");
|
||||
}
|
||||
if(sunShadows > 0) {
|
||||
int lods = sunShadows - 1;
|
||||
if(lods > 2) {
|
||||
lods = 2;
|
||||
}
|
||||
lst.add("COMPILE_SUN_SHADOW_LOD" + lods);
|
||||
}
|
||||
accelParticleFSH = ShaderCompiler.compileShader("accel_particle_forward", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.accel_particle_forward_fsh, lst);
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("accel_particle_forward", accelParticleVSH, accelParticleFSH);
|
||||
return new PipelineShaderAccelParticleForward(prog);
|
||||
}finally {
|
||||
if(accelParticleVSH != null) {
|
||||
accelParticleVSH.free();
|
||||
}
|
||||
if(accelParticleFSH != null) {
|
||||
accelParticleFSH.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderAccelParticleForward(IProgramGL prog) {
|
||||
super(prog, new Uniforms());
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public IUniformGL u_modelViewMatrix4f = null;
|
||||
public IUniformGL u_projectionMatrix4f = null;
|
||||
public IUniformGL u_inverseViewMatrix4f = null;
|
||||
public IUniformGL u_texCoordSize2f_particleSize1f = null;
|
||||
public IUniformGL u_transformParam_1_2_3_4_f = null;
|
||||
public IUniformGL u_transformParam_5_f = null;
|
||||
public IUniformGL u_textureYScale2f = null;
|
||||
|
||||
public int u_chunkLightingDataBlockBinding = -1;
|
||||
public int u_worldLightingDataBlockBinding = -1;
|
||||
|
||||
private Uniforms() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
u_modelViewMatrix4f = _wglGetUniformLocation(prog, "u_modelViewMatrix4f");
|
||||
u_projectionMatrix4f = _wglGetUniformLocation(prog, "u_projectionMatrix4f");
|
||||
u_inverseViewMatrix4f = _wglGetUniformLocation(prog, "u_inverseViewMatrix4f");
|
||||
u_texCoordSize2f_particleSize1f = _wglGetUniformLocation(prog, "u_texCoordSize2f_particleSize1f");
|
||||
u_transformParam_1_2_3_4_f = _wglGetUniformLocation(prog, "u_transformParam_1_2_3_4_f");
|
||||
u_transformParam_5_f = _wglGetUniformLocation(prog, "u_transformParam_5_f");
|
||||
u_textureYScale2f = _wglGetUniformLocation(prog, "u_textureYScale2f");
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_diffuseTexture"), 0);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_samplerNormalMaterial"), 2);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_metalsLUT"), 3);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_sunShadowDepthTexture"), 4);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_irradianceMap"), 10);
|
||||
int blockIndex = _wglGetUniformBlockIndex(prog, "u_worldLightingData");
|
||||
if(blockIndex != -1) {
|
||||
_wglUniformBlockBinding(prog, blockIndex, 0);
|
||||
u_worldLightingDataBlockBinding = 0;
|
||||
}else {
|
||||
u_worldLightingDataBlockBinding = -1;
|
||||
}
|
||||
blockIndex = _wglGetUniformBlockIndex(prog, "u_chunkLightingData");
|
||||
if(blockIndex != -1) {
|
||||
_wglUniformBlockBinding(prog, blockIndex, 1);
|
||||
u_chunkLightingDataBlockBinding = 1;
|
||||
}else {
|
||||
u_chunkLightingDataBlockBinding = -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderAccelParticleGBuffer extends ShaderProgram<PipelineShaderAccelParticleGBuffer.Uniforms> {
|
||||
|
||||
public static PipelineShaderAccelParticleGBuffer compile() {
|
||||
IShaderGL accelParticleVSH = ShaderCompiler.compileShader("accel_particle_gbuffer", GL_VERTEX_SHADER,
|
||||
ShaderSource.accel_particle_vsh, "COMPILE_GBUFFER_VSH");
|
||||
IShaderGL accelParticleFSH = null;
|
||||
try {
|
||||
accelParticleFSH = ShaderCompiler.compileShader("accel_particle_gbuffer", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.accel_particle_gbuffer_fsh);
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("accel_particle_gbuffer", accelParticleVSH, accelParticleFSH);
|
||||
return new PipelineShaderAccelParticleGBuffer(prog);
|
||||
}finally {
|
||||
if(accelParticleVSH != null) {
|
||||
accelParticleVSH.free();
|
||||
}
|
||||
if(accelParticleFSH != null) {
|
||||
accelParticleFSH.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderAccelParticleGBuffer(IProgramGL program) {
|
||||
super(program, new Uniforms());
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public IUniformGL u_matrixTransform = null;
|
||||
public IUniformGL u_texCoordSize2f_particleSize1f = null;
|
||||
public IUniformGL u_transformParam_1_2_3_4_f = null;
|
||||
public IUniformGL u_transformParam_5_f = null;
|
||||
public IUniformGL u_textureYScale2f = null;
|
||||
|
||||
private Uniforms() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
u_matrixTransform = _wglGetUniformLocation(prog, "u_matrixTransform");
|
||||
u_texCoordSize2f_particleSize1f = _wglGetUniformLocation(prog, "u_texCoordSize2f_particleSize1f");
|
||||
u_transformParam_1_2_3_4_f = _wglGetUniformLocation(prog, "u_transformParam_1_2_3_4_f");
|
||||
u_transformParam_5_f = _wglGetUniformLocation(prog, "u_transformParam_5_f");
|
||||
u_textureYScale2f = _wglGetUniformLocation(prog, "u_textureYScale2f");
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_diffuseTexture"), 0);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_samplerNormalMaterial"), 2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderBloomBlurPass extends ShaderProgram<PipelineShaderBloomBlurPass.Uniforms> {
|
||||
|
||||
public static PipelineShaderBloomBlurPass compile() {
|
||||
IShaderGL bloomBlurPass = ShaderCompiler.compileShader("post_bloom_blur", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.post_bloom_blur_fsh);
|
||||
try {
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("post_bloom_blur", SharedPipelineShaders.deferred_local, bloomBlurPass);
|
||||
return new PipelineShaderBloomBlurPass(prog);
|
||||
}finally {
|
||||
if(bloomBlurPass != null) {
|
||||
bloomBlurPass.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderBloomBlurPass(IProgramGL prog) {
|
||||
super(prog, new Uniforms());
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public IUniformGL u_sampleOffset2f = null;
|
||||
public IUniformGL u_outputSize4f = null;
|
||||
|
||||
private Uniforms() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
u_sampleOffset2f = _wglGetUniformLocation(prog, "u_sampleOffset2f");
|
||||
u_outputSize4f = _wglGetUniformLocation(prog, "u_outputSize4f");
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_inputTexture"), 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderBloomBrightPass extends ShaderProgram<PipelineShaderBloomBrightPass.Uniforms> {
|
||||
|
||||
public static PipelineShaderBloomBrightPass compile() throws ShaderException {
|
||||
IShaderGL bloomBrightPass = ShaderCompiler.compileShader("post_bloom_bright", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.post_bloom_bright_fsh);
|
||||
try {
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("post_bloom_bright", SharedPipelineShaders.deferred_local, bloomBrightPass);
|
||||
return new PipelineShaderBloomBrightPass(prog);
|
||||
}finally {
|
||||
if(bloomBrightPass != null) {
|
||||
bloomBrightPass.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderBloomBrightPass(IProgramGL prog) {
|
||||
super(prog, new Uniforms());
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public IUniformGL u_outputSize4f = null;
|
||||
|
||||
private Uniforms() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
u_outputSize4f = _wglGetUniformLocation(prog, "u_outputSize4f");
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_lightingHDRFramebufferTexture"), 0);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_framebufferLumaAvgInput"), 1);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_gbufferMaterialTexture"), 2);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_gbufferDepthTexture"), 3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderCloudsNoise3D extends ShaderProgram<PipelineShaderCloudsNoise3D.Uniforms> {
|
||||
|
||||
public static PipelineShaderCloudsNoise3D compile() {
|
||||
IShaderGL cloudsNoise3d = ShaderCompiler.compileShader("clouds_noise3d", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.clouds_noise3d_fsh);
|
||||
try {
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("clouds_noise3d", SharedPipelineShaders.deferred_local, cloudsNoise3d);
|
||||
return new PipelineShaderCloudsNoise3D(prog);
|
||||
}finally {
|
||||
if(cloudsNoise3d != null) {
|
||||
cloudsNoise3d.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderCloudsNoise3D(IProgramGL prog) {
|
||||
super(prog, new Uniforms());
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public IUniformGL u_textureSlice1f = null;
|
||||
public IUniformGL u_textureSize2f = null;
|
||||
public IUniformGL u_sampleOffsetMatrix4f = null;
|
||||
public IUniformGL u_cloudMovement3f = null;
|
||||
|
||||
private Uniforms() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
u_textureSlice1f = _wglGetUniformLocation(prog, "u_textureSlice1f");
|
||||
u_textureSize2f = _wglGetUniformLocation(prog, "u_textureSize2f");
|
||||
u_sampleOffsetMatrix4f = _wglGetUniformLocation(prog, "u_sampleOffsetMatrix4f");
|
||||
u_cloudMovement3f = _wglGetUniformLocation(prog, "u_cloudMovement3f");
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_noiseTexture"), 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderCloudsSample extends ShaderProgram<PipelineShaderCloudsSample.Uniforms> {
|
||||
|
||||
public static PipelineShaderCloudsSample compile() {
|
||||
IShaderGL cloudsSample = ShaderCompiler.compileShader("clouds_sample", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.clouds_sample_fsh);
|
||||
try {
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("clouds_sample", SharedPipelineShaders.deferred_local, cloudsSample);
|
||||
return new PipelineShaderCloudsSample(prog);
|
||||
}finally {
|
||||
if(cloudsSample != null) {
|
||||
cloudsSample.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderCloudsSample(IProgramGL prog) {
|
||||
super(prog, new Uniforms());
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public IUniformGL u_rainStrength1f = null;
|
||||
public IUniformGL u_densityModifier4f = null;
|
||||
public IUniformGL u_sampleStep1f = null;
|
||||
public IUniformGL u_cloudTimer1f = null;
|
||||
public IUniformGL u_cloudOffset3f = null;
|
||||
public IUniformGL u_sunDirection3f = null;
|
||||
public IUniformGL u_sunColor3f = null;
|
||||
|
||||
private Uniforms() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
u_rainStrength1f = _wglGetUniformLocation(prog, "u_rainStrength1f");
|
||||
u_densityModifier4f = _wglGetUniformLocation(prog, "u_densityModifier4f");
|
||||
u_sampleStep1f = _wglGetUniformLocation(prog, "u_sampleStep1f");
|
||||
u_cloudTimer1f = _wglGetUniformLocation(prog, "u_cloudTimer1f");
|
||||
u_cloudOffset3f = _wglGetUniformLocation(prog, "u_cloudOffset3f");
|
||||
u_sunDirection3f = _wglGetUniformLocation(prog, "u_sunDirection3f");
|
||||
u_sunColor3f = _wglGetUniformLocation(prog, "u_sunColor3f");
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_noiseTexture3D"), 0);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_skyIrradianceMap"), 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderCloudsShapes extends ShaderProgram<PipelineShaderCloudsShapes.Uniforms> {
|
||||
|
||||
public static PipelineShaderCloudsShapes compile() {
|
||||
IShaderGL cloudsShapesVSH = ShaderCompiler.compileShader("clouds_shapes", GL_VERTEX_SHADER,
|
||||
ShaderSource.clouds_shapes_vsh);
|
||||
IShaderGL cloudsShapesFSH = null;
|
||||
try {
|
||||
cloudsShapesFSH = ShaderCompiler.compileShader("clouds_shapes", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.clouds_shapes_fsh);
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("clouds_shapes", cloudsShapesVSH, cloudsShapesFSH);
|
||||
return new PipelineShaderCloudsShapes(prog);
|
||||
}finally {
|
||||
if(cloudsShapesVSH != null) {
|
||||
cloudsShapesVSH.free();
|
||||
}
|
||||
if(cloudsShapesFSH != null) {
|
||||
cloudsShapesFSH.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderCloudsShapes(IProgramGL prog) {
|
||||
super(prog, new Uniforms());
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public IUniformGL u_textureLevel1f = null;
|
||||
public IUniformGL u_textureLod1f = null;
|
||||
public IUniformGL u_transformMatrix3x2f = null;
|
||||
public IUniformGL u_sampleWeights2f = null;
|
||||
|
||||
private Uniforms() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
u_textureLevel1f = _wglGetUniformLocation(prog, "u_textureLevel1f");
|
||||
u_textureLod1f = _wglGetUniformLocation(prog, "u_textureLod1f");
|
||||
u_transformMatrix3x2f = _wglGetUniformLocation(prog, "u_transformMatrix3x2f");
|
||||
u_sampleWeights2f = _wglGetUniformLocation(prog, "u_sampleWeights2f");
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_inputTexture"), 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderCloudsSunOcclusion extends ShaderProgram<PipelineShaderCloudsSunOcclusion.Uniforms> {
|
||||
|
||||
public static PipelineShaderCloudsSunOcclusion compile() {
|
||||
IShaderGL cloudsOcclusion = ShaderCompiler.compileShader("clouds_sun_occlusion", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.clouds_sun_occlusion_fsh);
|
||||
try {
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("clouds_sun_occlusion", SharedPipelineShaders.deferred_local, cloudsOcclusion);
|
||||
return new PipelineShaderCloudsSunOcclusion(prog);
|
||||
}finally {
|
||||
if(cloudsOcclusion != null) {
|
||||
cloudsOcclusion.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
private PipelineShaderCloudsSunOcclusion(IProgramGL program) {
|
||||
super(program, new Uniforms());
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public IUniformGL u_sampleMatrix4x3f = null;
|
||||
|
||||
private Uniforms() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
u_sampleMatrix4x3f = _wglGetUniformLocation(prog, "u_sampleMatrix4x3f");
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_cloudsTexture"), 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderFXAA extends ShaderProgram<PipelineShaderFXAA.Uniforms> {
|
||||
|
||||
public static PipelineShaderFXAA compile() throws ShaderException {
|
||||
IShaderGL postFXAA = ShaderCompiler.compileShader("post_fxaa", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.post_fxaa_fsh);
|
||||
try {
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("post_fxaa", SharedPipelineShaders.deferred_local, postFXAA);
|
||||
return new PipelineShaderFXAA(prog);
|
||||
}finally {
|
||||
if(postFXAA != null) {
|
||||
postFXAA.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderFXAA(IProgramGL program) {
|
||||
super(program, new Uniforms());
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public IUniformGL u_screenSize2f;
|
||||
|
||||
private Uniforms() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_screenTexture"), 0);
|
||||
u_screenSize2f = _wglGetUniformLocation(prog, "u_screenSize2f");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderGBufferCombine extends ShaderProgram<PipelineShaderGBufferCombine.Uniforms> {
|
||||
|
||||
public static PipelineShaderGBufferCombine compile(boolean ssao, boolean env, boolean ssr) throws ShaderException {
|
||||
IShaderGL coreGBuffer = null;
|
||||
List<String> compileFlags = new ArrayList(2);
|
||||
if(ssao) {
|
||||
compileFlags.add("COMPILE_GLOBAL_AMBIENT_OCCLUSION");
|
||||
}
|
||||
if(env) {
|
||||
compileFlags.add("COMPILE_ENV_MAP_REFLECTIONS");
|
||||
}
|
||||
if(ssr) {
|
||||
compileFlags.add("COMPILE_SCREEN_SPACE_REFLECTIONS");
|
||||
}
|
||||
coreGBuffer = ShaderCompiler.compileShader("deferred_combine", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.deferred_combine_fsh, compileFlags);
|
||||
try {
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("deferred_combine", SharedPipelineShaders.deferred_local, coreGBuffer);
|
||||
return new PipelineShaderGBufferCombine(prog, ssao, env, ssr);
|
||||
}finally {
|
||||
if(coreGBuffer != null) {
|
||||
coreGBuffer.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderGBufferCombine(IProgramGL program, boolean ssao, boolean env, boolean ssr) {
|
||||
super(program, new Uniforms(ssao, env, ssr));
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public final boolean ssao;
|
||||
public final boolean env;
|
||||
public final boolean ssr;
|
||||
|
||||
public IUniformGL u_halfResolutionPixelAlignment2f;
|
||||
public IUniformGL u_inverseProjMatrix4f;
|
||||
public IUniformGL u_inverseViewMatrix4f;
|
||||
public IUniformGL u_sunDirection3f;
|
||||
public IUniformGL u_skyLightFactor1f;
|
||||
|
||||
private Uniforms(boolean ssao, boolean env, boolean ssr) {
|
||||
this.ssao = ssao;
|
||||
this.ssr = ssr;
|
||||
this.env = env;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_gbufferColorTexture"), 0);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_gbufferNormalTexture"), 1);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_gbufferMaterialTexture"), 2);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_gbufferDepthTexture"), 3);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_ssaoTexture"), 4);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_ssrReflectionTexture"), 5);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_environmentMap"), 6);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_irradianceMap"), 7);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_brdfLUT"), 8);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_metalsLUT"), 9);
|
||||
u_halfResolutionPixelAlignment2f = _wglGetUniformLocation(prog, "u_halfResolutionPixelAlignment2f");
|
||||
u_inverseProjMatrix4f = _wglGetUniformLocation(prog, "u_inverseProjMatrix4f");
|
||||
u_inverseViewMatrix4f = _wglGetUniformLocation(prog, "u_inverseViewMatrix4f");
|
||||
u_sunDirection3f = _wglGetUniformLocation(prog, "u_sunDirection3f");
|
||||
u_skyLightFactor1f = _wglGetUniformLocation(prog, "u_skyLightFactor1f");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderGBufferDebugView extends ShaderProgram<PipelineShaderGBufferDebugView.Uniforms> {
|
||||
|
||||
public static PipelineShaderGBufferDebugView compile(int view) throws ShaderException {
|
||||
IShaderGL debugView = ShaderCompiler.compileShader("gbuffer_debug_view", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.gbuffer_debug_view_fsh, ("DEBUG_VIEW_" + view));
|
||||
try {
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("gbuffer_debug_view", SharedPipelineShaders.deferred_local, debugView);
|
||||
return new PipelineShaderGBufferDebugView(prog, view);
|
||||
}finally {
|
||||
if(debugView != null) {
|
||||
debugView.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderGBufferDebugView(IProgramGL prog, int mode) {
|
||||
super(prog, new Uniforms(mode));
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public final int mode;
|
||||
|
||||
public IUniformGL u_inverseViewMatrix = null;
|
||||
public IUniformGL u_depthSliceStartEnd2f = null;
|
||||
|
||||
private Uniforms(int mode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_texture0"), 0);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_texture1"), 1);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_texture3D0"), 0);
|
||||
u_inverseViewMatrix = _wglGetUniformLocation(prog, "u_inverseViewMatrix");
|
||||
u_depthSliceStartEnd2f = _wglGetUniformLocation(prog, "u_depthSliceStartEnd2f");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderGBufferFog extends ShaderProgram<PipelineShaderGBufferFog.Uniforms> {
|
||||
|
||||
public static PipelineShaderGBufferFog compile(boolean linear, boolean atmosphere, boolean lightShafts) {
|
||||
List<String> macros = new ArrayList(3);
|
||||
if(linear) {
|
||||
macros.add("COMPILE_FOG_LINEAR");
|
||||
}
|
||||
if(atmosphere) {
|
||||
macros.add("COMPILE_FOG_ATMOSPHERE");
|
||||
}
|
||||
if(lightShafts) {
|
||||
macros.add("COMPILE_FOG_LIGHT_SHAFTS");
|
||||
}
|
||||
IShaderGL deferredFog = ShaderCompiler.compileShader("deferred_fog", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.deferred_fog_fsh, macros);
|
||||
try {
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("deferred_fog", SharedPipelineShaders.deferred_local, deferredFog);
|
||||
return new PipelineShaderGBufferFog(prog);
|
||||
}finally {
|
||||
if(deferredFog != null) {
|
||||
deferredFog.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderGBufferFog(IProgramGL prog) {
|
||||
super(prog, new Uniforms());
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public IUniformGL u_inverseViewProjMatrix4f = null;
|
||||
public IUniformGL u_linearFogParam2f = null;
|
||||
public IUniformGL u_expFogDensity1f = null;
|
||||
public IUniformGL u_fogColorLight4f = null;
|
||||
public IUniformGL u_fogColorDark4f = null;
|
||||
public IUniformGL u_sunColorAdd3f = null;
|
||||
|
||||
private Uniforms() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
u_inverseViewProjMatrix4f = _wglGetUniformLocation(prog, "u_inverseViewProjMatrix4f");
|
||||
u_linearFogParam2f = _wglGetUniformLocation(prog, "u_linearFogParam2f");
|
||||
u_expFogDensity1f = _wglGetUniformLocation(prog, "u_expFogDensity1f");
|
||||
u_fogColorLight4f = _wglGetUniformLocation(prog, "u_fogColorLight4f");
|
||||
u_fogColorDark4f = _wglGetUniformLocation(prog, "u_fogColorDark4f");
|
||||
u_sunColorAdd3f = _wglGetUniformLocation(prog, "u_sunColorAdd3f");
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_gbufferDepthTexture"), 0);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_gbufferNormalTexture"), 1);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_fogDepthTexture"), 2);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_environmentMap"), 3);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_lightShaftsTexture"), 4);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderHandDepthMask extends ShaderProgram<PipelineShaderHandDepthMask.Uniforms> {
|
||||
|
||||
public static PipelineShaderHandDepthMask compile() {
|
||||
IShaderGL handDepthMask = ShaderCompiler.compileShader("hand_depth_mask", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.hand_depth_mask_fsh);
|
||||
try {
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("hand_depth_mask", SharedPipelineShaders.deferred_local, handDepthMask);
|
||||
return new PipelineShaderHandDepthMask(prog);
|
||||
}finally {
|
||||
if(handDepthMask != null) {
|
||||
handDepthMask.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderHandDepthMask(IProgramGL prog) {
|
||||
super(prog, new Uniforms());
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
private Uniforms() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_depthTexture"), 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderLensDistortion extends ShaderProgram<PipelineShaderLensDistortion.Uniforms> {
|
||||
|
||||
public static PipelineShaderLensDistortion compile() throws ShaderException {
|
||||
IShaderGL lensDistort = ShaderCompiler.compileShader("post_lens_distort", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.post_lens_distort_fsh);
|
||||
try {
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("post_lens_distort", SharedPipelineShaders.deferred_local, lensDistort);
|
||||
return new PipelineShaderLensDistortion(prog);
|
||||
}finally {
|
||||
if(lensDistort != null) {
|
||||
lensDistort.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderLensDistortion(IProgramGL prog) {
|
||||
super(prog, new Uniforms());
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
private Uniforms() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_inputTexture"), 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderLensFlares extends ShaderProgram<PipelineShaderLensFlares.Uniforms> {
|
||||
|
||||
public static PipelineShaderLensFlares compileStreaks() {
|
||||
IShaderGL vertexShader = ShaderCompiler.compileShader("post_lens_streaks", GL_VERTEX_SHADER,
|
||||
ShaderSource.post_lens_streaks_vsh);
|
||||
IShaderGL fragmentShader = null;
|
||||
try {
|
||||
fragmentShader = ShaderCompiler.compileShader("post_lens_streaks", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.post_lens_streaks_fsh);
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("post_lens_streaks", vertexShader, fragmentShader);
|
||||
return new PipelineShaderLensFlares(prog);
|
||||
}finally {
|
||||
if(vertexShader != null) {
|
||||
vertexShader.free();
|
||||
}
|
||||
if(fragmentShader != null) {
|
||||
fragmentShader.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static PipelineShaderLensFlares compileGhosts() {
|
||||
IShaderGL vertexShader = ShaderCompiler.compileShader("post_lens_ghosts", GL_VERTEX_SHADER,
|
||||
ShaderSource.post_lens_ghosts_vsh);
|
||||
IShaderGL fragmentShader = null;
|
||||
try {
|
||||
fragmentShader = ShaderCompiler.compileShader("post_lens_ghosts", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.post_lens_ghosts_fsh);
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("post_lens_ghosts", vertexShader, fragmentShader);
|
||||
return new PipelineShaderLensFlares(prog);
|
||||
}finally {
|
||||
if(vertexShader != null) {
|
||||
vertexShader.free();
|
||||
}
|
||||
if(fragmentShader != null) {
|
||||
fragmentShader.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderLensFlares(IProgramGL program) {
|
||||
super(program, new Uniforms());
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public IUniformGL u_sunFlareMatrix3f = null;
|
||||
public IUniformGL u_flareColor3f = null;
|
||||
public IUniformGL u_sunPosition2f = null;
|
||||
public IUniformGL u_aspectRatio1f = null;
|
||||
public IUniformGL u_baseScale1f = null;
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
u_sunFlareMatrix3f = _wglGetUniformLocation(prog, "u_sunFlareMatrix3f");
|
||||
u_flareColor3f = _wglGetUniformLocation(prog, "u_flareColor3f");
|
||||
u_sunPosition2f = _wglGetUniformLocation(prog, "u_sunPosition2f");
|
||||
u_aspectRatio1f = _wglGetUniformLocation(prog, "u_aspectRatio1f");
|
||||
u_baseScale1f = _wglGetUniformLocation(prog, "u_baseScale1f");
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_flareTexture"), 0);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_exposureValue"), 1);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_sunOcclusionValue"), 2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderLensSunOcclusion extends ShaderProgram<PipelineShaderLensSunOcclusion.Uniforms> {
|
||||
|
||||
public static PipelineShaderLensSunOcclusion compile() throws ShaderException {
|
||||
IShaderGL sunOcclusion = ShaderCompiler.compileShader("lens_sun_occlusion", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.lens_sun_occlusion_fsh);
|
||||
try {
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("lens_sun_occlusion", SharedPipelineShaders.deferred_local, sunOcclusion);
|
||||
return new PipelineShaderLensSunOcclusion(prog);
|
||||
}finally {
|
||||
if(sunOcclusion != null) {
|
||||
sunOcclusion.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderLensSunOcclusion(IProgramGL prog) {
|
||||
super(prog, new Uniforms());
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public IUniformGL u_sampleMatrix3f = null;
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
u_sampleMatrix3f = _wglGetUniformLocation(prog, "u_sampleMatrix3f");
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_depthBufferTexture"), 0);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_cloudsSunOcclusion"), 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderLightShaftsSample extends ShaderProgram<PipelineShaderLightShaftsSample.Uniforms> {
|
||||
|
||||
public static PipelineShaderLightShaftsSample compile(int shadowsSun) {
|
||||
if(shadowsSun == 0) {
|
||||
throw new IllegalStateException("Enable shadows to compile this shader");
|
||||
}
|
||||
int lods = shadowsSun - 1;
|
||||
if(lods > 2) {
|
||||
lods = 2;
|
||||
}
|
||||
IShaderGL lightShaftsSample = ShaderCompiler.compileShader("light_shafts_sample", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.light_shafts_sample_fsh, Arrays.asList("COMPILE_SUN_SHADOW_LOD" + lods));
|
||||
try {
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("light_shafts_sample", SharedPipelineShaders.deferred_local, lightShaftsSample);
|
||||
return new PipelineShaderLightShaftsSample(prog);
|
||||
}finally {
|
||||
if(lightShaftsSample != null) {
|
||||
lightShaftsSample.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderLightShaftsSample(IProgramGL prog) {
|
||||
super(prog, new Uniforms());
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public IUniformGL u_inverseViewProjMatrix4f = null;
|
||||
public IUniformGL u_sampleStep1f = null;
|
||||
public IUniformGL u_eyePosition3f = null;
|
||||
public IUniformGL u_ditherScale2f = null;
|
||||
public IUniformGL u_sunShadowMatrixLOD04f = null;
|
||||
public IUniformGL u_sunShadowMatrixLOD14f = null;
|
||||
public IUniformGL u_sunShadowMatrixLOD24f = null;
|
||||
|
||||
private Uniforms() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
u_inverseViewProjMatrix4f = _wglGetUniformLocation(prog, "u_inverseViewProjMatrix4f");
|
||||
u_sampleStep1f = _wglGetUniformLocation(prog, "u_sampleStep1f");
|
||||
u_eyePosition3f = _wglGetUniformLocation(prog, "u_eyePosition3f");
|
||||
u_ditherScale2f = _wglGetUniformLocation(prog, "u_ditherScale2f");
|
||||
u_sunShadowMatrixLOD04f = _wglGetUniformLocation(prog, "u_sunShadowMatrixLOD04f");
|
||||
u_sunShadowMatrixLOD14f = _wglGetUniformLocation(prog, "u_sunShadowMatrixLOD14f");
|
||||
u_sunShadowMatrixLOD24f = _wglGetUniformLocation(prog, "u_sunShadowMatrixLOD24f");
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_gbufferDepthTexture"), 0);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_sunShadowDepthTexture"), 1);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_ditherTexture"), 2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderLightingPoint extends ShaderProgram<PipelineShaderLightingPoint.Uniforms> {
|
||||
|
||||
public static PipelineShaderLightingPoint compile(boolean shadows)
|
||||
throws ShaderException {
|
||||
List<String> compileFlags = new ArrayList(2);
|
||||
if(shadows) {
|
||||
compileFlags.add("COMPILE_PARABOLOID_SHADOW");
|
||||
}
|
||||
IShaderGL lightingPoint = ShaderCompiler.compileShader("lighting_point", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.lighting_point_fsh, compileFlags);
|
||||
try {
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("lighting_point", SharedPipelineShaders.lighting_mesh, lightingPoint);
|
||||
return new PipelineShaderLightingPoint(prog, shadows);
|
||||
}finally {
|
||||
if(lightingPoint != null) {
|
||||
lightingPoint.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderLightingPoint(IProgramGL program, boolean shadows) {
|
||||
super(program, new Uniforms(shadows));
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public IUniformGL u_viewportSize2f = null;
|
||||
public IUniformGL u_modelViewProjMatrix4f = null;
|
||||
public IUniformGL u_inverseProjectionMatrix4f = null;
|
||||
public IUniformGL u_inverseViewMatrix4f = null;
|
||||
public IUniformGL u_lightPosition3f = null;
|
||||
public IUniformGL u_lightColor3f = null;
|
||||
|
||||
public final boolean shadows;
|
||||
|
||||
private Uniforms(boolean shadows) {
|
||||
this.shadows = shadows;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_gbufferColorTexture"), 0);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_gbufferNormalTexture"), 1);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_gbufferMaterialTexture"), 2);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_gbufferDepthTexture"), 3);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_metalsLUT"), 5);
|
||||
u_viewportSize2f = _wglGetUniformLocation(prog, "u_viewportSize2f");
|
||||
u_modelViewProjMatrix4f = _wglGetUniformLocation(prog, "u_modelViewProjMatrix4f");
|
||||
u_inverseProjectionMatrix4f = _wglGetUniformLocation(prog, "u_inverseProjectionMatrix4f");
|
||||
u_inverseViewMatrix4f = _wglGetUniformLocation(prog, "u_inverseViewMatrix4f");
|
||||
u_lightPosition3f = _wglGetUniformLocation(prog, "u_lightPosition3f");
|
||||
u_lightColor3f = _wglGetUniformLocation(prog, "u_lightColor3f");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderLightingSun extends ShaderProgram<PipelineShaderLightingSun.Uniforms> {
|
||||
|
||||
public static PipelineShaderLightingSun compile(int shadowsSun, boolean coloredShadows) throws ShaderException {
|
||||
IShaderGL sunShader = null;
|
||||
List<String> compileFlags = new ArrayList(1);
|
||||
if(shadowsSun > 0) {
|
||||
compileFlags.add("COMPILE_SUN_SHADOW");
|
||||
}
|
||||
if(coloredShadows) {
|
||||
compileFlags.add("COMPILE_COLORED_SHADOW");
|
||||
}
|
||||
sunShader = ShaderCompiler.compileShader("lighting_sun", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.lighting_sun_fsh, compileFlags);
|
||||
try {
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("lighting_sun", SharedPipelineShaders.deferred_local, sunShader);
|
||||
return new PipelineShaderLightingSun(prog, shadowsSun);
|
||||
}finally {
|
||||
if(sunShader != null) {
|
||||
sunShader.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderLightingSun(IProgramGL program, int shadowsSun) {
|
||||
super(program, new Uniforms(shadowsSun));
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public final int shadowsSun;
|
||||
public IUniformGL u_inverseViewMatrix4f;
|
||||
public IUniformGL u_inverseProjectionMatrix4f;
|
||||
public IUniformGL u_sunDirection3f;
|
||||
public IUniformGL u_sunColor3f;
|
||||
|
||||
private Uniforms(int shadowsSun) {
|
||||
this.shadowsSun = shadowsSun;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_gbufferColorTexture"), 0);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_gbufferNormalTexture"), 1);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_gbufferMaterialTexture"), 2);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_gbufferDepthTexture"), 3);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_sunShadowTexture"), 4);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_metalsLUT"), 5);
|
||||
u_inverseViewMatrix4f = _wglGetUniformLocation(prog, "u_inverseViewMatrix4f");
|
||||
u_inverseProjectionMatrix4f = _wglGetUniformLocation(prog, "u_inverseProjectionMatrix4f");
|
||||
u_sunDirection3f = _wglGetUniformLocation(prog, "u_sunDirection3f");
|
||||
u_sunColor3f = _wglGetUniformLocation(prog, "u_sunColor3f");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderMoonRender extends ShaderProgram<PipelineShaderMoonRender.Uniforms> {
|
||||
|
||||
public static PipelineShaderMoonRender compile() {
|
||||
IShaderGL moonRenderVSH = ShaderCompiler.compileShader("moon_render", GL_VERTEX_SHADER,
|
||||
ShaderSource.moon_render_vsh);
|
||||
IShaderGL moonRenderFSH = null;
|
||||
try {
|
||||
moonRenderFSH = ShaderCompiler.compileShader("moon_render", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.moon_render_fsh);
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("moon_render", moonRenderVSH, moonRenderFSH);
|
||||
return new PipelineShaderMoonRender(prog);
|
||||
}finally {
|
||||
if(moonRenderVSH != null) {
|
||||
moonRenderVSH.free();
|
||||
}
|
||||
if(moonRenderFSH != null) {
|
||||
moonRenderFSH.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderMoonRender(IProgramGL program) {
|
||||
super(program, new Uniforms());
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public IUniformGL u_modelMatrix4f = null;
|
||||
public IUniformGL u_viewMatrix4f = null;
|
||||
public IUniformGL u_projMatrix4f = null;
|
||||
public IUniformGL u_moonColor3f = null;
|
||||
public IUniformGL u_lightDir3f = null;
|
||||
|
||||
private Uniforms() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
u_modelMatrix4f = _wglGetUniformLocation(prog, "u_modelMatrix4f");
|
||||
u_viewMatrix4f = _wglGetUniformLocation(prog, "u_viewMatrix4f");
|
||||
u_projMatrix4f = _wglGetUniformLocation(prog, "u_projMatrix4f");
|
||||
u_moonColor3f = _wglGetUniformLocation(prog, "u_moonColor3f");
|
||||
u_lightDir3f = _wglGetUniformLocation(prog, "u_lightDir3f");
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_moonTextures"), 0);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_cloudsTexture"), 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderPostExposureAvg extends ShaderProgram<PipelineShaderPostExposureAvg.Uniforms> {
|
||||
|
||||
public static PipelineShaderPostExposureAvg compile(boolean luma) throws ShaderException {
|
||||
List<String> compileFlags = new ArrayList(1);
|
||||
if(luma) {
|
||||
compileFlags.add("CALCULATE_LUMINANCE");
|
||||
}
|
||||
IShaderGL postExposureAvg = ShaderCompiler.compileShader("post_exposure_avg", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.post_exposure_avg_fsh, compileFlags);
|
||||
try {
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("post_exposure_avg", SharedPipelineShaders.deferred_local, postExposureAvg);
|
||||
return new PipelineShaderPostExposureAvg(prog);
|
||||
}finally {
|
||||
if(postExposureAvg != null) {
|
||||
postExposureAvg.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderPostExposureAvg(IProgramGL prog) {
|
||||
super(prog, new Uniforms());
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public IUniformGL u_sampleOffset4f = null;
|
||||
|
||||
private Uniforms() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_inputTexture"), 0);
|
||||
u_sampleOffset4f = _wglGetUniformLocation(prog, "u_sampleOffset4f");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderPostExposureFinal extends ShaderProgram<PipelineShaderPostExposureFinal.Uniforms> {
|
||||
|
||||
public static PipelineShaderPostExposureFinal compile() throws ShaderException {
|
||||
IShaderGL postExposureFinal = ShaderCompiler.compileShader("post_exposure_final", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.post_exposure_final_fsh);
|
||||
try {
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("post_exposure_final", SharedPipelineShaders.deferred_local, postExposureFinal);
|
||||
return new PipelineShaderPostExposureFinal(prog);
|
||||
}finally {
|
||||
if(postExposureFinal != null) {
|
||||
postExposureFinal.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderPostExposureFinal(IProgramGL prog) {
|
||||
super(prog, new Uniforms());
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public IUniformGL u_inputSize2f = null;
|
||||
|
||||
private Uniforms() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_inputTexture"), 0);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_exposureValue"), 1);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_sunOcclusionValue"), 2);
|
||||
u_inputSize2f = _wglGetUniformLocation(prog, "u_inputSize2f");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderRealisticWaterControl extends ShaderProgram<PipelineShaderRealisticWaterControl.Uniforms> {
|
||||
|
||||
public static PipelineShaderRealisticWaterControl compile() throws ShaderException {
|
||||
IShaderGL realisticWaterControl = ShaderCompiler.compileShader("realistic_water_control", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.realistic_water_control_fsh);
|
||||
try {
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("realistic_water_control", SharedPipelineShaders.deferred_local, realisticWaterControl);
|
||||
return new PipelineShaderRealisticWaterControl(prog);
|
||||
}finally {
|
||||
if(realisticWaterControl != null) {
|
||||
realisticWaterControl.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PipelineShaderRealisticWaterControl(IProgramGL program) {
|
||||
super(program, new Uniforms());
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public IUniformGL u_inverseProjectionMatrix4f = null;
|
||||
public IUniformGL u_inverseViewProjMatrix4f = null;
|
||||
public IUniformGL u_reprojectionMatrix4f = null;
|
||||
public IUniformGL u_lastInverseProjMatrix4f = null;
|
||||
public IUniformGL u_reprojectionInverseViewMatrix4f = null;
|
||||
public IUniformGL u_projectionMatrix4f = null;
|
||||
public IUniformGL u_viewToPreviousProjMatrix4f = null;
|
||||
public IUniformGL u_nearFarPlane4f = null;
|
||||
public IUniformGL u_pixelAlignment4f = null;
|
||||
public IUniformGL u_refractFogColor4f = null;
|
||||
|
||||
private Uniforms() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_gbufferColorTexture4f"), 0);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_gbufferDepthTexture"), 1);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_realisticWaterMaskNormal"), 2);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_realisticWaterDepthTexture"), 3);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_lastFrameReflectionInput4f"), 4);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_lastFrameHitVectorInput4f"), 5);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_lastFrameColorTexture"), 6);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_lastFrameDepthTexture"), 7);
|
||||
u_inverseProjectionMatrix4f = _wglGetUniformLocation(prog, "u_inverseProjectionMatrix4f");
|
||||
u_inverseViewProjMatrix4f = _wglGetUniformLocation(prog, "u_inverseViewProjMatrix4f");
|
||||
u_reprojectionMatrix4f = _wglGetUniformLocation(prog, "u_reprojectionMatrix4f");
|
||||
u_lastInverseProjMatrix4f = _wglGetUniformLocation(prog, "u_lastInverseProjMatrix4f");
|
||||
u_reprojectionInverseViewMatrix4f = _wglGetUniformLocation(prog, "u_reprojectionInverseViewMatrix4f");
|
||||
u_projectionMatrix4f = _wglGetUniformLocation(prog, "u_projectionMatrix4f");
|
||||
u_viewToPreviousProjMatrix4f = _wglGetUniformLocation(prog, "u_viewToPreviousProjMatrix4f");
|
||||
u_nearFarPlane4f = _wglGetUniformLocation(prog, "u_nearFarPlane4f");
|
||||
u_pixelAlignment4f = _wglGetUniformLocation(prog, "u_pixelAlignment4f");
|
||||
u_refractFogColor4f = _wglGetUniformLocation(prog, "u_refractFogColor4f");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderRealisticWaterNoise extends ShaderProgram<PipelineShaderRealisticWaterNoise.Uniforms> {
|
||||
|
||||
public static PipelineShaderRealisticWaterNoise compile() throws ShaderException {
|
||||
IShaderGL realisticWaterNoise = ShaderCompiler.compileShader("realistic_water_noise", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.realistic_water_noise_fsh);
|
||||
try {
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("realistic_water_noise", SharedPipelineShaders.deferred_local, realisticWaterNoise);
|
||||
return new PipelineShaderRealisticWaterNoise(prog);
|
||||
}finally {
|
||||
if(realisticWaterNoise != null) {
|
||||
realisticWaterNoise.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderRealisticWaterNoise(IProgramGL prog) {
|
||||
super(prog, new Uniforms());
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public IUniformGL u_waveTimer4f = null;
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_noiseTexture"), 0);
|
||||
u_waveTimer4f = _wglGetUniformLocation(prog, "u_waveTimer4f");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderRealisticWaterNormalMap extends ShaderProgram<PipelineShaderRealisticWaterNormalMap.Uniforms> {
|
||||
|
||||
public static PipelineShaderRealisticWaterNormalMap compile() throws ShaderException {
|
||||
IShaderGL realisticWaterNormals = ShaderCompiler.compileShader("realistic_water_normals", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.realistic_water_normals_fsh);
|
||||
try {
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("realistic_water_normals", SharedPipelineShaders.deferred_local, realisticWaterNormals);
|
||||
return new PipelineShaderRealisticWaterNormalMap(prog);
|
||||
}finally {
|
||||
if(realisticWaterNormals != null) {
|
||||
realisticWaterNormals.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderRealisticWaterNormalMap(IProgramGL prog) {
|
||||
super(prog, new Uniforms());
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public IUniformGL u_sampleOffset2f = null;
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_displacementTexture"), 0);
|
||||
u_sampleOffset2f = _wglGetUniformLocation(prog, "u_sampleOffset2f");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderReprojControl extends ShaderProgram<PipelineShaderReprojControl.Uniforms> {
|
||||
|
||||
public static PipelineShaderReprojControl compile(boolean ssao, boolean ssr) throws ShaderException {
|
||||
List<String> compileFlags = new ArrayList(2);
|
||||
if(ssao) {
|
||||
compileFlags.add("COMPILE_REPROJECT_SSAO");
|
||||
}
|
||||
if(ssr) {
|
||||
compileFlags.add("COMPILE_REPROJECT_SSR");
|
||||
}
|
||||
IShaderGL reprojControl = ShaderCompiler.compileShader("reproj_control", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.reproject_control_fsh, compileFlags);
|
||||
try {
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("reproj_control", SharedPipelineShaders.deferred_local, reprojControl);
|
||||
return new PipelineShaderReprojControl(prog, ssao, ssr);
|
||||
}finally {
|
||||
if(reprojControl != null) {
|
||||
reprojControl.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderReprojControl(IProgramGL prog, boolean ssao, boolean ssr) {
|
||||
super(prog, new Uniforms());
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public IUniformGL u_inverseViewProjMatrix4f = null;
|
||||
public IUniformGL u_projectionMatrix4f = null;
|
||||
public IUniformGL u_reprojectionMatrix4f = null;
|
||||
public IUniformGL u_inverseProjectionMatrix4f = null;
|
||||
public IUniformGL u_lastInverseProjMatrix4f = null;
|
||||
public IUniformGL u_reprojectionInverseViewMatrix4f = null;
|
||||
public IUniformGL u_viewToPreviousProjMatrix4f = null;
|
||||
public IUniformGL u_nearFarPlane4f = null;
|
||||
public IUniformGL u_pixelAlignment4f = null;
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_gbufferDepthTexture"), 0);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_ssaoSampleTexture"), 1);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_reprojectionSSAOInput4f"), 2);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_gbufferNormalTexture"), 3);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_reprojectionReflectionInput4f"), 4);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_reprojectionHitVectorInput4f"), 5);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_lastFrameColorInput4f"), 6);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_reprojectionDepthTexture"), 7);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_gbufferMaterialTexture"), 8);
|
||||
u_inverseViewProjMatrix4f = _wglGetUniformLocation(prog, "u_inverseViewProjMatrix4f");
|
||||
u_projectionMatrix4f = _wglGetUniformLocation(prog, "u_projectionMatrix4f");
|
||||
u_reprojectionMatrix4f = _wglGetUniformLocation(prog, "u_reprojectionMatrix4f");
|
||||
u_inverseProjectionMatrix4f = _wglGetUniformLocation(prog, "u_inverseProjectionMatrix4f");
|
||||
u_lastInverseProjMatrix4f = _wglGetUniformLocation(prog, "u_lastInverseProjMatrix4f");
|
||||
u_reprojectionInverseViewMatrix4f = _wglGetUniformLocation(prog, "u_reprojectionInverseViewMatrix4f");
|
||||
u_viewToPreviousProjMatrix4f = _wglGetUniformLocation(prog, "u_viewToPreviousProjMatrix4f");
|
||||
u_nearFarPlane4f = _wglGetUniformLocation(prog, "u_nearFarPlane4f");
|
||||
u_pixelAlignment4f = _wglGetUniformLocation(prog, "u_pixelAlignment4f");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderReprojSSR extends ShaderProgram<PipelineShaderReprojSSR.Uniforms> {
|
||||
|
||||
public static PipelineShaderReprojSSR compile() throws ShaderException {
|
||||
IShaderGL reprojSSR = ShaderCompiler.compileShader("reproj_ssr", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.reproject_ssr_fsh);
|
||||
try {
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("reproj_ssr", SharedPipelineShaders.deferred_local, reprojSSR);
|
||||
return new PipelineShaderReprojSSR(prog);
|
||||
}finally {
|
||||
if(reprojSSR != null) {
|
||||
reprojSSR.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderReprojSSR(IProgramGL prog) {
|
||||
super(prog, new Uniforms());
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public IUniformGL u_lastProjectionMatrix4f;
|
||||
public IUniformGL u_lastInverseProjMatrix4x2f;
|
||||
public IUniformGL u_inverseProjectionMatrix4f;
|
||||
public IUniformGL u_sampleStep1f;
|
||||
public IUniformGL u_pixelAlignment4f = null;
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_gbufferDepthTexture"), 0);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_gbufferNormalTexture"), 1);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_reprojectionReflectionInput4f"), 2);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_reprojectionHitVectorInput4f"), 3);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_lastFrameColorInput4f"), 4);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_lastFrameDepthInput"), 5);
|
||||
u_lastProjectionMatrix4f = _wglGetUniformLocation(prog, "u_lastProjectionMatrix4f");
|
||||
u_lastInverseProjMatrix4x2f = _wglGetUniformLocation(prog, "u_lastInverseProjMatrix4x2f");
|
||||
u_inverseProjectionMatrix4f = _wglGetUniformLocation(prog, "u_inverseProjectionMatrix4f");
|
||||
u_sampleStep1f = _wglGetUniformLocation(prog, "u_sampleStep1f");
|
||||
u_pixelAlignment4f = _wglGetUniformLocation(prog, "u_pixelAlignment4f");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderSSAOGenerate extends ShaderProgram<PipelineShaderSSAOGenerate.Uniforms> {
|
||||
|
||||
public static PipelineShaderSSAOGenerate compile() throws ShaderException {
|
||||
IShaderGL ssaoGenerate = ShaderCompiler.compileShader("ssao_generate", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.ssao_generate_fsh);
|
||||
try {
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("ssao_generate", SharedPipelineShaders.deferred_local, ssaoGenerate);
|
||||
return new PipelineShaderSSAOGenerate(prog);
|
||||
}finally {
|
||||
if(ssaoGenerate != null) {
|
||||
ssaoGenerate.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderSSAOGenerate(IProgramGL program) {
|
||||
super(program, new Uniforms());
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public IUniformGL u_projectionMatrix4f;
|
||||
public IUniformGL u_inverseProjectionMatrix4f;
|
||||
public IUniformGL u_randomizerDataMatrix2f;
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
u_projectionMatrix4f = _wglGetUniformLocation(prog, "u_projectionMatrix4f");
|
||||
u_inverseProjectionMatrix4f = _wglGetUniformLocation(prog, "u_inverseProjectionMatrix4f");
|
||||
u_randomizerDataMatrix2f = _wglGetUniformLocation(prog, "u_randomizerDataMatrix2f");
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_gbufferDepthTexture"), 0);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_gbufferNormalTexture"), 1);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_noiseConstantTexture"), 2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderShadowsSun extends ShaderProgram<PipelineShaderShadowsSun.Uniforms> {
|
||||
|
||||
public static PipelineShaderShadowsSun compile(int shadowsSun, boolean shadowsSunSmooth, boolean coloredShadows)
|
||||
throws ShaderException {
|
||||
IShaderGL shadowShader = null;
|
||||
List<String> compileFlags = new ArrayList(2);
|
||||
if(shadowsSun == 0) {
|
||||
throw new IllegalStateException("Enable shadows to compile this shader");
|
||||
}
|
||||
int lods = shadowsSun - 1;
|
||||
if(lods > 2) {
|
||||
lods = 2;
|
||||
}
|
||||
compileFlags.add("COMPILE_SUN_SHADOW_LOD" + lods);
|
||||
if(shadowsSunSmooth) {
|
||||
compileFlags.add("COMPILE_SUN_SHADOW_SMOOTH");
|
||||
}
|
||||
if(coloredShadows) {
|
||||
compileFlags.add("COMPILE_COLORED_SHADOW");
|
||||
}
|
||||
shadowShader = ShaderCompiler.compileShader("shadows_sun", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.shadows_sun_fsh, compileFlags);
|
||||
try {
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("shadows_sun", SharedPipelineShaders.deferred_local, shadowShader);
|
||||
return new PipelineShaderShadowsSun(prog, shadowsSun, shadowsSunSmooth);
|
||||
}finally {
|
||||
if(shadowShader != null) {
|
||||
shadowShader.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderShadowsSun(IProgramGL program, int shadowsSun, boolean shadowsSunSmooth) {
|
||||
super(program, new Uniforms(shadowsSun, shadowsSunSmooth));
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public final int shadowsSun;
|
||||
public final boolean shadowsSunSmooth;
|
||||
public IUniformGL u_inverseViewMatrix4f;
|
||||
public IUniformGL u_inverseViewProjMatrix4f;
|
||||
public IUniformGL u_sunShadowMatrixLOD04f;
|
||||
public IUniformGL u_sunShadowMatrixLOD14f;
|
||||
public IUniformGL u_sunShadowMatrixLOD24f;
|
||||
public IUniformGL u_sunDirection3f;
|
||||
|
||||
private Uniforms(int shadowsSun, boolean shadowsSunSmooth) {
|
||||
this.shadowsSun = shadowsSun;
|
||||
this.shadowsSunSmooth = shadowsSunSmooth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_gbufferNormalTexture"), 0);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_gbufferDepthTexture"), 1);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_sunShadowDepthTexture"), 2);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_sunShadowColorTexture"), 3);
|
||||
u_inverseViewMatrix4f = _wglGetUniformLocation(prog, "u_inverseViewMatrix4f");
|
||||
u_inverseViewProjMatrix4f = _wglGetUniformLocation(prog, "u_inverseViewProjMatrix4f");
|
||||
u_sunShadowMatrixLOD04f = _wglGetUniformLocation(prog, "u_sunShadowMatrixLOD04f");
|
||||
u_sunShadowMatrixLOD14f = _wglGetUniformLocation(prog, "u_sunShadowMatrixLOD14f");
|
||||
u_sunShadowMatrixLOD24f = _wglGetUniformLocation(prog, "u_sunShadowMatrixLOD24f");
|
||||
u_sunDirection3f = _wglGetUniformLocation(prog, "u_sunDirection3f");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderSkyboxAtmosphere extends ShaderProgram<PipelineShaderSkyboxAtmosphere.Uniforms> {
|
||||
|
||||
public static PipelineShaderSkyboxAtmosphere compile() throws ShaderException {
|
||||
IShaderGL skyboxAtmosphere = ShaderCompiler.compileShader("skybox_atmosphere", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.skybox_atmosphere_fsh);
|
||||
try {
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("skybox_atmosphere", SharedPipelineShaders.deferred_local, skyboxAtmosphere);
|
||||
return new PipelineShaderSkyboxAtmosphere(prog);
|
||||
}finally {
|
||||
if(skyboxAtmosphere != null) {
|
||||
skyboxAtmosphere.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderSkyboxAtmosphere(IProgramGL prog) {
|
||||
super(prog, new Uniforms());
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public IUniformGL u_sunDirectionIntensity4f = null;
|
||||
public IUniformGL u_altitude1f = null;
|
||||
public IUniformGL u_blendColor4f = null;
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
u_sunDirectionIntensity4f = _wglGetUniformLocation(prog, "u_sunDirectionIntensity4f");
|
||||
u_altitude1f = _wglGetUniformLocation(prog, "u_altitude1f");
|
||||
u_blendColor4f = _wglGetUniformLocation(prog, "u_blendColor4f");
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_skyNormals"), 0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderSkyboxIrradiance extends ShaderProgram<PipelineShaderSkyboxIrradiance.Uniforms> {
|
||||
|
||||
public static PipelineShaderSkyboxIrradiance compile(int phase) throws ShaderException {
|
||||
IShaderGL skyboxIrradiance = ShaderCompiler.compileShader("skybox_irradiance", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.skybox_irradiance_fsh, Arrays.asList("PHASE_" + phase));
|
||||
try {
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("skybox_irradiance", SharedPipelineShaders.deferred_local, skyboxIrradiance);
|
||||
return new PipelineShaderSkyboxIrradiance(prog);
|
||||
}finally {
|
||||
if(skyboxIrradiance != null) {
|
||||
skyboxIrradiance.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderSkyboxIrradiance(IProgramGL prog) {
|
||||
super(prog, new Uniforms());
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
private Uniforms() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_paraboloidSkyboxTexture"), 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderSkyboxRender extends ShaderProgram<PipelineShaderSkyboxRender.Uniforms> {
|
||||
|
||||
public static PipelineShaderSkyboxRender compile(boolean paraboloid, boolean clouds) throws ShaderException {
|
||||
List<String> compileFlags = new ArrayList();
|
||||
if(paraboloid) {
|
||||
compileFlags.add("COMPILE_PARABOLOID_SKY");
|
||||
}
|
||||
if(clouds) {
|
||||
compileFlags.add("COMPILE_CLOUDS");
|
||||
}
|
||||
IShaderGL vertexShader = ShaderCompiler.compileShader("skybox_render", GL_VERTEX_SHADER,
|
||||
ShaderSource.skybox_render_vsh, compileFlags);
|
||||
IShaderGL fragmentShader = null;
|
||||
try {
|
||||
fragmentShader = ShaderCompiler.compileShader("skybox_render", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.skybox_render_fsh, compileFlags);
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("skybox_render", vertexShader, fragmentShader);
|
||||
return new PipelineShaderSkyboxRender(prog, paraboloid);
|
||||
}finally {
|
||||
if(vertexShader != null) {
|
||||
vertexShader.free();
|
||||
}
|
||||
if(fragmentShader != null) {
|
||||
fragmentShader.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderSkyboxRender(IProgramGL program, boolean paraboloid) {
|
||||
super(program, new Uniforms(paraboloid));
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public IUniformGL u_viewMatrix4f = null;
|
||||
public IUniformGL u_projMatrix4f = null;
|
||||
public IUniformGL u_sunDirection3f = null;
|
||||
public IUniformGL u_sunColor3f = null;
|
||||
public IUniformGL u_lightningColor4f = null;
|
||||
public IUniformGL u_farPlane1f = null;
|
||||
|
||||
public final boolean paraboloid;
|
||||
|
||||
private Uniforms(boolean paraboloid) {
|
||||
this.paraboloid = paraboloid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
u_viewMatrix4f = _wglGetUniformLocation(prog, "u_viewMatrix4f");
|
||||
u_projMatrix4f = _wglGetUniformLocation(prog, "u_projMatrix4f");
|
||||
u_sunDirection3f = _wglGetUniformLocation(prog, "u_sunDirection3f");
|
||||
u_sunColor3f = _wglGetUniformLocation(prog, "u_sunColor3f");
|
||||
u_lightningColor4f = _wglGetUniformLocation(prog, "u_lightningColor4f");
|
||||
u_farPlane1f = _wglGetUniformLocation(prog, "u_farPlane1f");
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_renderedAtmosphere"), 0);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_cloudsTexture"), 1);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_sunOcclusion"), 2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderSkyboxRenderEnd extends ShaderProgram<PipelineShaderSkyboxRenderEnd.Uniforms> {
|
||||
|
||||
public static PipelineShaderSkyboxRenderEnd compile() throws ShaderException {
|
||||
IShaderGL vertexShader = ShaderCompiler.compileShader("skybox_render_end", GL_VERTEX_SHADER,
|
||||
ShaderSource.skybox_render_end_vsh);
|
||||
IShaderGL fragmentShader = null;
|
||||
try {
|
||||
fragmentShader = ShaderCompiler.compileShader("skybox_render_end", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.skybox_render_end_fsh);
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("skybox_render_end", vertexShader, fragmentShader);
|
||||
return new PipelineShaderSkyboxRenderEnd(prog);
|
||||
}finally {
|
||||
if(vertexShader != null) {
|
||||
vertexShader.free();
|
||||
}
|
||||
if(fragmentShader != null) {
|
||||
fragmentShader.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderSkyboxRenderEnd(IProgramGL prog) {
|
||||
super(prog, new Uniforms());
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public IUniformGL u_viewMatrix4f = null;
|
||||
public IUniformGL u_projMatrix4f = null;
|
||||
public IUniformGL u_skyTextureScale2f = null;
|
||||
|
||||
private Uniforms() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
u_viewMatrix4f = _wglGetUniformLocation(prog, "u_viewMatrix4f");
|
||||
u_projMatrix4f = _wglGetUniformLocation(prog, "u_projMatrix4f");
|
||||
u_skyTextureScale2f = _wglGetUniformLocation(prog, "u_skyTextureScale2f");
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_skyTexture"), 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IUniformGL;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PipelineShaderTonemap extends ShaderProgram<PipelineShaderTonemap.Uniforms> {
|
||||
|
||||
public static PipelineShaderTonemap compile() throws ShaderException {
|
||||
IShaderGL tonemapOperator = ShaderCompiler.compileShader("post_tonemap", GL_FRAGMENT_SHADER,
|
||||
ShaderSource.post_tonemap_fsh);
|
||||
try {
|
||||
IProgramGL prog = ShaderCompiler.linkProgram("post_tonemap", SharedPipelineShaders.deferred_local, tonemapOperator);
|
||||
return new PipelineShaderTonemap(prog);
|
||||
}finally {
|
||||
if(tonemapOperator != null) {
|
||||
tonemapOperator.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PipelineShaderTonemap(IProgramGL program) {
|
||||
super(program, new Uniforms());
|
||||
}
|
||||
|
||||
public static class Uniforms implements IProgramUniforms {
|
||||
|
||||
public IUniformGL u_exposure3f;
|
||||
public IUniformGL u_ditherScale2f;
|
||||
|
||||
@Override
|
||||
public void loadUniforms(IProgramGL prog) {
|
||||
u_exposure3f = _wglGetUniformLocation(prog, "u_exposure3f");
|
||||
u_ditherScale2f = _wglGetUniformLocation(prog, "u_ditherScale2f");
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_lightingHDRFramebufferTexture"), 0);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_framebufferLumaAvgInput"), 1);
|
||||
_wglUniform1i(_wglGetUniformLocation(prog, "u_ditherTexture"), 2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class ShaderCompileException extends ShaderException {
|
||||
|
||||
public final int stage;
|
||||
public final String fileName;
|
||||
|
||||
public ShaderCompileException(String shaderName, int stage, String fileName, String msg) {
|
||||
super(shaderName, msg);
|
||||
this.stage = stage;
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.FixedFunctionShader;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class ShaderCompiler {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger("DeferredPipelineCompiler");
|
||||
|
||||
public static IShaderGL compileShader(String name, int stage, ResourceLocation filename, String... compileFlags) throws ShaderCompileException {
|
||||
return compileShader(name, stage, filename.toString(), ShaderSource.getSourceFor(filename), Arrays.asList(compileFlags));
|
||||
}
|
||||
|
||||
public static IShaderGL compileShader(String name, int stage, String filename, String source, String... compileFlags) throws ShaderCompileException {
|
||||
return compileShader(name, stage, filename, source, Arrays.asList(compileFlags));
|
||||
}
|
||||
|
||||
public static IShaderGL compileShader(String name, int stage, ResourceLocation filename, List<String> compileFlags) throws ShaderCompileException {
|
||||
return compileShader(name, stage, filename.toString(), ShaderSource.getSourceFor(filename), compileFlags);
|
||||
}
|
||||
|
||||
public static IShaderGL compileShader(String name, int stage, String filename, String source, List<String> compileFlags) throws ShaderCompileException {
|
||||
logger.info("Compiling Shader: " + filename);
|
||||
StringBuilder srcCat = new StringBuilder();
|
||||
srcCat.append(FixedFunctionShader.FixedFunctionConstants.VERSION).append('\n');
|
||||
|
||||
if(compileFlags != null && compileFlags.size() > 0) {
|
||||
for(int i = 0, l = compileFlags.size(); i < l; ++i) {
|
||||
srcCat.append("#define ").append(compileFlags.get(i)).append('\n');
|
||||
}
|
||||
}
|
||||
|
||||
IShaderGL ret = _wglCreateShader(stage);
|
||||
_wglShaderSource(ret, srcCat.append(source).toString());
|
||||
_wglCompileShader(ret);
|
||||
|
||||
if(_wglGetShaderi(ret, GL_COMPILE_STATUS) != GL_TRUE) {
|
||||
logger.error("Failed to compile {} \"{}\" of program \"{}\"!", getStageName(stage), filename, name);
|
||||
String log = _wglGetShaderInfoLog(ret);
|
||||
if(log != null) {
|
||||
String s2 = getStageNameV2(stage);
|
||||
String[] lines = log.split("(\\r\\n|\\r|\\n)");
|
||||
for(int i = 0; i < lines.length; ++i) {
|
||||
logger.error("[{}] [{}] [{}] {}", name, s2, filename, lines[i]);
|
||||
}
|
||||
}
|
||||
_wglDeleteShader(ret);
|
||||
throw new ShaderCompileException(name, stage, filename, "Compile status for " + getStageName(stage) + " \"" + filename + "\" of \"" + name + "\" is not GL_TRUE!");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static IProgramGL linkProgram(String name, IShaderGL vert, IShaderGL frag) throws ShaderLinkException {
|
||||
IProgramGL ret = _wglCreateProgram();
|
||||
|
||||
_wglAttachShader(ret, vert);
|
||||
_wglAttachShader(ret, frag);
|
||||
_wglLinkProgram(ret);
|
||||
_wglDetachShader(ret, vert);
|
||||
_wglDetachShader(ret, frag);
|
||||
|
||||
if(_wglGetProgrami(ret, GL_LINK_STATUS) != GL_TRUE) {
|
||||
logger.error("Failed to link program \"{}\"!", name);
|
||||
String log = _wglGetProgramInfoLog(ret);
|
||||
if(log != null) {
|
||||
String[] lines = log.split("(\\r\\n|\\r|\\n)");
|
||||
for(int i = 0; i < lines.length; ++i) {
|
||||
logger.error("[{}] [LINK] {}", name, lines[i]);
|
||||
}
|
||||
}
|
||||
_wglDeleteProgram(ret);
|
||||
throw new ShaderLinkException(name, "Link status for program \"" + name + "\" is not GL_TRUE!");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static String getStageName(int stage) {
|
||||
switch(stage) {
|
||||
case GL_VERTEX_SHADER:
|
||||
return "GL_VERTEX_SHADER";
|
||||
case GL_FRAGMENT_SHADER:
|
||||
return "GL_FRAGMENT_SHADER";
|
||||
default:
|
||||
return "stage_" + stage;
|
||||
}
|
||||
}
|
||||
|
||||
private static String getStageNameV2(int stage) {
|
||||
switch(stage) {
|
||||
case GL_VERTEX_SHADER:
|
||||
return "VERT";
|
||||
case GL_FRAGMENT_SHADER:
|
||||
return "FRAG";
|
||||
default:
|
||||
return "stage_" + stage;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class ShaderException extends IllegalStateException {
|
||||
|
||||
public final String shaderName;
|
||||
|
||||
public ShaderException(String shaderName, String msg) {
|
||||
super(msg);
|
||||
this.shaderName = shaderName;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class ShaderLinkException extends ShaderException {
|
||||
|
||||
public ShaderLinkException(String shaderName, String msg) {
|
||||
super(shaderName, msg);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IProgramGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.EaglercraftGPU;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class ShaderProgram<U extends IProgramUniforms> {
|
||||
|
||||
public final IProgramGL program;
|
||||
public final U uniforms;
|
||||
|
||||
public ShaderProgram(IProgramGL program, U uniforms) {
|
||||
this.program = program;
|
||||
this.uniforms = uniforms;
|
||||
}
|
||||
|
||||
public ShaderProgram<U> loadUniforms() {
|
||||
if(uniforms != null) {
|
||||
EaglercraftGPU.bindGLShaderProgram(program);
|
||||
uniforms.loadUniforms(program);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public void useProgram() {
|
||||
EaglercraftGPU.bindGLShaderProgram(program);
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
program.free();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,186 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.text.StrTokenizer;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class ShaderSource {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger("ShaderSource");
|
||||
|
||||
public static final ResourceLocation accel_particle_vsh = new ResourceLocation("eagler:glsl/deferred/accel_particle.vsh");
|
||||
public static final ResourceLocation accel_particle_gbuffer_fsh = new ResourceLocation("eagler:glsl/deferred/accel_particle_gbuffer.fsh");
|
||||
public static final ResourceLocation accel_particle_forward_fsh = new ResourceLocation("eagler:glsl/deferred/accel_particle_forward.fsh");
|
||||
public static final ResourceLocation deferred_core_vsh = new ResourceLocation("eagler:glsl/deferred/deferred_core.vsh");
|
||||
public static final ResourceLocation deferred_core_gbuffer_fsh = new ResourceLocation("eagler:glsl/deferred/deferred_core_gbuffer.fsh");
|
||||
public static final ResourceLocation deferred_shadow_vsh = new ResourceLocation("eagler:glsl/deferred/deferred_shadow.vsh");
|
||||
public static final ResourceLocation deferred_shadow_fsh = new ResourceLocation("eagler:glsl/deferred/deferred_shadow.fsh");
|
||||
public static final ResourceLocation deferred_local_vsh = new ResourceLocation("eagler:glsl/deferred/deferred_local.vsh");
|
||||
public static final ResourceLocation deferred_combine_fsh = new ResourceLocation("eagler:glsl/deferred/deferred_combine.fsh");
|
||||
public static final ResourceLocation deferred_fog_fsh = new ResourceLocation("eagler:glsl/deferred/deferred_fog.fsh");
|
||||
public static final ResourceLocation forward_core_vsh = new ResourceLocation("eagler:glsl/deferred/forward_core.vsh");
|
||||
public static final ResourceLocation forward_core_fsh = new ResourceLocation("eagler:glsl/deferred/forward_core.fsh");
|
||||
public static final ResourceLocation forward_glass_highlights_vsh = new ResourceLocation("eagler:glsl/deferred/forward_glass_highlights.vsh");
|
||||
public static final ResourceLocation forward_glass_highlights_fsh = new ResourceLocation("eagler:glsl/deferred/forward_glass_highlights.fsh");
|
||||
public static final ResourceLocation realistic_water_mask_vsh = new ResourceLocation("eagler:glsl/deferred/realistic_water_mask.vsh");
|
||||
public static final ResourceLocation realistic_water_mask_fsh = new ResourceLocation("eagler:glsl/deferred/realistic_water_mask.fsh");
|
||||
public static final ResourceLocation realistic_water_render_vsh = new ResourceLocation("eagler:glsl/deferred/realistic_water_render.vsh");
|
||||
public static final ResourceLocation realistic_water_render_fsh = new ResourceLocation("eagler:glsl/deferred/realistic_water_render.fsh");
|
||||
public static final ResourceLocation realistic_water_control_fsh = new ResourceLocation("eagler:glsl/deferred/realistic_water_control.fsh");
|
||||
public static final ResourceLocation realistic_water_normals_fsh = new ResourceLocation("eagler:glsl/deferred/realistic_water_normals.fsh");
|
||||
public static final ResourceLocation realistic_water_noise_fsh = new ResourceLocation("eagler:glsl/deferred/realistic_water_noise.fsh");
|
||||
public static final ResourceLocation gbuffer_debug_view_fsh = new ResourceLocation("eagler:glsl/deferred/gbuffer_debug_view.fsh");
|
||||
public static final ResourceLocation ssao_generate_fsh = new ResourceLocation("eagler:glsl/deferred/ssao_generate.fsh");
|
||||
public static final ResourceLocation lighting_sun_fsh = new ResourceLocation("eagler:glsl/deferred/lighting_sun.fsh");
|
||||
public static final ResourceLocation shadows_sun_fsh = new ResourceLocation("eagler:glsl/deferred/shadows_sun.fsh");
|
||||
public static final ResourceLocation light_shafts_sample_fsh = new ResourceLocation("eagler:glsl/deferred/light_shafts_sample.fsh");
|
||||
public static final ResourceLocation post_tonemap_fsh = new ResourceLocation("eagler:glsl/deferred/post_tonemap.fsh");
|
||||
public static final ResourceLocation post_bloom_bright_fsh = new ResourceLocation("eagler:glsl/deferred/post_bloom_bright.fsh");
|
||||
public static final ResourceLocation post_bloom_blur_fsh = new ResourceLocation("eagler:glsl/deferred/post_bloom_blur.fsh");
|
||||
public static final ResourceLocation post_lens_distort_fsh = new ResourceLocation("eagler:glsl/deferred/post_lens_distort.fsh");
|
||||
public static final ResourceLocation post_exposure_avg_fsh = new ResourceLocation("eagler:glsl/deferred/post_exposure_avg.fsh");
|
||||
public static final ResourceLocation post_exposure_final_fsh = new ResourceLocation("eagler:glsl/deferred/post_exposure_final.fsh");
|
||||
public static final ResourceLocation post_lens_streaks_vsh = new ResourceLocation("eagler:glsl/deferred/post_lens_streaks.vsh");
|
||||
public static final ResourceLocation post_lens_streaks_fsh = new ResourceLocation("eagler:glsl/deferred/post_lens_streaks.fsh");
|
||||
public static final ResourceLocation post_lens_ghosts_vsh = new ResourceLocation("eagler:glsl/deferred/post_lens_ghosts.vsh");
|
||||
public static final ResourceLocation post_lens_ghosts_fsh = new ResourceLocation("eagler:glsl/deferred/post_lens_ghosts.fsh");
|
||||
public static final ResourceLocation lens_sun_occlusion_fsh = new ResourceLocation("eagler:glsl/deferred/lens_sun_occlusion.fsh");
|
||||
public static final ResourceLocation skybox_atmosphere_fsh = new ResourceLocation("eagler:glsl/deferred/skybox_atmosphere.fsh");
|
||||
public static final ResourceLocation skybox_irradiance_fsh = new ResourceLocation("eagler:glsl/deferred/skybox_irradiance.fsh");
|
||||
public static final ResourceLocation skybox_render_vsh = new ResourceLocation("eagler:glsl/deferred/skybox_render.vsh");
|
||||
public static final ResourceLocation skybox_render_fsh = new ResourceLocation("eagler:glsl/deferred/skybox_render.fsh");
|
||||
public static final ResourceLocation skybox_render_end_vsh = new ResourceLocation("eagler:glsl/deferred/skybox_render_end.vsh");
|
||||
public static final ResourceLocation skybox_render_end_fsh = new ResourceLocation("eagler:glsl/deferred/skybox_render_end.fsh");
|
||||
public static final ResourceLocation moon_render_vsh = new ResourceLocation("eagler:glsl/deferred/moon_render.vsh");
|
||||
public static final ResourceLocation moon_render_fsh = new ResourceLocation("eagler:glsl/deferred/moon_render.fsh");
|
||||
public static final ResourceLocation clouds_noise3d_fsh = new ResourceLocation("eagler:glsl/deferred/clouds_noise3d.fsh");
|
||||
public static final ResourceLocation clouds_shapes_fsh = new ResourceLocation("eagler:glsl/deferred/clouds_shapes.fsh");
|
||||
public static final ResourceLocation clouds_shapes_vsh = new ResourceLocation("eagler:glsl/deferred/clouds_shapes.vsh");
|
||||
public static final ResourceLocation clouds_sample_fsh = new ResourceLocation("eagler:glsl/deferred/clouds_sample.fsh");
|
||||
public static final ResourceLocation clouds_sun_occlusion_fsh = new ResourceLocation("eagler:glsl/deferred/clouds_sun_occlusion.fsh");
|
||||
public static final ResourceLocation clouds_color_fsh = new ResourceLocation("eagler:glsl/deferred/clouds_color.fsh");
|
||||
public static final ResourceLocation lighting_mesh_vsh = new ResourceLocation("eagler:glsl/deferred/lighting_mesh.vsh");
|
||||
public static final ResourceLocation lighting_point_fsh = new ResourceLocation("eagler:glsl/deferred/lighting_point.fsh");
|
||||
public static final ResourceLocation reproject_control_fsh = new ResourceLocation("eagler:glsl/deferred/reproject_control.fsh");
|
||||
public static final ResourceLocation reproject_ssr_fsh = new ResourceLocation("eagler:glsl/deferred/reproject_ssr.fsh");
|
||||
public static final ResourceLocation post_fxaa_fsh = new ResourceLocation("eagler:glsl/deferred/post_fxaa.fsh");
|
||||
public static final ResourceLocation hand_depth_mask_fsh = new ResourceLocation("eagler:glsl/deferred/hand_depth_mask.fsh");
|
||||
|
||||
private static final Map<ResourceLocation, String> sourceCache = new HashMap();
|
||||
|
||||
private static boolean isHighP = false;
|
||||
|
||||
public static String getSourceFor(ResourceLocation path) {
|
||||
return getSourceFor(path, 0);
|
||||
}
|
||||
|
||||
private static String getSourceFor(ResourceLocation path, int lineNumberOffset) {
|
||||
String str = sourceCache.get(path);
|
||||
if(str == null) {
|
||||
try {
|
||||
str = loadSource(path, lineNumberOffset);
|
||||
}catch(IOException ex) {
|
||||
str = "";
|
||||
logger.error("Could not load shader source \"{}\"! {}", deferred_core_vsh, ex.toString());
|
||||
logger.error("This may cause a NullPointerException when enabling certain features");
|
||||
logger.error(ex);
|
||||
}
|
||||
sourceCache.put(path, str);
|
||||
}
|
||||
return str.length() == 0 ? null : str;
|
||||
}
|
||||
|
||||
private static String loadSource(ResourceLocation resourceLocation, int fileID) throws IOException {
|
||||
StringBuilder ret = new StringBuilder();
|
||||
try(InputStream is = Minecraft.getMinecraft().getResourceManager().getResource(resourceLocation).getInputStream()) {
|
||||
int lineCounter = 1;
|
||||
BufferedReader lineReader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
|
||||
String line;
|
||||
while((line = lineReader.readLine()) != null) {
|
||||
if(line.startsWith("#line ")) {
|
||||
String[] split = line.split("\\s+", 3);
|
||||
try {
|
||||
lineCounter = Integer.parseInt(split[1]);
|
||||
}catch(NumberFormatException ex) {
|
||||
throw new IOException("Invalid preprocessor directive: " + line, ex);
|
||||
}
|
||||
ret.append("#line ").append(lineCounter).append(' ').append(fileID).append('\n');
|
||||
}else if(line.startsWith("#EAGLER ")) {
|
||||
StrTokenizer tokenizer = new StrTokenizer(line.substring(8));
|
||||
tokenizer.setDelimiterChar(' ');
|
||||
tokenizer.setIgnoreEmptyTokens(true);
|
||||
tokenizer.setQuoteChar('\"');
|
||||
if(tokenizer.hasNext()) {
|
||||
String p1 = tokenizer.next();
|
||||
if(p1.equals("INCLUDE") && tokenizer.hasNext()) {
|
||||
String fileIDStr = tokenizer.next();
|
||||
if(tokenizer.hasNext() && fileIDStr.charAt(0) == '(' && fileIDStr.charAt(fileIDStr.length() - 1) == ')') {
|
||||
String includePath = tokenizer.next();
|
||||
if(!tokenizer.hasNext()) { // ignore if there are extra arguments
|
||||
int newFileId = -1;
|
||||
try {
|
||||
newFileId = Integer.parseInt(fileIDStr.substring(1, fileIDStr.length() - 1));
|
||||
}catch(NumberFormatException ex) {
|
||||
}
|
||||
if(newFileId != -1) {
|
||||
newFileId += fileID * 100;
|
||||
ret.append('\n').append("////////////////////////////////////////////////////////////////////").append('\n');
|
||||
ret.append("//" + line).append('\n');
|
||||
ret.append("#line 1 ").append(newFileId).append('\n');
|
||||
ret.append(getSourceFor(new ResourceLocation(includePath), newFileId)).append('\n');
|
||||
ret.append("////////////////////////////////////////////////////////////////////").append('\n');
|
||||
ret.append("#line ").append(lineCounter - 1).append(' ').append(fileID).append('\n').append('\n');
|
||||
++lineCounter;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
logger.error("Skipping invalid preprocessor directive: " + line);
|
||||
ret.append("// [INVALID]: " + line).append('\n');
|
||||
}else if(isHighP && line.startsWith("precision")) {
|
||||
ret.append(line.replace("lowp", "highp").replace("mediump", "highp")).append('\n');
|
||||
}else {
|
||||
ret.append(line).append('\n');
|
||||
}
|
||||
++lineCounter;
|
||||
}
|
||||
}
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
public static void clearCache() {
|
||||
sourceCache.clear();
|
||||
logger.info("Cleared Cache");
|
||||
}
|
||||
|
||||
public static void setHighP(boolean b) {
|
||||
isHighP = b;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.program;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IShaderGL;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class SharedPipelineShaders {
|
||||
|
||||
public static IShaderGL deferred_local = null;
|
||||
public static IShaderGL lighting_mesh = null;
|
||||
|
||||
public static void init() throws ShaderException {
|
||||
free();
|
||||
deferred_local = ShaderCompiler.compileShader("deferred_local_vsh", GL_VERTEX_SHADER, ShaderSource.deferred_local_vsh);
|
||||
lighting_mesh = ShaderCompiler.compileShader("lighting_mesh", GL_VERTEX_SHADER, ShaderSource.lighting_mesh_vsh);
|
||||
}
|
||||
|
||||
public static void free() {
|
||||
if(deferred_local != null) {
|
||||
deferred_local.free();
|
||||
deferred_local = null;
|
||||
}
|
||||
if(lighting_mesh != null) {
|
||||
lighting_mesh.free();
|
||||
lighting_mesh = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.texture;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.ImageData;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class EaglerBitwisePackedTexture {
|
||||
|
||||
private static int getFromBits(int idxx, int bits, byte[] bytes) {
|
||||
int startByte = idxx >> 3;
|
||||
int endByte = (idxx + bits - 1) >> 3;
|
||||
if(startByte == endByte) {
|
||||
return (((int)bytes[startByte] & 0xff) >> (8 - (idxx & 7) - bits)) & ((1 << bits) - 1);
|
||||
}else {
|
||||
return (((((int)bytes[startByte] & 0xff) << 8) | ((int)bytes[endByte] & 0xff)) >> (16 - (idxx & 7) - bits)) & ((1 << bits) - 1);
|
||||
}
|
||||
}
|
||||
|
||||
public static ImageData loadTexture(InputStream is, int alpha) throws IOException {
|
||||
if(is.read() != '%' || is.read() != 'E' || is.read() != 'B' || is.read() != 'P') {
|
||||
throw new IOException("Not an EBP file!");
|
||||
}
|
||||
int v = is.read();
|
||||
if(v != 1) {
|
||||
throw new IOException("Unknown EBP version: " + v);
|
||||
}
|
||||
v = is.read();
|
||||
if(v != 3) {
|
||||
throw new IOException("Invalid component count: " + v);
|
||||
}
|
||||
int w = is.read() | (is.read() << 8);
|
||||
int h = is.read() | (is.read() << 8);
|
||||
ImageData img = new ImageData(w, h, true);
|
||||
alpha <<= 24;
|
||||
v = is.read();
|
||||
if(v == 0) {
|
||||
for(int i = 0, l = w * h; i < l; ++i) {
|
||||
img.pixels[i] = is.read() | (is.read() << 8) | (is.read() << 16) | alpha;
|
||||
}
|
||||
}else if(v == 1) {
|
||||
int paletteSize = is.read();
|
||||
int[] palette = new int[paletteSize + 1];
|
||||
palette[0] = alpha;
|
||||
for(int i = 0; i < paletteSize; ++i) {
|
||||
palette[i + 1] = is.read() | (is.read() << 8) | (is.read() << 16) | alpha;
|
||||
}
|
||||
int bpp = is.read();
|
||||
byte[] readSet = new byte[is.read() | (is.read() << 8) | (is.read() << 16)];
|
||||
is.read(readSet);
|
||||
for(int i = 0, l = w * h; i < l; ++i) {
|
||||
img.pixels[i] = palette[getFromBits(i * bpp, bpp, readSet)];
|
||||
}
|
||||
}else {
|
||||
throw new IOException("Unknown EBP storage type: " + v);
|
||||
}
|
||||
if(is.read() != ':' || is.read() != '>') {
|
||||
throw new IOException("Invalid footer! (:>)");
|
||||
}
|
||||
return img;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,312 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.texture;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.HString;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IFramebufferGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
|
||||
import net.lax1dude.eaglercraft.v1_8.minecraft.EaglerTextureAtlasSprite;
|
||||
import net.lax1dude.eaglercraft.v1_8.minecraft.TextureAnimationCache;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.GlStateManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.ImageData;
|
||||
import net.minecraft.client.renderer.texture.TextureUtil;
|
||||
import net.minecraft.client.resources.data.AnimationFrame;
|
||||
import net.minecraft.client.resources.data.AnimationMetadataSection;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.crash.CrashReportCategory;
|
||||
import net.minecraft.util.ReportedException;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class EaglerTextureAtlasSpritePBR extends EaglerTextureAtlasSprite {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger("EaglerTextureAtlasSpritePBR");
|
||||
|
||||
protected List<int[][]>[] frameTextureDataPBR = new List[] { Lists.newArrayList(), Lists.newArrayList(), Lists.newArrayList() };
|
||||
protected TextureAnimationCache[] animationCachePBR = new TextureAnimationCache[3];
|
||||
|
||||
public boolean dontAnimateNormals = true;
|
||||
public boolean dontAnimateMaterial = true;
|
||||
|
||||
public static EaglerTextureAtlasSpritePBR makeAtlasSprite(ResourceLocation spriteResourceLocation) {
|
||||
String s = spriteResourceLocation.toString();
|
||||
return (EaglerTextureAtlasSpritePBR) (locationNameClock.equals(s) ? new TextureClockPBRImpl(s)
|
||||
: (locationNameCompass.equals(s) ? new TextureCompassPBRImpl(s) : new EaglerTextureAtlasSpritePBR(s)));
|
||||
}
|
||||
|
||||
public EaglerTextureAtlasSpritePBR(String spriteName) {
|
||||
super(spriteName);
|
||||
}
|
||||
|
||||
public void loadSpritePBR(ImageData[][] imageDatas, AnimationMetadataSection meta,
|
||||
boolean dontAnimateNormals, boolean dontAnimateMaterial) {
|
||||
this.resetSprite();
|
||||
if(imageDatas.length != 3) {
|
||||
throw new IllegalArgumentException("loadSpritePBR required an array of 3 different textures (" + imageDatas.length + " given)");
|
||||
}
|
||||
this.dontAnimateNormals = dontAnimateNormals;
|
||||
this.dontAnimateMaterial = dontAnimateMaterial;
|
||||
int i = imageDatas[0][0].width;
|
||||
int j = imageDatas[0][0].height;
|
||||
this.width = i;
|
||||
this.height = j;
|
||||
int[][][] aint = new int[3][imageDatas[0].length][];
|
||||
|
||||
for (int l = 0; l < imageDatas.length; ++l) {
|
||||
ImageData[] images = imageDatas[l];
|
||||
for (int k = 0; k < images.length; ++k) {
|
||||
ImageData bufferedimage = images[k];
|
||||
if (bufferedimage != null) {
|
||||
if (k > 0 && (bufferedimage.width) != i >> k || bufferedimage.height != j >> k) {
|
||||
throw new RuntimeException(
|
||||
HString.format("Unable to load miplevel: %d, image is size: %dx%d, expected %dx%d",
|
||||
new Object[] { Integer.valueOf(k), Integer.valueOf(bufferedimage.width),
|
||||
Integer.valueOf(bufferedimage.height), Integer.valueOf(i >> k),
|
||||
Integer.valueOf(j >> k) }));
|
||||
}
|
||||
|
||||
aint[l][k] = new int[bufferedimage.width * bufferedimage.height];
|
||||
bufferedimage.getRGB(0, 0, bufferedimage.width, bufferedimage.height, aint[l][k], 0, bufferedimage.width);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (meta == null) {
|
||||
if (j != i) {
|
||||
throw new RuntimeException("broken aspect ratio and not an animation");
|
||||
}
|
||||
|
||||
this.frameTextureDataPBR[0].add(aint[0]);
|
||||
this.frameTextureDataPBR[1].add(aint[1]);
|
||||
this.frameTextureDataPBR[2].add(aint[2]);
|
||||
} else {
|
||||
int j1 = j / i;
|
||||
int k1 = i;
|
||||
int l = i;
|
||||
this.height = this.width;
|
||||
if (meta.getFrameCount() > 0) {
|
||||
Iterator iterator = meta.getFrameIndexSet().iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
int i1 = ((Integer) iterator.next()).intValue();
|
||||
if (i1 >= j1) {
|
||||
throw new RuntimeException("invalid frameindex " + i1);
|
||||
}
|
||||
|
||||
this.allocateFrameTextureData(i1);
|
||||
this.frameTextureDataPBR[0].set(i1, getFrameTextureData(aint[0], k1, l, i1));
|
||||
this.frameTextureDataPBR[1].set(i1, getFrameTextureData(aint[1], k1, l, i1));
|
||||
this.frameTextureDataPBR[2].set(i1, getFrameTextureData(aint[2], k1, l, i1));
|
||||
}
|
||||
|
||||
this.animationMetadata = meta;
|
||||
} else {
|
||||
ArrayList arraylist = Lists.newArrayList();
|
||||
|
||||
for (int l1 = 0; l1 < j1; ++l1) {
|
||||
this.frameTextureDataPBR[0].add(getFrameTextureData(aint[0], k1, l, l1));
|
||||
this.frameTextureDataPBR[1].add(getFrameTextureData(aint[1], k1, l, l1));
|
||||
this.frameTextureDataPBR[2].add(getFrameTextureData(aint[2], k1, l, l1));
|
||||
arraylist.add(new AnimationFrame(l1, -1));
|
||||
}
|
||||
|
||||
this.animationMetadata = new AnimationMetadataSection(arraylist, this.width, this.height,
|
||||
meta.getFrameTime(), meta.isInterpolate());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int[][][] getFramePBRTextureData(int index) {
|
||||
return new int[][][] { frameTextureDataPBR[0].get(index),
|
||||
frameTextureDataPBR[1].get(index),
|
||||
frameTextureDataPBR[2].get(index) };
|
||||
}
|
||||
|
||||
public int[][] getFrameTextureData(int index) {
|
||||
return frameTextureDataPBR[0].get(index);
|
||||
}
|
||||
|
||||
public int getFrameCount() {
|
||||
return frameTextureDataPBR[0].size();
|
||||
}
|
||||
|
||||
public void setFramesTextureDataPBR(List<int[][]>[] newFramesTextureData) {
|
||||
frameTextureDataPBR = newFramesTextureData;
|
||||
}
|
||||
|
||||
protected void allocateFrameTextureData(int index) {
|
||||
for(int j = 0; j < 3; ++j) {
|
||||
if (this.frameTextureDataPBR[j].size() <= index) {
|
||||
for (int i = this.frameTextureDataPBR[j].size(); i <= index; ++i) {
|
||||
this.frameTextureDataPBR[j].add((int[][]) null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void generateMipmaps(int level) {
|
||||
List[] arraylist = new List[] { Lists.newArrayList(), Lists.newArrayList(), Lists.newArrayList() };
|
||||
|
||||
for(int j = 0; j < 3; ++j) {
|
||||
for (int i = 0; i < this.frameTextureDataPBR[j].size(); ++i) {
|
||||
final int[][] aint = (int[][]) this.frameTextureDataPBR[j].get(i);
|
||||
if (aint != null) {
|
||||
try {
|
||||
if(j == 0) {
|
||||
arraylist[j].add(TextureUtil.generateMipmapData(level, this.width, aint));
|
||||
}else {
|
||||
arraylist[j].add(PBRTextureMapUtils.generateMipmapDataIgnoreAlpha(level, this.width, aint));
|
||||
}
|
||||
} catch (Throwable throwable) {
|
||||
CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Generating mipmaps for frame (pbr)");
|
||||
CrashReportCategory crashreportcategory = crashreport.makeCategory("Frame being iterated");
|
||||
crashreportcategory.addCrashSection("PBR Layer", Integer.valueOf(j));
|
||||
crashreportcategory.addCrashSection("Frame index", Integer.valueOf(i));
|
||||
crashreportcategory.addCrashSectionCallable("Frame sizes", new Callable<String>() {
|
||||
public String call() throws Exception {
|
||||
StringBuilder stringbuilder = new StringBuilder();
|
||||
|
||||
for (int[] aint1 : aint) {
|
||||
if (stringbuilder.length() > 0) {
|
||||
stringbuilder.append(", ");
|
||||
}
|
||||
|
||||
stringbuilder.append(aint1 == null ? "null" : Integer.valueOf(aint1.length));
|
||||
}
|
||||
|
||||
return stringbuilder.toString();
|
||||
}
|
||||
});
|
||||
throw new ReportedException(crashreport);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.setFramesTextureDataPBR(arraylist);
|
||||
this.bakeAnimationCache();
|
||||
}
|
||||
|
||||
public void bakeAnimationCache() {
|
||||
if(animationMetadata != null) {
|
||||
for(int i = 0; i < 3; ++i) {
|
||||
if(dontAnimateNormals && i == 1) continue;
|
||||
if(dontAnimateMaterial && i == 2) continue;
|
||||
int mipLevels = frameTextureDataPBR[i].get(0).length;
|
||||
if(animationCachePBR[i] == null) {
|
||||
animationCachePBR[i] = new TextureAnimationCache(width, height, mipLevels);
|
||||
}
|
||||
animationCachePBR[i].initialize(frameTextureDataPBR[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateAnimationPBR(IFramebufferGL[] copyColorFramebuffer, IFramebufferGL[] copyMaterialFramebuffer, int materialTexOffset) {
|
||||
if(animationCachePBR[0] == null || (!dontAnimateNormals && animationCachePBR[1] == null)
|
||||
|| (!dontAnimateMaterial && animationCachePBR[2] == null)) {
|
||||
throw new IllegalStateException("Animation cache for '" + this.iconName + "' was never baked!");
|
||||
}
|
||||
++this.tickCounter;
|
||||
if (this.tickCounter >= this.animationMetadata.getFrameTimeSingle(this.frameCounter)) {
|
||||
int i = this.animationMetadata.getFrameIndex(this.frameCounter);
|
||||
int j = this.animationMetadata.getFrameCount() == 0 ? this.frameTextureDataPBR[0].size()
|
||||
: this.animationMetadata.getFrameCount();
|
||||
this.frameCounter = (this.frameCounter + 1) % j;
|
||||
this.tickCounter = 0;
|
||||
int k = this.animationMetadata.getFrameIndex(this.frameCounter);
|
||||
if (i != k && k >= 0 && k < this.frameTextureDataPBR[0].size()) {
|
||||
animationCachePBR[0].copyFrameLevelsToTex2D(k, this.originX, this.originY, this.width, this.height, copyColorFramebuffer);
|
||||
if(!dontAnimateNormals) animationCachePBR[1].copyFrameLevelsToTex2D(k, this.originX, this.originY, this.width, this.height, copyMaterialFramebuffer);
|
||||
if(!dontAnimateMaterial) animationCachePBR[2].copyFrameLevelsToTex2D(k, this.originX, this.originY + materialTexOffset, this.width, this.height, copyMaterialFramebuffer);
|
||||
}
|
||||
} else if (this.animationMetadata.isInterpolate()) {
|
||||
float f = 1.0f - (float) this.tickCounter / (float) this.animationMetadata.getFrameTimeSingle(this.frameCounter);
|
||||
int i = this.animationMetadata.getFrameIndex(this.frameCounter);
|
||||
int j = this.animationMetadata.getFrameCount() == 0 ? this.frameTextureDataPBR[0].size()
|
||||
: this.animationMetadata.getFrameCount();
|
||||
int k = this.animationMetadata.getFrameIndex((this.frameCounter + 1) % j);
|
||||
if (i != k && k >= 0 && k < this.frameTextureDataPBR[0].size()) {
|
||||
animationCachePBR[0].copyInterpolatedFrameLevelsToTex2D(i, k, f, this.originX, this.originY, this.width, this.height, copyColorFramebuffer);
|
||||
if(!dontAnimateNormals) animationCachePBR[1].copyInterpolatedFrameLevelsToTex2D(i, k, f, this.originX, this.originY, this.width, this.height, copyMaterialFramebuffer);
|
||||
if(!dontAnimateMaterial) animationCachePBR[2].copyInterpolatedFrameLevelsToTex2D(i, k, f, this.originX, this.originY + materialTexOffset, this.width, this.height, copyMaterialFramebuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void clearFramesTextureData() {
|
||||
for(int i = 0; i < 3; ++i) {
|
||||
this.frameTextureDataPBR[i].clear();
|
||||
if(this.animationCachePBR[i] != null) {
|
||||
this.animationCachePBR[i].free();
|
||||
this.animationCachePBR[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void loadSprite(ImageData[] images, AnimationMetadataSection meta) throws IOException {
|
||||
Throwable t = new UnsupportedOperationException("Cannot call regular loadSprite in PBR mode, use loadSpritePBR");
|
||||
try {
|
||||
throw t;
|
||||
}catch(Throwable tt) {
|
||||
logger.error(t);
|
||||
}
|
||||
}
|
||||
|
||||
public void setFramesTextureData(List<int[][]> newFramesTextureData) {
|
||||
Throwable t = new UnsupportedOperationException("Cannot call regular setFramesTextureData in PBR mode, use setFramesTextureDataPBR");
|
||||
try {
|
||||
throw t;
|
||||
}catch(Throwable tt) {
|
||||
logger.error(t);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateAnimation(IFramebufferGL[] fb) {
|
||||
Throwable t = new UnsupportedOperationException("Cannot call regular updateAnimation in PBR mode, use updateAnimationPBR");
|
||||
try {
|
||||
throw t;
|
||||
}catch(Throwable tt) {
|
||||
logger.error(t);
|
||||
}
|
||||
}
|
||||
|
||||
protected void resetSprite() {
|
||||
this.animationMetadata = null;
|
||||
this.setFramesTextureDataPBR(new List[] { Lists.newArrayList(), Lists.newArrayList(), Lists.newArrayList() });
|
||||
this.frameCounter = 0;
|
||||
this.tickCounter = 0;
|
||||
for(int i = 0; i < 3; ++i) {
|
||||
if(this.animationCachePBR[i] != null) {
|
||||
this.animationCachePBR[i].free();
|
||||
this.animationCachePBR[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "EaglerTextureAtlasSpritePBR{name=\'" + this.iconName + '\'' + ", frameCount=" + this.framesTextureData.size()
|
||||
+ ", rotated=" + this.rotated + ", x=" + this.originX + ", y=" + this.originY + ", height="
|
||||
+ this.height + ", width=" + this.width + ", u0=" + this.minU + ", u1=" + this.maxU + ", v0="
|
||||
+ this.minV + ", v1=" + this.maxV + '}';
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.texture;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.resources.IResourceManagerReloadListener;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class EmissiveItems implements IResourceManagerReloadListener {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger("EmissiveItemsCSV");
|
||||
|
||||
private static final Map<String,float[]> entries = new HashMap();
|
||||
|
||||
public static float[] getItemEmission(ItemStack itemStack) {
|
||||
return getItemEmission(itemStack.getItem(), itemStack.getItemDamage());
|
||||
}
|
||||
|
||||
public static float[] getItemEmission(Item item, int damage) {
|
||||
return entries.get(Item.itemRegistry.getNameForObject(item).toString() + "#" + damage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager var1) {
|
||||
try {
|
||||
IResource itemsCsv = var1.getResource(new ResourceLocation("eagler:glsl/deferred/emissive_items.csv"));
|
||||
try (BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(itemsCsv.getInputStream(), StandardCharsets.UTF_8))) {
|
||||
entries.clear();
|
||||
String line;
|
||||
boolean firstLine = true;
|
||||
while((line = reader.readLine()) != null) {
|
||||
if((line = line.trim()).length() > 0) {
|
||||
if(firstLine) {
|
||||
firstLine = false;
|
||||
continue;
|
||||
}
|
||||
String[] split = line.split(",");
|
||||
if(split.length == 6) {
|
||||
try {
|
||||
int dmg = Integer.parseInt(split[1]);
|
||||
float r = Float.parseFloat(split[2]);
|
||||
float g = Float.parseFloat(split[3]);
|
||||
float b = Float.parseFloat(split[4]);
|
||||
float i = Float.parseFloat(split[5]);
|
||||
r *= i;
|
||||
g *= i;
|
||||
b *= i;
|
||||
entries.put(split[0] + "#" + dmg, new float[] { r, g, b });
|
||||
continue;
|
||||
}catch(NumberFormatException ex) {
|
||||
}
|
||||
}
|
||||
logger.error("Skipping bad emissive item entry: {}", line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch(Throwable t) {
|
||||
logger.error("Could not load list of emissive items!");
|
||||
logger.error(t);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.texture;
|
||||
|
||||
public class IEEE754 {
|
||||
|
||||
// source: https://stackoverflow.com/questions/6162651/half-precision-floating-point-in-java
|
||||
|
||||
public static int encodeHalfFloat(float fval) {
|
||||
int fbits = Float.floatToIntBits(fval);
|
||||
int sign = fbits >>> 16 & 0x8000; // sign only
|
||||
int val = (fbits & 0x7fffffff) + 0x1000; // rounded value
|
||||
|
||||
if (val >= 0x47800000) // might be or become NaN/Inf
|
||||
{ // avoid Inf due to rounding
|
||||
if ((fbits & 0x7fffffff) >= 0x47800000) { // is or must become NaN/Inf
|
||||
if (val < 0x7f800000) // was value but too large
|
||||
return sign | 0x7c00; // make it +/-Inf
|
||||
return sign | 0x7c00 | // remains +/-Inf or NaN
|
||||
(fbits & 0x007fffff) >>> 13; // keep NaN (and Inf) bits
|
||||
}
|
||||
return sign | 0x7bff; // unrounded not quite Inf
|
||||
}
|
||||
if (val >= 0x38800000) // remains normalized value
|
||||
return sign | val - 0x38000000 >>> 13; // exp - 127 + 15
|
||||
if (val < 0x33000000) // too small for subnormal
|
||||
return sign; // becomes +/-0
|
||||
val = (fbits & 0x7fffffff) >>> 23; // tmp exp for subnormal calc
|
||||
return sign | ((fbits & 0x7fffff | 0x800000) // add subnormal bit
|
||||
+ (0x800000 >>> val - 102) // round depending on cut off
|
||||
>>> 126 - val); // div by 2^(1-(exp-127+15)) and >> 13 | exp=0
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,149 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.texture;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.EagRuntime;
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.buffer.ByteBuffer;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.EaglercraftGPU;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.GlStateManager;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.resources.IResourceManagerReloadListener;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import static net.lax1dude.eaglercraft.v1_8.opengl.RealOpenGLEnums.*;
|
||||
import static net.lax1dude.eaglercraft.v1_8.internal.PlatformOpenGL.*;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2022-2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class MetalsLUT implements IResourceManagerReloadListener {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger("MetalsLUT");
|
||||
|
||||
private static int glTexture = -1;
|
||||
|
||||
public static int getGLTexture() {
|
||||
if(glTexture == -1) {
|
||||
float[] lut = new float[128];
|
||||
for(int i = 0, j; i < 16; ++i) {
|
||||
j = i << 3;
|
||||
lut[i] = 1.0f;
|
||||
lut[i + 1] = 1.0f;
|
||||
lut[i + 2] = 1.0f;
|
||||
lut[i + 3] = 0.0f;
|
||||
lut[i + 4] = 1.0f;
|
||||
lut[i + 5] = 1.0f;
|
||||
lut[i + 6] = 1.0f;
|
||||
lut[i + 7] = 0.0f;
|
||||
}
|
||||
try {
|
||||
IResource metalsCsv = Minecraft.getMinecraft().getResourceManager()
|
||||
.getResource(new ResourceLocation("eagler:glsl/deferred/metals.csv"));
|
||||
try (BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(metalsCsv.getInputStream(), StandardCharsets.UTF_8))) {
|
||||
String line;
|
||||
int cnt = 0;
|
||||
boolean firstLine = true;
|
||||
while((line = reader.readLine()) != null) {
|
||||
if((line = line.trim()).length() > 0) {
|
||||
if(firstLine) {
|
||||
firstLine = false;
|
||||
continue;
|
||||
}
|
||||
String[] split = line.split(",");
|
||||
if(split.length == 8) {
|
||||
try {
|
||||
int id = Integer.parseInt(split[1]);
|
||||
float nr = Float.parseFloat(split[2]);
|
||||
float ng = Float.parseFloat(split[3]);
|
||||
float nb = Float.parseFloat(split[4]);
|
||||
float kr = Float.parseFloat(split[5]);
|
||||
float kg = Float.parseFloat(split[6]);
|
||||
float kb = Float.parseFloat(split[7]);
|
||||
if(id < 230 || id > 245) {
|
||||
logger.error("Error, only metal IDs 230 to 245 are configurable!");
|
||||
}else {
|
||||
int i = (id - 230) << 3;
|
||||
lut[i] = nr;
|
||||
lut[i + 1] = ng;
|
||||
lut[i + 2] = nb;
|
||||
lut[i + 4] = kr;
|
||||
lut[i + 5] = kg;
|
||||
lut[i + 6] = kb;
|
||||
}
|
||||
++cnt;
|
||||
continue;
|
||||
}catch(NumberFormatException ex) {
|
||||
}
|
||||
}
|
||||
logger.error("Skipping bad metal constant entry: {}", line);
|
||||
}
|
||||
}
|
||||
logger.info("Loaded {} metal definitions", cnt);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error("Failed to load PBR metal lookup table!");
|
||||
logger.error(e);
|
||||
}
|
||||
if(EaglercraftGPU.checkHDRFramebufferSupport(16)) {
|
||||
ByteBuffer pixels = EagRuntime.allocateByteBuffer(256);
|
||||
for(int i = 0; i < 128; ++i) {
|
||||
pixels.putShort((short)IEEE754.encodeHalfFloat(lut[i]));
|
||||
}
|
||||
pixels.flip();
|
||||
glTexture = GlStateManager.generateTexture();
|
||||
GlStateManager.bindTexture(glTexture);
|
||||
setupFiltering();
|
||||
EaglercraftGPU.createFramebufferHDR16FTexture(GL_TEXTURE_2D, 0, 2, 16, GL_RGBA, pixels);
|
||||
EagRuntime.freeByteBuffer(pixels);
|
||||
}else if(EaglercraftGPU.checkHDRFramebufferSupport(32)) {
|
||||
logger.warn("16-bit HDR textures are not supported, using 32-bit fallback format");
|
||||
ByteBuffer pixels = EagRuntime.allocateByteBuffer(512);
|
||||
for(int i = 0; i < 128; ++i) {
|
||||
pixels.putFloat(lut[i]);
|
||||
}
|
||||
pixels.flip();
|
||||
glTexture = GlStateManager.generateTexture();
|
||||
GlStateManager.bindTexture(glTexture);
|
||||
setupFiltering();
|
||||
EaglercraftGPU.createFramebufferHDR32FTexture(GL_TEXTURE_2D, 0, 2, 16, GL_RGBA, pixels);
|
||||
EagRuntime.freeByteBuffer(pixels);
|
||||
}else {
|
||||
throw new UnsupportedOperationException("HDR textures are unavailable, could not create PBR metal definition LUT!");
|
||||
}
|
||||
}
|
||||
return glTexture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager var1) {
|
||||
if(glTexture != -1) {
|
||||
GlStateManager.deleteTexture(glTexture);
|
||||
glTexture = -1;
|
||||
}
|
||||
}
|
||||
|
||||
private static void setupFiltering() {
|
||||
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
_wglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.texture;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.resources.IResourceManagerReloadListener;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PBRMaterialConstants implements IResourceManagerReloadListener {
|
||||
|
||||
public static final Logger logger = LogManager.getLogger("PBRMaterialConstants");
|
||||
|
||||
public final ResourceLocation resourceLocation;
|
||||
public final Map<String,Integer> spriteNameToMaterialConstants = new HashMap();
|
||||
|
||||
public int defaultMaterial = 0x00000A77;
|
||||
|
||||
public PBRMaterialConstants(ResourceLocation resourceLocation) {
|
||||
this.resourceLocation = resourceLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager var1) {
|
||||
try(InputStream is = var1.getResource(resourceLocation).getInputStream()) {
|
||||
spriteNameToMaterialConstants.clear();
|
||||
BufferedReader bf = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
|
||||
String line;
|
||||
boolean firstLine = true;
|
||||
while((line = bf.readLine()) != null) {
|
||||
if((line = line.trim()).length() == 0) {
|
||||
continue;
|
||||
}
|
||||
if(firstLine) {
|
||||
firstLine = false;
|
||||
continue;
|
||||
}
|
||||
String[] cols = line.split(",");
|
||||
if(cols.length == 4) {
|
||||
try {
|
||||
int value = Integer.parseInt(cols[1]) | (Integer.parseInt(cols[2]) << 8) | (Integer.parseInt(cols[3]) << 16);
|
||||
if(cols[0].equals("default")) {
|
||||
defaultMaterial = value;
|
||||
}else {
|
||||
Integer v = spriteNameToMaterialConstants.get(cols[0]);
|
||||
if(v == null) {
|
||||
spriteNameToMaterialConstants.put(cols[0], value);
|
||||
}else if(v.intValue() != value) {
|
||||
logger.warn("Inconsistent material definition for sprite \"{}\": {}", cols[0], line);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}catch(NumberFormatException fmt) {
|
||||
}
|
||||
}
|
||||
logger.error("Skipping bad material constant entry: {}", line);
|
||||
}
|
||||
}catch(IOException ex) {
|
||||
logger.error("Could not load \"{}\"!", resourceLocation.toString());
|
||||
logger.error(ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,168 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.texture;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.ImageData;
|
||||
import net.minecraft.client.renderer.texture.TextureUtil;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class PBRTextureMapUtils {
|
||||
|
||||
public static final ImageData defaultNormalsTexture = new ImageData(1, 1, new int[] { 0 }, true);
|
||||
|
||||
public static final PBRMaterialConstants blockMaterialConstants = new PBRMaterialConstants(new ResourceLocation("eagler:glsl/deferred/material_block_constants.csv"));
|
||||
|
||||
public static final Logger logger = LogManager.getLogger("PBRTextureMap");
|
||||
|
||||
public static ImageData locateCompanionTexture(IResourceManager resMgr, IResource mainImage, String ext) {
|
||||
ResourceLocation baseLocation = mainImage.getResourceLocation();
|
||||
String domain = baseLocation.getResourceDomain();
|
||||
String resourcePack = mainImage.getResourcePackName();
|
||||
String fname = baseLocation.getResourcePath();
|
||||
int idx = fname.lastIndexOf('.');
|
||||
if(idx != -1) {
|
||||
fname = fname.substring(0, idx) + ext + fname.substring(idx);
|
||||
}else {
|
||||
fname += ext;
|
||||
}
|
||||
try {
|
||||
List<IResource> ress = resMgr.getAllResources(new ResourceLocation(domain, fname));
|
||||
for(IResource res : ress) {
|
||||
if(res.getResourcePackName().equals(resourcePack)) {
|
||||
ImageData toRet = TextureUtil.readBufferedImage(res.getInputStream());
|
||||
if(ext.equals("_s")) {
|
||||
for(int i = 0, j; i < toRet.pixels.length; ++i) {
|
||||
// swap B and A, because labPBR support
|
||||
int a = (toRet.pixels[i] >>> 24) & 0xFF;
|
||||
if(a == 0xFF) a = 0;
|
||||
toRet.pixels[i] = (toRet.pixels[i] & 0x0000FFFF) | Math.min(a << 18, 0xFF0000) | 0xFF000000;
|
||||
}
|
||||
}
|
||||
return toRet;
|
||||
}
|
||||
}
|
||||
}catch(Throwable t) {
|
||||
}
|
||||
if("Default".equals(resourcePack)) {
|
||||
idx = fname.lastIndexOf('.');
|
||||
if(idx != -1) {
|
||||
fname = fname.substring(0, idx);
|
||||
}
|
||||
try {
|
||||
return TextureUtil.readBufferedImage(resMgr.getResource(new ResourceLocation("eagler:glsl/deferred/assets_pbr/" + fname + ".png")).getInputStream());
|
||||
}catch(Throwable t) {
|
||||
}
|
||||
try {
|
||||
return EaglerBitwisePackedTexture.loadTexture(resMgr.getResource(new ResourceLocation("eagler:glsl/deferred/assets_pbr/" + fname + ".ebp")).getInputStream(), 255);
|
||||
}catch(Throwable t) {
|
||||
// dead code because teavm
|
||||
t.toString();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void unifySizes(int lvl, ImageData[]... imageSets) {
|
||||
int resX = -1;
|
||||
int resY = -1;
|
||||
int iw, ih;
|
||||
for(int i = 0; i < imageSets.length; ++i) {
|
||||
iw = imageSets[i][lvl].width;
|
||||
ih = imageSets[i][lvl].height;
|
||||
if(iw != ih) {
|
||||
}
|
||||
if(iw > resX) {
|
||||
resX = iw;
|
||||
}
|
||||
if(ih > resY) {
|
||||
resY = ih;
|
||||
}
|
||||
}
|
||||
if(resX == -1 || resY == -1) {
|
||||
throw new IllegalArgumentException("No images were provided!");
|
||||
}
|
||||
for(int i = 0; i < imageSets.length; ++i) {
|
||||
ImageData in = imageSets[i][lvl];
|
||||
ImageData out = null;
|
||||
if(in.width != resX || in.height != resY) {
|
||||
out = new ImageData(resX, resY, true);
|
||||
if(in.width == 1 && in.height == 1) {
|
||||
int px = in.pixels[0];
|
||||
for(int j = 0; j < out.pixels.length; ++j) {
|
||||
out.pixels[j] = px;
|
||||
}
|
||||
}else {
|
||||
for(int y = 0; y < resY; ++y) {
|
||||
for(int x = 0; x < resX; ++x) {
|
||||
out.pixels[y * resX + x] = in.pixels[((y * in.height / resY)) * in.width + (x * in.width / resX)];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(out != null) {
|
||||
imageSets[i][lvl] = out;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ImageData generateMaterialTextureFor(String iconName) {
|
||||
if(iconName.startsWith("minecraft:")) {
|
||||
iconName = iconName.substring(10);
|
||||
}
|
||||
Integer in = blockMaterialConstants.spriteNameToMaterialConstants.get(iconName);
|
||||
if(in == null) {
|
||||
return new ImageData(1, 1, new int[] { blockMaterialConstants.defaultMaterial }, true);
|
||||
}else {
|
||||
return new ImageData(1, 1, new int[] { in.intValue() }, true);
|
||||
}
|
||||
}
|
||||
|
||||
public static int[][] generateMipmapDataIgnoreAlpha(int level, int width, int[][] aint) {
|
||||
int[][] ret = new int[level + 1][];
|
||||
ret[0] = aint[0];
|
||||
if (level > 0) {
|
||||
for(int i = 1; i <= level; ++i) {
|
||||
if(aint[i] != null) {
|
||||
ret[i] = aint[i];
|
||||
}else {
|
||||
int lvlW = width >> i, lvl2W = lvlW << 1;
|
||||
int len = lvlW * lvlW;
|
||||
ret[i] = new int[len];
|
||||
int x, y, s1, s2, s3, s4, c1, c2, c3, c4;
|
||||
for(int j = 0; j < len; ++j) {
|
||||
x = (j % len) << 1;
|
||||
y = (j / len) << 1;
|
||||
s1 = ret[i - 1][x + y * lvl2W];
|
||||
s2 = ret[i - 1][x + y * lvl2W + 1];
|
||||
s3 = ret[i - 1][x + y * lvl2W + lvl2W];
|
||||
s4 = ret[i - 1][x + y * lvl2W + lvl2W + 1];
|
||||
c1 = ((s1 >> 24) & 0xFF) + ((s2 >> 24) & 0xFF) + ((s3 >> 24) & 0xFF) + ((s4 >> 24) & 0xFF);
|
||||
c2 = ((s1 >> 16) & 0xFF) + ((s2 >> 16) & 0xFF) + ((s3 >> 16) & 0xFF) + ((s4 >> 16) & 0xFF);
|
||||
c3 = ((s1 >> 8) & 0xFF) + ((s2 >> 8) & 0xFF) + ((s3 >> 8) & 0xFF) + ((s4 >> 8) & 0xFF);
|
||||
c4 = (s1 & 0xFF) + (s2 & 0xFF) + (s3 & 0xFF) + (s4 & 0xFF);
|
||||
ret[i][j] = ((c1 >> 2) << 24) | ((c2 >> 2) << 16) | ((c3 >> 2) << 8) | (c4 >> 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.texture;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.LogManager;
|
||||
import net.lax1dude.eaglercraft.v1_8.log4j.Logger;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.resources.IResourceManagerReloadListener;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2022-2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class TemperaturesLUT implements IResourceManagerReloadListener {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger("TemperaturesLUT");
|
||||
|
||||
public static final float[][] colorTemperatureLUT = new float[390][3];
|
||||
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager var1) {
|
||||
try {
|
||||
IResource res = var1.getResource(new ResourceLocation("eagler:glsl/deferred/temperatures.lut"));
|
||||
try(InputStream is = res.getInputStream()) {
|
||||
for(int i = 0; i < 390; ++i) {
|
||||
colorTemperatureLUT[i][0] = ((int)is.read() & 0xFF) * 0.0039216f;
|
||||
colorTemperatureLUT[i][0] *= colorTemperatureLUT[i][0];
|
||||
colorTemperatureLUT[i][1] = ((int)is.read() & 0xFF) * 0.0039216f;
|
||||
colorTemperatureLUT[i][1] *= colorTemperatureLUT[i][1];
|
||||
colorTemperatureLUT[i][2] = ((int)is.read() & 0xFF) * 0.0039216f;
|
||||
colorTemperatureLUT[i][2] *= colorTemperatureLUT[i][2];
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error("Failed to load color temperature lookup table!");
|
||||
logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static float[] getColorTemperature(int kelvin) {
|
||||
if (kelvin < 1000) kelvin = 1000;
|
||||
if (kelvin > 39000) kelvin = 39000;
|
||||
int k = ((kelvin - 100) / 100);
|
||||
return colorTemperatureLUT[k];
|
||||
}
|
||||
|
||||
public static void getColorTemperature(int kelvin, float[] ret) {
|
||||
if (kelvin < 1000) kelvin = 1000;
|
||||
if (kelvin > 39000) kelvin = 39000;
|
||||
int k = ((kelvin - 100) / 100);
|
||||
ret[0] = colorTemperatureLUT[k][0];
|
||||
ret[1] = colorTemperatureLUT[k][1];
|
||||
ret[2] = colorTemperatureLUT[k][2];
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.texture;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IFramebufferGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.GlStateManager;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.MathHelper;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class TextureClockPBRImpl extends EaglerTextureAtlasSpritePBR {
|
||||
private double smoothParam1;
|
||||
private double smoothParam2;
|
||||
|
||||
public TextureClockPBRImpl(String spriteName) {
|
||||
super(spriteName);
|
||||
}
|
||||
|
||||
public void updateAnimationPBR(IFramebufferGL[] copyColorFramebuffer, IFramebufferGL[] copyMaterialFramebuffer, int materialTexOffset) {
|
||||
if (!this.frameTextureDataPBR[0].isEmpty()) {
|
||||
Minecraft minecraft = Minecraft.getMinecraft();
|
||||
double d0 = 0.0;
|
||||
if (minecraft.theWorld != null && minecraft.thePlayer != null) {
|
||||
d0 = (double) minecraft.theWorld.getCelestialAngle(1.0f);
|
||||
if (!minecraft.theWorld.provider.isSurfaceWorld()) {
|
||||
d0 = Math.random();
|
||||
}
|
||||
}
|
||||
|
||||
double d1;
|
||||
for (d1 = d0 - this.smoothParam1; d1 < -0.5; ++d1) {
|
||||
;
|
||||
}
|
||||
|
||||
while (d1 >= 0.5) {
|
||||
--d1;
|
||||
}
|
||||
|
||||
d1 = MathHelper.clamp_double(d1, -1.0, 1.0);
|
||||
this.smoothParam2 += d1 * 0.1;
|
||||
this.smoothParam2 *= 0.8;
|
||||
this.smoothParam1 += this.smoothParam2;
|
||||
|
||||
int i, frameCount = this.frameTextureDataPBR[0].size();
|
||||
for (i = (int) ((this.smoothParam1 + 1.0) * frameCount) % frameCount; i < 0; i = (i + frameCount) % frameCount) {
|
||||
;
|
||||
}
|
||||
|
||||
if (i != this.frameCounter) {
|
||||
this.frameCounter = i;
|
||||
animationCachePBR[0].copyFrameLevelsToTex2D(this.frameCounter, this.originX, this.originY, this.width,
|
||||
this.height, copyColorFramebuffer);
|
||||
if (!dontAnimateNormals)
|
||||
animationCachePBR[1].copyFrameLevelsToTex2D(this.frameCounter, this.originX, this.originY,
|
||||
this.width, this.height, copyMaterialFramebuffer);
|
||||
if (!dontAnimateMaterial)
|
||||
animationCachePBR[2].copyFrameLevelsToTex2D(this.frameCounter, this.originX,
|
||||
this.originY + materialTexOffset, this.width, this.height, copyMaterialFramebuffer);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
package net.lax1dude.eaglercraft.v1_8.opengl.ext.deferred.texture;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.internal.IFramebufferGL;
|
||||
import net.lax1dude.eaglercraft.v1_8.opengl.GlStateManager;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2023 LAX1DUDE. All Rights Reserved.
|
||||
*
|
||||
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
|
||||
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
|
||||
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
|
||||
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
|
||||
*
|
||||
* NOT FOR COMMERCIAL OR MALICIOUS USE
|
||||
*
|
||||
* (please read the 'LICENSE' file this repo's root directory for more info)
|
||||
*
|
||||
*/
|
||||
public class TextureCompassPBRImpl extends EaglerTextureAtlasSpritePBR {
|
||||
public double currentAngle;
|
||||
public double angleDelta;
|
||||
|
||||
public TextureCompassPBRImpl(String spriteName) {
|
||||
super(spriteName);
|
||||
}
|
||||
|
||||
public void updateAnimationPBR(IFramebufferGL[] copyColorFramebuffer, IFramebufferGL[] copyMaterialFramebuffer, int materialOffset) {
|
||||
Minecraft minecraft = Minecraft.getMinecraft();
|
||||
if (minecraft.theWorld != null && minecraft.thePlayer != null) {
|
||||
this.updateCompassPBR(minecraft.theWorld, minecraft.thePlayer.posX, minecraft.thePlayer.posZ,
|
||||
(double) minecraft.thePlayer.rotationYaw, false, copyColorFramebuffer, copyMaterialFramebuffer, materialOffset);
|
||||
} else {
|
||||
this.updateCompassPBR((World) null, 0.0, 0.0, 0.0, true, copyColorFramebuffer, copyMaterialFramebuffer, materialOffset);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateCompassPBR(World worldIn, double playerX, double playerY, double playerZ, boolean noWorld,
|
||||
IFramebufferGL[] copyColorFramebuffer, IFramebufferGL[] copyMaterialFramebuffer, int materialOffset) {
|
||||
if (!this.frameTextureDataPBR[0].isEmpty()) {
|
||||
double d0 = 0.0;
|
||||
if (worldIn != null && !noWorld) {
|
||||
BlockPos blockpos = worldIn.getSpawnPoint();
|
||||
double d1 = (double) blockpos.getX() - playerX;
|
||||
double d2 = (double) blockpos.getZ() - playerY;
|
||||
playerZ = playerZ % 360.0;
|
||||
d0 = -((playerZ - 90.0) * Math.PI / 180.0 - Math.atan2(d2, d1));
|
||||
if (!worldIn.provider.isSurfaceWorld()) {
|
||||
d0 = Math.random() * Math.PI * 2.0;
|
||||
}
|
||||
}
|
||||
|
||||
double d3;
|
||||
for (d3 = d0 - this.currentAngle; d3 < -Math.PI; d3 += Math.PI * 2.0) {
|
||||
;
|
||||
}
|
||||
|
||||
while (d3 >= Math.PI) {
|
||||
d3 -= Math.PI * 2.0;
|
||||
}
|
||||
|
||||
d3 = MathHelper.clamp_double(d3, -1.0, 1.0);
|
||||
this.angleDelta += d3 * 0.1;
|
||||
this.angleDelta *= 0.8;
|
||||
this.currentAngle += this.angleDelta;
|
||||
|
||||
int i, frameCount = this.frameTextureDataPBR[0].size();
|
||||
for (i = (int) ((this.currentAngle / Math.PI * 0.5 + 1.0) * frameCount)
|
||||
% frameCount; i < 0; i = (i + frameCount) % frameCount) {
|
||||
;
|
||||
}
|
||||
|
||||
if (i != this.frameCounter) {
|
||||
this.frameCounter = i;
|
||||
animationCachePBR[0].copyFrameLevelsToTex2D(this.frameCounter, this.originX, this.originY, this.width,
|
||||
this.height, copyColorFramebuffer);
|
||||
if (!dontAnimateNormals)
|
||||
animationCachePBR[1].copyFrameLevelsToTex2D(this.frameCounter, this.originX, this.originY,
|
||||
this.width, this.height, copyMaterialFramebuffer);
|
||||
if (!dontAnimateMaterial)
|
||||
animationCachePBR[2].copyFrameLevelsToTex2D(this.frameCounter, this.originX,
|
||||
this.originY + materialOffset, this.width, this.height, copyMaterialFramebuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user