Skip to content

Instantly share code, notes, and snippets.

@Hadyn
Created March 22, 2016 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hadyn/025c4dce5783321e4469 to your computer and use it in GitHub Desktop.
Save Hadyn/025c4dce5783321e4469 to your computer and use it in GitHub Desktop.
/* Class348_Sub5_Sub1 - Decompiled by JODE
* Visit http://jode.sourceforge.net/
*/
import jaggl.OpenGL;
import java.io.*;
final class GlBloom extends GlPostProcess {
static int anInt8823;
static int anInt8827;
static int anInt8828;
static int anInt8829;
static int anInt8831;
static Class21 aClass21_8832 = new Class21();
static int anInt8834;
static int anInt8839;
static int anInt8840;
static int anInt8843;
private Program gaussianBlurShader;
private Program textProgramSq;
private FrameBuffer frameBuffer;
private int bitWidth;
private GlTexture2d colorBuffer1;
private int length;
private GlTexture2d colorBuffer0;
private Program combineProgram;
private GlTexture2d[] downSamples;
private int bitLength;
private int width;
private Program testProgramRt;
private FrameBuffer downsampleFrameBuffer;
GlBloom(OpenGlRenderer renderer) {
super(renderer);
}
public static void method2765(int i) {
aClass21_8832 = null;
if (i != 2048) {
method2765(52);
}
}
static final String method2766(boolean bool, Throwable throwable) throws IOException {
anInt8823++;
String string;
if (throwable instanceof RuntimeException_Sub1) {
RuntimeException_Sub1 runtimeexception_sub1 = (RuntimeException_Sub1) throwable;
string = (runtimeexception_sub1.aString4594 + " | ");
throwable = (runtimeexception_sub1.aThrowable4595);
} else {
string = "";
}
StringWriter stringwriter = new StringWriter();
PrintWriter printwriter = new PrintWriter(stringwriter);
throwable.printStackTrace(printwriter);
printwriter.close();
String string_8_ = stringwriter.toString();
BufferedReader bufferedreader = new BufferedReader(new StringReader(string_8_));
if (bool != false) {
method2765(-61);
}
String string_9_ = bufferedreader.readLine();
for (; ; ) {
String string_10_ = bufferedreader.readLine();
if (string_10_ == null) {
break;
}
int i = string_10_.indexOf('(');
int i_11_ = string_10_.indexOf(')', 1 + i);
String string_12_;
if (i == -1) {
string_12_ = string_10_;
} else {
string_12_ = string_10_.substring(0, i);
}
string_12_ = string_12_.trim();
string_12_ = string_12_.substring(1 + string_12_.lastIndexOf(' '));
string_12_ = string_12_.substring(1 + string_12_.lastIndexOf('\t'));
string += string_12_;
if ((i ^ 0xffffffff) != 0 && i_11_ != -1) {
int i_13_ = string_10_.indexOf(".java:", i);
if (i_13_ >= 0) {
string += string_10_.substring(i_13_ - -5, i_11_);
}
}
string += ' ';
}
string += "| " + string_9_;
return string;
}
final void reset(int i_0_) {
anInt8831++;
OpenGL.glUseProgramObjectARB(0L);
this.renderer.setActiveTexture(1);
this.renderer.bindTexture(null);
this.renderer.setActiveTexture(0);
}
final void handle(GlTexture2d sceneTexture, GlTexture2d depthTexture, int pass) {
try {
anInt8828++;
// GL_VIEWPORT_BIT
OpenGL.glPushAttrib(2048);
// Setup the projection matrix.
OpenGL.glMatrixMode(5889);
OpenGL.glPushMatrix();
OpenGL.glLoadIdentity();
OpenGL.glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
// Step One: Extract the bright colors over a specified threshold.
// Downsample the texture to 256x256 if we need to.
if (downSamples != null) {
renderer.pushFrameBuffer(downsampleFrameBuffer);
int hbw = Class348_Sub40_Sub1.getHighestBit(width);
int hbl = Class348_Sub40_Sub1.getHighestBit(length);
int step = 0;
while (hbw > 256 || hbl > 256) {
OpenGL.glViewport(0, 0, hbw, hbl);
downsampleFrameBuffer.attach(downSamples[step], 0, 0);
if (step == 0) {
this.renderer.bindTexture(sceneTexture);
OpenGL.glBegin(7);
OpenGL.glTexCoord2f(0.0F, 0.0F);
OpenGL.glVertex2i(0, 0);
OpenGL.glTexCoord2f((float) width, 0.0F);
OpenGL.glVertex2i(1, 0);
OpenGL.glTexCoord2f((float) width, (float) length);
OpenGL.glVertex2i(1, 1);
OpenGL.glTexCoord2f(0.0F, (float) length);
OpenGL.glVertex2i(0, 1);
OpenGL.glEnd();
} else {
this.renderer.bindTexture(downSamples[step - 1]);
OpenGL.glBegin(7);
OpenGL.glTexCoord2f(0.0F, 0.0F);
OpenGL.glVertex2i(0, 0);
OpenGL.glTexCoord2f(1.0F, 0.0F);
OpenGL.glVertex2i(1, 0);
OpenGL.glTexCoord2f(1.0F, 1.0F);
OpenGL.glVertex2i(1, 1);
OpenGL.glTexCoord2f(0.0F, 1.0F);
OpenGL.glVertex2i(0, 1);
OpenGL.glEnd();
}
if (hbl > 256) {
hbl >>= 1;
}
if (hbw > 256) {
hbw >>= 1;
}
step++;
}
this.renderer.popFrameBuffer(downsampleFrameBuffer);
this.renderer.bindTexture(downSamples[step - 1]);
this.renderer.pushFrameBuffer(frameBuffer);
frameBuffer.setDrawTarget(0);
OpenGL.glViewport(0, 0, 256, 256);
long programId = textProgramSq.id;
OpenGL.glUseProgramObjectARB(programId);
OpenGL.glUniform1iARB(OpenGL.glGetUniformLocationARB(programId, "sceneTex"), 0);
OpenGL.glUniform3fARB(OpenGL.glGetUniformLocationARB(programId, "params"),
Class75_Sub1.thresholdBrightness, 0.0F, 0.0F);
OpenGL.glBegin(7);
OpenGL.glTexCoord2f(0.0F, 0.0F);
OpenGL.glVertex2i(0, 0);
OpenGL.glTexCoord2f(1.0F, 0.0F);
OpenGL.glVertex2i(1, 0);
OpenGL.glTexCoord2f(1.0F, 1.0F);
OpenGL.glVertex2i(1, 1);
OpenGL.glTexCoord2f(0.0F, 1.0F);
OpenGL.glVertex2i(0, 1);
OpenGL.glEnd();
} else {
// Draw to texture 0, sample scene texture, test brightness threshold.
this.renderer.bindTexture(sceneTexture);
this.renderer.pushFrameBuffer(frameBuffer);
frameBuffer.setDrawTarget(0);
OpenGL.glViewport(0, 0, 256, 256);
long programId = testProgramRt.id;
OpenGL.glUseProgramObjectARB(programId);
OpenGL.glUniform1iARB(OpenGL.glGetUniformLocationARB(programId, "sceneTex"), 0);
OpenGL.glUniform3fARB(OpenGL.glGetUniformLocationARB(programId, "params"),
Class75_Sub1.thresholdBrightness, 0.0F, 0.0F);
OpenGL.glBegin(7);
OpenGL.glTexCoord2f(0.0F, 0.0F);
OpenGL.glVertex2i(0, 0);
OpenGL.glTexCoord2f((float) width, 0.0F);
OpenGL.glVertex2i(1, 0);
OpenGL.glTexCoord2f((float) width, (float) length);
OpenGL.glVertex2i(1, 1);
OpenGL.glTexCoord2f(0.0F, (float) length);
OpenGL.glVertex2i(0, 1);
OpenGL.glEnd();
}
// Step 2: Blur the bright objects in the scene.
// Draw to texture 1, sample texture 0, blur horizontal pass.
frameBuffer.setDrawTarget(1);
renderer.bindTexture(colorBuffer0);
long blurProgramId = gaussianBlurShader.id;
OpenGL.glUseProgramObjectARB(blurProgramId);
OpenGL.glUniform1iARB(OpenGL.glGetUniformLocationARB(blurProgramId, "baseTex"), 0);
OpenGL.glUniform3fARB(OpenGL.glGetUniformLocationARB(blurProgramId, "step"), 0.00390625F, 0.0F, 0.0F);
OpenGL.glBegin(7);
OpenGL.glTexCoord2f(0.0F, 0.0F);
OpenGL.glVertex2i(0, 0);
OpenGL.glTexCoord2f(1.0F, 0.0F);
OpenGL.glVertex2i(1, 0);
OpenGL.glTexCoord2f(1.0F, 1.0F);
OpenGL.glVertex2i(1, 1);
OpenGL.glTexCoord2f(0.0F, 1.0F);
OpenGL.glVertex2i(0, 1);
OpenGL.glEnd();
// Draw to texture 0, sample texture 1, blur vertical pass.
frameBuffer.setDrawTarget(0);
renderer.bindTexture(this.colorBuffer1);
OpenGL.glUniform3fARB(OpenGL.glGetUniformLocationARB(blurProgramId, "step"), 0.0F, 0.00390625F, 0.0F);
OpenGL.glBegin(7);
OpenGL.glTexCoord2f(0.0F, 0.0F);
OpenGL.glVertex2i(0, 0);
OpenGL.glTexCoord2f(1.0F, 0.0F);
OpenGL.glVertex2i(1, 0);
OpenGL.glTexCoord2f(1.0F, 1.0F);
OpenGL.glVertex2i(1, 1);
OpenGL.glTexCoord2f(0.0F, 1.0F);
OpenGL.glVertex2i(0, 1);
OpenGL.glEnd();
OpenGL.glPopAttrib();
OpenGL.glPopMatrix();
// Reset matrix mode.
OpenGL.glMatrixMode(5888);
renderer.popFrameBuffer(frameBuffer);
// Step 3: Combine the blur and the scene texture.
long combineProgramId = combineProgram.id;
OpenGL.glUseProgramObjectARB(combineProgramId);
OpenGL.glUniform1iARB(OpenGL.glGetUniformLocationARB(combineProgramId, "sceneTex"), 0);
OpenGL.glUniform1iARB(OpenGL.glGetUniformLocationARB(combineProgramId, "bloomTex"), 1);
OpenGL.glUniform3fARB(OpenGL.glGetUniformLocationARB(combineProgramId, "params"),
Class348_Sub40_Sub13.bloomIntensity, Class239_Sub26.sourceIntensity, 0.0F);
this.renderer.setActiveTexture(1);
this.renderer.bindTexture(colorBuffer0);
this.renderer.setActiveTexture(0);
this.renderer.bindTexture(sceneTexture);
} catch (RuntimeException runtimeexception) {
throw Class348_Sub17.method2929(runtimeexception,
("rda.H(" + (depthTexture != null ? "{...}" : "null") + ',' + (sceneTexture != null ?
"{...}" :
"null") + ',' + pass + ')'));
}
}
@Override
final void setDimensions(int width, int length) {
this.length = length;
anInt8843++;
this.width = width;
int hbWidth = Class348_Sub40_Sub1.getHighestBit(this.width);
int hbLength = Class348_Sub40_Sub1.getHighestBit(this.length);
if ((hbWidth ^ 0xffffffff) != (bitWidth ^ 0xffffffff) || bitLength != hbLength) {
if (downSamples != null) {
for (int i_18_ = 0; ((downSamples.length ^ 0xffffffff) < (i_18_ ^ 0xffffffff)); i_18_++) {
downSamples[i_18_].method1952(-19948);
}
downSamples = null;
}
if (hbWidth > 256 || hbLength > 256) {
int i_19_ = hbWidth;
int i_20_ = hbLength;
int step = 0;
while (i_19_ > 256 || (i_20_ ^ 0xffffffff) < -257) {
if (i_20_ > 256) {
i_20_ >>= 1;
}
if (i_19_ > 256) {
i_19_ >>= 1;
}
step++;
}
if (downsampleFrameBuffer == null) {
downsampleFrameBuffer = new FrameBuffer(this.renderer);
}
i_19_ = hbWidth;
downSamples = new GlTexture2d[step];
i_20_ = hbLength;
step = 0;
while (i_19_ > 256 || i_20_ > 256) {
downSamples[step++] = new GlTexture2d(this.renderer, 3553, 34842, i_19_, i_20_);
if ((i_20_ ^ 0xffffffff) < -257) {
i_20_ >>= 1;
}
if ((i_19_ ^ 0xffffffff) < -257) {
i_19_ >>= 1;
}
}
} else {
downsampleFrameBuffer = null;
}
bitWidth = hbWidth;
bitLength = hbLength;
}
}
@Override
final void destroy() {
gaussianBlurShader = null;
colorBuffer0 = null;
downsampleFrameBuffer = null;
frameBuffer = null;
testProgramRt = null;
anInt8839++;
downSamples = null;
textProgramSq = null;
combineProgram = null;
colorBuffer1 = null;
}
final boolean isInitialized() {
anInt8829++;
return frameBuffer != null;
}
final boolean isSupported() {
anInt8840++;
return this.renderer.frameBufferSupport
&& this.renderer.fragmentShaderSupport
&& this.renderer.textureFloatSupport;
}
final int getColorFormat() {
anInt8827++;
return 1;
}
@Override public final boolean initialize() {
anInt8834++;
if (renderer.frameBufferSupport
&& renderer.fragmentShaderSupport
&& renderer.textureFloatSupport) {
frameBuffer = new FrameBuffer(this.renderer);
colorBuffer0 = new GlTexture2d(this.renderer, 3553, 34842, 256, 256);
colorBuffer0.configure(false, false);
colorBuffer1 = new GlTexture2d(this.renderer, 3553, 34842, 256, 256);
colorBuffer1.configure(false, false);
renderer.pushFrameBuffer(frameBuffer);
frameBuffer.attach(colorBuffer0, 0, 0);
frameBuffer.attach(colorBuffer1, 1, 0);
frameBuffer.setDrawTarget(0);
if (!frameBuffer.isComplete()) {
renderer.popFrameBuffer(frameBuffer);
return false;
}
renderer.popFrameBuffer(frameBuffer);
testProgramRt = (Class318_Sub1_Sub5_Sub2.createProgram(this.renderer, (new Shader[] {
Class348_Sub42_Sub15.createShader(35632, this.renderer,
"#extension GL_ARB_texture_rectangle : enable\n" + "uniform vec3 params;\n"
+ "uniform sampler2DRect sceneTex;\n"
+ "const vec3 lumCoef = vec3(0.2126, 0.7152, 0.0722);\n" + "void main() {\n"
+ " vec4 col = texture2DRect(sceneTex, gl_TexCoord[0].xy);\n"
+ " gl_FragColor = col*step(params.x, dot(lumCoef, col.rgb));\n" + "}\n")})));
textProgramSq = (Class318_Sub1_Sub5_Sub2.createProgram(this.renderer, (new Shader[] {
Class348_Sub42_Sub15.createShader(35632, this.renderer,
"uniform vec3 params;\n" + "uniform sampler2D sceneTex;\n"
+ "const vec3 lumCoef = vec3(0.2126, 0.7152, 0.0722);\n" + "void main() {\n"
+ " vec4 col = texture2D(sceneTex, gl_TexCoord[0].xy);\n"
+ " gl_FragColor = col*step(params.x, dot(lumCoef, col.rgb));\n" + "}\n")})));
combineProgram = (Class318_Sub1_Sub5_Sub2.createProgram(this.renderer, (new Shader[] {
Class348_Sub42_Sub15.createShader(35632, this.renderer,
"#extension GL_ARB_texture_rectangle : enable\n" + "uniform vec3 params;\n"
+ "uniform vec3 dimScale;\n" + "uniform sampler2D bloomTex;\n"
+ "uniform sampler2DRect sceneTex;\n"
+ "const vec3 lumCoef = vec3(0.2126, 0.7152, 0.0722);\n" + "void main() {\n"
+ "\t vec4 bloomCol = texture2D(bloomTex, gl_TexCoord[1].xy);\n"
+ "\t vec4 sceneCol = texture2DRect(sceneTex, gl_TexCoord[0].xy);\n"
+ "\t float preLum = 0.99*dot(lumCoef, sceneCol.rgb)+0.01;\n"
+ "\t float postLum = preLum*(1.0+(preLum/params.y))/(preLum+1.0);\n"
+ "\t gl_FragColor = sceneCol*(postLum/preLum)+bloomCol*params.x;\n" + "}\n")})));
gaussianBlurShader = (Class318_Sub1_Sub5_Sub2.createProgram(this.renderer, (new Shader[] {
Class348_Sub42_Sub15.createShader(35632, this.renderer,
"uniform vec3 step;\n" + "uniform sampler2D baseTex;\n" + "void main() {\n"
+ "\tvec4 fragCol = texture2D(baseTex, gl_TexCoord[0].xy)*0.091396265;\n"
+ "\tfragCol += texture2D(baseTex, gl_TexCoord[0].xy+(-1.0*step.xy))*0.088584304;\n"
+ "\tfragCol += texture2D(baseTex, gl_TexCoord[0].xy+( 1.0*step.xy))*0.088584304;\n"
+ "\tfragCol += texture2D(baseTex, gl_TexCoord[0].xy+(-2.0*step.xy))*0.08065692;\n"
+ "\tfragCol += texture2D(baseTex, gl_TexCoord[0].xy+( 2.0*step.xy))*0.08065692;\n"
+ "\tfragCol += texture2D(baseTex, gl_TexCoord[0].xy+(-3.0*step.xy))*0.068989515;\n"
+ "\tfragCol += texture2D(baseTex, gl_TexCoord[0].xy+( 3.0*step.xy))*0.068989515;\n"
+ "\tfragCol += texture2D(baseTex, gl_TexCoord[0].xy+(-4.0*step.xy))*0.055434637;\n"
+ "\tfragCol += texture2D(baseTex, gl_TexCoord[0].xy+( 4.0*step.xy))*0.055434637;\n"
+ "\tfragCol += texture2D(baseTex, gl_TexCoord[0].xy+(-5.0*step.xy))*0.04184426;\n"
+ "\tfragCol += texture2D(baseTex, gl_TexCoord[0].xy+( 5.0*step.xy))*0.04184426;\n"
+ "\tfragCol += texture2D(baseTex, gl_TexCoord[0].xy+(-6.0*step.xy))*0.029672023;\n"
+ "\tfragCol += texture2D(baseTex, gl_TexCoord[0].xy+( 6.0*step.xy))*0.029672023;\n"
+ "\tfragCol += texture2D(baseTex, gl_TexCoord[0].xy+(-7.0*step.xy))*0.019765828;\n"
+ "\tfragCol += texture2D(baseTex, gl_TexCoord[0].xy+( 7.0*step.xy))*0.019765828;\n"
+ "\tfragCol += texture2D(baseTex, gl_TexCoord[0].xy+(-8.0*step.xy))*0.012369139;\n"
+ "\tfragCol += texture2D(baseTex, gl_TexCoord[0].xy+( 8.0*step.xy))*0.012369139;\n"
+ "\tgl_FragColor = fragCol;\n" + "}\n")})));
return !(textProgramSq == null || testProgramRt == null || combineProgram == null
|| gaussianBlurShader == null);
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment