diff --git a/DXWindow.cpp b/DXWindow.cpp index 28c5a33..4f17902 100644 --- a/DXWindow.cpp +++ b/DXWindow.cpp @@ -284,7 +284,7 @@ namespace eg3d { mCommandList->RSSetViewports(1, &mViewPort); mCommandList->RSSetScissorRects(1, &mScissorRect); - mCommandList->ClearRenderTargetView(getCurrentBackBufferRTVHandle(), DirectX::Colors::LightSteelBlue, 0, nullptr); + mCommandList->ClearRenderTargetView(getCurrentBackBufferRTVHandle(), DirectX::Colors::Black, 0, nullptr); mCommandList->ClearDepthStencilView(getDSVHandle(), D3D12_CLEAR_FLAG_DEPTH | D3D12_CLEAR_FLAG_STENCIL, 1.0f, 0, 0, nullptr); mCommandList->OMSetRenderTargets(1, &getCurrentBackBufferRTVHandle(), true, &getDSVHandle()); @@ -376,11 +376,14 @@ namespace eg3d { void DXWindow::updateConstantBuffers() { - DirectX::XMStoreFloat4x4(&constantBuffer.transformMatrix, XMMatrixTranspose(XMMatrixRotationX(-XM_PIDIV2))); + //DirectX::XMStoreFloat4x4(&constantBuffer.transformMatrix, XMMatrixTranspose(XMMatrixRotationX(-XM_PIDIV2))); if (pCam != nullptr) { constantBuffer.viewMatrix = pCam->getViewMatrix(); constantBuffer.projMatrix = pCam->getProjMatrix(); + + XMFLOAT3 camPos = pCam->getViewParams().position; + constantBuffer.camPosition = { camPos.x, camPos.y, camPos.z, 0.0 }; } bufferMapCopy(cbResource, static_cast(&constantBuffer), sizeof(constantBuffer)); diff --git a/RUNTIME/shaders/basic_shader.hlsl b/RUNTIME/shaders/basic_shader.hlsl index 26f7f4f..92c30df 100644 --- a/RUNTIME/shaders/basic_shader.hlsl +++ b/RUNTIME/shaders/basic_shader.hlsl @@ -8,6 +8,7 @@ struct VSOutput // vertex shader kimeneti strukt { float4 position_H : SV_Position; float3 color : COLOR; + float3 worldPosition : WORLDPOS; }; cbuffer CFrame : register(b0) @@ -15,6 +16,7 @@ cbuffer CFrame : register(b0) float4x4 transformMatrix; float4x4 viewMatrix; float4x4 projMatrix; + float4 camPosition; }; cbuffer CEntity : register(b1) { @@ -26,10 +28,18 @@ VSOutput vs_main(VSInput input) { VSOutput output; // vertex shader kimenete - output.position_H = mul(float4(input.position_D, 1.0), mul(worldMatrix, mul(viewMatrix, projMatrix))); - output.color = color; + float4 worldCoords = mul(float4(input.position_D, 1.0), worldMatrix); + output.position_H = mul(worldCoords, mul(viewMatrix, projMatrix)); // TODO fények + float3 L = normalize(float3(1.0, 1.0, 0.5)); + float3 I = float3(1.0, 1.0, 0.8); + float3 md = float3(1.0, 0.1, 0.1); + + //float3 p = float3(1440, 370, -1365); + output.color = (I * color.xyz) * max(dot(input.normal, L), 0); + + output.worldPosition = worldCoords; return output; } @@ -44,7 +54,8 @@ PSOutput ps_main(VSOutput input) PSOutput output; //output.color = float4(0.0f, 1.0f, 0.0f, 1.0f); - output.color = float4(input.color, 1.0f); + output.color = float4(input.color, 1.0f) / length(input.worldPosition - + camPosition.xyz) * 200; return output; } diff --git a/RUNTIME/shaders/compile_shaders.bat b/RUNTIME/shaders/compile_shaders.bat index 901dc3b..c5e6dcd 100644 --- a/RUNTIME/shaders/compile_shaders.bat +++ b/RUNTIME/shaders/compile_shaders.bat @@ -4,4 +4,5 @@ SET PATH=%PATH%;C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\V fxc "basic_shader.hlsl" /Od /Zi /T vs_5_0 /E "vs_main" /Fo "vs.cso" fxc "basic_shader.hlsl" /Od /Zi /T ps_5_0 /E "ps_main" /Fo "ps.cso" + ::PAUSE \ No newline at end of file diff --git a/const_bufs.h b/const_bufs.h index 376b2ed..23e1fa4 100644 --- a/const_bufs.h +++ b/const_bufs.h @@ -14,6 +14,7 @@ struct CB_Frame DirectX::XMFLOAT4X4 transformMatrix; DirectX::XMFLOAT4X4 viewMatrix; // nézet-mátrix DirectX::XMFLOAT4X4 projMatrix; // vetítési mátrix + DirectX::XMFLOAT4 camPosition; // kamerapozíció }; struct CB_Entity {