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;
}
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();
}
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);
}
Aggregations