mainly material and picking updates
This commit is contained in:
+467
-415
File diff suppressed because it is too large
Load Diff
@@ -35,8 +35,9 @@ public:
|
||||
wiSlider* emissiveSlider;
|
||||
wiSlider* sssSlider;
|
||||
wiSlider* pomSlider;
|
||||
wiSlider* movingTexSliderU;
|
||||
wiSlider* movingTexSliderV;
|
||||
wiSlider* texAnimFrameRateSlider;
|
||||
wiSlider* texAnimDirectionSliderU;
|
||||
wiSlider* texAnimDirectionSliderV;
|
||||
wiSlider* texMulSliderX;
|
||||
wiSlider* texMulSliderY;
|
||||
wiColorPicker* colorPicker;
|
||||
|
||||
@@ -30,19 +30,16 @@ Entity ImportModel_OBJ(const std::string& fileName)
|
||||
|
||||
if (success)
|
||||
{
|
||||
//Model* model = new Model;
|
||||
//model->name = name;
|
||||
|
||||
Entity modelEntity = scene.Entity_CreateModel(name);
|
||||
ModelComponent& model = *scene.models.GetComponent(modelEntity);
|
||||
TransformComponent& model_transform = *scene.transforms.GetComponent(modelEntity);
|
||||
|
||||
model_transform.UpdateTransform(); // everything will be attached to this, so values need to be up to date
|
||||
|
||||
// Load material library:
|
||||
vector<Entity> materialLibrary = {};
|
||||
for (auto& obj_material : obj_materials)
|
||||
{
|
||||
//Material* material = new Material(obj_material.name);
|
||||
|
||||
Entity materialEntity = scene.Entity_CreateMaterial(obj_material.name);
|
||||
MaterialComponent& material = *scene.materials.GetComponent(materialEntity);
|
||||
|
||||
@@ -54,17 +51,11 @@ Entity ImportModel_OBJ(const std::string& fileName)
|
||||
material.displacementMapName = obj_material.bump_texname;
|
||||
}
|
||||
material.emissive = max(obj_material.emission[0], max(obj_material.emission[1], obj_material.emission[2]));
|
||||
//obj_material.emissive_texname;
|
||||
material.refractionIndex = obj_material.ior;
|
||||
material.metalness = obj_material.metallic;
|
||||
//obj_material.metallic_texname;
|
||||
material.normalMapName = obj_material.normal_texname;
|
||||
material.surfaceMapName = obj_material.reflection_texname;
|
||||
material.roughness = obj_material.roughness;
|
||||
//obj_material.roughness_texname;
|
||||
//material.specular_power = (int)obj_material.shininess;
|
||||
//material.specular = XMFLOAT4(obj_material.specular[0], obj_material.specular[1], obj_material.specular[2], 1);
|
||||
//material.specularMapName = obj_material.specular_texname;
|
||||
|
||||
if (!material.surfaceMapName.empty())
|
||||
{
|
||||
@@ -86,17 +77,9 @@ Entity ImportModel_OBJ(const std::string& fileName)
|
||||
material.displacementMapName = directory + material.displacementMapName;
|
||||
material.displacementMap = (Texture2D*)wiResourceManager::GetGlobal()->add(material.displacementMapName);
|
||||
}
|
||||
//if (!material.specularMapName.empty())
|
||||
//{
|
||||
// material.specularMapName = directory + material.specularMapName;
|
||||
// material.specularMap = (Texture2D*)wiResourceManager::GetGlobal()->add(material.specularMapName);
|
||||
//}
|
||||
|
||||
//material.ConvertToPhysicallyBasedMaterial();
|
||||
|
||||
materialLibrary.push_back(materialEntity); // for subset-indexing...
|
||||
model.materials.insert(materialEntity);
|
||||
//model->materials.insert(make_pair(material.name, material));
|
||||
}
|
||||
|
||||
if (materialLibrary.empty())
|
||||
@@ -106,23 +89,17 @@ Entity ImportModel_OBJ(const std::string& fileName)
|
||||
MaterialComponent& material = *scene.materials.GetComponent(materialEntity);
|
||||
materialLibrary.push_back(materialEntity); // for subset-indexing...
|
||||
model.materials.insert(materialEntity);
|
||||
//Material* material = new Material("OBJImport_defaultMaterial");
|
||||
//materialLibrary.push_back(material);
|
||||
//model->materials.insert(make_pair(material.name, material));
|
||||
}
|
||||
|
||||
// Load objects, meshes:
|
||||
for (auto& shape : obj_shapes)
|
||||
{
|
||||
//Object* object = new Object(shape.name);
|
||||
//Mesh* mesh = new Mesh(shape.name + "_mesh");
|
||||
|
||||
Entity objectEntity = scene.Entity_CreateObject(shape.name);
|
||||
Entity meshEntity = scene.Entity_CreateMesh(shape.name + "_mesh");
|
||||
ObjectComponent& object = *scene.objects.GetComponent(objectEntity);
|
||||
MeshComponent& mesh = *scene.meshes.GetComponent(meshEntity);
|
||||
|
||||
//scene.Component_Attach(objectEntity, modelEntity);
|
||||
scene.Component_Attach(objectEntity, modelEntity);
|
||||
|
||||
object.meshID = meshEntity;
|
||||
mesh.renderable = true;
|
||||
@@ -184,9 +161,7 @@ Entity ImportModel_OBJ(const std::string& fileName)
|
||||
{
|
||||
registered_materialIndices[materialIndex] = (int)mesh.subsets.size();
|
||||
mesh.subsets.push_back(MeshComponent::MeshSubset());
|
||||
//MaterialComponent* material = materialLibrary[materialIndex];
|
||||
mesh.subsets.back().materialID = materialLibrary[materialIndex];
|
||||
//mesh.materialNames.push_back(material.name);
|
||||
}
|
||||
vert.tex.z = (float)registered_materialIndices[materialIndex]; // this indexes a mesh subset
|
||||
|
||||
@@ -221,30 +196,10 @@ Entity ImportModel_OBJ(const std::string& fileName)
|
||||
mesh.aabb.create(min, max);
|
||||
mesh.CreateRenderData();
|
||||
|
||||
//// We need to eliminate colliding mesh names, because objects can reference them by names:
|
||||
//// Note: in engine, object is decoupled from mesh, for instancing support. OBJ file have only meshes and names can collide there.
|
||||
//string meshName = mesh->name;
|
||||
//uint32_t unique_counter = 0;
|
||||
//bool meshNameCollision = model->meshes.count(meshName) != 0;
|
||||
//while (meshNameCollision)
|
||||
//{
|
||||
// meshName = mesh->name + to_string(unique_counter);
|
||||
// meshNameCollision = model->meshes.count(meshName) != 0;
|
||||
// unique_counter++;
|
||||
//}
|
||||
//mesh->name = meshName;
|
||||
|
||||
//object->meshName = mesh->name;
|
||||
|
||||
model.objects.insert(objectEntity);
|
||||
model.meshes.insert(meshEntity);
|
||||
|
||||
//model->objects.insert(object);
|
||||
//model->meshes.insert(make_pair(mesh->name, mesh));
|
||||
}
|
||||
|
||||
//model->FinishLoading();
|
||||
|
||||
return modelEntity;
|
||||
}
|
||||
|
||||
|
||||
+123
-149
@@ -3119,40 +3119,13 @@ void wiRenderer::UpdatePerFrameData(float dt)
|
||||
const ObjectComponent* object = scene.objects.GetComponent(entity);
|
||||
if (object != nullptr)
|
||||
{
|
||||
const MeshComponent* mesh = scene.meshes.GetComponent(object->meshID);
|
||||
if (mesh != nullptr)
|
||||
if (object->GetRenderTypes() & RENDERTYPE_OPAQUE)
|
||||
{
|
||||
UINT renderTypes = 0;
|
||||
for (auto& subset : mesh->subsets)
|
||||
{
|
||||
const MaterialComponent* material = scene.materials.GetComponent(subset.materialID);
|
||||
if (material != nullptr)
|
||||
{
|
||||
if (material->IsTransparent())
|
||||
{
|
||||
renderTypes |= RENDERTYPE_TRANSPARENT;
|
||||
}
|
||||
else
|
||||
{
|
||||
renderTypes |= RENDERTYPE_OPAQUE;
|
||||
}
|
||||
|
||||
if (material->IsWater())
|
||||
{
|
||||
renderTypes |= RENDERTYPE_TRANSPARENT | RENDERTYPE_WATER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (renderTypes & RENDERTYPE_OPAQUE)
|
||||
{
|
||||
culling.culledRenderer_opaque[object->meshID].push_back(entity);
|
||||
}
|
||||
if (renderTypes & RENDERTYPE_TRANSPARENT)
|
||||
{
|
||||
culling.culledRenderer_transparent[object->meshID].push_back(entity);
|
||||
}
|
||||
|
||||
culling.culledRenderer_opaque[object->meshID].push_back(entity);
|
||||
}
|
||||
if (object->GetRenderTypes() & RENDERTYPE_TRANSPARENT)
|
||||
{
|
||||
culling.culledRenderer_transparent[object->meshID].push_back(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5141,7 +5114,6 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle
|
||||
tessellation = tessellation && device->CheckCapability(GraphicsDevice::GRAPHICSDEVICE_CAPABILITY_TESSELLATION);
|
||||
|
||||
const XMFLOAT4X4 __identityMat = XMFLOAT4X4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
||||
XMFLOAT4X4 tempMat;
|
||||
|
||||
struct InstBuf
|
||||
{
|
||||
@@ -5211,6 +5183,7 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle
|
||||
|
||||
const TransformComponent& transform = *scene.transforms.GetComponent(objectEntity);
|
||||
|
||||
XMFLOAT4X4 tempMat;
|
||||
XMStoreFloat4x4(&tempMat, boxMat*XMLoadFloat4x4(&transform.world));
|
||||
|
||||
if (advancedVBRequest)
|
||||
@@ -5309,13 +5282,7 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle
|
||||
continue;
|
||||
}
|
||||
|
||||
bool softbody = false;
|
||||
|
||||
const PhysicsComponent* physicscomponent = scene.physicscomponents.GetComponent(meshEntity);
|
||||
if (physicscomponent != nullptr)
|
||||
{
|
||||
softbody = physicscomponent->softBody;
|
||||
}
|
||||
const bool dynamicVB = mesh.IsDynamicVB();
|
||||
|
||||
const auto& visibleInstances = iter->second;
|
||||
|
||||
@@ -5366,24 +5333,14 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle
|
||||
|
||||
const TransformComponent& transform = *scene.transforms.GetComponent(objectEntity);
|
||||
|
||||
if (softbody)
|
||||
tempMat = __identityMat;
|
||||
else
|
||||
tempMat = transform.world;
|
||||
|
||||
if (advancedVBRequest || tessellatorRequested)
|
||||
{
|
||||
((volatile InstBuf*)instances)[k].instance.Create(tempMat, instance.color);
|
||||
|
||||
if (softbody)
|
||||
tempMat = __identityMat;
|
||||
else
|
||||
tempMat = transform.world_prev;
|
||||
((volatile InstBuf*)instances)[k].instancePrev.Create(tempMat);
|
||||
((volatile InstBuf*)instances)[k].instance.Create(dynamicVB ? __identityMat : transform.world, instance.color);
|
||||
((volatile InstBuf*)instances)[k].instancePrev.Create(dynamicVB ? __identityMat : transform.world_prev);
|
||||
}
|
||||
else
|
||||
{
|
||||
((volatile Instance*)instances)[k].Create(tempMat, instance.color, dither);
|
||||
((volatile Instance*)instances)[k].Create(dynamicVB ? __identityMat : transform.world, instance.color, dither);
|
||||
}
|
||||
|
||||
++k;
|
||||
@@ -5489,7 +5446,7 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle
|
||||
case BOUNDVERTEXBUFFERTYPE::POSITION:
|
||||
{
|
||||
GPUBuffer* vbs[] = {
|
||||
softbody ? dynamicVertexBufferPool : (mesh.streamoutBuffer_POS != nullptr ? mesh.streamoutBuffer_POS : mesh.vertexBuffer_POS),
|
||||
dynamicVB ? dynamicVertexBufferPool : (mesh.streamoutBuffer_POS != nullptr ? mesh.streamoutBuffer_POS : mesh.vertexBuffer_POS),
|
||||
dynamicVertexBufferPool
|
||||
};
|
||||
UINT strides[] = {
|
||||
@@ -5497,7 +5454,7 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle
|
||||
sizeof(Instance)
|
||||
};
|
||||
UINT offsets[] = {
|
||||
softbody ? mesh.bufferOffset_POS : 0,
|
||||
dynamicVB ? mesh.bufferOffset_POS : 0,
|
||||
instancesOffset
|
||||
};
|
||||
device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, offsets, threadID);
|
||||
@@ -5506,7 +5463,7 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle
|
||||
case BOUNDVERTEXBUFFERTYPE::POSITION_TEXCOORD:
|
||||
{
|
||||
GPUBuffer* vbs[] = {
|
||||
softbody ? dynamicVertexBufferPool : (mesh.streamoutBuffer_POS != nullptr ? mesh.streamoutBuffer_POS : mesh.vertexBuffer_POS),
|
||||
dynamicVB ? dynamicVertexBufferPool : (mesh.streamoutBuffer_POS != nullptr ? mesh.streamoutBuffer_POS : mesh.vertexBuffer_POS),
|
||||
mesh.vertexBuffer_TEX,
|
||||
dynamicVertexBufferPool
|
||||
};
|
||||
@@ -5516,7 +5473,7 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle
|
||||
sizeof(Instance)
|
||||
};
|
||||
UINT offsets[] = {
|
||||
softbody ? mesh.bufferOffset_POS : 0,
|
||||
dynamicVB ? mesh.bufferOffset_POS : 0,
|
||||
0,
|
||||
instancesOffset
|
||||
};
|
||||
@@ -5526,9 +5483,9 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle
|
||||
case BOUNDVERTEXBUFFERTYPE::EVERYTHING:
|
||||
{
|
||||
GPUBuffer* vbs[] = {
|
||||
softbody ? dynamicVertexBufferPool : (mesh.streamoutBuffer_POS != nullptr ? mesh.streamoutBuffer_POS : mesh.vertexBuffer_POS),
|
||||
dynamicVB ? dynamicVertexBufferPool : (mesh.streamoutBuffer_POS != nullptr ? mesh.streamoutBuffer_POS : mesh.vertexBuffer_POS),
|
||||
mesh.vertexBuffer_TEX,
|
||||
softbody ? dynamicVertexBufferPool : (mesh.streamoutBuffer_PRE != nullptr ? mesh.streamoutBuffer_PRE : mesh.vertexBuffer_POS),
|
||||
dynamicVB ? dynamicVertexBufferPool : (mesh.streamoutBuffer_PRE != nullptr ? mesh.streamoutBuffer_PRE : mesh.vertexBuffer_POS),
|
||||
dynamicVertexBufferPool
|
||||
};
|
||||
UINT strides[] = {
|
||||
@@ -5538,9 +5495,9 @@ void wiRenderer::RenderMeshes(const XMFLOAT3& eye, const CulledCollection& culle
|
||||
sizeof(InstBuf)
|
||||
};
|
||||
UINT offsets[] = {
|
||||
softbody ? mesh.bufferOffset_POS : 0,
|
||||
dynamicVB ? mesh.bufferOffset_POS : 0,
|
||||
0,
|
||||
softbody ? mesh.bufferOffset_PRE : 0,
|
||||
dynamicVB ? mesh.bufferOffset_PRE : 0,
|
||||
instancesOffset
|
||||
};
|
||||
device->BindVertexBuffers(vbs, 0, ARRAYSIZE(vbs), strides, offsets, threadID);
|
||||
@@ -7989,112 +7946,129 @@ RAY wiRenderer::getPickRay(long cursorX, long cursorY) {
|
||||
|
||||
wiRenderer::RayIntersectWorldResult wiRenderer::RayIntersectWorld(const RAY& ray, UINT renderTypeMask, uint32_t layerMask, bool dynamicObjects, bool onlyVisible)
|
||||
{
|
||||
Scene& scene = GetScene();
|
||||
|
||||
RayIntersectWorldResult result;
|
||||
|
||||
//if (spTree != nullptr)
|
||||
//{
|
||||
// CulledList culledObjects;
|
||||
// spTree->getVisible(ray, culledObjects);
|
||||
{
|
||||
//CulledList culledObjects;
|
||||
//spTree->getVisible(ray, culledObjects);
|
||||
|
||||
// if (culledObjects.empty())
|
||||
// {
|
||||
// return result;
|
||||
// }
|
||||
//if (culledObjects.empty())
|
||||
//{
|
||||
// return result;
|
||||
//}
|
||||
|
||||
// const XMVECTOR rayOrigin = XMLoadFloat3(&ray.origin);
|
||||
// const XMVECTOR rayDirection = XMVector3Normalize(XMLoadFloat3(&ray.direction));
|
||||
const XMVECTOR rayOrigin = XMLoadFloat3(&ray.origin);
|
||||
const XMVECTOR rayDirection = XMVector3Normalize(XMLoadFloat3(&ray.direction));
|
||||
|
||||
// // pre allocate helper vector array:
|
||||
// static size_t _arraySize = 10000;
|
||||
// static XMVECTOR* _vertices = (XMVECTOR*)_mm_malloc(sizeof(XMVECTOR)*_arraySize, 16);
|
||||
// pre allocate helper vector array:
|
||||
static size_t _arraySize = 10000;
|
||||
static XMVECTOR* _vertices = (XMVECTOR*)_mm_malloc(sizeof(XMVECTOR)*_arraySize, 16);
|
||||
|
||||
// for (Cullable* culled : culledObjects)
|
||||
// {
|
||||
// Object* object = (Object*)culled;
|
||||
for (size_t i = 0; i < scene.objects.GetCount(); ++i)
|
||||
{
|
||||
Entity entity = scene.objects.GetEntity(i);
|
||||
const LayerComponent& layer = *scene.layers.GetComponent(entity);
|
||||
|
||||
// const uint32_t objectLayerMask = object->GetLayerMask();
|
||||
// if (objectLayerMask & layerMask)
|
||||
// {
|
||||
const uint32_t objectLayerMask = layer.GetLayerMask();
|
||||
if (objectLayerMask & layerMask)
|
||||
{
|
||||
const ObjectComponent& object = scene.objects[i];
|
||||
|
||||
// if (!(renderTypeMask & object->GetRenderTypes()))
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
// if (!dynamicObjects && object->isDynamic())
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
// if (onlyVisible && object->IsOccluded() && GetOcclusionCullingEnabled())
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
if (object.meshID == INVALID_ENTITY)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!(renderTypeMask & object.GetRenderTypes()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!dynamicObjects && object.IsDynamic())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (onlyVisible && object.IsOccluded() && GetOcclusionCullingEnabled())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Mesh* mesh = object->mesh;
|
||||
// if (mesh->vertices_POS.size() >= _arraySize)
|
||||
// {
|
||||
// // grow preallocated vector helper array
|
||||
// _mm_free(_vertices);
|
||||
// _arraySize = (mesh->vertices_POS.size() + 1) * 2;
|
||||
// _vertices = (XMVECTOR*)_mm_malloc(sizeof(XMVECTOR)*_arraySize, 16);
|
||||
// }
|
||||
const CullableComponent& cullable = *scene.cullables.GetComponent(entity);
|
||||
if (!ray.intersects(cullable.aabb))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// const XMMATRIX objectMat = object->getMatrix();
|
||||
// const XMMATRIX objectMat_Inverse = XMMatrixInverse(nullptr, objectMat);
|
||||
const MeshComponent& mesh = *scene.meshes.GetComponent(object.meshID);
|
||||
if (mesh.vertices_POS.size() >= _arraySize)
|
||||
{
|
||||
// grow preallocated vector helper array
|
||||
_mm_free(_vertices);
|
||||
_arraySize = (mesh.vertices_POS.size() + 1) * 2;
|
||||
_vertices = (XMVECTOR*)_mm_malloc(sizeof(XMVECTOR)*_arraySize, 16);
|
||||
}
|
||||
|
||||
// const XMVECTOR rayOrigin_local = XMVector3Transform(rayOrigin, objectMat_Inverse);
|
||||
// const XMVECTOR rayDirection_local = XMVector3Normalize(XMVector3TransformNormal(rayDirection, objectMat_Inverse));
|
||||
const TransformComponent& transform = *scene.transforms.GetComponent(entity);
|
||||
|
||||
// MeshComponent::Vertex_FULL _tmpvert;
|
||||
const XMMATRIX objectMat = XMLoadFloat4x4(&transform.world);
|
||||
const XMMATRIX objectMat_Inverse = XMMatrixInverse(nullptr, objectMat);
|
||||
|
||||
// if (object->isArmatureDeformed() && !object->mesh->armature->boneCollection.empty())
|
||||
// {
|
||||
// for (size_t i = 0; i < mesh->vertices_POS.size(); ++i)
|
||||
// {
|
||||
// _tmpvert = mesh->TransformVertex((int)i);
|
||||
// _vertices[i] = XMLoadFloat4(&_tmpvert.pos);
|
||||
// }
|
||||
// }
|
||||
// else if (mesh->hasDynamicVB())
|
||||
// {
|
||||
// for (size_t i = 0; i < mesh->vertices_Transformed_POS.size(); ++i)
|
||||
// {
|
||||
// _vertices[i] = mesh->vertices_Transformed_POS[i].LoadPOS();
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// for (size_t i = 0; i < mesh->vertices_POS.size(); ++i)
|
||||
// {
|
||||
// _vertices[i] = mesh->vertices_POS[i].LoadPOS();
|
||||
// }
|
||||
// }
|
||||
const XMVECTOR rayOrigin_local = XMVector3Transform(rayOrigin, objectMat_Inverse);
|
||||
const XMVECTOR rayDirection_local = XMVector3Normalize(XMVector3TransformNormal(rayDirection, objectMat_Inverse));
|
||||
|
||||
// for (size_t i = 0; i < mesh->indices.size(); i += 3)
|
||||
// {
|
||||
// int i0 = mesh->indices[i], i1 = mesh->indices[i + 1], i2 = mesh->indices[i + 2];
|
||||
// float distance;
|
||||
// if (TriangleTests::Intersects(rayOrigin_local, rayDirection_local, _vertices[i0], _vertices[i1], _vertices[i2], distance))
|
||||
// {
|
||||
// XMVECTOR pos = XMVector3Transform(XMVectorAdd(rayOrigin_local, rayDirection_local*distance), objectMat);
|
||||
// distance = wiMath::Distance(pos, rayOrigin);
|
||||
MeshComponent::Vertex_FULL _tmpvert;
|
||||
|
||||
// if (distance < result.distance)
|
||||
// {
|
||||
// XMVECTOR nor = XMVector3Normalize(XMVector3TransformNormal(XMVector3Normalize(XMVector3Cross(XMVectorSubtract(_vertices[i2], _vertices[i1]), XMVectorSubtract(_vertices[i1], _vertices[i0]))), objectMat));
|
||||
if (mesh.IsSkinned())
|
||||
{
|
||||
//for (size_t i = 0; i < mesh.vertices_POS.size(); ++i)
|
||||
//{
|
||||
// _tmpvert = mesh.TransformVertex((int)i);
|
||||
// _vertices[i] = XMLoadFloat4(&_tmpvert.pos);
|
||||
//}
|
||||
assert(0); // todo
|
||||
}
|
||||
else if (mesh.IsDynamicVB())
|
||||
{
|
||||
for (size_t i = 0; i < mesh.vertices_Transformed_POS.size(); ++i)
|
||||
{
|
||||
_vertices[i] = mesh.vertices_Transformed_POS[i].LoadPOS();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t i = 0; i < mesh.vertices_POS.size(); ++i)
|
||||
{
|
||||
_vertices[i] = mesh.vertices_POS[i].LoadPOS();
|
||||
}
|
||||
}
|
||||
|
||||
// result.object = object;
|
||||
// XMStoreFloat3(&result.position, pos);
|
||||
// XMStoreFloat3(&result.normal, nor);
|
||||
// result.distance = distance;
|
||||
// result.subsetIndex = (int)mesh->vertices_POS[i0].GetMaterialIndex();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
for (size_t i = 0; i < mesh.indices.size(); i += 3)
|
||||
{
|
||||
int i0 = mesh.indices[i], i1 = mesh.indices[i + 1], i2 = mesh.indices[i + 2];
|
||||
float distance;
|
||||
if (TriangleTests::Intersects(rayOrigin_local, rayDirection_local, _vertices[i0], _vertices[i1], _vertices[i2], distance))
|
||||
{
|
||||
XMVECTOR pos = XMVector3Transform(XMVectorAdd(rayOrigin_local, rayDirection_local*distance), objectMat);
|
||||
distance = wiMath::Distance(pos, rayOrigin);
|
||||
|
||||
// }
|
||||
if (distance < result.distance)
|
||||
{
|
||||
XMVECTOR nor = XMVector3Normalize(XMVector3TransformNormal(XMVector3Normalize(XMVector3Cross(XMVectorSubtract(_vertices[i2], _vertices[i1]), XMVectorSubtract(_vertices[i1], _vertices[i0]))), objectMat));
|
||||
|
||||
// }
|
||||
//}
|
||||
result.entity = entity;
|
||||
XMStoreFloat3(&result.position, pos);
|
||||
XMStoreFloat3(&result.normal, nor);
|
||||
result.distance = distance;
|
||||
result.subsetIndex = (int)mesh.vertices_POS[i0].GetMaterialIndex();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -578,6 +578,13 @@ namespace wiSceneSystem
|
||||
for (size_t i = 0; i < physicscomponents.GetCount(); ++i)
|
||||
{
|
||||
PhysicsComponent& physicscomponent = physicscomponents[i];
|
||||
Entity entity = physicscomponents.GetEntity(i);
|
||||
|
||||
if (physicscomponent.softBody)
|
||||
{
|
||||
MeshComponent& mesh = *meshes.GetComponent(entity);
|
||||
mesh.dynamicVB = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Update Material components:
|
||||
@@ -585,17 +592,14 @@ namespace wiSceneSystem
|
||||
{
|
||||
MaterialComponent& material = materials[i];
|
||||
|
||||
if (material.texAnimFrameRate > 0)
|
||||
{
|
||||
material.dirty = true; // will trigger contant buffer update!
|
||||
}
|
||||
|
||||
material.texAnimSleep -= dt * material.texAnimFrameRate;
|
||||
if (material.texAnimSleep <= 0)
|
||||
{
|
||||
material.texMulAdd.z = fmodf(material.texMulAdd.z + material.texAnimDirection.x, 1);
|
||||
material.texMulAdd.w = fmodf(material.texMulAdd.w + material.texAnimDirection.y, 1);
|
||||
material.texAnimSleep = 1.0f;
|
||||
|
||||
material.dirty = true; // will trigger constant buffer update!
|
||||
}
|
||||
|
||||
material.engineStencilRef = STENCILREF_DEFAULT;
|
||||
@@ -614,6 +618,8 @@ namespace wiSceneSystem
|
||||
CullableComponent& cullable = *cullables.GetComponent(entity);
|
||||
|
||||
cullable.aabb.createFromHalfWidth(XMFLOAT3(0, 0, 0), XMFLOAT3(0, 0, 0));
|
||||
object.rendertypeMask = 0;
|
||||
object.dynamic = false;
|
||||
|
||||
if (object.meshID != INVALID_ENTITY)
|
||||
{
|
||||
@@ -623,6 +629,33 @@ namespace wiSceneSystem
|
||||
if (mesh != nullptr && transform != nullptr)
|
||||
{
|
||||
cullable.aabb = mesh->aabb.get(transform->world);
|
||||
|
||||
if (mesh->IsSkinned() || mesh->IsDynamicVB())
|
||||
{
|
||||
object.dynamic = true;
|
||||
}
|
||||
|
||||
for (auto& subset : mesh->subsets)
|
||||
{
|
||||
const MaterialComponent* material = materials.GetComponent(subset.materialID);
|
||||
|
||||
if (material != nullptr)
|
||||
{
|
||||
if (material->IsTransparent())
|
||||
{
|
||||
object.rendertypeMask |= RENDERTYPE_TRANSPARENT;
|
||||
}
|
||||
else
|
||||
{
|
||||
object.rendertypeMask |= RENDERTYPE_OPAQUE;
|
||||
}
|
||||
|
||||
if (material->IsWater())
|
||||
{
|
||||
object.rendertypeMask |= RENDERTYPE_TRANSPARENT | RENDERTYPE_WATER;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace wiSceneSystem
|
||||
|
||||
struct MaterialComponent
|
||||
{
|
||||
bool dirty = true;
|
||||
bool dirty = true; // can trigger constant buffer update
|
||||
|
||||
STENCILREF engineStencilRef = STENCILREF_DEFAULT;
|
||||
uint8_t userStencilRef = 0;
|
||||
@@ -124,11 +124,25 @@ namespace wiSceneSystem
|
||||
wiGraphicsTypes::Texture2D* GetSurfaceMap() const;
|
||||
wiGraphicsTypes::Texture2D* GetDisplacementMap() const;
|
||||
|
||||
inline bool IsTransparent() const { return baseColor.w < 1.0f; }
|
||||
inline float GetOpacity() const { return baseColor.w; }
|
||||
|
||||
inline bool IsTransparent() const { return GetOpacity() < 1.0f; }
|
||||
inline bool IsWater() const { return water; }
|
||||
inline bool HasPlanarReflection() const { return planar_reflections || IsWater(); }
|
||||
inline bool IsCastingShadow() const { return cast_shadow; }
|
||||
inline bool IsAlphaTestEnabled() const { return alphaRef <= 1.0f - 1.0f / 256.0f; }
|
||||
|
||||
inline void SetBaseColor(const XMFLOAT4& value) { dirty = true; baseColor = value; }
|
||||
inline void SetRoughness(float value) { dirty = true; roughness = value; }
|
||||
inline void SetReflectance(float value) { dirty = true; reflectance = value; }
|
||||
inline void SetMetalness(float value) { dirty = true; metalness = value; }
|
||||
inline void SetEmissive(float value) { dirty = true; emissive = value; }
|
||||
inline void SetRefractionIndex(float value) { dirty = true; refractionIndex = value; }
|
||||
inline void SetSubsurfaceScattering(float value) { dirty = true; subsurfaceScattering = value; }
|
||||
inline void SetNormalMapStrength(float value) { dirty = true; normalMapStrength = value; }
|
||||
inline void SetParallaxOcclusionMapping(float value) { dirty = true; parallaxOcclusionMapping = value; }
|
||||
inline void SetOpacity(float value) { dirty = true; baseColor.w = value; }
|
||||
inline void SetAlphaRef(float value) { alphaRef = value; }
|
||||
};
|
||||
|
||||
struct MeshComponent
|
||||
@@ -282,6 +296,7 @@ namespace wiSceneSystem
|
||||
wiGraphicsTypes::GPUBuffer* streamoutBuffer_PRE = nullptr;
|
||||
|
||||
// Dynamic vertexbuffers write into a global pool, these will be the offsets into that:
|
||||
bool dynamicVB = false;
|
||||
UINT bufferOffset_POS;
|
||||
UINT bufferOffset_PRE;
|
||||
|
||||
@@ -308,8 +323,9 @@ namespace wiSceneSystem
|
||||
|
||||
bool HasImpostor() const { return impostorTarget.IsInitialized(); }
|
||||
inline float GetTessellationFactor() const { return tessellationFactor; }
|
||||
inline wiGraphicsTypes::INDEXBUFFER_FORMAT GetIndexFormat() { return indexFormat; }
|
||||
inline bool IsSkinned() { return armatureID != wiECS::INVALID_ENTITY; }
|
||||
inline wiGraphicsTypes::INDEXBUFFER_FORMAT GetIndexFormat() const { return indexFormat; }
|
||||
inline bool IsSkinned() const { return armatureID != wiECS::INVALID_ENTITY; }
|
||||
inline bool IsDynamicVB() const { return dynamicVB; }
|
||||
|
||||
void CreateRenderData();
|
||||
};
|
||||
@@ -323,9 +339,12 @@ namespace wiSceneSystem
|
||||
{
|
||||
wiECS::Entity meshID = wiECS::INVALID_ENTITY;
|
||||
bool renderable = true;
|
||||
bool dynamic = false;
|
||||
int cascadeMask = 0; // which shadow cascades to skip (0: skip none, 1: skip first, etc...)
|
||||
XMFLOAT4 color = XMFLOAT4(1, 1, 1, 1);
|
||||
|
||||
uint32_t rendertypeMask = 0;
|
||||
|
||||
// occlusion result history bitfield (32 bit->32 frame history)
|
||||
uint32_t occlusionHistory = ~0;
|
||||
// occlusion query pool index
|
||||
@@ -339,7 +358,9 @@ namespace wiSceneSystem
|
||||
// If it pops up for a frame after occluded, it is visible again for some frames
|
||||
return ((occlusionQueryID >= 0) && (occlusionHistory & 0xFFFFFFFF) == 0);
|
||||
}
|
||||
inline bool IsDynamic() const { return dynamic; }
|
||||
inline float GetTransparency() const { return 1 - color.w; }
|
||||
inline uint32_t GetRenderTypes() const { return rendertypeMask; }
|
||||
};
|
||||
|
||||
struct PhysicsComponent
|
||||
|
||||
Reference in New Issue
Block a user