diff --git a/include/polyscope/render/opengl/shaders/texture_draw_shaders.h b/include/polyscope/render/opengl/shaders/texture_draw_shaders.h index 820e8400..c9fe9060 100644 --- a/include/polyscope/render/opengl/shaders/texture_draw_shaders.h +++ b/include/polyscope/render/opengl/shaders/texture_draw_shaders.h @@ -32,8 +32,10 @@ extern const ShaderReplacementRule extern const ShaderReplacementRule TEXTURE_ORIGIN_LOWERLEFT; // sample textures with (0,0) in the lower left, which is the usual openGL rule extern const ShaderReplacementRule TEXTURE_SET_TRANSPARENCY; // apply a transparency uniform to the texture -extern const ShaderReplacementRule TEXTURE_PREMULTIPLY_OUT; // premultiply color samples -extern const ShaderReplacementRule TEXTURE_SHADE_COLOR; // sample a color from a texture and use it for shading +extern const ShaderReplacementRule + TEXTURE_SET_TRANSPARENCY_PREMULTIPLIED; // apply a transparency uniform to the texture +extern const ShaderReplacementRule TEXTURE_PREMULTIPLY_OUT; // premultiply color samples +extern const ShaderReplacementRule TEXTURE_SHADE_COLOR; // sample a color from a texture and use it for shading extern const ShaderReplacementRule TEXTURE_SHADE_COLORALPHA; // sample a coloralpha from a texture and use it for shading extern const ShaderReplacementRule TEXTURE_PROPAGATE_VALUE; // sample a scalar from a texture and use it for shading diff --git a/src/color_image_quantity.cpp b/src/color_image_quantity.cpp index 8c9cd3e7..d66b0f76 100644 --- a/src/color_image_quantity.cpp +++ b/src/color_image_quantity.cpp @@ -41,9 +41,17 @@ std::string ColorImageQuantity::niceName() { return name + " (color image)"; } void ColorImageQuantity::prepareFullscreen() { // Create the sourceProgram - fullscreenProgram = render::engine->requestShader( - "TEXTURE_DRAW_PLAIN", {getImageOriginRule(imageOrigin), "TEXTURE_SET_TRANSPARENCY", "INVERSE_TONEMAP"}, - render::ShaderReplacementDefaults::Process); + // clang-format off + fullscreenProgram = + render::engine->requestShader("TEXTURE_DRAW_PLAIN", + { + getImageOriginRule(imageOrigin), + getIsPremultiplied() ? "TEXTURE_SET_TRANSPARENCY_PREMULTIPLIED" : "TEXTURE_SET_TRANSPARENCY", + "INVERSE_TONEMAP", + getIsPremultiplied() ? "" : "TEXTURE_PREMULTIPLY_OUT" + }, + render::ShaderReplacementDefaults::Process); + // clang-format on fullscreenProgram->setAttribute("a_position", render::engine->screenTrianglesCoords()); // TODO throughout polyscope we discard the shared pointer when adding textures/attributes to programs... should we // just track the shared pointer? @@ -53,11 +61,18 @@ void ColorImageQuantity::prepareFullscreen() { void ColorImageQuantity::prepareBillboard() { // Create the sourceProgram - billboardProgram = render::engine->requestShader("TEXTURE_DRAW_PLAIN", - {getImageOriginRule(imageOrigin), "TEXTURE_SET_TRANSPARENCY", - "TEXTURE_BILLBOARD_FROM_UNIFORMS", "INVERSE_TONEMAP", - getIsPremultiplied() ? "" : "TEXTURE_PREMULTIPLY_OUT"}, - render::ShaderReplacementDefaults::Process); + // clang-format off + billboardProgram = + render::engine->requestShader("TEXTURE_DRAW_PLAIN", + { + getImageOriginRule(imageOrigin), + getIsPremultiplied() ? "TEXTURE_SET_TRANSPARENCY_PREMULTIPLIED" : "TEXTURE_SET_TRANSPARENCY", + "TEXTURE_BILLBOARD_FROM_UNIFORMS", + "INVERSE_TONEMAP", + getIsPremultiplied() ? "" : "TEXTURE_PREMULTIPLY_OUT" + }, + render::ShaderReplacementDefaults::Process); + // clang-format on billboardProgram->setAttribute("a_position", render::engine->screenTrianglesCoords()); billboardProgram->setTextureFromBuffer("t_image", colors.getRenderTextureBuffer().get()); } diff --git a/src/render/managed_buffer.cpp b/src/render/managed_buffer.cpp index ecba28e6..2a91a0d7 100644 --- a/src/render/managed_buffer.cpp +++ b/src/render/managed_buffer.cpp @@ -591,7 +591,7 @@ template<> ManagedBufferMap& ManagedBufferMaprequestShader("SCALAR_TEXTURE_COLORMAP", - this->addScalarRules({getImageOriginRule(imageOrigin), "TEXTURE_SET_TRANSPARENCY", - "TEXTURE_BILLBOARD_FROM_UNIFORMS"}), - render::ShaderReplacementDefaults::Process); + billboardProgram = render::engine->requestShader( + "SCALAR_TEXTURE_COLORMAP", + this->addScalarRules({getImageOriginRule(imageOrigin), "TEXTURE_SET_TRANSPARENCY", "TEXTURE_PREMULTIPLY_OUT", + "TEXTURE_BILLBOARD_FROM_UNIFORMS"}), + render::ShaderReplacementDefaults::Process); billboardProgram->setAttribute("a_position", render::engine->screenTrianglesCoords()); billboardProgram->setTextureFromBuffer("t_scalar", values.getRenderTextureBuffer().get()); billboardProgram->setTextureFromColormap("t_colormap", this->cMap.get());