forked from prusa3d/PrusaSlicer
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Greatly improves brightness and contrast. Colours are now rendered accurately in 3D visualization. Employs three-point lighting principles: key light, back light, and fill light. We use multiple key and fill lights, not for visual aesthetics, but to improve illumination of scene for inspection when rotating objects.
- Loading branch information
Showing
6 changed files
with
351 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,78 @@ | ||
#version 110 | ||
|
||
#define INTENSITY_CORRECTION 0.6 | ||
// Two key lights | ||
const vec3 LIGHT_KEY_TOP_DIR = vec3(-1.0, 0.75, 1.0); | ||
const vec3 LIGHT_KEY_BOT_DIR = vec3(-1.0, -0.75, 1.0); | ||
#define LIGHT_KEY_DIFFUSE 0.16 | ||
#define LIGHT_KEY_SPECULAR 0.008 | ||
|
||
// normalized values for (-0.6/1.31, 0.6/1.31, 1./1.31) | ||
const vec3 LIGHT_TOP_DIR = vec3(-0.4574957, 0.4574957, 0.7624929); | ||
#define LIGHT_TOP_DIFFUSE (0.8 * INTENSITY_CORRECTION) | ||
#define LIGHT_TOP_SPECULAR (0.125 * INTENSITY_CORRECTION) | ||
#define LIGHT_TOP_SHININESS 20.0 | ||
// One back light | ||
const vec3 LIGHT_BACK_DIR = vec3(0.75, 0.5, -1.0); | ||
#define LIGHT_BACK_DIFFUSE 0.3 | ||
#define LIGHT_BACK_SPECULAR 0.015 | ||
|
||
// normalized values for (1./1.43, 0.2/1.43, 1./1.43) | ||
const vec3 LIGHT_FRONT_DIR = vec3(0.6985074, 0.1397015, 0.6985074); | ||
#define LIGHT_FRONT_DIFFUSE (0.3 * INTENSITY_CORRECTION) | ||
// Four fill lights | ||
const vec3 LIGHT_FILL_TOP_FRONT_DIR = vec3(1.0, 0.75, 1.0); | ||
const vec3 LIGHT_FILL_BOT_FRONT_DIR = vec3(1.0, -0.75, 1.0); | ||
const vec3 LIGHT_FILL_TOP_MIDDLE_DIR = vec3(0.0, 1.0, 0.8); | ||
const vec3 LIGHT_FILL_BOT_MIDDLE_DIR = vec3(0.0, -1.0, 0.8); | ||
const vec3 LIGHT_FILL_CENTER_FRONT_DIR = vec3(0.0, 0.0, 1.0); | ||
|
||
#define INTENSITY_AMBIENT 0.3 | ||
#define LIGHT_FILL_DIFFUSE 0.1 | ||
#define LIGHT_FILL_SPECULAR 0.004 | ||
|
||
// x = tainted, y = specular; | ||
#define LIGHT_SHININESS 7.0 | ||
#define INTENSITY_AMBIENT 0.3 | ||
|
||
// x = diffuse, y = specular | ||
varying vec2 intensity; | ||
|
||
void main() | ||
{ | ||
// First transform the normal into camera space and normalize the result. | ||
vec3 normal = normalize(gl_NormalMatrix * gl_Normal); | ||
vec3 position = (gl_ModelViewMatrix * gl_Vertex).xyz; | ||
|
||
// Compute the cos of the angle between the normal and lights direction. The light is directional so the direction is constant for every vertex. | ||
// Since these two are normalized the cosine is the dot product. We also need to clamp the result to the [0,1] range. | ||
float NdotL = max(dot(normal, LIGHT_TOP_DIR), 0.0); | ||
|
||
intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE; | ||
vec3 position = (gl_ModelViewMatrix * gl_Vertex).xyz; | ||
intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position), reflect(-LIGHT_TOP_DIR, normal)), 0.0), LIGHT_TOP_SHININESS); | ||
// Ambient light | ||
intensity.x = INTENSITY_AMBIENT; | ||
|
||
// Key lights | ||
float NdotL = max(dot(normal, LIGHT_KEY_TOP_DIR), 0.0); | ||
intensity.x += NdotL * LIGHT_KEY_DIFFUSE; | ||
intensity.y = LIGHT_KEY_SPECULAR * pow(max(dot(-normalize(position), reflect(-LIGHT_KEY_TOP_DIR, normal)), 0.0), LIGHT_SHININESS); | ||
|
||
NdotL = max(dot(normal, LIGHT_KEY_BOT_DIR), 0.0); | ||
intensity.x += NdotL * LIGHT_KEY_DIFFUSE; | ||
intensity.y += LIGHT_KEY_SPECULAR * pow(max(dot(-normalize(position), reflect(-LIGHT_KEY_BOT_DIR, normal)), 0.0), LIGHT_SHININESS); | ||
|
||
// Back light | ||
NdotL = max(dot(normal, LIGHT_BACK_DIR), 0.0); | ||
intensity.x += NdotL * LIGHT_BACK_DIFFUSE; | ||
intensity.y += LIGHT_BACK_SPECULAR * pow(max(dot(-normalize(position), reflect(-LIGHT_BACK_DIR, normal)), 0.0), LIGHT_SHININESS); | ||
|
||
// Fill lights | ||
NdotL = max(dot(normal, LIGHT_FILL_TOP_FRONT_DIR), 0.0); | ||
intensity.x += NdotL * LIGHT_FILL_DIFFUSE; | ||
intensity.y += LIGHT_FILL_SPECULAR * pow(max(dot(-normalize(position), reflect(-LIGHT_FILL_TOP_FRONT_DIR, normal)), 0.0), LIGHT_SHININESS); | ||
|
||
NdotL = max(dot(normal, LIGHT_FILL_BOT_FRONT_DIR), 0.0); | ||
intensity.x += NdotL * LIGHT_FILL_DIFFUSE; | ||
intensity.y += LIGHT_FILL_SPECULAR * pow(max(dot(-normalize(position), reflect(-LIGHT_FILL_BOT_FRONT_DIR, normal)), 0.0), LIGHT_SHININESS); | ||
|
||
NdotL = max(dot(normal, LIGHT_FILL_TOP_MIDDLE_DIR), 0.0); | ||
intensity.x += NdotL * LIGHT_FILL_DIFFUSE; | ||
intensity.y += LIGHT_FILL_SPECULAR * pow(max(dot(-normalize(position), reflect(-LIGHT_FILL_TOP_MIDDLE_DIR, normal)), 0.0), LIGHT_SHININESS); | ||
|
||
NdotL = max(dot(normal, LIGHT_FILL_BOT_MIDDLE_DIR), 0.0); | ||
intensity.x += NdotL * LIGHT_FILL_DIFFUSE; | ||
intensity.y += LIGHT_FILL_SPECULAR * pow(max(dot(-normalize(position), reflect(-LIGHT_FILL_BOT_MIDDLE_DIR, normal)), 0.0), LIGHT_SHININESS); | ||
|
||
// Perform the same lighting calculation for the 2nd light source (no specular applied). | ||
NdotL = max(dot(normal, LIGHT_FRONT_DIR), 0.0); | ||
intensity.x += NdotL * LIGHT_FRONT_DIFFUSE; | ||
NdotL = max(dot(normal, LIGHT_FILL_CENTER_FRONT_DIR), 0.0); | ||
intensity.x += NdotL * LIGHT_FILL_DIFFUSE; | ||
intensity.y += LIGHT_FILL_SPECULAR * pow(max(dot(-normalize(position), reflect(-LIGHT_FILL_CENTER_FRONT_DIR, normal)), 0.0), LIGHT_SHININESS); | ||
|
||
gl_Position = ftransform(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.