mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-15 20:08:54 +03:00
PBR Directional light working
This commit is contained in:
@@ -98,13 +98,13 @@ void VkSceneRenderer::EndScene()
|
||||
|
||||
auto& albedo = GBufferPipeline.GetRenderPass("GBuffer").GetAttachment("Albedo");
|
||||
auto& normal = GBufferPipeline.GetRenderPass("GBuffer").GetAttachment("Normal");
|
||||
VulkanUtil::TransitionImage(cmd, albedo.Image->GetImage(), VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
||||
VulkanUtil::TransitionImage(cmd, normal.Image->GetImage(), VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
||||
auto& shading = GBufferPipeline.GetRenderPass("Shading").GetAttachment("Output");
|
||||
auto& selectedOutput = shading;
|
||||
VulkanUtil::TransitionImage(cmd, selectedOutput.Image->GetImage(), VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
|
||||
VulkanUtil::TransitionImage(cmd, vk.DrawImage->GetImage(), VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||
VulkanUtil::CopyImageToImage(cmd, normal.Image->GetImage(), vk.GetDrawImage()->GetImage(), albedo.Image->GetSize(), vk.DrawImage->GetSize());
|
||||
VulkanUtil::CopyImageToImage(cmd, selectedOutput.Image->GetImage(), vk.GetDrawImage()->GetImage(), selectedOutput.Image->GetSize(), vk.DrawImage->GetSize());
|
||||
VulkanUtil::TransitionImage(cmd, vk.DrawImage->GetImage(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL);
|
||||
VulkanUtil::TransitionImage(cmd, normal.Image->GetImage(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL);
|
||||
VulkanUtil::TransitionImage(cmd, albedo.Image->GetImage(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL);
|
||||
VulkanUtil::TransitionImage(cmd, selectedOutput.Image->GetImage(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL);
|
||||
}
|
||||
|
||||
void VkSceneRenderer::CreateBuffers()
|
||||
@@ -361,7 +361,7 @@ void VkSceneRenderer::CreatePipelines()
|
||||
shadingPass.SetDepthTest(false);
|
||||
shadingPass.AddInput("Albedo");
|
||||
shadingPass.AddInput("Normal");
|
||||
//shadingPass.AddInput("Depth");
|
||||
shadingPass.AddInput("Depth");
|
||||
shadingPass.AddInput("Material");
|
||||
shadingPass.SetPreRender([&](PassRenderContext& ctx) {
|
||||
std::vector<VkDescriptorSet> descriptors2 = { CameraBufferDescriptors, ModelBufferDescriptor };
|
||||
|
||||
@@ -74,9 +74,9 @@ float LinearizeDepth(float depth, float nearPlane, float farPlane, bool reverseD
|
||||
}
|
||||
}
|
||||
|
||||
const float PI = 3.141592653589793f;
|
||||
float DistributionGGX(float3 N, float3 H, float a)
|
||||
{
|
||||
float PI = 3.141592653589793f;
|
||||
float a2 = a * a;
|
||||
float NdotH = max(dot(N, H), 0.0);
|
||||
float NdotH2 = NdotH * NdotH;
|
||||
@@ -130,9 +130,9 @@ PSOutput main(PSInput input)
|
||||
float3 albedo = textures[albedoTextureId].Sample(mySampler, input.UV).xyz;
|
||||
float3 normal = textures[pushConstants.NormalInputTextureId].Sample(mySampler, input.UV).rgb;
|
||||
|
||||
output.oColor0 = float4(normal, 1);
|
||||
return output;
|
||||
|
||||
//output.oColor0 = float4(normal, 1);
|
||||
//return output//;
|
||||
//
|
||||
float4 materialSample = textures[pushConstants.MaterialInputTextureId].Sample(mySampler, input.UV);
|
||||
float metallic = materialSample.r;
|
||||
float ao = materialSample.g;
|
||||
@@ -148,7 +148,7 @@ PSOutput main(PSInput input)
|
||||
float3 Lo = float3(0.0, 0.0, 0.0);
|
||||
|
||||
// Directional light
|
||||
float3 dir = normalize(float3(0.1, -1.0, 0.1f));
|
||||
float3 dir = normalize(float3(0.1, 1.0, 0.1f));
|
||||
float attenuation = 1.0f;
|
||||
|
||||
float3 L = dir;
|
||||
@@ -163,16 +163,17 @@ PSOutput main(PSInput input)
|
||||
float3 specular = nominator / denominator;
|
||||
|
||||
float3 kS = F;
|
||||
float3 kD = float3(1.0, 1.0, 1.0) - kS;
|
||||
float3 kD = float3(3.0, 3.0, 3.0) - kS;
|
||||
kD *= 1.0 - metallic;
|
||||
|
||||
float NdotL = max(dot(N, L), 0.0);
|
||||
const float PI = 3.141592653589793f;
|
||||
Lo += (kD * albedo / PI + specular) * radiance * NdotL;
|
||||
|
||||
|
||||
float3 ambient = (albedo) * ao * 0.5f;
|
||||
float3 color = (ambient) + Lo;
|
||||
|
||||
output.oColor0 = float4(ambient, 1);
|
||||
output.oColor0 = float4(color, 1);
|
||||
return output;
|
||||
}
|
||||
@@ -73,7 +73,7 @@ PSOutput main(PSInput input)
|
||||
|
||||
normal = mul(input.TBN, normal);
|
||||
normal = normal / 2.0f + 0.5f;
|
||||
output.oNormal = float4(float3(1, 0, 0), 1.0f);
|
||||
output.oNormal = float4(normal, 1.0f);
|
||||
|
||||
// MATERIAL
|
||||
|
||||
@@ -92,7 +92,7 @@ PSOutput main(PSInput input)
|
||||
albedoColor.xyz = albedoSample.xyz;
|
||||
}
|
||||
output.oColor0 = albedoColor;
|
||||
|
||||
|
||||
// MATERIAL PROPERTIES
|
||||
float metalnessValue = inMaterial.metalnessValue;
|
||||
if(inMaterial.hasMetalness == 1)
|
||||
|
||||
@@ -67,6 +67,6 @@ VSOutput main(uint vertexIndex : SV_VertexID)
|
||||
float3 T = normalize(mul((float3x3)modelData.model, normalize(v.tangent.xyz)));
|
||||
float3 B = normalize(mul((float3x3)modelData.model, normalize(v.bitangent.xyz)));
|
||||
float3 N = normalize(mul((float3x3)modelData.model, normalize(v.normal)).xyz);
|
||||
output.TBN = float3x3(T, B, N);
|
||||
output.TBN = transpose(float3x3(T, B, N));
|
||||
return output;
|
||||
}
|
||||
Reference in New Issue
Block a user