| 1 | package net.minecraft.client.shader;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import java.io.IOException;
|
| 5 | import java.util.List;
|
| 6 | import net.minecraft.client.Minecraft;
|
| 7 | import net.minecraft.client.renderer.GlStateManager;
|
| 8 | import net.minecraft.client.renderer.Tessellator;
|
| 9 | import net.minecraft.client.renderer.WorldRenderer;
|
| 10 | import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
| 11 | import net.minecraft.client.resources.IResourceManager;
|
| 12 | import net.minecraft.client.util.JsonException;
|
| 13 | import org.lwjgl.util.vector.Matrix4f;
|
| 14 |
|
| 15 | public class Shader
|
| 16 | {
|
| 17 | private final ShaderManager manager;
|
| 18 | public final Framebuffer framebufferIn;
|
| 19 | public final Framebuffer framebufferOut;
|
| 20 | private final List<Object> listAuxFramebuffers = Lists.<Object>newArrayList();
|
| 21 | private final List<String> listAuxNames = Lists.<String>newArrayList();
|
| 22 | private final List<Integer> listAuxWidths = Lists.<Integer>newArrayList();
|
| 23 | private final List<Integer> listAuxHeights = Lists.<Integer>newArrayList();
|
| 24 | private Matrix4f projectionMatrix;
|
| 25 |
|
| 26 | public Shader(IResourceManager p_i45089_1_, String p_i45089_2_, Framebuffer p_i45089_3_, Framebuffer p_i45089_4_) throws JsonException, IOException
|
| 27 | {
|
| 28 | this.manager = new ShaderManager(p_i45089_1_, p_i45089_2_);
|
| 29 | this.framebufferIn = p_i45089_3_;
|
| 30 | this.framebufferOut = p_i45089_4_;
|
| 31 | }
|
| 32 |
|
| 33 | public void deleteShader()
|
| 34 | {
|
| 35 | this.manager.deleteShader();
|
| 36 | }
|
| 37 |
|
| 38 | public void addAuxFramebuffer(String p_148041_1_, Object p_148041_2_, int p_148041_3_, int p_148041_4_)
|
| 39 | {
|
| 40 | this.listAuxNames.add(this.listAuxNames.size(), p_148041_1_);
|
| 41 | this.listAuxFramebuffers.add(this.listAuxFramebuffers.size(), p_148041_2_);
|
| 42 | this.listAuxWidths.add(this.listAuxWidths.size(), Integer.valueOf(p_148041_3_));
|
| 43 | this.listAuxHeights.add(this.listAuxHeights.size(), Integer.valueOf(p_148041_4_));
|
| 44 | }
|
| 45 |
|
| 46 | private void preLoadShader()
|
| 47 | {
|
| 48 | GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
| 49 | GlStateManager.disableBlend();
|
| 50 | GlStateManager.disableDepth();
|
| 51 | GlStateManager.disableAlpha();
|
| 52 | GlStateManager.disableFog();
|
| 53 | GlStateManager.disableLighting();
|
| 54 | GlStateManager.disableColorMaterial();
|
| 55 | GlStateManager.enableTexture2D();
|
| 56 | GlStateManager.bindTexture(0);
|
| 57 | }
|
| 58 |
|
| 59 | public void setProjectionMatrix(Matrix4f p_148045_1_)
|
| 60 | {
|
| 61 | this.projectionMatrix = p_148045_1_;
|
| 62 | }
|
| 63 |
|
| 64 | public void loadShader(float p_148042_1_)
|
| 65 | {
|
| 66 | this.preLoadShader();
|
| 67 | this.framebufferIn.unbindFramebuffer();
|
| 68 | float f = (float)this.framebufferOut.framebufferTextureWidth;
|
| 69 | float f1 = (float)this.framebufferOut.framebufferTextureHeight;
|
| 70 | GlStateManager.viewport(0, 0, (int)f, (int)f1);
|
| 71 | this.manager.addSamplerTexture("DiffuseSampler", this.framebufferIn);
|
| 72 |
|
| 73 | for (int i = 0; i < this.listAuxFramebuffers.size(); ++i)
|
| 74 | {
|
| 75 | this.manager.addSamplerTexture((String)this.listAuxNames.get(i), this.listAuxFramebuffers.get(i));
|
| 76 | this.manager.getShaderUniformOrDefault("AuxSize" + i).set((float)((Integer)this.listAuxWidths.get(i)).intValue(), (float)((Integer)this.listAuxHeights.get(i)).intValue());
|
| 77 | }
|
| 78 |
|
| 79 | this.manager.getShaderUniformOrDefault("ProjMat").set(this.projectionMatrix);
|
| 80 | this.manager.getShaderUniformOrDefault("InSize").set((float)this.framebufferIn.framebufferTextureWidth, (float)this.framebufferIn.framebufferTextureHeight);
|
| 81 | this.manager.getShaderUniformOrDefault("OutSize").set(f, f1);
|
| 82 | this.manager.getShaderUniformOrDefault("Time").set(p_148042_1_);
|
| 83 | Minecraft minecraft = Minecraft.getMinecraft();
|
| 84 | this.manager.getShaderUniformOrDefault("ScreenSize").set((float)minecraft.displayWidth, (float)minecraft.displayHeight);
|
| 85 | this.manager.useShader();
|
| 86 | this.framebufferOut.framebufferClear();
|
| 87 | this.framebufferOut.bindFramebuffer(false);
|
| 88 | GlStateManager.depthMask(false);
|
| 89 | GlStateManager.colorMask(true, true, true, true);
|
| 90 | Tessellator tessellator = Tessellator.getInstance();
|
| 91 | WorldRenderer worldrenderer = tessellator.getWorldRenderer();
|
| 92 | worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
|
| 93 | worldrenderer.pos(0.0D, (double)f1, 500.0D).color(255, 255, 255, 255).endVertex();
|
| 94 | worldrenderer.pos((double)f, (double)f1, 500.0D).color(255, 255, 255, 255).endVertex();
|
| 95 | worldrenderer.pos((double)f, 0.0D, 500.0D).color(255, 255, 255, 255).endVertex();
|
| 96 | worldrenderer.pos(0.0D, 0.0D, 500.0D).color(255, 255, 255, 255).endVertex();
|
| 97 | tessellator.draw();
|
| 98 | GlStateManager.depthMask(true);
|
| 99 | GlStateManager.colorMask(true, true, true, true);
|
| 100 | this.manager.endShader();
|
| 101 | this.framebufferOut.unbindFramebuffer();
|
| 102 | this.framebufferIn.unbindFramebufferTexture();
|
| 103 |
|
| 104 | for (Object object : this.listAuxFramebuffers)
|
| 105 | {
|
| 106 | if (object instanceof Framebuffer)
|
| 107 | {
|
| 108 | ((Framebuffer)object).unbindFramebufferTexture();
|
| 109 | }
|
| 110 | }
|
| 111 | }
|
| 112 |
|
| 113 | public ShaderManager getShaderManager()
|
| 114 | {
|
| 115 | return this.manager;
|
| 116 | }
|
| 117 | }
|
| 118 |
|