Dear All,
I am trying to implement a simple tracer for evaluating Phong materials with shadows.
Execution runs fine if only directional and spotlight shadows are enabled. It also works with only directional and point light shadows enabled.
If shadow ray launches are enabled for directional and both point and spot lights (all rtTrace code lines uncommented) however, Optix code runs into a null pointer execution on CPU during rtContextLaunch2D(…).
Exception thrown at 0x0000000000000000 in optixtest.exe: 0xC0000005: Access violation executing location 0x0000000000000000.
Commenting rtTrace for either results in a successful trace
I am working on Windows 10 CUDA 10.1 (tried 10.0 as well), Optix 6.0, NVIDIA driver 430.86 (tried several other drivers), NVIDIA RTX 2070 GPU.
I have the following in my code.
In closest hit program:
#include <optix_world.h>
#include <optix_math.h>
//...
#define EPSILON 0.00001f
struct PerRayData_shadow
{
bool inShadow;
};
rtDeclareVariable(PerRayData_shadow, currentPerRayDataShadow, rtPayload, );
RT_PROGRAM void collisionAnyHitProgram()
{
currentPerRayDataShadow.inShadow = true;
rtTerminateRay();
}
rtDeclareVariable(rtObject, top_object, , );
rtDeclareVariable(uint4, lightCounts, , ); //Directional, spot, point.
rtDeclareVariable(float3, positionResult, attribute positionResultVector, );
//...
//Other declarations.
//...
__device__ void calculateDirectionalLightContribution(
uint lightIndex,
float3& ambient,
float4& diffuse,
float3& specular,
float& shininess,
float3& normal)
{
//... fetch directional
float3 VP = -directionLight.direction;
float shadow = 1.0f;
PerRayData_shadow shadowPrd;
shadowPrd.inShadow = false;
Ray shadowRay = make_Ray(positionResult, VP, 1, EPSILON, 3.402823466e+38F);
rtTrace(top_object, shadowRay, shadowPrd);
if (shadowPrd.inShadow)
{
shadow = 0.0f;
}
//...
}
__device__ void calculateSpotLightContribution(
uint lightIndex,
float3& ambient,
float4& diffuse,
float3& specular,
float& shininess,
float3& normal)
{
//... fetch spotlight from buffer, etc.
float3 surfaceToLight = spotLight.position-positionResult;
float3 VP = normalize(surfaceToLight);
float shadow = 1.0f;
float surfaceToLightDistance = length(surfaceToLight);
PerRayData_shadow shadowPrdPoint;
shadowPrdPoint.inShadow = false;
Ray shadowRay = make_Ray(positionResult, VP, 1, EPSILON, surfaceToLightDistance - EPSILON);
//TODO: Optix bug, if both point and spot shadow trace is enabled!
rtTrace(top_object, shadowRay, shadowPrdPoint);
if (shadowPrdPoint.inShadow)
{
shadow = 0.0f;
}
//...
}
__device__ void calculatePointLightContribution(
uint lightIndex,
float3& ambient,
float4& diffuse,
float3& specular,
float& shininess,
float3& normal)
{
//... Fetch point light from buffer, etc.
float3 surfaceToLight = pointLight.position-positionResult;
float3 VP = normalize(surfaceToLight);
float shadow = 1.0f;
float surfaceToLightDistance = length(surfaceToLight);
PerRayData_shadow shadowPrdPoint;
shadowPrdPoint.inShadow = false;
Ray shadowRay = make_Ray(positionResult, VP, 1, EPSILON, surfaceToLightDistance - EPSILON);
//TODO: Optix bug, if both point and spot shadow trace is enabled!
rtTrace(top_object, shadowRay, shadowPrdPoint);
if (shadowPrdPoint.inShadow)
{
shadow = 0.0f;
}
//...
}
RT_PROGRAM void collisionClosestHitProgram()
{
//...
//Material fetch here, not important.
//...
for (uint i = 0; i < lightCounts.x; ++i)
{
calculateDirectionalLightContribution(i, ambient, diffuse, specular, shininess, normal);
}
for (uint i = 0; i < lightCounts.y; ++i)
{
calculateSpotLightContribution(i, ambient, diffuse, specular, shininess, normal);
}
for (uint i = 0; i < lightCounts.z; ++i)
{
calculatePointLightContribution(i, ambient, diffuse, specular, shininess, normal);
}
//...
//Write results, not important.
//...
}
Is this known behaviour? Is there anything I can do about it?
Please let me know if you need more information. Thanks.
Best regards,
Attila Barsi