From 425224a96ca1a83ab3d72d42b940ced2eec0c9ce Mon Sep 17 00:00:00 2001 From: CatChow0 Date: Thu, 23 Jan 2025 22:45:59 +0100 Subject: [PATCH] patch update - fix sunlight shader MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prend en compte les paramètres direction et intensité --- enginecustom/imgui.ini | 2 +- enginecustom/imguiManager.cpp | 47 +++++++++++++++++++---------------- enginecustom/sunlight.ps | 7 ++---- enginecustom/sunlight.vs | 7 ------ 4 files changed, 29 insertions(+), 34 deletions(-) diff --git a/enginecustom/imgui.ini b/enginecustom/imgui.ini index d254183..cc9454d 100644 --- a/enginecustom/imgui.ini +++ b/enginecustom/imgui.ini @@ -79,7 +79,7 @@ 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=0x321620B2 + 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 diff --git a/enginecustom/imguiManager.cpp b/enginecustom/imguiManager.cpp index 75003ac..540ca07 100644 --- a/enginecustom/imguiManager.cpp +++ b/enginecustom/imguiManager.cpp @@ -252,31 +252,36 @@ void imguiManager::WidgetObjectWindow(ApplicationClass* app) app->DeleteKobject(index); } - // Shader selection - std::string shaderLabel = "Shader##" + std::to_string(index); + ImGui::Separator(); - // Radio buttons for shader options - Object::ShaderType activeShader = object->GetActiveShader(); - - if (ImGui::RadioButton("Enable Lighting", activeShader == Object::LIGHTING)) + // Liste des options + const char* shaderOptions[] = { "Enable Global Lighting", "Enable Lighting", "Enable Cel Shading", "Enable Normal Mapping", "Enable Specular Mapping" }; + Object::ShaderType shaderTypes[] = { Object::SUNLIGHT,Object::LIGHTING, Object::CEL_SHADING, Object::NORMAL_MAPPING, Object::SPECULAR_MAPPING }; + + // Variable pour stocker l'option sélectionnée + static int currentShader = 0; // Index de l'option actuellement sélectionnée + + // Création du menu déroulant + if (ImGui::BeginCombo("Shader Options", shaderOptions[currentShader])) { - object->SetActiveShader(Object::LIGHTING); - } - - if (ImGui::RadioButton("Enable Cel Shading", activeShader == Object::CEL_SHADING)) - { - object->SetActiveShader(Object::CEL_SHADING); - } - - if (ImGui::RadioButton("Enable Normal Mapping", activeShader == Object::NORMAL_MAPPING)) - { - object->SetActiveShader(Object::NORMAL_MAPPING); + for (int i = 0; i < IM_ARRAYSIZE(shaderOptions); i++) + { + // Crée une option sélectionnable pour chaque shader + bool isSelected = (currentShader == i); + if (ImGui::Selectable(shaderOptions[i], isSelected)) + { + // Met à jour l'option sélectionnée + currentShader = i; + object->SetActiveShader(shaderTypes[i]); + } + + // Si l'option sélectionnée est active, nous mettons en surbrillance + if (isSelected) + ImGui::SetItemDefaultFocus(); + } + ImGui::EndCombo(); } - if (ImGui::RadioButton("Enable Specular Mapping", activeShader == Object::SPECULAR_MAPPING)) - { - object->SetActiveShader(Object::SPECULAR_MAPPING); - } ImGui::Separator(); diff --git a/enginecustom/sunlight.ps b/enginecustom/sunlight.ps index bf13fa7..0e1b84b 100644 --- a/enginecustom/sunlight.ps +++ b/enginecustom/sunlight.ps @@ -24,8 +24,6 @@ struct PixelInputType float4 position : SV_POSITION; float2 tex : TEXCOORD0; float3 normal : NORMAL; - float3 lightDir : TEXCOORD1; - float intensity : TEXCOORD2; }; //////////////////////////////////////////////////////////////////////////////// @@ -34,7 +32,6 @@ struct PixelInputType float4 SunLightPixelShader(PixelInputType input) : SV_TARGET { float4 textureColor; - float3 lightDir; float4 color; float lightIntensity; float4 colorArray; @@ -44,10 +41,10 @@ float4 SunLightPixelShader(PixelInputType input) : SV_TARGET 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, input.lightDir)) * input.intensity; + lightIntensity = saturate(dot(input.normal, -lightDirection)); // Determine the diffuse color amount of the light. - colorArray = diffuseColor * lightIntensity; + colorArray = (diffuseColor * lightIntensity) * intensity; // Initialize the sum of colors. colorSum = float4(0.0f, 0.0f, 0.0f, 1.0f); diff --git a/enginecustom/sunlight.vs b/enginecustom/sunlight.vs index 8c2a64b..46fab3b 100644 --- a/enginecustom/sunlight.vs +++ b/enginecustom/sunlight.vs @@ -37,8 +37,6 @@ struct PixelInputType float4 position : SV_POSITION; float2 tex : TEXCOORD0; float3 normal : NORMAL; - float3 lightDir : TEXCOORD1; - float intensity : TEXCOORD2; }; //////////////////////////////////////////////////////////////////////////////// @@ -65,10 +63,5 @@ PixelInputType SunLightVertexShader(VertexInputType input) // Normalize the normal vector. output.normal = normalize(output.normal); - // Use the light direction directly. - output.lightDir = normalize(lightDirection); - - output.intensity = intensity; - return output; }