Skip to content

Commit

Permalink
Dev: Implemented Complete Lighting Model for test Hair Material
Browse files Browse the repository at this point in the history
  • Loading branch information
AEspinosaDev committed Nov 26, 2024
1 parent 2e3c5c7 commit e2b1e78
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
5 changes: 4 additions & 1 deletion include/engine/core/materials/hair_strand.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class HairStrandMaterial : public IMaterial
bool m_TT = true; // Transmitance
float m_TTpower = 1.0f;
bool m_TRT = true; // Second reflection
float m_TRTpower = 3.0f;
float m_TRTpower = 2.0f;

float m_roughness = 0.4f;
float m_scatter = 7.0f;
Expand Down Expand Up @@ -252,6 +252,8 @@ class HairStrandMaterial2 : public HairStrandMaterial
m_textures[N2] = new Texture(settings);
m_textures[GI] = new Texture(settings);
m_textures[MGI] = new Texture(settings);
m_textures[NGI] = new Texture(settings);
m_textures[NGI_TRT] = new Texture(settings);
Tools::Loaders::load_texture(
m_textures[N1], ENGINE_RESOURCES_PATH "textures/N_TT_R.png", TEXTURE_FORMAT_TYPE_NORMAL, false);
Tools::Loaders::load_texture(
Expand All @@ -271,6 +273,7 @@ class HairStrandMaterial2 : public HairStrandMaterial
m_textureBindingState[NGI] = false;
m_textureBindingState[NGI_TRT] = false;
m_isDirty = true;
m_useScatter = true;
}
};
} // namespace Core
Expand Down
34 changes: 21 additions & 13 deletions resources/shaders/forward/hair_strand2.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -177,20 +177,27 @@ vec3 computeAmbient(vec3 n) {
s, 0.0, c);
vec3 rotatedNormal = normalize(rotationY * n);

// ambient = evalMarschnerLookupBSDF(
// rotatedNormal,
// normalize(-g_pos),
// texture(irradianceMap, rotatedNormal).rgb*scene.ambientIntensity,
// bsdf,
// nTex1,
// nTex2,
// GITex,
// material.r,
// false, //Take oput transmitance
// material.trt);
ambient = evalMarschnerLookupBSDF(
rotatedNormal,
normalize(-g_pos),
texture(irradianceMap, rotatedNormal).rgb*scene.ambientIntensity,
bsdf,
nTex1,
nTex2,
GITex,
mGITex,
nGITex1,
nGITex2,
vec3(0.5),
vec3(0.5),
0.1,
material.r,
false,
material.trt,
material.useScatter);


ambient = (scene.ambientIntensity * scene.ambientColor) ;
// ambient = (scene.ambientIntensity * scene.ambientColor) ;
}else{
ambient = (scene.ambientIntensity * scene.ambientColor) ;
}
Expand Down Expand Up @@ -238,7 +245,8 @@ void main() {
directFraction,
material.r,
material.tt,
material.trt);
material.trt,
material.useScatter);

color += lighting;
}
Expand Down
23 changes: 22 additions & 1 deletion resources/shaders/scripts/BRDFs/marschner_LUT_BSDF.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ vec3 evalMarschnerLookupBSDF(
float directFraction,
bool r,
bool tt,
bool trt)
bool trt,
bool scatter)
{

//Theta
Expand Down Expand Up @@ -168,6 +169,7 @@ vec3 evalMarschnerLookupBSDF(

vec3 color = R+TT+TRT;

if(scatter){
//////////////////////////////////////////////////////////////////////////
// Local Scattering
//////////////////////////////////////////////////////////////////////////
Expand All @@ -187,9 +189,28 @@ vec3 evalMarschnerLookupBSDF(
// Global Scattering
//////////////////////////////////////////////////////////////////////////

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;

//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 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;
}
//////////////////////////////////////////////////////////////////////////

return color * irradiance * GLOBAL_SCALE;
Expand Down

0 comments on commit e2b1e78

Please sign in to comment.