Thanks for reply @droettger
Sorry for the poorly constructed question. I will try to be more clear.
I did solve the light direction calculation from previous posts by making all light calculations happen in world space. Thank you again for the assist.
The refdir
is calculated by the following (closest_hit.cu):
extern "C" __global__ void __closesthit__reflect() {
float3 rayDirection = optixGetWorldRayDirection();
float3 rayOrigin = optixGetWorldRayOrigin();
float tHit = optixGetRayTmax();
HitGroupData* hg_data = reinterpret_cast<HitGroupData*>(optixGetSbtDataPoint());
unsigned int triIdx = optixGetPrimitiveIndex();
// From HitGroupData SBT
float3 *norms = hg_data->d_norms;
float3 normalDir = norms[3*triIdx];
float3 rayD = normalize(optixTransformVectorFromWorldToObjectSpace(-rayDirection));
float cthv = dot(normalDir, rayD);
float3 reflectD = (2.0f*cthv) * normalDir - rayDirection;
float3 hit_pt = rayOrigin + tHit * rayDirection;
// Increment depth counter
++(prd->depth);
if(prd->depth < 2) {
PerRayDataReflect *refPrd;
// Set alpha to some scalar
float alpha = ...
float3 T = cross(normalDir, reflectD);
float3 B = cross(T, reflectD);
float dang = 2.0f * alpha;
if(dang > 1.4f) dang = 1.4f;
if(dang < 0.1801f) {
float3 P = reflectD;
float Pnorm = length(P);
P /= Pnorm;
float cthi = dot(normalDir, P);
float3 refdir = normalize(optixTransformVectorFromObjectToWorldSpace(P));
refPrd.depth = prd->depth;
refPrd.result = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
payload = SplitPointerReflect(&refPrd);
optixTrace(topObject, hit_pt, refdir, fmaxf(sceneEpsilon,0.0f), RT_DEFAULT_MAX,
0.0f, OptixVisibilityMask(255), OPTIX_RAY_FLAG_NONE,
RAY_TYPE_PRIMARY, RAY_NUM_TYPE, RAY_TYPE_PRIMARY,
payload.x, payload.y);
This is a typo, I meant to write __closesthit__ch()
You are correct. I put the brackets around the prd->depth++
and prd->results.x
simply for readability for me trying to debug the issue.
I would like to think that the speckled reflections are due to some simple flag or the like that I am not setting properly. I hope anyway.
Thanks again for the assist.
Also attached is a png showing some of the reflective speckling I am talking about.
I looks to me as almost a noise.