mirror of
https://github.com/antopilo/Nuake.git
synced 2026-01-04 22:10:34 +03:00
Added alpha scissoring in material editor + shadows
This commit is contained in:
@@ -45,6 +45,7 @@ struct Material
|
||||
int receiveShadow;
|
||||
int castShadow;
|
||||
int unlit;
|
||||
int alphaScissor;
|
||||
};
|
||||
[[vk::binding(0, 3)]]
|
||||
StructuredBuffer<Material> material;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
struct PSInput
|
||||
{
|
||||
float4 Position : SV_Position;
|
||||
float2 UV : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct ModelPushConstant
|
||||
@@ -17,4 +18,14 @@ ModelPushConstant pushConstants;
|
||||
|
||||
void main(PSInput input)
|
||||
{
|
||||
Material inMaterial = material[pushConstants.materialIndex];
|
||||
if(inMaterial.alphaScissor == 1)
|
||||
{
|
||||
SamplerState samplerr = mySampler[inMaterial.samplingType];
|
||||
float albedoAlpha = textures[inMaterial.albedoTextureId].Sample(samplerr, input.UV).a;
|
||||
if(albedoAlpha < 0.1f)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ ModelPushConstant pushConstants;
|
||||
struct VSOutput
|
||||
{
|
||||
float4 Position : SV_Position;
|
||||
float2 UV : TEXCOORD0;
|
||||
};
|
||||
|
||||
float LinearizeDepth(float depth, float nearPlane, float farPlane, bool reverseDepth)
|
||||
@@ -43,6 +44,7 @@ VSOutput main(uint vertexIndex : SV_VertexID)
|
||||
|
||||
// Output the position of each vertex
|
||||
output.Position = mul(camView.Projection, mul(camView.View,mul(modelData.model, float4(v.position, 1.0f))));
|
||||
output.UV = float2(v.uv_x, v.uv_y);
|
||||
|
||||
//output.Position.z = LinearizeDepth(output.Position.z, camView.Near, camView.Far, false);
|
||||
return output;
|
||||
|
||||
@@ -37,6 +37,23 @@ PSOutput main(PSInput input)
|
||||
Material inMaterial = material[pushConstants.materialIndex];
|
||||
|
||||
SamplerState samplerr = mySampler[inMaterial.samplingType];
|
||||
|
||||
// ALBEDO COLOR
|
||||
float4 albedoColor = float4(inMaterial.albedo.xyz, 1.0f);
|
||||
if(inMaterial.hasAlbedo == 1)
|
||||
{
|
||||
float4 albedoSample = textures[inMaterial.albedoTextureId].Sample(samplerr, input.UV);
|
||||
|
||||
// Alpha cutout?
|
||||
if(inMaterial.alphaScissor == 1 && albedoSample.a < 0.001f)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
|
||||
albedoColor.xyz = albedoSample.xyz * albedoColor.xyz;
|
||||
}
|
||||
output.oColor0 = albedoColor;
|
||||
|
||||
// NORMAL
|
||||
// TODO use TBN matrix
|
||||
float3 T = input.Tangent.xyz;
|
||||
@@ -63,21 +80,7 @@ PSOutput main(PSInput input)
|
||||
|
||||
// MATERIAL
|
||||
|
||||
// ALBEDO COLOR
|
||||
float4 albedoColor = float4(inMaterial.albedo.xyz, 1.0f);
|
||||
if(inMaterial.hasAlbedo == 1)
|
||||
{
|
||||
float4 albedoSample = textures[inMaterial.albedoTextureId].Sample(samplerr, input.UV);
|
||||
|
||||
// Alpha cutout?
|
||||
if(albedoSample.a < 0.001f)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
|
||||
albedoColor.xyz = albedoSample.xyz;
|
||||
}
|
||||
output.oColor0 = albedoColor;
|
||||
|
||||
// MATERIAL PROPERTIES
|
||||
float metalnessValue = inMaterial.metalnessValue;
|
||||
|
||||
@@ -502,6 +502,16 @@ void MaterialEditor::Draw(Ref<Nuake::Material> material)
|
||||
ImGui::TableNextColumn();
|
||||
}
|
||||
|
||||
{
|
||||
ImGui::Text("Alpha Scissoring");
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ImGui::Checkbox("##AlphaScissor", &material->m_AlphaScissor);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TableNextColumn();
|
||||
}
|
||||
|
||||
{
|
||||
ImGui::Text("Unlit");
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
@@ -83,6 +83,7 @@ namespace Nuake
|
||||
CullingType m_CullingType = CullingType::Back;
|
||||
bool m_ReceiveShadows = true;
|
||||
bool m_CastShadows = true;
|
||||
bool m_AlphaScissor = false;
|
||||
|
||||
Ref<Texture> m_Albedo;
|
||||
Ref<Texture> m_AO;
|
||||
|
||||
@@ -49,6 +49,7 @@ ShadowRenderPipeline::ShadowRenderPipeline()
|
||||
auto& cmd = ctx.commandBuffer;
|
||||
auto& scene = ctx.scene;
|
||||
auto& vk = VkRenderer::Get();
|
||||
auto& res = GPUResources::Get();
|
||||
|
||||
ZoneScopedN("Render Models");
|
||||
auto view = scene->m_Registry.view<TransformComponent, ModelComponent, VisibilityComponent>();
|
||||
@@ -72,14 +73,16 @@ ShadowRenderPipeline::ShadowRenderPipeline()
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
gbufferConstant.MaterialIndex = res.MeshMaterialMapping[vkMesh->GetID()];
|
||||
}
|
||||
|
||||
gbufferConstant.Index = GPUResources::Get().GetBindlessTransformID(entityId);
|
||||
gbufferConstant.CameraID = ctx.cameraID;
|
||||
|
||||
|
||||
cmd.PushConstants(ctx.renderPass->PipelineLayout, sizeof(GBufferConstant), &gbufferConstant);
|
||||
cmd.BindIndexBuffer(vkMesh->GetIndexBuffer()->GetBuffer());
|
||||
cmd.DrawIndexed(vkMesh->GetIndexBuffer()->GetSize() / sizeof(uint32_t));
|
||||
cmd.DrawIndexed(vkMesh->GetIndexBuffer()->GetSize() / sizeof(uint32_t));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -165,7 +165,7 @@ Ref<VulkanShader> ShaderCompiler::CompileShader(const std::string& path)
|
||||
|
||||
Logger::Log("Shader compilation failed: " + errorMsgStr, "DXC", CRITICAL);
|
||||
|
||||
throw std::runtime_error("Shader compilation failed: " + errorMsgStr);
|
||||
throw std::runtime_error("Shader compilation failed: " + errorMsgStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -46,6 +46,8 @@ namespace Nuake
|
||||
int ReceiveShadow;
|
||||
int CastShadow;
|
||||
int Unlit;
|
||||
int AlphaScissor;
|
||||
int pad[3];
|
||||
};
|
||||
|
||||
// This is the *whole* buffer
|
||||
|
||||
@@ -555,7 +555,8 @@ void VkSceneRenderer::PrepareScenes(const std::vector<Ref<Scene>>& scenes, Rende
|
||||
.SamplerType = static_cast<int>(material->m_SamplingType),
|
||||
.ReceiveShadow = material->m_ReceiveShadows,
|
||||
.CastShadow = material->m_CastShadows,
|
||||
.Unlit = material->data.u_Unlit
|
||||
.Unlit = material->data.u_Unlit,
|
||||
.AlphaScissor = static_cast<int>(material->m_AlphaScissor)
|
||||
};
|
||||
|
||||
// Save bindless mapping index
|
||||
|
||||
Reference in New Issue
Block a user