update resources

This commit is contained in:
QIDI TECH
2025-05-05 14:58:54 +08:00
parent 524bd808f3
commit 3fe258372a
566 changed files with 7708 additions and 5046 deletions

View File

@@ -0,0 +1,6 @@
#version 110
uniform vec4 uniform_color;
void main()
{
gl_FragColor = uniform_color;
}

View File

@@ -0,0 +1,8 @@
#version 110
attribute vec3 v_position;
void main()
{
gl_Position = vec4(v_position, 1.0);
}

View File

@@ -4,9 +4,15 @@ uniform mat4 view_matrix;
uniform mat4 projection_matrix;
attribute vec3 v_position;
attribute vec2 v_undefine;
attribute mat4 instanceMatrix;
// per instance data
// in mat4 instanceMatrix;
attribute vec4 i_data0;
attribute vec4 i_data1;
attribute vec4 i_data2;
attribute vec4 i_data3;
// end per instance data
void main()
{
gl_Position = projection_matrix * view_matrix * instanceMatrix * vec4(v_position, 1.0);
mat4 model_matrix = mat4(i_data0, i_data1, i_data2, i_data3);
gl_Position = projection_matrix * view_matrix * model_matrix * vec4(v_position, 1.0);
}

View File

@@ -0,0 +1,10 @@
#version 110
uniform sampler2D u_texture;
varying vec2 v_texcoord;
void main()
{
gl_FragColor = texture2D(u_texture, v_texcoord);
}

View File

@@ -0,0 +1,16 @@
#version 110
attribute vec3 v_position;
attribute vec2 v_tex_coord;
uniform mat4 view_model_matrix;
uniform mat4 projection_matrix;
uniform mat3 u_uvTransformMatrix;
varying vec2 v_texcoord;
void main()
{
v_texcoord = (u_uvTransformMatrix * vec3(v_tex_coord, 1.0)).xy;
gl_Position = projection_matrix * view_model_matrix * vec4(v_position, 1.0);
}

View File

@@ -0,0 +1,78 @@
#version 110
uniform vec4 u_viewport_size;
uniform sampler2D u_sampler;
varying vec2 tex_coords;
// thanks https://github.com/mattdesl/glsl-fxaa
#ifndef FXAA_REDUCE_MIN
#define FXAA_REDUCE_MIN (1.0/ 128.0)
#endif
#ifndef FXAA_REDUCE_MUL
#define FXAA_REDUCE_MUL (1.0 / 8.0)
#endif
#ifndef FXAA_SPAN_MAX
#define FXAA_SPAN_MAX 8.0
#endif
vec4 fxaa(sampler2D tex, vec2 fragCoord, vec2 inv_resolution,
vec2 v_rgbNW, vec2 v_rgbNE,
vec2 v_rgbSW, vec2 v_rgbSE,
vec2 v_rgbM) {
vec4 color;
vec2 inverseVP = inv_resolution;
vec3 rgbNW = texture2D(tex, v_rgbNW).xyz;
vec3 rgbNE = texture2D(tex, v_rgbNE).xyz;
vec3 rgbSW = texture2D(tex, v_rgbSW).xyz;
vec3 rgbSE = texture2D(tex, v_rgbSE).xyz;
vec4 texColor = texture2D(tex, v_rgbM);
vec3 rgbM = texColor.xyz;
vec3 luma = vec3(0.299, 0.587, 0.114);
float lumaNW = dot(rgbNW, luma);
float lumaNE = dot(rgbNE, luma);
float lumaSW = dot(rgbSW, luma);
float lumaSE = dot(rgbSE, luma);
float lumaM = dot(rgbM, luma);
float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
vec2 dir;
dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));
dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));
float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) *
(0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);
float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);
dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),
max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),
dir * rcpDirMin)) * inverseVP;
vec3 rgbA = 0.5 * (
texture2D(tex, fragCoord * inverseVP + dir * (1.0 / 3.0 - 0.5)).xyz +
texture2D(tex, fragCoord * inverseVP + dir * (2.0 / 3.0 - 0.5)).xyz);
vec3 rgbB = rgbA * 0.5 + 0.25 * (
texture2D(tex, fragCoord * inverseVP + dir * -0.5).xyz +
texture2D(tex, fragCoord * inverseVP + dir * 0.5).xyz);
float lumaB = dot(rgbB, luma);
if ((lumaB < lumaMin) || (lumaB > lumaMax))
color = vec4(rgbA, texColor.a);
else
color = vec4(rgbB, texColor.a);
return color;
}
void main()
{
vec2 fragCoord = tex_coords * u_viewport_size.xy;
vec2 add = u_viewport_size.zw;
vec2 rgbNW = tex_coords+vec2(-add.x, -add.y);
vec2 rgbNE = tex_coords+vec2( add.x, -add.y);
vec2 rgbSW = tex_coords+vec2(-add.x, add.y);
vec2 rgbSE = tex_coords+vec2( add.x, add.y);
vec2 rgbM = tex_coords;
gl_FragColor = fxaa(u_sampler, fragCoord, u_viewport_size.zw, rgbNW, rgbNE, rgbSW, rgbSE, rgbM);
}

View File

@@ -0,0 +1,12 @@
#version 110
attribute vec3 v_position;
attribute vec2 v_tex_coord;
varying vec2 tex_coords;
void main()
{
tex_coords = v_tex_coord;
gl_Position = vec4(v_position, 1.0);
}

View File

@@ -0,0 +1,35 @@
#version 110
uniform sampler2D u_sampler;
uniform mat3 u_convolution_matrix;
uniform vec2 u_viewport_size;
varying vec2 tex_coords;
vec4 sample(float offsetX, float offsetY)
{
return texture2D(u_sampler, vec2(tex_coords.x + offsetX, tex_coords.y + offsetY));
}
void main()
{
vec4 pixels[9];
float deltaWidth = 1.0 / u_viewport_size.x;
float deltaHeight = 1.0 / u_viewport_size.y;
pixels[0] = sample(-deltaWidth, deltaHeight );
pixels[1] = sample(0.0, deltaHeight );
pixels[2] = sample(deltaWidth, deltaHeight );
pixels[3] = sample(-deltaWidth, 0.0);
pixels[4] = sample(0.0, 0.0);
pixels[5] = sample(deltaWidth, 0.0);
pixels[6] = sample(-deltaWidth, -deltaHeight);
pixels[7] = sample(0.0, -deltaHeight);
pixels[8] = sample(deltaWidth, -deltaHeight);
vec4 accumulator = vec4(0.0);
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; ++j)
{
accumulator += pixels[3 * i + j] * u_convolution_matrix[i][j];
}
}
gl_FragColor = accumulator;
}

View File

@@ -0,0 +1,12 @@
#version 110
attribute vec3 v_position;
attribute vec2 v_tex_coord;
varying vec2 tex_coords;
void main()
{
tex_coords = v_tex_coord;
gl_Position = vec4(v_position, 1.0);
}

View File

@@ -0,0 +1,109 @@
#version 110
const vec3 ZERO = vec3(0.0, 0.0, 0.0);
//QDS: add grey and orange
//const vec3 GREY = vec3(0.9, 0.9, 0.9);
const vec3 ORANGE = vec3(0.8, 0.4, 0.0);
const vec3 LightRed = vec3(0.78, 0.0, 0.0);
const vec3 LightBlue = vec3(0.73, 1.0, 1.0);
const float EPSILON = 0.0001;
const float ONE_OVER_EPSILON = 1e4;
struct PrintVolumeDetection
{
// 0 = rectangle, 1 = circle, 2 = custom, 3 = invalid
int type;
// type = 0 (rectangle):
// x = min.x, y = min.y, z = max.x, w = max.y
// type = 1 (circle):
// x = center.x, y = center.y, z = radius
vec4 xy_data;
// x = min z, y = max z
vec2 z_data;
};
struct SlopeDetection
{
bool actived;
float normal_z;
mat3 volume_world_normal_matrix;
};
uniform vec4 uniform_color;
uniform SlopeDetection slope;
//QDS: add outline_color
uniform bool is_outline;
uniform bool offset_depth_buffer;
#ifdef ENABLE_ENVIRONMENT_MAP
uniform sampler2D environment_tex;
uniform bool use_environment_tex;
#endif // ENABLE_ENVIRONMENT_MAP
varying vec3 clipping_planes_dots;
// x = diffuse, y = specular;
varying vec2 intensity;
uniform PrintVolumeDetection print_volume;
uniform vec3 extruder_printable_heights;
varying vec4 world_pos;
varying float world_normal_z;
varying vec3 eye_normal;
void main()
{
if (any(lessThan(clipping_planes_dots, ZERO)))
discard;
vec3 color = uniform_color.rgb;
float alpha = uniform_color.a;
if (slope.actived) {
if(world_pos.z<0.1&&world_pos.z>-0.1)
{
color = LightBlue;
alpha = 0.8;
}
else if( world_normal_z < slope.normal_z - EPSILON)
{
color = color * 0.5 + LightRed * 0.5;
alpha = 0.8;
}
}
// if the fragment is outside the print volume -> use darker color
vec3 pv_check_min = (world_pos.xyz - vec3(print_volume.xy_data.x, print_volume.xy_data.y, print_volume.z_data.x)) * ONE_OVER_EPSILON;
vec3 pv_check_max = (world_pos.xyz - vec3(print_volume.xy_data.z, print_volume.xy_data.w, print_volume.z_data.y)) * ONE_OVER_EPSILON;
bool is_out_print_limit =(any(lessThan(pv_check_min, vec3(1.0))) || any(greaterThan(pv_check_max, vec3(1.0))));
if (print_volume.type == 0) {// rectangle
color = is_out_print_limit ? mix(color, ZERO, 0.3333) : color;
}
else if (print_volume.type == 1) {
// circle
float delta_radius = print_volume.xy_data.z - distance(world_pos.xy, print_volume.xy_data.xy);
pv_check_min = vec3(delta_radius, 0.0, world_pos.z - print_volume.z_data.x) * ONE_OVER_EPSILON;
pv_check_max = vec3(0.0, 0.0, world_pos.z - print_volume.z_data.y) * ONE_OVER_EPSILON;
color = (any(lessThan(pv_check_min, vec3(1.0))) || any(greaterThan(pv_check_max, vec3(1.0)))) ? mix(color, ZERO, 0.3333) : color;
}
if(extruder_printable_heights.x >= 1.0 ){
pv_check_min = (world_pos.xyz - vec3(print_volume.xy_data.x, print_volume.xy_data.y, extruder_printable_heights.y)) * ONE_OVER_EPSILON;
pv_check_max = (world_pos.xyz - vec3(print_volume.xy_data.z, print_volume.xy_data.w, extruder_printable_heights.z)) * ONE_OVER_EPSILON;
bool is_out_printable_height = (all(greaterThan(pv_check_min, vec3(1.0))) && all(lessThan(pv_check_max, vec3(1.0)))) ;
color = is_out_printable_height ? mix(color, ZERO, 0.7) : color;
}
//QDS: add outline_color
if (is_outline)
gl_FragColor = uniform_color;
#ifdef ENABLE_ENVIRONMENT_MAP
else if (use_environment_tex)
gl_FragColor = vec4(0.45 * texture2D(environment_tex, normalize(eye_normal).xy * 0.5 + 0.5).xyz + 0.8 * color * intensity.x, alpha);
#endif
else
gl_FragColor = vec4(vec3(intensity.y) + color * intensity.x, alpha);
// In the support painting gizmo and the seam painting gizmo are painted triangles rendered over the already
// rendered object. To resolved z-fighting between previously rendered object and painted triangles, values
// inside the depth buffer are offset by small epsilon for painted triangles inside those gizmos.
gl_FragDepth = gl_FragCoord.z - (offset_depth_buffer ? EPSILON : 0.0);
}

View File

@@ -0,0 +1,85 @@
#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 LIGHT_FRONT_SPECULAR (0.0 * INTENSITY_CORRECTION)
//#define LIGHT_FRONT_SHININESS 5.0
const vec3 LIGHT_BACK_DIR = vec3(0.1397015, 0.6985074,0.6985074);
#define LIGHT_BACK_DIFFUSE (0.3 * INTENSITY_CORRECTION)
#define INTENSITY_AMBIENT 0.3
const vec3 ZERO = vec3(0.0, 0.0, 0.0);
struct SlopeDetection
{
bool actived;
float normal_z;
mat3 volume_world_normal_matrix;
};
attribute vec3 v_position;
attribute vec3 v_normal;
uniform mat4 view_model_matrix;
uniform mat4 projection_matrix;
uniform mat3 normal_matrix;
uniform mat4 volume_world_matrix;
uniform SlopeDetection slope;
// Clipping plane, x = min z, y = max z. Used by the FFF and SLA previews to clip with a top / bottom plane.
uniform vec2 z_range;
// Clipping plane - general orientation. Used by the SLA gizmo.
uniform vec4 clipping_plane;
uniform bool is_text_shape;
// x = diffuse, y = specular;
varying vec2 intensity;
varying vec3 clipping_planes_dots;
varying vec4 model_pos;
varying vec4 world_pos;
varying float world_normal_z;
varying vec3 eye_normal;
void main()
{
// First transform the normal into camera space and normalize the result.
eye_normal = normalize(normal_matrix * v_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(eye_normal, LIGHT_TOP_DIR), 0.0);
intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE;
vec4 position = (view_model_matrix * vec4(v_position, 1.0));
intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position.xyz), 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;
if(!is_text_shape){
NdotL = max(dot(eye_normal, LIGHT_BACK_DIR), 0.0);
intensity.x += NdotL * LIGHT_BACK_DIFFUSE;
}
// Point in homogenous coordinates.
world_pos = volume_world_matrix * vec4(v_position, 1.0);
// z component of normal vector in world coordinate used for slope shading
world_normal_z = slope.actived ? (normalize(slope.volume_world_normal_matrix * v_normal)).z : 0.0;
gl_Position = projection_matrix * position;
// Fill in the scalars for fragment shader clipping. Fragments with any of these components lower than zero are discarded.
clipping_planes_dots = vec3(dot(world_pos, clipping_plane), world_pos.z - z_range.x, z_range.y - world_pos.z);
}

View File

@@ -0,0 +1,12 @@
#version 110
uniform vec4 uniform_color;
uniform float emission_factor;
// x = tainted, y = specular;
varying vec2 intensity;
void main()
{
gl_FragColor = vec4(vec3(intensity.y) + uniform_color.rgb * (intensity.x + emission_factor), uniform_color.a);
}

View File

@@ -0,0 +1,45 @@
#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
attribute vec3 v_position;
attribute vec3 v_normal;
uniform mat4 view_model_matrix;
uniform mat4 projection_matrix;
uniform mat3 normal_matrix;
// x = tainted, y = specular;
varying vec2 intensity;
void main()
{
// First transform the normal into camera space and normalize the result.
vec3 normal = normalize(normal_matrix * v_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;
vec4 position = view_model_matrix * vec4(v_position, 1.0);
intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position.xyz), reflect(-LIGHT_TOP_DIR, normal)), 0.0), LIGHT_TOP_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;
gl_Position = projection_matrix * position;
}

View File

@@ -0,0 +1,46 @@
#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
// vertex attributes
attribute vec3 v_position;
attribute vec3 v_normal;
// instance attributes
attribute vec3 i_offset;
attribute vec2 i_scales;
// x = tainted, y = specular;
varying vec2 intensity;
void main()
{
// First transform the normal into camera space and normalize the result.
vec3 eye_normal = normalize(gl_NormalMatrix * v_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(eye_normal, LIGHT_TOP_DIR), 0.0);
intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE;
vec4 world_position = vec4(v_position * vec3(vec2(1.5 * i_scales.x), 1.5 * i_scales.y) + i_offset - vec3(0.0, 0.0, 0.5 * i_scales.y), 1.0);
vec3 eye_position = (gl_ModelViewMatrix * world_position).xyz;
intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(eye_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;
gl_Position = gl_ProjectionMatrix * vec4(eye_position, 1.0);
}

View File

@@ -0,0 +1,51 @@
#version 110
const vec3 ZERO = vec3(0.0, 0.0, 0.0);
const vec3 WHITE = vec3(1.0, 1.0, 1.0);
const float ONE_OVER_EPSILON = 1e4;
struct PrintVolumeDetection
{
// 0 = rectangle, 1 = circle, 2 = custom, 3 = invalid
int type;
// type = 0 (rectangle):
// x = min.x, y = min.y, z = max.x, w = max.y
// type = 1 (circle):
// x = center.x, y = center.y, z = radius
vec4 xy_data;
// x = min z, y = max z
vec2 z_data;
};
uniform vec4 uniform_color;
uniform float emission_factor;
uniform PrintVolumeDetection print_volume;
// x = diffuse, y = specular;
varying vec2 intensity;
varying vec4 world_pos;
void main()
{
vec3 color = uniform_color.rgb;
float alpha = uniform_color.a;
// if the fragment is outside the print volume -> use darker color
vec3 pv_check_min = ZERO;
vec3 pv_check_max = ZERO;
if (print_volume.type == 0) {// rectangle
pv_check_min = world_pos.xyz - vec3(print_volume.xy_data.x, print_volume.xy_data.y, print_volume.z_data.x);
pv_check_max = world_pos.xyz - vec3(print_volume.xy_data.z, print_volume.xy_data.w, print_volume.z_data.y);
pv_check_min = pv_check_min * ONE_OVER_EPSILON;
pv_check_max = pv_check_max * ONE_OVER_EPSILON;
color = (any(lessThan(pv_check_min, vec3(1.0))) || any(greaterThan(pv_check_max, vec3(1.0)))) ? mix(color, WHITE, 0.3333) : color;
}
else if (print_volume.type == 1) {// circle
float delta_radius = print_volume.xy_data.z - distance(world_pos.xy, print_volume.xy_data.xy);
pv_check_min = vec3(delta_radius, 0.0, world_pos.z - print_volume.z_data.x);
pv_check_max = vec3(0.0, 0.0, world_pos.z - print_volume.z_data.y);
pv_check_min = pv_check_min * ONE_OVER_EPSILON;
pv_check_max = pv_check_max * ONE_OVER_EPSILON;
color = (any(lessThan(pv_check_min, vec3(1.0))) || any(greaterThan(pv_check_max, vec3(1.0)))) ? mix(color, WHITE, 0.3333) : color;
}
//gl_FragColor = vec4(vec3(intensity.y) + color * intensity.x, alpha);
gl_FragColor = vec4(vec3(intensity.y) + color * (intensity.x + emission_factor), alpha);
}

View File

@@ -0,0 +1,47 @@
#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
uniform mat4 view_model_matrix;
uniform mat4 projection_matrix;
uniform mat3 view_normal_matrix;
uniform mat4 volume_world_matrix;
attribute vec3 v_position;
attribute vec3 v_normal;
// x = tainted, y = specular;
varying vec2 intensity;
varying vec4 world_pos;
void main()
{
// First transform the normal into camera space and normalize the result.
vec3 normal = normalize(view_normal_matrix * v_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;
world_pos = volume_world_matrix * vec4(v_position, 1.0);
vec4 position = view_model_matrix * vec4(v_position, 1.0);
intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position.xyz), reflect(-LIGHT_TOP_DIR, normal)), 0.0), LIGHT_TOP_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;
gl_Position = projection_matrix * position;
}

View File

@@ -0,0 +1,11 @@
#version 110
uniform sampler2D Texture;
varying vec2 Frag_UV;
varying vec4 color;
void main()
{
gl_FragColor = color * texture2D(Texture, Frag_UV.st);
}

View File

@@ -0,0 +1,17 @@
#version 110
uniform mat4 ProjMtx;
attribute vec2 Position;
attribute vec2 UV;
attribute vec4 Color;
varying vec2 Frag_UV;
varying vec4 color;
void main()
{
Frag_UV = UV;
color = Color;
gl_Position = ProjMtx * vec4(Position.xy, 0.0, 1.0);
}

View File

@@ -0,0 +1,10 @@
#version 110
uniform sampler2D u_sampler;
varying vec2 tex_coords;
void main()
{
gl_FragColor = texture2D(u_sampler, tex_coords);
}

View File

@@ -0,0 +1,12 @@
#version 110
attribute vec3 v_position;
attribute vec2 v_tex_coord;
varying vec2 tex_coords;
void main()
{
tex_coords = v_tex_coord;
gl_Position = vec4(v_position, 1.0);
}

View File

@@ -0,0 +1,11 @@
#version 110
const float EPSILON = 0.0001;
void main()
{
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
// Values inside depth buffer for fragments of the contour of a selected area are offset
// by small epsilon to solve z-fighting between painted triangles and contour lines.
gl_FragDepth = gl_FragCoord.z - EPSILON;
}

View File

@@ -0,0 +1,11 @@
#version 110
uniform mat4 view_model_matrix;
uniform mat4 projection_matrix;
attribute vec3 v_position;
void main()
{
gl_Position = projection_matrix * view_model_matrix * vec4(v_position, 1.0);
}

View File

@@ -0,0 +1,118 @@
#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
const vec3 ZERO = vec3(0.0, 0.0, 0.0);
const float EPSILON = 0.0001;
//QDS: add grey and orange
//const vec3 GREY = vec3(0.9, 0.9, 0.9);
const vec3 ORANGE = vec3(0.8, 0.4, 0.0);
const vec3 LightRed = vec3(0.78, 0.0, 0.0);
const vec3 LightBlue = vec3(0.73, 1.0, 1.0);
const float CHESS_WIDTH = 2.0;
const vec3 COLOR_A = vec3(1.0, 1.0, 0.0);
const vec3 COLOR_B = vec3(0.3, 0.3, 0.0);
uniform vec4 uniform_color;
varying vec3 clipping_planes_dots;
varying vec3 model_pos;
varying vec4 world_pos;
uniform bool volume_mirrored;
struct SlopeDetection
{
bool actived;
float normal_z;
mat3 volume_world_normal_matrix;
};
uniform SlopeDetection slope;
//QDS: add wireframe logic
varying vec3 barycentric_coordinates;
float edgeFactor(float lineWidth) {
vec3 d = fwidth(barycentric_coordinates);
vec3 a3 = smoothstep(vec3(0.0), d * lineWidth, barycentric_coordinates);
return min(min(a3.x, a3.y), a3.z);
}
vec3 wireframe(vec3 fill, vec3 stroke, float lineWidth) {
return mix(stroke, fill, edgeFactor(lineWidth));
//if (any(lessThan(barycentric_coordinates, vec3(0.005, 0.005, 0.005))))
// return vec3(1.0, 0.0, 0.0);
//else
// return fill;
}
vec3 getWireframeColor(vec3 fill) {
float brightness = 0.2126 * fill.r + 0.7152 * fill.g + 0.0722 * fill.b;
return (brightness > 0.75) ? vec3(0.11, 0.165, 0.208) : vec3(0.988, 0.988, 0.988);
}
uniform bool show_wireframe;
uniform mat4 view_model_matrix;
uniform mat3 normal_matrix;
void main()
{
if (any(lessThan(clipping_planes_dots, ZERO)))
discard;
vec3 color = uniform_color.rgb;
float alpha = uniform_color.a;
vec3 triangle_normal = normalize(cross(dFdx(model_pos.xyz), dFdy(model_pos.xyz)));
if (volume_mirrored)
{
triangle_normal = -triangle_normal;
}
vec3 transformed_normal = normalize(slope.volume_world_normal_matrix * triangle_normal);
if (slope.actived) {
alpha = 1.0;
if(abs(world_pos.z) < 0.1){
color = LightBlue;
}
else if( transformed_normal.z < slope.normal_z - EPSILON){
bool x_flag = mod(world_pos.x, CHESS_WIDTH) < (CHESS_WIDTH / 2.0);
bool y_flag = mod(world_pos.y, CHESS_WIDTH) < (CHESS_WIDTH / 2.0);
vec3 temp_color = (x_flag^^y_flag) ? COLOR_A : COLOR_B;
color = mix(color,temp_color,0.2);
}
}
// First transform the normal into camera space and normalize the result.
vec3 eye_normal = normalize(normal_matrix * triangle_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(eye_normal, LIGHT_TOP_DIR), 0.0);
// x = diffuse, y = specular;
vec2 intensity = vec2(0.0, 0.0);
intensity.x = INTENSITY_AMBIENT + NdotL * LIGHT_TOP_DIFFUSE;
vec3 position = (view_model_matrix * vec4(model_pos, 1.0)).xyz;
intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(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;
if (show_wireframe) {
vec3 wireframeColor = getWireframeColor(color);
vec3 triangleColor = wireframe(color, wireframeColor, 1.0);
gl_FragColor = vec4(vec3(intensity.y) + triangleColor * intensity.x, alpha);
}
else {
gl_FragColor = vec4(vec3(intensity.y) + color * intensity.x, alpha);
}
}

View File

@@ -0,0 +1,44 @@
#version 110
const vec3 ZERO = vec3(0.0, 0.0, 0.0);
uniform mat4 view_model_matrix;
uniform mat4 projection_matrix;
uniform mat4 volume_world_matrix;
// Clipping plane, x = min z, y = max z. Used by the FFF and SLA previews to clip with a top / bottom plane.
uniform vec2 z_range;
// Clipping plane - general orientation. Used by the SLA gizmo.
uniform vec4 clipping_plane;
attribute vec3 v_position;
attribute vec3 v_color;
varying vec3 clipping_planes_dots;
varying vec3 model_pos;
varying vec4 world_pos;
varying vec3 barycentric_coordinates;
struct SlopeDetection
{
bool actived;
float normal_z;
mat3 volume_world_normal_matrix;
};
uniform SlopeDetection slope;
void main()
{
model_pos = v_position;
//model_pos = vec4(v_position, 1.0);
// Point in homogenous coordinates.
world_pos = volume_world_matrix * vec4(model_pos, 1.0);
gl_Position = projection_matrix * view_model_matrix * vec4(v_position, 1.0);
//gl_Position = gl_ModelViewProjectionMatrix * vec4(v_position, 1.0);
// Fill in the scalars for fragment shader clipping. Fragments with any of these components lower than zero are discarded.
clipping_planes_dots = vec3(dot(world_pos, clipping_plane), world_pos.z - z_range.x, z_range.y - world_pos.z);
//compute the Barycentric Coordinates
//int vertexMod3 = gl_VertexID % 3;
//barycentric_coordinates = vec3(float(vertexMod3 == 0), float(vertexMod3 == 1), float(vertexMod3 == 2));
barycentric_coordinates = v_color.xyz;
}

View File

@@ -3,32 +3,34 @@
const vec3 back_color_dark = vec3(0.235, 0.235, 0.235);
const vec3 back_color_light = vec3(0.365, 0.365, 0.365);
uniform sampler2D texture;
uniform sampler2D u_sampler;
uniform bool transparent_background;
uniform bool svg_source;
varying vec2 tex_coord;
vec4 svg_color()
vec4 svg_color(vec2 uv)
{
// takes foreground from texture
vec4 fore_color = texture2D(texture, tex_coord);
// takes foreground from u_sampler
vec4 fore_color = texture2D(u_sampler, uv);
// calculates radial gradient
vec3 back_color = vec3(mix(back_color_light, back_color_dark, smoothstep(0.0, 0.5, length(abs(tex_coord.xy) - vec2(0.5)))));
vec3 back_color = vec3(mix(back_color_light, back_color_dark, smoothstep(0.0, 0.5, length(abs(uv) - vec2(0.5)))));
// blends foreground with background
return vec4(mix(back_color, fore_color.rgb, fore_color.a), transparent_background ? fore_color.a : 1.0);
}
vec4 non_svg_color()
vec4 non_svg_color(vec2 uv)
{
// takes foreground from texture
vec4 color = texture2D(texture, tex_coord);
// takes foreground from u_sampler
vec4 color = texture2D(u_sampler, uv);
return vec4(color.rgb, transparent_background ? color.a * 0.25 : color.a);
}
void main()
{
gl_FragColor = svg_source ? svg_color() : non_svg_color();
// flip uv
vec2 uv = vec2(tex_coord.x, 1.0 - tex_coord.y);
gl_FragColor = svg_source ? svg_color(uv) : non_svg_color(uv);
}

View File

@@ -0,0 +1,6 @@
#version 110
uniform vec3 u_base_color;
void main()
{
gl_FragColor = vec4(u_base_color, 1.0);
}

View File

@@ -0,0 +1,11 @@
#version 110
uniform mat4 u_model_matrix;
uniform mat4 u_view_projection_matrix;
attribute vec3 v_position;
void main()
{
gl_Position = u_view_projection_matrix * u_model_matrix * vec4(v_position, 1.0);
}

View File

@@ -0,0 +1,57 @@
#version 110
uniform sampler2D u_sampler;
uniform mat3 u_convolution_matrix;
uniform vec3 u_viewport_size_alpha;
uniform vec3 u_picking_color;
varying vec2 tex_coords;
vec4 sample(float offsetX, float offsetY)
{
return texture2D(u_sampler, vec2(tex_coords.x + offsetX, tex_coords.y + offsetY));
}
// see https://docs.gl/sl4/sign
// glsl 110 & 120 may not support the sign func
float sign_glsl_110(float value)
{
if (value > 1e-6) {
return 1.0;
}
else if (value < -1e-6) {
return -1.0;
}
return 0.0;
}
void main()
{
vec4 pixels[9];
float deltaWidth = 1.0 / u_viewport_size_alpha.x;
float deltaHeight = 1.0 / u_viewport_size_alpha.y;
float alpha = u_viewport_size_alpha.z;
float effect_width = 2.0;
deltaWidth = deltaWidth * effect_width;
deltaHeight = deltaHeight * effect_width;
pixels[0] = sample(-deltaWidth, deltaHeight );
pixels[1] = sample(0.0, deltaHeight );
pixels[2] = sample(deltaWidth, deltaHeight );
pixels[3] = sample(-deltaWidth, 0.0);
pixels[4] = sample(0.0, 0.0);
pixels[5] = sample(deltaWidth, 0.0);
pixels[6] = sample(-deltaWidth, -deltaHeight);
pixels[7] = sample(0.0, -deltaHeight);
pixels[8] = sample(deltaWidth, -deltaHeight);
vec4 accumulator = vec4(0.0);
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; ++j)
{
accumulator += sign_glsl_110(pixels[3 * i + j].a) * vec4(u_picking_color, 1.0) * u_convolution_matrix[i][j];
}
}
if ((abs(accumulator.a) - alpha * pixels[4].a) * 1e6 > 1.0) {
accumulator = vec4(u_picking_color, abs(accumulator.a));
}
gl_FragColor = accumulator;
}

View File

@@ -0,0 +1,12 @@
#version 110
attribute vec3 v_position;
attribute vec2 v_tex_coord;
varying vec2 tex_coords;
void main()
{
tex_coords = v_tex_coord;
gl_Position = vec4(v_position, 1.0);
}

View File

@@ -0,0 +1,21 @@
#version 110
uniform bool ban_light;
uniform vec4 uniform_color;
uniform float emission_factor;
// x = tainted, y = specular;
varying vec2 intensity;
//varying float drop;
varying vec4 world_pos;
void main()
{
if (world_pos.z < 0.0)
discard;
if(ban_light){
gl_FragColor = uniform_color;
} else{
gl_FragColor = vec4(vec3(intensity.y) + uniform_color.rgb * (intensity.x + emission_factor), uniform_color.a);
}
}

View File

@@ -0,0 +1,50 @@
#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
attribute vec3 v_position;
attribute vec3 v_normal;
uniform mat4 view_model_matrix;
uniform mat4 projection_matrix;
uniform mat3 normal_matrix;
uniform mat4 volume_world_matrix;
// x = tainted, y = specular;
varying vec2 intensity;
varying vec4 world_pos;
void main()
{
// First transform the normal into camera space and normalize the result.
vec3 normal = normalize(normal_matrix * v_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;
vec4 position = (view_model_matrix * vec4(v_position, 1.0));
intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position.xyz), reflect(-LIGHT_TOP_DIR, normal)), 0.0), LIGHT_TOP_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;
// Point in homogenous coordinates.
world_pos = volume_world_matrix * vec4(v_position, 1.0);
gl_Position = projection_matrix * position;
}

View File

@@ -0,0 +1,28 @@
#version 110
// 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);
const vec3 LIGHT_FRONT_DIR = vec3(0.0, 0.0, 1.0);
// x = ambient, y = top diffuse, z = front diffuse, w = global
uniform vec4 light_intensity;
uniform vec4 uniform_color;
varying vec3 eye_normal;
void main()
{
vec3 normal = normalize(eye_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. Take the abs value to light the lines no matter in which direction the normal points.
float NdotL = abs(dot(normal, LIGHT_TOP_DIR));
float intensity = light_intensity.x + NdotL * light_intensity.y;
// Perform the same lighting calculation for the 2nd light source.
NdotL = abs(dot(normal, LIGHT_FRONT_DIR));
intensity += NdotL * light_intensity.z;
gl_FragColor = vec4(uniform_color.rgb * light_intensity.w * intensity, uniform_color.a);
}

View File

@@ -0,0 +1,16 @@
#version 110
attribute vec3 v_position;
attribute vec3 v_normal;
uniform mat4 view_model_matrix;
uniform mat4 projection_matrix;
uniform mat3 normal_matrix;
varying vec3 eye_normal;
void main()
{
gl_Position = projection_matrix * view_model_matrix * vec4(v_position, 1.0);
eye_normal = normal_matrix * v_normal;
}

View File

@@ -0,0 +1,41 @@
#version 110
#define M_PI 3.1415926535897932384626433832795
// 2D texture (1D texture split by the rows) of color along the object Z axis.
uniform sampler2D z_texture;
// Scaling from the Z texture rows coordinate to the normalized texture row coordinate.
uniform float z_to_texture_row;
uniform float z_texture_row_to_normalized;
uniform float z_cursor;
uniform float z_cursor_band_width;
// x = tainted, y = specular;
varying vec2 intensity;
varying float object_z;
void main()
{
float object_z_row = z_to_texture_row * object_z;
// Index of the row in the texture.
float z_texture_row = floor(object_z_row);
// Normalized coordinate from 0. to 1.
float z_texture_col = object_z_row - z_texture_row;
float z_blend = 0.25 * cos(min(M_PI, abs(M_PI * (object_z - z_cursor) * 1.8 / z_cursor_band_width))) + 0.25;
// Calculate level of detail from the object Z coordinate.
// This makes the slowly sloping surfaces to be shown with high detail (with stripes),
// and the vertical surfaces to be shown with low detail (no stripes)
float z_in_cells = object_z_row * 190.;
// Gradient of Z projected on the screen.
float dx_vtc = dFdx(z_in_cells);
float dy_vtc = dFdy(z_in_cells);
float lod = clamp(0.5 * log2(max(dx_vtc * dx_vtc, dy_vtc * dy_vtc)), 0., 1.);
// Sample the Z texture. Texture coordinates are normalized to <0, 1>.
vec4 color = vec4(0.25, 0.25, 0.25, 1.0);
if (z_texture_row >= 0.0)
color = mix(texture2D(z_texture, vec2(z_texture_col, z_texture_row_to_normalized * (z_texture_row + 0.5 )), -10000.),
texture2D(z_texture, vec2(z_texture_col, z_texture_row_to_normalized * (z_texture_row * 2. + 1.)), 10000.), lod);
// Mix the final color.
gl_FragColor = vec4(vec3(intensity.y), 1.0) + intensity.x * mix(color, vec4(1.0, 1.0, 0.0, 1.0), z_blend);
}

View File

@@ -0,0 +1,60 @@
#version 110
#define INTENSITY_CORRECTION 0.6
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
const vec3 LIGHT_FRONT_DIR = vec3(0.6985074, 0.1397015, 0.6985074);
#define LIGHT_FRONT_DIFFUSE (0.3 * INTENSITY_CORRECTION)
//#define LIGHT_FRONT_SPECULAR (0.0 * INTENSITY_CORRECTION)
//#define LIGHT_FRONT_SHININESS 5.0
#define INTENSITY_AMBIENT 0.3
attribute vec3 v_position;
attribute vec3 v_normal;
attribute vec2 v_tex_coord;
uniform mat4 view_model_matrix;
uniform mat4 projection_matrix;
uniform mat3 normal_matrix;
uniform mat4 volume_world_matrix;
uniform float object_max_z;
// x = tainted, y = specular;
varying vec2 intensity;
varying float object_z;
void main()
{
// First transform the normal into camera space and normalize the result.
vec3 normal = normalize(normal_matrix * v_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;
vec4 position = view_model_matrix * vec4(v_position, 1.0);
intensity.y = LIGHT_TOP_SPECULAR * pow(max(dot(-normalize(position.xyz), reflect(-LIGHT_TOP_DIR, normal)), 0.0), LIGHT_TOP_SHININESS);
// Perform the same lighting calculation for the 2nd light source (no specular)
NdotL = max(dot(normal, LIGHT_FRONT_DIR), 0.0);
intensity.x += NdotL * LIGHT_FRONT_DIFFUSE;
// Scaled to widths of the Z texture.
if (object_max_z > 0.0)
// when rendering the overlay
object_z = object_max_z * v_tex_coord.y;
else
// when rendering the volumes
object_z = (volume_world_matrix * vec4(v_position, 1.0)).z;
gl_Position = projection_matrix * position;
}