faut tout pt encore

This commit is contained in:
CatChow0 2025-01-14 16:10:40 +01:00
parent c5de18a9b3
commit 58cafd7682
7 changed files with 47 additions and 88 deletions

View File

@ -1505,6 +1505,7 @@ void ApplicationClass::AddKobject(WCHAR* filepath)
// Liste des fichiers de texture
std::vector<std::wstring> kobjTexture = {
L"assets/Texture/Bricks2K.png",
L"assets/Texture/BricksNRM2K.png",
L"assets/Texture/EmptyTexture.png"
};

View File

@ -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

View File

@ -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;
}

View File

@ -42,4 +42,4 @@ PixelInputType CelShadingVertexShader(VertexInputType input)
output.tex = input.tex;
return output;
}
}

View File

@ -7,7 +7,7 @@ Pos=1142,43
Size=392,273
[Window][Objects]
Pos=934,36
Pos=598,29
Size=457,294
[Window][Terrain]

View File

@ -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();
}

View File

@ -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;
}