There is a memory leak

This commit is contained in:
Dynamitos
2023-11-30 11:51:53 +01:00
parent d1475d506e
commit 1493627ceb
20 changed files with 91 additions and 102 deletions
+1
View File
@@ -19,6 +19,7 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target
{
MaterialParameter materialParams = params.getMaterialParameter();
LightingParameter lightingParams = params.getLightingParameter();
let brdf = pMaterial.prepare(materialParams);
float3 result = float3(0, 0, 0);
for(int i = 0; i < pLightEnv.numDirectionalLights; ++i)
+8 -7
View File
@@ -2,7 +2,7 @@ import Common;
interface IBRDF
{
float3 evaluate(float3 viewDir_TS, float3 lightDir_TS, float3 lightColor);
float3 evaluate(float3x3 tbn, float3 viewDir_WS, float3 lightDir_WS, float3 lightColor);
};
struct BlinnPhong : IBRDF
@@ -23,13 +23,14 @@ struct BlinnPhong : IBRDF
sheen = 1;
}
float3 evaluate(float3 viewDir_TS, float3 lightDir_TS, float3 lightColor)
float3 evaluate(float3x3 tbn, float3 viewDir_WS, float3 lightDir_WS, float3 lightColor)
{
float nDotL = saturate(dot(normal, lightDir_TS));
float3 h = normalize(lightDir_TS + viewDir_TS);
float nDotH = saturate(dot(normal, h));
float3 normal_WS = mul(tbn, normal);
float diffuse = max(dot(normal_WS, lightDir_WS), 0);
float3 h = lightDir_WS + viewDir_WS;
float specular = dot(normal_WS, h);
return baseColor;
return lightDir_WS * 2 + float3(1, 1, 1);//baseColor * (diffuse + specular) * lightColor;
}
};
@@ -48,7 +49,7 @@ struct DisneyBRDF : IBRDF
float clearCoat = 0;
float clearCoatGloss = 1;
float3 evaluate(float3 viewDir_TS, float3 lightDir_TS, float3 lightColor)
float3 evaluate(float3x3 tbn, float3 viewDir_TS, float3 lightDir_TS, float3 lightColor)
{
return baseColor;
}
+4 -6
View File
@@ -14,8 +14,7 @@ struct DirectionalLight : ILightEnv
float3 illuminate<B:IBRDF>(LightingParameter params, B brdf)
{
float3 lightDir_TS = mul(params.tbn, normalize(direction.xyz));
return brdf.evaluate(params.viewDir_TS, -lightDir_TS, color.xyz);
return brdf.evaluate(params.tbn, params.viewDir_WS, -normalize(direction.xyz), color.xyz);
}
};
@@ -26,11 +25,10 @@ struct PointLight : ILightEnv
float3 illuminate<B:IBRDF>(LightingParameter params, B brdf)
{
float3 position_TS = mul(params.tbn, position_WS.xyz);
float3 lightDir_TS = position_TS - params.position_TS;
float d = length(lightDir_TS);
float3 lightDir_WS = position_WS.xyz - params.position_WS;
float d = length(lightDir_WS);
float illuminance = max(1 - d / colorRange.w, 0);
return illuminance * brdf.evaluate(params.viewDir_TS, normalize(lightDir_TS), colorRange.xyz);
return brdf.evaluate(params.tbn, params.viewDir_WS, normalize(lightDir_WS), colorRange.xyz);
}
bool insidePlane(Plane plane)
+10 -17
View File
@@ -2,7 +2,6 @@ import Common;
struct MaterialParameter
{
float3 position_TS;
float3 position_WS;
float2 texCoords;
float3 vertexColor;
@@ -11,18 +10,16 @@ struct MaterialParameter
// data used by light environment
struct LightingParameter
{
// world to tangent space
float3x3 tbn;
float3 position_TS;
float3 viewDir_TS;
float3 position_WS;
float3 viewDir_WS;
};
// data passed to fragment shader
struct FragmentParameter
{
float4 position_CS : SV_Position;
float3 position_TS : POSITION0;
float3 viewDir_TS : POSITION1;
float3 viewDir_WS : POSITION1;
float3 normal_WS : NORMAL0;
float3 tangent_WS : TANGENT0;
float3 biTangent_WS : TANGENT1;
@@ -32,7 +29,6 @@ struct FragmentParameter
MaterialParameter getMaterialParameter()
{
MaterialParameter result;
result.position_TS = position_TS;
result.position_WS = position_WS;
result.texCoords = texCoords;
result.vertexColor = vertexColor;
@@ -41,9 +37,9 @@ struct FragmentParameter
LightingParameter getLightingParameter()
{
LightingParameter result;
result.tbn = transpose(float3x3(normalize(tangent_WS), normalize(biTangent_WS), normalize(normal_WS)));
result.position_TS = position_TS;
result.viewDir_TS = viewDir_TS;
result.tbn = float3x3(normalize(tangent_WS), normalize(biTangent_WS), normalize(normal_WS));
result.position_WS = position_WS;
result.viewDir_WS = viewDir_WS;
return result;
}
};
@@ -63,14 +59,11 @@ struct VertexAttributes
float4 worldPos = mul(transformMatrix, modelPos);
float4 viewPos = mul(pViewParams.viewMatrix, worldPos);
float4 clipPos = mul(pViewParams.projectionMatrix, viewPos);
float3 tangent_WS = mul(transformMatrix, float4(normalize(tangent_MS), 0)).xyz;
float3 biTangent_WS = mul(transformMatrix, float4(normalize(biTangent_MS), 0)).xyz;
float3 normal_WS = mul(transformMatrix, float4(normalize(normal_MS), 0)).xyz;
// Transforms from world space into tangent space
float3x3 tbn = transpose(float3x3(tangent_WS, biTangent_WS, normal_WS));
float3 tangent_WS = mul(float3x3(transformMatrix), normalize(tangent_MS));
float3 biTangent_WS = mul(float3x3(transformMatrix), normalize(biTangent_MS));
float3 normal_WS = mul(float3x3(transformMatrix), normalize(normal_MS));
FragmentParameter result;
result.position_TS = mul(tbn, worldPos.xyz);
result.viewDir_TS = mul(tbn, pViewParams.cameraPos_WS.xyz - worldPos.xyz);
result.viewDir_WS = pViewParams.cameraPos_WS.xyz - worldPos.xyz;
result.normal_WS = normal_WS;
result.tangent_WS = tangent_WS;
result.biTangent_WS = biTangent_WS;