v0.4.2: Implemented no-lighting shader
Gives a very big performance boost on older devices
This commit is contained in:
@@ -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 );" +
|
||||
"}";
|
||||
}
|
||||
Reference in New Issue
Block a user