Search in sources :

Example 6 with Material

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

the class ShaderManagerLwjgl method recompileAllShaders.

@Override
public void recompileAllShaders() {
    AssetManager assetManager = CoreRegistry.get(AssetManager.class);
    assetManager.getLoadedAssets(Shader.class).forEach(Shader::recompile);
    assetManager.getLoadedAssets(Material.class).forEach(Material::recompile);
    activeMaterial = null;
}
Also used : AssetManager(org.terasology.assets.management.AssetManager) Material(org.terasology.rendering.assets.material.Material) GLSLMaterial(org.terasology.rendering.opengl.GLSLMaterial) Shader(org.terasology.rendering.assets.shader.Shader)

Example 7 with Material

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

the class ShaderManagerLwjgl method addShaderProgram.

// TODO: discuss having a `public removeShaderProgram`, to dispose shader programs no longer in use by any node
public GLSLMaterial addShaderProgram(String title) {
    String uri = "engine:" + 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("engine:prog." + title), new MaterialData(shader.get()), Material.class);
    progamaticShaders.add(material);
    return material;
}
Also used : Material(org.terasology.rendering.assets.material.Material) GLSLMaterial(org.terasology.rendering.opengl.GLSLMaterial) MaterialData(org.terasology.rendering.assets.material.MaterialData) ResourceUrn(org.terasology.assets.ResourceUrn) GLSLMaterial(org.terasology.rendering.opengl.GLSLMaterial)

Example 8 with Material

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

the class Skysphere method render.

@Override
public void render(Camera camera) {
    glDepthMask(false);
    if (camera.isReflected()) {
        glCullFace(GL_BACK);
    } else {
        glCullFace(GL_FRONT);
    }
    Material shader = Assets.getMaterial("engine:prog.sky").get();
    shader.enable();
    // Draw the skysphere
    drawSkysphere(camera.getzFar());
    if (camera.isReflected()) {
        glCullFace(GL_FRONT);
    } else {
        glCullFace(GL_BACK);
    }
    glDepthMask(true);
}
Also used : Material(org.terasology.rendering.assets.material.Material)

Example 9 with Material

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

the class SpriteParticleRenderer method renderAlphaBlend.

@Override
public void renderAlphaBlend() {
    Material material = Assets.getMaterial(PARTICLE_MATERIAL_URI).get();
    material.enable();
    Vector3f camPos = worldRenderer.getActiveCamera().getPosition();
    particleSystemManager.getParticleEmittersByDataComponent(ParticleDataSpriteComponent.class).forEach(p -> drawParticles(material, p, camPos));
}
Also used : ParticleDataSpriteComponent(org.terasology.particles.components.ParticleDataSpriteComponent) Vector3f(org.terasology.math.geom.Vector3f) Material(org.terasology.rendering.assets.material.Material)

Example 10 with Material

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

the class Block method renderWithLightValue.

public void renderWithLightValue(float sunlight, float blockLight) {
    if (meshGenerator == null) {
        return;
    }
    Material mat = Assets.getMaterial("engine:prog.block").orElseThrow(() -> new RuntimeException("Missing engine material"));
    mat.activateFeature(ShaderProgramFeature.FEATURE_USE_MATRIX_STACK);
    mat.enable();
    mat.setFloat("sunlight", sunlight);
    mat.setFloat("blockLight", blockLight);
    Mesh mesh = meshGenerator.getStandaloneMesh();
    if (mesh != null) {
        mesh.render();
    }
    mat.deactivateFeature(ShaderProgramFeature.FEATURE_USE_MATRIX_STACK);
}
Also used : Mesh(org.terasology.rendering.assets.mesh.Mesh) Material(org.terasology.rendering.assets.material.Material)

Aggregations

Material (org.terasology.rendering.assets.material.Material)15 Mesh (org.terasology.rendering.assets.mesh.Mesh)7 EntityRef (org.terasology.entitySystem.entity.EntityRef)4 Vector3f (org.terasology.math.geom.Vector3f)4 MaterialData (org.terasology.rendering.assets.material.MaterialData)4 Shader (org.terasology.rendering.assets.shader.Shader)4 IOException (java.io.IOException)3 AssetFactory (org.terasology.assets.AssetFactory)3 ResourceUrn (org.terasology.assets.ResourceUrn)3 AssetManager (org.terasology.assets.management.AssetManager)3 ModuleAwareAssetTypeManager (org.terasology.assets.module.ModuleAwareAssetTypeManager)3 Context (org.terasology.context.Context)3 LocationComponent (org.terasology.logic.location.LocationComponent)3 MeshAnimation (org.terasology.rendering.assets.animation.MeshAnimation)3 MeshAnimationData (org.terasology.rendering.assets.animation.MeshAnimationData)3 MeshAnimationImpl (org.terasology.rendering.assets.animation.MeshAnimationImpl)3 Atlas (org.terasology.rendering.assets.atlas.Atlas)3 AtlasData (org.terasology.rendering.assets.atlas.AtlasData)3 Font (org.terasology.rendering.assets.font.Font)3 FloatBuffer (java.nio.FloatBuffer)2