GCodeViewer -> Newer version of shader for options
This commit is contained in:
parent
aa04f0e555
commit
35190936a3
13 changed files with 187 additions and 98 deletions
|
@ -5,7 +5,7 @@ uniform vec3 uniform_color;
|
|||
uniform float percent_outline_radius;
|
||||
uniform float percent_center_radius;
|
||||
|
||||
vec4 hard_color(float sq_radius)
|
||||
vec4 hardcoded_color(float sq_radius)
|
||||
{
|
||||
if ((sq_radius < 0.005625) || (sq_radius > 0.180625))
|
||||
return vec4(0.5 * uniform_color, 1.0);
|
||||
|
@ -13,7 +13,7 @@ vec4 hard_color(float sq_radius)
|
|||
return vec4(uniform_color, 1.0);
|
||||
}
|
||||
|
||||
vec4 custom_color(float sq_radius)
|
||||
vec4 customizable_color(float sq_radius)
|
||||
{
|
||||
float in_radius = 0.5 * percent_center_radius;
|
||||
float out_radius = 0.5 * (1.0 - percent_outline_radius);
|
||||
|
@ -30,5 +30,6 @@ void main()
|
|||
if (sq_radius > 0.25)
|
||||
discard;
|
||||
|
||||
gl_FragColor = custom_color(sq_radius);
|
||||
gl_FragColor = customizable_color(sq_radius);
|
||||
// gl_FragColor = hardcoded_color(sq_radius);
|
||||
}
|
88
resources/shaders/options_120_solid.fs
Normal file
88
resources/shaders/options_120_solid.fs
Normal file
|
@ -0,0 +1,88 @@
|
|||
// version 120 is needed for gl_PointCoord
|
||||
#version 120
|
||||
|
||||
#define INTENSITY_CORRECTION 0.6
|
||||
|
||||
// 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
|
||||
|
||||
// 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)
|
||||
|
||||
#define INTENSITY_AMBIENT 0.3
|
||||
|
||||
uniform vec3 uniform_color;
|
||||
uniform float percent_outline_radius;
|
||||
uniform float percent_center_radius;
|
||||
|
||||
// x = width, y = height
|
||||
uniform ivec2 viewport_sizes;
|
||||
uniform vec2 z_range;
|
||||
uniform mat4 inv_proj_matrix;
|
||||
|
||||
varying vec3 eye_center;
|
||||
|
||||
float radius = 0.5;
|
||||
// x = tainted, y = specular;
|
||||
vec2 intensity;
|
||||
|
||||
vec3 eye_position_from_fragment()
|
||||
{
|
||||
// Convert screen coordinates to normalized device coordinates (NDC)
|
||||
vec4 ndc = vec4(
|
||||
(gl_FragCoord.x / viewport_sizes.x - 0.5) * 2.0,
|
||||
(gl_FragCoord.y / viewport_sizes.y - 0.5) * 2.0,
|
||||
(gl_FragCoord.z - 0.5) * 2.0,
|
||||
1.0);
|
||||
|
||||
// Convert NDC throuch inverse clip coordinates to view coordinates
|
||||
vec4 clip = inv_proj_matrix * ndc;
|
||||
return (clip / clip.w).xyz;
|
||||
}
|
||||
|
||||
vec3 eye_position_on_sphere(vec3 eye_fragment_position)
|
||||
{
|
||||
vec3 eye_dir = normalize(eye_fragment_position);
|
||||
float a = dot(eye_dir, eye_dir);
|
||||
float b = 2.0 * dot(-eye_center, eye_dir);
|
||||
float c = dot(eye_center, eye_center) - radius * radius;
|
||||
float discriminant = b * b - 4 * a * c;
|
||||
float t = -(b + sqrt(discriminant)) / (2.0 * a);
|
||||
return t * eye_dir;
|
||||
}
|
||||
|
||||
vec4 on_sphere_color(vec3 eye_on_sphere_position)
|
||||
{
|
||||
vec3 eye_normal = normalize(eye_on_sphere_position - eye_center);
|
||||
|
||||
// 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(eye_normal, LIGHT_TOP_DIR), 0.0);
|
||||
|
||||
intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE;
|
||||
intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(eye_on_sphere_position), reflect(-LIGHT_TOP_DIR, eye_normal)), 0.0), LIGHT_TOP_SHININESS);
|
||||
|
||||
// Perform the same lighting calculation for the 2nd light source (no specular applied).
|
||||
NdotL = max(dot(eye_normal, LIGHT_FRONT_DIR), 0.0);
|
||||
intensity.x += NdotL * LIGHT_FRONT_DIFFUSE;
|
||||
|
||||
return vec4(vec3(intensity.y, intensity.y, intensity.y) + uniform_color.rgb * intensity.x, 1.0);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 pos = gl_PointCoord - vec2(0.5, 0.5);
|
||||
float sq_radius = dot(pos, pos);
|
||||
if (sq_radius > 0.25)
|
||||
discard;
|
||||
|
||||
vec3 eye_on_sphere_position = eye_position_on_sphere(eye_position_from_fragment());
|
||||
|
||||
// gl_FragDepth = eye_on_sphere_position.z;
|
||||
// gl_FragDepth = (eye_on_sphere_position.z - z_range.x) / (z_range.y - z_range.x);
|
||||
gl_FragColor = on_sphere_color(eye_on_sphere_position);
|
||||
}
|
14
resources/shaders/options_120_solid.vs
Normal file
14
resources/shaders/options_120_solid.vs
Normal file
|
@ -0,0 +1,14 @@
|
|||
#version 120
|
||||
|
||||
uniform float zoom;
|
||||
// x = min, y = max
|
||||
uniform vec2 point_sizes;
|
||||
|
||||
varying vec3 eye_center;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_PointSize = clamp(zoom, point_sizes.x, point_sizes.y);
|
||||
eye_center = (gl_ModelViewMatrix * gl_Vertex).xyz;
|
||||
gl_Position = ftransform();
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
#version 110
|
||||
|
||||
const vec3 ZERO = vec3(0.0, 0.0, 0.0);
|
||||
|
||||
uniform vec4 uniform_color;
|
||||
|
||||
// x = tainted, y = specular;
|
||||
varying vec2 intensity;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = vec4(vec3(intensity.y, intensity.y, intensity.y) + uniform_color.rgb * intensity.x, uniform_color.a);
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
#version 110
|
||||
|
||||
#define INTENSITY_CORRECTION 0.6
|
||||
|
||||
// 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
|
||||
|
||||
// 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)
|
||||
|
||||
#define INTENSITY_AMBIENT 0.3
|
||||
|
||||
// x = tainted, 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);
|
||||
|
||||
// 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;
|
||||
intensity.y = 0.0;
|
||||
|
||||
if (NdotL > 0.0)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
// Perform the same lighting calculation for the 2nd light source (no specular applied).
|
||||
intensity.x += max(dot(normal, LIGHT_FRONT_DIR), 0.0) * LIGHT_FRONT_DIFFUSE;
|
||||
|
||||
gl_Position = ftransform();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue