Skip to content

Commit 4d3e046

Browse files
committed
removed intersectdata usage, fix emissive bug
1 parent 8eaa714 commit 4d3e046

File tree

7 files changed

+214
-212
lines changed

7 files changed

+214
-212
lines changed

31_HLSLPathTracer/app_resources/hlsl/common.hlsl

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,33 @@ struct BxDFNode
105105

106106
NBL_CONSTEXPR_STATIC_INLINE uint32_t INVALID_ID = 0xffffu;
107107

108+
// for diffuse bxdfs
109+
static BxDFNode<Spectrum> create(uint32_t materialType, bool isAniso, NBL_CONST_REF_ARG(float32_t2) A, NBL_CONST_REF_ARG(spectral_type) albedo)
110+
{
111+
BxDFNode<Spectrum> retval;
112+
retval.albedo = albedo;
113+
retval.materialType = materialType;
114+
retval.params.is_aniso = isAniso;
115+
retval.params.A = hlsl::max<float32_t2>(A, 1e-4);
116+
retval.params.ior0 = (spectral_type)1.0;
117+
retval.params.ior1 = (spectral_type)1.0;
118+
return retval;
119+
}
120+
121+
// for conductor + dielectric
108122
static BxDFNode<Spectrum> create(uint32_t materialType, bool isAniso, NBL_CONST_REF_ARG(float32_t2) A, NBL_CONST_REF_ARG(spectral_type) ior0, NBL_CONST_REF_ARG(spectral_type) ior1)
109123
{
110124
BxDFNode<Spectrum> retval;
125+
retval.albedo = (spectral_type)1.0;
111126
retval.materialType = materialType;
112127
retval.params.is_aniso = isAniso;
113-
retval.params.A = A;
128+
retval.params.A = hlsl::max<float32_t2>(A, 1e-4);
114129
retval.params.ior0 = ior0;
115130
retval.params.ior1 = ior1;
116131
return retval;
117132
}
118133

134+
spectral_type albedo;
119135
uint32_t materialType;
120136
params_type params;
121137
};
@@ -149,50 +165,50 @@ enum PTPolygonMethod : uint16_t
149165
PPM_APPROX_PROJECTED_SOLID_ANGLE
150166
};
151167

152-
namespace Intersector
153-
{
154-
// ray query method
155-
// ray query struct holds AS info
156-
// pass in address to vertex/index buffers?
168+
// namespace Intersector
169+
// {
170+
// // ray query method
171+
// // ray query struct holds AS info
172+
// // pass in address to vertex/index buffers?
157173

158-
// ray tracing pipeline method
174+
// // ray tracing pipeline method
159175

160-
// procedural data store: [obj count] [intersect type] [obj1] [obj2] [...]
176+
// // procedural data store: [obj count] [intersect type] [obj1] [obj2] [...]
161177

162-
struct IntersectData
163-
{
164-
enum Mode : uint32_t // enum class?
165-
{
166-
RAY_QUERY,
167-
RAY_TRACING,
168-
PROCEDURAL
169-
};
178+
// struct IntersectData
179+
// {
180+
// enum Mode : uint32_t // enum class?
181+
// {
182+
// RAY_QUERY,
183+
// RAY_TRACING,
184+
// PROCEDURAL
185+
// };
170186

171-
NBL_CONSTEXPR_STATIC_INLINE uint32_t DataSize = 128;
187+
// NBL_CONSTEXPR_STATIC_INLINE uint32_t DataSize = 128;
172188

173-
uint32_t mode : 1;
174-
uint32_t unused : 31; // possible space for flags
175-
uint32_t data[DataSize];
189+
// uint32_t mode : 2;
190+
// uint32_t unused : 30; // possible space for flags
191+
// uint32_t data[DataSize];
192+
// };
193+
// }
194+
195+
enum IntersectMode : uint32_t
196+
{
197+
IM_RAY_QUERY,
198+
IM_RAY_TRACING,
199+
IM_PROCEDURAL
176200
};
177-
}
178201

179202
namespace NextEventEstimator
180203
{
181204
// procedural data store: [light count] [event type] [obj]
182205

183206
struct Event
184207
{
185-
enum Mode : uint32_t // enum class?
186-
{
187-
RAY_QUERY,
188-
RAY_TRACING,
189-
PROCEDURAL
190-
};
191-
192208
NBL_CONSTEXPR_STATIC_INLINE uint32_t DataSize = 16;
193209

194-
uint32_t mode : 1;
195-
uint32_t unused : 31; // possible space for flags
210+
uint32_t mode : 2;
211+
uint32_t unused : 30; // possible space for flags
196212
uint32_t data[DataSize];
197213
};
198214
}

31_HLSLPathTracer/app_resources/hlsl/intersector.hlsl

Lines changed: 85 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct Comprehensive
4141
{
4242
ray.intersectionT = t;
4343
objectID.id = i;
44-
objectID.mode = IntersectData::Mode::PROCEDURAL;
44+
objectID.mode = IM_PROCEDURAL;
4545
objectID.shapeType = PST_SPHERE;
4646
}
4747
}
@@ -55,7 +55,7 @@ struct Comprehensive
5555
{
5656
ray.intersectionT = t;
5757
objectID.id = i;
58-
objectID.mode = IntersectData::Mode::PROCEDURAL;
58+
objectID.mode = IM_PROCEDURAL;
5959
objectID.shapeType = PST_TRIANGLE;
6060
}
6161
}
@@ -69,7 +69,7 @@ struct Comprehensive
6969
{
7070
ray.intersectionT = t;
7171
objectID.id = i;
72-
objectID.mode = IntersectData::Mode::PROCEDURAL;
72+
objectID.mode = IM_PROCEDURAL;
7373
objectID.shapeType = PST_TRIANGLE;
7474
}
7575
}
@@ -81,90 +81,90 @@ struct Comprehensive
8181

8282
// note for future consideration: still need to encode to IntersectData?
8383
// obsolete?
84-
static ObjectID traceProcedural(NBL_REF_ARG(ray_type) ray, NBL_CONST_REF_ARG(IntersectData) intersect)
85-
{
86-
const bool anyHit = ray.intersectionT != numeric_limits<scalar_type>::max;
87-
const uint32_t objCount = intersect.data[0];
88-
const ProceduralShapeType type = (ProceduralShapeType)intersect.data[1];
89-
90-
ObjectID objectID = ray.objectID;
91-
objectID.mode = IntersectData::Mode::PROCEDURAL;
92-
objectID.shapeType = type;
93-
for (int i = 0; i < objCount; i++)
94-
{
95-
float t;
96-
switch (type)
97-
{
98-
case PST_SPHERE:
99-
{
100-
vector3_type position = vector3_type(asfloat(intersect.data[2 + i * Shape<PST_SPHERE>::ObjSize]), asfloat(intersect.data[2 + i * Shape<PST_SPHERE>::ObjSize + 1]), asfloat(intersect.data[2 + i * Shape<PST_SPHERE>::ObjSize + 2]));
101-
Shape<PST_SPHERE> sphere = Shape<PST_SPHERE>::create(position, asfloat(intersect.data[2 + i * Shape<PST_SPHERE>::ObjSize + 3]), intersect.data[2 + i * Shape<PST_SPHERE>::ObjSize + 4]);
102-
t = sphere.intersect(ray.origin, ray.direction);
103-
}
104-
break;
105-
case PST_TRIANGLE:
106-
{
107-
vector3_type vertex0 = vector3_type(asfloat(intersect.data[2 + i * Shape<PST_TRIANGLE>::ObjSize]), asfloat(intersect.data[2 + i * Shape<PST_SPHERE>::ObjSize + 1]), asfloat(intersect.data[2 + i * Shape<PST_TRIANGLE>::ObjSize + 2]));
108-
vector3_type vertex1 = vector3_type(asfloat(intersect.data[2 + i * Shape<PST_TRIANGLE>::ObjSize + 3]), asfloat(intersect.data[2 + i * Shape<PST_SPHERE>::ObjSize + 4]), asfloat(intersect.data[2 + i * Shape<PST_TRIANGLE>::ObjSize + 5]));
109-
vector3_type vertex2 = vector3_type(asfloat(intersect.data[2 + i * Shape<PST_TRIANGLE>::ObjSize + 6]), asfloat(intersect.data[2 + i * Shape<PST_SPHERE>::ObjSize + 7]), asfloat(intersect.data[2 + i * Shape<PST_TRIANGLE>::ObjSize + 8]));
110-
Shape<PST_TRIANGLE> tri = Shape<PST_TRIANGLE>::create(vertex0, vertex1, vertex2, intersect.data[2 + i * Shape<PST_TRIANGLE>::ObjSize + 9]);
111-
t = tri.intersect(ray.origin, ray.direction);
112-
}
113-
break;
114-
case PST_RECTANGLE:
115-
{
116-
vector3_type offset = vector3_type(asfloat(intersect.data[2 + i * Shape<PST_RECTANGLE>::ObjSize]), asfloat(intersect.data[2 + i * Shape<PST_RECTANGLE>::ObjSize + 1]), asfloat(intersect.data[2 + i * Shape<PST_RECTANGLE>::ObjSize + 2]));
117-
vector3_type edge0 = vector3_type(asfloat(intersect.data[2 + i * Shape<PST_RECTANGLE>::ObjSize + 3]), asfloat(intersect.data[2 + i * Shape<PST_RECTANGLE>::ObjSize + 4]), asfloat(intersect.data[2 + i * Shape<PST_RECTANGLE>::ObjSize + 5]));
118-
vector3_type edge1 = vector3_type(asfloat(intersect.data[2 + i * Shape<PST_RECTANGLE>::ObjSize + 6]), asfloat(intersect.data[2 + i * Shape<PST_RECTANGLE>::ObjSize + 7]), asfloat(intersect.data[2 + i * Shape<PST_RECTANGLE>::ObjSize + 8]));
119-
Shape<PST_RECTANGLE> rect = Shape<PST_RECTANGLE>::create(offset, edge0, edge1, intersect.data[2 + i * Shape<PST_RECTANGLE>::ObjSize + 9]);
120-
t = rect.intersect(ray.origin, ray.direction);
121-
}
122-
break;
123-
default:
124-
t = numeric_limits<float>::infinity;
125-
break;
126-
}
127-
128-
bool closerIntersection = t > 0.0 && t < ray.intersectionT;
129-
130-
ray.intersectionT = closerIntersection ? t : ray.intersectionT;
131-
objectID.id = closerIntersection ? i : objectID.id;
132-
133-
// allowing early out results in a performance regression, WTF!?
134-
//if (anyHit && closerIntersection)
135-
//break;
136-
}
137-
return objectID;
138-
}
84+
// static ObjectID traceProcedural(NBL_REF_ARG(ray_type) ray, NBL_CONST_REF_ARG(IntersectData) intersect)
85+
// {
86+
// const bool anyHit = ray.intersectionT != numeric_limits<scalar_type>::max;
87+
// const uint32_t objCount = intersect.data[0];
88+
// const ProceduralShapeType type = (ProceduralShapeType)intersect.data[1];
89+
90+
// ObjectID objectID = ray.objectID;
91+
// objectID.mode = IM_PROCEDURAL;
92+
// objectID.shapeType = type;
93+
// for (int i = 0; i < objCount; i++)
94+
// {
95+
// float t;
96+
// switch (type)
97+
// {
98+
// case PST_SPHERE:
99+
// {
100+
// vector3_type position = vector3_type(asfloat(intersect.data[2 + i * Shape<PST_SPHERE>::ObjSize]), asfloat(intersect.data[2 + i * Shape<PST_SPHERE>::ObjSize + 1]), asfloat(intersect.data[2 + i * Shape<PST_SPHERE>::ObjSize + 2]));
101+
// Shape<PST_SPHERE> sphere = Shape<PST_SPHERE>::create(position, asfloat(intersect.data[2 + i * Shape<PST_SPHERE>::ObjSize + 3]), intersect.data[2 + i * Shape<PST_SPHERE>::ObjSize + 4]);
102+
// t = sphere.intersect(ray.origin, ray.direction);
103+
// }
104+
// break;
105+
// case PST_TRIANGLE:
106+
// {
107+
// vector3_type vertex0 = vector3_type(asfloat(intersect.data[2 + i * Shape<PST_TRIANGLE>::ObjSize]), asfloat(intersect.data[2 + i * Shape<PST_SPHERE>::ObjSize + 1]), asfloat(intersect.data[2 + i * Shape<PST_TRIANGLE>::ObjSize + 2]));
108+
// vector3_type vertex1 = vector3_type(asfloat(intersect.data[2 + i * Shape<PST_TRIANGLE>::ObjSize + 3]), asfloat(intersect.data[2 + i * Shape<PST_SPHERE>::ObjSize + 4]), asfloat(intersect.data[2 + i * Shape<PST_TRIANGLE>::ObjSize + 5]));
109+
// vector3_type vertex2 = vector3_type(asfloat(intersect.data[2 + i * Shape<PST_TRIANGLE>::ObjSize + 6]), asfloat(intersect.data[2 + i * Shape<PST_SPHERE>::ObjSize + 7]), asfloat(intersect.data[2 + i * Shape<PST_TRIANGLE>::ObjSize + 8]));
110+
// Shape<PST_TRIANGLE> tri = Shape<PST_TRIANGLE>::create(vertex0, vertex1, vertex2, intersect.data[2 + i * Shape<PST_TRIANGLE>::ObjSize + 9]);
111+
// t = tri.intersect(ray.origin, ray.direction);
112+
// }
113+
// break;
114+
// case PST_RECTANGLE:
115+
// {
116+
// vector3_type offset = vector3_type(asfloat(intersect.data[2 + i * Shape<PST_RECTANGLE>::ObjSize]), asfloat(intersect.data[2 + i * Shape<PST_RECTANGLE>::ObjSize + 1]), asfloat(intersect.data[2 + i * Shape<PST_RECTANGLE>::ObjSize + 2]));
117+
// vector3_type edge0 = vector3_type(asfloat(intersect.data[2 + i * Shape<PST_RECTANGLE>::ObjSize + 3]), asfloat(intersect.data[2 + i * Shape<PST_RECTANGLE>::ObjSize + 4]), asfloat(intersect.data[2 + i * Shape<PST_RECTANGLE>::ObjSize + 5]));
118+
// vector3_type edge1 = vector3_type(asfloat(intersect.data[2 + i * Shape<PST_RECTANGLE>::ObjSize + 6]), asfloat(intersect.data[2 + i * Shape<PST_RECTANGLE>::ObjSize + 7]), asfloat(intersect.data[2 + i * Shape<PST_RECTANGLE>::ObjSize + 8]));
119+
// Shape<PST_RECTANGLE> rect = Shape<PST_RECTANGLE>::create(offset, edge0, edge1, intersect.data[2 + i * Shape<PST_RECTANGLE>::ObjSize + 9]);
120+
// t = rect.intersect(ray.origin, ray.direction);
121+
// }
122+
// break;
123+
// default:
124+
// t = numeric_limits<float>::infinity;
125+
// break;
126+
// }
127+
128+
// bool closerIntersection = t > 0.0 && t < ray.intersectionT;
129+
130+
// ray.intersectionT = closerIntersection ? t : ray.intersectionT;
131+
// objectID.id = closerIntersection ? i : objectID.id;
132+
133+
// // allowing early out results in a performance regression, WTF!?
134+
// //if (anyHit && closerIntersection)
135+
// //break;
136+
// }
137+
// return objectID;
138+
// }
139139

140140
// obsolete?
141-
static ObjectID traceRay(NBL_REF_ARG(ray_type) ray, NBL_CONST_REF_ARG(IntersectData) intersect)
142-
{
143-
const IntersectData::Mode mode = (IntersectData::Mode)intersect.mode;
144-
switch (mode)
145-
{
146-
case IntersectData::Mode::RAY_QUERY:
147-
{
148-
// TODO: do ray query stuff
149-
}
150-
break;
151-
case IntersectData::Mode::RAY_TRACING:
152-
{
153-
// TODO: do ray tracing stuff
154-
}
155-
break;
156-
case IntersectData::Mode::PROCEDURAL:
157-
{
158-
return traceProcedural(ray, intersect);
159-
}
160-
break;
161-
default:
162-
{
163-
return ObjectID::create(-1, 0, PST_SPHERE);
164-
}
165-
}
166-
return ObjectID::create(-1, 0, PST_SPHERE);
167-
}
141+
// static ObjectID traceRay(NBL_REF_ARG(ray_type) ray, NBL_CONST_REF_ARG(IntersectData) intersect)
142+
// {
143+
// const uint32_t mode = intersect.mode;
144+
// switch (mode)
145+
// {
146+
// case IM_RAY_QUERY:
147+
// {
148+
// // TODO: do ray query stuff
149+
// }
150+
// break;
151+
// case IM_RAY_TRACING:
152+
// {
153+
// // TODO: do ray tracing stuff
154+
// }
155+
// break;
156+
// case IM_PROCEDURAL:
157+
// {
158+
// return traceProcedural(ray, intersect);
159+
// }
160+
// break;
161+
// default:
162+
// {
163+
// return ObjectID::create(-1, 0, PST_SPHERE);
164+
// }
165+
// }
166+
// return ObjectID::create(-1, 0, PST_SPHERE);
167+
// }
168168

169169
// static ObjectID traceRay(NBL_REF_ARG(ray_type) ray, NBL_CONST_REF_ARG(scene_type) scene)
170170
// {
@@ -198,43 +198,6 @@ struct Comprehensive
198198
// }
199199
};
200200

201-
// does everything in traceray in ex 30
202-
// template<class Ray>
203-
// struct Procedural
204-
// {
205-
// using scalar_type = typename Ray::scalar_type;
206-
// using ray_type = Ray;
207-
208-
// static int traceRay(NBL_REF_ARG(ray_type) ray, IIntersection objects[32], int objCount)
209-
// {
210-
// const bool anyHit = ray.intersectionT != numeric_limits<scalar_type>::max;
211-
212-
// int objectID = -1;
213-
// for (int i = 0; i < objCount; i++)
214-
// {
215-
// float t;
216-
// if (objects[i].type == PST_SPHERE) // we don't know what type of intersection it is so cast, there has to be a better way to do this
217-
// {
218-
// Shape<PST_SPHERE> sphere = (Shape<PST_SPHERE>)objects[i];
219-
// t = sphere.intersect(ray.origin, ray.direction);
220-
// }
221-
// // TODO: other types
222-
223-
// bool closerIntersection = t > 0.0 && t < ray.intersectionT;
224-
225-
// ray.intersectionT = closerIntersection ? t : ray.intersectionT;
226-
// objectID = closerIntersection ? i : objectID;
227-
228-
// // allowing early out results in a performance regression, WTF!?
229-
// //if (anyHit && closerIntersection)
230-
// //break;
231-
// }
232-
// return objectID;
233-
// }
234-
235-
// // TODO? traceray with vertex/index buffer
236-
// };
237-
238201
}
239202
}
240203
}

31_HLSLPathTracer/app_resources/hlsl/material_system.hlsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ struct Material
2525

2626
NBL_CONSTEXPR_STATIC_INLINE uint32_t DataSize = 32;
2727

28-
uint32_t type : 1;
29-
uint32_t unused : 31; // possible space for flags
28+
uint32_t type : 2;
29+
uint32_t unused : 30; // possible space for flags
3030
uint32_t data[DataSize];
3131
};
3232

@@ -66,7 +66,7 @@ struct System
6666
case Material::Type::DIFFUSE:
6767
{
6868
diffuseBxDF.init(cparams);
69-
return (measure_type)diffuseBxDF.eval(params);
69+
return cparams.albedo * (measure_type)diffuseBxDF.eval(params);
7070
}
7171
break;
7272
case Material::Type::CONDUCTOR:

0 commit comments

Comments
 (0)