Now able to import stuff properly

This commit is contained in:
Dynamitos
2024-05-06 18:36:16 +02:00
parent 05bb1d0cee
commit af7d624d06
21 changed files with 189 additions and 79 deletions
+3 -2
View File
@@ -32,7 +32,8 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target
result += pLightEnv.pointLights[lightIndex].illuminate(lightingParams, brdf);
}
result += brdf.evaluateAmbient();
// gamma correction
result = result / (result + float3(1.0));
float3 gammaCorrected = pow(result, float3(1.0/2.2));
return float4(gammaCorrected, 1.0f);
result = pow(result, float3(1.0/2.2));
return float4(result, 1.0f);
}
+15
View File
@@ -0,0 +1,15 @@
{
"name": "Placeholder",
"params": {
},
"code": [
{
"exp": "BRDF",
"profile": "BlinnPhong",
"values": {
"baseColor": "float3(0, 1, 0)",
"normal": "float3(0, 0, 1)"
}
}
]
}
+7 -6
View File
@@ -21,12 +21,12 @@ struct Phong : IBRDF
float3 evaluate(float3x3 tbn, float3 viewDir_TS, float3 lightDir_TS, float3 lightColor)
{
float3 n = normalize(normal);
float3 nDotL = dot(n, lightDir_TS);
float3 r = 2 * (nDotL) * n - lightDir_TS;
float3 normal_TS = normalize(normal);
float3 nDotL = dot(normal_TS, lightDir_TS);
float3 r = 2 * (nDotL) * normal_TS - lightDir_TS;
float rDotV = dot(r, viewDir_TS);
return baseColor * max(nDotL, 0.0) * lightColor + specular * pow(max(rDotV, 0.0), shininess) * lightColor;
return baseColor * max(nDotL, 0.0) * lightColor + specular * pow(max(rDotV, 0.0), shininess);
}
float3 evaluateAmbient()
@@ -40,6 +40,7 @@ struct BlinnPhong : IBRDF
float3 baseColor;
float3 specularColor;
float3 normal;
float shininess;
float3 ambient;
__init()
@@ -52,9 +53,9 @@ struct BlinnPhong : IBRDF
float3 normal_TS = normalize(normal);
float diffuse = max(dot(normal_TS, lightDir_TS), 0);
float3 h = normalize(lightDir_TS + viewDir_TS);
float specular = saturate(dot(normal_TS, h));
float specular = pow(saturate(dot(normal_TS, h)), shininess);
return (baseColor * diffuse * lightColor) + (specularColor * specular) * lightColor;
return (baseColor * diffuse * lightColor) + (specularColor * specular);
}
float3 evaluateAmbient()
+1
View File
@@ -1,5 +1,6 @@
const static float PI = 3.1415926535897932f;
const static uint BLOCK_SIZE = 32;
static const uint64_t MAX_TEXCOORDS = 8;
struct ViewParameter
{
+5 -5
View File
@@ -33,21 +33,21 @@ struct PointLight : ILightEnv
return illuminance * brdf.evaluate(params.tbn, params.viewDir_TS, -normalize(lightDir_TS), colorRange.xyz);
}
bool insidePlane(Plane plane, float3 position_VS)
bool insidePlane(Plane plane, float3 position)
{
return dot(plane.n, position_VS) - plane.d < -colorRange.w;
return dot(plane.n, position) - plane.d < -colorRange.w;
}
bool insideFrustum(Frustum frustum, float3 position_VS, float minDepth, float maxDepth)
bool insideFrustum(Frustum frustum, float3 position, float minDepth, float maxDepth)
{
bool result = true;
if(position_VS.z - colorRange.w > minDepth || position_VS.z + colorRange.w < maxDepth)
if(position.z - colorRange.w > minDepth || position.z + colorRange.w < maxDepth)
{
result = false;
}
for(int i = 0; i < 4 && result; ++i)
{
if(insidePlane(frustum.sides[i], position_VS))
if(insidePlane(frustum.sides[i], position))
{
result = false;
}
+14 -8
View File
@@ -3,7 +3,7 @@ import Common;
struct MaterialParameter
{
float3 position_WS;
float2 texCoords[1];
float2 texCoords[MAX_TEXCOORDS];
float3 vertexColor;
};
@@ -25,13 +25,16 @@ struct FragmentParameter
float3 biTangent_WS : TANGENT1;
float3 position_WS : POSITION2;
float3 vertexColor : COLOR0;
float2 texCoords : TEXCOORD0;
float2 texCoords[MAX_TEXCOORDS] : TEXCOORD0;
MaterialParameter getMaterialParameter()
{
MaterialParameter result;
result.position_WS = position_WS;
result.vertexColor = vertexColor;
result.texCoords[0] = texCoords;
for(uint i = 0; i < MAX_TEXCOORDS; ++i)
{
result.texCoords[i] = texCoords[i];
}
return result;
}
LightingParameter getLightingParameter()
@@ -52,16 +55,16 @@ struct VertexAttributes
float3 tangent_MS;
float3 biTangent_MS;
float3 vertexColor;
float2 texCoords;
float2 texCoords[MAX_TEXCOORDS];
FragmentParameter getParameter(float4x4 transformMatrix)
{
float4 modelPos = float4(position_MS, 1);
float4 worldPos = mul(transformMatrix, modelPos);
float4 viewPos = mul(pViewParams.viewMatrix, worldPos);
float4 clipPos = mul(pViewParams.projectionMatrix, viewPos);
float3 tangent_WS = mul(float3x3(transformMatrix), tangent_MS);
float3 biTangent_WS = mul(float3x3(transformMatrix), biTangent_MS);
float3 normal_WS = mul(float3x3(transformMatrix), normal_MS);
float3 tangent_WS = normalize(mul(transformMatrix, float4(tangent_MS, 0.0)).xyz);
float3 biTangent_WS = normalize(mul(transformMatrix, float4(biTangent_MS, 0.0)).xyz);
float3 normal_WS = normalize(mul(transformMatrix, float4(normal_MS, 0.0)).xyz);
FragmentParameter result;
result.viewDir_WS = pViewParams.cameraPos_WS.xyz - worldPos.xyz;
result.normal_WS = normal_WS;
@@ -70,7 +73,10 @@ struct VertexAttributes
result.position_WS = worldPos.xyz;
result.position_CS = clipPos;
result.vertexColor = vertexColor;
result.texCoords = texCoords;
for(uint i = 0; i < MAX_TEXCOORDS; ++i)
{
result.texCoords[i] = texCoords[i];
}
return result;
}
};
+5 -2
View File
@@ -11,14 +11,17 @@ struct StaticMeshVertexData : IVertexData
attributes.normal_MS = float3(normals[3 * index + 0], normals[3 * index + 1], normals[3 * index + 2]);
attributes.tangent_MS = float3(tangents[3 * index + 0], tangents[3 * index + 1], tangents[3 * index + 2]);
attributes.biTangent_MS = float3(biTangents[3 * index + 0], biTangents[3 * index + 1], biTangents[3 * index + 2]);
attributes.texCoords = float2(texCoords[2 * index + 0], texCoords[2 * index + 1]);
for(uint i = 0; i < MAX_TEXCOORDS; ++i)
{
attributes.texCoords[i] = float2(texCoords[i][2 * index + 0], texCoords[i][2 * index + 1]);
}
attributes.vertexColor = float3(color[3 * index + 0], color[3 * index + 1], color[3 * index + 2]);
return attributes;
}
StructuredBuffer<float> positions;
StructuredBuffer<float> texCoords;
StructuredBuffer<float> normals;
StructuredBuffer<float> tangents;
StructuredBuffer<float> biTangents;
StructuredBuffer<float> color;
StructuredBuffer<float> texCoords[MAX_TEXCOORDS];
};