From 58cafd7682abc0b731895b3841d46a790d7bf218 Mon Sep 17 00:00:00 2001 From: CatChow0 Date: Tue, 14 Jan 2025 16:10:40 +0100 Subject: [PATCH] faut tout pt encore --- enginecustom/applicationclass.cpp | 1 + enginecustom/assets/Texture/imgui.ini | 28 ++++++++++++ enginecustom/celshading.ps | 61 ++------------------------- enginecustom/celshading.vs | 2 +- enginecustom/imgui.ini | 2 +- enginecustom/imguiManager.cpp | 37 ++++------------ enginecustom/normalmapshaderclass.cpp | 4 ++ 7 files changed, 47 insertions(+), 88 deletions(-) create mode 100644 enginecustom/assets/Texture/imgui.ini diff --git a/enginecustom/applicationclass.cpp b/enginecustom/applicationclass.cpp index 9f34040..087b92f 100644 --- a/enginecustom/applicationclass.cpp +++ b/enginecustom/applicationclass.cpp @@ -1505,6 +1505,7 @@ void ApplicationClass::AddKobject(WCHAR* filepath) // Liste des fichiers de texture std::vector kobjTexture = { L"assets/Texture/Bricks2K.png", + L"assets/Texture/BricksNRM2K.png", L"assets/Texture/EmptyTexture.png" }; diff --git a/enginecustom/assets/Texture/imgui.ini b/enginecustom/assets/Texture/imgui.ini new file mode 100644 index 0000000..244abcd --- /dev/null +++ b/enginecustom/assets/Texture/imgui.ini @@ -0,0 +1,28 @@ +[Window][Debug##Default] +Pos=60,60 +Size=400,400 + +[Window][Khaotic Engine] +Pos=1142,43 +Size=392,273 + +[Window][Objects] +Pos=598,29 +Size=457,294 + +[Window][Terrain] +Pos=58,62 +Size=342,82 + +[Window][Light] +Pos=1548,17 +Size=358,535 + +[Window][Shader Manager] +Pos=471,90 +Size=180,79 + +[Window][Engine Settings] +Pos=106,212 +Size=407,81 + diff --git a/enginecustom/celshading.ps b/enginecustom/celshading.ps index 32fd479..ff3ee0e 100644 --- a/enginecustom/celshading.ps +++ b/enginecustom/celshading.ps @@ -24,64 +24,11 @@ struct PixelInputType float4 CelShadingPixelShader(PixelInputType input) : SV_TARGET { - float4 textureColor; - float lightIntensity; - float4 finalColor; - - // Sample the pixel color from the texture. - textureColor = shaderTexture.Sample(SampleType, input.tex); - + // Normalize the normal float3 normal = normalize(input.normal); - // Calculate the light vector from the light position to the world position - float3 lightVector = normalize(lightPosition - input.worldPos); + // Convert the normal to a color + float4 color = float4((normal + 1.0f) * 0.5f, 1.0f); - // Calculate the light intensity based on the light direction. - float directionalLightIntensity = saturate(dot(normal, normalize(lightDirection))); - - // Calculate the light intensity based on the light position. - float positionalLightIntensity = saturate(dot(normal, lightVector)); - - // Combine the directional and positional light intensities. - lightIntensity = max(directionalLightIntensity, positionalLightIntensity); - - // Calculate the distance from the light to the fragment. - float distance = length(lightPosition - input.worldPos); - - // Apply an attenuation factor based on the distance. - float attenuation = 1.0f / (constantAttenuation + linearAttenuation * distance + quadraticAttenuation * distance * distance); - - // Combine the light intensity with the attenuation factor. - lightIntensity *= attenuation; - - // Apply a step function to create the cel shading effect. - if (lightIntensity > 0.75f) - { - lightIntensity = 1.0f; // Brightest level - } - else if (lightIntensity > 0.5f) - { - lightIntensity = 0.7f; // Mid-bright level - } - else if (lightIntensity > 0.25f) - { - lightIntensity = 0.4f; // Mid-dark level - } - else - { - lightIntensity = 0.1f; // Darkest level - } - - // Simple shadow calculation: if the fragment is behind the light source, it is in shadow. - float3 toLight = normalize(lightPosition - input.worldPos); - float shadow = saturate(dot(normal, toLight)); - if (shadow < 0.1f) - { - lightIntensity *= 0.5f; // Darken the fragment if it is in shadow - } - - // Calculate the final color by combining the texture color with the light intensity and diffuse color. - finalColor = textureColor * diffuseColor * lightIntensity; - - return finalColor; + return color; } diff --git a/enginecustom/celshading.vs b/enginecustom/celshading.vs index 842d724..774baf8 100644 --- a/enginecustom/celshading.vs +++ b/enginecustom/celshading.vs @@ -42,4 +42,4 @@ PixelInputType CelShadingVertexShader(VertexInputType input) output.tex = input.tex; return output; -} \ No newline at end of file +} diff --git a/enginecustom/imgui.ini b/enginecustom/imgui.ini index 50a166a..244abcd 100644 --- a/enginecustom/imgui.ini +++ b/enginecustom/imgui.ini @@ -7,7 +7,7 @@ Pos=1142,43 Size=392,273 [Window][Objects] -Pos=934,36 +Pos=598,29 Size=457,294 [Window][Terrain] diff --git a/enginecustom/imguiManager.cpp b/enginecustom/imguiManager.cpp index 6771062..4a94b88 100644 --- a/enginecustom/imguiManager.cpp +++ b/enginecustom/imguiManager.cpp @@ -93,7 +93,7 @@ void imguiManager::WidgetAddObject(ApplicationClass* app) ofn.lpstrFile = szFile; ofn.lpstrFile[0] = '\0'; ofn.nMaxFile = sizeof(szFile); - ofn.lpstrFilter = L"TXT\0*.txt\0KOBJ\0*.kobj\0*OBJ\0*.obj"; + ofn.lpstrFilter = L"OBJ\0*.obj\0KOBJ\0*.kobj\0TXT\0*.txt"; ofn.nFilterIndex = 1; ofn.lpstrFileTitle = NULL; ofn.nMaxFileTitle = 0; @@ -169,36 +169,15 @@ void imguiManager::WidgetObjectWindow(ApplicationClass* app) "Refraction" }; - - for (int count = 0; count < 1; count++) - { - std::string textureLabel = "Texture##" + std::to_string(index); - ID3D11ShaderResourceView* texture = object->GetTexture(count); - if (texture != nullptr) - { - // Set the cursor position - ImGui::SetCursorPosX(count * (64 + 20) + 10); // 64 is the width of the image, 10 is the spacing - - // Display the texture name - std::string textureName = textureCategories[count]; - ImGui::Text(textureName.c_str()); - - if(count < 5) - { - ImGui::SameLine(); - } - } - } - // Display all images - for (int count = 0; count < 1; count++) + for (int count = 0; count < textureCategories.size(); count++) { - std::string textureLabel = "Texture##" + std::to_string(index); + std::string textureLabel = "Texture##" + std::to_string(index) + "##" + std::to_string(count); ID3D11ShaderResourceView* texture = object->GetTexture(count); if (texture != nullptr) { - // Set the cursor position - ImGui::SetCursorPosX(count * (64 + 20) + 10); // 64 is the width of the image, 10 is the spacing + ImGui::Text(textureCategories[count].c_str()); + ImGui::SameLine(); if (ImGui::ImageButton((ImTextureID)texture, ImVec2(64, 64))) { @@ -221,7 +200,7 @@ void imguiManager::WidgetObjectWindow(ApplicationClass* app) if (GetOpenFileName(&ofn)) { // Load the selected texture - object->ChangeTexture(m_device, m_deviceContext, ofn.lpstrFile, index); + object->ChangeTexture(m_device, m_deviceContext, ofn.lpstrFile, count); } } @@ -232,8 +211,7 @@ void imguiManager::WidgetObjectWindow(ApplicationClass* app) ImGui::EndTooltip(); } - // If this is not the last texture, put the next button on the same line - if (count < 5) + if (count < textureCategories.size() - 1) { ImGui::SameLine(); } @@ -310,6 +288,7 @@ void imguiManager::WidgetTerrainWindow(ApplicationClass* app) app->DeleteTerrain(); } + ImGui::End(); } diff --git a/enginecustom/normalmapshaderclass.cpp b/enginecustom/normalmapshaderclass.cpp index 6333e1c..58d491b 100644 --- a/enginecustom/normalmapshaderclass.cpp +++ b/enginecustom/normalmapshaderclass.cpp @@ -442,6 +442,10 @@ bool NormalMapShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContex // Finally set the light constant buffer in the pixel shader with the updated values. deviceContext->PSSetConstantBuffers(bufferNumber, 1, &m_lightBuffer); + // Set shader texture resources in the pixel shader. + deviceContext->PSSetShaderResources(0, 1, &texture1); + deviceContext->PSSetShaderResources(1, 1, &texture2); + return true; }