Skip to content

Commit

Permalink
-Change: Change in hair shader and material
Browse files Browse the repository at this point in the history
  • Loading branch information
AEspinosaDev committed Dec 19, 2024
1 parent 0200837 commit e6e171a
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 63 deletions.
1 change: 1 addition & 0 deletions include/engine/core/materials/hair_strand.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ class HairStrandMaterial2 : public HairStrandMaterial
public:
HairStrandMaterial2(HairPigmentType pigment = BLONDE)
: HairStrandMaterial(Vec4(0.0), {}, "hairstr2") {
m_coloredScatter = true;
TextureSettings settings{};
settings.useMipmaps = false;
settings.adressMode = ADDRESS_MODE_CLAMP_TO_EDGE;
Expand Down
34 changes: 15 additions & 19 deletions resources/shaders/forward/hair_strand2.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ layout(set = 1, binding = 1) uniform MaterialUniforms {
float density;

bool glints;
bool useScatter;
bool coloredScatter;
bool localScatter;
bool globalScatter;
bool r;

bool tt;
Expand Down Expand Up @@ -176,7 +176,7 @@ vec3 computeAmbient(vec3 n) {
0.0, 1.0, 0.0,
s, 0.0, c);
vec3 rotatedNormal = normalize(rotationY * n);

bsdf.tt = false;
ambient = evalMarschnerLookupBSDF(
rotatedNormal,
normalize(-g_pos),
Expand All @@ -190,12 +190,7 @@ vec3 computeAmbient(vec3 n) {
nGITex2,
vec3(0.5),
vec3(0.5),
0.1,
material.r,
false,
material.trt,
material.useScatter);

0.1);

// ambient = (scene.ambientIntensity * scene.ambientColor) ;
}else{
Expand All @@ -207,11 +202,16 @@ vec3 computeAmbient(vec3 n) {
void main() {

//BSDF setup ............................................................
bsdf.tangent = normalize(g_dir);
bsdf.Rpower = material.Rpower;
bsdf.TTpower = material.TTpower;
bsdf.TRTpower = material.TRTpower;
bsdf.density = material.density;
bsdf.tangent = normalize(g_dir);
bsdf.Rpower = material.Rpower;
bsdf.TTpower = material.TTpower;
bsdf.TRTpower = material.TRTpower;
bsdf.density = material.density;
bsdf.r = material.r;
bsdf.tt = material.tt;
bsdf.trt = material.trt;
bsdf.localScatter = material.localScatter;
bsdf.globalScatter = material.globalScatter;


//DIRECT LIGHTING .......................................................
Expand Down Expand Up @@ -242,11 +242,7 @@ void main() {
nGITex2,
shadow,
spread,
directFraction,
material.r,
material.tt,
material.trt,
material.useScatter);
directFraction);

color += lighting;
}
Expand Down
76 changes: 41 additions & 35 deletions resources/shaders/scripts/BRDFs/marschner_LUT_BSDF.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ struct MarschnerLookupBSDF{
float TTpower;
float TRTpower;
float density;
//Options
bool r;
bool tt;
bool trt;
bool localScatter;
bool globalScatter;
};

//Longitudinal TERM (Gaussian Distribution)
Expand Down Expand Up @@ -102,23 +108,21 @@ vec3 computeHairShadow(LightUniform light,int lightId, sampler2DArray shadowMap,


vec3 evalMarschnerLookupBSDF(
vec3 wi, //Light vector
vec3 v, //View vector
vec3 irradiance,
vec3 wi, //Light vector
vec3 v, //View vector
vec3 irradiance, //Li
MarschnerLookupBSDF bsdf,
//LUTs
sampler2D texN,
sampler2D texNTRT,
sampler3D texGI,
sampler2D texGI_M,
sampler2D texGI_N,
sampler2D texGI_NTRT,
//Factors
vec3 transDirect,
vec3 spread,
float directFraction,
bool r,
bool tt,
bool trt,
bool scatter)
float directFraction)
{

//Theta
Expand Down Expand Up @@ -163,53 +167,55 @@ vec3 evalMarschnerLookupBSDF(
float MTT = M(thH - TT_SHIFT ,TT_DEV);
float MTRT = M(thH - TRT_SHIFT ,TRT_DEV);

float R = r ? MR * NR * bsdf.Rpower : 0.0;
vec3 TT = tt ? MTT * NTT * bsdf.TTpower : vec3(0.0);
vec3 TRT = trt ? MTRT * NTRT * bsdf.TRTpower: vec3(0.0);
float R = bsdf.r ? MR * NR * bsdf.Rpower : 0.0;
vec3 TT = bsdf.tt ? MTT * NTT * bsdf.TTpower : vec3(0.0);
vec3 TRT = bsdf.trt ? MTRT * NTRT * bsdf.TRTpower: vec3(0.0);

vec3 color = R+TT+TRT;

if(scatter){
//////////////////////////////////////////////////////////////////////////
// Local Scattering
//////////////////////////////////////////////////////////////////////////

vec3 gi = vec3(0.0);
float ix_thH = thH * ONE_OVER_PI * 0.5 + 0.5;
vec3 ix_spread = sqrt(spread) * ONE_OVER_PI* 0.5;

vec3 gi;
gi.r = DENSITY * texture( texGI, vec3( ix_spread.r, 1-ix_thH, ix_th ) ).r;
gi.g = DENSITY * texture( texGI, vec3( ix_spread.g, 1-ix_thH, ix_th ) ).g;
gi.b = DENSITY * texture( texGI, vec3( ix_spread.b, 1-ix_thH, ix_th ) ).b;
if(bsdf.localScatter){


color += gi;
color *= directFraction;
gi.r = DENSITY * texture( texGI, vec3( ix_spread.r, 1-ix_thH, ix_th ) ).r;
gi.g = DENSITY * texture( texGI, vec3( ix_spread.g, 1-ix_thH, ix_th ) ).g;
gi.b = DENSITY * texture( texGI, vec3( ix_spread.b, 1-ix_thH, ix_th ) ).b;

color += gi;
color *= directFraction;

}
//////////////////////////////////////////////////////////////////////////
// Global Scattering
//////////////////////////////////////////////////////////////////////////
if(bsdf.globalScatter){

vec3 trans = transDirect - directFraction;
vec3 trans = transDirect - directFraction;

//N
vec4 N_GI = texture(texGI_N, index1 );
float NR_GI = N_GI.a;
vec3 NTT_GI = N_GI.rgb;
vec3 NTRT_GI = texture(texGI_NTRT, index2 ).rgb;
//N
vec4 N_GI = texture(texGI_N, index1 );
float NR_GI = N_GI.a;
vec3 NTT_GI = N_GI.rgb;
vec3 NTRT_GI = texture(texGI_NTRT, index2 ).rgb;

//M
vec3 M_GIr = texture(texGI_M, vec2(ix_spread.r, 1-ix_thH) ).xyz;
vec3 M_GIg = texture(texGI_M, vec2(ix_spread.g, 1-ix_thH) ).xyz;
vec3 M_GIb = texture(texGI_M, vec2(ix_spread.b, 1-ix_thH) ).xyz;
//M
vec3 M_GIr = texture(texGI_M, vec2(ix_spread.r, 1-ix_thH) ).xyz;
vec3 M_GIg = texture(texGI_M, vec2(ix_spread.g, 1-ix_thH) ).xyz;
vec3 M_GIb = texture(texGI_M, vec2(ix_spread.b, 1-ix_thH) ).xyz;

vec3 MR_GI = vec3( M_GIr.x, M_GIg.x, M_GIb.x );
vec3 MTT_GI = vec3( M_GIr.y, M_GIg.y, M_GIb.y );
vec3 MTRT_GI = vec3( M_GIr.z, M_GIg.z, M_GIb.z );
vec3 MR_GI = vec3( M_GIr.x, M_GIg.x, M_GIb.x );
vec3 MTT_GI = vec3( M_GIr.y, M_GIg.y, M_GIb.y );
vec3 MTRT_GI = vec3( M_GIr.z, M_GIg.z, M_GIb.z );

vec3 f_indir = trans * DENSITY * ( gi + MR_GI*NR_GI + MTT_GI*NTT_GI + MTRT_GI*NTRT_GI ); // N components already divided by PI
color += f_indir;
vec3 f_indir = trans * DENSITY * ( gi + MR_GI*NR_GI + MTT_GI*NTT_GI + MTRT_GI*NTRT_GI ); // N components already divided by PI
color += f_indir;

// color += gi * 0.1;
}
//////////////////////////////////////////////////////////////////////////

Expand Down
16 changes: 7 additions & 9 deletions src/tools/widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,24 +723,22 @@ void ObjectExplorerWidget::render() {
mat->set_ior(ior); // Update index of refraction
}

bool glints = mat->get_glints();
if (ImGui::Checkbox("Glints", &glints))
{
mat->set_glints(glints); // Update glints
}

bool useScatter = mat->get_useScatter();
if (ImGui::Checkbox("Use Scatter", &useScatter))
if (ImGui::Checkbox("Local Scatter", &useScatter))
{
mat->set_useScatter(useScatter); // Update use scatter
}

bool coloredScatter = mat->get_coloredScatter();
if (ImGui::Checkbox("Colored Scatter", &coloredScatter))
if (ImGui::Checkbox("Global Scatter", &coloredScatter))
{
mat->set_coloredScatter(coloredScatter); // Update colored scatter
}

bool glints = mat->get_glints();
if (ImGui::Checkbox("Glints", &glints))
{
mat->set_glints(glints); // Update glints
}
bool occlusion = mat->get_occlusion();
if (ImGui::Checkbox("Occlusion", &occlusion))
{
Expand Down

0 comments on commit e6e171a

Please sign in to comment.