diff --git a/SPD-classes/src/main/java/com/watabou/noosa/Game.java b/SPD-classes/src/main/java/com/watabou/noosa/Game.java index 7b923de5a..0a634a7a2 100644 --- a/SPD-classes/src/main/java/com/watabou/noosa/Game.java +++ b/SPD-classes/src/main/java/com/watabou/noosa/Game.java @@ -216,6 +216,7 @@ public class Game extends Activity implements GLSurfaceView.Renderer, View.OnTou step(); NoosaScript.get().resetCamera(); + NoosaScriptNoLighting.get().resetCamera(); GLES20.glScissor( 0, 0, width, height ); GLES20.glClear( GLES20.GL_COLOR_BUFFER_BIT ); draw(); diff --git a/SPD-classes/src/main/java/com/watabou/noosa/Image.java b/SPD-classes/src/main/java/com/watabou/noosa/Image.java index 31e010491..040323a03 100644 --- a/SPD-classes/src/main/java/com/watabou/noosa/Image.java +++ b/SPD-classes/src/main/java/com/watabou/noosa/Image.java @@ -164,7 +164,7 @@ public class Image extends Visual { dirty = false; } - NoosaScript script = NoosaScript.get(); + NoosaScript script = script(); texture.bind(); @@ -179,6 +179,10 @@ public class Image extends Visual { } + protected NoosaScript script(){ + return NoosaScript.get(); + } + @Override public void destroy() { super.destroy(); diff --git a/SPD-classes/src/main/java/com/watabou/noosa/NoosaScript.java b/SPD-classes/src/main/java/com/watabou/noosa/NoosaScript.java index 48a812744..033a387d2 100644 --- a/SPD-classes/src/main/java/com/watabou/noosa/NoosaScript.java +++ b/SPD-classes/src/main/java/com/watabou/noosa/NoosaScript.java @@ -47,8 +47,7 @@ public class NoosaScript extends Script { private Camera lastCamera; public NoosaScript() { - - super(); + compile( shader() ); uCamera = uniform( "uCamera" ); diff --git a/SPD-classes/src/main/java/com/watabou/noosa/NoosaScriptNoLighting.java b/SPD-classes/src/main/java/com/watabou/noosa/NoosaScriptNoLighting.java new file mode 100644 index 000000000..1eb169704 --- /dev/null +++ b/SPD-classes/src/main/java/com/watabou/noosa/NoosaScriptNoLighting.java @@ -0,0 +1,80 @@ +/* + * Pixel Dungeon + * Copyright (C) 2012-2015 Oleg Dolya + * + * Shattered Pixel Dungeon + * Copyright (C) 2014-2016 Evan Debenham + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + */ + +package com.watabou.noosa; + +import com.watabou.glscripts.Script; + +//This class should be used on heavy pixel-fill based loads when lighting is not needed. +// It skips the lighting component of the fragment shader, giving a significant performance boost + +//Remember that switching programs is expensive +// if this script is to be used many times try to block them together +public class NoosaScriptNoLighting extends NoosaScript { + + public NoosaScriptNoLighting() { + + compile( shader() ); + + //we can use the same components as regular noosascript + NoosaScript n = NoosaScript.get(); + uCamera = n.uCamera; + uModel = n.uModel; + uTex = n.uTex; + aXY = n.aXY; + aUV = n.aUV; + + } + + @Override + public void lighting(float rm, float gm, float bm, float am, float ra, float ga, float ba, float aa) { + //Does nothing + } + + public static NoosaScriptNoLighting get(){ + return Script.use( NoosaScriptNoLighting.class ); + } + + @Override + protected String shader() { + return SHADER; + } + + private static final String SHADER = + + "uniform mat4 uCamera;" + + "uniform mat4 uModel;" + + "attribute vec4 aXYZW;" + + "attribute vec2 aUV;" + + "varying vec2 vUV;" + + "void main() {" + + " gl_Position = uCamera * uModel * aXYZW;" + + " vUV = aUV;" + + "}" + + + "//\n" + + + "varying mediump vec2 vUV;" + + "uniform lowp sampler2D uTex;" + + "void main() {" + + " gl_FragColor = texture2D( uTex, vUV );" + + "}"; +} diff --git a/SPD-classes/src/main/java/com/watabou/noosa/Tilemap.java b/SPD-classes/src/main/java/com/watabou/noosa/Tilemap.java index ce318fded..c77389f77 100644 --- a/SPD-classes/src/main/java/com/watabou/noosa/Tilemap.java +++ b/SPD-classes/src/main/java/com/watabou/noosa/Tilemap.java @@ -254,14 +254,11 @@ public class Tilemap extends Visual { || camH + camH < 0) return; - NoosaScript script = NoosaScript.get(); + NoosaScript script = NoosaScriptNoLighting.get(); texture.bind(); script.uModel.valueM4( matrix ); - script.lighting( - rm, gm, bm, am, - ra, ga, ba, aa ); script.camera( camera ); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/FogOfWar.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/FogOfWar.java index 95e6e7dde..4364979c9 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/FogOfWar.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/FogOfWar.java @@ -26,6 +26,8 @@ import com.watabou.gltextures.SmartTexture; import com.watabou.gltextures.TextureCache; import com.watabou.glwrap.Texture; import com.watabou.noosa.Image; +import com.watabou.noosa.NoosaScript; +import com.watabou.noosa.NoosaScriptNoLighting; import com.watabou.utils.Rect; import java.nio.ByteBuffer; @@ -202,6 +204,11 @@ public class FogOfWar extends Image { } } + @Override + protected NoosaScript script() { + return NoosaScriptNoLighting.get(); + } + @Override public void draw() { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java index 19881b105..644b709b9 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java @@ -89,6 +89,8 @@ import com.shatteredpixel.shatteredpixeldungeon.windows.WndTradeItem; import com.watabou.noosa.Camera; import com.watabou.noosa.Game; import com.watabou.noosa.Group; +import com.watabou.noosa.NoosaScript; +import com.watabou.noosa.NoosaScriptNoLighting; import com.watabou.noosa.SkinnedBlock; import com.watabou.noosa.Visual; import com.watabou.noosa.audio.Music; @@ -160,15 +162,20 @@ public class GameScene extends PixelScene { water = new SkinnedBlock( Dungeon.level.width() * DungeonTilemap.SIZE, Dungeon.level.height() * DungeonTilemap.SIZE, - Dungeon.level.waterTex() ); + Dungeon.level.waterTex() ){ + @Override + protected NoosaScript script() { + return NoosaScriptNoLighting.get(); + } + }; terrain.add( water ); - ripples = new Group(); - terrain.add( ripples ); - tiles = new DungeonTilemap(); terrain.add( tiles ); + ripples = new Group(); + terrain.add( ripples ); + customTiles = new Group(); terrain.add(customTiles); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Archs.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Archs.java index cb84116b1..ea9d600b1 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Archs.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/Archs.java @@ -22,6 +22,8 @@ package com.shatteredpixel.shatteredpixeldungeon.ui; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.watabou.noosa.Game; +import com.watabou.noosa.NoosaScript; +import com.watabou.noosa.NoosaScriptNoLighting; import com.watabou.noosa.SkinnedBlock; import com.watabou.noosa.ui.Component; @@ -39,12 +41,22 @@ public class Archs extends Component { @Override protected void createChildren() { - arcsBg = new SkinnedBlock( 1, 1, Assets.ARCS_BG ); + arcsBg = new SkinnedBlock( 1, 1, Assets.ARCS_BG ){ + @Override + protected NoosaScript script() { + return NoosaScriptNoLighting.get(); + } + }; arcsBg.autoAdjust = true; arcsBg.offsetTo( 0, offsB ); add( arcsBg ); - arcsFg = new SkinnedBlock( 1, 1, Assets.ARCS_FG ); + arcsFg = new SkinnedBlock( 1, 1, Assets.ARCS_FG ){ + @Override + protected NoosaScript script() { + return NoosaScriptNoLighting.get(); + } + }; arcsFg.autoAdjust = true; arcsFg.offsetTo( 0, offsF ); add( arcsFg );