Progress i guess

This commit is contained in:
Dynamitos
2023-11-08 23:27:21 +01:00
parent ecb5050dc7
commit 19c3e559b1
49 changed files with 268 additions and 361 deletions
+2 -3
View File
@@ -9,15 +9,14 @@ struct ViewParameter
float4 cameraPos_WS;
float2 screenDimensions;
}
layout(set = INDEX_VIEW_PARAMS)
ParameterBlock<ViewParameter> viewParams;
ParameterBlock<ViewParameter> pViewParams;
// Convert screen space coordinates to view space.
float4 screenToClip( float4 screen )
{
// Convert to normalized texture coordinates
float2 texCoord = screen.xy / viewParams.screenDimensions;
float2 texCoord = screen.xy / pViewParams.screenDimensions;
// Convert to clip space
return float4( float2( texCoord.x, 1.0f-texCoord.y ) * 2.0f - 1.0f, screen.z, screen.w );
+5 -5
View File
@@ -1,6 +1,6 @@
import MaterialParameter;
import BRDF;
import Common;
import BRDF;
import MaterialParameter;
interface ILightEnv
{
@@ -15,7 +15,7 @@ struct DirectionalLight : ILightEnv
float3 illuminate<B:IBRDF>(MaterialParameter input, B brdf)
{
float3 lightDir_TS = normalize(direction.xyz);
return brdf.evaluate(input.viewDir_TS, -lightDir_TS, color.xyz);
return brdf.evaluate(input.viewDir_TS, -lightDir_TS, color.xyz);
}
};
@@ -57,7 +57,7 @@ struct PointLight : ILightEnv
}
float3 getViewPos()
{
return mul(viewParams.viewMatrix, position_WS).xyz;
return mul(pViewParams.viewMatrix, position_WS).xyz;
}
};
@@ -69,4 +69,4 @@ struct LightEnv
uint numPointLights;
};
ParameterBlock<LightEnv> gLightEnv;
ParameterBlock<LightEnv> pLightEnv;
+1 -1
View File
@@ -8,4 +8,4 @@ interface IMaterial
BRDF prepare(MaterialParameter input);
};
ParameterBlock<IMaterial> gMaterial;
ParameterBlock<IMaterial> pMaterial;
+1 -14
View File
@@ -1,24 +1,11 @@
import VertexData;
struct MaterialParameter
{
float3 position_TS;
float3 position_TS;
float3 worldPosition;
float2 texCoords;
float3 normal;
float3 tangent;
float3 biTangent;
float3 viewDir_TS;
static MaterialParameter create(VertexAttributes attrib)
{
MaterialParameter result;
result.worldPosition = attrib.getWorldPosition().xyz;
result.texCoords = attrib.getTexCoords();
result.normal = attrib.getNormal();
result.tangent = attrib.getTangent();
result.biTangent = attrib.getBiTangent();
return result;
}
}
+1 -1
View File
@@ -37,5 +37,5 @@ struct Scene
StructuredBuffer<uint32_t> vertexIndices;
};
ParameterBlock<Scene> scene;
ParameterBlock<Scene> pScene;
+19 -26
View File
@@ -1,8 +1,8 @@
import VertexData;
import Common;
import Scene;
import VertexData;
import MaterialParameter;
struct StaticMeshVertexAttributes : VertexAttributes
struct StaticMeshVertexAttributes : IVertexAttributes
{
float4 clipPosition: SV_Position;
float3 worldPosition: POSITION0;
@@ -10,37 +10,30 @@ struct StaticMeshVertexAttributes : VertexAttributes
float3 normal: NORMAL0;
float3 tangent: TANGENT0;
float3 biTangent: BITANGENT0;
float3 getWorldPosition()
MaterialParameter create()
{
return worldPosition;
MaterialParameter result;
result.worldPosition = worldPosition;
result.texCoords = texCoords;
result.normal = normal;
result.tangent = tangent;
result.biTangent = biTangent;
return result;
}
float2 getTexCoords()
{
return texCoords;
}
float3 getNormal()
{
return normal;
}
float3 getTangent()
{
return tangent;
}
float3 getBiTangent()
{
return biTangent;
}
}
struct StaticMeshVertexData : VertexData
};
struct StaticMeshVertexData : IVertexData
{
typedef StaticMeshVertexAttributes VertexAttributes;
StaticMeshVertexAttributes getAttributes(uint index, float4x4 transform)
{
StaticMeshVertexAttributes attr;
float4 localPos = float4(positions[index], 1);
float4 worldPos = mul(transform, localPos);
float4 viewPos = mul(viewParams.viewMatrix, worldPos);
float4 clipPos = mul(viewParams.projectionMatrix, viewPos);
float4 viewPos = mul(pViewParams.viewMatrix, worldPos);
float4 clipPos = mul(pViewParams.projectionMatrix, viewPos);
attr.clipPosition = clipPos;
attr.worldPosition = worldPos.xyz;
attr.texCoords = texCoords[index];
@@ -54,4 +47,4 @@ struct StaticMeshVertexData : VertexData
StructuredBuffer<float3> normals;
StructuredBuffer<float3> tangents;
StructuredBuffer<float3> biTangents;
}
};
+7 -10
View File
@@ -1,16 +1,13 @@
import Scene;
import MaterialParameter;
interface VertexAttributes
interface IVertexAttributes
{
float3 getWorldPosition();
float2 getTexCoords();
float3 getNormal();
float3 getTangent();
float3 getBiTangent();
}
MaterialParameter create();
};
interface VertexData
interface IVertexData
{
associatedtype VertexAttributes : IVertexAttributes;
VertexAttributes getAttributes(uint index, float4x4 transform);
};
ParameterBlock<VertexData> vertexData;
ParameterBlock<IVertexData> pVertexData;