diff options
| author | Bryan Galdrikian <[email protected]> | 2017-08-23 11:24:32 -0700 |
|---|---|---|
| committer | Bryan Galdrikian <[email protected]> | 2017-08-23 11:24:32 -0700 |
| commit | f1e539cadfb085cedc32f9773cfb9d14bfcdf138 (patch) | |
| tree | 7ca74e06a4386dd22fd850a8417a31a85d282a30 /tools/ArtistTools/source/BlastPlugin/SampleBase/renderer | |
| parent | Updated to CL 22661993: (diff) | |
| download | blast-f1e539cadfb085cedc32f9773cfb9d14bfcdf138.tar.xz blast-f1e539cadfb085cedc32f9773cfb9d14bfcdf138.zip | |
Removing ArtistTools and CurveEditor projects
Diffstat (limited to 'tools/ArtistTools/source/BlastPlugin/SampleBase/renderer')
25 files changed, 0 insertions, 5028 deletions
diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ConvexRenderMesh.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ConvexRenderMesh.cpp deleted file mode 100644 index dc938b9..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ConvexRenderMesh.cpp +++ /dev/null @@ -1,100 +0,0 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. - - -#include "ConvexRenderMesh.h" -#include "Renderer.h" -#include "PxConvexMesh.h" - - -struct Vertex -{ - PxVec3 position; - PxVec3 normal; -}; - -ConvexRenderMesh::ConvexRenderMesh(const PxConvexMesh* mesh) -{ - const uint32_t nbPolygons = mesh->getNbPolygons(); - const uint8_t* indexBuffer = mesh->getIndexBuffer(); - const PxVec3* meshVertices = mesh->getVertices(); - - uint32_t nbVerts = 0; - uint32_t nbFaces = 0; - - for (uint32_t i = 0; i < nbPolygons; i++) - { - PxHullPolygon data; - mesh->getPolygonData(i, data); - uint32_t nbPolyVerts = data.mNbVerts; - nbVerts += nbPolyVerts; - nbFaces += (nbPolyVerts - 2) * 3; - } - - std::vector<Vertex> vertices; - std::vector<uint16_t> faces; - - vertices.resize(nbVerts); - faces.resize(nbFaces); - - uint32_t vertCounter = 0; - uint32_t facesCounter = 0; - for (uint32_t i = 0; i < nbPolygons; i++) - { - PxHullPolygon data; - mesh->getPolygonData(i, data); - - PxVec3 normal(data.mPlane[0], data.mPlane[1], data.mPlane[2]); - - uint32_t vI0 = vertCounter; - for (uint32_t vI = 0; vI < data.mNbVerts; vI++) - { - vertices[vertCounter].position = meshVertices[indexBuffer[data.mIndexBase + vI]]; - vertices[vertCounter].normal = normal; - vertCounter++; - } - - for (uint32_t vI = 1; vI < uint32_t(data.mNbVerts) - 1; vI++) - { - faces[facesCounter++] = uint16_t(vI0); - faces[facesCounter++] = uint16_t(vI0 + vI + 1); - faces[facesCounter++] = uint16_t(vI0 + vI); - } - } - - std::vector<D3D11_INPUT_ELEMENT_DESC> layout; - layout.push_back({ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }); - layout.push_back({ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }); - - initialize(vertices.data(), (uint32_t)vertices.size(), sizeof(Vertex), layout, faces.data(), nbFaces); -} - - -ConvexRenderMesh::~ConvexRenderMesh() -{ -} - diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ConvexRenderMesh.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ConvexRenderMesh.h deleted file mode 100644 index f7bc5c6..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ConvexRenderMesh.h +++ /dev/null @@ -1,52 +0,0 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. - - -#ifndef CONVEX_RENDER_MESH_H -#define CONVEX_RENDER_MESH_H - -#include "CustomRenderMesh.h" - -namespace physx -{ -class PxConvexMesh; -} - - -/** -PxConvexMesh render mesh -(this class relates to PhysX more then to Renderer) -*/ -class ConvexRenderMesh : public CustomRenderMesh -{ -public: - ConvexRenderMesh(const PxConvexMesh* mesh); - virtual ~ConvexRenderMesh(); -}; - - -#endif //CONVEX_RENDER_MESH_H
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/CustomRenderMesh.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/CustomRenderMesh.cpp deleted file mode 100644 index 0feae3f..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/CustomRenderMesh.cpp +++ /dev/null @@ -1,114 +0,0 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. - - -#include "CustomRenderMesh.h" - - -CustomRenderMesh::CustomRenderMesh() - : m_indexBuffer(nullptr) -{ -} - -CustomRenderMesh::CustomRenderMesh(const void* vertices, uint32_t numVertices, uint32_t vertexSize, std::vector<D3D11_INPUT_ELEMENT_DESC>& inputDesc, const uint16_t* faces, uint32_t numFaces) - : m_indexBuffer(nullptr) -{ - initialize(vertices, numVertices, vertexSize, inputDesc, faces, numFaces); -} - -void CustomRenderMesh::initialize(const void* vertices, uint32_t numVertices, uint32_t vertexSize, std::vector<D3D11_INPUT_ELEMENT_DESC>& inputDesc, const uint16_t* faces, uint32_t numFaces) -{ - ID3D11Device* device = GetDeviceManager()->GetDevice(); - - m_inputDesc = inputDesc; - m_numVertices = numVertices; - m_vertexSize = vertexSize; - m_numFaces = numFaces; - - // VB - { - D3D11_SUBRESOURCE_DATA vertexBufferData; - - ZeroMemory(&vertexBufferData, sizeof(vertexBufferData)); - vertexBufferData.pSysMem = vertices; - - D3D11_BUFFER_DESC bufferDesc; - - memset(&bufferDesc, 0, sizeof(D3D11_BUFFER_DESC)); - bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; - bufferDesc.ByteWidth = vertexSize * numVertices; - bufferDesc.CPUAccessFlags = 0; - bufferDesc.MiscFlags = 0; - bufferDesc.Usage = D3D11_USAGE_IMMUTABLE; - - V(device->CreateBuffer(&bufferDesc, &vertexBufferData, &m_vertexBuffer)); - } - - // IB - if (faces != nullptr) - { - D3D11_SUBRESOURCE_DATA indexBufferData; - - ZeroMemory(&indexBufferData, sizeof(indexBufferData)); - indexBufferData.pSysMem = faces; - - D3D11_BUFFER_DESC bufferDesc; - - memset(&bufferDesc, 0, sizeof(D3D11_BUFFER_DESC)); - bufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER; - bufferDesc.ByteWidth = sizeof(uint16_t) * numFaces; - bufferDesc.CPUAccessFlags = 0; - bufferDesc.MiscFlags = 0; - bufferDesc.Usage = D3D11_USAGE_IMMUTABLE; - - V(device->CreateBuffer(&bufferDesc, &indexBufferData, &m_indexBuffer)); - } -} - -CustomRenderMesh::~CustomRenderMesh() -{ - SAFE_RELEASE(m_vertexBuffer); - SAFE_RELEASE(m_indexBuffer); -} - - -void CustomRenderMesh::render(ID3D11DeviceContext& context) const -{ - context.IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); - - UINT strides[1] = { m_vertexSize }; - UINT offsets[1] = { 0 }; - context.IASetVertexBuffers(0, 1, &m_vertexBuffer, strides, offsets); - - context.IASetIndexBuffer(m_indexBuffer, DXGI_FORMAT_R16_UINT, 0); - - if (m_indexBuffer) - context.DrawIndexed(m_numFaces, 0, 0); - else - context.Draw(m_numVertices, 0); -} - diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/CustomRenderMesh.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/CustomRenderMesh.h deleted file mode 100644 index 025d3bf..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/CustomRenderMesh.h +++ /dev/null @@ -1,59 +0,0 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. - - -#ifndef CUSTOM_RENDER_MESH_H -#define CUSTOM_RENDER_MESH_H - -#include "Renderable.h" - - -class CustomRenderMesh : public IRenderMesh -{ -public: - const std::vector<D3D11_INPUT_ELEMENT_DESC>& getInputElementDesc() const { return m_inputDesc; } - void render(ID3D11DeviceContext& context) const; - - CustomRenderMesh(const void* vertices, uint32_t numVertices, uint32_t vertexSize, std::vector<D3D11_INPUT_ELEMENT_DESC>& inputDesc, const uint16_t* faces = nullptr, uint32_t numFaces = 0); - virtual ~CustomRenderMesh(); - -protected: - CustomRenderMesh(); - void initialize(const void* vertices, uint32_t numVertices, uint32_t vertexSize, std::vector<D3D11_INPUT_ELEMENT_DESC>& inputDesc, const uint16_t* faces, uint32_t numFaces); - -private: - ID3D11Buffer* m_vertexBuffer; - ID3D11Buffer* m_indexBuffer; - uint32_t m_numFaces; - uint32_t m_numVertices; - uint32_t m_vertexSize; - - std::vector<D3D11_INPUT_ELEMENT_DESC> m_inputDesc; -}; - - -#endif //CUSTOM_RENDER_MESH_H
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/DebugRenderBuffer.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/DebugRenderBuffer.h deleted file mode 100644 index 06cd509..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/DebugRenderBuffer.h +++ /dev/null @@ -1,68 +0,0 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. - - -#ifndef DEBUGRENDERBUFFER_H -#define DEBUGRENDERBUFFER_H - -#include "PxRenderBuffer.h" -#include <vector> - -using namespace physx; - - -/** -Simple PxRenderBuffer implementation for easy debug primitives adding -*/ -class DebugRenderBuffer : public PxRenderBuffer -{ -public: - ~DebugRenderBuffer() {} - - virtual PxU32 getNbPoints() const { return 0; } - virtual const PxDebugPoint* getPoints() const { return nullptr; } - - virtual PxU32 getNbLines() const { return static_cast<PxU32>(m_lines.size()); } - virtual const PxDebugLine* getLines() const { return m_lines.data(); } - - virtual PxU32 getNbTriangles() const { return 0; } - virtual const PxDebugTriangle* getTriangles() const { return nullptr; } - - virtual PxU32 getNbTexts() const { return 0; } - virtual const PxDebugText* getTexts() const { return nullptr; } - - virtual void append(const PxRenderBuffer& other) {} - virtual void clear() - { - m_lines.clear(); - } - - std::vector<PxDebugLine> m_lines; -}; - - -#endif //DEBUGRENDERBUFFER_H
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Mesh.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Mesh.cpp deleted file mode 100644 index c6c8398..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Mesh.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. - - -#include "Mesh.h" - diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Mesh.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Mesh.h deleted file mode 100644 index 3ef7090..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Mesh.h +++ /dev/null @@ -1,74 +0,0 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. - - -#ifndef MESH_H -#define MESH_H - -#include <vector> -#include "PxVec2.h" -#include "PxVec3.h" - -// Add By Lixu Begin -class MeshBase -// Add By Lixu End -{ - virtual uint32_t getVertexStride() = 0; - // ... TBD -}; - -/** -SimpleMesh: position + normal + uv -We use only this type everywhere, once other versions will be required we should generalize Mesh and refactor code. -*/ -// Add By Lixu Begin -class SimpleMesh : public MeshBase -// Add By Lixu End -{ -public: - - class Vertex - { - public: - physx::PxVec3 position; - physx::PxVec3 normal; - physx::PxVec3 facenormal; - physx::PxVec3 tangent; - physx::PxVec2 uv; - }; - - virtual uint32_t getVertexStride() { return sizeof(Vertex); } - - std::vector<Vertex> vertices; - std::vector<uint16_t> indices; - - physx::PxVec3 extents; - physx::PxVec3 center; -}; - - -#endif //MESH_H
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/PrimitiveRenderMesh.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/PrimitiveRenderMesh.cpp deleted file mode 100644 index bcb1580..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/PrimitiveRenderMesh.cpp +++ /dev/null @@ -1,301 +0,0 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. - - -#include "PrimitiveRenderMesh.h" -#include "Renderer.h" - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Base Mesh internal class -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -PrimitiveRenderMesh::PrimitiveRenderMesh(const float v[], UINT numVertices) -{ - std::vector<D3D11_INPUT_ELEMENT_DESC> layout; - layout.push_back({ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }); - layout.push_back({ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }); - - initialize(v, numVertices, sizeof(float) * 6, layout, nullptr, 0); -} - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Box Mesh -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -const float boxVertices[] = -{ - -1.0f, -1.0f, -1.0f, 0.0f, 0.0f, -1.0f, - 1.0f, -1.0f, -1.0f, 0.0f, 0.0f, -1.0f, - 1.0f, 1.0f, -1.0f, 0.0f, 0.0f, -1.0f, - 1.0f, 1.0f, -1.0f, 0.0f, 0.0f, -1.0f, - -1.0f, 1.0f, -1.0f, 0.0f, 0.0f, -1.0f, - -1.0f, -1.0f, -1.0f, 0.0f, 0.0f, -1.0f, - - -1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, - 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, - 1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, - 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, - -1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, - -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, - - -1.0f, 1.0f, 1.0f, -1.0f, 0.0f, 0.0f, - -1.0f, -1.0f, -1.0f, -1.0f, 0.0f, 0.0f, - -1.0f, 1.0f, -1.0f, -1.0f, 0.0f, 0.0f, - -1.0f, -1.0f, -1.0f, -1.0f, 0.0f, 0.0f, - -1.0f, 1.0f, 1.0f, -1.0f, 0.0f, 0.0f, - -1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 0.0f, - - 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, - 1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f, - 1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 0.0f, - 1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 0.0f, - 1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, - 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, - - -1.0f, -1.0f, -1.0f, 0.0f, -1.0f, 0.0f, - 1.0f, -1.0f, 1.0f, 0.0f, -1.0f, 0.0f, - 1.0f, -1.0f, -1.0f, 0.0f, -1.0f, 0.0f, - 1.0f, -1.0f, 1.0f, 0.0f, -1.0f, 0.0f, - -1.0f, -1.0f, -1.0f, 0.0f, -1.0f, 0.0f, - -1.0f, -1.0f, 1.0f, 0.0f, -1.0f, 0.0f, - - -1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, - 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, - 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, - 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, - -1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, - -1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f -}; - -BoxRenderMesh::BoxRenderMesh() : PrimitiveRenderMesh(boxVertices, sizeof(boxVertices) / (6 * sizeof(boxVertices[0]))) {} - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Plane Mesh -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -const float planeSize = 1.0f; // we use scaling instead -const float planeTilesCount = 1000.0f; - -const float planeVertices[] = -{ - 0, planeSize, planeSize, 1.0f, 0.0f, 0.0f, planeTilesCount, planeTilesCount, - 0, planeSize, -planeSize, 1.0f, 0.0f, 0.0f, planeTilesCount, -planeTilesCount, - 0, -planeSize, -planeSize, 1.0f, 0.0f, 0.0f, -planeTilesCount, -planeTilesCount, - 0, -planeSize, -planeSize, 1.0f, 0.0f, 0.0f, -planeTilesCount, -planeTilesCount, - 0, -planeSize, planeSize, 1.0f, 0.0f, 0.0f, -planeTilesCount, planeTilesCount, - 0, planeSize, planeSize, 1.0f, 0.0f, 0.0f, planeTilesCount, planeTilesCount -}; - -PlaneRenderMesh::PlaneRenderMesh() -{ - std::vector<D3D11_INPUT_ELEMENT_DESC> layout; - layout.push_back({ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }); - layout.push_back({ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }); - layout.push_back({ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 }); - - initialize(planeVertices, sizeof(planeVertices) / (8 * sizeof(planeVertices[0])), sizeof(float) * 8, layout, nullptr, 0); -} - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Sphere Mesh -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - -const uint32_t g_numSlices = 8; // along lines of longitude -const uint32_t g_numStacks = 16; // along lines of latitude - -const uint32_t g_numSphereVertices = (g_numSlices * 2 + 1)*(g_numStacks + 1); -const uint32_t g_numSphereIndices = g_numSlices * 2 * g_numStacks * 6; - -const uint32_t g_numConeVertices = (g_numSlices * 2 + 1) * 2; -const uint32_t g_numConeIndices = g_numSlices * 2 * 6; - -PxVec3 g_spherePositions[g_numSphereVertices]; -uint16_t g_sphereIndices[g_numSphereIndices]; - -void generateSphereMesh(uint16_t slices, uint16_t stacks, PxVec3* positions, uint16_t* indices) -{ - const PxF32 thetaStep = PxPi / stacks; - const PxF32 phiStep = PxTwoPi / (slices * 2); - - PxF32 theta = 0.0f; - - // generate vertices - for (uint16_t y = 0; y <= stacks; ++y) - { - PxF32 phi = 0.0f; - - PxF32 cosTheta = PxCos(theta); - PxF32 sinTheta = PxSin(theta); - - for (uint16_t x = 0; x <= slices * 2; ++x) - { - PxF32 cosPhi = PxCos(phi); - PxF32 sinPhi = PxSin(phi); - - PxVec3 p(cosPhi*sinTheta, cosTheta, sinPhi*sinTheta); - - // write vertex - *(positions++) = p; - - phi += phiStep; - } - - theta += thetaStep; - } - - const uint16_t numRingQuads = 2 * slices; - const uint16_t numRingVerts = 2 * slices + 1; - - // add faces - for (uint16_t y = 0; y < stacks; ++y) - { - for (uint16_t i = 0; i < numRingQuads; ++i) - { - // add a quad - *(indices++) = (y + 0)*numRingVerts + i; - *(indices++) = (y + 1)*numRingVerts + i; - *(indices++) = (y + 1)*numRingVerts + i + 1; - - *(indices++) = (y + 1)*numRingVerts + i + 1; - *(indices++) = (y + 0)*numRingVerts + i + 1; - *(indices++) = (y + 0)*numRingVerts + i; - } - } -} - - -struct SphereVertex -{ - PxVec3 position; - PxVec3 normal; -}; - -SphereRenderMesh::SphereRenderMesh() -{ - generateSphereMesh(g_numSlices, g_numStacks, g_spherePositions, g_sphereIndices); - - std::vector<SphereVertex> vertices; - for (uint32_t i = 0; i < g_numSphereVertices; i++) - { - vertices.push_back({ g_spherePositions[i], g_spherePositions[i] }); - } - - std::vector<D3D11_INPUT_ELEMENT_DESC> layout; - layout.push_back({ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }); - layout.push_back({ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }); - - initialize(vertices.data(), (uint32_t)vertices.size(), sizeof(SphereVertex), layout, g_sphereIndices, g_numSphereIndices); -} - - -SphereRenderMesh::~SphereRenderMesh() -{ -} - -// Add By Lixu Begin -const float coneVertices[] = -{ - 0.0f, 1.0f, 0.0f, -1.0f, 0.0f, 0.0f,//top - -1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 0.0f,//left bottom - -1.0f, -1.0f, -1.0f, -1.0f, 0.0f, 0.0f,//left top - - 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f,//top - 1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 0.0f,//right top - 1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f,//right bottom - - 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, -1.0f,//top - -1.0f, -1.0f, -1.0f, 0.0f, 0.0f, -1.0f,//left top - 1.0f, -1.0f, -1.0f, 0.0f, 0.0f, -1.0f,//right top - - 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f,//top - 1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f,//right bottom - -1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f,//left bottom - - -1.0f, -1.0f, -1.0f, 0.0f, -1.0f, 0.0f,//left top - 1.0f, -1.0f, 1.0f, 0.0f, -1.0f, 0.0f,//right bottom - 1.0f, -1.0f, -1.0f, 0.0f, -1.0f, 0.0f,//right top - - 1.0f, -1.0f, 1.0f, 0.0f, -1.0f, 0.0f,//right bottom - -1.0f, -1.0f, -1.0f, 0.0f, -1.0f, 0.0f,//left top - -1.0f, -1.0f, 1.0f, 0.0f, -1.0f, 0.0f,//left bottom -}; - -ConeRenderMesh::ConeRenderMesh() : PrimitiveRenderMesh(coneVertices, sizeof(coneVertices) / (6 * sizeof(coneVertices[0]))) {} - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// FBX Mesh class -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -#include <AnimUtil.h> -#include <PxVec2.h> -#include <vector> - -struct FBXVertex -{ - PxVec3 position; - PxVec3 normal; - PxVec2 uv; -}; - -FBXRenderMesh::FBXRenderMesh(MeshDesc* pMeshData) -{ - std::vector<D3D11_INPUT_ELEMENT_DESC> layout; - layout.push_back({ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }); - layout.push_back({ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }); - layout.push_back({ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 }); - - std::vector<FBXVertex> vertices; - std::vector<uint16_t> indices; - - for (uint32_t i = 0; i < pMeshData->m_NumVertices; ++i) - { - atcore_float3 pos = pMeshData->m_pVertices[i]; - atcore_float3 vertexNormal = pMeshData->m_pVertexNormals[i]; - atcore_float2 texcoord = pMeshData->m_pTexCoords[i]; - - FBXVertex newVertex; - newVertex.position = physx::PxVec3(pos.x, pos.y, pos.z); - newVertex.normal = physx::PxVec3(vertexNormal.x, vertexNormal.y, vertexNormal.z); - newVertex.uv = physx::PxVec2(texcoord.x, texcoord.y); - - vertices.push_back(newVertex); - } - - for (uint32_t i = 0; i < pMeshData->m_NumTriangles; ++i) - { - indices.push_back(pMeshData->m_pIndices[i * 3 + 0]); - indices.push_back(pMeshData->m_pIndices[i * 3 + 1]); - indices.push_back(pMeshData->m_pIndices[i * 3 + 2]); - } - - initialize(vertices.data(), (uint32_t)vertices.size(), sizeof(FBXVertex), layout, indices.data(), (uint32_t)indices.size()); -} -// Add By Lixu End
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/PrimitiveRenderMesh.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/PrimitiveRenderMesh.h deleted file mode 100644 index 107af25..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/PrimitiveRenderMesh.h +++ /dev/null @@ -1,99 +0,0 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. - - -#ifndef PRIMITIVE_RENDER_MESH_H -#define PRIMITIVE_RENDER_MESH_H - -#include "Utils.h" -#include <DirectXMath.h> - -#include <vector> -#include "Renderable.h" -#include "CustomRenderMesh.h" - - -class PrimitiveRenderMesh : public CustomRenderMesh -{ -protected: - PrimitiveRenderMesh(const float v[], UINT numVertices); -}; - -class BoxRenderMesh : public PrimitiveRenderMesh -{ -public: - BoxRenderMesh(); -}; - - -class PlaneRenderMesh : public CustomRenderMesh -{ -public: - PlaneRenderMesh(); -}; - - -class SphereRenderMesh : public CustomRenderMesh -{ -public: - SphereRenderMesh(); - virtual ~SphereRenderMesh(); -}; - - -// Add By Lixu Begin -class ConeRenderMesh : public PrimitiveRenderMesh -{ -public: - ConeRenderMesh(); -}; - -class MeshDesc; - -class FBXRenderMesh : public CustomRenderMesh -{ -public: - FBXRenderMesh(MeshDesc* pMeshData); -}; -// Add By Lixu End - - -struct PrimitiveRenderMeshType -{ - enum Enum - { - Box, - Plane, - Sphere, -// Add By Lixu Begin - Cone, -// Add By Lixu End - Count - }; -}; - -#endif //PRIMITIVE_RENDER_MESH_H
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RenderMaterial.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RenderMaterial.cpp deleted file mode 100644 index 88533cb..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RenderMaterial.cpp +++ /dev/null @@ -1,353 +0,0 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. - - -#include "RenderMaterial.h" -#include <DirectXMath.h> -#include "ShaderUtils.h" -#include "Renderer.h" -#include "SampleManager.h" -#include "Light.h" -#include "D3D11TextureResource.h" -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// RenderMaterial -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -RenderMaterial::RenderMaterial(const char* materialName, ResourceManager& resourceCallback, const char* shaderFileName, - const char* textureFileName, BlendMode blendMode) -{ - mMaterialName = materialName; - setDiffuseColor(0.5, 0.5, 0.5, 1.0); - mTextureFileNames[TT_Diffuse] = textureFileName; - - this->initialize(resourceCallback, shaderFileName, textureFileName, blendMode); -} - -RenderMaterial::RenderMaterial(const char* materialName, ResourceManager& resourceCallback, const char* shaderFileName, float r, float g, float b, float a, BlendMode blendMode) -{ - mMaterialName = materialName; - setDiffuseColor(r, g, b, a); - this->initialize(resourceCallback, shaderFileName, "", blendMode); -} - -void RenderMaterial::initialize(ResourceManager& resourceCallback, const char* shaderFileName, const char* textureFileName, BlendMode blendMode) -{ - std::vector<std::string> v; - v.push_back(shaderFileName); - initialize(resourceCallback, v, textureFileName, blendMode); -} - -void RenderMaterial::initialize(ResourceManager& resourceCallback, std::vector<std::string> shaderFileNames, const char* textureFileName, BlendMode blendMode) -{ - for (int i = 0; i < TT_Num; i++) - { - m_TextureSRVs[i] = nullptr; - mTextureResources[i] = nullptr; - } - mBlendState = nullptr; - - memset(mSpecularColor, 0, sizeof(float) * 4); - mSpecularShininess = 20; - - for (uint32_t i = 0; i < shaderFileNames.size(); i++) - { - const ShaderFileResource* resource = resourceCallback.requestShaderFile(shaderFileNames[i].c_str()); - if (resource) - { - std::string shaderFilePath = resource->path; - mShaderFilePathes.push_back(shaderFilePath); - } - } - mShaderGroups.reserve(mShaderFilePathes.size()); - - if (!mTextureFileNames[TT_Diffuse].empty()) - { - mTextureResources[TT_Diffuse] = resourceCallback.requestTexture(mTextureFileNames[TT_Diffuse].c_str()); - } - - setBlending(blendMode); - - reload(); -} - -void RenderMaterial::releaseReloadableResources() -{ - for (std::vector<ShaderGroup*>::iterator it = mShaderGroups.begin(); it != mShaderGroups.end(); it++) - { - delete *it; - } - mShaderGroups.clear(); - -// Add By Lixu Begin - for (std::map<const IRenderMesh*, Instance*>::iterator it = mRenderMeshToInstanceMap.begin(); - it != mRenderMeshToInstanceMap.end(); it++) - { - delete it->second; - } - mRenderMeshToInstanceMap.clear(); -// Add By Lixu End - - for (int i = 0; i < TT_Num; i++) - { - SAFE_RELEASE(m_TextureSRVs[i]); - } -} - -RenderMaterial::~RenderMaterial() -{ - releaseReloadableResources(); - SAFE_RELEASE(mBlendState); -} - -void RenderMaterial::setBlending(BlendMode blendMode) -{ - mBlendMode = blendMode; - - SAFE_RELEASE(mBlendState); - - D3D11_BLEND_DESC desc; - ZeroMemory(&desc, sizeof(desc)); - - switch (blendMode) - { - case BLEND_NONE: - desc.RenderTarget[0].BlendEnable = FALSE; - desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; - break; - case BLEND_ALPHA_BLENDING: - desc.AlphaToCoverageEnable = FALSE; - desc.IndependentBlendEnable = TRUE; - desc.RenderTarget[0].BlendEnable = TRUE; - desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; - desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; - desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; - desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; - desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA; - desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA; - desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; - break; - case BLEND_ADDITIVE: // actually, is's additive by alpha - desc.AlphaToCoverageEnable = FALSE; - desc.IndependentBlendEnable = TRUE; - desc.RenderTarget[0].BlendEnable = TRUE; - desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; - desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; - desc.RenderTarget[0].DestBlend = D3D11_BLEND_ONE; - desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE; - desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA; - desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA; - desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; - break; - default: - PX_ALWAYS_ASSERT_MESSAGE("Unknown blend mode"); - } - - ID3D11Device* device = GetDeviceManager()->GetDevice(); - V(device->CreateBlendState(&desc, &mBlendState)); -} - -void RenderMaterial::reload() -{ - releaseReloadableResources(); - - // load shaders - ID3D11Device* device = GetDeviceManager()->GetDevice(); - - for (std::vector<std::string>::iterator it = mShaderFilePathes.begin(); it != mShaderFilePathes.end(); it++) - { - const char* shaderFilePath = (*it).c_str(); - ShaderGroup* shaderGroup = new ShaderGroup(); - V(createShaderFromFile(device, shaderFilePath, "VS", &(shaderGroup->vs), shaderGroup->buffer)); - createShaderFromFile(device, shaderFilePath, "PS", &shaderGroup->ps); - createShaderFromFile(device, shaderFilePath, "GS", &shaderGroup->gs); - mShaderGroups.push_back(shaderGroup); - } - - // load texture - for (int i = 0; i < TT_Num; i++) - { - if (mTextureResources[i]) - { - V(DirectX::CreateShaderResourceView(device, - mTextureResources[i]->image.GetImages(), - mTextureResources[i]->image.GetImageCount(), - mTextureResources[i]->metaData, &m_TextureSRVs[i])); - } - } -} - - - -RenderMaterial::InstancePtr RenderMaterial::getMaterialInstance(const IRenderMesh* mesh) -{ - // look in cache - auto it = mRenderMeshToInstanceMap.find(mesh); - if (it != mRenderMeshToInstanceMap.end()) - { -// Add By Lixu Begin - /* - if (!(*it).second.expired()) - { - return (*it).second.lock(); - } - */ - return it->second; -// Add By Lixu End - } - - // create new - const std::vector<D3D11_INPUT_ELEMENT_DESC>& descs = mesh->getInputElementDesc(); - RenderMaterial::InstancePtr instance = getMaterialInstance(&descs[0], (uint32_t)descs.size()); - mRenderMeshToInstanceMap[mesh] = instance; - return instance; -} - -RenderMaterial::InstancePtr RenderMaterial::getMaterialInstance(const D3D11_INPUT_ELEMENT_DESC* elementDescs, uint32_t numElements) -{ - ID3D11Device* device = GetDeviceManager()->GetDevice(); - - for (uint32_t i = 0; i < mShaderGroups.size(); i++) - { - if (mShaderGroups[i]->buffer == NULL) - continue; - - ID3D11InputLayout* inputLayout = NULL; - device->CreateInputLayout(elementDescs, numElements, mShaderGroups[i]->buffer->GetBufferPointer(), mShaderGroups[i]->buffer->GetBufferSize(), &inputLayout); - - if (inputLayout) - { - RenderMaterial::InstancePtr materialInstance(new Instance(*this, inputLayout, i)); - return materialInstance; - } - } - PX_ALWAYS_ASSERT(); - return NULL; -} - -void RenderMaterial::Instance::bind(ID3D11DeviceContext& context, uint32_t slot, bool depthStencilOnly) -{ - mMaterial.mShaderGroups[mShaderNum]->Set(&context, !depthStencilOnly); - - GPUShaderResource* pResource = Light::GetEnvTextureSRV(); - ID3D11ShaderResourceView* pEnvTextureSRV = D3D11TextureResource::GetResource(pResource); - - context.OMSetBlendState(mMaterial.mBlendState, nullptr, 0xFFFFFFFF); - context.PSSetShaderResources(slot, TT_Num, mMaterial.m_TextureSRVs); - context.PSSetShaderResources(TT_Num, 1, &pEnvTextureSRV); - context.IASetInputLayout(mInputLayout); -} - -bool RenderMaterial::Instance::isValid() -{ - return mMaterial.mShaderGroups.size() > 0 && mMaterial.mShaderGroups[mShaderNum]->IsValid(); -} - -// Add By Lixu Begin -void RenderMaterial::setTextureFileName(std::string textureFileName, TextureType tt) -{ - if (mTextureFileNames[tt] == textureFileName) - { - return; - } - mTextureFileNames[tt] = textureFileName; - - mTextureResources[tt] = nullptr; - SAFE_RELEASE(m_TextureSRVs[tt]); - - if (mTextureFileNames[tt].empty()) - { - return; - } - - std::string searchDir = mTextureFileNames[tt]; - size_t ind = searchDir.find_last_of('/'); - if (ind > 0 && (ind != std::string::npos)) - searchDir = searchDir.substr(0, ind); - - ResourceManager* pResourceManager = ResourceManager::ins(); - pResourceManager->addSearchDir(searchDir.c_str()); - mTextureResources[tt] = pResourceManager->requestTexture(mTextureFileNames[tt].c_str()); - if (mTextureResources[tt] == nullptr) - { - return; - } - - ID3D11Device* device = GetDeviceManager()->GetDevice(); - DirectX::CreateShaderResourceView(device, - mTextureResources[tt]->image.GetImages(), - mTextureResources[tt]->image.GetImageCount(), - mTextureResources[tt]->metaData, &m_TextureSRVs[tt]); -} - -void RenderMaterial::setDiffuseColor(float r, float g, float b, float a) -{ - mDiffuseColor[0] = r; - mDiffuseColor[1] = g; - mDiffuseColor[2] = b; - mDiffuseColor[3] = a; -} - -void RenderMaterial::getDiffuseColor(float& r, float& g, float& b, float& a) -{ - r = mDiffuseColor[0]; - g = mDiffuseColor[1]; - b = mDiffuseColor[2]; - a = mDiffuseColor[3]; -} - -void RenderMaterial::setSpecularColor(float r, float g, float b, float a) -{ - mSpecularColor[0] = r; - mSpecularColor[1] = g; - mSpecularColor[2] = b; - mSpecularColor[3] = a; -} - -void RenderMaterial::getSpecularColor(float& r, float& g, float& b, float& a) -{ - r = mSpecularColor[0]; - g = mSpecularColor[1]; - b = mSpecularColor[2]; - a = mSpecularColor[3]; -} - -RenderMaterial* g_DefaultRenderMaterial = nullptr; -RenderMaterial* RenderMaterial::getDefaultRenderMaterial() -{ - if (g_DefaultRenderMaterial == nullptr) - { - ResourceManager* pResourceManager = ResourceManager::ins(); - g_DefaultRenderMaterial = new RenderMaterial("", *pResourceManager, "model_simple_textured_ex", 0.5, 0.5, 0.5); - } - return g_DefaultRenderMaterial; -} - -bool RenderMaterial::isBadTexture(TextureType tt) -{ - return (nullptr == m_TextureSRVs[tt]); -} -// Add By Lixu End
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RenderMaterial.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RenderMaterial.h deleted file mode 100644 index 27f0672..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RenderMaterial.h +++ /dev/null @@ -1,178 +0,0 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. - - -#ifndef RENDER_MATERIAL_H -#define RENDER_MATERIAL_H - -#include "Utils.h" -#include "DirectXTex.h" - -#include <string> -#include <vector> -#include <list> -#include <map> -#include <memory> - - -class IRenderMesh; -class ResourceManager; -struct TextureResource; -class Renderable; - - -class RenderMaterial -{ - public: - - enum BlendMode - { - BLEND_NONE, - BLEND_ALPHA_BLENDING, - BLEND_ADDITIVE - }; - - enum TextureType - { - TT_Diffuse, - TT_Specular, - TT_Normal, - TT_Num - }; - - RenderMaterial(const char* materialName, ResourceManager& resourceProvider, const char* shaderFileName, const char* textureFileName = "", BlendMode blendMode = BLEND_NONE); - RenderMaterial(const char* materialName, ResourceManager& resourceProvider, const char* shaderFileName, float r, float g, float b, float a = 1.0, BlendMode blendMode = BLEND_NONE); - ~RenderMaterial(); - - void setBlending(BlendMode blendMode); - BlendMode getBlending() const { return mBlendMode; } - - void reload(); - - class Instance - { - public: - Instance(RenderMaterial& material, ID3D11InputLayout* inputLayout, uint32_t shaderNum = 0) : mMaterial(material), mInputLayout(inputLayout), mShaderNum(shaderNum) {} - ~Instance() { SAFE_RELEASE(mInputLayout); } - - bool isValid(); - void bind(ID3D11DeviceContext& context, uint32_t slot, bool depthStencilOnly = false); - RenderMaterial& getMaterial() const { return mMaterial; } - private: - RenderMaterial& mMaterial; - ID3D11InputLayout* mInputLayout; - uint32_t mShaderNum; - }; - -// Add By Lixu Begin - typedef Instance* InstancePtr; - std::string getMaterialName(){ return mMaterialName; } - void setMaterialName(std::string materialName){ mMaterialName = materialName; } - std::string getTextureFileName(TextureType tt = TT_Diffuse){ return mTextureFileNames[tt]; } - void setTextureFileName(std::string textureFileName, TextureType tt = TT_Diffuse); - void getDiffuseColor(float& r, float& g, float& b, float& a); - void setDiffuseColor(float r, float g, float b, float a = 1.0); - void getSpecularColor(float& r, float& g, float& b, float& a); - void setSpecularColor(float r, float g, float b, float a = 1.0); - float getSpecularShininess() { return mSpecularShininess; } - void setSpecularShininess(float specularShininess) { mSpecularShininess = specularShininess; } - void addRelatedRenderable(Renderable* pRenderable){ mRelatedRenderables.push_back(pRenderable); } - std::vector<Renderable*>& getRelatedRenderables(){ return mRelatedRenderables; } - void clearRelatedRenderables(){ mRelatedRenderables.clear(); } - bool isBadTexture(TextureType tt = TT_Diffuse); - static RenderMaterial* getDefaultRenderMaterial(); -// Add By Lixu End - - InstancePtr getMaterialInstance(const IRenderMesh* mesh); - InstancePtr getMaterialInstance(const D3D11_INPUT_ELEMENT_DESC* elementDescs, uint32_t numElements); - - private: - void initialize(ResourceManager& resourceCallback, const char* shaderFileName, const char* textureFileName, BlendMode blendMode); - void initialize(ResourceManager&resourceProvider, std::vector<std::string> shaderFileNames, const char* textureFileName, BlendMode blendMode); - - void releaseReloadableResources(); - - std::string mMaterialName; - std::string mShaderFileName; -// std::string mTextureFileName; - - struct ShaderGroup - { - ShaderGroup() : vs(nullptr), gs(nullptr), ps(nullptr), buffer(nullptr) - { - } - ~ShaderGroup() - { - Release(); - } - void Release() - { - SAFE_RELEASE(vs); - SAFE_RELEASE(gs); - SAFE_RELEASE(ps); - SAFE_RELEASE(buffer); - } - void Set(ID3D11DeviceContext* c, bool setPixelShader = true) - { - c->VSSetShader(vs, nullptr, 0); - c->GSSetShader(gs, nullptr, 0); - c->PSSetShader(setPixelShader ? ps : nullptr, nullptr, 0); - } - bool IsValid() - { - return vs != nullptr; - } - ID3D11VertexShader* vs; - ID3D11GeometryShader* gs; - ID3D11PixelShader* ps; - ID3DBlob* buffer; - }; - -// Add By Lixu Begin - std::map<const IRenderMesh*, Instance*> mRenderMeshToInstanceMap; - std::vector<Renderable*> mRelatedRenderables; -// float mr; -// float mg; -// float mb; -// float ma; -// Add By Lixu End -// const TextureResource* mTexture; -// ID3D11ShaderResourceView* mTextureSRV; - std::vector<std::string> mShaderFilePathes; - std::vector<ShaderGroup*> mShaderGroups; - ID3D11BlendState* mBlendState; - BlendMode mBlendMode; - - std::string mTextureFileNames[TT_Num]; - const TextureResource* mTextureResources[TT_Num]; - ID3D11ShaderResourceView* m_TextureSRVs[TT_Num]; - float mDiffuseColor[4]; - float mSpecularColor[4]; - float mSpecularShininess; -}; - -#endif
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RenderUtils.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RenderUtils.h deleted file mode 100644 index 098f7a9..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RenderUtils.h +++ /dev/null @@ -1,119 +0,0 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. - - -#ifndef RENDER_UTILS_H -#define RENDER_UTILS_H - -#include "DirectXTex.h" -#include <DirectXMath.h> -#include "PxMat44.h" -#include "PxVec3.h" -#include "PxVec4.h" - -static DirectX::XMFLOAT4 getRandomPastelColor() -{ - float r = ((double)rand() / (RAND_MAX)) * 0.5f + 0.5f; - float g = ((double)rand() / (RAND_MAX)) * 0.5f + 0.5f; - float b = ((double)rand() / (RAND_MAX)) * 0.5f + 0.5f; - return DirectX::XMFLOAT4(r, g, b, 1.0f); -} - -static physx::PxMat44 XMMATRIXToPxMat44(const DirectX::XMMATRIX& mat) -{ - physx::PxMat44 m; - memcpy(const_cast<float*>(m.front()), &mat.r[0], 4 * 4 * sizeof(float)); - return m; -} - -static DirectX::XMMATRIX PxMat44ToXMMATRIX(const physx::PxMat44& mat) -{ - return DirectX::XMMATRIX(mat.front()); -} - -static physx::PxVec4 XMVECTORToPxVec4(const DirectX::XMVECTOR& vec) -{ - DirectX::XMFLOAT4 f; - DirectX::XMStoreFloat4(&f, vec); - return physx::PxVec4(f.x, f.y, f.z, f.w); -} - -static physx::PxVec3 XMFLOAT3ToPxVec3(const DirectX::XMFLOAT3& vec) -{ - return physx::PxVec3(vec.x, vec.y, vec.z); -} - -static physx::PxVec4 XMFLOAT4ToPxVec4(const DirectX::XMFLOAT4& vec) -{ - return physx::PxVec4(vec.x, vec.y, vec.z, vec.w); -} - -static uint32_t XMFLOAT4ToU32Color(const DirectX::XMFLOAT4& color) -{ - uint32_t c = 0; - c |= (int)(color.w * 255); c <<= 8; - c |= (int)(color.z * 255); c <<= 8; - c |= (int)(color.y * 255); c <<= 8; - c |= (int)(color.x * 255); - return c; -} - -static DirectX::XMFLOAT4 XMFLOAT4Lerp(const DirectX::XMFLOAT4 v0, const DirectX::XMFLOAT4 v1, float val) -{ - DirectX::XMFLOAT4 v( - v0.x * (1 - val) + v1.x * val, - v0.y * (1 - val) + v1.y * val, - v0.z * (1 - val) + v1.z * val, - v0.w * (1 - val) + v1.w * val - ); - return v; -} - -static const physx::PxVec3 forwardVector = physx::PxVec3(0, 0, 1); -static const physx::PxVec3 upVector = physx::PxVec3(0, 1, 0); -static const physx::PxVec3 rightVector = physx::PxVec3(1, 0, 0); - -PX_INLINE physx::PxQuat quatLookAt(const physx::PxVec3 direction) -{ - float d = direction.dot(forwardVector); - if (physx::PxAbs(d + 1.0f) < 1e-5f) - { - return physx::PxQuat(physx::PxPi, upVector); - } - else if (physx::PxAbs(d - 1.0f) < 1e-5f) - { - return physx::PxQuat(physx::PxIdentity); - } - else - { - float angle = physx::PxAcos(d); - physx::PxVec3 axis = forwardVector.cross(direction).getNormalized(); - return physx::PxQuat(angle, axis); - } -} - -#endif //RENDER_UTILS_H
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderable.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderable.cpp deleted file mode 100644 index b72c3b0..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderable.cpp +++ /dev/null @@ -1,151 +0,0 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. - - -#include "Renderable.h" -#include "Renderer.h" -#include "RenderUtils.h" -#include "GlobalSettings.h" -const DirectX::XMFLOAT4 DEFAULT_COLOR(0.5f, 0.5f, 0.5f, 1.0f); - -Renderable::Renderable(IRenderMesh& mesh, RenderMaterial& material) : m_mesh(mesh), m_scale(1, 1, 1), m_color(DEFAULT_COLOR), m_hidden(false), m_transform(PxIdentity) -// Add By Lixu Begin -, m_selected(false) -, m_depthTest(true) -, m_highlight(false) -// Add By Lixu End -{ - setMaterial(material); -} - -void Renderable::setMaterial(RenderMaterial& material) -{ - material.addRelatedRenderable(this); - m_materialInstance = material.getMaterialInstance(&m_mesh); -} - -void Renderable::render(Renderer& renderer, bool depthStencilOnly) const -{ - if (renderer.bFetchSelection) - { - RenderMaterial::InstancePtr materialInstance = renderer.getSelectionRenderMaterialInstance(); - if (!materialInstance->isValid()) - { - PX_ALWAYS_ASSERT(); - return; - } - - materialInstance->bind(*renderer.m_context, 0); - - // setup object CB - { - D3D11_MAPPED_SUBRESOURCE mappedResource; - renderer.m_context->Map(renderer.m_objectCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); - Renderer::CBObject* objectBuffer = (Renderer::CBObject*)mappedResource.pData; - objectBuffer->worldMatrix = PxMat44ToXMMATRIX(getModelMatrix()); - // use selected to store mUniqueId - objectBuffer->selected = m_mesh.mUniqueId; - renderer.m_context->Unmap(renderer.m_objectCB, 0); - } - - m_mesh.render(*renderer.m_context); - - return; - } - - if (!m_materialInstance->isValid()) - { - PX_ALWAYS_ASSERT(); - return; - } - - m_materialInstance->bind(*renderer.m_context, 0, depthStencilOnly); - - DirectX::XMFLOAT4 diffuseColor = getColor(); - DirectX::XMFLOAT4 specularColor = diffuseColor; - float useDiffuseTexture = -1.0; - float useSpecularTexture = -1.0; - float useNormalTexture = -1.0; - float specularShininess = 1.0; - bool useTexture = GlobalSettings::Inst().m_renderStyle == MESH_RENDER_TEXTURED; - RenderMaterial& renderMaterial = m_materialInstance->getMaterial(); - std::string mName = renderMaterial.getMaterialName(); - if (mName != "") - { - float r, g, b, a; - std::string texName; - - renderMaterial.getDiffuseColor(r, g, b, a); - diffuseColor = DirectX::XMFLOAT4(r, g, b, a); - renderMaterial.getSpecularColor(r, g, b, a); - specularColor = DirectX::XMFLOAT4(r, g, b, a); - - texName = renderMaterial.getTextureFileName(); - if (useTexture && texName != "" && !renderMaterial.isBadTexture()) - { - useDiffuseTexture = 1.0; - } - - texName = renderMaterial.getTextureFileName(RenderMaterial::TT_Specular); - if (useTexture && texName != "" && !renderMaterial.isBadTexture(RenderMaterial::TT_Specular)) - { - useSpecularTexture = 1.0; - } - - texName = renderMaterial.getTextureFileName(RenderMaterial::TT_Normal); - if (useTexture && texName != "" && !renderMaterial.isBadTexture(RenderMaterial::TT_Normal)) - { - useNormalTexture = 1.0; - } - - specularShininess = renderMaterial.getSpecularShininess(); - } - - float selected = -1.0; - if (m_selected || m_highlight) - { - selected = 1.0; - } - - // setup object CB - { - D3D11_MAPPED_SUBRESOURCE mappedResource; - renderer.m_context->Map(renderer.m_objectCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); - Renderer::CBObject* objectBuffer = (Renderer::CBObject*)mappedResource.pData; - objectBuffer->worldMatrix = PxMat44ToXMMATRIX(getModelMatrix()); - objectBuffer->diffuseColor = diffuseColor; - objectBuffer->specularColor = specularColor; - objectBuffer->useDiffuseTexture = useDiffuseTexture; - objectBuffer->useSpecularTexture = useSpecularTexture; - objectBuffer->useNormalTexture = useNormalTexture; - objectBuffer->specularShininess = specularShininess; - objectBuffer->selected = selected; - renderer.m_context->Unmap(renderer.m_objectCB, 0); - } - - m_mesh.render(*renderer.m_context); -} diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderable.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderable.h deleted file mode 100644 index 129b8f2..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderable.h +++ /dev/null @@ -1,204 +0,0 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. - - -#ifndef RENDERABLE_H -#define RENDERABLE_H - -#include "RenderMaterial.h" -#include <DirectXMath.h> -#include "PxMat44.h" -#include "PxVec3.h" -#include "PxVec4.h" - -using namespace physx; - -class Renderer; - -/** -RenderMesh interface, used by Renderable -*/ -class IRenderMesh -{ -public: - virtual ~IRenderMesh() {} - virtual const std::vector<D3D11_INPUT_ELEMENT_DESC>& getInputElementDesc() const = 0; - virtual void render(ID3D11DeviceContext& context) const = 0; -// Add By Lixu Begin - virtual void setScale(PxMat44 scale, bool replace) {}; - int mUniqueId; -// Add By Lixu End -}; - -/** -Renderable, represents single object renderer by Renderer. -Basically Renderable = RenderMaterial + RenderMesh -*/ -class Renderable -{ -public: - //////// public API //////// - - // suppose chunk count is less than 10000 - static int getRenderableId(int familyId, int chunkId) - { - int renderableId = familyId * 10000 + chunkId; - return renderableId; - } - static void getFamilyChunkId(int renderableId, int& familyId, int& chunkId) - { - familyId = renderableId / 10000; - chunkId = renderableId % 10000; - } - - void setMaterial(RenderMaterial& material); - - PxMat44 getModelMatrix() const - { - return PxMat44(m_transform) * PxMat44(PxVec4(m_scale, 1)); - } - - void setTransform(PxTransform& transform) - { - m_transform = transform; - } - - const PxTransform& getTransform() const - { - return m_transform; - } - - void setScale(PxVec3 scale) - { - m_scale = scale; - } - - const PxVec3& getScale() const - { - return m_scale; - } - - void setColor(DirectX::XMFLOAT4 color) - { - m_color = color; - } - DirectX::XMFLOAT4 getColor() const - { - return m_color; - } - - void setHidden(bool hidden) - { - m_hidden = hidden; - } - - bool isHidden() const - { - return m_hidden; - } - -// Add By Lixu Begin - void setSelected(bool selected) - { - m_selected = selected; - } - - bool isSelected() const - { - return m_selected; - } - - void setMeshScale(PxMat44 scale, bool replace) - { - m_mesh.setScale(scale, replace); - } - - void setDepthTest(bool depthTest) - { - m_depthTest = depthTest; - } - - bool isDepthTest() const - { - return m_depthTest; - } - - void setHighlight(bool highlight) - { - m_highlight = highlight; - } - - bool isHighlight() const - { - return m_highlight; - } -// Add By Lixu End - - bool isTransparent() const - { - return !(m_materialInstance->getMaterial().getBlending() == RenderMaterial::BLEND_NONE); - } - - RenderMaterial& getMaterial() const { return m_materialInstance->getMaterial(); } - -private: - //////// methods used by Renderer //////// - - friend class Renderer; - - void render(Renderer& renderer) const - { - render(renderer, false); - } - - void renderDepthStencilOnly(Renderer& renderer) const - { - render(renderer, true); - } - - Renderable(IRenderMesh& mesh, RenderMaterial& material); - - void render(Renderer& renderer, bool depthStencilOnly) const; - - - //////// internal data //////// - - DirectX::XMFLOAT4 m_color; - PxTransform m_transform; - PxVec3 m_scale; - - RenderMaterial::InstancePtr m_materialInstance; - IRenderMesh& m_mesh; - bool m_hidden; -// Add By Lixu Begin - bool m_selected; - bool m_depthTest; - bool m_highlight; -// Add By Lixu End -}; - -#endif //RENDERABLE_H
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderer.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderer.cpp deleted file mode 100644 index 05941df..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderer.cpp +++ /dev/null @@ -1,1245 +0,0 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. - - -#include "Renderer.h" -#include "RenderUtils.h" -#include "UIHelpers.h" -#include "SampleProfiler.h" - -#include "PxRenderBuffer.h" - -#include <set> -#include "SimpleScene.h" -#include "GlobalSettings.h" -#include "Light.h" -#include "AppMainWindow.h" -#include "PxVec2.h" - - -const float CAMERA_CLIP_NEAR = 1.0f; -const float CAMERA_CLIP_FAR = 1000.00f; - -const float CLEAR_SCENE_COLOR[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; - -const int RenderTarget_Size = 512; -const float SelectionTexture_InitData = -1; - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Renderer -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -Renderer* g_Renderer = nullptr; -Renderer* Renderer::Inst() -{ - return g_Renderer; -} - - -Renderer::Renderer() -: m_cameraCB(nullptr) -, m_worldCB(nullptr) -, m_objectCB(nullptr) -, m_opaqueRenderDSState(nullptr) -, m_transparencyRenderDSState(nullptr) -, m_opaqueRenderNoDepthDSState(nullptr) -, m_DSTexture(nullptr) -, m_DSView(nullptr) -, m_DSTextureSRV(nullptr) -, m_selectionRenderTargetTexture(nullptr) -, m_selectionRenderTargetView(nullptr) -, m_selectionRenderTargetSRV(nullptr) -, m_selectionDepthStencilTexture(nullptr) -, m_selectionDepthStencilView(nullptr) -, m_selectionDepthStencilSRV(nullptr) -, m_selectionTextureForCPU(nullptr) -, m_pointSampler(nullptr) -, m_linearSampler(nullptr) -, m_wireframeMode(false) -, m_debugPrimitiveVB(nullptr) -, m_debugPrimitiveVBVerticesCount(0) -, m_screenPrimitiveVB(nullptr) -, m_screenPrimitiveVBVerticesCount(0) -, m_shadowEnabled(true) -, m_HBAOEnabled(true) -, m_visibleOpaqueRenderablesCount(0) -, m_visibleTransparentRenderablesCount(0) -{ - m_worldCBData.ambientColor = DirectX::XMFLOAT3(0.21f, 0.21f, 0.22f); - m_worldCBData.pointLightColor = DirectX::XMFLOAT3(1.0f, 1.0f, 1.0f); - m_worldCBData.pointLightPos = DirectX::XMFLOAT3(0.0f, 30.0f, 12.0f); - m_worldCBData.dirLightColor = DirectX::XMFLOAT3(0.0f, 0.0f, 0.0f); - m_worldCBData.dirLightDir = DirectX::XMFLOAT3(-0.08f, -0.34f, -0.91f); - m_worldCBData.specularPower = 140.0f; - m_worldCBData.specularIntensity = 0.4f; - - m_RSState[0] = nullptr; - m_RSState[1] = nullptr; - - toggleCameraSpeed(false); - - g_Renderer = this; - bFetchSelection = false; -} - -Renderer::~Renderer() -{ -} - -void Renderer::initializeDefaultRSState() -{ - D3D11_RASTERIZER_DESC desc; - ZeroMemory(&desc, sizeof(desc)); - desc.CullMode = D3D11_CULL_NONE; - desc.AntialiasedLineEnable = FALSE; - desc.DepthBias = 0; - desc.DepthBiasClamp = 0; - desc.DepthClipEnable = TRUE; - desc.FrontCounterClockwise = FALSE; - desc.MultisampleEnable = TRUE; - desc.ScissorEnable = FALSE; - desc.SlopeScaledDepthBias = 0; - - desc.FillMode = D3D11_FILL_SOLID; - V(m_device->CreateRasterizerState(&desc, &m_RSState[0])); - - desc.FillMode = D3D11_FILL_WIREFRAME; - V(m_device->CreateRasterizerState(&desc, &m_RSState[1])); -} - -HRESULT Renderer::DeviceCreated(ID3D11Device* device) -{ - m_device = device; - - // Camera constant buffer - { - D3D11_BUFFER_DESC buffer_desc; - ZeroMemory(&buffer_desc, sizeof(buffer_desc)); - buffer_desc.Usage = D3D11_USAGE_DYNAMIC; - buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; - buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - buffer_desc.ByteWidth = sizeof(CBCamera); - _ASSERT((buffer_desc.ByteWidth % 16) == 0); - - V(device->CreateBuffer(&buffer_desc, nullptr, &m_cameraCB)); - } - - // World constant buffer - { - D3D11_BUFFER_DESC buffer_desc; - ZeroMemory(&buffer_desc, sizeof(buffer_desc)); - buffer_desc.Usage = D3D11_USAGE_DYNAMIC; - buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; - buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - buffer_desc.ByteWidth = sizeof(CBWorld); - _ASSERT((buffer_desc.ByteWidth % 16) == 0); - - V(device->CreateBuffer(&buffer_desc, nullptr, &m_worldCB)); - } - - // Object constant buffer - { - D3D11_BUFFER_DESC buffer_desc; - ZeroMemory(&buffer_desc, sizeof(buffer_desc)); - buffer_desc.Usage = D3D11_USAGE_DYNAMIC; - buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; - buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - buffer_desc.ByteWidth = sizeof(CBObject); - _ASSERT((buffer_desc.ByteWidth % 16) == 0); - - V(device->CreateBuffer(&buffer_desc, nullptr, &m_objectCB)); - } - - // Opaque Render Depth-Stencil state - { - D3D11_DEPTH_STENCIL_DESC desc; - ZeroMemory(&desc, sizeof(desc)); - desc.StencilEnable = FALSE; - desc.DepthEnable = TRUE; - desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; - desc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL; - - V(device->CreateDepthStencilState(&desc, &m_opaqueRenderDSState)); - } - - // Transparency Render Depth-Stencil state - { - D3D11_DEPTH_STENCIL_DESC desc; - ZeroMemory(&desc, sizeof(desc)); - desc.StencilEnable = FALSE; - desc.DepthEnable = TRUE; - desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO; - desc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL; - - V(device->CreateDepthStencilState(&desc, &m_transparencyRenderDSState)); - } - - // Opaque Render Depth-Stencil state Without Depth Test - { - D3D11_DEPTH_STENCIL_DESC desc; - ZeroMemory(&desc, sizeof(desc)); - desc.StencilEnable = FALSE; - desc.DepthEnable = FALSE; - desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; - desc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL; - - V(device->CreateDepthStencilState(&desc, &m_opaqueRenderNoDepthDSState)); - } - - // Linear sampler - { - D3D11_SAMPLER_DESC desc; - ZeroMemory(&desc, sizeof(desc)); - desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; - desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; - desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; - desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; - desc.MaxAnisotropy = 1; - desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS; - desc.MinLOD = 0; - desc.MaxLOD = D3D11_FLOAT32_MAX; - V(device->CreateSamplerState(&desc, &m_linearSampler)); - } - - // Point sampler - { - D3D11_SAMPLER_DESC desc; - ZeroMemory(&desc, sizeof(desc)); - desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; - desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; - desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; - desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; - desc.MaxAnisotropy = 1; - desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS; - desc.MinLOD = 0; - desc.MaxLOD = D3D11_FLOAT32_MAX; - V(device->CreateSamplerState(&desc, &m_pointSampler)); - } - - // Rasterizer state - initializeDefaultRSState(); - - // init primitive render meshes - for (uint32_t i = 0; i < PrimitiveRenderMeshType::Count; i++) - { - m_primitiveRenderMeshes[i] = nullptr; - } - - // init shadows - ID3D11DeviceContext* pd3dDeviceContext; - m_device->GetImmediateContext(&pd3dDeviceContext); - m_shadow.createResources(m_device, pd3dDeviceContext, &m_camera); - - // init hbao - m_HBAO.createResources(m_device); - - return S_OK; -} - -void Renderer::DeviceDestroyed() -{ - SAFE_RELEASE(m_cameraCB); - SAFE_RELEASE(m_worldCB); - SAFE_RELEASE(m_objectCB); - SAFE_RELEASE(m_RSState[0]); - SAFE_RELEASE(m_RSState[1]); - SAFE_RELEASE(m_opaqueRenderDSState); - SAFE_RELEASE(m_transparencyRenderDSState); - SAFE_RELEASE(m_opaqueRenderNoDepthDSState); - SAFE_RELEASE(m_pointSampler); - SAFE_RELEASE(m_linearSampler); - SAFE_RELEASE(m_debugPrimitiveVB); - SAFE_RELEASE(m_screenPrimitiveVB); - SAFE_RELEASE(m_DSTexture); - SAFE_RELEASE(m_DSView); - SAFE_RELEASE(m_DSTextureSRV); - SAFE_RELEASE(m_selectionRenderTargetTexture); - SAFE_RELEASE(m_selectionRenderTargetView); - SAFE_RELEASE(m_selectionRenderTargetSRV); - SAFE_RELEASE(m_selectionDepthStencilTexture); - SAFE_RELEASE(m_selectionDepthStencilView); - SAFE_RELEASE(m_selectionDepthStencilSRV); - SAFE_RELEASE(m_selectionTextureForCPU); - - for (uint32_t i = 0; i < PrimitiveRenderMeshType::Count; i++) - { - SAFE_DELETE(m_primitiveRenderMeshes[i]); - } -} - -void Renderer::onInitialize() -{ - // search paths - m_resourceManager.addSearchDir("..\\resources"); - m_resourceManager.addSearchDir("..\\..\\..\\..\\bin\\resources"); - //m_resourceManager.addSearchDir("..\\..\\samples\\resources"); - //m_resourceManager.addSearchDir("..\\..\\..\\samples\\resources"); - - // debug primitive render material and input layout - { - m_debugPrimitiveRenderMaterial = new RenderMaterial("", m_resourceManager, "debug_primitive", ""); - - D3D11_INPUT_ELEMENT_DESC layout[] = { - { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 } - }; - - m_debugPrimitiveRenderMaterialInstance = m_debugPrimitiveRenderMaterial->getMaterialInstance(layout, ARRAYSIZE(layout)); - } - - // screen primitive render material and input layout - { - m_screenPrimitiveRenderMaterial = new RenderMaterial("", m_resourceManager, "screen_primitive_ex", ""); - - D3D11_INPUT_ELEMENT_DESC layout[] = { - { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 } - }; - - m_screenPrimitiveRenderMaterialInstance = m_screenPrimitiveRenderMaterial->getMaterialInstance(layout, ARRAYSIZE(layout)); - } - - // selection render material and input layout - { - m_selectionRenderMaterial = new RenderMaterial("idm", m_resourceManager, "model_simple_id_ex", ""); - - D3D11_INPUT_ELEMENT_DESC layout[] = { - { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "VERTEX_NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "FACE_NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 36, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 48, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "TEXCOORD", 1, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 } - }; - - m_selectionRenderMaterialInstance = m_selectionRenderMaterial->getMaterialInstance(layout, ARRAYSIZE(layout)); - } -} - -void Renderer::onTerminate() -{ - SAFE_DELETE(m_debugPrimitiveRenderMaterial); - SAFE_DELETE(m_screenPrimitiveRenderMaterial); -} - -void Renderer::BackBufferResized(ID3D11Device* /*device*/, const DXGI_SURFACE_DESC* sd) -{ - // Setup the camera's projection parameters - m_screenWidth = sd->Width; - m_screenHeight = sd->Height; - float fAspectRatio = m_screenWidth / m_screenHeight; - float fov = (GlobalSettings::Inst().m_fovAngle / 360.0f) * 3.141592653589793; - m_camera.SetProjParams(fov, fAspectRatio, CAMERA_CLIP_NEAR, CAMERA_CLIP_FAR); - - SAFE_RELEASE(m_DSTexture); - SAFE_RELEASE(m_DSView); - SAFE_RELEASE(m_DSTextureSRV); - SAFE_RELEASE(m_selectionRenderTargetTexture); - SAFE_RELEASE(m_selectionRenderTargetView); - SAFE_RELEASE(m_selectionRenderTargetSRV); - SAFE_RELEASE(m_selectionDepthStencilTexture); - SAFE_RELEASE(m_selectionDepthStencilView); - SAFE_RELEASE(m_selectionDepthStencilSRV); - SAFE_RELEASE(m_selectionTextureForCPU); - - // create m_selectionRenderTargetTexture - { - D3D11_TEXTURE2D_DESC desc; - ZeroMemory(&desc, sizeof(desc)); - desc.Width = RenderTarget_Size; - desc.Height = RenderTarget_Size; - desc.MipLevels = 1; - desc.ArraySize = 1; - desc.Format = DXGI_FORMAT_R32_FLOAT; // Use a typeless type here so that it can be both depth-stencil and shader resource. - desc.SampleDesc.Count = 1; - desc.SampleDesc.Quality = 0; - desc.Usage = D3D11_USAGE_DEFAULT; - desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE; - desc.CPUAccessFlags = 0; - desc.MiscFlags = 0; - V(m_device->CreateTexture2D(&desc, NULL, &m_selectionRenderTargetTexture)); - } - - // create m_selectionRenderTargetView - { - D3D11_RENDER_TARGET_VIEW_DESC desc; - ZeroMemory(&desc, sizeof(desc)); - desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; - desc.Format = DXGI_FORMAT_R32_FLOAT; // Make the view see this as D32_FLOAT instead of typeless - desc.Texture2D.MipSlice = 0; - V(m_device->CreateRenderTargetView(m_selectionRenderTargetTexture, &desc, &m_selectionRenderTargetView)); - } - - // create m_selectionRenderTargetSRV - { - D3D11_SHADER_RESOURCE_VIEW_DESC desc; - ZeroMemory(&desc, sizeof(desc)); - desc.Format = DXGI_FORMAT_R32_FLOAT; // Make the shaders see this as R32_FLOAT instead of typeless - desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; - desc.Texture2D.MipLevels = 1; - desc.Texture2D.MostDetailedMip = 0; - V(m_device->CreateShaderResourceView(m_selectionRenderTargetTexture, &desc, &m_selectionRenderTargetSRV)); - } - - // create m_selectionDepthStencilTexture - { - D3D11_TEXTURE2D_DESC desc; - ZeroMemory(&desc, sizeof(desc)); - desc.Width = RenderTarget_Size; - desc.Height = RenderTarget_Size; - desc.MipLevels = 1; - desc.ArraySize = 1; - desc.Format = DXGI_FORMAT_R32_TYPELESS; // Use a typeless type here so that it can be both depth-stencil and shader resource. - desc.SampleDesc.Count = 1; - desc.SampleDesc.Quality = 0; - desc.Usage = D3D11_USAGE_DEFAULT; - desc.BindFlags = D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE; - desc.CPUAccessFlags = 0; - desc.MiscFlags = 0; - V(m_device->CreateTexture2D(&desc, NULL, &m_selectionDepthStencilTexture)); - } - - // create m_selectionDepthStencilView - { - D3D11_DEPTH_STENCIL_VIEW_DESC desc; - ZeroMemory(&desc, sizeof(desc)); - desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; - desc.Format = DXGI_FORMAT_D32_FLOAT; // Make the view see this as D32_FLOAT instead of typeless - desc.Texture2D.MipSlice = 0; - V(m_device->CreateDepthStencilView(m_selectionDepthStencilTexture, &desc, &m_selectionDepthStencilView)); - } - - // create m_selectionDepthStencilSRV - { - D3D11_SHADER_RESOURCE_VIEW_DESC desc; - ZeroMemory(&desc, sizeof(desc)); - desc.Format = DXGI_FORMAT_R32_FLOAT; // Make the shaders see this as R32_FLOAT instead of typeless - desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; - desc.Texture2D.MipLevels = 1; - desc.Texture2D.MostDetailedMip = 0; - V(m_device->CreateShaderResourceView(m_selectionDepthStencilTexture, &desc, &m_selectionDepthStencilSRV)); - } - - // create m_selectionTextureForCPU - { - D3D11_TEXTURE2D_DESC desc; - ZeroMemory(&desc, sizeof(desc)); - desc.Width = RenderTarget_Size; - desc.Height = RenderTarget_Size; - desc.MipLevels = 1; - desc.ArraySize = 1; - desc.Format = DXGI_FORMAT_R32_FLOAT; // Use a typeless type here so that it can be both depth-stencil and shader resource. - desc.SampleDesc.Count = 1; - desc.SampleDesc.Quality = 0; - desc.Usage = D3D11_USAGE_STAGING; - desc.BindFlags = 0; - desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; - desc.MiscFlags = 0; - V(m_device->CreateTexture2D(&desc, NULL, &m_selectionTextureForCPU)); - } - - // create a new Depth-Stencil texture - { - D3D11_TEXTURE2D_DESC desc; - ZeroMemory(&desc, sizeof(desc)); - desc.Width = sd->Width; - desc.Height = sd->Height; - desc.MipLevels = 1; - desc.ArraySize = 1; - desc.Format = DXGI_FORMAT_R32_TYPELESS; // Use a typeless type here so that it can be both depth-stencil and shader resource. - desc.SampleDesc.Count = sd->SampleDesc.Count; - desc.SampleDesc.Quality = sd->SampleDesc.Quality; - desc.Usage = D3D11_USAGE_DEFAULT; - desc.BindFlags = D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE; - desc.CPUAccessFlags = 0; - desc.MiscFlags = 0; - V(m_device->CreateTexture2D(&desc, NULL, &m_DSTexture)); - } - - // create Depth-Stencil view - { - D3D11_DEPTH_STENCIL_VIEW_DESC desc; - ZeroMemory(&desc, sizeof(desc)); - desc.ViewDimension = sd->SampleDesc.Count > 1 ? D3D11_DSV_DIMENSION_TEXTURE2DMS : D3D11_DSV_DIMENSION_TEXTURE2D; - desc.Format = DXGI_FORMAT_D32_FLOAT; // Make the view see this as D32_FLOAT instead of typeless - desc.Texture2D.MipSlice = 0; - V(m_device->CreateDepthStencilView(m_DSTexture, &desc, &m_DSView)); - } - - // create Depth-Stencil shader resource view - { - D3D11_SHADER_RESOURCE_VIEW_DESC desc; - ZeroMemory(&desc, sizeof(desc)); - desc.Format = DXGI_FORMAT_R32_FLOAT; // Make the shaders see this as R32_FLOAT instead of typeless - desc.ViewDimension = sd->SampleDesc.Count > 1 ? D3D11_SRV_DIMENSION_TEXTURE2DMS : D3D11_SRV_DIMENSION_TEXTURE2D; - desc.Texture2D.MipLevels = 1; - desc.Texture2D.MostDetailedMip = 0; - V(m_device->CreateShaderResourceView(m_DSTexture, &desc, &m_DSTextureSRV)); - } - - // setup viewport - m_viewport.Width = (FLOAT)sd->Width; - m_viewport.Height = (FLOAT)sd->Height; - m_viewport.MinDepth = 0; - m_viewport.MaxDepth = 1; - m_viewport.TopLeftX = 0; - m_viewport.TopLeftY = 0; - - // setup shadows - m_shadow.setScreenResolution(0, sd->Width, sd->Height, sd->SampleDesc.Count, nullptr); -} - -void Renderer::setAllConstantBuffers(ID3D11DeviceContext* ctx) -{ - ID3D11Buffer* cbs[3] = { m_cameraCB, m_worldCB, m_objectCB }; - ctx->VSSetConstantBuffers(0, 3, cbs); - ctx->GSSetConstantBuffers(0, 3, cbs); - ctx->PSSetConstantBuffers(0, 3, cbs); -} - -void Renderer::Render(ID3D11Device* /*device*/, ID3D11DeviceContext* ctx, ID3D11RenderTargetView* pRTV, - ID3D11DepthStencilView*) -{ - GlobalSettings& globalSettings = GlobalSettings::Inst(); - if (!globalSettings.m_showGraphicsMesh) - return; - - PROFILER_SCOPED_FUNCTION(); - - m_context = ctx; - - ctx->ClearDepthStencilView(m_DSView, D3D11_CLEAR_DEPTH, 1.0, 0); - ctx->RSSetViewports(1, &m_viewport); - - // needed matrices - DirectX::XMMATRIX viewMatrix = SimpleScene::Inst()->GetViewMatrix(); - DirectX::XMMATRIX projMatrix = SimpleScene::Inst()->GetProjMatrix(); - DirectX::XMMATRIX projMatrixInv = DirectX::XMMatrixInverse(NULL, projMatrix); - DirectX::XMMATRIX viewProjMatrix = viewMatrix * projMatrix; - - // Fill Camera constant buffer - { - D3D11_MAPPED_SUBRESOURCE mappedResource; - ctx->Map(m_cameraCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); - CBCamera* cameraBuffer = (CBCamera*)mappedResource.pData; - cameraBuffer->viewProjection = viewProjMatrix; - cameraBuffer->projectionInv = projMatrixInv; - DirectX::XMStoreFloat3(&(cameraBuffer->viewPos), SimpleScene::Inst()->GetEyePt()); - ctx->Unmap(m_cameraCB, 0); - } - - // Fill World constant buffer - { - D3D11_MAPPED_SUBRESOURCE mappedResource; - ctx->Map(m_worldCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); - CBWorld* worldBuffer = (CBWorld*)mappedResource.pData; - float flatNormal = -1.0; - if (globalSettings.m_renderStyle == MESH_RENDER_FLAT) - { - flatNormal = 1.0; - } - float useLighting = 1.0; - if (!globalSettings.m_useLighting) - { - useLighting = -1.0; - } - m_worldCBData.flatNormal = flatNormal; - m_worldCBData.wireFrameOver = -1.0; - m_worldCBData.useLighting = useLighting; - Light::FillLightShaderParam(m_worldCBData.lightParam); - memcpy(worldBuffer, &m_worldCBData, sizeof(m_worldCBData)); - //worldBuffer->ambientColor = m_CBWorldData.ambientColor; - //worldBuffer->pointLightPos = m_CBWorldData.pointLightPos; - //worldBuffer->pointLightColor = m_CBWorldData.pointLightColor; - //worldBuffer->dirLightDir = m_CBWorldData.dirLightDir; - //worldBuffer->specularPower = m_CBWorldData.specularPower; - //worldBuffer->dirLightColor = m_CBWorldData.dirLightColor; - //worldBuffer->specularIntensity = m_CBWorldData.specularIntensity; - ctx->Unmap(m_worldCB, 0); - } - - if (globalSettings.m_renderStyle != MESH_RENDER_WIREFRAME) - { - ctx->RSSetState(m_RSState[0]); - } - else - { - ctx->RSSetState(m_RSState[1]); - } - - ctx->PSSetSamplers(0, 1, &m_linearSampler); - ctx->PSSetSamplers(1, 1, &m_pointSampler); - - - if (m_shadowEnabled) - { - // render depth only - { - ctx->OMSetRenderTargets(0, nullptr, m_DSView); - ctx->OMSetDepthStencilState(m_opaqueRenderDSState, 0xFF); - - // set constants buffers - setAllConstantBuffers(ctx); - - for (auto it = m_renderables.begin(); it != m_renderables.end(); it++) - { - if (!(*it)->isTransparent() && !(*it)->isHidden()) - (*it)->renderDepthStencilOnly(*this); - } - } - - m_shadow.clearBuffer(); - - std::vector<Light>& lights = Light::GetDefaultLights(); - for (int l = 0; l < 3; l++) - { - if (!lights[l].m_useShadows) - { - continue; - } - - atcore_float3 eye = lights[l].m_lightCamera._eye; - eye.x = -eye.x; - atcore_float3 at = lights[l].m_lightCamera._at; - at.x = -at.x; - - ctx->OMSetRenderTargets(0, nullptr, m_DSView); - m_shadow.renderShadowMaps(this, eye, at); - ctx->OMSetRenderTargets(0, nullptr, nullptr); - m_shadow.renderShadowBuffer(m_DSTextureSRV, nullptr); - } - - m_shadow.finalizeBuffer(); - } - - // Opaque render - { - ctx->RSSetViewports(1, &m_viewport); - ctx->OMSetRenderTargets(1, &pRTV, m_DSView); - ctx->OMSetDepthStencilState(m_opaqueRenderDSState, 0xFF); - - // set constants buffers - setAllConstantBuffers(ctx); - - // Fill Camera constant buffer - { - D3D11_MAPPED_SUBRESOURCE mappedResource; - ctx->Map(m_cameraCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); - CBCamera* cameraBuffer = (CBCamera*)mappedResource.pData; - cameraBuffer->viewProjection = viewProjMatrix; - cameraBuffer->projectionInv = projMatrixInv; - DirectX::XMStoreFloat3(&(cameraBuffer->viewPos), SimpleScene::Inst()->GetEyePt()); - ctx->Unmap(m_cameraCB, 0); - } - - std::vector<Renderable*> renderablesWithoutDepthTest; - - // Render opaque renderables - m_visibleOpaqueRenderablesCount = 0; - for (auto it = m_renderables.begin(); it != m_renderables.end(); it++) - { - if (!(*it)->isTransparent() && !(*it)->isHidden()) - { - if (!(*it)->isDepthTest()) - { - renderablesWithoutDepthTest.push_back(*it); - continue; - } - (*it)->render(*this); - m_visibleOpaqueRenderablesCount++; - } - } - - if (renderablesWithoutDepthTest.size() > 0) - { - ctx->OMSetDepthStencilState(m_opaqueRenderNoDepthDSState, 0xFF); - std::vector<Renderable*>::iterator itR; - for (itR = renderablesWithoutDepthTest.begin(); itR != renderablesWithoutDepthTest.end(); itR++) - { - (*itR)->render(*this); - } - ctx->OMSetDepthStencilState(m_opaqueRenderDSState, 0xFF); - } - } - - // draw overline - if (globalSettings.m_showWireframe) - { - if (globalSettings.m_renderStyle != MESH_RENDER_WIREFRAME) - { - ctx->RSSetState(m_RSState[1]); - } - - // update wireFrameOver - { - D3D11_MAPPED_SUBRESOURCE mappedResource; - ctx->Map(m_worldCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); - CBWorld* worldBuffer = (CBWorld*)mappedResource.pData; - float wireFrameOver = -1.0; - { - if (globalSettings.m_showWireframe) - { - wireFrameOver = 1.0; - } - } - m_worldCBData.wireFrameOver = wireFrameOver; - memcpy(worldBuffer, &m_worldCBData, sizeof(m_worldCBData)); - ctx->Unmap(m_worldCB, 0); - } - - for (auto it = m_renderables.begin(); it != m_renderables.end(); it++) - { - if (!(*it)->isTransparent() && !(*it)->isHidden()) - { - (*it)->render(*this); - } - } - - if (globalSettings.m_renderStyle != MESH_RENDER_WIREFRAME) - { - ctx->RSSetState(m_RSState[0]); - } - } - - // modulate shadows - if (m_shadowEnabled && globalSettings.m_useLighting) - { - m_shadow.modulateShadowBuffer(pRTV); - } - - // render AO - if (m_HBAOEnabled) - { - m_HBAO.renderAO(m_context, pRTV, m_DSTextureSRV, projMatrix); - } - - ctx->RSSetViewports(1, &m_viewport); - - // render debug render buffers - if (!AppMainWindow::Inst().m_bGizmoWithDepthTest) - { - ctx->OMSetDepthStencilState(m_opaqueRenderNoDepthDSState, 0xFF); - } - while (m_queuedRenderBuffers.size() > 0) - { - render(m_queuedRenderBuffers.back()); - m_queuedRenderBuffers.pop_back(); - } - while (m_screenRenderBuffers.size() > 0) - { - render(m_screenRenderBuffers.back(), true); - m_screenRenderBuffers.pop_back(); - } - - // Transparency render - ctx->OMSetRenderTargets(1, &pRTV, m_DSView); - ctx->OMSetDepthStencilState(m_transparencyRenderDSState, 0xFF); - - // depth as SRV isn't used now (uncommenting will produce a warning, probably need readonly depth?) - //ctx->PSSetShaderResources(1, 1, &mDSTextureSRV); - - // Render transparent renderables - m_visibleTransparentRenderablesCount = 0; - for (auto it = m_renderables.begin(); it != m_renderables.end(); it++) - { - if ((*it)->isTransparent() && !(*it)->isHidden()) - { - (*it)->render(*this); - m_visibleTransparentRenderablesCount++; - } - } - - // shadows debug render - if (0) - { - m_shadow.displayMapFrustums(pRTV, m_DSView); - } - - // Reset RT and SRV state - ID3D11ShaderResourceView* nullAttach[16] = { nullptr }; - ctx->PSSetShaderResources(0, 16, nullAttach); - ctx->OMSetRenderTargets(0, nullptr, nullptr); -} - -LRESULT Renderer::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - PX_UNUSED(hWnd); - PX_UNUSED(wParam); - PX_UNUSED(lParam); - - if (uMsg == WM_KEYDOWN || uMsg == WM_KEYUP) - { - // Camera overspeed event - int iKeyPressed = static_cast<int>(wParam); - if (iKeyPressed == VK_SHIFT) - { - toggleCameraSpeed(uMsg == WM_KEYDOWN); - } - } - - UpdateCamera(); - - return 0; - - // Camera events - return m_camera.HandleMessages(hWnd, uMsg, wParam, lParam); -} - -void Renderer::Animate(double fElapsedTimeSeconds) -{ - PROFILER_SCOPED_FUNCTION(); - - m_camera.FrameMove((float)fElapsedTimeSeconds); -} - -void Renderer::renderDepthOnly(DirectX::XMMATRIX* viewProjectionSubstitute) -{ - // Fill Camera constant buffer - if (viewProjectionSubstitute) - { - D3D11_MAPPED_SUBRESOURCE mappedResource; - m_context->Map(m_cameraCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); - CBCamera* cameraBuffer = (CBCamera*)mappedResource.pData; - cameraBuffer->viewProjection = *viewProjectionSubstitute; - m_context->Unmap(m_cameraCB, 0); - } - - // set constants buffers - setAllConstantBuffers(m_context); - - // render - for (auto it = m_renderables.begin(); it != m_renderables.end(); it++) - { - if (!(*it)->isTransparent() && !(*it)->isHidden()) - (*it)->renderDepthStencilOnly(*this); - } -} - -void Renderer::render(const PxRenderBuffer* renderBuffer, bool bScreen) -{ - // points - uint32_t pointsCount = renderBuffer->getNbPoints(); - if (pointsCount > 0) - { - RenderDebugVertex* verts = new RenderDebugVertex[pointsCount]; - const PxDebugPoint* points = renderBuffer->getPoints(); - for (uint32_t i = 0; i < pointsCount; i++) - { - verts[i].mPos = points[i].pos; - verts[i].mColor = points[i].color; - } - - renderDebugPrimitive(verts, pointsCount, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST); - delete[] verts; - } - - // lines - uint32_t linesCount = renderBuffer->getNbLines(); - if (linesCount > 0) - { - RenderDebugVertex* verts = new RenderDebugVertex[linesCount * 2]; - const PxDebugLine* lines = renderBuffer->getLines(); - for (uint32_t i = 0; i < linesCount; i++) - { - verts[i * 2].mPos = lines[i].pos0; - verts[i * 2].mColor = lines[i].color0; - verts[i * 2 + 1].mPos = lines[i].pos1; - verts[i * 2 + 1].mColor = lines[i].color1; - } - - renderDebugPrimitive(verts, linesCount * 2, D3D11_PRIMITIVE_TOPOLOGY_LINELIST, bScreen); - delete[] verts; - } - - // triangles - uint32_t trianglesCount = renderBuffer->getNbTriangles(); - if (trianglesCount > 0) - { - RenderDebugVertex* verts = new RenderDebugVertex[trianglesCount * 3]; - const PxDebugTriangle* triangles = renderBuffer->getTriangles(); - for (uint32_t i = 0; i < trianglesCount; i++) - { - verts[i * 3].mPos = triangles[i].pos0; - verts[i * 3].mColor = triangles[i].color0; - verts[i * 3 + 1].mPos = triangles[i].pos1; - verts[i * 3 + 1].mColor = triangles[i].color1; - verts[i * 3 + 2].mPos = triangles[i].pos2; - verts[i * 3 + 2].mColor = triangles[i].color2; - } - - renderDebugPrimitive(verts, trianglesCount * 3, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); - delete[] verts; - } - - // texts? - // .... -} - -void Renderer::renderDebugPrimitive(const Renderer::RenderDebugVertex *vertices, uint32_t verticesCount, D3D11_PRIMITIVE_TOPOLOGY topology, bool bScreen) -{ - m_context->IASetPrimitiveTopology(topology); - - if (bScreen) - { - m_screenPrimitiveRenderMaterialInstance->bind(*m_context, 0); - } - else - { - m_debugPrimitiveRenderMaterialInstance->bind(*m_context, 0); - } - - D3D11_MAPPED_SUBRESOURCE mappedResource; - m_context->Map(m_objectCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); - CBObject* objectBuffer = (CBObject*)mappedResource.pData; - - objectBuffer->worldMatrix = PxMat44ToXMMATRIX(PxMat44(PxIdentity)); - - m_context->Unmap(m_objectCB, 0); - - if (m_debugPrimitiveVBVerticesCount < verticesCount) - { - m_debugPrimitiveVBVerticesCount = verticesCount; - SAFE_RELEASE(m_debugPrimitiveVB); - - D3D11_BUFFER_DESC bufferDesc; - - memset(&bufferDesc, 0, sizeof(D3D11_BUFFER_DESC)); - bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; - bufferDesc.ByteWidth = sizeof(Renderer::RenderDebugVertex) * m_debugPrimitiveVBVerticesCount; - bufferDesc.CPUAccessFlags = 0; - bufferDesc.MiscFlags = 0; - bufferDesc.Usage = D3D11_USAGE_DEFAULT; - - V(m_device->CreateBuffer(&bufferDesc, NULL, &m_debugPrimitiveVB)); - } - - CD3D11_BOX box(0, 0, 0, (LONG)(sizeof(Renderer::RenderDebugVertex) * verticesCount), 1, 1); - m_context->UpdateSubresource(m_debugPrimitiveVB, 0, &box, vertices, 0, 0); - - ID3D11Buffer* pBuffers[1] = { m_debugPrimitiveVB }; - UINT strides[1] = { sizeof(RenderDebugVertex) }; - UINT offsets[1] = { 0 }; - m_context->IASetVertexBuffers(0, 1, pBuffers, strides, offsets); - - m_context->Draw(verticesCount, 0); -} - -IRenderMesh* Renderer::getPrimitiveRenderMesh(PrimitiveRenderMeshType::Enum type) -{ - if (m_primitiveRenderMeshes[type] == NULL) - { - switch (type) - { - case PrimitiveRenderMeshType::Box: - m_primitiveRenderMeshes[type] = new BoxRenderMesh(); - break; - case PrimitiveRenderMeshType::Plane: - m_primitiveRenderMeshes[type] = new PlaneRenderMesh(); - break; - case PrimitiveRenderMeshType::Sphere: - m_primitiveRenderMeshes[type] = new SphereRenderMesh(); - break; -// Add By Lixu Begin - case PrimitiveRenderMeshType::Cone: - m_primitiveRenderMeshes[type] = new ConeRenderMesh(); - break; -// Add By Lixu End - default: - PX_ALWAYS_ASSERT_MESSAGE("Unsupported PxGeometryType"); - return NULL; - } - } - - return m_primitiveRenderMeshes[type]; -} - - -Renderable* Renderer::createRenderable(IRenderMesh& mesh, RenderMaterial& material) -{ - Renderable* renderable = new Renderable(mesh, material); - m_renderables.emplace(renderable); - return renderable; -} - -void Renderer::removeRenderable(Renderable* r) -{ - m_renderables.erase(m_renderables.find(r)); - delete r; -} - -void Renderer::toggleCameraSpeed(bool overspeed) -{ - m_camera.SetScalers(0.002f, overspeed ? 150.f : 25.f); -} - -void Renderer::reloadShaders() -{ - // iterate Renderables materials and call reload() - std::set<RenderMaterial*> materials; - for (auto it = m_renderables.begin(); it != m_renderables.end(); it++) - { - materials.emplace(&((*it)->getMaterial())); - } - for (std::set<RenderMaterial*>::iterator it = materials.begin(); it != materials.end(); it++) - { - (*it)->reload(); - } -} - -void Renderer::drawUI() -{ - // Lighting - if (ImGui::TreeNode("Lighting")) - { - ImGui::ColorEdit3("Ambient Color", &(m_worldCBData.ambientColor.x)); - ImGui::ColorEdit3("Point Light Color", &(m_worldCBData.pointLightColor.x)); - ImGui::DragFloat3("Point Light Pos", &(m_worldCBData.pointLightPos.x)); - ImGui::ColorEdit3("Dir Light Color", &(m_worldCBData.dirLightColor.x)); - ImGui_DragFloat3Dir("Dir Light Dir", &(m_worldCBData.dirLightDir.x)); - ImGui::DragFloat("Specular Power", &(m_worldCBData.specularPower), 1.0f, 1.0f, 500.0f); - ImGui::DragFloat("Specular Intensity", &(m_worldCBData.specularIntensity), 0.01f, 0.0f, 2.0f); - - ImGui::TreePop(); - } - - // Shadow - if (ImGui::TreeNode("Shadow")) - { - ImGui::Checkbox("Shadows Enabled", &m_shadowEnabled); - if (m_shadowEnabled) - { - m_shadow.drawUI(); - } - - ImGui::TreePop(); - } - - // HBAO+ - if (ImGui::TreeNode("HBAO+")) - { - ImGui::Checkbox("HBAO Enabled", &(m_HBAOEnabled)); - if (m_HBAOEnabled) - { - m_HBAO.drawUI(); - } - - ImGui::TreePop(); - } -} - -void Renderer::UpdateCamera() -{ - Camera* pCamera = SimpleScene::Inst()->m_pCamera; - DirectX::XMVECTORF32 eyePt = { pCamera->_eye.x, pCamera->_eye.y, pCamera->_eye.z, 0 }; - DirectX::XMVECTORF32 lookAtPt = { pCamera->_at.x, pCamera->_at.y, pCamera->_at.z, 0 }; - m_camera.SetViewParams(eyePt, lookAtPt); - m_camera.SetProjParams(pCamera->_fov, pCamera->_aspectRatio, pCamera->_znear, pCamera->_zfar); -} - -bool _pointInPolygon(std::vector<PxVec2>& screenPoints, PxVec2& test) -{ - int polySides = screenPoints.size(); - int i, j = polySides - 1; - bool oddNodes = false; - for (i = 0; i < polySides; i++) - { - if ((screenPoints[i].y < test.y && screenPoints[j].y >= test.y - || screenPoints[j].y <test.y && screenPoints[i].y >= test.y) - && (screenPoints[i].x <= test.x || screenPoints[j].x <= test.x)) - { - float temp = (test.y - screenPoints[i].y) / - (screenPoints[j].y - screenPoints[i].y) * - (screenPoints[j].x - screenPoints[i].x); - oddNodes ^= (screenPoints[i].x + temp < test.x); - } - j = i; - } - return oddNodes; -} - -void Renderer::fetchSelection(std::vector<PxVec2>& screenPoints, std::map<int, std::set<int>>& selection) -{ - PROFILER_SCOPED_FUNCTION(); - - selection.clear(); - - int pointSize = screenPoints.size(); - if (pointSize == 0) - { - return; - } - - GlobalSettings& globalSettings = GlobalSettings::Inst(); - if (!globalSettings.m_showGraphicsMesh) - return; - - ID3D11DeviceContext* ctx = m_context; - - // needed matrices - DirectX::XMMATRIX viewMatrix = SimpleScene::Inst()->GetViewMatrix(); - DirectX::XMMATRIX projMatrix = SimpleScene::Inst()->GetProjMatrix(); - DirectX::XMMATRIX projMatrixInv = DirectX::XMMatrixInverse(NULL, projMatrix); - DirectX::XMMATRIX viewProjMatrix = viewMatrix * projMatrix; - - // Fill Camera constant buffer - { - D3D11_MAPPED_SUBRESOURCE mappedResource; - ctx->Map(m_cameraCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); - CBCamera* cameraBuffer = (CBCamera*)mappedResource.pData; - cameraBuffer->viewProjection = viewProjMatrix; - ctx->Unmap(m_cameraCB, 0); - } - - int width = RenderTarget_Size; - int height = RenderTarget_Size; - float init_data = SelectionTexture_InitData; - int dataSize = width * height; - if (m_selectionTextureData.size() != dataSize) - { - m_selectionTextureData.resize(dataSize); - } - std::fill(m_selectionTextureData.begin(), m_selectionTextureData.end(), init_data); - - ctx->OMSetRenderTargets(1, &m_selectionRenderTargetView, m_selectionDepthStencilView); - float ClearColor[4] = { init_data, init_data, init_data, init_data }; - ctx->ClearRenderTargetView(m_selectionRenderTargetView, ClearColor); - ctx->ClearDepthStencilView(m_selectionDepthStencilView, D3D11_CLEAR_DEPTH, 1.0, 0); - D3D11_VIEWPORT vp = { 0.0f, 0.0f, (float)width, (float)height, 0.0f, 1.0f }; - ctx->RSSetViewports(1, &vp); - ctx->RSSetState(m_RSState[0]); - ctx->OMSetDepthStencilState(m_opaqueRenderDSState, 0xFF); - - // set constants buffers - setAllConstantBuffers(ctx); - - bFetchSelection = true; - - // Render renderables - for (auto it = m_renderables.begin(); it != m_renderables.end(); it++) - { - if (!(*it)->isHidden()) - { - (*it)->render(*this); - } - } - - bFetchSelection = false; - - { - ctx->CopyResource(m_selectionTextureForCPU, m_selectionRenderTargetTexture); - D3D11_MAPPED_SUBRESOURCE mapResource; - HRESULT hr = ctx->Map(m_selectionTextureForCPU, 0, D3D11_MAP_READ, NULL, &mapResource); - memcpy(m_selectionTextureData.data(), mapResource.pData, dataSize * sizeof(float)); - ctx->Unmap(m_selectionTextureForCPU, 0); - } - - std::set<int> vids; - if (pointSize == 1) - { - // point selection - int centerX = screenPoints[0].x * width; - int centerY = screenPoints[0].y * height; - - int ds = centerY * width + centerX; - int vid = m_selectionTextureData[ds]; - vids.emplace(vid); - } - else if (pointSize == 2) - { - // rect selection - PxVec2 lefttop = screenPoints[0]; - PxVec2 rightbottom = screenPoints[1]; - int startX = lefttop.x * width; - int startY = lefttop.y * height; - int endX = rightbottom.x * width; - int endY = rightbottom.y * height; - for (int h = startY; h <= endY; h++) - { - for (int w = startX; w <= endX; w++) - { - int ds = h * width + w; - int vid = m_selectionTextureData[ds]; - vids.emplace(vid); - } - } - } - else - { - // draw selection - PxVec2 pMin, pMax; - pMin = pMax = screenPoints[0]; - for (int ps = 1; ps < pointSize; ps++) - { - PxVec2& p = screenPoints[ps]; - if (p.x < pMin.x) - { - pMin.x = p.x; - } - if (p.y < pMin.y) - { - pMin.y = p.y; - } - if (p.x > pMax.x) - { - pMax.x = p.x; - } - if (p.y > pMax.y) - { - pMax.y = p.y; - } - } - int startX = pMin.x * width; - int startY = pMin.y * height; - int endX = pMax.x * width; - int endY = pMax.y * height; - for (int h = startY; h <= endY; h++) - { - for (int w = startX; w <= endX; w++) - { - PxVec2 test(1.0 * w / width, 1.0 * h / height); - bool valid = _pointInPolygon(screenPoints, test); - if (valid) - { - int ds = h * width + w; - int vid = m_selectionTextureData[ds]; - vids.emplace(vid); - } - } - } - } - - int familyId, chunkId; - for (int vid : vids) - { - if (vid < 0) - { - continue; - } - - Renderable::getFamilyChunkId(vid, familyId, chunkId); - selection[familyId].emplace(chunkId); - } -}
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderer.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderer.h deleted file mode 100644 index eeaf98c..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/Renderer.h +++ /dev/null @@ -1,317 +0,0 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. - - -#ifndef RENDERER_H -#define RENDERER_H - -#include "RenderMaterial.h" -#include <DirectXMath.h> -#include "XInput.h" -#include "DXUTMisc.h" -#include "DXUTCamera.h" -#include "SampleManager.h" -#include "Utils.h" -#include "ResourceManager.h" -#include "PrimitiveRenderMesh.h" -#include "RendererShadow.h" -#include "RendererHBAO.h" -#include <unordered_set> -#include "LightShaderParam.h" - -class CFirstPersonCamera; -class PhysXPrimitive; -class RenderDebugImpl; - -namespace physx -{ -class PxRenderBuffer; -} - - -/** -3D World Renderer -- use createRenderable() to add objects to render. -- use queueRenderBuffer() every frame to render debug primitives. -- contains ResourceManager to search for file and load resources. -- contains RendererShadow and RendererHBAO, use them through getters to control shadows. -*/ -class Renderer : public ISampleController -{ - friend class Renderable; - - public: - //////// ctor //////// - - Renderer(); - ~Renderer(); - - static Renderer* Inst(); - bool bFetchSelection; - void fetchSelection(std::vector<PxVec2>& screenPoints, std::map<int, std::set<int>>& selection); - //////// public API //////// - - void reloadShaders(); - - bool getWireframeMode() - { - return m_wireframeMode; - } - - void setWireframeMode(bool enabled) - { - if(m_wireframeMode != enabled) - { - m_wireframeMode = enabled; - initializeDefaultRSState(); - } - } - - IRenderMesh* getPrimitiveRenderMesh(PrimitiveRenderMeshType::Enum type); - - Renderable* createRenderable(IRenderMesh& mesh, RenderMaterial& material); - void removeRenderable(Renderable* r); - - void drawUI(); - - - //////// public getters //////// - - float getScreenWidth() const - { - return m_screenWidth; - } - - float getScreenHeight() const - { - return m_screenHeight; - } - - void queueRenderBuffer(const PxRenderBuffer* buffer, bool bScreen = false) - { - if (bScreen) - { - m_screenRenderBuffers.push_back(buffer); - } - else - { - m_queuedRenderBuffers.push_back(buffer); - } - } - - void clearQueue() - { - m_screenRenderBuffers.clear(); - m_queuedRenderBuffers.clear(); - } - - ResourceManager& getResourceManager() - { - return m_resourceManager; - } - - uint32_t getVisibleOpaqueRenderablesCount() - { - return m_visibleOpaqueRenderablesCount; - } - - uint32_t getVisibleTransparentRenderablesCount() - { - return m_visibleTransparentRenderablesCount; - } - - CFirstPersonCamera& getCamera() - { - return m_camera; - } - - RenderMaterial::InstancePtr getSelectionRenderMaterialInstance() - { - return m_selectionRenderMaterialInstance; - } - - //////// public 'internal' methods //////// - - // for internal usage (used by RenderShadows) - void renderDepthOnly(DirectX::XMMATRIX* viewProjectionSubstitute); - void UpdateCamera(); - protected: - - //////// controller callbacks //////// - - virtual HRESULT DeviceCreated(ID3D11Device* pDevice); - virtual void DeviceDestroyed(); - virtual LRESULT MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); - virtual void Animate(double fElapsedTimeSeconds); - virtual void onInitialize(); - virtual void onTerminate(); - virtual void BackBufferResized(ID3D11Device* pDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc); - virtual void Render(ID3D11Device* /*device*/, ID3D11DeviceContext* ctx, ID3D11RenderTargetView* pRTV, - ID3D11DepthStencilView* pDSV); - - private: - - //////// internal methods //////// - - struct RenderDebugVertex - { - PxVec3 mPos; - uint32_t mColor; - }; - - void render(const PxRenderBuffer* renderBuffer, bool bScreen = false); - void render(Renderable* renderable); - void renderDebugPrimitive(const RenderDebugVertex *vertices, uint32_t verticesCount, D3D11_PRIMITIVE_TOPOLOGY topology, bool bScreen = false); - void initializeDefaultRSState(); - void setAllConstantBuffers(ID3D11DeviceContext* ctx); - void toggleCameraSpeed(bool overspeed); - - - //////// constant buffers //////// - - struct CBCamera - { - DirectX::XMMATRIX viewProjection; - DirectX::XMMATRIX projectionInv; - DirectX::XMFLOAT3 viewPos; - float unusedPad; - }; - struct CBWorld - { - DirectX::XMFLOAT3 ambientColor; - float unusedPad1; - DirectX::XMFLOAT3 pointLightPos; - float unusedPad2; - DirectX::XMFLOAT3 pointLightColor; - float unusedPad3; - DirectX::XMFLOAT3 dirLightDir; - float specularPower; - DirectX::XMFLOAT3 dirLightColor; - float specularIntensity; // TODO: actually it's per object property - float flatNormal; - float wireFrameOver; - float useLighting; - float unusedPad4; - LightShaderParam lightParam; - }; - struct CBObject - { - DirectX::XMMATRIX worldMatrix; - DirectX::XMFLOAT4 diffuseColor; - DirectX::XMFLOAT4 specularColor; - float useDiffuseTexture; - float useSpecularTexture; - float useNormalTexture; - float specularShininess; - float selected; - }; - - - //////// internal data //////// - - // camera - CFirstPersonCamera m_camera; - float m_screenWidth; - float m_screenHeight; - - // resources - ResourceManager m_resourceManager; - - // additional render modules(libs) - RendererShadow m_shadow; - bool m_shadowEnabled; - RendererHBAO m_HBAO; - bool m_HBAOEnabled; - - // DX11 common - ID3D11Device* m_device; - ID3D11DeviceContext* m_context; - D3D11_VIEWPORT m_viewport; - - // DX11 states - ID3D11RasterizerState* m_RSState[2]; - ID3D11DepthStencilState* m_opaqueRenderDSState; - ID3D11DepthStencilState* m_transparencyRenderDSState; - ID3D11DepthStencilState* m_opaqueRenderNoDepthDSState; - - // DX11 samplers - ID3D11SamplerState* m_pointSampler; - ID3D11SamplerState* m_linearSampler; - - // Depth Buffer - ID3D11Texture2D* m_DSTexture; - ID3D11DepthStencilView* m_DSView; - ID3D11ShaderResourceView* m_DSTextureSRV; - - // Constant Buffers - ID3D11Buffer* m_cameraCB; - ID3D11Buffer* m_worldCB; - CBWorld m_worldCBData; - ID3D11Buffer* m_objectCB; - - // toggles (options) - bool m_wireframeMode; - - // renderables - std::unordered_set<Renderable*> m_renderables; - - // primitive meshes cache - IRenderMesh* m_primitiveRenderMeshes[PrimitiveRenderMeshType::Count]; - - // stats - uint32_t m_visibleOpaqueRenderablesCount; - uint32_t m_visibleTransparentRenderablesCount; - - // Debug Render - RenderMaterial* m_debugPrimitiveRenderMaterial; - RenderMaterial::InstancePtr m_debugPrimitiveRenderMaterialInstance; - ID3D11Buffer* m_debugPrimitiveVB; - uint32_t m_debugPrimitiveVBVerticesCount; - std::vector<const PxRenderBuffer*> m_queuedRenderBuffers; - - // Screen Render - RenderMaterial* m_screenPrimitiveRenderMaterial; - RenderMaterial::InstancePtr m_screenPrimitiveRenderMaterialInstance; - ID3D11Buffer* m_screenPrimitiveVB; - uint32_t m_screenPrimitiveVBVerticesCount; - std::vector<const PxRenderBuffer*> m_screenRenderBuffers; - - // Selection Render Resource - RenderMaterial* m_selectionRenderMaterial; - RenderMaterial::InstancePtr m_selectionRenderMaterialInstance; - ID3D11Texture2D* m_selectionRenderTargetTexture; - ID3D11RenderTargetView* m_selectionRenderTargetView; - ID3D11ShaderResourceView* m_selectionRenderTargetSRV; - ID3D11Texture2D* m_selectionDepthStencilTexture; - ID3D11DepthStencilView* m_selectionDepthStencilView; - ID3D11ShaderResourceView* m_selectionDepthStencilSRV; - ID3D11Texture2D* m_selectionTextureForCPU; - std::vector<float> m_selectionTextureData; -}; - - -#endif
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererHBAO.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererHBAO.cpp deleted file mode 100644 index c674b2b..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererHBAO.cpp +++ /dev/null @@ -1,98 +0,0 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. - - -#include "RendererHBAO.h" -#include "Renderer.h" -#include "imgui.h" - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Renderer HBAO (wrapper for hbao+) -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - -RendererHBAO::RendererHBAO() -{ - m_SSAOContext = NULL; - - // default parameters - m_SSAOParameters.Radius = 2.0f; -} - - -RendererHBAO::~RendererHBAO() -{ - releaseResources(); -} - - -void RendererHBAO::createResources(ID3D11Device *pd3dDevice) -{ - GFSDK_SSAO_Status status; - status = GFSDK_SSAO_CreateContext_D3D11(pd3dDevice, &m_SSAOContext, nullptr); - assert(status == GFSDK_SSAO_OK); -} - - -void RendererHBAO::releaseResources() -{ - if (m_SSAOContext != NULL) - { - m_SSAOContext->Release(); - } -} - - -void RendererHBAO::renderAO(ID3D11DeviceContext *pd3dDeviceContext, ID3D11RenderTargetView* pRTV, ID3D11ShaderResourceView* pDepthSRV, DirectX::XMMATRIX& projMatrix) -{ - GFSDK_SSAO_InputData_D3D11 InputData; - InputData.DepthData.pFullResDepthTextureSRV = pDepthSRV; - InputData.DepthData.DepthTextureType = GFSDK_SSAO_HARDWARE_DEPTHS; - InputData.DepthData.MetersToViewSpaceUnits = 1.0f; - InputData.DepthData.ProjectionMatrix.Data = GFSDK_SSAO_Float4x4(reinterpret_cast<const GFSDK_SSAO_FLOAT*>(&(projMatrix.r[0]))); - InputData.DepthData.ProjectionMatrix.Layout = GFSDK_SSAO_ROW_MAJOR_ORDER; - - GFSDK_SSAO_Output_D3D11 Output; - Output.pRenderTargetView = pRTV;// m_pSceneRTs->ColorRTV; - Output.Blend.Mode = GFSDK_SSAO_MULTIPLY_RGB; - - m_SSAOContext->RenderAO(pd3dDeviceContext, InputData, m_SSAOParameters, Output); -} - - -void RendererHBAO::drawUI() -{ - ImGui::DragFloat("Radius", &(m_SSAOParameters.Radius), 0.05f, 0.0f, 100.0f); - ImGui::DragFloat("Bias", &(m_SSAOParameters.Bias), 0.01f, 0.0f, 0.5f); - ImGui::DragFloat("NearAO", &(m_SSAOParameters.NearAO), 0.01f, 1.0f, 4.0f); - ImGui::DragFloat("FarAO", &(m_SSAOParameters.FarAO), 0.01, 1.0f, 4.0f); - ImGui::DragFloat("PowerExponent", &(m_SSAOParameters.PowerExponent), 0.01f, 1.0f, 8.0f); - ImGui::Checkbox("ForegroundAO Enabled", (bool*)&(m_SSAOParameters.ForegroundAO.Enable)); - ImGui::DragFloat("ForegroundAO ViewDepth", &(m_SSAOParameters.ForegroundAO.ForegroundViewDepth), 0.01f, 0.0f, 100.0f); - ImGui::Checkbox("BackgroundAO Enabled", (bool*)&(m_SSAOParameters.BackgroundAO.Enable)); - ImGui::DragFloat("BackgroundAO ViewDepth", &(m_SSAOParameters.BackgroundAO.BackgroundViewDepth), 0.01f, 0.0f, 100.0f); -}
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererHBAO.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererHBAO.h deleted file mode 100644 index 3237ddf..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererHBAO.h +++ /dev/null @@ -1,58 +0,0 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. - - -#ifndef RENDERER_HBAO_H -#define RENDERER_HBAO_H - -#include <DirectXMath.h> -#include "GFSDK_SSAO.h" - - -class Renderer; - -class RendererHBAO -{ -public: - RendererHBAO(); - ~RendererHBAO(); - - void createResources(ID3D11Device *pd3dDevice); - void renderAO(ID3D11DeviceContext *pd3dDeviceContext, ID3D11RenderTargetView* pRTV, ID3D11ShaderResourceView* pDepthSRV, DirectX::XMMATRIX& projMatrix); - - void drawUI(); - -private: - void releaseResources(); - - GFSDK_SSAO_Parameters m_SSAOParameters; - - GFSDK_SSAO_Context_D3D11* m_SSAOContext; -}; - - -#endif
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererShadow.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererShadow.cpp deleted file mode 100644 index c26358b..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererShadow.cpp +++ /dev/null @@ -1,446 +0,0 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. - - -#include "RendererShadow.h" - -#include "XInput.h" -#include "DXUTMisc.h" -#include "DXUTCamera.h" -#include "Renderer.h" -#include "UIHelpers.h" -#include "SimpleScene.h" -#define CASCADES 1 - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Renderer Shadows (wrapper for shadow_lib) -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - -const float DEFAULT_LIGHT_SIZE = 3.0f; -const DirectX::XMFLOAT3 DEFAULT_LIGHT_POS(-25, 25, 25); -const DirectX::XMFLOAT3 DEFAULT_LIGHT_LOOK_AT(0, 0, 0); -const DirectX::XMFLOAT3 DEFAULT_SHADOW_COLOR(0.25f, 0.25f, 0.25f); - -RendererShadow::RendererShadow() -{ - m_shadowLibContext = NULL; - - m_PCSSEnabled = false; - m_lightSize = DEFAULT_LIGHT_SIZE; - m_lightPos = DEFAULT_LIGHT_POS; - m_lightLookAt = DEFAULT_LIGHT_LOOK_AT; - m_shadowColor = DEFAULT_SHADOW_COLOR; - - m_worldSpaceBBox0.x = m_worldSpaceBBox0.y = m_worldSpaceBBox0.z = -100; - m_worldSpaceBBox1.x = m_worldSpaceBBox1.y = m_worldSpaceBBox1.z = 100; - - // Penumbra params - m_PCSSParams.fMaxThreshold = 80.0f; - m_PCSSParams.fMaxClamp = 40.0f; - m_PCSSParams.fMinSizePercent = 3.0f; - m_PCSSParams.fMinWeightExponent = 5.0f; - m_PCSSParams.fMinWeightThresholdPercent = 20.0f; - - m_softShadowTestScale = 0.002f; - - memset(&m_shadowBufferSRV, 0, sizeof(m_shadowBufferSRV)); - - m_shadowMapHandle = NULL; - m_shadowBufferHandle = NULL; -} - - -RendererShadow::~RendererShadow() -{ - ReleaseResources(); -} - - -void RendererShadow::createResources(ID3D11Device *pd3dDevice, ID3D11DeviceContext* context, CFirstPersonCamera* camera) -{ - m_camera = camera; - -#if !CASCADES - uint32_t shadowMapScale = 5; - uint32_t shadowMapWidth = 1024; - uint32_t shadowMapHeight = 1024; - - // SM Desc - m_SMDesc.eViewType = GFSDK_ShadowLib_ViewType_Single; - m_SMDesc.eMapType = GFSDK_ShadowLib_MapType_Texture; -#else - - uint32_t shadowMapScale = 5; - uint32_t shadowMapWidth = 1024; - uint32_t shadowMapHeight = 1024; - - // SM Desc - m_SMDesc.eViewType = GFSDK_ShadowLib_ViewType_Cascades_2; - m_SMDesc.eMapType = GFSDK_ShadowLib_MapType_TextureArray; -#endif - - m_SMDesc.uResolutionWidth = shadowMapWidth * shadowMapScale; - m_SMDesc.uResolutionHeight = shadowMapHeight * shadowMapScale; - m_SMDesc.uArraySize = m_SMDesc.eViewType; - - for (int j = 0; j < GFSDK_ShadowLib_ViewType_Cascades_4; j++) - { - m_SMDesc.ViewLocation[j].uMapID = j; - m_SMDesc.ViewLocation[j].v2Origin.x = 0; - m_SMDesc.ViewLocation[j].v2Origin.y = 0; - m_SMDesc.ViewLocation[j].v2Dimension.x = shadowMapWidth * shadowMapScale; - m_SMDesc.ViewLocation[j].v2Dimension.y = shadowMapHeight * shadowMapScale; - } - - - // SM Render Params - m_SMRenderParams.iDepthBias = 1000; - m_SMRenderParams.fSlopeScaledDepthBias = 8; - - // SB Render Params - m_SBRenderParams.eTechniqueType = GFSDK_ShadowLib_TechniqueType_PCSS; - m_SBRenderParams.eQualityType = GFSDK_ShadowLib_QualityType_High; - - // DLL version - GFSDK_ShadowLib_Version DLLVersion; - GFSDK_ShadowLib_Status retCode = GFSDK_ShadowLib_GetDLLVersion(&DLLVersion); - - // Header version - GFSDK_ShadowLib_Version headerVersion; - headerVersion.uMajor = GFSDK_SHADOWLIB_MAJOR_VERSION; - headerVersion.uMinor = GFSDK_SHADOWLIB_MINOR_VERSION; - - // Do they match? - if (DLLVersion.uMajor == headerVersion.uMajor && DLLVersion.uMinor == headerVersion.uMinor) - { - GFSDK_ShadowLib_DeviceContext deviceAndContext; - deviceAndContext.pD3DDevice = pd3dDevice; - deviceAndContext.pDeviceContext = context; - - retCode = GFSDK_ShadowLib_Create(&headerVersion, &m_shadowLibContext, &deviceAndContext, NULL); - - if (retCode != GFSDK_ShadowLib_Status_Ok) assert(false); - } - else - { - assert(false); - } -} - - -void RendererShadow::ReleaseResources() -{ - SAFE_RELEASE(m_downsampledShadowMap.pTexture); - SAFE_RELEASE(m_downsampledShadowMap.pSRV); - SAFE_RELEASE(m_downsampledShadowMap.pRTV); - - if (m_shadowLibContext != NULL) - { - m_shadowLibContext->Destroy(); - m_shadowLibContext = NULL; - } -} - - -void RendererShadow::setScreenResolution(float FovyRad, UINT Width, UINT Height, UINT uSampleCount, ID3D11DepthStencilView* pReadOnlyDSV) -{ - changeShadowSettings(Width, Height, uSampleCount, pReadOnlyDSV); -} - - -void RendererShadow::changeShadowSettings(UINT Width, UINT Height, UINT uSampleCount, ID3D11DepthStencilView* pReadOnlyDSV) -{ - m_SBDesc.uResolutionWidth = Width; - m_SBDesc.uResolutionHeight = Height; - m_SBDesc.uSampleCount = uSampleCount; - m_SBDesc.ReadOnlyDSV.pDSV = pReadOnlyDSV; - - reloadBuffers(); -} - -void RendererShadow::reloadBuffers() -{ - { - if(m_shadowMapHandle != nullptr) - { - m_shadowLibContext->RemoveMap(&m_shadowMapHandle); - } - - if (m_SMDesc.eMapType == GFSDK_ShadowLib_MapType_Texture && - m_SMDesc.eViewType == GFSDK_ShadowLib_ViewType_Single && - m_SBRenderParams.eTechniqueType == GFSDK_ShadowLib_TechniqueType_PCSS) - { - m_SMDesc.bDownsample = true; - } - - m_shadowLibContext->AddMap(&m_SMDesc, &m_shadowMapHandle); - } - - if (m_SMDesc.eMapType == GFSDK_ShadowLib_MapType_Texture && m_SMDesc.eViewType == GFSDK_ShadowLib_ViewType_Single) - { - m_downsampledShadowMap.uWidth = m_SMDesc.uResolutionWidth >> 1; - m_downsampledShadowMap.uHeight = m_SMDesc.uResolutionHeight >> 1; - m_downsampledShadowMap.uSampleCount = 1; - m_downsampledShadowMap.Format = DXGI_FORMAT_R32_FLOAT; - SAFE_RELEASE(m_downsampledShadowMap.pTexture); - SAFE_RELEASE(m_downsampledShadowMap.pSRV); - SAFE_RELEASE(m_downsampledShadowMap.pRTV); - m_shadowLibContext->DevModeCreateTexture2D(&m_downsampledShadowMap); - } - - if (m_shadowBufferHandle != nullptr) - { - m_shadowLibContext->RemoveBuffer(&m_shadowBufferHandle); - } - m_shadowLibContext->AddBuffer(&m_SBDesc, &m_shadowBufferHandle); -} - - - -//-------------------------------------------------------------------------------------- -// Data passed to the shadow map render function -//-------------------------------------------------------------------------------------- -struct ShadowMapRenderFunctionParams -{ - Renderer* renderer; -}; -static ShadowMapRenderFunctionParams s_RenderParams; - -//-------------------------------------------------------------------------------------- -// Shadow map render function -//-------------------------------------------------------------------------------------- -static void ShadowMapRenderFunction(void* pParams, gfsdk_float4x4* pViewProj) -{ - ShadowMapRenderFunctionParams* pRP = (ShadowMapRenderFunctionParams*)pParams; - - DirectX::XMMATRIX viewProjection; - memcpy(&viewProjection, &pViewProj->_11, sizeof(gfsdk_float4x4)); - - pRP->renderer->renderDepthOnly(&viewProjection); -} - -void RendererShadow::renderShadowMaps(Renderer* renderer, atcore_float3& lightPos, atcore_float3& lightLookAt) -{ - // select technique - GFSDK_ShadowLib_TechniqueType technique = m_SBRenderParams.eTechniqueType; - m_SBRenderParams.eTechniqueType = m_PCSSEnabled ? GFSDK_ShadowLib_TechniqueType_PCSS : GFSDK_ShadowLib_TechniqueType_PCF; - if (technique != m_SBRenderParams.eTechniqueType) - reloadBuffers(); - - - DirectX::XMMATRIX viewMatrix = m_camera->GetViewMatrix(); - DirectX::XMMATRIX projMatrix = m_camera->GetProjMatrix(); - - memcpy(&m_SMRenderParams.m4x4EyeViewMatrix, &viewMatrix.r[0], sizeof(gfsdk_float4x4)); - memcpy(&m_SMRenderParams.m4x4EyeProjectionMatrix, &projMatrix.r[0], sizeof(gfsdk_float4x4)); - - // TODO: (better world space bbox needed) - m_SMRenderParams.v3WorldSpaceBBox[0] = m_worldSpaceBBox0; - m_SMRenderParams.v3WorldSpaceBBox[1] = m_worldSpaceBBox1; - - m_SMRenderParams.LightDesc.eLightType = GFSDK_ShadowLib_LightType_Directional; - memcpy(&m_SMRenderParams.LightDesc.v3LightPos, &lightPos, sizeof(gfsdk_float3)); - memcpy(&m_SMRenderParams.LightDesc.v3LightLookAt, &lightLookAt, sizeof(gfsdk_float3)); - m_SMRenderParams.LightDesc.fLightSize = m_lightSize; - m_SMRenderParams.LightDesc.bLightFalloff = false; - - // Scene specific setup for the shadow map phase that follows - s_RenderParams.renderer = renderer; - m_SMRenderParams.fnpDrawFunction = GFSDK_ShadowLib_FunctionPointer(ShadowMapRenderFunction); - m_SMRenderParams.pDrawFunctionParams = &s_RenderParams; - - // render shadow map - m_shadowLibContext->RenderMap(m_shadowMapHandle, &m_SMRenderParams); -} - - -void RendererShadow::renderShadowBuffer(ID3D11ShaderResourceView* pDepthStencilSRV, ID3D11ShaderResourceView* pResolvedDepthStencilSRV) -{ - if (m_SBRenderParams.eTechniqueType == GFSDK_ShadowLib_TechniqueType_PCSS && - m_SMDesc.eMapType == GFSDK_ShadowLib_MapType_Texture && - m_SMDesc.eViewType == GFSDK_ShadowLib_ViewType_Single) - { - m_tempResources.pDownsampledShadowMap = &m_downsampledShadowMap; - m_shadowLibContext->SetTempResources(&m_tempResources); - } - - m_SBRenderParams.PCSSPenumbraParams = m_PCSSParams; - m_SBRenderParams.fSoftShadowTestScale = m_softShadowTestScale; - - m_SBRenderParams.DepthBufferDesc.DepthStencilSRV.pSRV = pDepthStencilSRV; - - m_shadowLibContext->RenderBuffer(m_shadowMapHandle, m_shadowBufferHandle, &m_SBRenderParams); -} - - -void RendererShadow::modulateShadowBuffer(ID3D11RenderTargetView* pOutputRTV) -{ - GFSDK_ShadowLib_RenderTargetView ColorRTV; - ColorRTV.pRTV = pOutputRTV; - - gfsdk_float3 v3ShadowColor = { m_shadowColor.x, m_shadowColor.y, m_shadowColor.z }; - m_shadowLibContext->ModulateBuffer(m_shadowBufferHandle, &ColorRTV, v3ShadowColor, GFSDK_ShadowLib_ModulateBufferMask_RGB); -} - - -void RendererShadow::displayShadowMaps(ID3D11RenderTargetView* pOutputRTV, UINT Width, UINT Height) -{ - GFSDK_ShadowLib_RenderTargetView ColorRTV; - ColorRTV.pRTV = pOutputRTV; - - float fMapResW = (float)m_SMDesc.uResolutionWidth; - float fMapResH = (float)m_SMDesc.uResolutionHeight; - - float fWidthScale = Width / ((float)m_SMDesc.uArraySize * fMapResW); - fWidthScale = (fWidthScale > 1.0f) ? (1.0f) : (fWidthScale); - - float fOneFifth = (float)Height / (5.0f); - float fHeightScale = fOneFifth / fMapResH; - fHeightScale = (fHeightScale > 1.0f) ? (1.0f) : (fHeightScale); - - float fScale = (fHeightScale < fWidthScale) ? (fHeightScale) : (fWidthScale); - - fMapResW = floorf(fMapResW * fScale); - fMapResH = floorf(fMapResH * fScale); - - for (unsigned int j = 0; j < (unsigned int)m_SMDesc.uArraySize; j++) - { - m_shadowLibContext->DevModeDisplayMap(m_shadowBufferHandle, - &ColorRTV, - m_shadowMapHandle, - j, - j * (unsigned int)fMapResW + j, - Height - (unsigned int)fMapResH, - fScale); - } -} - - -void RendererShadow::displayMapFrustums(ID3D11RenderTargetView* pOutputRTV, ID3D11DepthStencilView* pDSV) -{ - gfsdk_float3 v3Color; - v3Color.x = 1.0f; - v3Color.y = 0.0f; - v3Color.z = 0.0f; - - GFSDK_ShadowLib_RenderTargetView ColorRTV; - ColorRTV.pRTV = pOutputRTV; - - GFSDK_ShadowLib_DepthStencilView DSV; - DSV.pDSV = pDSV; - - unsigned int NumViews; - NumViews = m_SMDesc.eViewType; - - for (unsigned int j = 0; j < NumViews; j++) - { - switch (j) - { - case 0: - v3Color.x = 1.0f; - v3Color.y = 0.0f; - v3Color.z = 0.0f; - break; - case 1: - v3Color.x = 0.0f; - v3Color.y = 1.0f; - v3Color.z = 0.0f; - break; - case 2: - v3Color.x = 0.0f; - v3Color.y = 0.0f; - v3Color.z = 1.0f; - break; - case 3: - v3Color.x = 1.0f; - v3Color.y = 1.0f; - v3Color.z = 0.0f; - break; - } - - m_shadowLibContext->DevModeDisplayMapFrustum(m_shadowBufferHandle, - &ColorRTV, - &DSV, - m_shadowMapHandle, - j, - v3Color); - } -} - - -void RendererShadow::displayShadowBuffer(ID3D11RenderTargetView* pOutputRTV) -{ - gfsdk_float2 v2Scale; - v2Scale.x = 1.0f; - v2Scale.y = 1.0f; - - GFSDK_ShadowLib_RenderTargetView ColorRTV; - ColorRTV.pRTV = pOutputRTV; - - m_shadowLibContext->DevModeDisplayBuffer(m_shadowBufferHandle, - &ColorRTV, - v2Scale, - NULL); -} - - -void RendererShadow::toggleDisplayCascades(bool bToggle) -{ - m_shadowLibContext->DevModeToggleDebugCascadeShader(m_shadowBufferHandle, - bToggle); -} - - -void RendererShadow::drawUI() -{ - ImGui::Checkbox("PCSS", &m_PCSSEnabled); - ImGui::ColorEdit3("Shadow Color", &(m_shadowColor.x)); - ImGui::DragFloat("Light Size", &m_lightSize, 0.05f, 0.0f, 100.0f); - ImGui::DragFloat3("Light Position", &(m_lightPos.x)); - ImGui_DragFloat3Dir("Light LookAt", &(m_lightLookAt.x)); - ImGui::DragFloat("SoftShadowTestScale", &(m_softShadowTestScale), 0.0001f, 0.0f, 10.0f); - if (m_PCSSEnabled) - { - ImGui::DragFloat("PCSS: fMaxClamp", &(m_PCSSParams.fMaxClamp), 0.001f, 0.0f, 100.0f); - ImGui::DragFloat("PCSS: fMaxThreshold", &(m_PCSSParams.fMaxThreshold), 0.001f, 0.0f, 100.0f); - ImGui::DragFloat("PCSS: fMinSizePercent", &(m_PCSSParams.fMinSizePercent), 0.001f, 0.0f, 100.0f); - ImGui::DragFloat("PCSS: fMinWeightExponent", &(m_PCSSParams.fMinWeightExponent), 0.001f, 0.0f, 100.0f); - ImGui::DragFloat("PCSS: fMinWeightThresholdPercent", &(m_PCSSParams.fMinWeightThresholdPercent), 0.001f, 0.0f, 100.0f); - ImGui::DragFloat("PCSS: fBlockerSearchDitherPercent", &(m_PCSSParams.fBlockerSearchDitherPercent), 0.001f, 0.0f, 100.0f); - ImGui::DragFloat("PCSS: fFilterDitherPercent", &(m_PCSSParams.fFilterDitherPercent), 0.001f, 0.0f, 100.0f); - } -} - -void RendererShadow::clearBuffer() -{ - m_shadowLibContext->ClearBuffer(m_shadowBufferHandle); -} - -void RendererShadow::finalizeBuffer() -{ - m_shadowLibContext->FinalizeBuffer(m_shadowBufferHandle, &m_shadowBufferSRV); -}
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererShadow.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererShadow.h deleted file mode 100644 index e16af1f..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/RendererShadow.h +++ /dev/null @@ -1,103 +0,0 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. - - -#ifndef RENDERER_SHADOW_H -#define RENDERER_SHADOW_H - -#include <DirectXMath.h> -#include "Utils.h" -#include "gfsdk_shadowlib.h" - -#include <string> - - -class CFirstPersonCamera; -class Renderer; - -class RendererShadow -{ -public: - RendererShadow(); - ~RendererShadow(); - - void createResources(ID3D11Device *pd3dDevice, ID3D11DeviceContext* context, CFirstPersonCamera* camera); - - void setScreenResolution(float FovyRad, UINT Width, UINT Height, UINT uSampleCount, ID3D11DepthStencilView* pReadOnlyDSV); - void changeShadowSettings(UINT Width, UINT Height, UINT uSampleCount, ID3D11DepthStencilView* pReadOnlyDSV); - void renderShadowMaps(Renderer* renderer, atcore_float3& lightPos, atcore_float3& lightLookAt); - void renderShadowBuffer(ID3D11ShaderResourceView* pDepthStencilSRV, ID3D11ShaderResourceView* pResolvedDepthStencilSRV); - void modulateShadowBuffer(ID3D11RenderTargetView* pOutputRTV); - void displayShadowMaps(ID3D11RenderTargetView* pOutputRTV, UINT Width, UINT Height); - void displayMapFrustums(ID3D11RenderTargetView* pOutputRTV, ID3D11DepthStencilView* pDSV); - void displayShadowBuffer(ID3D11RenderTargetView* pOutputRTV); - void toggleDisplayCascades(bool bToggle); - - - void drawUI(); - - void clearBuffer(); - void finalizeBuffer(); - -private: - void reloadBuffers(); - void ReleaseResources(); - - - GFSDK_ShadowLib_Context* m_shadowLibContext; - - GFSDK_ShadowLib_ShaderResourceView m_shadowBufferSRV; - - GFSDK_ShadowLib_Map* m_shadowMapHandle; - GFSDK_ShadowLib_MapDesc m_SMDesc; - GFSDK_ShadowLib_BufferDesc m_SBDesc; - GFSDK_ShadowLib_MapRenderParams m_SMRenderParams; - - GFSDK_ShadowLib_Buffer* m_shadowBufferHandle; - GFSDK_ShadowLib_BufferRenderParams m_SBRenderParams; - - GFSDK_ShadowLib_TempResources m_tempResources; - GFSDK_ShadowLib_Texture2D m_downsampledShadowMap; - - CFirstPersonCamera* m_camera; - - // params - bool m_PCSSEnabled; - float m_lightSize; - DirectX::XMFLOAT3 m_lightPos; - DirectX::XMFLOAT3 m_lightLookAt; - DirectX::XMFLOAT3 m_shadowColor; - GFSDK_ShadowLib_PCSSPenumbraParams m_PCSSParams; - float m_softShadowTestScale; - - gfsdk_float3 m_worldSpaceBBox0; - gfsdk_float3 m_worldSpaceBBox1; - -}; - - -#endif
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ResourceManager.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ResourceManager.cpp deleted file mode 100644 index d1d04e2..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ResourceManager.cpp +++ /dev/null @@ -1,291 +0,0 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. - - -#include "ResourceManager.h" -#include "PxAssert.h" -#include "PsString.h" -#include "Utils.h" - -#include <windows.h> - - -using namespace physx; - -#define PATH_MAX_LEN 512 - -// Add By Lixu Begin -ResourceManager* pResourceManager = nullptr; -ResourceManager* ResourceManager::ins() -{ - return pResourceManager; -} -// Add By Lixu End - -ResourceManager::ResourceManager() -{ - // search for root folder by default - addSearchDir("."); - -// Add By Lixu Begin - pResourceManager = this; -// Add By Lixu End -} - -const ShaderFileResource* ResourceManager::requestShaderFile(const char* name) -{ - const Resource* resource = requestResource(eSHADER_FILE, name); - return resource != nullptr ? static_cast<const ShaderFileResource*>(resource) : nullptr; -} - -const TextureResource* ResourceManager::requestTexture(const char* name) -{ - const Resource* resource = requestResource(eTEXTURE, name); - return resource != nullptr ? static_cast<const TextureResource*>(resource) : nullptr; -} - -void ResourceManager::releaseTexture(const char* name) -{ - std::pair<ResourceType, std::string> key(eTEXTURE, name); - auto val = m_loadedResources.find(key); - if (val != m_loadedResources.end()) - { - Resource* pResource = val->second; - delete pResource; - pResource = nullptr; - m_loadedResources.erase(key); - } -} - -const Resource* ResourceManager::requestResource(ResourceType type, const char* name) -{ - // search in loaded - std::pair<ResourceType, std::string> key(type, name); - auto val = m_loadedResources.find(key); - if (val != m_loadedResources.end()) - { - return val->second; - } - - Resource* resource = nullptr; - if (type == eSHADER_FILE) - { - char path[PATH_MAX_LEN]; - const char* exts[] = { "hlsl" }; - if (findFile(name, std::vector<const char*>(exts, exts + sizeof(exts) / sizeof(exts[0])), path)) - { - resource = new ShaderFileResource(path); - } - else - { - PX_ALWAYS_ASSERT_MESSAGE(name); - } - } - else if (type == eTEXTURE) - { - char path[PATH_MAX_LEN]; -// Add By Lixu Begin - const char* exts[] = { "dds", "tga", "jpg", "png", "bmp" }; -// Add By Lixu End - if (findFile(name, std::vector<const char*>(exts, exts + sizeof(exts) / sizeof(exts[0])), path)) - { - TextureResource* textureResource(new TextureResource()); - WCHAR wPath[MAX_PATH]; - MultiByteToWideChar(CP_ACP, 0, path, -1, wPath, MAX_PATH); - wPath[MAX_PATH - 1] = 0; - - const char* ext = strext(path); - if (::stricmp(ext, "dds") == 0) - { - V(DirectX::LoadFromDDSFile(wPath, DirectX::DDS_FLAGS_NONE, &textureResource->metaData, - textureResource->image)); - } - else if (::stricmp(ext, "tga") == 0) - { - V(DirectX::LoadFromTGAFile(wPath, &textureResource->metaData, - textureResource->image)); - } -// Add By Lixu Begin - else if (::stricmp(ext, "jpg") == 0) - { - V(DirectX::LoadFromWICFile(wPath, DirectX::TEX_FILTER_DEFAULT | DirectX::WIC_FLAGS_ALL_FRAMES, &textureResource->metaData, - textureResource->image)); - } - else if (::stricmp(ext, "png") == 0) - { - V(DirectX::LoadFromWICFile(wPath, DirectX::TEX_FILTER_DEFAULT | DirectX::WIC_FLAGS_ALL_FRAMES, &textureResource->metaData, - textureResource->image)); - } - else if (::stricmp(ext, "bmp") == 0) - { - V(DirectX::LoadFromWICFile(wPath, DirectX::TEX_FILTER_DEFAULT | DirectX::WIC_FLAGS_ALL_FRAMES, &textureResource->metaData, - textureResource->image)); - } -// Add By Lixu End - else - { - PX_ALWAYS_ASSERT_MESSAGE("Unsupported texture extension"); - } - resource = textureResource; - } - } - - if (resource) - { - m_loadedResources.emplace(key, resource); - return resource; - } - else - { - PX_ALWAYS_ASSERT_MESSAGE(name); - return nullptr; - } -} - -bool dirExists(const char* dir) -{ - DWORD ftyp = GetFileAttributesA(dir); - if (ftyp == INVALID_FILE_ATTRIBUTES) - return false; // something is wrong with path! - - if (ftyp & FILE_ATTRIBUTE_DIRECTORY) - return true; // this is a directory! - - return false; // this is not a directory! -} - -bool ResourceManager::addSearchDir(const char* dir, bool recursive) -{ - if (dirExists(dir)) - { - m_searchDirs.push_back(SearchDir(dir, recursive)); - return true; - } - return false; -} - - -ResourceManager::~ResourceManager() -{ -} - - -bool ResourceManager::findFileInDir(std::string fileNameFull, const char* path, bool recursive, char* foundPath) -{ - WIN32_FIND_DATAA ffd; - char tmp[PATH_MAX_LEN]; - shdfnd::snprintf(tmp, sizeof(tmp), "%s\\*", path); - HANDLE hFind = FindFirstFileA(tmp, &ffd); - - if(INVALID_HANDLE_VALUE == hFind) - { - return NULL; - } - - do - { - if (0 == shdfnd::strcmp(".", ffd.cFileName) || 0 == shdfnd::strcmp("..", ffd.cFileName)) - continue; - - if(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - { - shdfnd::snprintf(tmp, sizeof(tmp), "%s\\%s", path, ffd.cFileName); - if(findFileInDir(fileNameFull, tmp, recursive, foundPath)) - return true; - } - else if (shdfnd::stricmp(ffd.cFileName, fileNameFull.c_str()) == 0) - { - shdfnd::snprintf(foundPath, PATH_MAX_LEN, "%s\\%s", path, ffd.cFileName); - return true; - } - } while(FindNextFileA(hFind, &ffd) != 0); - // release handle - FindClose(hFind); - return false; -} - -bool ResourceManager::findFile(std::string fileName, const std::vector<const char*>& exts, char* foundPath) -{ - std::string fileNameOnly = fileName; - - std::string::size_type pos = 0; - pos = fileNameOnly.find("\\", pos); - while ((pos != std::string::npos)) - { - fileNameOnly.replace(pos, 1, "/"); - pos = fileNameOnly.find("\\", (pos + 1)); - } - - size_t ind = fileNameOnly.find_last_of('/'); - if (ind > 0 && (ind != std::string::npos)) - fileNameOnly = fileNameOnly.substr(ind + 1); - -// Add By Lixu Begin - std::string fileDir = "."; - size_t fl = fileName.length(); - if (ind >= 0 && ind < fl) - fileDir = fileName.substr(0, ind); - if (findFileInDir(fileNameOnly.c_str(), fileDir.c_str(), true, foundPath)) - return true; -// Add By Lixu End - - for(size_t i = 0; i < m_searchDirs.size(); i++) - { - const SearchDir& searchDir = m_searchDirs[i]; - - for(size_t j = 0; j < exts.size(); j++) - { - const char* ext = exts[j]; - const uint32_t fileMaxLen = 128; - char fileNameFull[fileMaxLen] = { 0 }; - - physx::shdfnd::snprintf(fileNameFull, fileMaxLen, "%s.%s", fileNameOnly.c_str(), ext); - if(findFileInDir(fileNameFull, searchDir.path.c_str(), searchDir.recursive, foundPath)) - return true; - } - - if (findFileInDir(fileNameOnly.c_str(), searchDir.path.c_str(), searchDir.recursive, foundPath)) - return true; - } - return false; -} - -bool ResourceManager::findFile(std::string fileName, std::string& foundPath) -{ - std::vector<const char*> exts; - char path[PATH_MAX_LEN]; - if (findFile(fileName, exts, path)) - { - foundPath = path; - return true; - } - else - { - return false; - } -} - diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ResourceManager.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ResourceManager.h deleted file mode 100644 index 697b16b..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ResourceManager.h +++ /dev/null @@ -1,117 +0,0 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. - - -#ifndef RESOURCE_MANAGER_H -#define RESOURCE_MANAGER_H - -#include <vector> -#include <string> -#include <map> -#include <memory> -#include "DirectXTex.h" - - -struct Resource -{ -private: - Resource& operator = (const Resource&); -}; - - -struct ShaderFileResource : public Resource -{ - ShaderFileResource(const std::string& p) : path(p) {} - std::string path; -}; - - -struct TextureResource : public Resource -{ - DirectX::TexMetadata metaData; - DirectX::ScratchImage image; -}; - - -/** -ResourceManager used to look for files in provided dirs (see addSearchDir). Also it loads resources and caches them. -*/ -class ResourceManager -{ -public: - //////// ctor //////// - - ResourceManager(); - ~ResourceManager(); - -// Add By Lixu Begin - static ResourceManager* ins(); -// Add By Lixu End - - //////// public API //////// - - bool addSearchDir(const char* dir, bool recursive = true); - - const ShaderFileResource* requestShaderFile(const char* name); - - const TextureResource* requestTexture(const char* name); - - void releaseTexture(const char* name); - - bool findFile(std::string fileName, std::string& foundPath); - - bool findFile(std::string fileName, const std::vector<const char*>& exts, char* foundPath); - - -private: - //////// internal methods //////// - - enum ResourceType - { - eSHADER_FILE, - eTEXTURE - }; - - const Resource* requestResource(ResourceType type, const char* name); - - bool findFileInDir(std::string fileNameFull, const char* path, bool recursive, char* foundPath); - - struct SearchDir - { - SearchDir(std::string path_, bool recursive_) : path(path_), recursive(recursive_) {} - - std::string path; - bool recursive; - }; - - - //////// internal data //////// - - std::vector<SearchDir> m_searchDirs; - std::map<std::pair<ResourceType, std::string>, Resource*> m_loadedResources; -}; -#endif
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ShaderUtils.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ShaderUtils.h deleted file mode 100644 index da9caa0..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/ShaderUtils.h +++ /dev/null @@ -1,117 +0,0 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. - - -#ifndef SHADER_UTILS_H -#define SHADER_UTILS_H - -#include "Utils.h" -#include <d3dcompiler.h> - - -static HRESULT CompileShaderFromFile(const char* szFileName, LPCSTR szEntryPoint, LPCSTR szShaderModel, - ID3DBlob** ppBlobOut) -{ - HRESULT hr = S_OK; - ID3DBlob* pErrorBlob = NULL; - - WCHAR wFileName[MAX_PATH]; - MultiByteToWideChar(CP_ACP, 0, szFileName, -1, wFileName, MAX_PATH); - wFileName[MAX_PATH - 1] = 0; - hr = D3DCompileFromFile(wFileName, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, szEntryPoint, szShaderModel, D3D10_SHADER_ENABLE_STRICTNESS, 0, - ppBlobOut, &pErrorBlob); - if(FAILED(hr)) - { - OutputDebugStringA((char*)pErrorBlob->GetBufferPointer()); - SAFE_RELEASE(pErrorBlob); - return hr; - } - SAFE_RELEASE(pErrorBlob); - - return S_OK; -} - -static HRESULT createShader(ID3D11Device* pDev, const void* pData, size_t len, ID3D11VertexShader** ppShd, bool) -{ - return pDev->CreateVertexShader(pData, len, nullptr, ppShd); -} - -static HRESULT createShader(ID3D11Device* pDev, const void* pData, size_t len, ID3D11GeometryShader** ppShd, - bool forceFast) -{ - PX_UNUSED(forceFast); - return pDev->CreateGeometryShader(pData, len, nullptr, ppShd); -} - -static HRESULT createShader(ID3D11Device* pDev, const void* pData, size_t len, ID3D11PixelShader** ppShd, bool) -{ - return pDev->CreatePixelShader(pData, len, nullptr, ppShd); -} - -static const char* shaderModel(ID3D11VertexShader**) -{ - return "vs_5_0"; -} - -static const char* shaderModel(ID3D11GeometryShader**) -{ - return "gs_5_0"; -} - -static const char* shaderModel(ID3D11PixelShader**) -{ - return "ps_5_0"; -} - -// Give back the shader buffer blob for use in CreateVertexLayout. Caller must release the blob. -template <class S> -static HRESULT createShaderFromFile(ID3D11Device* pDev, const char* szFileName, LPCSTR szEntryPoint, S** ppShd, - ID3DBlob*& pShaderBuffer, bool forceFast = false) -{ - HRESULT hr = CompileShaderFromFile(szFileName, szEntryPoint, shaderModel(ppShd), &pShaderBuffer); - if(SUCCEEDED(hr) && pShaderBuffer) - { - const void* shaderBufferData = pShaderBuffer->GetBufferPointer(); - const UINT shaderBufferSize = pShaderBuffer->GetBufferSize(); - createShader(pDev, shaderBufferData, shaderBufferSize, ppShd, forceFast); - } - return hr; -} - -// Overloaded, same as above but don't give back the shader buffer blob. -template <class S> -static HRESULT createShaderFromFile(ID3D11Device* pDev, const char* szFileName, LPCSTR szEntryPoint, S** ppShd, - bool forceFast = false) -{ - ID3DBlob* pShaderBuffer = NULL; - HRESULT hr = createShaderFromFile(pDev, szFileName, szEntryPoint, ppShd, pShaderBuffer, forceFast); - SAFE_RELEASE(pShaderBuffer); - return hr; -} - - -#endif //SHADER_UTILS_H
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/SkinnedRenderMesh.cpp b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/SkinnedRenderMesh.cpp deleted file mode 100644 index ff121d6..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/SkinnedRenderMesh.cpp +++ /dev/null @@ -1,234 +0,0 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. - - -#include "SkinnedRenderMesh.h" -#include "Renderer.h" - -SkinnedRenderMesh::SkinnedRenderMesh(const std::vector<const SimpleMesh*>& meshes) -{ - PX_ASSERT_WITH_MESSAGE(meshes.size() <= MeshesCountMax, "meshes.size() have to be <= SkinnedRenderMesh::MeshesCountMax"); - - m_device = GetDeviceManager()->GetDevice(); - - // input element desc setup - m_inputDesc.push_back({ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }); - m_inputDesc.push_back({ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }); - m_inputDesc.push_back({ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 }); - m_inputDesc.push_back({ "TEXCOORD", 1, DXGI_FORMAT_R32_UINT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }); - - // reserve VB - uint32_t verticesTotal = 0; - std::for_each(meshes.begin(), meshes.end(), [&](const SimpleMesh* c) { verticesTotal += (uint32_t)c->vertices.size(); }); - std::vector<SimpleMesh::Vertex> vertexBuffer; - vertexBuffer.reserve(verticesTotal); - - // reserve IB - uint32_t indicesTotal = 0; - std::for_each(meshes.begin(), meshes.end(), [&](const SimpleMesh* c) { indicesTotal += (uint32_t)c->indices.size(); }); - m_indices.reserve(indicesTotal); - - // fill VB, IB, MeshInfo - m_meshesInfo.resize(meshes.size()); - for (uint32_t meshIndex = 0; meshIndex < meshes.size(); ++meshIndex) - { - const SimpleMesh* mesh = meshes[meshIndex]; - MeshInfo& meshInfo = m_meshesInfo[meshIndex]; - - meshInfo.firstVertex = (uint32_t)vertexBuffer.size(); - vertexBuffer.insert(vertexBuffer.end(), mesh->vertices.begin(), mesh->vertices.end()); - meshInfo.verticesCount = (uint32_t)mesh->vertices.size(); - - meshInfo.firstIndex = (uint32_t)m_indices.size(); - uint32_t indexOffset = meshInfo.firstVertex; - for (uint32_t index : mesh->indices) - { - m_indices.push_back((uint32_t)index + indexOffset); - } - meshInfo.indicesCount = (uint32_t)mesh->indices.size(); - } - - // vertex buffer - { - D3D11_SUBRESOURCE_DATA vertexBufferData; - - ZeroMemory(&vertexBufferData, sizeof(vertexBufferData)); - vertexBufferData.pSysMem = vertexBuffer.data(); - - D3D11_BUFFER_DESC bufferDesc; - - memset(&bufferDesc, 0, sizeof(D3D11_BUFFER_DESC)); - bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; - bufferDesc.ByteWidth = (uint32_t)(sizeof(SimpleMesh::Vertex) * vertexBuffer.size()); - bufferDesc.CPUAccessFlags = 0; - bufferDesc.MiscFlags = 0; - bufferDesc.Usage = D3D11_USAGE_IMMUTABLE; - - V(m_device->CreateBuffer(&bufferDesc, &vertexBufferData, &m_vertexBuffer)); - } - - // bone index buffer - { - D3D11_BUFFER_DESC bufferDesc; - - memset(&bufferDesc, 0, sizeof(D3D11_BUFFER_DESC)); - bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; - bufferDesc.ByteWidth = (uint32_t)(sizeof(uint32_t) * vertexBuffer.size()); - bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - bufferDesc.MiscFlags = 0; - bufferDesc.Usage = D3D11_USAGE_DYNAMIC; - - V(m_device->CreateBuffer(&bufferDesc, nullptr, &m_boneIndexBuffer)); - } - - // index buffer - { - D3D11_BUFFER_DESC bufferDesc; - - memset(&bufferDesc, 0, sizeof(D3D11_BUFFER_DESC)); - bufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER; - bufferDesc.ByteWidth = (uint32_t)(sizeof(uint32_t) * m_indices.size()); - bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - bufferDesc.MiscFlags = 0; - bufferDesc.Usage = D3D11_USAGE_DYNAMIC; - - V(m_device->CreateBuffer(&bufferDesc, nullptr, &m_indexBuffer)); - } - - // bone texture - { - D3D11_TEXTURE2D_DESC desc; - ZeroMemory(&desc, sizeof(desc)); - desc.Width = 4; - desc.Height = (uint32_t)meshes.size(); - desc.MipLevels = 1; - desc.ArraySize = 1; - desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; - desc.SampleDesc.Count = 1; - desc.SampleDesc.Quality = 0; - desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - desc.Usage = D3D11_USAGE_DYNAMIC; - desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; - - V(m_device->CreateTexture2D(&desc, nullptr, &m_boneTexture)); - } - - // bone texture SRV - { - D3D11_SHADER_RESOURCE_VIEW_DESC desc; - ZeroMemory(&desc, sizeof(desc)); - desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; - desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; - desc.Texture2D.MipLevels = 1; - desc.Texture2D.MostDetailedMip = 0; - V(m_device->CreateShaderResourceView(m_boneTexture, &desc, &m_boneTextureSRV)); - } -} - -SkinnedRenderMesh::~SkinnedRenderMesh() -{ - SAFE_RELEASE(m_vertexBuffer); - SAFE_RELEASE(m_boneIndexBuffer); - SAFE_RELEASE(m_indexBuffer); - SAFE_RELEASE(m_boneTexture); - SAFE_RELEASE(m_boneTextureSRV); -} - -void SkinnedRenderMesh::updateVisibleMeshes(const std::vector<uint32_t>& visibleMeshes) -{ - ID3D11DeviceContext* context; - m_device->GetImmediateContext(&context); - - // update bone index buffer - { - D3D11_MAPPED_SUBRESOURCE mappedRead; - V(context->Map(m_boneIndexBuffer, 0, D3D11_MAP_WRITE_DISCARD, NULL, &mappedRead)); - - uint32_t* boneIndexBuffer = (uint32_t*)mappedRead.pData; - for (uint32_t i = 0; i < visibleMeshes.size(); ++i) - { - const MeshInfo& info = m_meshesInfo[visibleMeshes[i]]; - for (uint32_t v = info.firstVertex; v < info.firstVertex + info.verticesCount; ++v) - { - boneIndexBuffer[v] = i; - } - } - - context->Unmap(m_boneIndexBuffer, 0); - } - - // update index buffer - { - D3D11_MAPPED_SUBRESOURCE mappedRead; - V(context->Map(m_indexBuffer, 0, D3D11_MAP_WRITE_DISCARD, NULL, &mappedRead)); - - uint32_t* indexBuffer = (uint32_t*)mappedRead.pData; - uint32_t indexCount = 0; - for (uint32_t meshIndex : visibleMeshes) - { - const MeshInfo& info = m_meshesInfo[meshIndex]; - memcpy(indexBuffer + indexCount, &m_indices[info.firstIndex], info.indicesCount * sizeof(uint32_t)); - indexCount += info.indicesCount; - } - context->Unmap(m_indexBuffer, 0); - m_indexCount = indexCount; - PX_ASSERT(m_indexCount % 3 == 0); - } -} - -void SkinnedRenderMesh::updateVisibleMeshTransforms(std::vector<PxMat44>& transforms) -{ - ID3D11DeviceContext* context; - m_device->GetImmediateContext(&context); - - // update bone transform texture - { - D3D11_MAPPED_SUBRESOURCE mappedRead; - V(context->Map(m_boneTexture, 0, D3D11_MAP_WRITE_DISCARD, NULL, &mappedRead)); - for (uint32_t i = 0; i < transforms.size(); ++i) - { - std::memcpy((uint8_t*)mappedRead.pData + i * mappedRead.RowPitch, &transforms[i], sizeof(PxMat44)); - } - context->Unmap(m_boneTexture, 0); - } -} - -void SkinnedRenderMesh::render(ID3D11DeviceContext& context) const -{ - context.IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); - - UINT strides[2] = { sizeof(SimpleMesh::Vertex), sizeof(uint32_t) }; - UINT offsets[2] = { 0 }; - ID3D11Buffer* buffers[2] = { m_vertexBuffer, m_boneIndexBuffer }; - context.IASetVertexBuffers(0, 2, buffers, strides, offsets); - - context.IASetIndexBuffer(m_indexBuffer, DXGI_FORMAT_R32_UINT, 0); - - context.VSSetShaderResources(1, 1, &m_boneTextureSRV); - - context.DrawIndexed(m_indexCount, 0, 0); -}
\ No newline at end of file diff --git a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/SkinnedRenderMesh.h b/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/SkinnedRenderMesh.h deleted file mode 100644 index f3643d8..0000000 --- a/tools/ArtistTools/source/BlastPlugin/SampleBase/renderer/SkinnedRenderMesh.h +++ /dev/null @@ -1,100 +0,0 @@ -// This code contains NVIDIA Confidential Information and is disclosed to you -// under a form of NVIDIA software license agreement provided separately to you. -// -// Notice -// NVIDIA Corporation and its licensors retain all intellectual property and -// proprietary rights in and to this software and related documentation and -// any modifications thereto. Any use, reproduction, disclosure, or -// distribution of this software and related documentation without an express -// license agreement from NVIDIA Corporation is strictly prohibited. -// -// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES -// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO -// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, -// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. -// -// Information and code furnished is believed to be accurate and reliable. -// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such -// information or for any infringement of patents or other rights of third parties that may -// result from its use. No license is granted by implication or otherwise under any patent -// or patent rights of NVIDIA Corporation. Details are subject to change without notice. -// This code supersedes and replaces all information previously supplied. -// NVIDIA Corporation products are not authorized for use as critical -// components in life support devices or systems without express written approval of -// NVIDIA Corporation. -// -// Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved. - - -#ifndef SKINNED_RENDER_MESH_H -#define SKINNED_RENDER_MESH_H - -#include "Utils.h" -#include <DirectXMath.h> - -#include <vector> -#include "Renderable.h" -#include "Mesh.h" - -/** -SkinnedRenderMesh: - bonde indices are passed as vertex input, - bone transforms are stored in texture - max bone meshes count: SkinnedRenderMesh::MeshesCountMax -*/ -class SkinnedRenderMesh : public IRenderMesh -{ -public: - //////// ctor //////// - - SkinnedRenderMesh(const std::vector<const SimpleMesh*>& meshes); - ~SkinnedRenderMesh(); - - - //////// const //////// - - static const uint32_t MeshesCountMax = D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION; - - - //////// public API //////// - - void updateVisibleMeshes(const std::vector<uint32_t>& visibleMeshes); - void updateVisibleMeshTransforms(std::vector<PxMat44>& transforms); - - - //////// IRenderMesh implementation //////// - - virtual const std::vector<D3D11_INPUT_ELEMENT_DESC>& getInputElementDesc() const { return m_inputDesc; } - virtual void render(ID3D11DeviceContext& context) const; - -private: - //////// internal data //////// - - struct MeshInfo - { - uint32_t firstIndex; - uint32_t indicesCount; - - uint32_t firstVertex; - uint32_t verticesCount; - }; - - std::vector<D3D11_INPUT_ELEMENT_DESC> m_inputDesc; - - ID3D11Device* m_device; - - ID3D11Buffer* m_vertexBuffer; - ID3D11Buffer* m_boneIndexBuffer; - ID3D11Buffer* m_indexBuffer; - ID3D11Texture2D* m_boneTexture; - ID3D11ShaderResourceView* m_boneTextureSRV; - - uint32_t m_indexCount; - - std::vector<MeshInfo> m_meshesInfo; - std::vector<uint32_t> m_indices; -}; - - - -#endif //SKINNED_RENDER_MESH_H
\ No newline at end of file |