v0.4.2: Implemented no-lighting shader
Gives a very big performance boost on older devices
This commit is contained in:
parent
182b24d9ae
commit
6ed1ec2214
|
@ -216,6 +216,7 @@ public class Game extends Activity implements GLSurfaceView.Renderer, View.OnTou
|
||||||
step();
|
step();
|
||||||
|
|
||||||
NoosaScript.get().resetCamera();
|
NoosaScript.get().resetCamera();
|
||||||
|
NoosaScriptNoLighting.get().resetCamera();
|
||||||
GLES20.glScissor( 0, 0, width, height );
|
GLES20.glScissor( 0, 0, width, height );
|
||||||
GLES20.glClear( GLES20.GL_COLOR_BUFFER_BIT );
|
GLES20.glClear( GLES20.GL_COLOR_BUFFER_BIT );
|
||||||
draw();
|
draw();
|
||||||
|
|
|
@ -164,7 +164,7 @@ public class Image extends Visual {
|
||||||
dirty = false;
|
dirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
NoosaScript script = NoosaScript.get();
|
NoosaScript script = script();
|
||||||
|
|
||||||
texture.bind();
|
texture.bind();
|
||||||
|
|
||||||
|
@ -179,6 +179,10 @@ public class Image extends Visual {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected NoosaScript script(){
|
||||||
|
return NoosaScript.get();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
super.destroy();
|
super.destroy();
|
||||||
|
|
|
@ -48,7 +48,6 @@ public class NoosaScript extends Script {
|
||||||
|
|
||||||
public NoosaScript() {
|
public NoosaScript() {
|
||||||
|
|
||||||
super();
|
|
||||||
compile( shader() );
|
compile( shader() );
|
||||||
|
|
||||||
uCamera = uniform( "uCamera" );
|
uCamera = uniform( "uCamera" );
|
||||||
|
|
|
@ -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 <http://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
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 );" +
|
||||||
|
"}";
|
||||||
|
}
|
|
@ -254,14 +254,11 @@ public class Tilemap extends Visual {
|
||||||
|| camH + camH < 0)
|
|| camH + camH < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
NoosaScript script = NoosaScript.get();
|
NoosaScript script = NoosaScriptNoLighting.get();
|
||||||
|
|
||||||
texture.bind();
|
texture.bind();
|
||||||
|
|
||||||
script.uModel.valueM4( matrix );
|
script.uModel.valueM4( matrix );
|
||||||
script.lighting(
|
|
||||||
rm, gm, bm, am,
|
|
||||||
ra, ga, ba, aa );
|
|
||||||
|
|
||||||
script.camera( camera );
|
script.camera( camera );
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,8 @@ import com.watabou.gltextures.SmartTexture;
|
||||||
import com.watabou.gltextures.TextureCache;
|
import com.watabou.gltextures.TextureCache;
|
||||||
import com.watabou.glwrap.Texture;
|
import com.watabou.glwrap.Texture;
|
||||||
import com.watabou.noosa.Image;
|
import com.watabou.noosa.Image;
|
||||||
|
import com.watabou.noosa.NoosaScript;
|
||||||
|
import com.watabou.noosa.NoosaScriptNoLighting;
|
||||||
import com.watabou.utils.Rect;
|
import com.watabou.utils.Rect;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
@ -202,6 +204,11 @@ public class FogOfWar extends Image {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected NoosaScript script() {
|
||||||
|
return NoosaScriptNoLighting.get();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw() {
|
public void draw() {
|
||||||
|
|
||||||
|
|
|
@ -89,6 +89,8 @@ import com.shatteredpixel.shatteredpixeldungeon.windows.WndTradeItem;
|
||||||
import com.watabou.noosa.Camera;
|
import com.watabou.noosa.Camera;
|
||||||
import com.watabou.noosa.Game;
|
import com.watabou.noosa.Game;
|
||||||
import com.watabou.noosa.Group;
|
import com.watabou.noosa.Group;
|
||||||
|
import com.watabou.noosa.NoosaScript;
|
||||||
|
import com.watabou.noosa.NoosaScriptNoLighting;
|
||||||
import com.watabou.noosa.SkinnedBlock;
|
import com.watabou.noosa.SkinnedBlock;
|
||||||
import com.watabou.noosa.Visual;
|
import com.watabou.noosa.Visual;
|
||||||
import com.watabou.noosa.audio.Music;
|
import com.watabou.noosa.audio.Music;
|
||||||
|
@ -160,15 +162,20 @@ public class GameScene extends PixelScene {
|
||||||
water = new SkinnedBlock(
|
water = new SkinnedBlock(
|
||||||
Dungeon.level.width() * DungeonTilemap.SIZE,
|
Dungeon.level.width() * DungeonTilemap.SIZE,
|
||||||
Dungeon.level.height() * DungeonTilemap.SIZE,
|
Dungeon.level.height() * DungeonTilemap.SIZE,
|
||||||
Dungeon.level.waterTex() );
|
Dungeon.level.waterTex() ){
|
||||||
|
@Override
|
||||||
|
protected NoosaScript script() {
|
||||||
|
return NoosaScriptNoLighting.get();
|
||||||
|
}
|
||||||
|
};
|
||||||
terrain.add( water );
|
terrain.add( water );
|
||||||
|
|
||||||
ripples = new Group();
|
|
||||||
terrain.add( ripples );
|
|
||||||
|
|
||||||
tiles = new DungeonTilemap();
|
tiles = new DungeonTilemap();
|
||||||
terrain.add( tiles );
|
terrain.add( tiles );
|
||||||
|
|
||||||
|
ripples = new Group();
|
||||||
|
terrain.add( ripples );
|
||||||
|
|
||||||
customTiles = new Group();
|
customTiles = new Group();
|
||||||
terrain.add(customTiles);
|
terrain.add(customTiles);
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,8 @@ package com.shatteredpixel.shatteredpixeldungeon.ui;
|
||||||
|
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.Assets;
|
import com.shatteredpixel.shatteredpixeldungeon.Assets;
|
||||||
import com.watabou.noosa.Game;
|
import com.watabou.noosa.Game;
|
||||||
|
import com.watabou.noosa.NoosaScript;
|
||||||
|
import com.watabou.noosa.NoosaScriptNoLighting;
|
||||||
import com.watabou.noosa.SkinnedBlock;
|
import com.watabou.noosa.SkinnedBlock;
|
||||||
import com.watabou.noosa.ui.Component;
|
import com.watabou.noosa.ui.Component;
|
||||||
|
|
||||||
|
@ -39,12 +41,22 @@ public class Archs extends Component {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void createChildren() {
|
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.autoAdjust = true;
|
||||||
arcsBg.offsetTo( 0, offsB );
|
arcsBg.offsetTo( 0, offsB );
|
||||||
add( arcsBg );
|
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.autoAdjust = true;
|
||||||
arcsFg.offsetTo( 0, offsF );
|
arcsFg.offsetTo( 0, offsF );
|
||||||
add( arcsFg );
|
add( arcsFg );
|
||||||
|
|
Loading…
Reference in New Issue
Block a user