Skip to content

Commit

Permalink
final resolve sss small bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
zhxx1987 committed Dec 12, 2023
1 parent 4761535 commit 1abe301
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 26 deletions.
10 changes: 5 additions & 5 deletions zenovis/xinxinoptix/DeflMatShader.cu
Original file line number Diff line number Diff line change
Expand Up @@ -482,18 +482,18 @@ extern "C" __global__ void __closesthit__radiance()
float3 _vertices_[3];
optixGetTriangleVertexData( gas, primIdx, sbtGASIndex, 0, _vertices_);

const float3& v0 = _vertices_[0];
const float3& v1 = _vertices_[1];
const float3& v2 = _vertices_[2];
const float3& v0 = optixTransformPointFromObjectToWorldSpace(_vertices_[0]);
const float3& v1 = optixTransformPointFromObjectToWorldSpace(_vertices_[1]);
const float3& v2 = optixTransformPointFromObjectToWorldSpace(_vertices_[2]);

/* MODMA */
float2 barys = optixGetTriangleBarycentrics();
auto P_Local = interp(barys, v0, v1, v2);
P = optixTransformPointFromObjectToWorldSpace(P_Local); // this value has precision issue for big float
P = P_Local; // this value has precision issue for big float

attrs.pos = P;

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

if (isBadVector(N_World))
Expand Down
33 changes: 17 additions & 16 deletions zenovis/xinxinoptix/DisneyBSDF.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ namespace DisneyBSDF{
}
if((sssPr>0.0&&reflectance) || (sssPr>0.0 && dot(wo, N2)<0.0))
{
bool trans = dot(wo, N2) * dot(wi, N2)<0;
bool trans = (dot(wi, N2) * dot(wo, N2)<0) && (wi.z * wo.z<0);
float FL = BRDFBasics::SchlickWeight(abs(wi.z));
float FV = BRDFBasics::SchlickWeight(abs(wo.z));
float term = wo.z>0?FV:FL;
Expand Down Expand Up @@ -629,21 +629,8 @@ namespace DisneyBSDF{

//go inside
wi = -BRDFBasics::UniformSampleHemisphere(r1, r2);

}
}

tbn.inverse_transform(wi);
wi = normalize(wi);

bool sameside2 = (dot(wi, N) * dot(wi, N2)) > 0.0f;
if (sameside == false) {
wi = normalize(wi - 1.01f * dot(wi, N2) * N2);
}
auto woo = wo;
tbn.inverse_transform(woo);
if(dot(wi, N2) * dot(woo, N2)<0 && dot(wi, N2)<0) {

wi.z = min(-0.2f, wi.z);
wi = normalize(wi);
isSS = true;
flag = transmissionEvent;
vec3 color = mix(mat.basecolor, mat.sssColor, mat.subsurface);
Expand All @@ -656,6 +643,20 @@ namespace DisneyBSDF{
CalculateExtinction2(color, sssRadius, prd->sigma_t,
prd->ss_alpha, 1.4f);
}

}
}

tbn.inverse_transform(wi);
wi = normalize(wi);

bool sameside2 = (dot(wi, N) * dot(wi, N2)) > 0.0f;
if (sameside == false) {
wi = normalize(wi - 1.01f * dot(wi, N2) * N2);
}
if(dot(wi, N2)>0)
{
isSS = false;
}
//reflectance = vec3(1.0f) * M_PIf ;
//return true;
Expand Down
6 changes: 3 additions & 3 deletions zenovis/xinxinoptix/Sampling.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ inline Vector3f GramSchmidt(Vector3f v, Vector3f w) {

namespace rtgems {

constexpr float origin() { return 1.0f / 16.0f; }
constexpr float int_scale() { return 3.0f * 256.0f; }
constexpr float float_scale() { return 3.0f / 65536.0f; }
constexpr float origin() { return 1.0f / 32.0f; }
constexpr float int_scale() { return 1.0f * 256.0f; }
constexpr float float_scale() { return 1.0f / 65536.0f; }

// Normal points outward for rays exiting the surface, else is flipped.
static __inline__ __device__ float3 offset_ray(const float3 p, const float3 n)
Expand Down
10 changes: 8 additions & 2 deletions zenovis/xinxinoptix/TraceStuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,17 @@ struct RadiancePRD
}

void offsetUpdateRay(float3& P, float3 new_dir) {
auto beforeOffset = P - this->camPos;
double x = (double)(P.x) - (double)(this->camPos.x);
double y = (double)(P.y) - (double)(this->camPos.y);
double z = (double)(P.z) - (double)(this->camPos.z);
auto beforeOffset = make_float3(x, y, z);
//this->origin = P;
this->direction = new_dir;
offsetRay(beforeOffset, new_dir);
this->origin = beforeOffset + this->camPos;
double x2 = (double)(beforeOffset.x) + (double)(this->camPos.x);
double y2 = (double)(beforeOffset.y) + (double)(this->camPos.y);
double z2 = (double)(beforeOffset.z) + (double)(this->camPos.z);
this->origin = make_float3(x2, y2, z2);
}

uint8_t _mask_ = EverythingMask;
Expand Down

0 comments on commit 1abe301

Please sign in to comment.