當前位置: 首頁>>代碼示例>>Java>>正文


Java ShaderProgram類代碼示例

本文整理匯總了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);
   	}
}
 
開發者ID:mingwuyun,項目名稱:cocos2d-java,代碼行數:17,代碼來源:Sprite.java

示例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();
}
 
開發者ID:ZKasica,項目名稱:Planet-Generator,代碼行數:21,代碼來源:Scene.java

示例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");
}
 
開發者ID:game-libgdx-unity,項目名稱:GDX-Engine,代碼行數:17,代碼來源:DefaultGameAsset.java

示例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");
    }
}
 
開發者ID:game-libgdx-unity,項目名稱:GDX-Engine,代碼行數:28,代碼來源:BaseGameScene3D.java

示例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();
    }
}
 
開發者ID:RedTroop,項目名稱:Cubes_2,代碼行數:26,代碼來源:WorldShaderProvider.java

示例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;
    }
}
 
開發者ID:CypherCove,項目名稱:gdx-cclibs,代碼行數:25,代碼來源:CompliantBatch.java

示例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");
}
 
開發者ID:CypherCove,項目名稱:gdx-cclibs,代碼行數:20,代碼來源:FullScreenFader.java

示例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);
}
 
開發者ID:EtherWorks,項目名稱:arcadelegends-gg,代碼行數:26,代碼來源:RenderSystem.java

示例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>();
}
 
開發者ID:kyperbelt,項目名稱:KyperBox,代碼行數:17,代碼來源:GameState.java

示例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);
                }
            }
        }
    }
}
 
開發者ID:kyperbelt,項目名稱:KyperBox,代碼行數:22,代碼來源:GameState.java

示例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;
}
 
開發者ID:Quexten,項目名稱:RavTech,代碼行數:28,代碼來源:ShaderManager.java

示例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;
}
 
開發者ID:henryco,項目名稱:Escapy,代碼行數:25,代碼來源:EscapyVolumeRenderer.java

示例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();
}
 
開發者ID:MovementSpeed,項目名稱:nhglib,代碼行數:19,代碼來源:LightProbe.java

示例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();
}
 
開發者ID:MovementSpeed,項目名稱:nhglib,代碼行數:20,代碼來源:MainDef.java

示例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");
}
 
開發者ID:PWorlds,項目名稱:LibGDX-PBR,代碼行數:20,代碼來源:PBRShader.java


注:本文中的com.badlogic.gdx.graphics.glutils.ShaderProgram類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。