grafika-color kezdő
This commit is contained in:
		
							parent
							
								
									89ca072b2d
								
							
						
					
					
						commit
						8b67a40e55
					
				@ -388,14 +388,15 @@ namespace eg3d {
 | 
				
			|||||||
	void DXWindow::createRootSignature()
 | 
						void DXWindow::createRootSignature()
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		// root paraméterek létrehozása
 | 
							// root paraméterek létrehozása
 | 
				
			||||||
		CD3DX12_ROOT_PARAMETER slotParams[1];
 | 
							CD3DX12_ROOT_PARAMETER slotParams[2];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// TODO worldMatrix konstansbufferének hozzáadása
 | 
							// TODO worldMatrix konstansbufferének hozzáadása
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// konstansbuffer-TÍPUS beállítása
 | 
							// konstansbuffer-TÍPUS beállítása
 | 
				
			||||||
		slotParams[0].InitAsConstantBufferView(0);
 | 
							slotParams[0].InitAsConstantBufferView(0);
 | 
				
			||||||
 | 
							slotParams[1].InitAsConstantBufferView(1);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		CD3DX12_ROOT_SIGNATURE_DESC rsD(1, &slotParams[0], 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);
 | 
							CD3DX12_ROOT_SIGNATURE_DESC rsD(2, &slotParams[0], 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		ComPtr<ID3DBlob> serializedRS = nullptr, errorBlob = nullptr;
 | 
							ComPtr<ID3DBlob> serializedRS = nullptr, errorBlob = nullptr;
 | 
				
			||||||
		if (FAILED(D3D12SerializeRootSignature(&rsD, D3D_ROOT_SIGNATURE_VERSION_1, serializedRS.GetAddressOf(), errorBlob.GetAddressOf())))
 | 
							if (FAILED(D3D12SerializeRootSignature(&rsD, D3D_ROOT_SIGNATURE_VERSION_1, serializedRS.GetAddressOf(), errorBlob.GetAddressOf())))
 | 
				
			||||||
 | 
				
			|||||||
@ -82,7 +82,7 @@ namespace eg3d {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // TODO konstansbuffer példány és DX-objektum
 | 
					        // TODO konstansbuffer példány és DX-objektum
 | 
				
			||||||
		ComPtr<ID3D12Resource> cbResource; // konstansbuffer DX-objektuma
 | 
							ComPtr<ID3D12Resource> cbResource; // konstansbuffer DX-objektuma
 | 
				
			||||||
		ConstantBuffer constantBuffer; // konstansbuffer
 | 
							CB_Frame constantBuffer; // konstansbuffer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// virtuális kamera
 | 
							// virtuális kamera
 | 
				
			||||||
		Cam * pCam;
 | 
							Cam * pCam;
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										27
									
								
								Entity.cpp
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								Entity.cpp
									
									
									
									
									
								
							@ -5,17 +5,20 @@
 | 
				
			|||||||
#include "Entity.h"
 | 
					#include "Entity.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
eg3d::Entity::Entity(const ComPtr<ID3D12Device> &device) : Geometry(device) {
 | 
					eg3d::Entity::Entity(const ComPtr<ID3D12Device> &device) : Geometry(device) {
 | 
				
			||||||
 | 
						createConstantBuffer();
 | 
				
			||||||
    loadDefaults();
 | 
					    loadDefaults();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
eg3d::Entity::Entity(const Entity& other): Geometry(other.device)
 | 
					eg3d::Entity::Entity(const Entity& other): Geometry(other.device)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						createConstantBuffer();
 | 
				
			||||||
	setEntitySRT(other.getEntitySRT());
 | 
						setEntitySRT(other.getEntitySRT());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void eg3d::Entity::loadDefaults() {
 | 
					void eg3d::Entity::loadDefaults() {
 | 
				
			||||||
    XMStoreFloat4x4(&mWorldMatrix, XMMatrixIdentity()); // egységmátrix betöltése a világ-mátrixba
 | 
					    XMStoreFloat4x4(&mConstBuf.worldMatrix, XMMatrixIdentity()); // egységmátrix betöltése a világ-mátrixba
 | 
				
			||||||
	mSRTProps.loadDefaults();
 | 
						mSRTProps.loadDefaults();
 | 
				
			||||||
 | 
						constructWorldMatrix();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void eg3d::Entity::setEntitySRT(const eg3d::SRTProps &srtProps) {
 | 
					void eg3d::Entity::setEntitySRT(const eg3d::SRTProps &srtProps) {
 | 
				
			||||||
@ -30,16 +33,34 @@ eg3d::SRTProps eg3d::Entity::getEntitySRT() const {
 | 
				
			|||||||
void eg3d::Entity::draw(ComPtr<ID3D12GraphicsCommandList> commandList) const
 | 
					void eg3d::Entity::draw(ComPtr<ID3D12GraphicsCommandList> commandList) const
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	// TODO konstansbuffer becsatolása
 | 
						// TODO konstansbuffer becsatolása
 | 
				
			||||||
 | 
						commandList->SetGraphicsRootConstantBufferView(1, mConstBufRes->GetGPUVirtualAddress());
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						Geometry::draw(commandList);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void eg3d::Entity::constructWorldMatrix() {
 | 
					void eg3d::Entity::constructWorldMatrix() {
 | 
				
			||||||
    // TODO (Cam alapján)
 | 
					    // TODO (Cam alapján)
 | 
				
			||||||
	// XMMATRIX w = s * r * t
 | 
					 | 
				
			||||||
	// XMStoreFloat4x4(...)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						auto scaling = mSRTProps.scaling;
 | 
				
			||||||
 | 
						auto rotation = mSRTProps.rotation;
 | 
				
			||||||
 | 
						auto translation = mSRTProps.translation;
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
 | 
						XMMATRIX w = XMMatrixTranslation(translation.x, translation.y, translation.z) *
 | 
				
			||||||
 | 
							XMMatrixRotationX(rotation.x) * XMMatrixRotationY(rotation.y) * XMMatrixRotationZ(rotation.z) *
 | 
				
			||||||
 | 
							XMMatrixScaling(scaling.x, scaling.y, scaling.z);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						w = XMMatrixTranspose(w);
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						XMStoreFloat4x4(&mConstBuf.worldMatrix, w);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// konstansbuffer felmásolása a videokártyára
 | 
				
			||||||
 | 
						bufferMapCopy(mConstBufRes, static_cast<void*>(&mConstBuf), sizeof(CB_Entity));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void eg3d::Entity::createConstantBuffer()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						mConstBufRes = createBuffer_UH(device, calc256AlignedSize(sizeof(CB_Entity)));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ----------------------
 | 
					// ----------------------
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										5
									
								
								Entity.h
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								Entity.h
									
									
									
									
									
								
							@ -7,6 +7,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "Geometry.h"
 | 
					#include "Geometry.h"
 | 
				
			||||||
#include "IHasDefault.h"
 | 
					#include "IHasDefault.h"
 | 
				
			||||||
 | 
					#include "const_bufs.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace eg3d {
 | 
					namespace eg3d {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -22,12 +23,14 @@ namespace eg3d {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    class Entity : public Geometry, public IHasDefault {
 | 
					    class Entity : public Geometry, public IHasDefault {
 | 
				
			||||||
    private:
 | 
					    private:
 | 
				
			||||||
        DirectX::XMFLOAT4X4 mWorldMatrix; // világ-mátrix
 | 
							ComPtr<ID3D12Resource> mConstBufRes; // konstansbuffer erõforrás a videokártyán
 | 
				
			||||||
 | 
							CB_Entity mConstBuf; // konstansbuffer
 | 
				
			||||||
        SRTProps mSRTProps; // STR-tulajdonságok
 | 
					        SRTProps mSRTProps; // STR-tulajdonságok
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        void constructWorldMatrix(); // világ-mátrix újragenerálása
 | 
					        void constructWorldMatrix(); // világ-mátrix újragenerálása
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    	// TODO konstansbuffer létrehozása, feltöltése
 | 
					    	// TODO konstansbuffer létrehozása, feltöltése
 | 
				
			||||||
 | 
							void createConstantBuffer(); // konstansbuffer létrehozása
 | 
				
			||||||
    public:
 | 
					    public:
 | 
				
			||||||
        Entity(const ComPtr<ID3D12Device> &device);
 | 
					        Entity(const ComPtr<ID3D12Device> &device);
 | 
				
			||||||
		explicit Entity(const Entity& other); // másolókonstruktor
 | 
							explicit Entity(const Entity& other); // másolókonstruktor
 | 
				
			||||||
 | 
				
			|||||||
@ -10,18 +10,22 @@ struct VSOutput // vertex shader kimeneti strukt
 | 
				
			|||||||
    float3 color : COLOR;
 | 
					    float3 color : COLOR;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
cbuffer CBuf : register(b0)
 | 
					cbuffer CFrame : register(b0)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    float4x4 transformMatrix;
 | 
					    float4x4 transformMatrix;
 | 
				
			||||||
    float4x4 viewMatrix;
 | 
					    float4x4 viewMatrix;
 | 
				
			||||||
    float4x4 projMatrix;
 | 
					    float4x4 projMatrix;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					cbuffer CEntity : register(b1)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    float4x4 worldMatrix;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
VSOutput vs_main(VSInput input)
 | 
					VSOutput vs_main(VSInput input)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    VSOutput output; // vertex shader kimenete
 | 
					    VSOutput output; // vertex shader kimenete
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    output.position_H = mul(float4(input.position_D, 1.0), mul(viewMatrix, projMatrix));
 | 
					    output.position_H = mul(float4(input.position_D, 1.0), mul(worldMatrix, mul(viewMatrix, projMatrix)));
 | 
				
			||||||
    output.color = float3(1.0, 1.0, 1.0);
 | 
					    output.color = float3(1.0, 1.0, 1.0);
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    return output;
 | 
					    return output;
 | 
				
			||||||
 | 
				
			|||||||
@ -9,7 +9,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// konstansbuffer struktúrája
 | 
					// konstansbuffer struktúrája
 | 
				
			||||||
// TODO refactor!
 | 
					// TODO refactor!
 | 
				
			||||||
struct ConstantBuffer
 | 
					struct CB_Frame
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    DirectX::XMFLOAT4X4 transformMatrix;
 | 
					    DirectX::XMFLOAT4X4 transformMatrix;
 | 
				
			||||||
    DirectX::XMFLOAT4X4 viewMatrix; // nézet-mátrix
 | 
					    DirectX::XMFLOAT4X4 viewMatrix; // nézet-mátrix
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										19
									
								
								main.cpp
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								main.cpp
									
									
									
									
									
								
							@ -13,6 +13,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "Timer.h"
 | 
					#include "Timer.h"
 | 
				
			||||||
#include "Geometry.h"
 | 
					#include "Geometry.h"
 | 
				
			||||||
 | 
					#include "Entity.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// FPS-mérés
 | 
					// FPS-mérés
 | 
				
			||||||
size_t gFrames = 0;
 | 
					size_t gFrames = 0;
 | 
				
			||||||
@ -71,6 +72,18 @@ void mouseCB(EventHandlerCBData * pCBData)
 | 
				
			|||||||
	LOG("Mouse clicked!");
 | 
						LOG("Mouse clicked!");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// TODO új entitás behozása a kamera pozíciójára
 | 
						// TODO új entitás behozása a kamera pozíciójára
 | 
				
			||||||
 | 
						DXWindow * pWindow = static_cast<DXWindow *>((void *)GetWindowLongPtrA(pCBData->hwnd, GWLP_USERDATA));
 | 
				
			||||||
 | 
						ComPtr<ID3D12Device> device = pWindow->getDevice(); // device elkérése
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						SRTProps srtProps;
 | 
				
			||||||
 | 
						srtProps.translation = gCam.getViewParams().position;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// új geometria létrehozása
 | 
				
			||||||
 | 
						auto pTeapot = std::shared_ptr<Entity>(new Entity(device));
 | 
				
			||||||
 | 
						pTeapot->loadBinarySTL("assets/utahteapot.stl", ImportAdapters::IAD_SwapYZ_RH);
 | 
				
			||||||
 | 
						pTeapot->setEntitySRT(srtProps);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						gDrawables.push_back(pTeapot);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void moveForward_H(EventHandlerCBData * pCBData)
 | 
					void moveForward_H(EventHandlerCBData * pCBData)
 | 
				
			||||||
@ -125,7 +138,7 @@ void regEventHandlers(EventHandler * pEH)
 | 
				
			|||||||
	pEH->regKeyCB('P', keyCB, nullptr, { ET_KeyDown });
 | 
						pEH->regKeyCB('P', keyCB, nullptr, { ET_KeyDown });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// kattintás 
 | 
						// kattintás 
 | 
				
			||||||
	pEH->regMouseCB(mouseCB, nullptr, { ET_LMouseDown });
 | 
						pEH->regMouseCB(mouseCB, nullptr, { ET_RMouseDown });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// mozgás
 | 
						// mozgás
 | 
				
			||||||
	pEH->regKeyCB('W', moveForward_H, nullptr, { ET_KeyDown, ET_KeyUp }); // előre
 | 
						pEH->regKeyCB('W', moveForward_H, nullptr, { ET_KeyDown, ET_KeyUp }); // előre
 | 
				
			||||||
@ -173,11 +186,11 @@ int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszA
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	std::vector<uint32_t> indices = { 0, 1, 2 }; // indexek
 | 
						std::vector<uint32_t> indices = { 0, 1, 2 }; // indexek
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	auto pGeo = std::shared_ptr<Geometry>(new Geometry(win.getDevice()));
 | 
						auto pGeo = std::shared_ptr<Entity>(new Entity(win.getDevice()));
 | 
				
			||||||
	pGeo->setVertices(vertices);
 | 
						pGeo->setVertices(vertices);
 | 
				
			||||||
	pGeo->setIndices(indices);
 | 
						pGeo->setIndices(indices);
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	auto pGeo2 = std::shared_ptr<Geometry>(new Geometry(win.getDevice()));
 | 
						auto pGeo2 = std::shared_ptr<Entity>(new Entity(win.getDevice()));
 | 
				
			||||||
	pGeo2->loadBinarySTL("assets/dust2.stl", ImportAdapters::IAD_SwapYZ_RH);
 | 
						pGeo2->loadBinarySTL("assets/dust2.stl", ImportAdapters::IAD_SwapYZ_RH);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	(*pGeo) += (*pGeo2);
 | 
						(*pGeo) += (*pGeo2);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user