@@ -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}
0 commit comments