Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbudda committed Jul 7, 2016
1 parent d176ede commit 712d488
Show file tree
Hide file tree
Showing 13 changed files with 444 additions and 77 deletions.
250 changes: 190 additions & 60 deletions patches/net/minecraft/client/Minecraft.java.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- a/net/minecraft/client/Minecraft.java
+++ b/net/minecraft/client/Minecraft.java
@@ -1,40 +1,97 @@
@@ -1,40 +1,100 @@
package net.minecraft.client;

-import com.google.common.collect.Iterables;
Expand Down Expand Up @@ -55,6 +55,7 @@
+import org.lwjgl.input.Cursor;
+import org.lwjgl.input.Keyboard;
+import org.lwjgl.input.Mouse;
+import org.lwjgl.opengl.ARBSamplerObjects;
+import org.lwjgl.opengl.ARBShaderObjects;
+import org.lwjgl.opengl.ContextCapabilities;
+import org.lwjgl.opengl.Display;
Expand All @@ -67,6 +68,8 @@
+import org.lwjgl.opengl.OpenGLException;
+import org.lwjgl.opengl.PixelFormat;
+import org.lwjgl.util.glu.GLU;
+import org.lwjgl.util.vector.Matrix4f;
+import org.lwjgl.util.vector.Vector4f;
+
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
Expand Down Expand Up @@ -108,15 +111,24 @@
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiChat;
@@ -97,6 +154,7 @@
@@ -68,6 +128,8 @@
import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldRenderer;
+import net.minecraft.client.renderer.culling.ClippingHelper;
+import net.minecraft.client.renderer.culling.ClippingHelperImpl;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.client.renderer.texture.TextureManager;
@@ -97,6 +159,7 @@
import net.minecraft.client.settings.GameSettings;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.client.shader.Framebuffer;
+import net.minecraft.client.shader.ShaderGroup;
import net.minecraft.client.stream.IStream;
import net.minecraft.client.stream.NullStream;
import net.minecraft.client.stream.TwitchStream;
@@ -127,6 +185,8 @@
@@ -127,6 +190,8 @@
import net.minecraft.profiler.Profiler;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.integrated.IntegratedServer;
Expand All @@ -125,15 +137,15 @@
import net.minecraft.stats.AchievementList;
import net.minecraft.stats.IStatStringFormat;
import net.minecraft.stats.StatFileWriter;
@@ -142,6 +202,7 @@
@@ -142,6 +207,7 @@
import net.minecraft.util.Session;
import net.minecraft.util.Timer;
import net.minecraft.util.Util;
+import net.minecraft.util.Vec3;
import net.minecraft.world.EnumDifficulty;
import net.minecraft.world.WorldProviderEnd;
import net.minecraft.world.WorldProviderHell;
@@ -150,2988 +211,4855 @@
@@ -150,2988 +216,4973 @@
import net.minecraft.world.storage.ISaveFormat;
import net.minecraft.world.storage.ISaveHandler;
import net.minecraft.world.storage.WorldInfo;
Expand Down Expand Up @@ -1900,10 +1912,18 @@
+ public double PredictedDisplayTimeSeconds = 0d;
+ public int _Lanczos_shaderProgramId = -1;
+ public int _LanczosShader_texelWidthOffsetUniform = -1;
+ public int _depthFilter_programId = -1;
+
+ public int _LanczosShader_texelHeightOffsetUniform = -1;
+ public int _LanczosShader_inputImageTextureUniform = -1;
+ public int _DepthMask_shaderProgramId = -1;
+ public int _DepthMask_resolutionUniform = -1;
+ public int _DepthMask_positionUniform = -1;
+ public int _DepthMask_scaleUniform = -1;
+ public int _DepthMask_colorTexUniform = -1;
+ public int _DepthMask_depthTexUniform = -1;
+ public int _DepthMask_zNearUniform = -1;
+ public int _DepthMask_zFarUniform = -1;
+ public int _DepthMask_playerDepthUniform = -1;
+ public int _DepthMask_passUniform = -1;
+ private Framebuffer mirrorFB = null;
+ private Framebuffer fsaaFirstPassResultFBO;
+ private final float OCULUS_RED_COLOUR_COMPONENT = (1f/255f)*61f;
Expand Down Expand Up @@ -5211,12 +5231,7 @@
+ doKeyboardInput(fmlCommonHandler);
+
+ }
+ /** MINECRIFT */
+ else
+ {
+ VRHotkeys.handleKeyboardInputs(this);
+ }
+ /** END MINECRIFT */
+
+
+ if (this.theWorld != null)
+ {
Expand Down Expand Up @@ -5367,6 +5382,15 @@
+ }
+ else
+ {
+
+ /** MINECRIFT */
+
+ {
+ VRHotkeys.handleKeyboardInputs(this);
+ }
+ /** END MINECRIFT */
+
+
+ if (Keyboard.getEventKey() == 1)
+ {
+ this.displayInGameMenu();
Expand All @@ -5392,6 +5416,11 @@
+ {
+ this.renderGlobal.loadRenderers();
+ }
+
+ if (Keyboard.getEventKey() == 38 && Keyboard.isKeyDown(61))
+ {
+ this.reinitFramebuffers = true;
+ }
+
+ if (Keyboard.getEventKey() == 35 && Keyboard.isKeyDown(61))
+ {
Expand Down Expand Up @@ -6727,6 +6756,7 @@
+
+ /** MINECRIFT ADDITIONS BELOW */
+
+ float mixedRealityPlayerDepth;
+
+ private boolean copyToMirror(renderPass currentPass2)
+ {
Expand All @@ -6746,7 +6776,7 @@
+ this.framebufferMc.unbindFramebuffer(); //draw directly to window
+
+
+ Vector3f eye = new Vector3f((float)renderViewEntity.posX,
+ /*Vector3f eye = new Vector3f((float)renderViewEntity.posX,
+ (float)renderViewEntity.posY,
+ (float)renderViewEntity.posZ);
+
Expand All @@ -6762,50 +6792,69 @@
+
+ Vector3f cam_orig = eye.subtract(pos);
+
+ float dist = cam_player.dot(cam_orig);
+ float dist = eye.subtract(pos).length() * 10;
+ //float dist = cam_player.dot(cam_orig);
+ //System.out.println(dist);
+
+ float total = entityRenderer.clipDistance - entityRenderer.minClipDistance;
+
+ float percent = dist / total; //TODO: Depth is prolly non linear.
+ if(percent < 0) percent = 0.5f;
+ if(percent < 0) percent = 0.5f;*/
+
+
+ //percent = 0.5F; //just for testing.
+
+ percent = 0.5F; //just for testing.
+ //Vec3 playerv = entityRenderer.getEyeRenderPos(renderPass.Center);
+ //float depth = getDepthOfPosition(new Vector3f((float)playerv.xCoord, (float)playerv.yCoord, (float)playerv.zCoord));
+
+
+// GL11.glClearDepth(percent);
+// GL11.glClearColor(255, 0, 255, 0);
+// GL11.glEnable(GL11.GL_DEPTH_TEST);
+// GL11.glDepthMask(true);
+// GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
+//
+//
+// for(int i = 0; i < 2; i++) {
+//
+// if(i == 0) {
+// GL11.glDepthFunc(GL11.GL_GREATER);
+// } else {
+// GL11.glDepthFunc(GL11.GL_LESS);
+// }
+// GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, 0);
+// GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, framebuffer.framebufferObject);
+//
+// //dont work GL30.glBlitFramebuffer(0, 0, framebufferMc.framebufferWidth, framebufferMc.framebufferHeight, 0, 0,displayWidth, displayHeight, GL11.GL_COLOR_BUFFER_BIT, GL11.GL_LINEAR);
+//
+//
+// OpenGlHelper.glUseProgram(_depthFilter_programId);
+//
+// ///something something ... .. ... GL20.glUniform1(location, values);
+//
+// framebufferMc.framebufferRender((int)(0 + (displayWidth *i)*0.5f), displayWidth/2, displayHeight,0 );
+//
+// OpenGlHelper.glUseProgram(0);
+// }
+//
+// GL11.glDisable(GL11.GL_DEPTH_TEST);
+// GL11.glDepthMask(true);
+// GL11.glDepthFunc(GL11.GL_LEQUAL);
+// GL11.glClearDepth(1.0D);
+ //GL11.glClearDepth(percent);
+ GL11.glClearColor(0.0F, 0.0F, 0.0F, 1.0F);
+ //GL11.glEnable(GL11.GL_DEPTH_TEST);
+ //GL11.glDepthMask(true);
+ //GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
+
+
+ GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, 0);
+ GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, framebuffer.framebufferObject);
+ GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
+ for(int i = 0; i < 2; i++) {
+
+ /*if(i == 0) {
+ GL11.glDepthFunc(GL11.GL_GREATER);
+ } else {
+ GL11.glDepthFunc(GL11.GL_LESS);
+ }*/
+
+ //dont work GL30.glBlitFramebuffer(0, 0, framebufferMc.framebufferWidth, framebufferMc.framebufferHeight, 0, 0,displayWidth, displayHeight, GL11.GL_COLOR_BUFFER_BIT, GL11.GL_LINEAR);
+
+ OpenGlHelper.glUseProgram(_DepthMask_shaderProgramId);
+
+ ARBShaderObjects.glUniform2fARB(_DepthMask_resolutionUniform, displayWidth / 2, displayHeight / 2);
+ ARBShaderObjects.glUniform2fARB(_DepthMask_positionUniform, (displayWidth / 2) * i, 0);
+ ARBShaderObjects.glUniform1iARB(_DepthMask_colorTexUniform, 1);
+ ARBShaderObjects.glUniform1iARB(_DepthMask_depthTexUniform, 2);
+ ARBShaderObjects.glUniform1fARB(_DepthMask_zNearUniform, entityRenderer.minClipDistance);
+ ARBShaderObjects.glUniform1fARB(_DepthMask_zFarUniform, entityRenderer.clipDistance);
+ ARBShaderObjects.glUniform1fARB(_DepthMask_playerDepthUniform, mixedRealityPlayerDepth); // TODO
+ ARBShaderObjects.glUniform1iARB(_DepthMask_passUniform, i);
+ GL13.glActiveTexture(GL13.GL_TEXTURE1);
+ framebuffer.bindFramebufferTexture();
+ //ARBSamplerObjects.glBindSampler(1, _DepthMask_colorTexUniform);
+ GL13.glActiveTexture(GL13.GL_TEXTURE2);
+ GL11.glBindTexture(GL11.GL_TEXTURE_2D, framebuffer.depthBuffer);
+ //ARBSamplerObjects.glBindSampler(2, _DepthMask_depthTexUniform);
+
+ GL13.glActiveTexture(GL13.GL_TEXTURE0);
+ framebufferMc.framebufferRender((displayWidth / 2) * i, displayWidth / 2, displayHeight / 2, 0);
+
+ OpenGlHelper.glUseProgram(0);
+ }
+
+ //GL11.glDisable(GL11.GL_DEPTH_TEST);
+ //GL11.glDepthMask(true);
+ //GL11.glDepthFunc(GL11.GL_LEQUAL);
+ //GL11.glClearDepth(1.0D);
+
+ return true;
+ } else {
Expand Down Expand Up @@ -6846,6 +6895,37 @@
+
+ return false;
+ }
+
+ /**
+ * Probably somewhat expensive, don't call often
+ */
+ public float getDepthOfPosition(Vector3f pos) {
+ if(true) return 0.5f;
+ Matrix4f projectionMatrix = new Matrix4f();
+ Matrix4f modelViewMatrix = new Matrix4f();
+ FloatBuffer projectionMatrixBuf = GLAllocation.createDirectFloatBuffer(16);
+ FloatBuffer modelViewMatrixBuf = GLAllocation.createDirectFloatBuffer(16);
+ ClippingHelper clip = ClippingHelperImpl.getInstance();
+ for (float f : clip.projectionMatrix) {
+ projectionMatrixBuf.put(f);
+ }
+ for (float f : clip.modelviewMatrix) {
+ modelViewMatrixBuf.put(f);
+ }
+ projectionMatrixBuf.rewind();
+ modelViewMatrixBuf.rewind();
+ projectionMatrix.load(projectionMatrixBuf);
+ modelViewMatrix.load(modelViewMatrixBuf);
+ Matrix4f mvp = Matrix4f.mul(projectionMatrix, modelViewMatrix, null);
+ Vector4f tPos = Matrix4f.transform(mvp, new Vector4f(pos.x, pos.y, pos.z, 1), null);
+ float total = entityRenderer.clipDistance - entityRenderer.minClipDistance;
+ float len = tPos.length() - entityRenderer.minClipDistance;
+ return len / total;
+ }
+
+ public void updatePlayerDepth() {
+ mixedRealityPlayerDepth = getDepthOfPosition(null);
+ }
+
+ private int tex0, tex1;
+
Expand Down Expand Up @@ -7066,7 +7146,54 @@
+ this.guiFramebuffer.setFramebufferColor(RED_COLOUR_COMPONENT, GREEN_COLOUR_COMPONENT, BLUE_COLOUR_COMPONENT, 0.0F);
+ checkGLError("post color");
+
+ _depthFilter_programId = ShaderHelper.initShaders(VERTEX_PASSTHRU_SHADER, DEPTH_FILTER_SHADER, true);
+ String DEPTH_MASK_VERTEX_SHADER =
+ "#version 110\n" +
+ //"layout(location = 0) in vec4 in_position;\n" +
+ "void main() {\n" +
+ "gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" +
+ "}\n" ;
+
+ String DEPTH_MASK_FRAGMENT_SHADER =
+ "#version 330\n" +
+ "uniform vec2 resolution;\n"+
+ "uniform vec2 position;\n"+
+ "uniform sampler2D colorTex;\n"+
+ "uniform sampler2D depthTex;\n"+
+ "uniform float zNear;\n"+
+ "uniform float zFar;\n"+
+ "uniform float playerDepth;\n"+
+ "uniform int pass;\n"+
+ "out vec4 out_Color;\n"+
+ "void main (void) {\n" +
+ "vec2 pos = (gl_FragCoord.xy - position.xy) / resolution.xy;\n" +
+ "float rawDepth = texture(depthTex, pos).x;\n"+
+ "float depth = (2 * zNear) / (zFar + zNear - rawDepth * (zFar - zNear));\n"+
+ "if ((pass == 0 && playerDepth >= depth) || (pass == 1 && playerDepth <= depth)) {\n"+
+ "vec4 color = texture(colorTex, pos);\n"+
+ "if (color.x == 0 && color.y == 0 && color.z == 0) {\n"+
+ "color = vec4(0.005, 0.005, 0.005, 1);\n"+ // Prevent absolute black so people can color key and not have it look weird sometimes
+ "}\n"+
+ "out_Color = color;\n" +
+ //"out_Color = vec4(vec3(depth), 1);\n"+ // Draw depth buffer
+ "} else {\n"+
+ "discard;\n"+
+ "}\n"+
+ "}\n"
+ ;
+ _DepthMask_shaderProgramId = ShaderHelper.initShaders(DEPTH_MASK_VERTEX_SHADER, DEPTH_MASK_FRAGMENT_SHADER, true);
+ if (_DepthMask_shaderProgramId == 0) {
+ //throw new Exception("Failed to validate depth mask shader!");
+ }
+
+ // Setup uniform IDs
+ _DepthMask_resolutionUniform = ARBShaderObjects.glGetUniformLocationARB(_DepthMask_shaderProgramId, "resolution");
+ _DepthMask_positionUniform = ARBShaderObjects.glGetUniformLocationARB(_DepthMask_shaderProgramId, "position");
+ _DepthMask_colorTexUniform = ARBShaderObjects.glGetUniformLocationARB(_DepthMask_shaderProgramId, "colorTex");
+ _DepthMask_depthTexUniform = ARBShaderObjects.glGetUniformLocationARB(_DepthMask_shaderProgramId, "depthTex");
+ _DepthMask_zNearUniform = ARBShaderObjects.glGetUniformLocationARB(_DepthMask_shaderProgramId, "zNear");
+ _DepthMask_zFarUniform = ARBShaderObjects.glGetUniformLocationARB(_DepthMask_shaderProgramId, "zFar");
+ _DepthMask_playerDepthUniform = ARBShaderObjects.glGetUniformLocationARB(_DepthMask_shaderProgramId, "playerDepth");
+ _DepthMask_passUniform = ARBShaderObjects.glGetUniformLocationARB(_DepthMask_shaderProgramId, "pass");
+
+ checkGLError("post select");
+ entityRenderer.setupClipPlanes();
Expand Down Expand Up @@ -7791,23 +7918,26 @@
+ }
+ }
+
+ public final String VERTEX_PASSTHRU_SHADER =
+ "#version 330\n" +
+ "layout(location = 0) in vec4 in_position;\n" +
+ /*public final String DEPTH_MASK_VERTEX_SHADER =
+ "#version 110\n" +
+ //"layout(location = 0) in vec4 in_position;\n" +
+ "void main()\n" +
+ "{\n" +
+ "gl_Position = in_position;\n" +
+ "gl_Position = gl_Vertex * gl_ModelViewProjectionMatrix;\n" +
+ "}\n" ;
+
+ public final String DEPTH_FILTER_SHADER =
+ public final String DEPTH_MASK_FRAGMENT_SHADER =
+ "#version 330\n" +
+ "uniform vec4 uColor;\n"+
+ "uniform vec2 resolution;\n"+
+ "uniform sampler2D colorTex;\n"+
+ "uniform sampler2D depthTex;\n"+
+ "out vec4 out_Color;\n"+
+ "void main (void) \n" +
+ "{\n" +
+ "if(gl_FragDepth" +
+ "gl_FragColor = uColor;\n " +
+ "vec2 pos = gl_FragCoord.xy / resolution.xy;\n" +
+ "out_Color = texture(colorTex, pos);\n" +
+ "}\n"
+ ;
+ ;*/
+
+ public final String LANCZOS_SAMPLER_VERTEX_SHADER =
+ "#version 120\n" +
Expand Down
Loading

0 comments on commit 712d488

Please sign in to comment.