Faster raytracing
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -3,9 +3,10 @@
|
||||
#include "std/math.hlsl"
|
||||
|
||||
struct Vertex {
|
||||
float3 position;
|
||||
float3 normal;
|
||||
float2 tex;
|
||||
uint posxy;
|
||||
uint poszw;
|
||||
uint nor;
|
||||
uint tex;
|
||||
};
|
||||
|
||||
struct RayGenConstantBuffer {
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
#include "std/math.hlsl"
|
||||
|
||||
struct Vertex {
|
||||
float3 position;
|
||||
float3 normal;
|
||||
float2 tex;
|
||||
uint posxy;
|
||||
uint poszw;
|
||||
uint nor;
|
||||
uint tex;
|
||||
};
|
||||
|
||||
struct RayGenConstantBuffer {
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
#include "std/attrib.hlsl"
|
||||
|
||||
struct Vertex {
|
||||
float3 position;
|
||||
float3 normal;
|
||||
float2 tex;
|
||||
uint posxy;
|
||||
uint poszw;
|
||||
uint nor;
|
||||
uint tex;
|
||||
};
|
||||
|
||||
struct RayGenConstantBuffer {
|
||||
@@ -91,16 +92,16 @@ void closesthit(inout RayPayload payload, in BuiltInTriangleIntersectionAttribut
|
||||
uint3 indices_sample = indices.Load3(base_index);
|
||||
|
||||
float3 vertex_normals[3] = {
|
||||
float3(vertices[indices_sample[0]].normal),
|
||||
float3(vertices[indices_sample[1]].normal),
|
||||
float3(vertices[indices_sample[2]].normal)
|
||||
float3(S16toF32(vertices[indices_sample[0]].nor), S16toF32(vertices[indices_sample[0]].poszw).y),
|
||||
float3(S16toF32(vertices[indices_sample[1]].nor), S16toF32(vertices[indices_sample[1]].poszw).y),
|
||||
float3(S16toF32(vertices[indices_sample[2]].nor), S16toF32(vertices[indices_sample[2]].poszw).y)
|
||||
};
|
||||
float3 n = normalize(hit_attribute(vertex_normals, attr));
|
||||
|
||||
float2 vertex_uvs[3] = {
|
||||
float2(vertices[indices_sample[0]].tex),
|
||||
float2(vertices[indices_sample[1]].tex),
|
||||
float2(vertices[indices_sample[2]].tex)
|
||||
S16toF32(vertices[indices_sample[0]].tex),
|
||||
S16toF32(vertices[indices_sample[1]].tex),
|
||||
S16toF32(vertices[indices_sample[2]].tex)
|
||||
};
|
||||
float2 tex_coord = hit_attribute2d(vertex_uvs, attr);
|
||||
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
#include "std/math.hlsl"
|
||||
|
||||
struct Vertex {
|
||||
float3 position;
|
||||
float3 normal;
|
||||
float2 tex;
|
||||
uint posxy;
|
||||
uint poszw;
|
||||
uint nor;
|
||||
uint tex;
|
||||
};
|
||||
|
||||
struct RayGenConstantBuffer {
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
#include "std/math.hlsl"
|
||||
|
||||
struct Vertex {
|
||||
float3 position;
|
||||
float3 normal;
|
||||
float2 tex;
|
||||
uint posxy;
|
||||
uint poszw;
|
||||
uint nor;
|
||||
uint tex;
|
||||
};
|
||||
|
||||
struct RayGenConstantBuffer {
|
||||
@@ -122,9 +123,9 @@ void closesthit(inout RayPayload payload, in BuiltInTriangleIntersectionAttribut
|
||||
uint3 indices_sample = indices.Load3(base_index);
|
||||
|
||||
float2 vertex_uvs[3] = {
|
||||
float2(vertices[indices_sample[0]].tex),
|
||||
float2(vertices[indices_sample[1]].tex),
|
||||
float2(vertices[indices_sample[2]].tex)
|
||||
S16toF32(vertices[indices_sample[0]].tex),
|
||||
S16toF32(vertices[indices_sample[1]].tex),
|
||||
S16toF32(vertices[indices_sample[2]].tex)
|
||||
};
|
||||
float2 tex_coord = hit_attribute2d(vertex_uvs, attr);
|
||||
|
||||
@@ -140,9 +141,9 @@ void closesthit(inout RayPayload payload, in BuiltInTriangleIntersectionAttribut
|
||||
}
|
||||
|
||||
float3 vertex_normals[3] = {
|
||||
float3(vertices[indices_sample[0]].normal),
|
||||
float3(vertices[indices_sample[1]].normal),
|
||||
float3(vertices[indices_sample[2]].normal)
|
||||
float3(S16toF32(vertices[indices_sample[0]].nor), S16toF32(vertices[indices_sample[0]].poszw).y),
|
||||
float3(S16toF32(vertices[indices_sample[1]].nor), S16toF32(vertices[indices_sample[1]].poszw).y),
|
||||
float3(S16toF32(vertices[indices_sample[2]].nor), S16toF32(vertices[indices_sample[2]].poszw).y)
|
||||
};
|
||||
float3 n = normalize(hit_attribute(vertex_normals, attr));
|
||||
|
||||
|
||||
@@ -2,6 +2,12 @@
|
||||
#ifndef _ATTRIB_HLSL_
|
||||
#define _ATTRIB_HLSL_
|
||||
|
||||
float2 S16toF32(uint val) {
|
||||
int a = (int)(val << 16) >> 16;
|
||||
int b = (int)(val & 0xffff0000) >> 16;
|
||||
return float2(a, b) / 32767.0f;
|
||||
}
|
||||
|
||||
float3 hit_world_position() {
|
||||
return WorldRayOrigin() + RayTCurrent() * WorldRayDirection();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user