mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-08-03 16:58:24 +02:00
[ui] Viewer3D: introduce SphericalHarmonics shader + display mode
Add experimental render mode to display model normals or shading based on spherical harmonics coefficients
This commit is contained in:
parent
9aa059a565
commit
3ae95869bd
7 changed files with 194 additions and 1 deletions
|
@ -0,0 +1,34 @@
|
|||
#version 330 core
|
||||
|
||||
in vec3 normal;
|
||||
out vec4 fragColor;
|
||||
|
||||
uniform vec3 shCoeffs[9];
|
||||
uniform bool displayNormals = false;
|
||||
|
||||
vec3 resolveSH_Opt(vec3 premulCoefficients[9], vec3 dir)
|
||||
{
|
||||
vec3 result = premulCoefficients[0] * dir.x;
|
||||
result += premulCoefficients[1] * dir.y;
|
||||
result += premulCoefficients[2] * dir.z;
|
||||
result += premulCoefficients[3];
|
||||
vec3 dirSq = dir * dir;
|
||||
result += premulCoefficients[4] * (dir.x * dir.y);
|
||||
result += premulCoefficients[5] * (dir.x * dir.z);
|
||||
result += premulCoefficients[6] * (dir.y * dir.z);
|
||||
result += premulCoefficients[7] * (dirSq.x - dirSq.y);
|
||||
result += premulCoefficients[8] * (3 * dirSq.z - 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
if(displayNormals) {
|
||||
// Display normals mode
|
||||
fragColor = vec4(normal, 1.0);
|
||||
}
|
||||
else {
|
||||
// Calculate the color from spherical harmonics coeffs
|
||||
fragColor = vec4(resolveSH_Opt(shCoeffs, normal), 1.0);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
#version 330 core
|
||||
|
||||
in vec3 vertexPosition;
|
||||
in vec3 vertexNormal;
|
||||
|
||||
out vec3 normal;
|
||||
|
||||
uniform mat4 modelView;
|
||||
uniform mat3 modelViewNormal;
|
||||
uniform mat4 mvp;
|
||||
|
||||
void main()
|
||||
{
|
||||
normal = vertexNormal;
|
||||
gl_Position = mvp * vec4( vertexPosition, 1.0 );
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue