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

data compression, normal conversion bug fix #1647

Merged
merged 1 commit into from
Dec 18, 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 zeno/src/nodes/mtl/ShaderAttrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct ShaderInputAttr : ShaderNodeClone<ShaderInputAttr> {

ZENDEFNODE(ShaderInputAttr, {
{
{"enum pos clr nrm uv tang bitang NoL LoV N T L V H reflectance fresnel instPos instNrm instUv instClr instTang prd.rndf() attrs.localPosLazy() attrs.uniformPosLazy()", "attr", "pos"},
{"enum pos clr nrm uv tang bitang NoL LoV N T L V H reflectance fresnel instPos instNrm instUv instClr instTang prd.rndf() attrs.localPosLazy() attrs.uniformPosLazy() rayLength", "attr", "pos"},
{"enum float vec2 vec3 vec4", "type", "vec3"},
},
{
Expand Down
17 changes: 13 additions & 4 deletions zenovis/xinxinoptix/DeflMatShader.cu
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ static __inline__ __device__ MatOutput evalMat(cudaTextureObject_t zenotex[], fl
auto att_instUv = attrs.instUv;
auto att_instClr = attrs.instClr;
auto att_instTang = attrs.instTang;
auto att_rayLength = attrs.rayLength;
auto att_NoL = attrs.NoL;
auto att_LoV = attrs.LoV;
auto att_N = attrs.N;
Expand Down Expand Up @@ -287,6 +288,7 @@ extern "C" __global__ void __anyhit__shadow_cutout()
attrs.clr = interp(barys, clr0, clr1, clr2);
attrs.tang = interp(barys, tan0, tan1, tan2);
attrs.tang = optixTransformVectorFromObjectToWorldSpace(attrs.tang);
attrs.rayLength = optixGetRayTmax();

attrs.instPos = rt_data->instPos[inst_idx];
attrs.instNrm = rt_data->instNrm[inst_idx];
Expand Down Expand Up @@ -440,7 +442,7 @@ extern "C" __global__ void __closesthit__radiance()

HitGroupData* rt_data = (HitGroupData*)optixGetSbtDataPointer();
MatInput attrs{};

float estimation = 0;
#if (_SPHERE_)

unsigned short isLight = 0;
Expand Down Expand Up @@ -496,6 +498,7 @@ extern "C" __global__ void __closesthit__radiance()
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))
{
N_World = normalize(DisneyBSDF::SampleScatterDirection(prd->seed));
Expand All @@ -515,8 +518,10 @@ extern "C" __global__ void __closesthit__radiance()
const float3& tan0 = decodeNormal( rt_data->tan[ vert_idx_offset+0 ] );
const float3& tan1 = decodeNormal( rt_data->tan[ vert_idx_offset+1 ] );
const float3& tan2 = decodeNormal( rt_data->tan[ vert_idx_offset+2 ] );

attrs.uv = interp(barys, uv0, uv1, uv2);//todo later
float tri_area = length(cross(_vertices_[1]-_vertices_[0], _vertices_[2]-_vertices_[1]));
float uv_area = length(cross(uv1 - uv0, uv2-uv0));
estimation = uv_area * 4096.0f*4096.0f / (tri_area + 1e-6);
attrs.uv = interp(barys, uv0, uv1, uv2);//todo later
attrs.clr = interp(barys, clr0, clr1, clr2);
attrs.tang = normalize(interp(barys, tan0, tan1, tan2));
attrs.tang = optixTransformVectorFromObjectToWorldSpace(attrs.tang);
Expand All @@ -526,7 +531,7 @@ extern "C" __global__ void __closesthit__radiance()
attrs.instUv = rt_data->instUv[inst_idx];
attrs.instClr = rt_data->instClr[inst_idx];
attrs.instTang = rt_data->instTang[inst_idx];

attrs.rayLength = optixGetRayTmax();
#endif

MatOutput mats = evalMaterial(rt_data->textures, rt_data->uniforms, attrs);
Expand Down Expand Up @@ -561,6 +566,10 @@ extern "C" __global__ void __closesthit__radiance()
#endif

attrs.nrm = N;
float term = log2(optixGetRayTmax()*prd->pixel_area*sqrt(estimation))/2.5f;
// printf("rayDist:%f, tex_per_area:%f, term:%f, pixel_area:%f\n", optixGetRayTmax(),
// sqrt(estimation), term, prd->pixel_area);
mats.nrm = normalize(mix(mats.nrm, vec3(0,0,1), clamp(term,0.0f,1.0f)));
//end of material computation
//mats.metallic = clamp(mats.metallic,0.01, 0.99);
mats.roughness = clamp(mats.roughness, 0.01f,0.99f);
Expand Down
32 changes: 24 additions & 8 deletions zenovis/xinxinoptix/DisneyBSDF.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ namespace DisneyBSDF{
world2local(wo, T, B, N);
world2local(N2, T, B, N);

bool reflect = wi.z * wo.z > 0.0f;
bool reflect = (dot(wi, N2) * dot(wo, N2) > 0.0f) ;

vec3 Csheen, Cspec0;
float F0;
Expand Down Expand Up @@ -345,7 +345,7 @@ namespace DisneyBSDF{
float ax, ay;
BRDFBasics::CalculateAnisotropicParams(mat.roughness,mat.anisotropic,ax,ay);
vec3 s = BRDFBasics::EvalMicrofacetReflection(ax, ay, wo, wi, wm,
mix(Cspec0, vec3(1.0f), F) * mat.specular * 0.5f, tmpPdf) * dielectricWt * illum;
mix(Cspec0, vec3(1.0f), F) * mat.specular, tmpPdf) * dielectricWt * illum;
sterm = sterm + s;
f = f + s;
fPdf += tmpPdf * dielectricPr;
Expand Down Expand Up @@ -615,6 +615,13 @@ namespace DisneyBSDF{
wi = BRDFBasics::UniformSampleHemisphere(r1, r2);
flag = transmissionEvent;
isSS = false;
tbn.inverse_transform(wi);
wi = normalize(wi);

if(dot(wi, N2)<0)
{
wi = normalize(wi - 1.01f * dot(wi, N2) * N2);
}
}
else{
//switch between scattering or diffuse reflection
Expand All @@ -624,6 +631,14 @@ namespace DisneyBSDF{
prd->fromDiff = true;
wi = BRDFBasics::CosineSampleHemisphere(r1, r2);
isSS = false;
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);
}
}else
{

Expand All @@ -643,17 +658,18 @@ 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);
}

}
}

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;
Expand Down
1 change: 1 addition & 0 deletions zenovis/xinxinoptix/IOMat.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct MatInput {
vec3 instTang;
float NoL;
float LoV;
float rayLength;
vec3 reflectance;
vec3 N;
vec3 T;
Expand Down
1 change: 1 addition & 0 deletions zenovis/xinxinoptix/PTKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ extern "C" __global__ void __raygen__rg()
ray_direction = normalize(ray_direction);

RadiancePRD prd;
prd.pixel_area = cam.height/(float)(h)/(cam.focal_length);
prd.adepth = 0;
prd.camPos = cam.eye;
prd.emission = make_float3(0.f);
Expand Down
2 changes: 1 addition & 1 deletion zenovis/xinxinoptix/TraceStuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct RadiancePRD
bool isSS;
float scatterStep;
int nonThinTransHit;

float pixel_area;
float Lweight;
vec3 sigma_t_queue[8];
vec3 ss_alpha_queue[8];
Expand Down
2 changes: 1 addition & 1 deletion zenovis/xinxinoptix/optixPathTracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ ushort2 halfNormal(float4 in)
float3 val = make_float3((in.x + 1.0f)/2.0f,
(in.y + 1.0f)/2.0f,
(in.z + 1.0f)/2.0f);
val = normalize(val);
//val = normalize(val);

return make_ushort3((unsigned short)(val.x*65536.0f),
(unsigned short)(val.y*65536.0f),
Expand Down
Loading