safety checks on shaders & unified format

This commit is contained in:
MachineMuse 2013-05-16 22:52:45 -06:00
parent 9a520fbe2c
commit 016925f507
11 changed files with 94 additions and 67 deletions

View file

@ -1,8 +1,8 @@
#version 400 #version 150
uniform sampler2D depth; uniform sampler2D depth;
void main() { void main() {
vec2 coords = vec2(gl_TexCoord[0].x, gl_TexCoord[0].y); vec2 coords = vec2(gl_TexCoord[0].x, gl_TexCoord[0].y);
gl_FragDepth = texture2D(depth, coords).r; gl_FragDepth = texture(depth, coords).r;
gl_FragColor = vec4(0.0); gl_FragColor = vec4(0.0);
} }

View file

@ -1,16 +1,16 @@
#version 400 #version 150
uniform sampler2D depth; uniform sampler2D depth;
uniform sampler2D occlusion; uniform sampler2D occlusion;
uniform sampler2D texture; uniform sampler2D texture;
void main() { void main() {
vec2 coords = vec2(gl_TexCoord[0].x, gl_TexCoord[0].y); vec2 coords = vec2(gl_TexCoord[0].x, gl_TexCoord[0].y);
float depth = texture2D(depth, coords).r - 0.001; float depth = texture(depth, coords).r - 0.001;
float occlusion = texture2D(occlusion, coords).r; float occlusion = texture(occlusion, coords).r;
vec4 color = vec4(0.0); vec4 color = vec4(0.0);
float writedepth = occlusion; float writedepth = occlusion;
if(depth <= occlusion) { if(depth <= occlusion) {
color = texture2D(texture, coords); color = texture(texture, coords);
// color = vec4(1.0); // color = vec4(1.0);
writedepth = depth; writedepth = depth;
} }

View file

@ -1,3 +1,5 @@
void main(){ void main(){
gl_Position = gl_ModelViewProjectionMatrix*gl_Vertex; gl_Position = gl_ModelViewProjectionMatrix*gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0; gl_TexCoord[0] = gl_MultiTexCoord0;

View file

@ -1,26 +1,50 @@
#version 400 #version 150
uniform vec2 u_Scale; uniform vec2 u_Scale;
uniform sampler2D u_Texture0; uniform sampler2D u_Texture0;
const float gaussFilter[14] = float[14]( const float gaussFilter[50] = float[50](
-3.0, 0.015625, -12.0, 1.0/16777216.0,
-2.0, 0.09375, -11.0, 24.0/16777216.0,
-1.0, 0.234375, -10.0, 276.0/16777216.0,
0.0, 0.3125, -9.0, 2024.0/16777216.0,
1.0, 0.234375, -8.0, 10626.0/16777216.0,
2.0, 0.09375, -7.0, 42504.0/16777216.0,
3.0, 0.015625 -6.0, 134596.0/16777216.0,
-5.0, 346104.0/16777216.0,
-4.0, 735471.0/16777216.0,
-3.0, 1307504.0/16777216.0,
-2.0, 1961256.0/16777216.0,
-1.0, 2496144.0/16777216.0,
0.0, 2704156.0/16777216.0,
1.0, 2496144.0/16777216.0,
2.0, 1961256.0/16777216.0,
3.0, 1307504.0/16777216.0,
4.0, 735471.0/16777216.0,
5.0, 346104.0/16777216.0,
6.0, 134596.0/16777216.0,
7.0, 42504.0/16777216.0,
8.0, 10626.0/16777216.0,
9.0, 2024.0/16777216.0,
10.0, 276.0/16777216.0,
11.0, 24.0/16777216.0,
12.0, 1.0/16777216.0
); );
void main() { void main() {
vec4 color = vec4(0.0); vec4 color = vec4(0.0);
float k = 0.0;
float wt = 0.0; float wt = 0.0;
for( int i = 0; i < 7; i++ ) for( int i = 0; i < 25; i++ )
{ {
vec4 pix = texture2D( u_Texture0, vec4 pix = texture( u_Texture0,
vec2(gl_TexCoord[0].x+gaussFilter[i*2]*u_Scale.x, gl_TexCoord[0].y+gaussFilter[i*2]*u_Scale.y ) vec2(gl_TexCoord[0].x+gaussFilter[i*2]*u_Scale.x, gl_TexCoord[0].y+gaussFilter[i*2]*u_Scale.y )
); );
color += pix*gaussFilter[i*2+1] * pix.w*1.5; wt = gaussFilter[i*2+1] * pix.w * 1.5;
color += wt * pix;
k += wt;
} }
gl_FragColor = color; gl_FragColor = color;
// if(k > 1) {
// gl_FragColor /= k;
// }
} }

View file

@ -1,3 +1,5 @@
#version 150
void main(){ void main(){
gl_Position = gl_ModelViewProjectionMatrix*gl_Vertex; gl_Position = gl_ModelViewProjectionMatrix*gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0; gl_TexCoord[0] = gl_MultiTexCoord0;

View file

@ -1,3 +1,5 @@
#version 150
varying vec4 vertColor; varying vec4 vertColor;
void main(){ void main(){

View file

@ -1,3 +1,5 @@
#version 150
varying vec4 vertColor; varying vec4 vertColor;
void main(){ void main(){

View file

@ -89,8 +89,11 @@ public class ClientProxy extends CommonProxy {
URL otherResource = ClientProxy.class.getResource(Config.RESOURCE_PREFIX + "models/armor2.xml"); URL otherResource = ClientProxy.class.getResource(Config.RESOURCE_PREFIX + "models/armor2.xml");
ModelSpecXMLReader.parseFile(otherResource); ModelSpecXMLReader.parseFile(otherResource);
if (MuseShaders.hBlurProgram().program() == 0) { try {
MuseLogger.logDebug("Hi"); MuseShaders.hBlurProgram().program();
Config.canUseShaders = true;
} catch (Throwable e) {
MuseLogger.logException("Loading shaders failed!", e);
} }
// DefaultModelSpec.loadDefaultModel(); // DefaultModelSpec.loadDefaultModel();
// ModelSpecXMLWriter.writeRegistry("modelspec.xml"); // ModelSpecXMLWriter.writeRegistry("modelspec.xml");

View file

@ -296,4 +296,14 @@ public class Config {
public static boolean fontAntiAliasing() { public static boolean fontAntiAliasing() {
return config.get("Font", "Font Anti-Aliasing", false).getBoolean(false); return config.get("Font", "Font Anti-Aliasing", false).getBoolean(false);
} }
public static int glowMultiplier() {
return config.get("Graphics", "Bloom Multiplier", 1).getInt(1);
}
public static boolean useShaders() {
return config.get("Graphics", "Use Pixel/Vertex Shaders", true).getBoolean(true);
}
public static boolean canUseShaders = false;
} }

View file

@ -2,6 +2,7 @@ package net.machinemuse.powersuits.event;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import net.machinemuse.powersuits.common.Config;
import net.machinemuse.utils.render.GlowBuffer; import net.machinemuse.utils.render.GlowBuffer;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.gui.ScaledResolution;
@ -16,7 +17,9 @@ public class TextureStitchHandler {
Minecraft mc = Minecraft.getMinecraft(); Minecraft mc = Minecraft.getMinecraft();
ScaledResolution screen = new ScaledResolution(mc.gameSettings, mc.displayWidth, mc.displayHeight); ScaledResolution screen = new ScaledResolution(mc.gameSettings, mc.displayWidth, mc.displayHeight);
GlowBuffer.drawFullScreen(screen); if (Config.useShaders() && Config.canUseShaders) {
GlowBuffer.drawFullScreen(screen);
}
} }
@ForgeSubscribe @ForgeSubscribe

View file

@ -5,6 +5,8 @@ import net.minecraft.client.gui.ScaledResolution
import net.machinemuse.general.geometry.Colour import net.machinemuse.general.geometry.Colour
import org.lwjgl.opengl.GL13._ import org.lwjgl.opengl.GL13._
import net.minecraft.client.Minecraft import net.minecraft.client.Minecraft
import net.machinemuse.utils.render.Render._
import net.machinemuse.powersuits.common.Config
/** /**
* Author: MachineMuse (Claire Semple) * Author: MachineMuse (Claire Semple)
@ -90,13 +92,32 @@ object GlowBuffer {
glActiveTexture(GL_TEXTURE0) glActiveTexture(GL_TEXTURE0)
glDisable(GL_DEPTH_TEST) glDisable(GL_DEPTH_TEST)
// Vertical Pass for(i<- 1 until Config.glowMultiplier) {
doBlurPasses()
}
// To Main display
fromBuffer(secondBuffer) {
Render.pure {
drawTexSquare(texDimension)
}
}.run()
glPopAttrib()
MuseRenderer.blendingOff()
MuseRenderer.glowOff()
popDualIdentityMatrix()
}
def doBlurPasses() {
// Vertical Pass
fromBuffer(secondBuffer) { fromBuffer(secondBuffer) {
toBuffer(glowBuffer) { toBuffer(glowBuffer) {
withShaderProgram(MuseShaders.vBlurProgram) { withShaderProgram(MuseShaders.vBlurProgram) {
Render pure { Render pure {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
MuseShaders.vBlurProgram.setUniform2f("u_Scale", 0, 2.0f / texDimension) MuseShaders.vBlurProgram.setUniform2f("u_Scale", 0, 1.0f / texDimension)
MuseShaders.vBlurProgram.setTexUnit("u_Texture0", 0) MuseShaders.vBlurProgram.setTexUnit("u_Texture0", 0)
drawTexSquare(texDimension) drawTexSquare(texDimension)
} }
@ -111,55 +132,13 @@ object GlowBuffer {
withShaderProgram(MuseShaders.hBlurProgram) { withShaderProgram(MuseShaders.hBlurProgram) {
Render.pure { Render.pure {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
MuseShaders.hBlurProgram.setUniform2f("u_Scale", 2.0f / texDimension, 0) MuseShaders.hBlurProgram.setUniform2f("u_Scale", 1.0f / texDimension, 0)
MuseShaders.hBlurProgram.setTexUnit("u_Texture0", 0) MuseShaders.hBlurProgram.setTexUnit("u_Texture0", 0)
drawTexSquare(texDimension) drawTexSquare(texDimension)
} }
} }
} }
}.run() }.run()
// Vertical Pass
fromBuffer(secondBuffer) {
toBuffer(glowBuffer) {
withShaderProgram(MuseShaders.vBlurProgram) {
Render pure {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
MuseShaders.vBlurProgram.setUniform2f("u_Scale", 0, 2.0f / texDimension)
MuseShaders.vBlurProgram.setTexUnit("u_Texture0", 0)
drawTexSquare(texDimension)
}
}
}
}.run()
// Horizontal Pass
fromBuffer(glowBuffer) {
toBuffer(secondBuffer) {
withShaderProgram(MuseShaders.hBlurProgram) {
Render.pure {
MuseShaders.hBlurProgram.setUniform2f("u_Scale", 2.0f / texDimension, 0)
MuseShaders.hBlurProgram.setTexUnit("u_Texture0", 0)
drawTexSquare(texDimension)
}
}
}
}.run()
// To Main display
fromBuffer(secondBuffer) {
Render.pure {
drawTexSquare(texDimension)
}
}.run()
glPopAttrib()
MuseRenderer.blendingOff()
MuseRenderer.glowOff()
popDualIdentityMatrix()
} }
def drawTexSquare(td: Int) { def drawTexSquare(td: Int) {