More ray tracing changes
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import Common;
|
||||
import RayTracingData;
|
||||
import MaterialParameter;
|
||||
import LightEnv;
|
||||
import MATERIAL_FILE_NAME;
|
||||
|
||||
[shader("callable")]
|
||||
void callable(inout CallablePayload payload)
|
||||
{
|
||||
LightingParameter lightingParams = payload.params.getLightingParameter();
|
||||
MaterialParameter materialParams = payload.params.getMaterialParameter();
|
||||
let brdf = Material.prepare(materialParams);
|
||||
|
||||
float3 result = float3(0, 0, 0);
|
||||
for(int i = 0; i < pLightEnv.numDirectionalLights; ++i)
|
||||
{
|
||||
result += pLightEnv.directionalLights[i].illuminate(lightingParams, brdf);
|
||||
}
|
||||
for(uint i = 0; i < pLightEnv.numPointLights; ++i)
|
||||
{
|
||||
result += pLightEnv.pointLights[i].illuminate(lightingParams, brdf);
|
||||
}
|
||||
result += brdf.evaluateAmbient();
|
||||
// gamma correction
|
||||
result = result / (result + float3(1.0));
|
||||
result = pow(result, float3(1.0/2.2));
|
||||
payload.color = float3(0, 0, 1);
|
||||
}
|
||||
@@ -4,12 +4,11 @@ import MaterialParameter;
|
||||
import LightEnv;
|
||||
import Scene;
|
||||
import RayTracingData;
|
||||
import MATERIAL_FILE_NAME;
|
||||
|
||||
// simplification: all BLAS only have 1 geometry
|
||||
|
||||
[shader("closesthit")]
|
||||
void closesthit(inout float3 hitValue, in BuiltInTriangleIntersectionAttributes attr)
|
||||
void closestHit(inout RayPayload hitValue, in BuiltInTriangleIntersectionAttributes attr)
|
||||
{
|
||||
const float3 barycentricCoords = float3(1.0f - attr.barycentrics.x - attr.barycentrics.y, attr.barycentrics.x, attr.barycentrics.y);
|
||||
|
||||
@@ -35,23 +34,10 @@ void closesthit(inout float3 hitValue, in BuiltInTriangleIntersectionAttributes
|
||||
|
||||
FragmentParameter params = FragmentParameter.interpolate(f0, f1, f2, barycentricCoords);
|
||||
|
||||
LightingParameter lightingParams = params.getLightingParameter();
|
||||
MaterialParameter materialParams = params.getMaterialParameter();
|
||||
let brdf = Material.prepare(materialParams);
|
||||
|
||||
float3 result = float3(0, 0, 0);
|
||||
for(int i = 0; i < pLightEnv.numDirectionalLights; ++i)
|
||||
{
|
||||
result += pLightEnv.directionalLights[i].illuminate(lightingParams, brdf);
|
||||
}
|
||||
for(uint i = 0; i < pLightEnv.numPointLights; ++i)
|
||||
{
|
||||
result += pLightEnv.pointLights[i].illuminate(lightingParams, brdf);
|
||||
}
|
||||
result += brdf.evaluateAmbient();
|
||||
// gamma correction
|
||||
result = result / (result + float3(1.0));
|
||||
result = pow(result, float3(1.0/2.2));
|
||||
CallablePayload callable;
|
||||
callable.params = params;
|
||||
|
||||
hitValue = result;
|
||||
CallShader(0, callable);
|
||||
|
||||
hitValue.color = float3(0, 1, 1) + callable.color;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import RayTracingData;
|
||||
|
||||
[shader("miss")]
|
||||
void main(inout float3 p)
|
||||
void miss(inout RayPayload p)
|
||||
{
|
||||
p = float3(1, 0, 1);
|
||||
p.color = float3(0, 1, 0);
|
||||
}
|
||||
@@ -2,33 +2,33 @@ import Common;
|
||||
import RayTracingData;
|
||||
|
||||
[shader("raygeneration")]
|
||||
void main()
|
||||
void raygen()
|
||||
{
|
||||
const float2 pixelCenter = float2(DispatchRaysIndex().xy) + float2(0.5);
|
||||
const float2 inUV = pixelCenter / float2(DispatchRaysDimensions().xy);
|
||||
float2 d = inUV * 2.0 - 1.0;
|
||||
|
||||
float4 origin = mul(pViewParams.inverseViewMatrix, float4(0, 0, 0, 1));
|
||||
float4 target = mul(pViewParams.inverseProjection, float4(d.x, d.y, 1, 1));
|
||||
float4 direction = mul(pViewParams.inverseViewMatrix, float4(normalize(target.xyz), 0));
|
||||
float4 target = mul(pViewParams.inverseProjection, float4(d.x, d.y, 1, 1));
|
||||
float4 direction = mul(pViewParams.inverseViewMatrix, float4(target.xyz, 0));
|
||||
|
||||
float tmin = 0.0001;
|
||||
float tmax = 10000.0;
|
||||
|
||||
uint max_rays = 24;
|
||||
|
||||
float4 color = float4(0, 0, 0, 0);
|
||||
float expectedDistance = -1;
|
||||
float3 payload;
|
||||
RayPayload payload;
|
||||
|
||||
RayDesc desc = {
|
||||
origin.xyz,
|
||||
tmin,
|
||||
direction.xyz,
|
||||
tmax,
|
||||
};
|
||||
RayDesc desc;
|
||||
desc.Origin = origin.xyz;
|
||||
desc.Direction = direction.xyz;
|
||||
desc.TMin = tmin;
|
||||
desc.TMax = tmax;
|
||||
|
||||
TraceRay(pRayTracingParams.scene, RAY_FLAG_FORCE_OPAQUE, 0xff, 0, 0, 0, desc, payload);
|
||||
pRayTracingParams.origins[DispatchRaysIndex().x + DispatchRaysDimensions().x * DispatchRaysIndex().y] = origin.xyz;
|
||||
pRayTracingParams.rayDirections[DispatchRaysIndex().x + DispatchRaysDimensions().x * DispatchRaysIndex().y] = direction.xyz;
|
||||
|
||||
pRayTracingParams.image[DispatchRaysIndex().xy] = float4(payload, 1.0f);
|
||||
TraceRay(pRayTracingParams.scene, 0, 0xff, 0, 1, 0, desc, payload);
|
||||
|
||||
pRayTracingParams.image[DispatchRaysIndex().xy] = float4(payload.color, 1.0f);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,23 @@
|
||||
import MaterialParameter;
|
||||
|
||||
struct RayTracingParams
|
||||
{
|
||||
RaytracingAccelerationStructure scene;
|
||||
RWTexture2D<float4> image;
|
||||
StructuredBuffer<uint> indexBuffer;
|
||||
RWStructuredBuffer<float3> rayDirections;
|
||||
RWStructuredBuffer<float3> origins;
|
||||
};
|
||||
layout(set=5)
|
||||
ParameterBlock<RayTracingParams> pRayTracingParams;
|
||||
|
||||
struct CallablePayload
|
||||
{
|
||||
FragmentParameter params;
|
||||
float3 color;
|
||||
};
|
||||
|
||||
struct RayPayload
|
||||
{
|
||||
float3 color;
|
||||
};
|
||||
Reference in New Issue
Block a user