diff --git a/.idea/.idea.KhaoticEngineReborn/.idea/discord.xml b/.idea/.idea.KhaoticEngineReborn/.idea/discord.xml new file mode 100644 index 0000000..912db82 --- /dev/null +++ b/.idea/.idea.KhaoticEngineReborn/.idea/discord.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="DiscordProjectSettings"> + <option name="show" value="PROJECT_FILES" /> + <option name="description" value="" /> + <option name="applicationTheme" value="default" /> + <option name="iconsTheme" value="default" /> + <option name="button1Title" value="" /> + <option name="button1Url" value="" /> + <option name="button2Title" value="" /> + <option name="button2Url" value="" /> + <option name="customApplicationId" value="" /> + </component> +</project> \ No newline at end of file diff --git a/.idea/.idea.KhaoticEngineReborn/.idea/encodings.xml b/.idea/.idea.KhaoticEngineReborn/.idea/encodings.xml new file mode 100644 index 0000000..24f3ba2 --- /dev/null +++ b/.idea/.idea.KhaoticEngineReborn/.idea/encodings.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="Encoding"> + <file url="file://$PROJECT_DIR$/enginecustom/src/src/system/applicationclass.cpp" charset="windows-1252" /> + <file url="file://$PROJECT_DIR$/enginecustom/src/src/system/imguiManager.cpp" charset="windows-1252" /> + <file url="PROJECT" charset="windows-1252" /> + </component> +</project> \ No newline at end of file diff --git a/.idea/.idea.KhaoticEngineReborn/.idea/material_theme_project_new.xml b/.idea/.idea.KhaoticEngineReborn/.idea/material_theme_project_new.xml index b3ff0c7..0f9005c 100644 --- a/.idea/.idea.KhaoticEngineReborn/.idea/material_theme_project_new.xml +++ b/.idea/.idea.KhaoticEngineReborn/.idea/material_theme_project_new.xml @@ -3,7 +3,9 @@ <component name="MaterialThemeProjectNewConfig"> <option name="metadata"> <MTProjectMetadataState> - <option name="userId" value="-6a4cade4:194a9b80ce0:-7ffa" /> + <option name="migrated" value="true" /> + <option name="pristineConfig" value="false" /> + <option name="userId" value="4025287c:194ad69ad19:-7ff7" /> </MTProjectMetadataState> </option> </component> diff --git a/.idea/.idea.KhaoticEngineReborn/.idea/projectSettingsUpdater.xml b/.idea/.idea.KhaoticEngineReborn/.idea/projectSettingsUpdater.xml index 64af657..4bb9f4d 100644 --- a/.idea/.idea.KhaoticEngineReborn/.idea/projectSettingsUpdater.xml +++ b/.idea/.idea.KhaoticEngineReborn/.idea/projectSettingsUpdater.xml @@ -1,7 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <project version="4"> <component name="RiderProjectSettingsUpdater"> - <option name="singleClickDiffPreview" value="1" /> - <option name="vcsConfiguration" value="3" /> + <option name="vcsConfiguration" value="2" /> </component> </project> \ No newline at end of file diff --git a/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml b/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml index 0eb482a..d1b362c 100644 --- a/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml +++ b/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml @@ -1,10 +1,77 @@ <?xml version="1.0" encoding="UTF-8"?> <project version="4"> - <component name="RunManager" selected="C/C++ Project.enginecustom"> + <component name="AutoImportSettings"> + <option name="autoReloadType" value="SELECTIVE" /> + </component> + <component name="ChangeListManager"> + <list default="true" id="e81d6e08-efc7-40a0-909d-ec4943d948e9" name="Changes" comment=""> + <change afterPath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/discord.xml" afterDir="false" /> + <change afterPath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/encodings.xml" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/material_theme_project_new.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/material_theme_project_new.xml" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/projectSettingsUpdater.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/projectSettingsUpdater.xml" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/enginecustom/assets/Texture/imgui.ini" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/assets/Texture/imgui.ini" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/enginecustom/imgui.ini" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/imgui.ini" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/enginecustom/shader-error.txt" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/shader-error.txt" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/enginecustom/src/hlsl/celshading.ps" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/hlsl/celshading.ps" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/enginecustom/src/hlsl/celshading.vs" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/hlsl/celshading.vs" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/enginecustom/src/inc/shader/CelShadingShader.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/shader/CelShadingShader.h" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/enginecustom/src/inc/shader/shadermanagerclass.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/shader/shadermanagerclass.h" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/applicationclass.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/applicationclass.h" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/enginecustom/src/inc/system/imguiManager.h" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/inc/system/imguiManager.h" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/enginecustom/src/src/shader/CelShadingShader.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/shader/CelShadingShader.cpp" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/enginecustom/src/src/shader/shadermanagerclass.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/shader/shadermanagerclass.cpp" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/applicationclass.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/applicationclass.cpp" afterDir="false" /> + <change beforePath="$PROJECT_DIR$/enginecustom/src/src/system/imguiManager.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/enginecustom/src/src/system/imguiManager.cpp" afterDir="false" /> + </list> + <option name="SHOW_DIALOG" value="false" /> + <option name="HIGHLIGHT_CONFLICTS" value="true" /> + <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> + <option name="LAST_RESOLUTION" value="IGNORE" /> + </component> + <component name="Git.Settings"> + <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> + </component> + <component name="HighlightingSettingsPerFile"> + <setting file="file://$PROJECT_DIR$/enginecustom/src/src/shader/CelShadingShader.cpp" root0="FORCE_HIGHLIGHTING" /> + </component> + <component name="ProjectColorInfo">{ + "associatedIndex": 6 +}</component> + <component name="ProjectId" id="2sGIWDeT5ixyzDQ0he4A3RFpG9W" /> + <component name="ProjectViewState"> + <option name="hideEmptyMiddlePackages" value="true" /> + <option name="showLibraryContents" value="true" /> + </component> + <component name="PropertiesComponent"><![CDATA[{ + "keyToString": { + "ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true", + "C++ Project.enginecustom.executor": "Run", + "RunOnceActivity.ShowReadmeOnStart": "true", + "SHARE_PROJECT_CONFIGURATION_FILES": "true", + "git-widget-placeholder": "main", + "node.js.detected.package.eslint": "true", + "node.js.detected.package.tslint": "true", + "node.js.selected.package.eslint": "(autodetect)", + "node.js.selected.package.tslint": "(autodetect)", + "nodejs_package_manager_path": "npm", + "settings.editor.selected.configurable": "preferences.fileTypes", + "vue.rearranger.settings.migration": "true" + }, + "keyToStringList": { + "rider.external.source.directories": [ + "C:\\Users\\arivas\\AppData\\Roaming\\JetBrains\\Rider2024.1\\resharper-host\\DecompilerCache", + "C:\\Users\\arivas\\AppData\\Roaming\\JetBrains\\Rider2024.1\\resharper-host\\SourcesCache", + "C:\\Users\\arivas\\AppData\\Local\\Symbols\\src" + ] + } +}]]></component> + <component name="RunManager" selected="C++ Project.enginecustom"> <configuration name="KhaoticDemo" type="CppProject" factoryName="C++ Project"> - <configuration_1 setup="1"> + <configuration_1> <option name="CONFIGURATION" value="Debug" /> <option name="PLATFORM" value="x64" /> + <option name="PROJECT_FILE_PATH" value="$PROJECT_DIR$/KhaoticDemo/KhaoticDemo.vcxproj" /> <option name="CURRENT_LAUNCH_PROFILE" value="Local" /> <option name="EXE_PATH" value="$(LocalDebuggerCommand)" /> <option name="PROGRAM_PARAMETERS" value="$(LocalDebuggerCommandArguments)" /> @@ -12,19 +79,18 @@ <option name="PASS_PARENT_ENVS" value="1" /> <option name="USE_EXTERNAL_CONSOLE" value="0" /> <option name="TERMINAL_INTERACTION_BEHAVIOR" value="AUTO_DETECT" /> - <option name="PROJECT_FILE_PATH" value="$PROJECT_DIR$/KhaoticDemo/KhaoticDemo.vcxproj" /> </configuration_1> <option name="DEFAULT_PROJECT_PATH" value="$PROJECT_DIR$/KhaoticDemo/KhaoticDemo.vcxproj" /> - <option name="PROJECT_FILE_PATH" value="$PROJECT_DIR$/KhaoticDemo/KhaoticDemo.vcxproj" /> <option name="AUTO_SELECT_PRIORITY" value="0" /> <method v="2"> <option name="Build" /> </method> </configuration> <configuration name="enginecustom" type="CppProject" factoryName="C++ Project"> - <configuration_1 setup="1"> + <configuration_1> <option name="CONFIGURATION" value="Debug" /> <option name="PLATFORM" value="x64" /> + <option name="PROJECT_FILE_PATH" value="$PROJECT_DIR$/enginecustom/enginecustom.vcxproj" /> <option name="CURRENT_LAUNCH_PROFILE" value="Local" /> <option name="EXE_PATH" value="$(LocalDebuggerCommand)" /> <option name="PROGRAM_PARAMETERS" value="$(LocalDebuggerCommandArguments)" /> @@ -32,14 +98,34 @@ <option name="PASS_PARENT_ENVS" value="1" /> <option name="USE_EXTERNAL_CONSOLE" value="0" /> <option name="TERMINAL_INTERACTION_BEHAVIOR" value="AUTO_DETECT" /> - <option name="PROJECT_FILE_PATH" value="$PROJECT_DIR$/enginecustom/enginecustom.vcxproj" /> </configuration_1> <option name="DEFAULT_PROJECT_PATH" value="$PROJECT_DIR$/enginecustom/enginecustom.vcxproj" /> - <option name="PROJECT_FILE_PATH" value="$PROJECT_DIR$/enginecustom/enginecustom.vcxproj" /> <option name="AUTO_SELECT_PRIORITY" value="0" /> <method v="2"> <option name="Build" /> </method> </configuration> </component> + <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" /> + <component name="TaskManager"> + <task active="true" id="Default" summary="Default task"> + <changelist id="e81d6e08-efc7-40a0-909d-ec4943d948e9" name="Changes" comment="" /> + <created>1738075515913</created> + <option name="number" value="Default" /> + <option name="presentableId" value="Default" /> + <updated>1738075515913</updated> + <workItem from="1738075517746" duration="553000" /> + <workItem from="1738076088229" duration="80000" /> + <workItem from="1738076192788" duration="19000" /> + <workItem from="1738076222547" duration="6131000" /> + </task> + <servers /> + </component> + <component name="TypeScriptGeneratedFilesManager"> + <option name="version" value="3" /> + </component> + <component name="UnityProjectConfiguration" hasMinimizedUI="false" /> + <component name="VcsManagerConfiguration"> + <option name="CLEAR_INITIAL_COMMIT_MESSAGE" value="true" /> + </component> </project> \ No newline at end of file diff --git a/enginecustom/assets/Texture/imgui.ini b/enginecustom/assets/Texture/imgui.ini index 244abcd..cfd977a 100644 --- a/enginecustom/assets/Texture/imgui.ini +++ b/enginecustom/assets/Texture/imgui.ini @@ -1,28 +1,89 @@ [Window][Debug##Default] Pos=60,60 Size=400,400 +Collapsed=0 [Window][Khaotic Engine] -Pos=1142,43 -Size=392,273 +Pos=1180,27 +Size=396,826 +Collapsed=0 +DockId=0x00000005,0 [Window][Objects] -Pos=598,29 -Size=457,294 +Pos=8,27 +Size=290,826 +Collapsed=0 +DockId=0x0000000A,0 [Window][Terrain] -Pos=58,62 -Size=342,82 +Pos=8,27 +Size=290,487 +Collapsed=0 +DockId=0x00000009,0 [Window][Light] -Pos=1548,17 -Size=358,535 +Pos=8,27 +Size=290,487 +Collapsed=0 +DockId=0x00000009,1 [Window][Shader Manager] -Pos=471,90 -Size=180,79 +Pos=8,27 +Size=330,487 +Collapsed=0 +DockId=0x00000001,2 [Window][Engine Settings] -Pos=106,212 -Size=407,81 +Pos=1516,27 +Size=396,974 +Collapsed=0 +DockId=0x00000005,1 + +[Window][DockSpace Demo] +Size=1584,861 +Collapsed=0 + +[Window][Render Window] +Pos=300,27 +Size=878,826 +Collapsed=0 +DockId=0x00000002,0 + +[Window][DockSpace] +Pos=0,0 +Size=1584,861 +Collapsed=0 + +[Window][Add Object] +Pos=1188,0 +Size=396,430 +Collapsed=0 + +[Window][Log] +Pos=8,518 +Size=1568,335 +Collapsed=0 +DockId=0x0000000C,0 + +[Window][Log Window] +Pos=8,775 +Size=1904,226 +Collapsed=0 +DockId=0x0000000E,0 + +[Docking][Data] +DockSpace ID=0xC0DFADC4 Pos=8,27 Size=1568,826 Split=X + DockNode ID=0x00000001 Parent=0xC0DFADC4 SizeRef=330,1094 Selected=0x393905AB + DockNode ID=0x00000003 Parent=0xC0DFADC4 SizeRef=1700,1094 CentralNode=1 +DockSpace ID=0xCCBD8CF7 Window=0x3DA2F1DE Pos=8,27 Size=1568,826 Split=Y + DockNode ID=0x0000000D Parent=0xCCBD8CF7 SizeRef=1568,598 Split=Y + DockNode ID=0x0000000B Parent=0x0000000D SizeRef=1568,637 Split=X + DockNode ID=0x00000007 Parent=0x0000000B SizeRef=290,826 Split=Y Selected=0x393905AB + DockNode ID=0x00000009 Parent=0x00000007 SizeRef=395,413 Selected=0x393905AB + DockNode ID=0x0000000A Parent=0x00000007 SizeRef=395,411 Selected=0x031DC75C + DockNode ID=0x00000008 Parent=0x0000000B SizeRef=1276,826 Split=X + DockNode ID=0x00000002 Parent=0x00000008 SizeRef=878,826 CentralNode=1 Selected=0x9204953B + DockNode ID=0x00000005 Parent=0x00000008 SizeRef=396,826 Selected=0x9F035453 + DockNode ID=0x0000000C Parent=0x0000000D SizeRef=1568,335 Selected=0x139FDA3F + DockNode ID=0x0000000E Parent=0xCCBD8CF7 SizeRef=1568,226 Selected=0xAB74BEE9 diff --git a/enginecustom/imgui.ini b/enginecustom/imgui.ini index 3903abd..cfd977a 100644 --- a/enginecustom/imgui.ini +++ b/enginecustom/imgui.ini @@ -10,20 +10,20 @@ Collapsed=0 DockId=0x00000005,0 [Window][Objects] -Pos=8,442 -Size=290,411 +Pos=8,27 +Size=290,826 Collapsed=0 DockId=0x0000000A,0 [Window][Terrain] Pos=8,27 -Size=290,826 +Size=290,487 Collapsed=0 DockId=0x00000009,0 [Window][Light] Pos=8,27 -Size=290,826 +Size=290,487 Collapsed=0 DockId=0x00000009,1 @@ -34,8 +34,8 @@ Collapsed=0 DockId=0x00000001,2 [Window][Engine Settings] -Pos=1180,27 -Size=396,826 +Pos=1516,27 +Size=396,974 Collapsed=0 DockId=0x00000005,1 @@ -44,8 +44,8 @@ Size=1584,861 Collapsed=0 [Window][Render Window] -Pos=8,27 -Size=1170,826 +Pos=300,27 +Size=878,826 Collapsed=0 DockId=0x00000002,0 @@ -66,8 +66,8 @@ Collapsed=0 DockId=0x0000000C,0 [Window][Log Window] -Pos=8,627 -Size=1568,226 +Pos=8,775 +Size=1904,226 Collapsed=0 DockId=0x0000000E,0 diff --git a/enginecustom/shader-error.txt b/enginecustom/shader-error.txt index a0b1877..1cff77c 100644 Binary files a/enginecustom/shader-error.txt and b/enginecustom/shader-error.txt differ diff --git a/enginecustom/src/hlsl/celshading.ps b/enginecustom/src/hlsl/celshading.ps index ff3ee0e..b9bfe03 100644 --- a/enginecustom/src/hlsl/celshading.ps +++ b/enginecustom/src/hlsl/celshading.ps @@ -1,34 +1,78 @@ -cbuffer LightBuffer +///////////// +// GLOBALS // +///////////// +Texture2D shaderTexture : register(t0); +SamplerState SampleType : register(s0); +cbuffer SunLightBuffer { + float4 ambientColor; float4 diffuseColor; float3 lightDirection; - float padding; // Padding to ensure the structure is a multiple of 16 bytes. - float3 lightPosition; // Add light position - float padding2; // Padding to ensure the structure is a multiple of 16 bytes. - float constantAttenuation; - float linearAttenuation; - float quadraticAttenuation; - float padding3; // Padding to ensure the structure is a multiple of 16 bytes. + float intensity; }; -Texture2D shaderTexture; -SamplerState SampleType; +cbuffer SunLightColorBuffer +{ + float4 sunColor; +}; +////////////// +// TYPEDEFS // +////////////// struct PixelInputType { float4 position : SV_POSITION; - float3 normal : NORMAL; float2 tex : TEXCOORD0; - float3 worldPos : TEXCOORD1; // Add world position + float3 normal : NORMAL; }; -float4 CelShadingPixelShader(PixelInputType input) : SV_TARGET +//////////////////////////////////////////////////////////////////////////////// +// Pixel Shader +//////////////////////////////////////////////////////////////////////////////// +float4 SunLightPixelShader(PixelInputType input) : SV_TARGET { - // Normalize the normal - float3 normal = normalize(input.normal); + float4 textureColor; + float4 color; + float lightIntensity; + float4 colorArray; + float4 colorSum; - // Convert the normal to a color - float4 color = float4((normal + 1.0f) * 0.5f, 1.0f); + // Sample the pixel color from the texture using the sampler at this texture coordinate location. + textureColor = shaderTexture.Sample(SampleType, input.tex); + + // Calculate the different amounts of light on this pixel based on the direction of the light. + lightIntensity = saturate(dot(input.normal, -lightDirection)); + + if(lightIntensity > 0.95f) + { + lightIntensity = 1.0f; + } + else if(lightIntensity > 0.5f) + { + lightIntensity = 0.75f; + } + else if(lightIntensity > 0.25f) + { + lightIntensity = 0.5f; + } + else + { + lightIntensity = 0.25f; + } + + // Determine the diffuse color amount of the light. + colorArray = (diffuseColor * lightIntensity) * intensity; + + // Initialize the sum of colors. + colorSum = float4(0.0f, 0.0f, 0.0f, 1.0f); + + // Add the light color. + colorSum.r += colorArray.r; + colorSum.g += colorArray.g; + colorSum.b += colorArray.b; + + // Multiply the texture pixel by the light color to get the final result. + color = saturate(colorSum) * textureColor; return color; } diff --git a/enginecustom/src/hlsl/celshading.vs b/enginecustom/src/hlsl/celshading.vs index 774baf8..e704290 100644 --- a/enginecustom/src/hlsl/celshading.vs +++ b/enginecustom/src/hlsl/celshading.vs @@ -1,3 +1,6 @@ +///////////// +// GLOBALS // +///////////// cbuffer MatrixBuffer { matrix worldMatrix; @@ -5,22 +8,42 @@ cbuffer MatrixBuffer matrix projectionMatrix; }; +cbuffer CameraBuffer +{ + float3 cameraPosition; + float padding; +}; + +cbuffer SunLightBuffer +{ + float4 ambientColor; // Color of the ambient light. + float4 diffuseColor; // Color of the diffuse light. + float3 lightDirection; // Direction of the light. + float intensity; // Intensity of the light. + +}; + +////////////// +// TYPEDEFS // +////////////// struct VertexInputType { float4 position : POSITION; - float3 normal : NORMAL; float2 tex : TEXCOORD0; + float3 normal : NORMAL; }; struct PixelInputType { float4 position : SV_POSITION; - float3 normal : NORMAL; float2 tex : TEXCOORD0; - float3 worldPos : TEXCOORD1; // Add world position + float3 normal : NORMAL; }; -PixelInputType CelShadingVertexShader(VertexInputType input) +//////////////////////////////////////////////////////////////////////////////// +// Vertex Shader +//////////////////////////////////////////////////////////////////////////////// +PixelInputType SunLightVertexShader(VertexInputType input) { PixelInputType output; @@ -28,18 +51,18 @@ PixelInputType CelShadingVertexShader(VertexInputType input) input.position.w = 1.0f; // Calculate the position of the vertex against the world, view, and projection matrices. - float4 worldPosition = mul(input.position, worldMatrix); - output.position = mul(worldPosition, viewMatrix); + output.position = mul(input.position, worldMatrix); + output.position = mul(output.position, viewMatrix); output.position = mul(output.position, projectionMatrix); - - // Pass the normal to the pixel shader - output.normal = mul((float3x3)worldMatrix, input.normal); - - // Pass the world position to the pixel shader - output.worldPos = worldPosition.xyz; - + // Store the texture coordinates for the pixel shader. output.tex = input.tex; + + // Calculate the normal vector against the world matrix only. + output.normal = mul(input.normal, (float3x3) worldMatrix); + + // Normalize the normal vector. + output.normal = normalize(output.normal); return output; } diff --git a/enginecustom/src/inc/shader/CelShadingShader.h b/enginecustom/src/inc/shader/CelShadingShader.h index 141c6a3..7522ea1 100644 --- a/enginecustom/src/inc/shader/CelShadingShader.h +++ b/enginecustom/src/inc/shader/CelShadingShader.h @@ -1,9 +1,5 @@ -#ifndef _CELSHADINGSHADER_H_ -#define _CELSHADINGSHADER_H_ +#pragma once -////////////// -// INCLUDES // -////////////// #include "Logger.h" #include <d3d11.h> #include <d3dcompiler.h> @@ -12,57 +8,57 @@ using namespace DirectX; using namespace std; -//////////////////////////////////////////////////////////////////////////////// -// Class name: CelShadingShader -//////////////////////////////////////////////////////////////////////////////// -class CelShadingShader +class CelshadeClass { -private: - struct MatrixBufferType + + private : + struct MatrixBufferType { XMMATRIX world; XMMATRIX view; XMMATRIX projection; }; - struct LightBufferType + struct CameraBufferType { - XMFLOAT4 diffuseColor; - XMFLOAT3 lightDirection; - float padding; // Padding to ensure the structure is a multiple of 16 bytes. - XMFLOAT3 lightPosition; // Add light position - float padding2; // Padding to ensure the structure is a multiple of 16 bytes. - float constantAttenuation; - float linearAttenuation; - float quadraticAttenuation; - float padding3; // Padding to ensure the structure is a multiple of 16 bytes. + XMFLOAT3 cameraPosition; + float padding; }; + struct SunLightBufferType + { + XMFLOAT4 diffuseColor; + XMFLOAT4 ambientColor; + XMFLOAT3 sunDirection; + float intensity; + }; + -public: - CelShadingShader(); - CelShadingShader(const CelShadingShader&); - ~CelShadingShader(); +public : + CelshadeClass(); + CelshadeClass(const CelshadeClass&); + ~CelshadeClass(); bool Initialize(ID3D11Device*, HWND); void Shutdown(); - bool Render(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT3, XMFLOAT4, XMFLOAT3); + bool Render(ID3D11DeviceContext* deviceContex, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, ID3D11ShaderResourceView* texture, XMFLOAT4 diffuseColor, XMFLOAT4 ambientColor, XMFLOAT3 sunDirection,float intensity); private: bool InitializeShader(ID3D11Device*, HWND, WCHAR*, WCHAR*); void ShutdownShader(); void OutputShaderErrorMessage(ID3D10Blob*, HWND, WCHAR*); - bool SetShaderParameters(ID3D11DeviceContext*, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT3, XMFLOAT4, XMFLOAT3); + bool SetShaderParameters(ID3D11DeviceContext* deviceContext, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, ID3D11ShaderResourceView* texture, XMFLOAT4 ambientColor, XMFLOAT4 diffuseColor, XMFLOAT3 lightDirection, float sunIntensity); void RenderShader(ID3D11DeviceContext*, int); private: ID3D11VertexShader* m_vertexShader; ID3D11PixelShader* m_pixelShader; ID3D11InputLayout* m_layout; - ID3D11Buffer* m_matrixBuffer; ID3D11SamplerState* m_sampleState; - ID3D11Buffer* m_lightBuffer; -}; - -#endif \ No newline at end of file + ID3D11Buffer* m_matrixBuffer; + ID3D11Buffer* m_cameraBuffer; + ID3D11Buffer* m_sunlightBuffer; + ID3D11Buffer* m_sunlightColorBuffer; + ID3D11Buffer* m_sunlightPositionBuffer; +}; \ No newline at end of file diff --git a/enginecustom/src/inc/shader/shadermanagerclass.h b/enginecustom/src/inc/shader/shadermanagerclass.h index d4a00bd..87be1c3 100644 --- a/enginecustom/src/inc/shader/shadermanagerclass.h +++ b/enginecustom/src/inc/shader/shadermanagerclass.h @@ -1,7 +1,7 @@ #ifndef _SHADERMANAGERCLASS_H_ #define _SHADERMANAGERCLASS_H_ -// Inclure les en-t�tes n�cessaires +// Inclure les en-têtes nécessaires #include <d3d11.h> #include <DirectXMath.h> #include <vector> @@ -42,7 +42,7 @@ public: bool RenderlightMapShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*); bool RenderRefractionShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT3, XMFLOAT4[], XMFLOAT4[], XMFLOAT4[], XMFLOAT4); bool RenderWaterShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*, ID3D11ShaderResourceView*, float, float); - bool RenderCelShadingShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT3, XMFLOAT4, XMFLOAT3); + bool RenderCelShadingShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4, XMFLOAT4, XMFLOAT3, float); bool RenderSunlightShader(ID3D11DeviceContext*, int, XMMATRIX, XMMATRIX, XMMATRIX, ID3D11ShaderResourceView*, XMFLOAT4, XMFLOAT4, XMFLOAT3, float); private: TextureShaderClass* m_TextureShader; @@ -56,7 +56,7 @@ private: LightMapShaderClass* m_LightMapShader; RefractionShaderClass* m_RefractionShader; WaterShaderClass* m_WaterShader; - CelShadingShader* m_CelShadingShader; + CelshadeClass* m_CelShadingShader; SunlightShaderClass* m_SunlightShader; }; diff --git a/enginecustom/src/inc/system/applicationclass.h b/enginecustom/src/inc/system/applicationclass.h index d61994b..76946fa 100644 --- a/enginecustom/src/inc/system/applicationclass.h +++ b/enginecustom/src/inc/system/applicationclass.h @@ -35,6 +35,9 @@ #include <comdef.h> // Pour _com_error #include <chrono> #include <thread> +#include <map> +#include <algorithm> +#include <DirectXMath.h> ///////////// @@ -136,7 +139,6 @@ public: bool GetCanFixedUpdate() const { return CanFixedUpdate; }; void SetCanFixedUpdate(bool canFixedUpdate) { CanFixedUpdate = canFixedUpdate; }; - private: bool Render(float, float, float, float, float); bool RenderPhysics(bool keyLeft, bool keyRight, bool keyUp, bool keyDown, float deltaTime); diff --git a/enginecustom/src/inc/system/imguiManager.h b/enginecustom/src/inc/system/imguiManager.h index bf893b0..0333dc0 100644 --- a/enginecustom/src/inc/system/imguiManager.h +++ b/enginecustom/src/inc/system/imguiManager.h @@ -33,7 +33,6 @@ public: void WidgetObjectWindow(ApplicationClass* app); void WidgetTerrainWindow(ApplicationClass* app); void WidgetLightWindow(ApplicationClass* app); - void WidgetShaderWindow(ApplicationClass* app); void WidgetEngineSettingsWindow(ApplicationClass* app); void WidgetRenderWindow(ApplicationClass* app, ImVec2 availableSize); void WidgetLogWindow(ApplicationClass* app); diff --git a/enginecustom/src/src/shader/CelShadingShader.cpp b/enginecustom/src/src/shader/CelShadingShader.cpp index 25f238f..fa31940 100644 --- a/enginecustom/src/src/shader/CelShadingShader.cpp +++ b/enginecustom/src/src/shader/CelShadingShader.cpp @@ -1,38 +1,47 @@ +//////////////////////////////////////////////////////////////////////////////// +// Filename: lightshaderclass.cpp +//////////////////////////////////////////////////////////////////////////////// #include "CelShadingShader.h" -#include <iostream> -CelShadingShader::CelShadingShader() + +CelshadeClass::CelshadeClass() { m_vertexShader = 0; m_pixelShader = 0; m_layout = 0; - m_matrixBuffer = 0; m_sampleState = 0; - m_lightBuffer = 0; + m_matrixBuffer = 0; + m_cameraBuffer = 0; + m_sunlightBuffer = 0; + m_sunlightColorBuffer = 0; + m_sunlightPositionBuffer = 0; } -CelShadingShader::CelShadingShader(const CelShadingShader& other) + +CelshadeClass::CelshadeClass(const CelshadeClass& other) { } -CelShadingShader::~CelShadingShader() + +CelshadeClass::~CelshadeClass() { } -bool CelShadingShader::Initialize(ID3D11Device* device, HWND hwnd) -{ - Logger::Get().Log("Initializing CelShadingShader", __FILE__, __LINE__, Logger::LogLevel::Initialize); - bool result; +bool CelshadeClass::Initialize(ID3D11Device* device, HWND hwnd) +{ + Logger::Get().Log("Initializing LightShaderClass", __FILE__, __LINE__, Logger::LogLevel::Initialize); + wchar_t vsFilename[128]; wchar_t psFilename[128]; int error; + bool result; // Set the filename of the vertex shader. error = wcscpy_s(vsFilename, 128, L"src/hlsl/celshading.vs"); if (error != 0) { - Logger::Get().Log("Failed to set the filename of the vertex shader", __FILE__, __LINE__); + Logger::Get().Log("Failed to copy string", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -40,38 +49,42 @@ bool CelShadingShader::Initialize(ID3D11Device* device, HWND hwnd) error = wcscpy_s(psFilename, 128, L"src/hlsl/celshading.ps"); if (error != 0) { - Logger::Get().Log("Failed to set the filename of the pixel shader", __FILE__, __LINE__); + Logger::Get().Log("Failed to copy string", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } - // Initialize the vertex and pixel shaders. result = InitializeShader(device, hwnd, vsFilename, psFilename); if (!result) { - Logger::Get().Log("Failed to initialize the vertex and pixel shaders", __FILE__, __LINE__); + Logger::Get().Log("Failed to initialize shader", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } - Logger::Get().Log("Successfully initialized CelShadingShader", __FILE__, __LINE__, Logger::LogLevel::Initialize); + Logger::Get().Log("SunLightShaderClass initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); return true; } -void CelShadingShader::Shutdown() + +void CelshadeClass::Shutdown() { // Shutdown the vertex and pixel shaders as well as the related objects. ShutdownShader(); + + return; } -bool CelShadingShader::Render(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, - ID3D11ShaderResourceView* texture, XMFLOAT3 lightDirection, XMFLOAT4 diffuseColor, XMFLOAT3 lightPosition) +bool CelshadeClass::Render(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, + ID3D11ShaderResourceView* texture, XMFLOAT4 diffuseColor, XMFLOAT4 ambientColor, XMFLOAT3 sunDirection, float sunIntensity) { bool result; + + // Set the shader parameters that it will use for rendering. - result = SetShaderParameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, lightDirection, diffuseColor, lightPosition); + result = SetShaderParameters(deviceContext, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, ambientColor, sunDirection, sunIntensity); if (!result) { - Logger::Get().Log("CelShading Error", __FILE__, __LINE__, Logger::LogLevel::Error); + Logger::Get().Log("Failed to set shader parameters", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } @@ -81,89 +94,92 @@ bool CelShadingShader::Render(ID3D11DeviceContext* deviceContext, int indexCount return true; } -bool CelShadingShader::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename) + +bool CelshadeClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename) { + Logger::Get().Log("Initializing shader", __FILE__, __LINE__, Logger::LogLevel::Initialize); + HRESULT result; - ID3D10Blob* errorMessage = nullptr; - ID3D10Blob* vertexShaderBuffer = nullptr; - ID3D10Blob* pixelShaderBuffer = nullptr; + ID3D10Blob* errorMessage; + ID3D10Blob* vertexShaderBuffer; + ID3D10Blob* pixelShaderBuffer; D3D11_INPUT_ELEMENT_DESC polygonLayout[3]; unsigned int numElements; - D3D11_BUFFER_DESC matrixBufferDesc; D3D11_SAMPLER_DESC samplerDesc; - D3D11_BUFFER_DESC lightBufferDesc; + D3D11_BUFFER_DESC matrixBufferDesc; + D3D11_BUFFER_DESC sunlightBufferDesc; + + // Initialize the pointers this function will use to null. + errorMessage = 0; + vertexShaderBuffer = 0; + pixelShaderBuffer = 0; // Compile the vertex shader code. - result = D3DCompileFromFile(vsFilename, nullptr, nullptr, "CelShadingVertexShader", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, &vertexShaderBuffer, &errorMessage); + result = D3DCompileFromFile(vsFilename, NULL, NULL, "SunLightVertexShader", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, &vertexShaderBuffer, &errorMessage); if (FAILED(result)) { - // If the shader failed to compile it should have written something to the error message. if (errorMessage) { OutputShaderErrorMessage(errorMessage, hwnd, vsFilename); } - // If there was nothing in the error message then it simply could not find the shader file itself. else { - MessageBox(hwnd, vsFilename, L"Missing Shader File", MB_OK); + Logger::Get().Log("Failed to compile shader", __FILE__, __LINE__, Logger::LogLevel::Error); } - return false; } // Compile the pixel shader code. - result = D3DCompileFromFile(psFilename, nullptr, nullptr, "CelShadingPixelShader", "ps_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, &pixelShaderBuffer, &errorMessage); + result = D3DCompileFromFile(psFilename, NULL, NULL, "SunLightPixelShader", "ps_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, &pixelShaderBuffer, &errorMessage); if (FAILED(result)) { - // If the shader failed to compile it should have written something to the error message. if (errorMessage) { OutputShaderErrorMessage(errorMessage, hwnd, psFilename); } - // If there was nothing in the error message then it simply could not find the file itself. else { - MessageBox(hwnd, psFilename, L"Missing Shader File", MB_OK); + Logger::Get().Log("Failed to compile shader", __FILE__, __LINE__, Logger::LogLevel::Error); } - return false; } // Create the vertex shader from the buffer. - result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), nullptr, &m_vertexShader); + result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &m_vertexShader); if (FAILED(result)) { + Logger::Get().Log("Failed to create vertex shader", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } // Create the pixel shader from the buffer. - result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), nullptr, &m_pixelShader); + result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &m_pixelShader); if (FAILED(result)) { + Logger::Get().Log("Failed to create pixel shader", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } // Create the vertex input layout description. - // This setup needs to match the VertexType structure in the ModelClass and in the shader. polygonLayout[0].SemanticName = "POSITION"; polygonLayout[0].SemanticIndex = 0; - polygonLayout[0].Format = DXGI_FORMAT_R32G32B32A32_FLOAT; + polygonLayout[0].Format = DXGI_FORMAT_R32G32B32_FLOAT; polygonLayout[0].InputSlot = 0; polygonLayout[0].AlignedByteOffset = 0; polygonLayout[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; polygonLayout[0].InstanceDataStepRate = 0; - polygonLayout[1].SemanticName = "NORMAL"; + polygonLayout[1].SemanticName = "TEXCOORD"; polygonLayout[1].SemanticIndex = 0; - polygonLayout[1].Format = DXGI_FORMAT_R32G32B32_FLOAT; + polygonLayout[1].Format = DXGI_FORMAT_R32G32_FLOAT; polygonLayout[1].InputSlot = 0; polygonLayout[1].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; polygonLayout[1].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; polygonLayout[1].InstanceDataStepRate = 0; - polygonLayout[2].SemanticName = "TEXCOORD"; + polygonLayout[2].SemanticName = "NORMAL"; polygonLayout[2].SemanticIndex = 0; - polygonLayout[2].Format = DXGI_FORMAT_R32G32_FLOAT; + polygonLayout[2].Format = DXGI_FORMAT_R32G32B32_FLOAT; polygonLayout[2].InputSlot = 0; polygonLayout[2].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; polygonLayout[2].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; @@ -176,30 +192,16 @@ bool CelShadingShader::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR* result = device->CreateInputLayout(polygonLayout, numElements, vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), &m_layout); if (FAILED(result)) { + Logger::Get().Log("Failed to create input layout", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } // Release the vertex shader buffer and pixel shader buffer since they are no longer needed. vertexShaderBuffer->Release(); - vertexShaderBuffer = nullptr; + vertexShaderBuffer = 0; pixelShaderBuffer->Release(); - pixelShaderBuffer = nullptr; - - // Setup the description of the dynamic matrix constant buffer that is in the vertex shader. - matrixBufferDesc.Usage = D3D11_USAGE_DYNAMIC; - matrixBufferDesc.ByteWidth = sizeof(MatrixBufferType); - matrixBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; - matrixBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - matrixBufferDesc.MiscFlags = 0; - matrixBufferDesc.StructureByteStride = 0; - - // Create the constant buffer pointer so we can access the vertex shader constant buffer from within this class. - result = device->CreateBuffer(&matrixBufferDesc, nullptr, &m_matrixBuffer); - if (FAILED(result)) - { - return false; - } + pixelShaderBuffer = 0; // Create a texture sampler state description. samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; @@ -220,78 +222,128 @@ bool CelShadingShader::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR* result = device->CreateSamplerState(&samplerDesc, &m_sampleState); if (FAILED(result)) { + Logger::Get().Log("Failed to create sampler state", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } - // Setup the description of the light dynamic constant buffer that is in the pixel shader. - lightBufferDesc.Usage = D3D11_USAGE_DYNAMIC; - lightBufferDesc.ByteWidth = sizeof(LightBufferType); - lightBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; - lightBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - lightBufferDesc.MiscFlags = 0; - lightBufferDesc.StructureByteStride = 0; + // Setup the description of the dynamic matrix constant buffer that is in the vertex shader. + matrixBufferDesc.Usage = D3D11_USAGE_DYNAMIC; + matrixBufferDesc.ByteWidth = sizeof(MatrixBufferType); + matrixBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; + matrixBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + matrixBufferDesc.MiscFlags = 0; + matrixBufferDesc.StructureByteStride = 0; - // Create the constant buffer pointer so we can access the pixel shader constant buffer from within this class. - result = device->CreateBuffer(&lightBufferDesc, nullptr, &m_lightBuffer); + // Create the constant buffer pointer so we can access the vertex shader constant buffer from within this class. + result = device->CreateBuffer(&matrixBufferDesc, NULL, &m_matrixBuffer); if (FAILED(result)) { + Logger::Get().Log("Failed to create matrix buffer", __FILE__, __LINE__, Logger::LogLevel::Error); return false; } + // Setup the description of the dynamic sunlight constant buffer that is in the pixel shader. + sunlightBufferDesc.Usage = D3D11_USAGE_DYNAMIC; + sunlightBufferDesc.ByteWidth = sizeof(SunLightBufferType); + sunlightBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; + sunlightBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + sunlightBufferDesc.MiscFlags = 0; + sunlightBufferDesc.StructureByteStride = 0; + + // Create the constant buffer pointer so we can access the pixel shader constant buffer from within this class. + result = device->CreateBuffer(&sunlightBufferDesc, NULL, &m_sunlightBuffer); + if (FAILED(result)) + { + Logger::Get().Log("Failed to create sunlight buffer", __FILE__, __LINE__, Logger::LogLevel::Error); + return false; + } + + Logger::Get().Log("Shader initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize); + return true; } -void CelShadingShader::ShutdownShader() + + +void CelshadeClass::ShutdownShader() { - // Release the light constant buffer. - if (m_lightBuffer) + Logger::Get().Log("Shutting down SunLightShaderClass", __FILE__, __LINE__, Logger::LogLevel::Shutdown); + + // Release the light constant buffers. + if (m_sunlightColorBuffer) { - m_lightBuffer->Release(); - m_lightBuffer = nullptr; + m_sunlightColorBuffer->Release(); + m_sunlightColorBuffer = 0; } - // Release the sampler state. - if (m_sampleState) + if (m_sunlightPositionBuffer) { - m_sampleState->Release(); - m_sampleState = nullptr; + m_sunlightPositionBuffer->Release(); + m_sunlightPositionBuffer = 0; + } + + // Release the light constant buffer. + if (m_sunlightBuffer) + { + m_sunlightBuffer->Release(); + m_sunlightBuffer = 0; + } + + // Release the camera constant buffer. + if (m_cameraBuffer) + { + m_cameraBuffer->Release(); + m_cameraBuffer = 0; } // Release the matrix constant buffer. if (m_matrixBuffer) { m_matrixBuffer->Release(); - m_matrixBuffer = nullptr; + m_matrixBuffer = 0; + } + + // Release the sampler state. + if (m_sampleState) + { + m_sampleState->Release(); + m_sampleState = 0; } // Release the layout. if (m_layout) { m_layout->Release(); - m_layout = nullptr; + m_layout = 0; } // Release the pixel shader. if (m_pixelShader) { m_pixelShader->Release(); - m_pixelShader = nullptr; + m_pixelShader = 0; } // Release the vertex shader. if (m_vertexShader) { m_vertexShader->Release(); - m_vertexShader = nullptr; + m_vertexShader = 0; } + + Logger::Get().Log("SunLightShaderClass shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown); + + return; } -void CelShadingShader::OutputShaderErrorMessage(ID3D10Blob* errorMessage, HWND hwnd, WCHAR* shaderFilename) + +void CelshadeClass::OutputShaderErrorMessage(ID3D10Blob* errorMessage, HWND hwnd, WCHAR* shaderFilename) { char* compileErrors; - unsigned long bufferSize, i; - std::ofstream fout; + unsigned __int64 bufferSize, i; + ofstream fout; + // Get a pointer to the error message text buffer. compileErrors = (char*)(errorMessage->GetBufferPointer()); @@ -313,20 +365,32 @@ void CelShadingShader::OutputShaderErrorMessage(ID3D10Blob* errorMessage, HWND h // Release the error message. errorMessage->Release(); - errorMessage = nullptr; + errorMessage = 0; // Pop a message up on the screen to notify the user to check the text file for compile errors. - MessageBox(hwnd, L"Error compiling shader. Check shader-error.txt for message.", shaderFilename, MB_OK); + MessageBox(hwnd, L"Error compiling shader. Check shader-error.txt for message.", shaderFilename, MB_OK); + + return; } -bool CelShadingShader::SetShaderParameters(ID3D11DeviceContext* deviceContext, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, - ID3D11ShaderResourceView* texture, XMFLOAT3 lightDirection, XMFLOAT4 diffuseColor, XMFLOAT3 lightPosition) +bool CelshadeClass::SetShaderParameters( + ID3D11DeviceContext* deviceContext, + XMMATRIX worldMatrix, + XMMATRIX viewMatrix, + XMMATRIX projectionMatrix, + ID3D11ShaderResourceView* texture, + XMFLOAT4 ambientColor, + XMFLOAT4 diffuseColor, + XMFLOAT3 lightDirection, + float sunIntensity + ) { HRESULT result; D3D11_MAPPED_SUBRESOURCE mappedResource; MatrixBufferType* dataPtr; - LightBufferType* dataPtr2; + CameraBufferType* dataPtr2; + SunLightBufferType* dataPtr3; unsigned int bufferNumber; // Transpose the matrices to prepare them for the shader. @@ -358,32 +422,30 @@ bool CelShadingShader::SetShaderParameters(ID3D11DeviceContext* deviceContext, X // Finally set the constant buffer in the vertex shader with the updated values. deviceContext->VSSetConstantBuffers(bufferNumber, 1, &m_matrixBuffer); - // Lock the light constant buffer so it can be written to. - result = deviceContext->Map(m_lightBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); + // Lock the sunlight constant buffer so it can be written to. + result = deviceContext->Map(m_sunlightBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); if (FAILED(result)) { return false; } // Get a pointer to the data in the constant buffer. - dataPtr2 = (LightBufferType*)mappedResource.pData; + dataPtr3 = (SunLightBufferType*)mappedResource.pData; // Copy the lighting variables into the constant buffer. - dataPtr2->diffuseColor = diffuseColor; - dataPtr2->lightDirection = lightDirection; - dataPtr2->lightPosition = lightPosition; - dataPtr2->constantAttenuation = 0.5f; // Set your attenuation values here - dataPtr2->linearAttenuation = 0.1f; - dataPtr2->quadraticAttenuation = 0.01f; + dataPtr3->ambientColor = ambientColor; + dataPtr3->diffuseColor = diffuseColor; + dataPtr3->sunDirection = lightDirection; + dataPtr3->intensity = sunIntensity; // Unlock the constant buffer. - deviceContext->Unmap(m_lightBuffer, 0); + deviceContext->Unmap(m_sunlightBuffer, 0); - // Set the position of the light constant buffer in the pixel shader. + // Set the position of the sunlight constant buffer in the pixel shader. bufferNumber = 0; - - // Finally set the light constant buffer in the pixel shader with the updated values. - deviceContext->PSSetConstantBuffers(bufferNumber, 1, &m_lightBuffer); + + // Finally set the sunlight constant buffer in the pixel shader with the updated values. + deviceContext->PSSetConstantBuffers(bufferNumber, 1, &m_sunlightBuffer); // Set shader texture resource in the pixel shader. deviceContext->PSSetShaderResources(0, 1, &texture); @@ -391,20 +453,20 @@ bool CelShadingShader::SetShaderParameters(ID3D11DeviceContext* deviceContext, X return true; } - - -void CelShadingShader::RenderShader(ID3D11DeviceContext* deviceContext, int indexCount) +void CelshadeClass::RenderShader(ID3D11DeviceContext* deviceContext, int indexCount) { // Set the vertex input layout. deviceContext->IASetInputLayout(m_layout); // Set the vertex and pixel shaders that will be used to render this triangle. - deviceContext->VSSetShader(m_vertexShader, nullptr, 0); - deviceContext->PSSetShader(m_pixelShader, nullptr, 0); + deviceContext->VSSetShader(m_vertexShader, NULL, 0); + deviceContext->PSSetShader(m_pixelShader, NULL, 0); // Set the sampler state in the pixel shader. deviceContext->PSSetSamplers(0, 1, &m_sampleState); // Render the triangle. deviceContext->DrawIndexed(indexCount, 0, 0); + + return; } diff --git a/enginecustom/src/src/shader/shadermanagerclass.cpp b/enginecustom/src/src/shader/shadermanagerclass.cpp index 582dd24..eb38a3a 100644 --- a/enginecustom/src/src/shader/shadermanagerclass.cpp +++ b/enginecustom/src/src/shader/shadermanagerclass.cpp @@ -127,7 +127,7 @@ bool ShaderManagerClass::Initialize(ID3D11Device* device, HWND hwnd) return false; } - m_CelShadingShader = new CelShadingShader; + m_CelShadingShader = new CelshadeClass; result = m_CelShadingShader->Initialize(device, hwnd); if (!result) { @@ -422,11 +422,11 @@ bool ShaderManagerClass::RenderWaterShader(ID3D11DeviceContext* deviceContext, i } bool ShaderManagerClass::RenderCelShadingShader(ID3D11DeviceContext* deviceContext, int indexCount, XMMATRIX worldMatrix, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, - ID3D11ShaderResourceView* texture, XMFLOAT3 lightDirection, XMFLOAT4 diffuseColor, XMFLOAT3 lightPosition) + ID3D11ShaderResourceView* texture, XMFLOAT4 diffuseColor, XMFLOAT4 ambientColor, XMFLOAT3 sunDirection, float sunIntensity) { bool result; - result = m_CelShadingShader->Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, lightDirection, diffuseColor, lightPosition); + result = m_CelShadingShader->Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, diffuseColor, ambientColor, sunDirection, sunIntensity); if (!result) { return false; diff --git a/enginecustom/src/src/system/applicationclass.cpp b/enginecustom/src/src/system/applicationclass.cpp index 8785b33..443fa52 100644 --- a/enginecustom/src/src/system/applicationclass.cpp +++ b/enginecustom/src/src/system/applicationclass.cpp @@ -1899,8 +1899,18 @@ bool ApplicationClass::RenderPass(const std::vector<std::reference_wrapper<std:: switch (object->GetActiveShader()) { case Object::CEL_SHADING: - result = m_ShaderManager->RenderCelShadingShader(m_Direct3D->GetDeviceContext(), object->GetIndexCount(), worldMatrix, view, projection, object->GetTexture(0), - m_Lights[0]->GetDirection(), m_Lights[0]->GetDiffuseColor(), TrueLightPosition); + result = m_ShaderManager->RenderCelShadingShader( + m_Direct3D->GetDeviceContext(), + object->GetIndexCount(), + worldMatrix, + view, + projection, + object->GetTexture(0), + m_SunLight->GetDiffuseColor(), + m_SunLight->GetAmbientColor(), + m_SunLight->GetDirection(), + m_SunLight->GetIntensity() + ); if (!result) { Logger::Get().Log("Could not render the model using the cel shader", __FILE__, __LINE__, Logger::LogLevel::Error); @@ -1909,7 +1919,17 @@ bool ApplicationClass::RenderPass(const std::vector<std::reference_wrapper<std:: break; case Object::NORMAL_MAPPING: - result = m_ShaderManager->RenderNormalMapShader(m_Direct3D->GetDeviceContext(), object->GetIndexCount(), worldMatrix, view, projection, object->GetTexture(0), object->GetTexture(1), m_Lights[0]->GetDirection(), m_Lights[0]->GetDiffuseColor()); + result = m_ShaderManager->RenderNormalMapShader( + m_Direct3D->GetDeviceContext(), + object->GetIndexCount(), + worldMatrix, + view, + projection, + object->GetTexture(0), + object->GetTexture(1), + m_Lights[0]->GetDirection(), + m_Lights[0]->GetDiffuseColor() + ); if (!result) { Logger::Get().Log("Could not render the model using the normal map shader", __FILE__, __LINE__, Logger::LogLevel::Error); @@ -1945,8 +1965,17 @@ bool ApplicationClass::RenderPass(const std::vector<std::reference_wrapper<std:: break; case Object::SUNLIGHT: - result = m_ShaderManager->RenderSunlightShader(m_Direct3D->GetDeviceContext(), object->GetIndexCount(), worldMatrix, view, projection, - object->GetTexture(0), m_SunLight->GetDiffuseColor(), m_SunLight->GetAmbientColor(), m_SunLight->GetDirection(), m_SunLight->GetIntensity()); + result = m_ShaderManager->RenderSunlightShader( + m_Direct3D->GetDeviceContext(), + object->GetIndexCount(), + worldMatrix, + view, + projection, + object->GetTexture(0), + m_SunLight->GetDiffuseColor(), + m_SunLight->GetAmbientColor(), + m_SunLight->GetDirection(), + m_SunLight->GetIntensity()); if (!result) { Logger::Get().Log("Could not render the object model using the sunlight shader", __FILE__, __LINE__, Logger::LogLevel::Error); diff --git a/enginecustom/src/src/system/imguiManager.cpp b/enginecustom/src/src/system/imguiManager.cpp index 540ca07..833c238 100644 --- a/enginecustom/src/src/system/imguiManager.cpp +++ b/enginecustom/src/src/system/imguiManager.cpp @@ -134,17 +134,6 @@ void imguiManager::WidgetAddObject(ApplicationClass* app) } } -void imguiManager::WidgetShaderWindow(ApplicationClass* app) -{ - ImGui::Begin("Shader Manager"); - - // Checkbox for toggling cel shading globally in the application class by calling the SetCelShading function in the application class when the checkbox state changes - ImGui::Checkbox("Enable Cel Shading", &m_EnableCelShading); - app->SetCelShading(m_EnableCelShading); - - ImGui::End(); -} - void imguiManager::WidgetObjectWindow(ApplicationClass* app) { ImGui::Begin("Objects", &showObjectWindow); @@ -417,11 +406,6 @@ bool imguiManager::ImGuiWidgetRenderer(ApplicationClass* app) WidgetLightWindow(app); } - if (showShaderWindow) - { - WidgetShaderWindow(app); - } - if (showEngineSettingsWindow) { WidgetEngineSettingsWindow(app);