Skip to content

Commit

Permalink
fix singularity
Browse files Browse the repository at this point in the history
  • Loading branch information
iaomw committed Jan 14, 2025
1 parent edab05b commit f41ebeb
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 18 deletions.
6 changes: 6 additions & 0 deletions zenovis/xinxinoptix/Host.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ static inline float __uint_as_float(uint32_t i) {
return bitConvert<uint32_t, float>(i);;
}

template<typename T>
inline T smoothstep(T l, T h, T v) {
auto t = clamp((v-l) / (h-l), 0.0f, 1.0f);
return t * t * (3.0f - 2.0f * t);
}

// #ifndef isnan
// static inline bool isnan(float v) {
// return std::isnan(v);
Expand Down
6 changes: 3 additions & 3 deletions zenovis/xinxinoptix/Light.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ static __inline__ __device__ void sampleSphereIES(LightSampleRecord& lsr, const
lsr.NoL = 1.0f;
lsr.PDF = 1.0f;

lsr.intensity = 1.0f / dist2;
lsr.intensity = PointIntensity(dist2, lsr.dist, 1.0f);
}

static __inline__ __device__ float light_spread_attenuation(
Expand Down Expand Up @@ -289,8 +289,8 @@ void DirectLighting(RadiancePRD *prd, ShadowPRD& shadowPRD, const float3& shadin

if (n_len <= 0) {return;}

lsr.dist = n_len * lsr.dist;
lsr.intensity = M_PIf/(lsr.dist * lsr.dist);
auto d = n_len * lsr.dist;
lsr.intensity = PointIntensity(d * d, d, 1.0f);

auto tanU = t_len / n_len;
auto tanV = b_len / n_len;
Expand Down
5 changes: 5 additions & 0 deletions zenovis/xinxinoptix/Sampling.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ inline float NextFloatDown(float v) {
return __uint_as_float(ui);
}

//http://www.cemyuksel.com/research/pointlightattenuation/
inline float PointIntensity(float d2, float d, float r2) {
return 2.0f / ( d * sqrtf(d2 + r2) + d2 + r2 );
}

// *Really* minimal PCG32 code / (c) 2014 M.E. O'Neill / pcg-random.org
// Licensed under Apache License 2.0 (NO WARRANTY, etc. see website)

Expand Down
9 changes: 4 additions & 5 deletions zenovis/xinxinoptix/Shape.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ struct TriangleShape {

struct PointShape {
float3 p;
float r;

inline float PDF() {return 0.25f / M_PIf;}

Expand All @@ -426,8 +427,9 @@ struct PointShape {

lsr->PDF = 1.0f; //PDF();
lsr->NoL = 1.0f;
lsr->intensity = M_PIf / dist2;
lsr->isDelta = true;

lsr->intensity = PointIntensity(dist2, dist, r * r);
}

pbrt::LightBounds BoundAsLight(float phi, bool doubleSided) {
Expand Down Expand Up @@ -796,11 +798,8 @@ struct ConeShape {
lsr->p = p;
lsr->PDF = 1.0f;

#ifdef __CUDACC_RTC__
lsr->intensity = smoothstep(cosFalloffEnd, cosFalloffStart, lsr->NoL);
#endif

lsr->intensity *= M_PIf / dist2;
lsr->intensity *= PointIntensity(dist2, dist, 1.0f);
}

inline float Phi() {
Expand Down
2 changes: 1 addition & 1 deletion zenovis/xinxinoptix/optixPathTracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2109,7 +2109,7 @@ void buildLightTree() {
}

} else if (light.shape == zeno::LightShape::Point) {
light.point = {center};
light.point = {center, radius};
if (dat.fluxFixed > 0) {
auto intensity = dat.fluxFixed / (4 * M_PIf);
light.intensity = intensity;
Expand Down
11 changes: 2 additions & 9 deletions zenovis/xinxinoptix/zxxglslvec.h
Original file line number Diff line number Diff line change
Expand Up @@ -885,15 +885,8 @@ __forceinline__ __device__ vec4 step(vec4 limit, vec4 a)

__forceinline__ __device__ float smoothstep(float a, float b, float c)
{
if(c>b)
{
return 1;
}
if(c>a)
{
return (c-a)/(b-a);
}
return 0;
auto t = clamp((c - a) / (b - a), 0.0f, 1.0f);
return t * t * (3.0f - 2.0f * t);
}
__forceinline__ __device__ vec2 smoothstep(vec2 a, vec2 b, vec2 c)
{
Expand Down

0 comments on commit f41ebeb

Please sign in to comment.