Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix far obj offset bug #1606

Merged
merged 7 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion projects/CUDA/utils/Tracing.cu
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ constexpr float int_scale() {
return 256.0f;
}
constexpr float float_scale() {
return 1.0f / 65536.0f;
return 1.0f / 32768.0f;
}

// Normal points outward for rays exiting the surface, else is flipped.
Expand Down
54 changes: 54 additions & 0 deletions zeno/src/nodes/StringNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,60 @@ ZENDEFNODE(StringRegexMatch, {
{"string"},
});


struct StringSplitAndMerge: zeno::INode{

std::vector<std::string> split(const std::string& s, std::string seperator)
{
std::vector<std::string> output;

std::string::size_type prev_pos = 0, pos = 0;

while((pos = s.find(seperator, pos)) != std::string::npos)
{
std::string substring( s.substr(prev_pos, pos-prev_pos) );

output.push_back(substring);

prev_pos = ++pos;
}

output.push_back(s.substr(prev_pos, pos-prev_pos)); // Last word

return output;
}
virtual void apply() override {
auto str = get_input2<std::string>("str");
auto schar = get_input2<std::string>("schar");
auto merge = get_input2<std::string>("merge");

auto &strings = split(str, schar);
auto &merges = split(merge, ",");
std::string outputstr = "";
for(auto idx:merges)
{
outputstr += strings[std::atoi(idx.c_str())];
}

set_output2("output", outputstr);
}
};

ZENDEFNODE(StringSplitAndMerge, {
{
{"string", "str", ""},
{"string", "schar", "_"},
{"string", "merge", "0"},
},
{
{"string", "output"}
},
{},
{"string"},
});



struct FormatString : zeno::INode {
virtual void apply() override {
auto formatStr = get_input2<std::string>("str");
Expand Down
2 changes: 1 addition & 1 deletion zenovis/include/zenovis/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct Camera {
float m_far = 20000.0f;
float m_fov = 45.f;

float m_aperture = 11.0f;
float m_aperture = 0.0f;
float focalPlaneDistance = 2.0f;
float m_dof = -1.f;
float m_safe_frames = 0;
Expand Down
14 changes: 10 additions & 4 deletions zenovis/xinxinoptix/DeflMatShader.cu
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ static __inline__ __device__ bool isBadVector(const float3& vector) {

extern "C" __global__ void __anyhit__shadow_cutout()
{

const OptixTraversableHandle gas = optixGetGASTraversableHandle();
const uint sbtGASIndex = optixGetSbtGASIndex();
const uint primIdx = optixGetPrimitiveIndex();
Expand All @@ -199,6 +200,7 @@ extern "C" __global__ void __anyhit__shadow_cutout()
RadiancePRD* prd = getPRD();
MatInput attrs{};


bool sphere_external_ray = false;

#if (_SPHERE_)
Expand Down Expand Up @@ -329,6 +331,7 @@ extern "C" __global__ void __anyhit__shadow_cutout()
auto sssParam = mats.sssParam;
auto scatterStep = mats.scatterStep;


if(params.simpleRender==true)
opacity = 0;
//opacity = clamp(opacity, 0.0f, 0.99f);
Expand Down Expand Up @@ -432,7 +435,7 @@ extern "C" __global__ void __closesthit__radiance()
const uint primIdx = optixGetPrimitiveIndex();

const float3 ray_orig = optixGetWorldRayOrigin();
const float3 ray_dir = optixGetWorldRayDirection();
const float3 ray_dir = normalize(optixGetWorldRayDirection());
float3 P = ray_orig + optixGetRayTmax() * ray_dir;

HitGroupData* rt_data = (HitGroupData*)optixGetSbtDataPointer();
Expand Down Expand Up @@ -488,14 +491,14 @@ extern "C" __global__ void __closesthit__radiance()
auto P_Local = interp(barys, v0, v1, v2);
P = optixTransformPointFromObjectToWorldSpace(P_Local); // this value has precision issue for big float

attrs.pos = P;
attrs.pos = P + prd->camPos;

float3 N_Local = normalize( cross( normalize(v1-v0), normalize(v2-v1) ) ); // this value has precision issue for big float
float3 N_World = optixTransformNormalFromObjectToWorldSpace(N_Local);
float3 N_World = normalize(optixTransformNormalFromObjectToWorldSpace(N_Local));

if (isBadVector(N_World))
{
N_World = DisneyBSDF::SampleScatterDirection(prd->seed);
N_World = normalize(DisneyBSDF::SampleScatterDirection(prd->seed));
N_World = faceforward( N_World, -ray_dir, N_World );
}
prd->geometryNormal = N_World;
Expand Down Expand Up @@ -650,6 +653,7 @@ extern "C" __global__ void __closesthit__radiance()
prd->passed = false;
if(mats.opacity>0.99f)
{

if (prd->curMatIdx > 0) {
vec3 sigma_t, ss_alpha;
//vec3 sigma_t, ss_alpha;
Expand All @@ -662,6 +666,7 @@ extern "C" __global__ void __closesthit__radiance()
}
prd->attenuation2 = prd->attenuation;
prd->passed = true;
prd->adepth++;
//prd->samplePdf = 0.0f;
prd->radiance = make_float3(0.0f);
//prd->origin = P + 1e-5 * ray_dir;
Expand All @@ -686,6 +691,7 @@ extern "C" __global__ void __closesthit__radiance()
}
prd->attenuation2 = prd->attenuation;
prd->passed = true;
prd->adepth++;
//prd->samplePdf = 0.0f;
//you shall pass!
prd->radiance = make_float3(0.0f);
Expand Down
16 changes: 8 additions & 8 deletions zenovis/xinxinoptix/DisneyBSDF.h
Original file line number Diff line number Diff line change
Expand Up @@ -671,10 +671,10 @@ namespace DisneyBSDF{
tbn.inverse_transform(wi);
wi = normalize(wi);

// if(dot(wi, N2)<0)
// {
// wi = normalize(wi - 1.01f * dot(wi, N2) * N2);
// }
if(dot(wi, N2)<0)
{
wi = normalize(wi - 1.01f * dot(wi, N2) * N2);
}
}else if(r3<p4)//glass
{

Expand Down Expand Up @@ -725,10 +725,10 @@ namespace DisneyBSDF{
wi = normalize(reflect(-wo, wm));
tbn.inverse_transform(wi);
wi = normalize(wi);
// if(dot(wi, N2)<0)
// {
// wi = normalize(wi - 1.01f * dot(wi, N2) * N2);
// }
if(dot(wi, N2)<0)
{
wi = normalize(wi - 1.01f * dot(wi, N2) * N2);
}
}
tbn.inverse_transform(wo);
float pdf, pdf2;
Expand Down
4 changes: 2 additions & 2 deletions zenovis/xinxinoptix/Light.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ void DirectLighting(RadiancePRD *prd, RadiancePRD& shadow_prd, const float3& sha
}

if (lsr.NoL > _FLT_EPL_ && lsr.PDF > _FLT_EPL_) {

shadow_prd.depth = 0;
traceOcclusion(params.handle, shadingP, lsr.dir, 0, lsr.dist, &shadow_prd);
light_attenuation = shadow_prd.shadowAttanuation;

Expand Down Expand Up @@ -460,7 +460,7 @@ void DirectLighting(RadiancePRD *prd, RadiancePRD& shadow_prd, const float3& sha
if (envpdf < __FLT_DENORM_MIN__) {
return;
}

shadow_prd.depth = 0;
//LP = rtgems::offset_ray(LP, sun_dir);
traceOcclusion(params.handle, LP, sun_dir,
1e-5f, // tmin
Expand Down
6 changes: 4 additions & 2 deletions zenovis/xinxinoptix/PTKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,13 @@ extern "C" __global__ void __raygen__rg()
terminal_point = camera_transform * terminal_point;
eye_shake = camera_transform * eye_shake;

float3 ray_origin = cam.eye + eye_shake;
float3 ray_origin = eye_shake;
float3 ray_direction = terminal_point - eye_shake;
ray_direction = normalize(ray_direction);

RadiancePRD prd;
prd.adepth = 0;
prd.camPos = cam.eye;
prd.emission = make_float3(0.f);
prd.radiance = make_float3(0.f);
prd.attenuation = make_float3(1.f);
Expand Down Expand Up @@ -245,7 +247,7 @@ extern "C" __global__ void __raygen__rg()
prd.done = true;
}

if( prd.done || params.simpleRender==true){
if( prd.done || params.simpleRender==true || prd.adepth>64){
break;
}

Expand Down
7 changes: 6 additions & 1 deletion zenovis/xinxinoptix/TraceStuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ struct RadiancePRD
float3 attenuation2;
float3 origin;
float3 direction;
float3 camPos;
float minSpecRough;
bool passed;
float prob;
Expand All @@ -81,6 +82,7 @@ struct RadiancePRD
int curMatIdx;
float samplePdf;
bool fromDiff;
unsigned char adepth;

__forceinline__ float rndf() {
return rnd(this->seed);
Expand Down Expand Up @@ -123,7 +125,10 @@ struct RadiancePRD

void offsetRay(float3& P, const float3& new_dir) {
bool forward = dot(geometryNormal, new_dir) > 0;
P = rtgems::offset_ray(P, forward? geometryNormal:-geometryNormal);
auto dir = forward? geometryNormal:-geometryNormal;
auto offset = rtgems::offset_ray(P, dir);
float l = length( offset - P );
P = l>1e-4? offset : (P + 1e-4 * dir);
}

void offsetUpdateRay(float3& P, float3 new_dir) {
Expand Down
Loading
Loading