mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 19:03:07 +02:00
images support materials
This commit is contained in:
parent
25e4f59d55
commit
186f505b15
5 changed files with 89 additions and 37 deletions
|
@ -496,7 +496,7 @@ EntityRenderer::Pipeline EntityRenderer::getPipelineType(const graphics::MultiMa
|
||||||
}
|
}
|
||||||
|
|
||||||
graphics::MaterialKey drawMaterialKey = materials.getMaterialKey();
|
graphics::MaterialKey drawMaterialKey = materials.getMaterialKey();
|
||||||
if (drawMaterialKey.isEmissive() || drawMaterialKey.isUnlit() || drawMaterialKey.isMetallic() || drawMaterialKey.isScattering()) {
|
if (drawMaterialKey.isEmissive() || drawMaterialKey.isMetallic() || drawMaterialKey.isScattering()) {
|
||||||
return Pipeline::MATERIAL;
|
return Pipeline::MATERIAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -635,20 +635,22 @@ void EntityRenderer::updateShapeKeyBuilderFromMaterials(ShapeKey::Builder& build
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.withCullFaceMode(materials->second.getCullFaceMode());
|
builder.withCullFaceMode(materials->second.getCullFaceMode());
|
||||||
|
|
||||||
|
graphics::MaterialKey drawMaterialKey = materials->second.getMaterialKey();
|
||||||
|
if (drawMaterialKey.isUnlit()) {
|
||||||
|
builder.withUnlit();
|
||||||
|
}
|
||||||
|
|
||||||
auto pipelineType = getPipelineType(materials->second);
|
auto pipelineType = getPipelineType(materials->second);
|
||||||
if (pipelineType == Pipeline::MATERIAL) {
|
if (pipelineType == Pipeline::MATERIAL) {
|
||||||
builder.withMaterial();
|
builder.withMaterial();
|
||||||
|
|
||||||
graphics::MaterialKey drawMaterialKey = materials->second.getMaterialKey();
|
|
||||||
if (drawMaterialKey.isNormalMap()) {
|
if (drawMaterialKey.isNormalMap()) {
|
||||||
builder.withTangents();
|
builder.withTangents();
|
||||||
}
|
}
|
||||||
if (drawMaterialKey.isLightMap()) {
|
if (drawMaterialKey.isLightMap()) {
|
||||||
builder.withLightMap();
|
builder.withLightMap();
|
||||||
}
|
}
|
||||||
if (drawMaterialKey.isUnlit()) {
|
|
||||||
builder.withUnlit();
|
|
||||||
}
|
|
||||||
} else if (pipelineType == Pipeline::PROCEDURAL) {
|
} else if (pipelineType == Pipeline::PROCEDURAL) {
|
||||||
builder.withOwnPipeline();
|
builder.withOwnPipeline();
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,7 +231,7 @@ Item::Bound GizmoEntityRenderer::getBound(RenderArgs* args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ShapeKey GizmoEntityRenderer::getShapeKey() {
|
ShapeKey GizmoEntityRenderer::getShapeKey() {
|
||||||
auto builder = render::ShapeKey::Builder().withoutCullFace();
|
auto builder = render::ShapeKey::Builder().withoutCullFace().withDepthBias();
|
||||||
|
|
||||||
auto mat = getAndUpdateMaterials();
|
auto mat = getAndUpdateMaterials();
|
||||||
|
|
||||||
|
@ -240,7 +240,7 @@ ShapeKey GizmoEntityRenderer::getShapeKey() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_primitiveMode == PrimitiveMode::LINES) {
|
if (_primitiveMode == PrimitiveMode::LINES) {
|
||||||
builder.withUnlit().withDepthBias().withWireframe();
|
builder.withUnlit().withWireframe();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateShapeKeyBuilderFromMaterials(builder, mat);
|
updateShapeKeyBuilderFromMaterials(builder, mat);
|
||||||
|
|
|
@ -11,11 +11,15 @@
|
||||||
#include <DependencyManager.h>
|
#include <DependencyManager.h>
|
||||||
#include <GeometryCache.h>
|
#include <GeometryCache.h>
|
||||||
|
|
||||||
|
#include "RenderPipelines.h"
|
||||||
|
|
||||||
using namespace render;
|
using namespace render;
|
||||||
using namespace render::entities;
|
using namespace render::entities;
|
||||||
|
|
||||||
ImageEntityRenderer::ImageEntityRenderer(const EntityItemPointer& entity) : Parent(entity) {
|
ImageEntityRenderer::ImageEntityRenderer(const EntityItemPointer& entity) : Parent(entity) {
|
||||||
_geometryId = DependencyManager::get<GeometryCache>()->allocateID();
|
_geometryId = DependencyManager::get<GeometryCache>()->allocateID();
|
||||||
|
_material->setCullFaceMode(graphics::MaterialKey::CullFaceMode::CULL_NONE);
|
||||||
|
addMaterial(graphics::MaterialLayer(_material, 0), "0");
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageEntityRenderer::~ImageEntityRenderer() {
|
ImageEntityRenderer::~ImageEntityRenderer() {
|
||||||
|
@ -51,20 +55,38 @@ void ImageEntityRenderer::doRenderUpdateAsynchronousTyped(const TypedEntityPoint
|
||||||
_textureIsLoaded = false;
|
_textureIsLoaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_emissive = entity->getEmissive();
|
|
||||||
_keepAspectRatio = entity->getKeepAspectRatio();
|
_keepAspectRatio = entity->getKeepAspectRatio();
|
||||||
_subImage = entity->getSubImage();
|
_subImage = entity->getSubImage();
|
||||||
|
|
||||||
_color = entity->getColor();
|
|
||||||
_alpha = entity->getAlpha();
|
|
||||||
_pulseProperties = entity->getPulseProperties();
|
_pulseProperties = entity->getPulseProperties();
|
||||||
|
|
||||||
|
bool materialChanged = false;
|
||||||
|
glm::vec3 color = toGlm(entity->getColor());
|
||||||
|
if (_color != color) {
|
||||||
|
_color = color;
|
||||||
|
_material->setAlbedo(color);
|
||||||
|
materialChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
float alpha = entity->getAlpha();
|
||||||
|
if (_alpha != alpha) {
|
||||||
|
_alpha = alpha;
|
||||||
|
_material->setOpacity(alpha);
|
||||||
|
materialChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto emissive = entity->getEmissive();
|
||||||
|
if (_emissive != emissive) {
|
||||||
|
_emissive = emissive;
|
||||||
|
_material->setUnlit(_emissive);
|
||||||
|
materialChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateMaterials(materialChanged);
|
||||||
|
|
||||||
if (!_textureIsLoaded) {
|
if (!_textureIsLoaded) {
|
||||||
emit requestRenderUpdate();
|
emit requestRenderUpdate();
|
||||||
}
|
}
|
||||||
_textureIsLoaded = _texture && (_texture->isLoaded() || _texture->isFailed());
|
_textureIsLoaded = _texture && (_texture->isLoaded() || _texture->isFailed());
|
||||||
|
|
||||||
updateMaterials();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ImageEntityRenderer::isTransparent() const {
|
bool ImageEntityRenderer::isTransparent() const {
|
||||||
|
@ -79,41 +101,53 @@ Item::Bound ImageEntityRenderer::getBound(RenderArgs* args) {
|
||||||
|
|
||||||
ShapeKey ImageEntityRenderer::getShapeKey() {
|
ShapeKey ImageEntityRenderer::getShapeKey() {
|
||||||
auto builder = render::ShapeKey::Builder().withoutCullFace().withDepthBias();
|
auto builder = render::ShapeKey::Builder().withoutCullFace().withDepthBias();
|
||||||
|
|
||||||
|
auto mat = getAndUpdateMaterials();
|
||||||
|
|
||||||
if (isTransparent()) {
|
if (isTransparent()) {
|
||||||
builder.withTranslucent();
|
builder.withTranslucent();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_emissive) {
|
|
||||||
builder.withUnlit();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_primitiveMode == PrimitiveMode::LINES) {
|
if (_primitiveMode == PrimitiveMode::LINES) {
|
||||||
builder.withWireframe();
|
builder.withWireframe();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateShapeKeyBuilderFromMaterials(builder, mat);
|
||||||
|
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageEntityRenderer::doRender(RenderArgs* args) {
|
void ImageEntityRenderer::doRender(RenderArgs* args) {
|
||||||
glm::vec4 color = glm::vec4(toGlm(_color), _alpha);
|
PerformanceTimer perfTimer("RenderableImageEntityItem::render");
|
||||||
color = EntityRenderer::calculatePulseColor(color, _pulseProperties, _created);
|
Q_ASSERT(args->_batch);
|
||||||
Transform transform;
|
|
||||||
withReadLock([&] {
|
|
||||||
transform = _renderTransform;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!_visible || !_texture || !_texture->isLoaded() || color.a == 0.0f) {
|
graphics::MultiMaterial materials;
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(_materialsLock);
|
||||||
|
materials = _materials["0"];
|
||||||
|
}
|
||||||
|
|
||||||
|
auto& schema = materials.getSchemaBuffer().get<graphics::MultiMaterial::Schema>();
|
||||||
|
glm::vec4 color = glm::vec4(ColorUtils::tosRGBVec3(schema._albedo), schema._opacity);
|
||||||
|
color = EntityRenderer::calculatePulseColor(color, _pulseProperties, _created);
|
||||||
|
|
||||||
|
if (!_texture || !_texture->isLoaded() || color.a == 0.0f) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_ASSERT(args->_batch);
|
Transform transform;
|
||||||
|
bool transparent;
|
||||||
|
withReadLock([&] {
|
||||||
|
transform = _renderTransform;
|
||||||
|
transparent = isTransparent();
|
||||||
|
});
|
||||||
|
|
||||||
gpu::Batch* batch = args->_batch;
|
gpu::Batch* batch = args->_batch;
|
||||||
|
|
||||||
transform.setRotation(BillboardModeHelpers::getBillboardRotation(transform.getTranslation(), transform.getRotation(), _billboardMode,
|
transform.setRotation(BillboardModeHelpers::getBillboardRotation(transform.getTranslation(), transform.getRotation(), _billboardMode,
|
||||||
args->_renderMode == RenderArgs::RenderMode::SHADOW_RENDER_MODE ? BillboardModeHelpers::getPrimaryViewFrustumPosition() : args->getViewFrustum().getPosition()));
|
args->_renderMode == RenderArgs::RenderMode::SHADOW_RENDER_MODE ? BillboardModeHelpers::getPrimaryViewFrustumPosition() : args->getViewFrustum().getPosition()));
|
||||||
|
|
||||||
batch->setModelTransform(transform);
|
batch->setModelTransform(transform);
|
||||||
batch->setResourceTexture(0, _texture->getGPUTexture());
|
|
||||||
|
|
||||||
float imageWidth = _texture->getWidth();
|
float imageWidth = _texture->getWidth();
|
||||||
float imageHeight = _texture->getHeight();
|
float imageHeight = _texture->getHeight();
|
||||||
|
@ -144,6 +178,19 @@ void ImageEntityRenderer::doRender(RenderArgs* args) {
|
||||||
glm::vec2 texCoordBottomLeft((fromImage.x() + 0.5f) / imageWidth, (fromImage.y() + fromImage.height() - 0.5f) / imageHeight);
|
glm::vec2 texCoordBottomLeft((fromImage.x() + 0.5f) / imageWidth, (fromImage.y() + fromImage.height() - 0.5f) / imageHeight);
|
||||||
glm::vec2 texCoordTopRight((fromImage.x() + fromImage.width() - 0.5f) / imageWidth, (fromImage.y() + 0.5f) / imageHeight);
|
glm::vec2 texCoordTopRight((fromImage.x() + fromImage.width() - 0.5f) / imageWidth, (fromImage.y() + 0.5f) / imageHeight);
|
||||||
|
|
||||||
|
Pipeline pipelineType = getPipelineType(materials);
|
||||||
|
if (pipelineType == Pipeline::PROCEDURAL) {
|
||||||
|
auto procedural = std::static_pointer_cast<graphics::ProceduralMaterial>(materials.top().material);
|
||||||
|
transparent |= procedural->isFading();
|
||||||
|
procedural->prepare(*batch, transform.getTranslation(), transform.getScale(), transform.getRotation(), _created, ProceduralProgramKey(transparent));
|
||||||
|
} else if (pipelineType == Pipeline::SIMPLE) {
|
||||||
|
batch->setResourceTexture(0, _texture->getGPUTexture());
|
||||||
|
} else {
|
||||||
|
if (RenderPipelines::bindMaterials(materials, *batch, args->_renderMode, args->_enableTexturing)) {
|
||||||
|
args->_details._materialSwitches++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DependencyManager::get<GeometryCache>()->renderQuad(
|
DependencyManager::get<GeometryCache>()->renderQuad(
|
||||||
*batch, glm::vec2(-x, -y), glm::vec2(x, y), texCoordBottomLeft, texCoordTopRight,
|
*batch, glm::vec2(-x, -y), glm::vec2(x, y), texCoordBottomLeft, texCoordTopRight,
|
||||||
color, _geometryId
|
color, _geometryId
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
|
|
||||||
#include <ImageEntityItem.h>
|
#include <ImageEntityItem.h>
|
||||||
|
|
||||||
|
#include <procedural/Procedural.h>
|
||||||
|
|
||||||
namespace render { namespace entities {
|
namespace render { namespace entities {
|
||||||
|
|
||||||
class ImageEntityRenderer : public TypedEntityRenderer<ImageEntityItem> {
|
class ImageEntityRenderer : public TypedEntityRenderer<ImageEntityItem> {
|
||||||
|
@ -42,8 +44,9 @@ private:
|
||||||
bool _keepAspectRatio;
|
bool _keepAspectRatio;
|
||||||
QRect _subImage;
|
QRect _subImage;
|
||||||
|
|
||||||
glm::u8vec3 _color;
|
std::shared_ptr<graphics::ProceduralMaterial> _material { std::make_shared<graphics::ProceduralMaterial>() };
|
||||||
float _alpha;
|
glm::vec3 _color { NAN };
|
||||||
|
float _alpha { NAN };
|
||||||
PulsePropertyGroup _pulseProperties;
|
PulsePropertyGroup _pulseProperties;
|
||||||
|
|
||||||
int _geometryId { 0 };
|
int _geometryId { 0 };
|
||||||
|
|
|
@ -108,15 +108,6 @@ void ShapeEntityRenderer::doRender(RenderArgs* args) {
|
||||||
PerformanceTimer perfTimer("RenderableShapeEntityItem::render");
|
PerformanceTimer perfTimer("RenderableShapeEntityItem::render");
|
||||||
Q_ASSERT(args->_batch);
|
Q_ASSERT(args->_batch);
|
||||||
|
|
||||||
gpu::Batch& batch = *args->_batch;
|
|
||||||
|
|
||||||
auto geometryCache = DependencyManager::get<GeometryCache>();
|
|
||||||
GeometryCache::Shape geometryShape = geometryCache->getShapeForEntityShape(_shape);
|
|
||||||
Transform transform;
|
|
||||||
withReadLock([&] {
|
|
||||||
transform = _renderTransform;
|
|
||||||
});
|
|
||||||
|
|
||||||
graphics::MultiMaterial materials;
|
graphics::MultiMaterial materials;
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(_materialsLock);
|
std::lock_guard<std::mutex> lock(_materialsLock);
|
||||||
|
@ -131,6 +122,15 @@ void ShapeEntityRenderer::doRender(RenderArgs* args) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gpu::Batch& batch = *args->_batch;
|
||||||
|
|
||||||
|
auto geometryCache = DependencyManager::get<GeometryCache>();
|
||||||
|
GeometryCache::Shape geometryShape = geometryCache->getShapeForEntityShape(_shape);
|
||||||
|
Transform transform;
|
||||||
|
withReadLock([&] {
|
||||||
|
transform = _renderTransform;
|
||||||
|
});
|
||||||
|
|
||||||
bool wireframe = render::ShapeKey(args->_globalShapeKey).isWireframe() || _primitiveMode == PrimitiveMode::LINES;
|
bool wireframe = render::ShapeKey(args->_globalShapeKey).isWireframe() || _primitiveMode == PrimitiveMode::LINES;
|
||||||
|
|
||||||
transform.setRotation(BillboardModeHelpers::getBillboardRotation(transform.getTranslation(), transform.getRotation(), _billboardMode,
|
transform.setRotation(BillboardModeHelpers::getBillboardRotation(transform.getTranslation(), transform.getRotation(), _billboardMode,
|
||||||
|
|
Loading…
Reference in a new issue