Bake thickness
This commit is contained in:
Binary file not shown.
@@ -2,3 +2,4 @@
|
||||
.\dxc.exe -Zpr -Fo ..\raytrace_bake_ao.cso -T lib_6_3 .\raytrace_bake_ao.hlsl
|
||||
.\dxc.exe -Zpr -Fo ..\raytrace_bake_light.cso -T lib_6_3 .\raytrace_bake_light.hlsl
|
||||
.\dxc.exe -Zpr -Fo ..\raytrace_bake_bent.cso -T lib_6_3 .\raytrace_bake_bent.hlsl
|
||||
.\dxc.exe -Zpr -Fo ..\raytrace_bake_thick.cso -T lib_6_3 .\raytrace_bake_thick.hlsl
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
|
||||
#include "std/rand.hlsl"
|
||||
#include "std/math.hlsl"
|
||||
|
||||
struct Vertex {
|
||||
float3 position;
|
||||
float3 normal;
|
||||
float2 tex;
|
||||
};
|
||||
|
||||
struct RayGenConstantBuffer {
|
||||
float4 v0; // frame, strength, radius, offset
|
||||
float4 v1;
|
||||
float4 v2;
|
||||
float4 v3;
|
||||
float4 v4;
|
||||
};
|
||||
|
||||
struct RayPayload {
|
||||
float4 color;
|
||||
float3 ray_origin;
|
||||
float3 ray_dir;
|
||||
};
|
||||
|
||||
RWTexture2D<float4> render_target : register(u0);
|
||||
RaytracingAccelerationStructure scene : register(t0);
|
||||
ByteAddressBuffer indices : register(t1);
|
||||
StructuredBuffer<Vertex> vertices : register(t2);
|
||||
ConstantBuffer<RayGenConstantBuffer> constant_buffer : register(b0);
|
||||
|
||||
Texture2D<float4> mytexture0 : register(t3);
|
||||
Texture2D<float4> mytexture1 : register(t4);
|
||||
Texture2D<float4> mytexture2 : register(t5);
|
||||
Texture2D<float4> mytexture_env : register(t6);
|
||||
Texture2D<float4> mytexture_sobol : register(t7);
|
||||
Texture2D<float4> mytexture_scramble : register(t8);
|
||||
Texture2D<float4> mytexture_rank : register(t9);
|
||||
|
||||
static const int SAMPLES = 64;
|
||||
static uint seed = 0;
|
||||
|
||||
[shader("raygeneration")]
|
||||
void raygeneration() {
|
||||
float2 xy = DispatchRaysIndex().xy + 0.5f;
|
||||
float3 pos = mytexture0.Load(uint3(xy, 0)).rgb;
|
||||
float3 nor = mytexture1.Load(uint3(xy, 0)).rgb;
|
||||
|
||||
RayPayload payload;
|
||||
|
||||
RayDesc ray;
|
||||
ray.TMin = constant_buffer.v0.w * 0.01;
|
||||
ray.TMax = constant_buffer.v0.z * 10.0;
|
||||
ray.Origin = pos;
|
||||
payload.ray_origin = ray.Origin;
|
||||
|
||||
float3 accum = float3(0, 0, 0);
|
||||
|
||||
for (int i = 0; i < SAMPLES; ++i) {
|
||||
ray.Direction = cos_weighted_hemisphere_direction(-nor, i, seed, constant_buffer.v0.x, mytexture_sobol, mytexture_scramble, mytexture_rank);
|
||||
seed += 1;
|
||||
TraceRay(scene, RAY_FLAG_FORCE_OPAQUE, ~0, 0, 1, 0, ray, payload);
|
||||
accum += payload.color.rgb;
|
||||
}
|
||||
|
||||
accum /= SAMPLES;
|
||||
|
||||
float3 color = float3(render_target[DispatchRaysIndex().xy].xyz);
|
||||
if (constant_buffer.v0.x == 0) {
|
||||
color = accum.xyz;
|
||||
}
|
||||
else {
|
||||
float a = 1.0 / constant_buffer.v0.x;
|
||||
float b = 1.0 - a;
|
||||
color = color * b + accum.xyz * a;
|
||||
}
|
||||
render_target[DispatchRaysIndex().xy] = float4(color.xyz, 0.0f);
|
||||
}
|
||||
|
||||
[shader("closesthit")]
|
||||
void closesthit(inout RayPayload payload, in BuiltInTriangleIntersectionAttributes attr) {
|
||||
float dist = RayTCurrent() * 2.0;
|
||||
payload.color = float4(dist, dist, dist, 1);
|
||||
}
|
||||
|
||||
[shader("miss")]
|
||||
void miss(inout RayPayload payload) {
|
||||
payload.color = float4(1, 1, 1, 1);
|
||||
}
|
||||
@@ -415,9 +415,10 @@ class RenderPathPaint {
|
||||
if (isMerged) Context.mergedObject.visible = _visible;
|
||||
}
|
||||
#if kha_direct3d12
|
||||
else if (UITrait.inst.bakeType == 0 || // AO (DXR)
|
||||
UITrait.inst.bakeType == 8 || // Lightmap (DXR)
|
||||
UITrait.inst.bakeType == 9) { // Bent Normal (DXR)
|
||||
else if (UITrait.inst.bakeType == 0 || // AO (DXR)
|
||||
UITrait.inst.bakeType == 8 || // Lightmap (DXR)
|
||||
UITrait.inst.bakeType == 9 || // Bent Normal (DXR)
|
||||
UITrait.inst.bakeType == 10) { // Thickness (DXR)
|
||||
RenderPathRaytrace.commandsBake();
|
||||
}
|
||||
#end
|
||||
|
||||
@@ -316,7 +316,8 @@ class RenderPathRaytrace {
|
||||
return
|
||||
UITrait.inst.bakeType == 0 ? "raytrace_bake_ao.cso" :
|
||||
UITrait.inst.bakeType == 8 ? "raytrace_bake_light.cso" :
|
||||
"raytrace_bake_bent.cso";
|
||||
UITrait.inst.bakeType == 9 ? "raytrace_bake_bent.cso" :
|
||||
"raytrace_bake_thick.cso";
|
||||
}
|
||||
|
||||
public static function draw() {
|
||||
|
||||
@@ -990,6 +990,7 @@ class UITrait {
|
||||
#if kha_direct3d12
|
||||
bakes.push("Lightmap (DXR)");
|
||||
bakes.push("BentNormal (DXR)");
|
||||
bakes.push("Thickness (DXR)");
|
||||
#end
|
||||
bakeType = ui.combo(bakeHandle, bakes, "Bake");
|
||||
if (bakeType == 3 || bakeType == 4 || bakeType == 9) {
|
||||
@@ -1009,7 +1010,7 @@ class UITrait {
|
||||
bakeAoOffset = ui.slider(offsetHandle, "Offset", 0.0, 2.0, true);
|
||||
}
|
||||
#if kha_direct3d12
|
||||
if (bakeType == 0 || bakeType == 8 || bakeType == 9) { // ao, bent, lightmap
|
||||
if (bakeType == 0 || bakeType == 8 || bakeType == 9 || bakeType == 10) { // ao, bent, lightmap, thick
|
||||
ui.text("Rays/pix: " + arm.render.RenderPathRaytrace.raysPix);
|
||||
ui.text("Rays/sec: " + arm.render.RenderPathRaytrace.raysSec);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user