Skip to content
6 changes: 6 additions & 0 deletions data/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ coin_embed_gl_shader(gl_point_triangle_geometry data/shaders/gl/point/TriangleGe
coin_embed_gl_shader(gl_point_fragment data/shaders/gl/point/Fragment.glsl)
coin_embed_gl_shader(gl_pixel_vertex data/shaders/gl/pixel/Vertex.glsl)
coin_embed_gl_shader(gl_pixel_fragment data/shaders/gl/pixel/Fragment.glsl)
coin_embed_gl_shader(gl_picking_fragment data/shaders/gl/picking/Fragment.glsl)
coin_embed_gl_shader(gl_picking_wide_line_fragment data/shaders/gl/picking/WideLineFragment.glsl)
coin_embed_gl_shader(gl_picking_pixel_fragment data/shaders/gl/picking/PixelFragment.glsl)
coin_embed_gl_shader(gl_selection_fragment data/shaders/gl/selection/Fragment.glsl)
coin_embed_gl_shader(gl_selection_wide_line_fragment data/shaders/gl/selection/WideLineFragment.glsl)
coin_embed_gl_shader(gl_selection_pixel_fragment data/shaders/gl/selection/PixelFragment.glsl)

# These are legacy shader snippets exposed through Coin's built-in shader
# dictionary. They are ordinary embedded text, not core-profile root
Expand Down
23 changes: 23 additions & 0 deletions data/shaders/gl/picking/Fragment.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#version 330 core

/* Integer-ID surface root. Reuse visual coverage and alpha testing, then
* replace visual output with the frame-local uint identity. */
#include "../material/FragmentEvaluation.glsl"
#include "Peel.glsl"

uniform uint u_pickId;

in vec4 v_color;
in vec3 v_litColor;
in vec2 v_texcoord;

layout(location = 0) out uint outPickId;

void main()
{
if (!coin_pick_peel_pass()) discard;
vec4 color = coin_surface_fragment_color(v_color, v_litColor, v_texcoord);
if (!coin_material_alpha_test_pass(color.a, u_alphaTestFunction,
u_alphaTestReference)) discard;
outPickId = u_pickId;
}
10 changes: 10 additions & 0 deletions data/shaders/gl/picking/Peel.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* Shared bounded depth-peeling rejection for integer-ID picking. */
uniform sampler2D u_previousDepth;
uniform int u_peelEnabled;

bool coin_pick_peel_pass()
{
if (u_peelEnabled == 0) return true;
float previous = texelFetch(u_previousDepth, ivec2(gl_FragCoord.xy), 0).r;
return gl_FragCoord.z > previous + 1.0e-6;
}
34 changes: 34 additions & 0 deletions data/shaders/gl/picking/PixelFragment.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#version 330 core

/* Integer-ID pixel root. Pixel producers supply final RGBA, so this pass
* applies only pixel-coordinate coverage and explicit alpha testing before
* writing the uint identity. */
uniform sampler2D u_texture;
uniform int u_alphaTestFunction;
uniform float u_alphaTestReference;
uniform vec2 u_sourceSize;
uniform vec2 u_rasterSize;
uniform vec2 u_pixelOrigin;
uniform vec2 u_viewportOrigin;
uniform uint u_pickId;

in vec2 v_texcoord;
layout(location = 0) out uint outPickId;

#include "../pixel/Common.glsl"
#include "../material/AlphaTest.glsl"
#include "Peel.glsl"

void main()
{
if (!coin_pick_peel_pass()) discard;
vec2 rasterPixel = coin_pixel_raster_coordinate(
gl_FragCoord.xy, u_viewportOrigin, u_pixelOrigin);
if (!coin_pixel_in_raster(rasterPixel, u_rasterSize)) discard;
ivec2 pixel = coin_pixel_source_coordinate(
rasterPixel, u_sourceSize, u_rasterSize, textureSize(u_texture, 0));
vec4 texel = coin_pixel_fetch(u_texture, pixel);
if (!coin_material_alpha_test_pass(texel.a, u_alphaTestFunction,
u_alphaTestReference)) discard;
outPickId = u_pickId;
}
30 changes: 30 additions & 0 deletions data/shaders/gl/picking/WideLineFragment.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#version 330 core

/* Integer-ID wide-line root. Stipple and shared surface coverage must match
* the visual wide-line pipeline; only the final output differs. */
#include "../material/FragmentEvaluation.glsl"
#include "Peel.glsl"

uniform int u_stipplePattern;
uniform float u_stippleScale;
uniform uint u_pickId;

in vec4 v_color;
in vec3 v_litColor;
in vec2 v_texcoord;
noperspective in float v_lineDistance;

layout(location = 0) out uint outPickId;

void main()
{
if (!coin_pick_peel_pass()) discard;
int bit = int(floor(max(v_lineDistance, 0.0) /
max(u_stippleScale, 1.0))) & 15;
if (((u_stipplePattern >> bit) & 1) == 0) discard;

vec4 color = coin_surface_fragment_color(v_color, v_litColor, v_texcoord);
if (!coin_material_alpha_test_pass(color.a, u_alphaTestFunction,
u_alphaTestReference)) discard;
outPickId = u_pickId;
}
20 changes: 20 additions & 0 deletions data/shaders/gl/selection/Fragment.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#version 330 core

/* Selection surface root. Match visual coverage, then emit the explicit
* selection color; selection is interaction state, not scene identity. */
#include "../material/FragmentEvaluation.glsl"
uniform vec4 u_selectionColor;

in vec4 v_color;
in vec3 v_litColor;
in vec2 v_texcoord;

out vec4 fragColor;

void main()
{
vec4 coverage = coin_surface_fragment_color(v_color, v_litColor, v_texcoord);
if (!coin_material_alpha_test_pass(coverage.a, u_alphaTestFunction,
u_alphaTestReference)) discard;
fragColor = u_selectionColor;
}
31 changes: 31 additions & 0 deletions data/shaders/gl/selection/PixelFragment.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#version 330 core

/* Selection pixel root. Match final-RGBA pixel coverage exactly, then emit
* the requested overlay color. */
uniform sampler2D u_texture;
uniform int u_alphaTestFunction;
uniform float u_alphaTestReference;
uniform vec2 u_sourceSize;
uniform vec2 u_rasterSize;
uniform vec2 u_pixelOrigin;
uniform vec2 u_viewportOrigin;
uniform vec4 u_selectionColor;

in vec2 v_texcoord;
out vec4 fragColor;

#include "../pixel/Common.glsl"
#include "../material/AlphaTest.glsl"

void main()
{
vec2 rasterPixel = coin_pixel_raster_coordinate(
gl_FragCoord.xy, u_viewportOrigin, u_pixelOrigin);
if (!coin_pixel_in_raster(rasterPixel, u_rasterSize)) discard;
ivec2 pixel = coin_pixel_source_coordinate(
rasterPixel, u_sourceSize, u_rasterSize, textureSize(u_texture, 0));
vec4 texel = coin_pixel_fetch(u_texture, pixel);
if (!coin_material_alpha_test_pass(texel.a, u_alphaTestFunction,
u_alphaTestReference)) discard;
fragColor = u_selectionColor;
}
28 changes: 28 additions & 0 deletions data/shaders/gl/selection/WideLineFragment.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#version 330 core

/* Selection wide-line root. Preserve stipple and coverage while changing
* only the output color used by the explicit overlay operation. */
#include "../material/FragmentEvaluation.glsl"

uniform int u_stipplePattern;
uniform float u_stippleScale;
uniform vec4 u_selectionColor;

in vec4 v_color;
in vec3 v_litColor;
in vec2 v_texcoord;
noperspective in float v_lineDistance;

out vec4 fragColor;

void main()
{
int bit = int(floor(max(v_lineDistance, 0.0) /
max(u_stippleScale, 1.0))) & 15;
if (((u_stipplePattern >> bit) & 1) == 0) discard;

vec4 coverage = coin_surface_fragment_color(v_color, v_litColor, v_texcoord);
if (!coin_material_alpha_test_pass(coverage.a, u_alphaTestFunction,
u_alphaTestReference)) discard;
fragColor = u_selectionColor;
}
4 changes: 4 additions & 0 deletions include/Inventor/SoPickedPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class COIN_DLL_API SoPickedPoint {
SoPickedPoint(const SoPickedPoint & pp);
SoPickedPoint(const SoPath * const path, SoState * const state,
const SbVec3f & objSpacePoint);
//! Construct a scene hit resolved without a live ray-picking traversal.
SoPickedPoint(const SoPath * const path,
const SbVec3f & worldSpacePoint,
const SbViewportRegion & viewport);
~SoPickedPoint();
SoPickedPoint *copy() const;
const SbVec3f &getPoint() const;
Expand Down
7 changes: 7 additions & 0 deletions include/Inventor/actions/SoIRRenderAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <Inventor/rendering/SoRenderIR.h>

#include <cstddef>
#include <vector>
class SoPrimitiveVertex;
class SoPath;
class SoPathList;
Expand Down Expand Up @@ -80,6 +81,10 @@ class COIN_DLL_API SoIRRenderAction : public SoAction {

//! Append a retained command produced during the current traversal.
void addCommand(const SoRenderCommand & command);
//! Return the non-owned path retained for a command in this frame.
//! The pointer is borrowed and remains valid until the next apply/beginFrame
//! on this action or until the action is destroyed.
const SoPath * getCommandPath(int commandIndex) const;

//! Mark the current frame as unsupported by the retained renderer.
void markUnsupported(const SoNode * node, const char * reason);
Expand Down Expand Up @@ -123,9 +128,11 @@ class COIN_DLL_API SoIRRenderAction : public SoAction {

private:
void resetFrameResources();
void clearCommandPaths();

SbViewportRegion vpRegion;
SoDrawList drawlist;
std::vector<SoPath *> commandPaths;
SoIRRenderActionP * pimpl;
bool unsupportedRendering = false;
const SoNode * unsupportedNode = nullptr;
Expand Down
Loading