diff --git a/zenovis/xinxinoptix/DeflMatShader.cu b/zenovis/xinxinoptix/DeflMatShader.cu index f1b91025c7..39662f612a 100644 --- a/zenovis/xinxinoptix/DeflMatShader.cu +++ b/zenovis/xinxinoptix/DeflMatShader.cu @@ -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)) diff --git a/zenovis/xinxinoptix/DisneyBSDF.h b/zenovis/xinxinoptix/DisneyBSDF.h index a23d1e0d76..f93fec323a 100644 --- a/zenovis/xinxinoptix/DisneyBSDF.h +++ b/zenovis/xinxinoptix/DisneyBSDF.h @@ -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; @@ -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); @@ -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; diff --git a/zenovis/xinxinoptix/Sampling.h b/zenovis/xinxinoptix/Sampling.h index f186bea0f6..2a76f7a28d 100644 --- a/zenovis/xinxinoptix/Sampling.h +++ b/zenovis/xinxinoptix/Sampling.h @@ -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) diff --git a/zenovis/xinxinoptix/TraceStuff.h b/zenovis/xinxinoptix/TraceStuff.h index e29f3068a6..c8306a1454 100644 --- a/zenovis/xinxinoptix/TraceStuff.h +++ b/zenovis/xinxinoptix/TraceStuff.h @@ -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;