Trying to fix wrong tex coord imports
This commit is contained in:
@@ -16,7 +16,7 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target
|
||||
{
|
||||
LightingParameter lightingParams = params.getLightingParameter();
|
||||
MaterialParameter materialParams = params.getMaterialParameter();
|
||||
let brdf = Material.prepare(materialParams);
|
||||
var brdf = Material.prepare(materialParams);
|
||||
uint2 tileIndex = uint2(floor(params.position_CS.xy / BLOCK_SIZE));
|
||||
uint startOffset = pLightCullingData.lightGrid[tileIndex].x;
|
||||
uint lightCount = pLightCullingData.lightGrid[tileIndex].y;
|
||||
@@ -25,10 +25,10 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target
|
||||
{
|
||||
result += pLightEnv.directionalLights[i].illuminate(lightingParams, brdf);
|
||||
}
|
||||
for(uint i = 0; i < pLightEnv.numPointLights; ++i)
|
||||
for (uint i = 0; i < lightCount; ++i)
|
||||
{
|
||||
//uint lightIndex = pLightCullingData.lightIndexList[startOffset + i];
|
||||
result += pLightEnv.pointLights[i].illuminate(lightingParams, brdf);
|
||||
uint lightIndex = pLightCullingData.lightIndexList[startOffset + i];
|
||||
result += pLightEnv.pointLights[lightIndex].illuminate(lightingParams, brdf);
|
||||
}
|
||||
result += brdf.evaluateAmbient(lightingParams.viewDir_WS);
|
||||
return float4(result, brdf.getAlpha());
|
||||
|
||||
@@ -70,20 +70,15 @@ struct LightEnv
|
||||
layout(set=3)
|
||||
ParameterBlock<LightEnv> pLightEnv;
|
||||
|
||||
[Differentiable]
|
||||
float polynomial(float a, float b, float c, float x) {
|
||||
return a * x * x + b * x + c;
|
||||
}
|
||||
|
||||
interface IBRDF
|
||||
{
|
||||
float3 evaluate(float3 viewDir_WS, float3 lightDir_WS, float3 lightColor);
|
||||
[mutating] void transformNormal(float3x3 tangentToWorld);
|
||||
float3 getNormal();
|
||||
float3 getBaseColor();
|
||||
float3 evaluateAmbient(float3 viewDir_WS);
|
||||
float getAlpha();
|
||||
float3 getEmissive();
|
||||
[mutating] void setNormal(float3 n);
|
||||
};
|
||||
|
||||
struct Phong : IBRDF
|
||||
@@ -116,11 +111,6 @@ struct Phong : IBRDF
|
||||
|
||||
return lightColor * (baseColor * max(nDotL, 0.0)) + specular * pow(max(rDotV, 0.0), max(shininess, 1));
|
||||
}
|
||||
[mutating]
|
||||
void transformNormal(float3x3 tangentToWorld)
|
||||
{
|
||||
normal = normalize(mul(tangentToWorld, normal));
|
||||
}
|
||||
float3 getNormal()
|
||||
{
|
||||
return normal;
|
||||
@@ -141,6 +131,7 @@ struct Phong : IBRDF
|
||||
{
|
||||
return emissive;
|
||||
}
|
||||
[mutating] void setNormal(float3 n) { normal = n; }
|
||||
};
|
||||
|
||||
struct BlinnPhong : IBRDF
|
||||
@@ -170,14 +161,9 @@ struct BlinnPhong : IBRDF
|
||||
float diffuse = max(dot(normal_WS, lightDir_WS), 0);
|
||||
float3 h = normalize(lightDir_WS + viewDir_WS);
|
||||
float specular = pow(saturate(dot(normal_WS, h)), shininess);
|
||||
|
||||
|
||||
return (baseColor * diffuse * lightColor) + (specularColor * specular);
|
||||
}
|
||||
[mutating]
|
||||
void transformNormal(float3x3 tangentToWorld)
|
||||
{
|
||||
normal = normalize(mul(tangentToWorld, normal));
|
||||
}
|
||||
float3 getNormal()
|
||||
{
|
||||
return normal;
|
||||
@@ -198,6 +184,7 @@ struct BlinnPhong : IBRDF
|
||||
{
|
||||
return emissive;
|
||||
}
|
||||
[mutating] void setNormal(float3 n) { normal = n; }
|
||||
};
|
||||
|
||||
struct CelShading : IBRDF
|
||||
@@ -230,11 +217,6 @@ struct CelShading : IBRDF
|
||||
return darkenedBase * lightColor;
|
||||
}
|
||||
}
|
||||
[mutating]
|
||||
void transformNormal(float3x3 tangentToWorld)
|
||||
{
|
||||
normal = normalize(mul(tangentToWorld, normal));
|
||||
}
|
||||
float3 getNormal()
|
||||
{
|
||||
return normal;
|
||||
@@ -255,6 +237,7 @@ struct CelShading : IBRDF
|
||||
{
|
||||
return emissive;
|
||||
}
|
||||
[mutating] void setNormal(float3 n) { normal = n; }
|
||||
};
|
||||
|
||||
// https://learnopengl.com/PBR/Theory
|
||||
@@ -315,7 +298,7 @@ struct CookTorrance : IBRDF
|
||||
|
||||
float3 evaluate(float3 viewDir_WS, float3 lightDir_WS, float3 lightColor)
|
||||
{
|
||||
float3 n = normal;
|
||||
float3 n = normalize(normal);
|
||||
float3 h = normalize(lightDir_WS + viewDir_WS);
|
||||
|
||||
float3 F0 = float3(0.04);
|
||||
@@ -337,12 +320,7 @@ struct CookTorrance : IBRDF
|
||||
float nDotL = max(dot(n, lightDir_WS), 0.0);
|
||||
|
||||
float3 result = (k_d * baseColor / PI + specular) * nDotL * lightColor;
|
||||
return baseColor;
|
||||
}
|
||||
[mutating]
|
||||
void transformNormal(float3x3 tangentToWorld)
|
||||
{
|
||||
normal = normalize(mul(tangentToWorld, normal));
|
||||
return result;
|
||||
}
|
||||
float3 getNormal()
|
||||
{
|
||||
@@ -371,5 +349,6 @@ struct CookTorrance : IBRDF
|
||||
{
|
||||
return emissive;
|
||||
}
|
||||
[mutating] void setNormal(float3 n) { normal = n; }
|
||||
};
|
||||
|
||||
|
||||
@@ -98,13 +98,13 @@ struct FragmentParameter
|
||||
{
|
||||
// in theory, transposing would make this a world-to-tangent matrix, but because we are building the matrix ourselves
|
||||
// and something with matrix layouts is working the opposite direction, we need to transpose here
|
||||
return transpose(float3x3(tangent_WS, biTangent_WS, normal_WS));
|
||||
return transpose(float3x3(normalize(tangent_WS), normalize(biTangent_WS), normalize(normal_WS)));
|
||||
}
|
||||
#endif
|
||||
static FragmentParameter interpolate(FragmentParameter f0, FragmentParameter f1, FragmentParameter f2, float3 barycentricCoords)
|
||||
{
|
||||
FragmentParameter result;
|
||||
result.position_CS = f0.position_CS * barycentricCoords.x + f1.position_CS * barycentricCoords.y + f2.position_CS * barycentricCoords.z;
|
||||
result.position_CS = f0.position_CS * barycentricCoords.x + f1.position_CS * barycentricCoords.y + f2.position_CS * barycentricCoords.z;
|
||||
#ifndef POS_ONLY
|
||||
result.normal_WS = f0.normal_WS * barycentricCoords.x + f1.normal_WS * barycentricCoords.y + f2.normal_WS * barycentricCoords.z;
|
||||
result.tangent_WS = f0.tangent_WS * barycentricCoords.x + f1.tangent_WS * barycentricCoords.y + f2.tangent_WS * barycentricCoords.z;
|
||||
@@ -142,9 +142,9 @@ struct VertexAttributes
|
||||
result.position_CS = clipPos;
|
||||
#ifndef POS_ONLY
|
||||
//float3x3 tbn = qTangentToMatrix(qTangent);
|
||||
result.tangent_WS = normalize(mul(transformMatrix, float4(tangent_MS, 0)).xyz);
|
||||
result.biTangent_WS = normalize(mul(transformMatrix, float4(biTangent_MS, 0)).xyz);
|
||||
result.normal_WS = normalize(mul(transformMatrix, float4(normal_MS, 0)).xyz);
|
||||
result.tangent_WS = mul(transformMatrix, float4(tangent_MS, 0)).xyz;
|
||||
result.biTangent_WS = mul(transformMatrix, float4(biTangent_MS, 0)).xyz;
|
||||
result.normal_WS = mul(transformMatrix, float4(normal_MS, 0)).xyz;
|
||||
result.vertexColor = vertexColor;
|
||||
result.position_WS = worldPos.xyz;
|
||||
result.texCoords0 = float4(texCoords[0], texCoords[1]);
|
||||
|
||||
@@ -16,9 +16,8 @@ struct StaticMeshVertexData : IVertexData
|
||||
#ifndef POS_ONLY
|
||||
//attributes.qTangent = qTangent[index];
|
||||
attributes.normal_MS = float3(normals[index * 3 + 0], normals[index * 3 + 1], normals[index * 3 + 2]);
|
||||
float4 tangentSign = float4(tangents[index * 4 + 0], tangents[index * 4 + 1], tangents[index * 4 + 2], tangents[index * 4 + 3]);
|
||||
attributes.tangent_MS = tangentSign.xyz;
|
||||
attributes.biTangent_MS = cross(attributes.normal_MS, attributes.tangent_MS) * -tangentSign.w;
|
||||
attributes.tangent_MS = float3(tangents[index * 3 + 0], tangents[index * 3 + 1], tangents[index * 3 + 2]);
|
||||
attributes.biTangent_MS = float3(biTangents[index * 3 + 0], biTangents[index * 3 + 1], biTangents[index * 3 + 2]);;
|
||||
for(uint i = 0; i < MAX_TEXCOORDS; ++i)
|
||||
{
|
||||
attributes.texCoords[i] = float2(uint16ToFloat(texCoords[i][index * 2 + 0]), uint16ToFloat(texCoords[i][index * 2 + 1]));
|
||||
@@ -30,7 +29,8 @@ struct StaticMeshVertexData : IVertexData
|
||||
StructuredBuffer<float> positions;
|
||||
//StructuredBuffer<float> qTangents;
|
||||
StructuredBuffer<float> normals;
|
||||
StructuredBuffer<float> tangents;
|
||||
StructuredBuffer<float> tangents;
|
||||
StructuredBuffer<float> biTangents;
|
||||
StructuredBuffer<uint16_t> color;
|
||||
StructuredBuffer<uint16_t> texCoords[MAX_TEXCOORDS];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user