Skip to content

Commit

Permalink
UPBGE: Fix for hard self shadowing
Browse files Browse the repository at this point in the history
Burley and lambert custom needed to be multiplied by nl

Code by @UnidayStudio
  • Loading branch information
lordloki committed May 13, 2020
1 parent 9eebbe0 commit 86841ea
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion source/blender/gpu/intern/gpu_material.c
Expand Up @@ -1055,7 +1055,7 @@ static void shade_one_light(GPUShadeInput *shi, GPUShadeResult *shr, GPULamp *la
GPU_link(mat, "shade_diffuse_fresnel", vn, lv, view,
GPU_uniform(&ma->param[0]), GPU_uniform(&ma->param[1]), &is);
else if (ma->diff_shader == MA_DIFF_LAMBERT_CUSTOM_BSDF)
GPU_link(mat, "shade_diffuse_BSDF_Custom_Lambert",
GPU_link(mat, "shade_diffuse_BSDF_Custom_Lambert", vn, lv,
shi->metallic_bsdf, &is);
else if (ma->diff_shader == MA_DIFF_BURLEY_BSDF)
GPU_link(mat, "shade_diffuse_BSDF_Burley", vn, lv, view,
Expand Down
7 changes: 4 additions & 3 deletions source/blender/gpu/shaders/gpu_shader_material.glsl
Expand Up @@ -2152,9 +2152,10 @@ void shade_diffuse_minnaert(float nl, vec3 n, vec3 v, float darkness, out float

// BSDF Burley diffuse shader from Urho3D https://github.com/urho3d/Urho3D (MIT License)

void shade_diffuse_BSDF_Custom_Lambert(float reflectance, out float is)
void shade_diffuse_BSDF_Custom_Lambert(vec3 n, vec3 l, float reflectance, out float is)
{
is = (reflectance / M_PI);
float nl = clamp(dot(n, l), 0.001, 1.0);
is = (reflectance / M_PI) * nl ;
}

void shade_diffuse_BSDF_Burley(vec3 n, vec3 l, vec3 v, float roughness, out float is)
Expand All @@ -2170,7 +2171,7 @@ void shade_diffuse_BSDF_Burley(vec3 n, vec3 l, vec3 v, float roughness, out floa
float light_scatter = f0 + (fd90 - f0) * pow(1.0 - nl, 5.0);
float view_scatter = f0 + (fd90 - f0) * pow(1.0 - nv, 5.0);

is = light_scatter * view_scatter * (1 / M_PI);
is = light_scatter * view_scatter * (1 / M_PI) * nl;
}


Expand Down

2 comments on commit 86841ea

@youle31
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ‘

@BluePrintRandom
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ‘
@UnidayStudio congrats !

Please sign in to comment.