mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-12 06:59:00 +08:00
Tech ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - Use vertex attributes and matrices in shaders.
Shader: printbed
This commit is contained in:
parent
4323b602f5
commit
93610ebb02
@ -7,15 +7,15 @@ uniform sampler2D texture;
|
|||||||
uniform bool transparent_background;
|
uniform bool transparent_background;
|
||||||
uniform bool svg_source;
|
uniform bool svg_source;
|
||||||
|
|
||||||
varying vec2 tex_coords;
|
varying vec2 tex_coord;
|
||||||
|
|
||||||
vec4 svg_color()
|
vec4 svg_color()
|
||||||
{
|
{
|
||||||
// takes foreground from texture
|
// takes foreground from texture
|
||||||
vec4 fore_color = texture2D(texture, tex_coords);
|
vec4 fore_color = texture2D(texture, tex_coord);
|
||||||
|
|
||||||
// calculates radial gradient
|
// calculates radial gradient
|
||||||
vec3 back_color = vec3(mix(back_color_light, back_color_dark, smoothstep(0.0, 0.5, length(abs(tex_coords.xy) - vec2(0.5)))));
|
vec3 back_color = vec3(mix(back_color_light, back_color_dark, smoothstep(0.0, 0.5, length(abs(tex_coord.xy) - vec2(0.5)))));
|
||||||
|
|
||||||
// blends foreground with background
|
// blends foreground with background
|
||||||
return vec4(mix(back_color, fore_color.rgb, fore_color.a), transparent_background ? fore_color.a : 1.0);
|
return vec4(mix(back_color, fore_color.rgb, fore_color.a), transparent_background ? fore_color.a : 1.0);
|
||||||
@ -24,7 +24,7 @@ vec4 svg_color()
|
|||||||
vec4 non_svg_color()
|
vec4 non_svg_color()
|
||||||
{
|
{
|
||||||
// takes foreground from texture
|
// takes foreground from texture
|
||||||
vec4 color = texture2D(texture, tex_coords);
|
vec4 color = texture2D(texture, tex_coord);
|
||||||
return vec4(color.rgb, transparent_background ? color.a * 0.25 : color.a);
|
return vec4(color.rgb, transparent_background ? color.a * 0.25 : color.a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
#version 110
|
#version 110
|
||||||
|
|
||||||
varying vec2 tex_coords;
|
varying vec2 tex_coord;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = ftransform();
|
gl_Position = ftransform();
|
||||||
tex_coords = gl_MultiTexCoord0.xy;
|
tex_coord = gl_MultiTexCoord0.xy;
|
||||||
}
|
}
|
||||||
|
15
resources/shaders/printbed_attr.vs
Normal file
15
resources/shaders/printbed_attr.vs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#version 110
|
||||||
|
|
||||||
|
attribute vec3 v_position;
|
||||||
|
attribute vec2 v_tex_coord;
|
||||||
|
|
||||||
|
uniform mat4 view_model_matrix;
|
||||||
|
uniform mat4 projection_matrix;
|
||||||
|
|
||||||
|
varying vec2 tex_coord;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
tex_coord = v_tex_coord;
|
||||||
|
gl_Position = projection_matrix * view_model_matrix * vec4(v_position, 1.0);
|
||||||
|
}
|
@ -599,9 +599,18 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas)
|
|||||||
#if ENABLE_GLBEGIN_GLEND_REMOVAL
|
#if ENABLE_GLBEGIN_GLEND_REMOVAL
|
||||||
init_triangles();
|
init_triangles();
|
||||||
|
|
||||||
|
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
|
GLShaderProgram* shader = wxGetApp().get_shader("printbed_attr");
|
||||||
|
#else
|
||||||
GLShaderProgram* shader = wxGetApp().get_shader("printbed");
|
GLShaderProgram* shader = wxGetApp().get_shader("printbed");
|
||||||
|
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
if (shader != nullptr) {
|
if (shader != nullptr) {
|
||||||
shader->start_using();
|
shader->start_using();
|
||||||
|
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
|
const Camera& camera = wxGetApp().plater()->get_camera();
|
||||||
|
shader->set_uniform("view_model_matrix", camera.get_view_matrix());
|
||||||
|
shader->set_uniform("projection_matrix", camera.get_projection_matrix());
|
||||||
|
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
shader->set_uniform("transparent_background", bottom);
|
shader->set_uniform("transparent_background", bottom);
|
||||||
shader->set_uniform("svg_source", boost::algorithm::iends_with(m_texture.get_source(), ".svg"));
|
shader->set_uniform("svg_source", boost::algorithm::iends_with(m_texture.get_source(), ".svg"));
|
||||||
|
|
||||||
|
@ -64,7 +64,11 @@ std::pair<bool, std::string> GLShadersManager::init()
|
|||||||
valid &= append_shader("gouraud_light", { "gouraud_light.vs", "gouraud_light.fs" });
|
valid &= append_shader("gouraud_light", { "gouraud_light.vs", "gouraud_light.fs" });
|
||||||
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
// used to render printbed
|
// used to render printbed
|
||||||
|
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
|
valid &= append_shader("printbed_attr", { "printbed_attr.vs", "printbed.fs" });
|
||||||
|
#else
|
||||||
valid &= append_shader("printbed", { "printbed.vs", "printbed.fs" });
|
valid &= append_shader("printbed", { "printbed.vs", "printbed.fs" });
|
||||||
|
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
// used to render options in gcode preview
|
// used to render options in gcode preview
|
||||||
if (GUI::wxGetApp().is_gl_version_greater_or_equal_to(3, 3)) {
|
if (GUI::wxGetApp().is_gl_version_greater_or_equal_to(3, 3)) {
|
||||||
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
|
Loading…
x
Reference in New Issue
Block a user