Search in sources :

Example 1 with MaterialData

use of org.terasology.engine.rendering.assets.material.MaterialData in project Terasology by MovingBlocks.

the class ShaderManagerLwjgl method addShaderProgram.

public GLSLMaterial addShaderProgram(String title, String providingModule) {
    String uri = providingModule + ":" + title;
    Optional<? extends Shader> shader = Assets.getShader(uri);
    checkState(shader.isPresent(), "Failed to resolve %s", uri);
    shader.get().recompile();
    GLSLMaterial material = (GLSLMaterial) Assets.generateAsset(new ResourceUrn(providingModule + ":prog." + title), new MaterialData(shader.get()), Material.class);
    progamaticShaders.add(material);
    return material;
}
Also used : GLSLMaterial(org.terasology.engine.rendering.opengl.GLSLMaterial) Material(org.terasology.engine.rendering.assets.material.Material) MaterialData(org.terasology.engine.rendering.assets.material.MaterialData) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) GLSLMaterial(org.terasology.engine.rendering.opengl.GLSLMaterial)

Example 2 with MaterialData

use of org.terasology.engine.rendering.assets.material.MaterialData in project Terasology by MovingBlocks.

the class FontMaterialProducer method getAssetData.

@Override
public Optional<MaterialData> getAssetData(ResourceUrn urn) throws IOException {
    if (RESOURCE_NAME.equals(urn.getResourceName()) && !urn.getFragmentName().isEmpty()) {
        Optional<? extends Shader> fontShader = assetManager.getAsset(FONT_SHADER_URN, Shader.class);
        if (!fontShader.isPresent()) {
            logger.error("Unable to resolve font shader");
            return Optional.empty();
        }
        Optional<Texture> texture = assetManager.getAsset(new ResourceUrn(urn.getModuleName(), urn.getFragmentName()), Texture.class);
        if (texture.isPresent()) {
            MaterialData materialData = new MaterialData(fontShader.get());
            materialData.setParam("tex", texture.get());
            return Optional.of(materialData);
        }
    }
    return Optional.empty();
}
Also used : MaterialData(org.terasology.engine.rendering.assets.material.MaterialData) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Texture(org.terasology.engine.rendering.assets.texture.Texture)

Example 3 with MaterialData

use of org.terasology.engine.rendering.assets.material.MaterialData in project Terasology by MovingBlocks.

the class WorldAtlasImpl method buildAtlas.

private void buildAtlas() {
    calculateAtlasSizes();
    int numMipMaps = getNumMipmaps();
    ByteBuffer[] data = createAtlasMipmaps(numMipMaps, TRANSPARENT_COLOR, tiles, "tiles.png");
    ByteBuffer[] dataNormal = createAtlasMipmaps(numMipMaps, UNIT_Z_COLOR, tilesNormal, "tilesNormal.png", tilesGloss);
    ByteBuffer[] dataHeight = createAtlasMipmaps(numMipMaps, MID_RED_COLOR, tilesHeight, "tilesHeight.png");
    TextureData terrainTexData = new TextureData(atlasSize, atlasSize, data, Texture.WrapMode.CLAMP, Texture.FilterMode.NEAREST);
    Texture terrainTex = Assets.generateAsset(new ResourceUrn("engine:terrain"), terrainTexData, Texture.class);
    TextureData terrainNormalData = new TextureData(atlasSize, atlasSize, dataNormal, Texture.WrapMode.CLAMP, Texture.FilterMode.NEAREST);
    Assets.generateAsset(new ResourceUrn("engine:terrainNormal"), terrainNormalData, Texture.class);
    TextureData terrainHeightData = new TextureData(atlasSize, atlasSize, dataHeight, Texture.WrapMode.CLAMP, Texture.FilterMode.LINEAR);
    Assets.generateAsset(new ResourceUrn("engine:terrainHeight"), terrainHeightData, Texture.class);
    MaterialData terrainMatData = new MaterialData(Assets.getShader("engine:block").get());
    terrainMatData.setParam("textureAtlas", terrainTex);
    terrainMatData.setParam("colorOffset", new float[] { 1, 1, 1 });
    terrainMatData.setParam("textured", true);
    Assets.generateAsset(new ResourceUrn("engine:terrain"), terrainMatData, Material.class);
    createTextureAtlas(terrainTex);
}
Also used : TextureData(org.terasology.engine.rendering.assets.texture.TextureData) MaterialData(org.terasology.engine.rendering.assets.material.MaterialData) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) ByteBuffer(java.nio.ByteBuffer) Texture(org.terasology.engine.rendering.assets.texture.Texture)

Aggregations

MaterialData (org.terasology.engine.rendering.assets.material.MaterialData)3 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)3 Texture (org.terasology.engine.rendering.assets.texture.Texture)2 ByteBuffer (java.nio.ByteBuffer)1 Material (org.terasology.engine.rendering.assets.material.Material)1 TextureData (org.terasology.engine.rendering.assets.texture.TextureData)1 GLSLMaterial (org.terasology.engine.rendering.opengl.GLSLMaterial)1