Adding basic depth prepass
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
|
||||
import LightEnv;
|
||||
import Common;
|
||||
|
||||
struct ComputeShaderInput
|
||||
|
||||
@@ -4,10 +4,6 @@ import VERTEX_INPUT_IMPORT;
|
||||
import MATERIAL_IMPORT;
|
||||
import PrimitiveSceneData;
|
||||
|
||||
struct ModelParameter
|
||||
{
|
||||
float4x4 modelMatrix;
|
||||
}
|
||||
|
||||
struct VertexStageOutput
|
||||
{
|
||||
|
||||
@@ -38,6 +38,7 @@ VertexStageOutput vertexMain(
|
||||
clipSpacePosition = mul(gViewParams.projectionMatrix, viewSpacePosition);
|
||||
output.position = clipSpacePosition;
|
||||
output.shaderAttributeInterpolation = input.getInterpolants(cache, vertexParams);
|
||||
output.cache = cache;
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -72,5 +73,5 @@ float4 fragmentMain(
|
||||
result += pointLight.illuminate(materialParams, brdf, viewDir);
|
||||
}
|
||||
|
||||
return float4(result, 1);
|
||||
return float4(result, 0);
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@ cbuffer DispatchParams
|
||||
|
||||
layout(binding = 2)
|
||||
RWTexture2D depthTextureVS;
|
||||
layout(binding = 3)
|
||||
ConstantBuffer<Lights> lights;
|
||||
layout(binding = 4)
|
||||
StructuredBuffer<Frustum> frustums;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ struct ViewParameter
|
||||
float4x4 projectionMatrix;
|
||||
float4 cameraPos_WS;
|
||||
}
|
||||
layout(set = 1, binding = 0, std430)
|
||||
layout(set = INDEX_VIEW_PARAMS, binding = 0, std430)
|
||||
ConstantBuffer<ViewParameter> gViewParams;
|
||||
|
||||
struct ScreenToViewParams
|
||||
@@ -16,7 +16,7 @@ struct ScreenToViewParams
|
||||
float4x4 inverseProjection;
|
||||
float2 screenDimensions;
|
||||
}
|
||||
layout(set = 1, binding = 1, std430)
|
||||
layout(set = INDEX_VIEW_PARAMS, binding = 1, std430)
|
||||
ConstantBuffer<ScreenToViewParams> gScreenToViewParams;
|
||||
|
||||
// Convert clip space coordinates to view space
|
||||
|
||||
@@ -15,7 +15,7 @@ struct DirectionalLight : ILightEnv
|
||||
|
||||
float3 illuminate<B:IBRDF>(MaterialFragmentParameter input, B brdf, float3 wo)
|
||||
{
|
||||
return intensity.xyz * brdf.evaluate(wo, direction.xyz, input.worldNormal, input.worldTangent, input.worldBiTangent, color.xyz);
|
||||
return intensity.xyz * brdf.evaluate(wo, normalize(direction.xyz), input.worldNormal, input.worldTangent, input.worldBiTangent, color.xyz);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -68,5 +68,5 @@ struct Lights
|
||||
uint numPointLights;
|
||||
};
|
||||
|
||||
layout(set = 0, binding = 0, std430)
|
||||
layout(set = INDEX_LIGHT_ENV, binding = 0, std430)
|
||||
ConstantBuffer<Lights> gLightEnv;
|
||||
|
||||
@@ -18,5 +18,5 @@ interface IMaterial
|
||||
};
|
||||
|
||||
type_param TMaterial : IMaterial;
|
||||
layout(set = 2, binding = 0, std430)
|
||||
layout(set = INDEX_MATERIAL, binding = 0, std430)
|
||||
ParameterBlock<TMaterial> gMaterial;
|
||||
|
||||
@@ -5,5 +5,5 @@ struct PrimitiveSceneData
|
||||
float4 actorLocation;
|
||||
};
|
||||
|
||||
layout(set = 3, binding = 0, std430)
|
||||
layout(set = INDEX_SCENE_DATA, binding = 0, std430)
|
||||
ConstantBuffer<PrimitiveSceneData> gSceneData;
|
||||
|
||||
@@ -12,7 +12,6 @@ struct VertexValueCache
|
||||
//leading to a compiler error
|
||||
float3 tangentToLocal[3];
|
||||
float3 tangentToWorld[3];
|
||||
float tangentToWorldSign;
|
||||
float4 color;
|
||||
|
||||
float3x3 getTangentToLocal()
|
||||
@@ -46,8 +45,9 @@ struct VertexValueCache
|
||||
struct ShaderAttributeInterpolation
|
||||
{
|
||||
float3 worldPosition;
|
||||
float3 tangentX;
|
||||
float4 tangentZ;
|
||||
float3 normal;
|
||||
float3 tangent;
|
||||
float3 biTangent;
|
||||
float4 color;
|
||||
#if NUM_MATERIAL_TEXCOORDS
|
||||
float4 packedTexCoords[(NUM_MATERIAL_TEXCOORDS+1) / 2];
|
||||
@@ -72,16 +72,15 @@ struct ShaderAttributeInterpolation
|
||||
}
|
||||
}
|
||||
#endif
|
||||
float3 tangentY = cross(tangentZ.xyz, tangentX) * tangentZ.w;
|
||||
result.tangentToWorld[0] = cross(tangentY, tangentZ.xyz) * tangentZ.w;
|
||||
result.tangentToWorld[1] = tangentY;
|
||||
result.tangentToWorld[2] = tangentZ.xyz;
|
||||
result.tangentToWorld[0] = tangent;
|
||||
result.tangentToWorld[1] = biTangent;
|
||||
result.tangentToWorld[2] = normal;
|
||||
result.clipPosition = clipSpacePosition;
|
||||
result.worldPosition = worldPosition;
|
||||
result.viewDir = gViewParams.cameraPos_WS.xyz - worldPosition;
|
||||
result.worldNormal = tangentZ.xyz;
|
||||
result.worldTangent = tangentX;
|
||||
result.worldBiTangent = tangentY;
|
||||
result.worldNormal = normal;
|
||||
result.worldTangent = tangent;
|
||||
result.worldBiTangent = biTangent;
|
||||
result.vertexColor = color;
|
||||
return result;
|
||||
}
|
||||
@@ -90,8 +89,9 @@ struct ShaderAttributeInterpolation
|
||||
struct VertexShaderInput
|
||||
{
|
||||
float4 position;
|
||||
float3 tangentX;
|
||||
float4 tangentZ;
|
||||
float3 normal;
|
||||
float3 tangent;
|
||||
float3 biTangent;
|
||||
float4 color;
|
||||
#if NUM_MATERIAL_TEXCOORDS
|
||||
#if NUM_MATERIAL_TEXCOORDS > 1
|
||||
@@ -118,15 +118,12 @@ struct VertexShaderInput
|
||||
float3 instanceTransform3;
|
||||
#endif // USE_INSTANCING
|
||||
|
||||
float3x3 calcTangentToLocal(out float tangentSign)
|
||||
float3x3 calcTangentToLocal()
|
||||
{
|
||||
float3x3 result;
|
||||
tangentSign = tangentZ.w;
|
||||
|
||||
float3 tangentY = cross(tangentZ.xyz, tangentX) * tangentZ.w;
|
||||
result[0] = cross(tangentY, tangentZ.xyz) * tangentZ.w;
|
||||
result[1] = tangentY;
|
||||
result[2] = tangentZ.xyz;
|
||||
result[0] = tangent;
|
||||
result[1] = biTangent;
|
||||
result[2] = normal;
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -149,17 +146,14 @@ struct VertexShaderInput
|
||||
cache.instanceOrigin = instanceOrigin;
|
||||
#endif
|
||||
|
||||
float tangentSign;
|
||||
float3x3 tangentToLocal = calcTangentToLocal(tangentSign);
|
||||
float3x3 tangentToLocal = calcTangentToLocal();
|
||||
cache.tangentToLocal[0] = tangentToLocal[0];
|
||||
cache.tangentToLocal[1] = tangentToLocal[1];
|
||||
cache.tangentToLocal[2] = tangentToLocal[2];
|
||||
float3x3 localToWorld = float3x3(gSceneData.localToWorld[0].xyz, gSceneData.localToWorld[1].xyz, gSceneData.localToWorld[2].xyz);
|
||||
float3x3 tangentToWorld = mul(tangentToLocal, localToWorld);
|
||||
cache.tangentToWorld[0] = tangentToWorld[0];
|
||||
cache.tangentToWorld[1] = tangentToWorld[1];
|
||||
cache.tangentToWorld[2] = tangentToWorld[2];
|
||||
cache.tangentToWorldSign = tangentSign;
|
||||
|
||||
cache.tangentToWorld[0] = mul(gSceneData.localToWorld, float4(tangentToLocal[0], 0.0f)).xyz;
|
||||
cache.tangentToWorld[1] = mul(gSceneData.localToWorld, float4(tangentToLocal[1], 0.0f)).xyz;
|
||||
cache.tangentToWorld[2] = mul(gSceneData.localToWorld, float4(tangentToLocal[2], 0.0f)).xyz;
|
||||
|
||||
return cache;
|
||||
}
|
||||
@@ -186,8 +180,10 @@ struct VertexShaderInput
|
||||
ShaderAttributeInterpolation getInterpolants(VertexValueCache cache, MaterialVertexParameter vertexParams)
|
||||
{
|
||||
ShaderAttributeInterpolation result = (ShaderAttributeInterpolation)0;
|
||||
result.tangentX = tangentX;
|
||||
result.tangentZ = tangentZ;
|
||||
float3x3 tangentToWorld = cache.getTangentToWorld();
|
||||
result.normal = mul(gSceneData.localToWorld, float4(normal, 0.0f)).xyz;
|
||||
result.tangent = mul(gSceneData.localToWorld, float4(tangent, 0.0f)).xyz;
|
||||
result.biTangent = mul(gSceneData.localToWorld, float4(biTangent, 0.0f)).xyz;
|
||||
result.color = color;
|
||||
result.worldPosition = vertexParams.worldPosition;
|
||||
for(int i = 0; i < NUM_MATERIAL_TEXCOORDS; ++i)
|
||||
|
||||
Reference in New Issue
Block a user