Trying to fix invalid descriptorlayout

This commit is contained in:
Dynamitos
2020-10-03 11:00:10 +02:00
parent 79388bf41a
commit ceee96b462
69 changed files with 1087 additions and 393 deletions
+2 -18
View File
@@ -1,30 +1,14 @@
import Common;
import Material;
import VERTEX_INPUT_IMPORT;
import MATERIAL_IMPORT;
struct ViewParams
{
float4x4 viewMatrix;
float4x4 projectionMatrix;
float4 cameraPos_WS;
};
layout(set = 0, binding = 0)
ParameterBlock<ViewParams> gViewParams;
layout(set = 1)
type_param TMaterial : IMaterial;
ParameterBlock<TMaterial> gMaterial;
import PrimitiveSceneData;
struct ModelParameter
{
float4x4 modelMatrix;
}
[[vk::push_constant]]
ConstantBuffer<ModelParameter> gModelParams;
struct VertexStageOutput
{
float4 position : SV_Position;
+4 -6
View File
@@ -1,7 +1,7 @@
import Common;
import LightEnv;
import BRDF;
import Material;
import Common;
import VERTEX_INPUT_IMPORT;
import MATERIAL_IMPORT;
@@ -13,9 +13,6 @@ import MaterialParameter;
//layout(set = 0, binding = 3)
//RWTexture2D<uint2> lightGrid;
type_param TMaterial : IMaterial;
layout(set = 1)
ParameterBlock<TMaterial> gMaterial;
struct VertexStageOutput
{
@@ -31,9 +28,10 @@ VertexStageOutput vertexMain(
VertexStageOutput output;
VertexValueCache cache = input.getVertexCache();
float3 worldPosition = input.getWorldPosition();
worldPosition += gMaterial.getWorldOffset();
float4 clipSpacePosition;
float3x3 tangentToLocal = cache.tangentToLocal;
float3x3 tangentToLocal = cache.getTangentToLocal();
MaterialVertexParameter vertexParams = input.getMaterialVertexParameters(cache, worldPosition, tangentToLocal);
float4 viewSpacePosition = mul(gViewParams.viewMatrix, float4(worldPosition, 1));
@@ -75,5 +73,5 @@ float4 fragmentMain(
}
return float4(0, 1, 0, 1);
return float4(result, 1);
}
+14 -3
View File
@@ -2,17 +2,28 @@ const static float PI = 3.1415926535897932f;
const static uint MAX_PARTICLES = 65536;
const static uint BLOCK_SIZE = 8;
cbuffer ScreenToViewParams
struct ViewParameter
{
float4x4 viewMatrix;
float4x4 projectionMatrix;
float4 cameraPos_WS;
}
layout(set = 1, binding = 0, std430)
ConstantBuffer<ViewParameter> gViewParams;
struct ScreenToViewParams
{
float4x4 inverseProjection;
float2 screenDimensions;
}
layout(set = 1, binding = 1, std430)
ConstantBuffer<ScreenToViewParams> gScreenToViewParams;
// Convert clip space coordinates to view space
float4 clipToView( float4 clip )
{
// View space position.
float4 view = mul( inverseProjection, clip );
float4 view = mul( gScreenToViewParams.inverseProjection, clip );
// Perspective projection.
view = view / view.w;
@@ -23,7 +34,7 @@ float4 clipToView( float4 clip )
float4 screenToView( float4 screen )
{
// Convert to normalized texture coordinates
float2 texCoord = screen.xy / screenDimensions;
float2 texCoord = screen.xy / gScreenToViewParams.screenDimensions;
// Convert to clip space
float4 clip = float4( float2( texCoord.x, -texCoord.y ) * 2.0f - 1.0f, screen.z, screen.w );
+7 -8
View File
@@ -23,28 +23,27 @@ struct PointLight : ILightEnv
{
float4 positionWS;
float4 positionVS;
float3 color;
float range;
float4 colorRange;
float3 illuminate<B:IBRDF>(MaterialFragmentParameter input, B brdf, float3 viewDir)
{
float3 lightVec = positionWS.xyz - input.worldPosition;
float d = length(lightVec);
float3 direction = normalize(lightVec);
float illuminance = max(1 - d / range, 0);
return illuminance * brdf.evaluate(viewDir, direction, input.worldNormal, input.worldTangent, input.worldBiTangent, color);
float illuminance = max(1 - d / colorRange.w, 0);
return illuminance * brdf.evaluate(viewDir, direction, input.worldNormal, input.worldTangent, input.worldBiTangent, colorRange.xyz);
}
bool insidePlane(Plane plane)
{
return dot(plane.n, positionVS.xyz) - plane.d < -range;
return dot(plane.n, positionVS.xyz) - plane.d < -colorRange.w;
}
bool insideFrustum(Frustum frustum, float zNear, float zFar)
{
bool result = true;
//if(positionVS.z - range > zNear || positionVS.z + range < zFar)
//if(positionVS.z - range > zNear || positionVS.z + colorRange.w < zFar)
{
// result = false;
}
@@ -69,5 +68,5 @@ struct Lights
uint numPointLights;
};
layout(set = 0, binding = 1)
layout(set = 0, binding = 0, std430)
ConstantBuffer<Lights> gLightEnv;
+4
View File
@@ -16,3 +16,7 @@ interface IMaterial
float getRoughness(MaterialFragmentParameter input);
float getSheen(MaterialFragmentParameter input);
};
type_param TMaterial : IMaterial;
layout(set = 2, binding = 0, std430)
ParameterBlock<TMaterial> gMaterial;
-1
View File
@@ -44,4 +44,3 @@ struct MaterialFragmentParameter
}
};
+1 -12
View File
@@ -4,16 +4,5 @@ struct PrimitiveSceneData
float4x4 worldToLocal;
};
struct ViewParameter
{
float4x4 viewMatrix;
float4x4 projectionMatrix;
float4 cameraPos_WS;
};
layout(set = 0)
ConstantBuffer<ViewParameter> gViewParams;
layout(set = 2)
layout(set = 3, binding = 0, std430)
ConstantBuffer<PrimitiveSceneData> gSceneData;
+28 -5
View File
@@ -1,13 +1,30 @@
import Common;
import MaterialParameter;
import PrimitiveSceneData;
struct VertexValueCache
{
float3x3 tangentToLocal;
float3x3 tangentToWorld;
//This struct is passed between vertex and fragment stage
//which means, that it is passed as out mat3x3 in glsl
//but Slang for some reason puts a layout(row_major) above
//every attribute, including this matrix, but matrix layout
//qualifiers are illegal for non-uniform and buffer fields,
//leading to a compiler error
float3 tangentToLocal[3];
float3 tangentToWorld[3];
float tangentToWorldSign;
float4 color;
float3x3 getTangentToLocal()
{
return float3x3(tangentToLocal[0], tangentToLocal[1], tangentToLocal[2]);
}
float3x3 getTangentToWorld()
{
return float3x3(tangentToWorld[0], tangentToWorld[1], tangentToWorld[2]);
}
#if USE_INSTANCING
float4 instanceOrigin;
float3 instanceTransform1;
@@ -133,9 +150,15 @@ struct VertexShaderInput
#endif
float tangentSign;
cache.tangentToLocal = calcTangentToLocal(tangentSign);
float3x3 tangentToLocal = calcTangentToLocal(tangentSign);
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);
cache.tangentToWorld = mul(cache.tangentToLocal, localToWorld);
float3x3 tangentToWorld = mul(tangentToLocal, localToWorld);
cache.tangentToWorld[0] = tangentToWorld[0];
cache.tangentToWorld[1] = tangentToWorld[1];
cache.tangentToWorld[2] = tangentToWorld[2];
cache.tangentToWorldSign = tangentSign;
return cache;
@@ -146,7 +169,7 @@ struct VertexShaderInput
MaterialVertexParameter result;
result.worldPosition = worldPosition;
result.vertexColor = cache.color;
result.tangentToWorld = cache.tangentToWorld;
result.tangentToWorld = cache.getTangentToWorld();
// TODO instancing
/*for(int i = 0; i < NUM_MATERIAL_TEXCOORDS-1; i+=2)
{