Added cast,receive shadows & unlit flags in the materials
This commit is contained in:
@@ -42,6 +42,9 @@ struct Material
|
||||
int roughnessTextureId;
|
||||
int aoTextureId;
|
||||
int samplingType;
|
||||
int receiveShadow;
|
||||
int castShadow;
|
||||
int unlit;
|
||||
};
|
||||
[[vk::binding(0, 3)]]
|
||||
StructuredBuffer<Material> material;
|
||||
@@ -104,7 +107,7 @@ BlurConstant pushConstants;
|
||||
|
||||
float3 SampleTexture(int textureId, float2 uv)
|
||||
{
|
||||
return textures[textureId].Sample(mySampler[1], uv).rgb;
|
||||
return textures[textureId].Sample(mySampler[0], uv).rgb;
|
||||
}
|
||||
|
||||
PSOutput main(PSInput input)
|
||||
|
||||
@@ -42,6 +42,9 @@ struct Material
|
||||
int roughnessTextureId;
|
||||
int aoTextureId;
|
||||
int samplingType;
|
||||
int receiveShadow;
|
||||
int castShadow;
|
||||
int unlit;
|
||||
};
|
||||
[[vk::binding(0, 3)]]
|
||||
StructuredBuffer<Material> material;
|
||||
|
||||
@@ -42,6 +42,9 @@ struct Material
|
||||
int roughnessTextureId;
|
||||
int aoTextureId;
|
||||
int samplingType;
|
||||
int receiveShadow;
|
||||
int castShadow;
|
||||
int unlit;
|
||||
};
|
||||
[[vk::binding(0, 3)]]
|
||||
StructuredBuffer<Material> material;
|
||||
@@ -109,8 +112,8 @@ PSOutput main(PSInput input)
|
||||
int source2TextureID = pushConstants.Source2TextureID;
|
||||
|
||||
float2 uv = input.UV;
|
||||
float4 sampleValue = textures[sourceTextureID].Sample(mySampler[1], input.UV);
|
||||
float4 sampleValue2 = textures[source2TextureID].Sample(mySampler[1], input.UV);
|
||||
float4 sampleValue = textures[sourceTextureID].Sample(mySampler[0], input.UV);
|
||||
float4 sampleValue2 = textures[source2TextureID].Sample(mySampler[0], input.UV);
|
||||
|
||||
if(pushConstants.Mode == 0)
|
||||
{
|
||||
|
||||
@@ -42,6 +42,9 @@ struct Material
|
||||
int roughnessTextureId;
|
||||
int aoTextureId;
|
||||
int samplingType;
|
||||
int receiveShadow;
|
||||
int castShadow;
|
||||
int unlit;
|
||||
};
|
||||
[[vk::binding(0, 3)]]
|
||||
StructuredBuffer<Material> material;
|
||||
|
||||
@@ -42,6 +42,9 @@ struct Material
|
||||
int roughnessTextureId;
|
||||
int aoTextureId;
|
||||
int samplingType;
|
||||
int receiveShadow;
|
||||
int castShadow;
|
||||
int unlit;
|
||||
};
|
||||
[[vk::binding(0, 3)]]
|
||||
StructuredBuffer<Material> material;
|
||||
@@ -116,8 +119,8 @@ float PixelToUV(float2 uv, Texture2D tex)
|
||||
PSOutput main(PSInput input)
|
||||
{
|
||||
int depthTexture = pushConstants.DepthTextureID;
|
||||
float upSampledDepth = textures[depthTexture].Sample(mySampler[1], input.UV).r;
|
||||
float3 upSampledColor = textures[pushConstants.VolumetricTextureID].Sample(mySampler[1], input.UV).rgb;
|
||||
float upSampledDepth = textures[depthTexture].Sample(mySampler[0], input.UV).r;
|
||||
float3 upSampledColor = textures[pushConstants.VolumetricTextureID].Sample(mySampler[0], input.UV).rgb;
|
||||
float3 color = 0.0f.xxx;
|
||||
float totalWeight = 0.0f;
|
||||
|
||||
@@ -134,8 +137,8 @@ PSOutput main(PSInput input)
|
||||
{
|
||||
float2 uvOffset = float2(offsets[i].x * 4.0, offsets[i].y * 4.0) ;
|
||||
uvOffset = PixelToUV(uvOffset, textures[pushConstants.DepthTextureID]);
|
||||
float3 downscaledColor = textures[pushConstants.VolumetricTextureID].Sample(mySampler[1], input.UV + uvOffset).rgb;
|
||||
float downscaledDepth = textures[pushConstants.DepthTextureID].Sample(mySampler[1], input.UV + uvOffset).r;
|
||||
float3 downscaledColor = textures[pushConstants.VolumetricTextureID].Sample(mySampler[0], input.UV + uvOffset).rgb;
|
||||
float downscaledDepth = textures[pushConstants.DepthTextureID].Sample(mySampler[0], input.UV + uvOffset).r;
|
||||
|
||||
float currentWeight = 1.0f;
|
||||
|
||||
|
||||
@@ -42,6 +42,9 @@ struct Material
|
||||
int roughnessTextureId;
|
||||
int aoTextureId;
|
||||
int samplingType;
|
||||
int receiveShadow;
|
||||
int castShadow;
|
||||
int unlit;
|
||||
};
|
||||
[[vk::binding(0, 3)]]
|
||||
StructuredBuffer<Material> material;
|
||||
|
||||
@@ -42,6 +42,9 @@ struct Material
|
||||
int roughnessTextureId;
|
||||
int aoTextureId;
|
||||
int samplingType;
|
||||
int receiveShadow;
|
||||
int castShadow;
|
||||
int unlit;
|
||||
};
|
||||
[[vk::binding(0, 3)]]
|
||||
StructuredBuffer<Material> material;
|
||||
@@ -115,7 +118,7 @@ PSOutput main(PSInput input)
|
||||
else
|
||||
{
|
||||
float2 uv = input.UV;
|
||||
float4 textureSample = textures[pushConstants.TextureID].Sample(mySampler[1], uv);
|
||||
float4 textureSample = textures[pushConstants.TextureID].Sample(mySampler[0], uv);
|
||||
|
||||
// Alpha scisorring
|
||||
if(textureSample.a < 0.1)
|
||||
|
||||
@@ -42,6 +42,9 @@ struct Material
|
||||
int roughnessTextureId;
|
||||
int aoTextureId;
|
||||
int samplingType;
|
||||
int receiveShadow;
|
||||
int castShadow;
|
||||
int unlit;
|
||||
};
|
||||
[[vk::binding(0, 3)]]
|
||||
StructuredBuffer<Material> material;
|
||||
|
||||
@@ -42,6 +42,9 @@ struct Material
|
||||
int roughnessTextureId;
|
||||
int aoTextureId;
|
||||
int samplingType;
|
||||
int receiveShadow;
|
||||
int castShadow;
|
||||
int unlit;
|
||||
};
|
||||
[[vk::binding(0, 3)]]
|
||||
StructuredBuffer<Material> material;
|
||||
|
||||
@@ -42,6 +42,9 @@ struct Material
|
||||
int roughnessTextureId;
|
||||
int aoTextureId;
|
||||
int samplingType;
|
||||
int receiveShadow;
|
||||
int castShadow;
|
||||
int unlit;
|
||||
};
|
||||
[[vk::binding(0, 3)]]
|
||||
StructuredBuffer<Material> material;
|
||||
|
||||
@@ -42,6 +42,9 @@ struct Material
|
||||
int roughnessTextureId;
|
||||
int aoTextureId;
|
||||
int samplingType;
|
||||
int receiveShadow;
|
||||
int castShadow;
|
||||
int unlit;
|
||||
};
|
||||
[[vk::binding(0, 3)]]
|
||||
StructuredBuffer<Material> material;
|
||||
@@ -128,8 +131,8 @@ PSOutput main(PSInput input)
|
||||
int entityIDTextureID = pushConstants.EntityIDTextureID;
|
||||
float hasHit = 0.0f;
|
||||
|
||||
float sampleValue = textures[entityIDTextureID].Sample(mySampler[1], uv).r;
|
||||
float depth = textures[pushConstants.DepthTextureID].Sample(mySampler[1], uv).r;
|
||||
float sampleValue = textures[entityIDTextureID].Sample(mySampler[0], uv).r;
|
||||
float depth = textures[pushConstants.DepthTextureID].Sample(mySampler[0], uv).r;
|
||||
|
||||
float4 fragColor = float4(0, 0, 0, 0);
|
||||
const float TAU = 6.28318530;
|
||||
@@ -142,8 +145,8 @@ PSOutput main(PSInput input)
|
||||
sampleUV.x = clamp(sampleUV.x, 0.0, 0.999);
|
||||
sampleUV.y = clamp(sampleUV.y, 0.0, 0.999);
|
||||
|
||||
float sample = textures[entityIDTextureID].Sample(mySampler[1], sampleUV).r;
|
||||
float sampleDepth = textures[pushConstants.DepthTextureID].Sample(mySampler[1], sampleUV).r;
|
||||
float sample = textures[entityIDTextureID].Sample(mySampler[0], sampleUV).r;
|
||||
float sampleDepth = textures[pushConstants.DepthTextureID].Sample(mySampler[0], sampleUV).r;
|
||||
|
||||
//sampleDepth = LinearizeDepth(sampleDepth, 0.1f, 200.0f);
|
||||
//depth = LinearizeDepth(depth, 0.1f, 200.0f);
|
||||
@@ -173,7 +176,7 @@ PSOutput main(PSInput input)
|
||||
fragColor.a = 1.0f;
|
||||
}
|
||||
|
||||
float3 sourceTexture = textures[pushConstants.SourceTextureID].Sample(mySampler[1], uv).rgb;
|
||||
float3 sourceTexture = textures[pushConstants.SourceTextureID].Sample(mySampler[0], uv).rgb;
|
||||
float ratio = float(sampleValue != target && hasHit > 0.0f);
|
||||
float4 finalColor = float4(
|
||||
lerp(sourceTexture.r, fragColor.r, ratio),
|
||||
|
||||
@@ -42,6 +42,9 @@ struct Material
|
||||
int roughnessTextureId;
|
||||
int aoTextureId;
|
||||
int samplingType;
|
||||
int receiveShadow;
|
||||
int castShadow;
|
||||
int unlit;
|
||||
};
|
||||
[[vk::binding(0, 3)]]
|
||||
StructuredBuffer<Material> material;
|
||||
|
||||
@@ -42,6 +42,9 @@ struct Material
|
||||
int roughnessTextureId;
|
||||
int aoTextureId;
|
||||
int samplingType;
|
||||
int receiveShadow;
|
||||
int castShadow;
|
||||
int unlit;
|
||||
};
|
||||
|
||||
[[vk::binding(0, 3)]]
|
||||
@@ -104,6 +107,7 @@ struct ShadingPushConstant
|
||||
float AmbientTerm;
|
||||
float cascadeDepth[4];
|
||||
int SSAOTextureId;
|
||||
int EntityTextureId;
|
||||
};
|
||||
|
||||
[[vk::push_constant]]
|
||||
@@ -198,7 +202,7 @@ int GetCSMSplit(float depth)
|
||||
|
||||
float SampleShadowMap(int textureId, float2 coords, float compare)
|
||||
{
|
||||
return compare > textures[textureId].Sample(mySampler[1], coords.xy).r;
|
||||
return compare > textures[textureId].Sample(mySampler[0], coords.xy).r;
|
||||
}
|
||||
|
||||
float SampleShadowMapLinear(int textureId, float2 coords, float compare, float2 texelSize)
|
||||
@@ -260,7 +264,7 @@ float ShadowCalculation(Light light, float3 fragPos, float3 normal)
|
||||
return result /= NUM_SAMPLES_SQUARED;
|
||||
}
|
||||
|
||||
float shadowMapDepth = textures[light.shadowMapTextureId[splitIndex]].Sample(mySampler[1], projCoords.xy).r;
|
||||
float shadowMapDepth = textures[light.shadowMapTextureId[splitIndex]].Sample(mySampler[0], projCoords.xy).r;
|
||||
|
||||
return (currentDepth > shadowMapDepth);//> 0.0 ? 1.0 : 0.0;
|
||||
}
|
||||
@@ -270,24 +274,36 @@ PSOutput main(PSInput input)
|
||||
CameraView camView = cameras[pushConstants.CameraID];
|
||||
|
||||
int depthTexture = pushConstants.DepthInputTextureId;
|
||||
float depth = textures[depthTexture].Sample(mySampler[1], input.UV).r;
|
||||
float depth = textures[depthTexture].Sample(mySampler[0], input.UV).r;
|
||||
|
||||
if(depth == 0.0f)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
|
||||
float3 worldPos = WorldPosFromDepth(depth, input.UV, camView.InverseProjection, camView.InverseView);
|
||||
int albedoTextureId = pushConstants.AlbedoInputTextureId;
|
||||
float3 albedo = textures[albedoTextureId].Sample(mySampler[1], input.UV).xyz;
|
||||
float3 normal = textures[pushConstants.NormalInputTextureId].Sample(mySampler[1], input.UV).rgb;
|
||||
float3 albedo = textures[albedoTextureId].Sample(mySampler[0], input.UV).xyz;
|
||||
int materialId = (int)textures[pushConstants.EntityTextureId].Sample(mySampler[0], input.UV).g;
|
||||
Material inMaterial = material[materialId];
|
||||
|
||||
if(inMaterial.unlit)
|
||||
{
|
||||
output.oColor0 = float4(albedo, 1);
|
||||
return output;
|
||||
}
|
||||
|
||||
float3 worldPos = WorldPosFromDepth(depth, input.UV, camView.InverseProjection, camView.InverseView);
|
||||
|
||||
float3 normal = textures[pushConstants.NormalInputTextureId].Sample(mySampler[0], input.UV).rgb;
|
||||
normal = normal * 2.0f - 1.0f;
|
||||
|
||||
float4 materialSample = textures[pushConstants.MaterialInputTextureId].Sample(mySampler[1], input.UV);
|
||||
float4 materialSample = textures[pushConstants.MaterialInputTextureId].Sample(mySampler[0], input.UV);
|
||||
float metallic = materialSample.r;
|
||||
float ao = materialSample.g;
|
||||
float roughness = materialSample.b;
|
||||
float ssao = textures[pushConstants.SSAOTextureId].Sample(mySampler[1], input.UV);
|
||||
float ssao = textures[pushConstants.SSAOTextureId].Sample(mySampler[0], input.UV).r;
|
||||
|
||||
|
||||
|
||||
float3 N = normal;
|
||||
float3 V = normalize(camView.Position - worldPos);
|
||||
@@ -347,6 +363,11 @@ PSOutput main(PSInput input)
|
||||
kD *= 1.0 - metallic;
|
||||
|
||||
float NdotL = max(dot(N, L), 0.0);
|
||||
|
||||
if(inMaterial.receiveShadow == 0)
|
||||
{
|
||||
shadow = 1.0f;
|
||||
}
|
||||
Lo += (kD * albedo / PI + specular) * radiance * NdotL * shadow;
|
||||
}
|
||||
|
||||
@@ -393,7 +414,7 @@ PSOutput main(PSInput input)
|
||||
float3 kD = 1.0 - kS;
|
||||
kD *= 1.0 - metallic;
|
||||
|
||||
float3 ambient = (albedo) * ao * ssao * pushConstants.AmbientTerm;
|
||||
float3 ambient = (albedo) * ao * ssao * pushConstants.AmbientTerm;
|
||||
float3 color = (ambient) + Lo;
|
||||
|
||||
output.oColor0 = float4(color, 1);
|
||||
|
||||
@@ -42,6 +42,9 @@ struct Material
|
||||
int roughnessTextureId;
|
||||
int aoTextureId;
|
||||
int samplingType;
|
||||
int receiveShadow;
|
||||
int castShadow;
|
||||
int unlit;
|
||||
};
|
||||
[[vk::binding(0, 3)]]
|
||||
StructuredBuffer<Material> material;
|
||||
@@ -93,6 +96,7 @@ struct ShadingPushConstant
|
||||
float AmbientTerm;
|
||||
float cascadeDepth[4];
|
||||
int SSAOTextureId;
|
||||
int EntityTextureId;
|
||||
};
|
||||
|
||||
[[vk::push_constant]]
|
||||
|
||||
@@ -42,6 +42,9 @@ struct Material
|
||||
int roughnessTextureId;
|
||||
int aoTextureId;
|
||||
int samplingType;
|
||||
int receiveShadow;
|
||||
int castShadow;
|
||||
int unlit;
|
||||
};
|
||||
[[vk::binding(0, 3)]]
|
||||
StructuredBuffer<Material> material;
|
||||
|
||||
@@ -42,6 +42,9 @@ struct Material
|
||||
int roughnessTextureId;
|
||||
int aoTextureId;
|
||||
int samplingType;
|
||||
int receiveShadow;
|
||||
int castShadow;
|
||||
int unlit;
|
||||
};
|
||||
[[vk::binding(0, 3)]]
|
||||
StructuredBuffer<Material> material;
|
||||
@@ -132,12 +135,12 @@ float3 WorldPosFromDepth(float depth, float2 uv, CameraView camera)
|
||||
|
||||
float3 SampleTexture(int textureId, float2 uv)
|
||||
{
|
||||
return textures[textureId].Sample(mySampler[1], uv).rgb;
|
||||
return textures[textureId].Sample(mySampler[0], uv).rgb;
|
||||
}
|
||||
|
||||
float SampleDepth(float2 uv)
|
||||
{
|
||||
return textures[pushConstants.depthTextureID].Sample(mySampler[1], uv).r;
|
||||
return textures[pushConstants.depthTextureID].Sample(mySampler[0], uv).r;
|
||||
}
|
||||
|
||||
float3x3 Inverse3x3(float3x3 m)
|
||||
|
||||
@@ -42,6 +42,9 @@ struct Material
|
||||
int roughnessTextureId;
|
||||
int aoTextureId;
|
||||
int samplingType;
|
||||
int receiveShadow;
|
||||
int castShadow;
|
||||
int unlit;
|
||||
};
|
||||
[[vk::binding(0, 3)]]
|
||||
StructuredBuffer<Material> material;
|
||||
|
||||
@@ -42,6 +42,9 @@ struct Material
|
||||
int roughnessTextureId;
|
||||
int aoTextureId;
|
||||
int samplingType;
|
||||
int receiveShadow;
|
||||
int castShadow;
|
||||
int unlit;
|
||||
};
|
||||
[[vk::binding(0, 3)]]
|
||||
StructuredBuffer<Material> material;
|
||||
@@ -123,7 +126,7 @@ float3 PBRNeutralToneMapping(float3 color)
|
||||
PSOutput main(PSInput input)
|
||||
{
|
||||
PSOutput output;
|
||||
float3 color = textures[pushConstants.SourceTextureID].Sample(mySampler[1], input.UV).rgb;
|
||||
float3 color = textures[pushConstants.SourceTextureID].Sample(mySampler[0], input.UV).rgb;
|
||||
float3 mapped = float3(1.0, 1.0, 1.0) - exp(-color * pushConstants.Exposure);
|
||||
|
||||
color = pow(mapped, float3(pushConstants.Gamma, pushConstants.Gamma, pushConstants.Gamma));
|
||||
|
||||
@@ -42,6 +42,9 @@ struct Material
|
||||
int roughnessTextureId;
|
||||
int aoTextureId;
|
||||
int samplingType;
|
||||
int receiveShadow;
|
||||
int castShadow;
|
||||
int unlit;
|
||||
};
|
||||
[[vk::binding(0, 3)]]
|
||||
StructuredBuffer<Material> material;
|
||||
|
||||
@@ -42,6 +42,9 @@ struct Material
|
||||
int roughnessTextureId;
|
||||
int aoTextureId;
|
||||
int samplingType;
|
||||
int receiveShadow;
|
||||
int castShadow;
|
||||
int unlit;
|
||||
};
|
||||
[[vk::binding(0, 3)]]
|
||||
StructuredBuffer<Material> material;
|
||||
@@ -183,7 +186,7 @@ PSOutput main(PSInput input)
|
||||
|
||||
output.oMaterial = float4(materialOuput, 1.0f);
|
||||
|
||||
output.oEntityID = float4(pushConstants.entityID, 0.0f, 0.0f, 1.0f);
|
||||
output.oEntityID = float4(pushConstants.entityID, pushConstants.materialIndex, 0.0f, 1.0f);
|
||||
|
||||
return output;
|
||||
}
|
||||
@@ -42,6 +42,9 @@ struct Material
|
||||
int roughnessTextureId;
|
||||
int aoTextureId;
|
||||
int samplingType;
|
||||
int receiveShadow;
|
||||
int castShadow;
|
||||
int unlit;
|
||||
};
|
||||
[[vk::binding(0, 3)]]
|
||||
StructuredBuffer<Material> material;
|
||||
|
||||
@@ -42,6 +42,9 @@ struct Material
|
||||
int roughnessTextureId;
|
||||
int aoTextureId;
|
||||
int samplingType;
|
||||
int receiveShadow;
|
||||
int castShadow;
|
||||
int unlit;
|
||||
};
|
||||
[[vk::binding(0, 3)]]
|
||||
StructuredBuffer<Material> material;
|
||||
@@ -228,7 +231,7 @@ int GetCSMSplit(float depth)
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
PSOutput main(PSInput input)
|
||||
@@ -242,7 +245,7 @@ PSOutput main(PSInput input)
|
||||
float3 startPosition = camView.Position;
|
||||
|
||||
int depthTexture = pushConstants.DepthTextureID;
|
||||
float depth = textures[depthTexture].Sample(mySampler[1], input.UV).r;
|
||||
float depth = textures[depthTexture].Sample(mySampler[0], input.UV).r;
|
||||
|
||||
float3 worldPos = WorldPosFromDepth(depth, input.UV, camView.InverseProjection, camView.InverseView);
|
||||
|
||||
@@ -275,7 +278,7 @@ PSOutput main(PSInput input)
|
||||
|
||||
if(splitIndex == -1)
|
||||
{
|
||||
accumFog += (ComputeScattering(dot(rayDirection, light.direction)).rrr * light.color.xyz) * pushConstants.Exponant;
|
||||
//accumFog += (ComputeScattering(dot(rayDirection, light.direction)).rrr * light.color.xyz) * pushConstants.Exponant;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -285,7 +288,7 @@ PSOutput main(PSInput input)
|
||||
projCoords.xy = projCoords.xy * 0.5 + 0.5;
|
||||
|
||||
float currentDepth = projCoords.z;
|
||||
float closestDepth = textures[light.shadowMapTextureId[splitIndex]].Sample(mySampler[1], projCoords.xy).r;
|
||||
float closestDepth = textures[light.shadowMapTextureId[splitIndex]].Sample(mySampler[0], projCoords.xy).r;
|
||||
|
||||
float3 noiseOffset = float3(pushConstants.NoiseSpeed * pushConstants.Time, pushConstants.NoiseSpeed * pushConstants.Time, pushConstants.NoiseSpeed * pushConstants.Time);
|
||||
float3 noiseSamplePos = (currentPosition + noiseOffset) * pushConstants.NoiseScale;
|
||||
|
||||
@@ -42,6 +42,9 @@ struct Material
|
||||
int roughnessTextureId;
|
||||
int aoTextureId;
|
||||
int samplingType;
|
||||
int receiveShadow;
|
||||
int castShadow;
|
||||
int unlit;
|
||||
};
|
||||
[[vk::binding(0, 3)]]
|
||||
StructuredBuffer<Material> material;
|
||||
|
||||
@@ -42,6 +42,9 @@ struct Material
|
||||
int roughnessTextureId;
|
||||
int aoTextureId;
|
||||
int samplingType;
|
||||
int receiveShadow;
|
||||
int castShadow;
|
||||
int unlit;
|
||||
};
|
||||
[[vk::binding(0, 3)]]
|
||||
StructuredBuffer<Material> material;
|
||||
@@ -122,8 +125,8 @@ PSOutput main(PSInput input)
|
||||
int entityIDTextureID = pushConstants.EntityIDTextureID;
|
||||
float hasHit = 0.0f;
|
||||
|
||||
float sampleValue = textures[entityIDTextureID].Sample(mySampler[1],, uv).r;
|
||||
float depth = textures[pushConstants.DepthTextureID].Sample(mySampler[1], uv).r;
|
||||
float sampleValue = textures[entityIDTextureID].Sample(mySampler[0],, uv).r;
|
||||
float depth = textures[pushConstants.DepthTextureID].Sample(mySampler[0], uv).r;
|
||||
|
||||
float4 fragColor = float4(0, 0, 0, 0);
|
||||
const float TAU = 6.28318530;
|
||||
@@ -136,8 +139,8 @@ PSOutput main(PSInput input)
|
||||
sampleUV.x = clamp(sampleUV.x, 0.0, 0.999);
|
||||
sampleUV.y = clamp(sampleUV.y, 0.0, 0.999);
|
||||
|
||||
float sample = textures[entityIDTextureID].Sample(mySampler[1], sampleUV).r;
|
||||
float sampleDepth = textures[pushConstants.DepthTextureID].Sample(mySampler[1], sampleUV).r;
|
||||
float sample = textures[entityIDTextureID].Sample(mySampler[0], sampleUV).r;
|
||||
float sampleDepth = textures[pushConstants.DepthTextureID].Sample(mySampler[0], sampleUV).r;
|
||||
if(sample == target && sampleDepth != 1.0f && sampleDepth > depth)
|
||||
{
|
||||
hasHit = 1.0f;
|
||||
@@ -159,7 +162,7 @@ PSOutput main(PSInput input)
|
||||
fragColor.a = 1.0f;
|
||||
}
|
||||
|
||||
float3 sourceTexture = textures[pushConstants.SourceTextureID].Sample(mySampler[1], uv).rgb;
|
||||
float3 sourceTexture = textures[pushConstants.SourceTextureID].Sample(mySampler[0], uv).rgb;
|
||||
float ratio = float(sampleValue != target && hasHit > 0.0f);
|
||||
float4 finalColor = float4(
|
||||
lerp(sourceTexture.r, fragColor.r, ratio),
|
||||
|
||||
@@ -42,6 +42,9 @@ struct Material
|
||||
int roughnessTextureId;
|
||||
int aoTextureId;
|
||||
int samplingType;
|
||||
int receiveShadow;
|
||||
int castShadow;
|
||||
int unlit;
|
||||
};
|
||||
[[vk::binding(0, 3)]]
|
||||
StructuredBuffer<Material> material;
|
||||
@@ -228,7 +231,7 @@ PSOutput main(PSInput input)
|
||||
float3 startPosition = camView.Position;
|
||||
|
||||
int depthTexture = pushConstants.DepthTextureID;
|
||||
float depth = textures[depthTexture].Sample(mySampler[1], input.UV).r;
|
||||
float depth = textures[depthTexture].Sample(mySampler[0], input.UV).r;
|
||||
|
||||
float3 worldPos = WorldPosFromDepth(depth, input.UV, camView.InverseProjection, camView.InverseView);
|
||||
|
||||
@@ -262,7 +265,7 @@ PSOutput main(PSInput input)
|
||||
projCoords.xy = projCoords.xy * 0.5 + 0.5;
|
||||
|
||||
float currentDepth = projCoords.z;
|
||||
float closestDepth = textures[light.shadowMapTextureId[0]].Sample(mySampler[1], projCoords.xy).r;
|
||||
float closestDepth = textures[light.shadowMapTextureId[0]].Sample(mySampler[0], projCoords.xy).r;
|
||||
|
||||
float3 noiseOffset = float3(pushConstants.NoiseSpeed * pushConstants.Time, pushConstants.NoiseSpeed * pushConstants.Time, pushConstants.NoiseSpeed * pushConstants.Time);
|
||||
float3 noiseSamplePos = (currentPosition + noiseOffset) * pushConstants.NoiseScale;
|
||||
|
||||
@@ -472,12 +472,31 @@ void MaterialEditor::Draw(Ref<Nuake::Material> material)
|
||||
}
|
||||
|
||||
{
|
||||
ImGui::Text("Unlit");
|
||||
ImGui::Text("Receive Shadows");
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ImGui::Checkbox("##ReceiveShadows", &material->m_ReceiveShadows);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TableNextColumn();
|
||||
}
|
||||
|
||||
{
|
||||
ImGui::Text("Cast Shadows");
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
bool unlit = material->data.u_Unlit == 1;
|
||||
ImGui::Checkbox("##Unlit", &unlit);
|
||||
material->data.u_Unlit = (int)unlit;
|
||||
ImGui::Checkbox("##CastShadows", &material->m_CastShadows);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TableNextColumn();
|
||||
}
|
||||
|
||||
{
|
||||
ImGui::Text("Unlit");
|
||||
ImGui::TableNextColumn();
|
||||
bool val = static_cast<bool>(material->data.u_Unlit);
|
||||
ImGui::Checkbox("##Unlit", &val);
|
||||
material->data.u_Unlit = static_cast<int>(val);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TableNextColumn();
|
||||
}
|
||||
|
||||
@@ -81,6 +81,8 @@ namespace Nuake
|
||||
|
||||
SamplingType m_SamplingType = SamplingType::Nearest;
|
||||
CullingType m_CullingType = CullingType::Back;
|
||||
bool m_ReceiveShadows = true;
|
||||
bool m_CastShadows = true;
|
||||
|
||||
Ref<Texture> m_Albedo;
|
||||
Ref<Texture> m_AO;
|
||||
|
||||
@@ -66,6 +66,14 @@ ShadowRenderPipeline::ShadowRenderPipeline()
|
||||
Ref<VkMesh> vkMesh = m->GetVkMesh();
|
||||
cmd.BindDescriptorSet(ctx.renderPass->PipelineLayout, vkMesh->GetDescriptorSet(), 1);
|
||||
|
||||
if (auto material = m->GetMaterial(); material)
|
||||
{
|
||||
if (!material->m_CastShadows)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
gbufferConstant.Index = GPUResources::Get().GetBindlessTransformID(entityId);
|
||||
gbufferConstant.CameraID = ctx.cameraID;
|
||||
|
||||
@@ -603,6 +611,7 @@ void SceneRenderPipeline::RecreatePipeline()
|
||||
shadingConstant.MaterialTextureID = res.GetBindlessTextureID(GBufferMaterial->GetID());
|
||||
shadingConstant.AmbientTerm = ctx.scene->GetEnvironment()->AmbientTerm;
|
||||
shadingConstant.SSAOTextureID = res.GetBindlessTextureID(SSAOBlurOutput->GetID());
|
||||
shadingConstant.EntityTextureID = res.GetBindlessTextureID(GBufferEntityID->GetID());
|
||||
|
||||
// Camera
|
||||
shadingConstant.CameraID = ctx.cameraID;
|
||||
|
||||
@@ -81,6 +81,7 @@ namespace Nuake
|
||||
float AmbientTerm;
|
||||
float CascadeSplits[4];
|
||||
int SSAOTextureID;
|
||||
int EntityTextureID;
|
||||
};
|
||||
|
||||
struct TonemapConstant
|
||||
|
||||
@@ -127,7 +127,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
|
||||
{
|
||||
|
||||
@@ -43,7 +43,9 @@ namespace Nuake
|
||||
uint32_t RoughnessTextureId;
|
||||
uint32_t AoTextureId;
|
||||
int SamplerType;
|
||||
int pad[3];
|
||||
int ReceiveShadow;
|
||||
int CastShadow;
|
||||
int Unlit;
|
||||
};
|
||||
|
||||
// This is the *whole* buffer
|
||||
|
||||
@@ -298,7 +298,7 @@ void GPUResources::CreateBindlessLayout()
|
||||
samplerCreateInfo.minFilter = VK_FILTER_NEAREST;
|
||||
samplerCreateInfo.anisotropyEnable = VK_TRUE;
|
||||
samplerCreateInfo.maxAnisotropy = properties.limits.maxSamplerAnisotropy;
|
||||
vkCreateSampler(device, &samplerCreateInfo, nullptr, &SamplerNearest);
|
||||
vkCreateSampler(device, &samplerCreateInfo, nullptr, &SamplerNearest);
|
||||
|
||||
samplerCreateInfo.magFilter = VK_FILTER_LINEAR;
|
||||
samplerCreateInfo.minFilter = VK_FILTER_LINEAR;
|
||||
|
||||
@@ -552,7 +552,10 @@ void VkSceneRenderer::PrepareScenes(const std::vector<Ref<Scene>>& scenes, Rende
|
||||
.MetalnessTextureId = material->HasMetalness() ? gpu.GetBindlessTextureID(material->MetalnessImage) : 0,
|
||||
.RoughnessTextureId = material->HasRoughness() ? gpu.GetBindlessTextureID(material->RoughnessImage) : 0,
|
||||
.AoTextureId = material->HasAO() ? gpu.GetBindlessTextureID(material->AOImage) : 0,
|
||||
.SamplerType = static_cast<int>(material->m_SamplingType)
|
||||
.SamplerType = static_cast<int>(material->m_SamplingType),
|
||||
.ReceiveShadow = material->m_ReceiveShadows,
|
||||
.CastShadow = material->m_CastShadows,
|
||||
.Unlit = material->data.u_Unlit
|
||||
};
|
||||
|
||||
// Save bindless mapping index
|
||||
|
||||
Reference in New Issue
Block a user