use of org.terasology.engine.rendering.assets.material.Material in project Terasology by MovingBlocks.
the class FloatingTextRenderer method diposeMeshMap.
private void diposeMeshMap(Map<Material, Mesh> meshMap) {
for (Map.Entry<Material, Mesh> meshMapEntry : meshMap.entrySet()) {
Mesh mesh = meshMapEntry.getValue();
mesh.dispose();
// Note: Material belongs to font and must not be disposed
}
}
use of org.terasology.engine.rendering.assets.material.Material in project Terasology by MovingBlocks.
the class MeshRenderer method renderEntitiesByMaterial.
private void renderEntitiesByMaterial(SetMultimap<Material, EntityRef> meshByMaterial) {
Vector3f cameraPosition = worldRenderer.getActiveCamera().getPosition();
Quaternionf worldRot = new Quaternionf();
Vector3f worldPos = new Vector3f();
Matrix3f normalMatrix = new Matrix3f();
Matrix4f matrixCameraSpace = new Matrix4f();
Matrix4f modelViewMatrix = new Matrix4f();
FloatBuffer tempMatrixBuffer44 = BufferUtils.createFloatBuffer(16);
FloatBuffer tempMatrixBuffer33 = BufferUtils.createFloatBuffer(12);
for (Material material : meshByMaterial.keySet()) {
if (material.isRenderable()) {
material.enable();
material.setFloat("sunlight", 1.0f, true);
material.setFloat("blockLight", 1.0f, true);
material.setMatrix4("projectionMatrix", worldRenderer.getActiveCamera().getProjectionMatrix(), true);
material.bindTextures();
Set<EntityRef> entities = meshByMaterial.get(material);
lastRendered = entities.size();
for (EntityRef entity : entities) {
MeshComponent meshComp = entity.getComponent(MeshComponent.class);
LocationComponent location = entity.getComponent(LocationComponent.class);
if (isHidden(entity, meshComp) || location == null || meshComp.mesh == null) {
continue;
}
Vector3f worldPosition = location.getWorldPosition(new Vector3f());
if (!worldPosition.isFinite() && !isRelevant(entity, worldPosition)) {
continue;
}
if (meshComp.mesh.isDisposed()) {
logger.error("Attempted to render disposed mesh");
continue;
}
worldRot.set(location.getWorldRotation(new Quaternionf()));
worldPos.set(location.getWorldPosition(new Vector3f()));
float worldScale = location.getWorldScale();
Vector3f offsetFromCamera = worldPos.sub(cameraPosition, new Vector3f());
matrixCameraSpace.translationRotateScale(offsetFromCamera, worldRot, worldScale);
AABBf aabb = meshComp.mesh.getAABB().transform(new Matrix4f().translationRotateScale(worldPos, worldRot, worldScale), new AABBf());
if (worldRenderer.getActiveCamera().hasInSight(aabb)) {
modelViewMatrix.set(worldRenderer.getActiveCamera().getViewMatrix()).mul(matrixCameraSpace);
modelViewMatrix.get(tempMatrixBuffer44);
modelViewMatrix.normal(normalMatrix).get(tempMatrixBuffer33);
material.setMatrix4("projectionMatrix", worldRenderer.getActiveCamera().getProjectionMatrix(), true);
material.setMatrix4("modelViewMatrix", tempMatrixBuffer44, true);
material.setMatrix3("normalMatrix", tempMatrixBuffer33, true);
material.setFloat3("colorOffset", meshComp.color.rf(), meshComp.color.gf(), meshComp.color.bf(), true);
material.setFloat("sunlight", worldRenderer.getMainLightIntensityAt(worldPos), true);
material.setFloat("blockLight", Math.max(worldRenderer.getBlockLightIntensityAt(worldPos), meshComp.selfLuminance), true);
meshComp.mesh.render();
}
}
}
}
}
use of org.terasology.engine.rendering.assets.material.Material in project Terasology by MovingBlocks.
the class SpriteParticleRenderer method renderAlphaBlend.
@Override
public void renderAlphaBlend() {
if (!opengl33) {
return;
}
PerspectiveCamera camera = (PerspectiveCamera) worldRenderer.getActiveCamera();
Vector3f cameraPosition = camera.getPosition();
Matrix4f viewProjection = new Matrix4f(camera.getViewProjectionMatrix()).translate(-cameraPosition.x, -cameraPosition.y, -cameraPosition.z);
Material material = Assets.getMaterial(PARTICLE_MATERIAL_URI).get();
material.enable();
material.setFloat3("camera_position", cameraPosition.x, cameraPosition.y, cameraPosition.z);
material.setMatrix4("view_projection", viewProjection.get(matrixBuffer));
particleSystemManager.getParticleEmittersByDataComponent(ParticleDataSpriteComponent.class).forEach(particleSystem -> drawParticles(material, particleSystem));
}
use of org.terasology.engine.rendering.assets.material.Material in project Terasology by MovingBlocks.
the class FontFormat method parsePage.
private void parsePage(FontDataBuilder builder, Name moduleName, String pageInfo) throws IOException {
Matcher pageMatcher = pagePattern.matcher(pageInfo);
if (pageMatcher.matches()) {
int pageId = Integer.parseInt(pageMatcher.group(1));
Name textureName = new Name(pageMatcher.group(2).substring(0, pageMatcher.group(2).lastIndexOf('.')));
Optional<Material> material = assetManager.getAsset(new ResourceUrn(moduleName, new Name("font"), textureName), Material.class);
if (!material.isPresent()) {
throw new IOException("Failed to load font - unable to resolve font page '" + textureName + "'");
} else {
builder.addPage(pageId, assetManager.getAsset(new ResourceUrn(moduleName, textureName), Texture.class).get(), material.get());
}
} else {
throw new IOException("Failed to load font - invalid page line '" + pageInfo + "'");
}
}
use of org.terasology.engine.rendering.assets.material.Material 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;
}
Aggregations