some transparency

This commit is contained in:
Dynamitos
2024-07-17 14:34:00 +02:00
parent 12001152d4
commit 67c4ce2f7a
8 changed files with 51 additions and 9 deletions
+17
View File
@@ -5,6 +5,7 @@ interface IBRDF
float3 evaluate(float3 viewDir_TS, float3 lightDir_TS, float3 lightColor); float3 evaluate(float3 viewDir_TS, float3 lightDir_TS, float3 lightColor);
float3 evaluateAmbient(); float3 evaluateAmbient();
float getAlpha(); float getAlpha();
float3 getTangentNormal();
}; };
struct Phong : IBRDF struct Phong : IBRDF
@@ -40,6 +41,10 @@ struct Phong : IBRDF
{ {
return alpha; return alpha;
} }
float3 getTangentNormal()
{
return normal;
}
}; };
struct BlinnPhong : IBRDF struct BlinnPhong : IBRDF
@@ -75,6 +80,10 @@ struct BlinnPhong : IBRDF
{ {
return alpha; return alpha;
} }
float3 getTangentNormal()
{
return normal;
}
}; };
struct CelShading : IBRDF struct CelShading : IBRDF
@@ -113,6 +122,10 @@ struct CelShading : IBRDF
{ {
return alpha; return alpha;
} }
float3 getTangentNormal()
{
return normal;
}
}; };
// https://learnopengl.com/PBR/Theory // https://learnopengl.com/PBR/Theory
@@ -201,4 +214,8 @@ struct CookTorrance : IBRDF
{ {
return alpha; return alpha;
} }
float3 getTangentNormal()
{
return normal;
}
}; };
+5
View File
@@ -49,6 +49,11 @@ struct FragmentParameter
result.normal_TS = mul(tbn, normal_WS); result.normal_TS = mul(tbn, normal_WS);
return result; return result;
} }
float3x3 getTangentToWorld()
{
float3x3 tbn = float3x3(normalize(tangent_WS), normalize(biTangent_WS), normalize(normal_WS));
return transpose(tbn);
}
#endif #endif
static FragmentParameter interpolate(FragmentParameter f0, FragmentParameter f1, FragmentParameter f2, float3 barycentricCoords) static FragmentParameter interpolate(FragmentParameter f0, FragmentParameter f1, FragmentParameter f2, float3 barycentricCoords)
{ {
+4 -1
View File
@@ -53,6 +53,9 @@ void closestHit(inout RayPayload hitValue, in BuiltInTriangleIntersectionAttribu
// gamma correction // gamma correction
result = result / (result + float3(1.0)); result = result / (result + float3(1.0));
result = pow(result, float3(1.0/2.2)); result = pow(result, float3(1.0/2.2));
hitValue.color = result; hitValue.color = result;
hitValue.alpha = brdf.getAlpha();
hitValue.intersection_WS = WorldRayOrigin() + RayTCurrent() * WorldRayDirection();
hitValue.normal_WS = mul(params.getTangentToWorld(), brdf.getTangentNormal());
} }
+3
View File
@@ -4,4 +4,7 @@ import RayTracingData;
void miss(inout RayPayload p) void miss(inout RayPayload p)
{ {
p.color = float3(0, 1, 0); p.color = float3(0, 1, 0);
p.alpha = 1;
p.intersection_WS = float3(0, 0, 0);
p.normal_WS = float3(0, 0, 0);
} }
+15 -5
View File
@@ -17,10 +17,20 @@ void raygen()
rayDesc.Direction = mul(pViewParams.inverseViewMatrix, float4(normalize(target.xyz), 0)).xyz; rayDesc.Direction = mul(pViewParams.inverseViewMatrix, float4(normalize(target.xyz), 0)).xyz;
rayDesc.TMin = 0.001; rayDesc.TMin = 0.001;
rayDesc.TMax = 10000.0; rayDesc.TMax = 10000.0;
const uint maxRays = 12;
float3 color = float3(0, 0, 0);
float alpha;
for(uint i = 0; i < maxRays; ++i) {
RayPayload payload;
TraceRay(pRayTracingParams.scene, RAY_FLAG_FORCE_OPAQUE, 0xff, 0, 0, 0, rayDesc, payload);
color = color.rgb * alpha + payload.color * payload.alpha;
alpha = alpha + payload.alpha;
rayDesc.Origin = payload.intersection_WS;
if(alpha > 0.9){
break;
}
}
RayPayload payload; pRayTracingParams.image[int2(LaunchID.xy)] = float4(color, alpha);
payload.rayDirection = rayDesc.Direction;
TraceRay(pRayTracingParams.scene, RAY_FLAG_FORCE_OPAQUE, 0xff, 0, 0, 0, rayDesc, payload);
pRayTracingParams.image[int2(LaunchID.xy)] = float4(payload.color, 1.0);
} }
+3 -1
View File
@@ -17,6 +17,8 @@ struct CallablePayload
struct RayPayload struct RayPayload
{ {
float3 rayDirection;
float3 color; float3 color;
float alpha;
float3 intersection_WS;
float3 normal_WS;
}; };
+2
View File
@@ -1,5 +1,6 @@
#pragma once #pragma once
#include "Asset.h" #include "Asset.h"
#include "TextureAsset.h"
namespace Seele { namespace Seele {
class LevelAsset : public Asset { class LevelAsset : public Asset {
@@ -12,5 +13,6 @@ class LevelAsset : public Asset {
virtual void load(ArchiveBuffer& buffer) override; virtual void load(ArchiveBuffer& buffer) override;
private: private:
Array<OTextureAsset> lightMaps;
}; };
} // namespace Seele } // namespace Seele
+2 -2
View File
@@ -4,8 +4,8 @@
namespace Seele { namespace Seele {
namespace Component { namespace Component {
struct PointLight { struct PointLight {
Vector4 positionWS; // give the lights a radius so that they are not actual points
// Vector4 positionVS; Vector4 positionWSRadius;
Vector4 colorRange; Vector4 colorRange;
}; };
} // namespace Component } // namespace Component