本文整理汇总了Java中com.badlogic.gdx.graphics.glutils.ShaderProgram类的典型用法代码示例。如果您正苦于以下问题:Java ShaderProgram类的具体用法?Java ShaderProgram怎么用?Java ShaderProgram使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ShaderProgram类属于com.badlogic.gdx.graphics.glutils包,在下文中一共展示了ShaderProgram类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCommand
import com.badlogic.gdx.graphics.glutils.ShaderProgram; //导入依赖的package包/类
@Override
public void onCommand(PolygonSpriteBatch batch) {
if(_shaderProgram == null) {
ShaderProgram p = GLProgramCache.getInstance().getSpriteBatchDefaultProgram();
if(batch.getShader() != p) {
batch.setShader(null);
}
} else {
if(batch.getShader() != _shaderProgram) {
batch.setShader(_shaderProgram);
}
}
if(_sprite.getTexture() != null) {
_sprite.draw(batch);
}
}
示例2: setupRendering
import com.badlogic.gdx.graphics.glutils.ShaderProgram; //导入依赖的package包/类
private void setupRendering() {
ShaderProgram.pedantic = false;
gameCamera = new OrthographicCamera();
gameCamera.setToOrtho(false, BUFFER_WIDTH, BUFFER_HEIGHT);
gameCamera.translate(EDITOR_OFFSET, 0);
gameCamera.update();
starCamera = new OrthographicCamera();
starCamera.setToOrtho(false, BUFFER_WIDTH, BUFFER_HEIGHT);
starCamera.translate(STAR_EDITOR_OFFSET, 0);
starCamera.update();
screenCamera = new OrthographicCamera();
screenCamera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
screenCamera.update();
batch = new SpriteBatch();
pixelBuffer = new PixelBuffer();
}
示例3: loadShader
import com.badlogic.gdx.graphics.glutils.ShaderProgram; //导入依赖的package包/类
@Override
public ShaderProgram loadShader(String vsFilePath)
{
if(!Game.isSupportOpenGL20)
return null;
String fsProcess = vsFilePath.substring(0, vsFilePath.length()-7);
fsProcess += "fs.glsl";
ShaderProgram shader = new ShaderProgram(Gdx.files.internal(vsFilePath),
Gdx.files.internal(fsProcess));
if(shader.isCompiled())
return shader;
else
throw new GdxRuntimeException("Cannot compile the shader");
}
示例4: preRender
import com.badlogic.gdx.graphics.glutils.ShaderProgram; //导入依赖的package包/类
/**
* Call right before starting render stage of Scene 3D
*/
protected void preRender() {
//Create default member for managers if the managers don't have any member.
if(camera.count() == 0)
{
camera.add("default", new FreeCamera(70, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), new Vector3(0, 5, 5), 0,135));
camera.setActiveCamera("default");
}
if(light.count() == 0 && Game.isSupportOpenGL20)
{
light.addBaseLight("default", new DirectionLight(new Vector3(1, 1, 1), new Vector3(1, 1, -1)));
}
if(shader.count() == 0 && Game.isSupportOpenGL20)
{
String vs = loadShaderFile("effect/default-vs.glsl");
String fs = loadShaderFile("effect/default-fs.glsl");
ShaderProgram s = new ShaderProgram(vs , fs);
if(!s.isCompiled())
{
throw new GdxRuntimeException("Cannot compile default shader");
}
shader.add("default", s);
shader.setActiveShader("default");
}
}
示例5: getShaderIf
import com.badlogic.gdx.graphics.glutils.ShaderProgram; //导入依赖的package包/类
private void getShaderIf(int shader, Renderable renderable, boolean fogFlag, boolean aoFlag) {
if (shaders[shader] == null) {
if (shader == 0) {
shaders[shader] = new CubesShader(renderable);
} else {
ArrayList<Feature> f = new ArrayList<Feature>();
if (fogFlag)
f.add(new FogFeature());
if (aoFlag)
f.add(new AmbientOcclusionFeature());
shaders[shader] = new FeatureShader(renderable, f);
}
ShaderProgram program = shaders[shader].program;
if (!program.isCompiled()) {
Log.error("Failed to compile shader");
Log.error("Shader log: \n" + program.getLog());
Log.error("Fragment shader source: \n" + program.getFragmentShaderSource());
Log.error("Vertex shader source: \n" + program.getVertexShaderSource());
throw new CubesException("Failed to compile shader");
}
shaders[shader].init();
}
}
示例6: CompliantBatch
import com.badlogic.gdx.graphics.glutils.ShaderProgram; //导入依赖的package包/类
/** Constructs a CompliantQuadBatch with a specified capacity and optional default shader.
* @param maxVertices The number of vertices this FlexBatch can batch at once. Maximum of 32767.
* @param generateDefaultShader Whether a default shader should be created. The default shader is owned by the
* CompliantQuadBatch, so it is disposed when the CompliantQuadBatch is disposed. If an alternate shader has been
* applied with {@link #setShader(ShaderProgram)}, the default can be used again by setting the shader to null.
* @param supportPolygons Whether Poly2Ds are supported for drawing. The FlexBatch will not be optimized for
* FixedSizeBatchables. */
public CompliantBatch (Class<T> batchableType, int maxVertices, boolean generateDefaultShader, boolean supportPolygons) {
super(batchableType, maxVertices, supportPolygons ? maxVertices * 2 : 0);
try {
tmp = batchableType.newInstance();
} catch (Exception e) {
throw new IllegalArgumentException("Batchable classes must be public and have an empty constructor.", e);
}
if (generateDefaultShader) {
defaultShader = new ShaderProgram(BatchablePreparation.generateGenericVertexShader(1),
BatchablePreparation.generateGenericFragmentShader(1));
if (defaultShader.isCompiled() == false)
throw new IllegalArgumentException("Error compiling shader: " + defaultShader.getLog());
setShader(defaultShader);
} else {
defaultShader = null;
}
}
示例7: createShader
import com.badlogic.gdx.graphics.glutils.ShaderProgram; //导入依赖的package包/类
public void createShader(){
String vertexShaderSrc = "attribute vec4 a_position; \n" +
"void main() \n" +
"{ \n" +
" gl_Position = a_position; \n" +
"} \n";
String fragmentShaderSrc = "#ifdef GL_ES\n" +
"precision mediump float;\n" +
"#endif\n" +
"uniform vec4 u_color; \n" +
"void main() \n" +
"{ \n" +
" gl_FragColor = u_color;\n" +
"} \n";
shader=new ShaderProgram(vertexShaderSrc,fragmentShaderSrc);
u_color = shader.getUniformLocation("u_color");
}
示例8: RenderSystem
import com.badlogic.gdx.graphics.glutils.ShaderProgram; //导入依赖的package包/类
public RenderSystem(DecalBatch decalBatch, AssetManager assetManager, float worldDegree, Assets.LevelAssets assets) {
super(Aspect.all(RenderComponent.class, PositionComponent.class));
this.levelAssets = assets;
decalMap = new ObjectMap<>();
uiMap = new ObjectMap<>();
this.decalBatch = decalBatch;
this.assetManager = assetManager;
buffers = new ObjectMap<>();
this.spriteBatch = new SpriteBatch();
this.font = assets.uifont;
font.setColor(Color.BLACK);
this.uiCamera = new OrthographicCamera();
Viewport viewportUi = new FitViewport(levelAssets.health_bar_gradient.getWidth(), levelAssets.health_bar_gradient.getHeight(), uiCamera);
viewportUi.update(viewportUi.getScreenWidth(), viewportUi.getScreenHeight(), true);
stateTime = 0;
this.worldDegree = worldDegree;
gradientShader = new ShaderProgram(Shaders.GradientShader.vertexShader, Shaders.GradientShader.fragmentShader);
if (gradientShader.isCompiled() == false)
throw new IllegalArgumentException("couldn't compile shader: " + gradientShader.getLog());
shaderBatch = new SpriteBatch(10, gradientShader);
}
示例9: GameState
import com.badlogic.gdx.graphics.glutils.ShaderProgram; //导入依赖的package包/类
public GameState(String name, String tmx, StateManager manager) {
this.tmx = tmx;
setManager(manager);
if(name!=null)
this.name = name;
else
this.name = "";
sprites = new ObjectMap<String, Sprite>();
animations = new ObjectMap<String, Animation<String>>();
fonts = new ObjectMap<String, BitmapFont>(); //TODO: test load to avoid repeats
particle_effects = new ObjectMap<String, ParticleEffectPool>();
pvalues = new Array<String>();
time_scale = 1f;
shaders = new ObjectMap<String, ShaderProgram>();
svalues = new Array<String>();
}
示例10: loadShaders
import com.badlogic.gdx.graphics.glutils.ShaderProgram; //导入依赖的package包/类
private void loadShaders(TiledMap data) {
MapObjects objects = data.getLayers().get("preload").getObjects();
String scheck = "Shader";
for (MapObject o : objects) {
String name = o.getName();
MapProperties properties = o.getProperties();
String type = properties.get("type", String.class);
if (type != null && type.equals(scheck)) {
String file = properties.get("shader_name", String.class);
if (file != null) {
game.loadShader(file);
game.getAssetManager().finishLoading();
if (!shaders.containsKey(name)) {
ShaderProgram sp = game.getShader(file);
shaders.put(name, sp);
svalues.add(KyperBoxGame.SHADER_FOLDER + KyperBoxGame.FILE_SEPARATOR + file);
}
}
}
}
}
示例11: init
import com.badlogic.gdx.graphics.glutils.ShaderProgram; //导入依赖的package包/类
/** Adds GLES specifics (if needed) and compiles shaders.
*
* @param key - shader identifier
* @param vert - vertex shader source
* @param frag - fragment shader source
* @return whether the shaders compiled correctly */
protected boolean init (String key, String vert, String frag) {
if (frag == null || vert == null)
return false;
frag = appendGLESPrecisions(frag);
vert = appendGLESPrecisions(vert);
sourcesVert.put(key, vert);
sourcesFrag.put(key, frag);
ShaderProgram sp = new ShaderProgram(vert, frag);
if (!sp.isCompiled()) {
Gdx.app.log("ShaderManager", "Error while loading shader '" + key + "':\n" + sp.getLog());
Gdx.app.log("ShaderManager", "--------------------------------");
Gdx.app.log("ShaderManager", "Vertex shader source: \n" + vert);
Gdx.app.log("ShaderManager", "--------------------------------");
Gdx.app.log("ShaderManager", "Fragment shader source: \n" + frag);
Gdx.app.log("ShaderManager", "--------------------------------");
return false;
}
shaders.put(key, sp);
Gdx.app.log("ShaderManager", "Shader '" + key + "' loaded");
return true;
}
示例12: initShader
import com.badlogic.gdx.graphics.glutils.ShaderProgram; //导入依赖的package包/类
private ShaderProgram initShader(Texture colorMapTex, Texture maskMapTex, Texture normalMapTex, TransVec dim,
float amIntensity, float dirIntensity, float shadIntensity, float sprtSize, float lum, float thresh, ShaderProgram shader) {
shader.begin();
{
maskMapTex.bind(2);
normalMapTex.bind(1);
colorMapTex.bind(0);
super.batcher.setShader(shader);
shader.setUniformi(maskMap, 2);
shader.setUniformi(normalMap, 1);
shader.setUniformi(colorMap, 0);
shader.setUniformf(fieldSize, dim.x, dim.y);
shader.setUniformf(ambientIntensity, amIntensity);
shader.setUniformf(directIntensity, dirIntensity);
shader.setUniformf(shadowIntensity, shadIntensity);
shader.setUniformf(spriteSize, sprtSize);
shader.setUniformf(height, lum);
shader.setUniformf(threshold, thresh);
}
shader.end();
return shader;
}
示例13: renderBRDF
import com.badlogic.gdx.graphics.glutils.ShaderProgram; //导入依赖的package包/类
private Texture renderBRDF() {
ShaderProgram brdfShader = new ShaderProgram(
Gdx.files.internal("shaders/brdf_shader.vert"),
Gdx.files.internal("shaders/brdf_shader.frag"));
FrameBuffer frameBuffer = FrameBuffer.createFrameBuffer(Pixmap.Format.RGB888, (int) brdfWidth, (int) brdfHeight, true);
brdfShader.begin();
frameBuffer.begin();
Gdx.gl.glViewport(0, 0, (int) brdfWidth, (int) brdfHeight);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
quadMesh.render(brdfShader, GL20.GL_TRIANGLES);
frameBuffer.end();
brdfShader.end();
brdfShader.dispose();
return frameBuffer.getColorBufferTexture();
}
示例14: create
import com.badlogic.gdx.graphics.glutils.ShaderProgram; //导入依赖的package包/类
@Override
public void create() {
super.create();
geometryPass = new ShaderProgram(
Gdx.files.internal("shaders/g_buffer.vert"),
Gdx.files.internal("shaders/g_buffer.frag"));
lightingPass = new ShaderProgram(
Gdx.files.internal("shaders/deferred_shader.vert"),
Gdx.files.internal("shaders/deferred_shader.frag"));
ModelBuilder mb = new ModelBuilder();
Model cube = mb.createBox(1, 1, 1, new Material(),
VertexAttributes.Usage.Position |
VertexAttributes.Usage.Normal |
VertexAttributes.Usage.TextureCoordinates);
cubeMesh = cube.meshes.first();
}
示例15: init
import com.badlogic.gdx.graphics.glutils.ShaderProgram; //导入依赖的package包/类
@Override
public void init() {
loadReflection("rnl_phong_m00");
String vert = Gdx.files.internal("Shaders/VS_ShaderPlain.vsh").readString();
String frag = Gdx.files.internal("Shaders/ShaderPlain.fsh").readString();
program = new ShaderProgram(vert, frag);
if (!program.isCompiled()){
throw new GdxRuntimeException(program.getLog());
}
u_worldTrans = program.getUniformLocation("u_worldTrans");
u_projTrans = program.getUniformLocation("u_projTrans");
vLight0 = program.getUniformLocation("vLight0");
albedo = program.getUniformLocation("albedo");
metallic = program.getUniformLocation("metallic");
sCubemapTexture = program.getUniformLocation("sCubemapTexture");
vRoughness = program.getUniformLocation("vRoughness");
ambientOcclusion = program.getUniformLocation("ambientOcclusion");
}