use of org.terasology.engine.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;
}
use of org.terasology.engine.rendering.assets.material.Material in project Terasology by MovingBlocks.
the class MeshRenderer method renderEntities.
private void renderEntities(Iterable<EntityRef> entityRefs) {
SetMultimap<Material, EntityRef> entitiesToRender = HashMultimap.create();
for (EntityRef entity : entityRefs) {
MeshComponent meshComponent = entity.getComponent(MeshComponent.class);
if (meshComponent != null && meshComponent.material != null) {
entitiesToRender.put(meshComponent.material, entity);
}
}
renderEntitiesByMaterial(entitiesToRender);
}
use of org.terasology.engine.rendering.assets.material.Material in project Terasology by MovingBlocks.
the class FloatingTextRenderer method render.
private void render(Iterable<EntityRef> floatingTextEntities) {
Vector3fc cameraPosition = camera.getPosition();
Matrix4f model = new Matrix4f();
Matrix4f modelView = new Matrix4f();
Vector3f worldPos = new Vector3f();
for (EntityRef entity : floatingTextEntities) {
FloatingTextComponent floatingText = entity.getComponent(FloatingTextComponent.class);
LocationComponent location = entity.getComponent(LocationComponent.class);
if (location == null) {
logger.warn("location component is not defined can't render text: {}", floatingText.text);
continue;
}
location.getWorldPosition(worldPos);
if (!worldProvider.isBlockRelevant(worldPos) || !worldPos.isFinite()) {
continue;
}
String[] linesOfText = floatingText.text.split("\n");
Color baseColor = floatingText.textColor;
Color shadowColor = floatingText.textShadowColor;
boolean underline = false;
int textWidth = 0;
for (String singleLine : linesOfText) {
if (font.getWidth(singleLine) > textWidth) {
textWidth = font.getWidth(singleLine);
}
}
FontMeshBuilder meshBuilder = new FontMeshBuilder(underlineMaterial);
Map<Material, Mesh> meshMap = entityMeshCache.get(entity);
if (meshMap == null) {
meshMap = meshBuilder.createTextMesh(font, Arrays.asList(linesOfText), textWidth, HorizontalAlign.CENTER, baseColor, shadowColor, underline);
entityMeshCache.put(entity, meshMap);
}
if (floatingText.isOverlay) {
glDisable(GL_DEPTH_TEST);
}
float scale = METER_PER_PIXEL * floatingText.scale;
model.setTranslation(worldPos.sub(cameraPosition));
modelView.set(camera.getViewMatrix()).mul(model).m00(1.0f).m10(0.0f).m20(0.0f).m01(0.0f).m11(1.0f).m21(0.0f).m02(0.0f).m12(0.0f).m22(1.0f);
modelView.scale(scale, -scale, scale);
modelView.translate(-textWidth / 2.0f, 0.0f, 0.0f);
for (Map.Entry<Material, Mesh> meshMapEntry : meshMap.entrySet()) {
Mesh mesh = meshMapEntry.getValue();
Material material = meshMapEntry.getKey();
material.enable();
material.bindTextures();
material.setFloat4("croppingBoundaries", Float.MIN_VALUE, Float.MAX_VALUE, Float.MIN_VALUE, Float.MAX_VALUE);
material.setMatrix4("modelViewMatrix", modelView);
material.setMatrix4("projectionMatrix", camera.getProjectionMatrix());
material.setFloat2("offset", 0.0f, 0.0f);
material.setFloat("alpha", 1.0f);
mesh.render();
}
// Revert to default state
if (floatingText.isOverlay) {
glEnable(GL_DEPTH_TEST);
}
}
}
use of org.terasology.engine.rendering.assets.material.Material in project Terasology by MovingBlocks.
the class LwjglCanvasRenderer method drawText.
@Override
public void drawText(String text, Font font, HorizontalAlign hAlign, VerticalAlign vAlign, Rectanglei absoluteRegionRectangle, Colorc color, Colorc shadowColor, float alpha, boolean underlined) {
Rectanglei absoluteRegion = new Rectanglei(absoluteRegionRectangle);
TextCacheKey key = new TextCacheKey(text, font, absoluteRegion.getSizeX(), hAlign, color, shadowColor, underlined);
usedText.add(key);
Map<Material, Mesh> fontMesh = cachedText.get(key);
List<String> lines = TextLineBuilder.getLines(font, text, absoluteRegion.getSizeX());
if (fontMesh != null) {
for (Mesh mesh : fontMesh.values()) {
if (mesh.isDisposed()) {
fontMesh = null;
break;
}
}
}
if (fontMesh == null) {
fontMesh = fontMeshBuilder.createTextMesh((org.terasology.engine.rendering.assets.font.Font) font, lines, absoluteRegion.getSizeX(), hAlign, color, shadowColor, underlined);
cachedText.put(key, fontMesh);
}
Vector2i offset = new Vector2i(absoluteRegion.minX, absoluteRegion.minY);
offset.y += vAlign.getOffset(lines.size() * font.getLineHeight(), absoluteRegion.lengthY());
fontMesh.entrySet().stream().filter(entry -> entry.getKey().isRenderable()).forEach(entry -> {
entry.getKey().bindTextures();
entry.getKey().setMatrix4("projectionMatrix", projMatrix);
entry.getKey().setMatrix4("modelViewMatrix", modelMatrixStack);
entry.getKey().setFloat4(CROPPING_BOUNDARIES_PARAM, requestedCropRegion.minX, requestedCropRegion.maxX, requestedCropRegion.minY, requestedCropRegion.maxY);
entry.getKey().setFloat2("offset", offset.x, offset.y);
entry.getKey().setFloat("alpha", alpha);
entry.getValue().render();
});
}
Aggregations