Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,8 @@ if(COIN_BUILD_VISUAL_TESTS)
add_subdirectory(tools)
set(COIN_DRAWLIST_BASE_VISUAL_SPECS
"unlit_cube_basic,unlit_transformed_cubes,unlit_vertex_colors,unlit_orthographic_basic,unlit_depth_overlap")
set(COIN_MATERIAL_VISUAL_SPECS
"cube_basic,camera_persp_basic,camera_ortho_basic,material_emissive,two_lights,point_spot_lights_basic,texture_rgb,texture_luminance_alpha,transparent_overlap,depth_buffer_basic,alpha_test_basic,transparency_depth_basic,transparency_order_basic,specular_shininess_basic")
add_test(NAME visual_smoke COMMAND CoinVisualTests snapshot --help)
set_tests_properties(visual_smoke PROPERTIES LABELS "visual-contract")
if(COIN_BUILD_LEGACY_GL_RENDERER)
Expand Down Expand Up @@ -1001,6 +1003,26 @@ if(COIN_BUILD_VISUAL_TESTS)
)
set_tests_properties(visual_gl_drawlist_core
PROPERTIES LABELS "visual-render;visual-drawlist")
add_test(
NAME visual_gl_drawlist_material_compat
COMMAND CoinVisualTests run
--renderer drawlist
--gl-profile compat
--only ${COIN_MATERIAL_VISUAL_SPECS}
--artifacts-dir ${CMAKE_BINARY_DIR}/render_artifacts
)
set_tests_properties(visual_gl_drawlist_material_compat
PROPERTIES LABELS "visual-render;visual-material")
add_test(
NAME visual_gl_drawlist_material_core
COMMAND CoinVisualTests run
--renderer drawlist
--gl-profile core
--only ${COIN_MATERIAL_VISUAL_SPECS}
--artifacts-dir ${CMAKE_BINARY_DIR}/render_artifacts
)
set_tests_properties(visual_gl_drawlist_material_core
PROPERTIES LABELS "visual-render;visual-material")
add_test(
NAME visual_gl_invalid_legacy_profile
COMMAND CoinVisualTests run
Expand Down
9 changes: 0 additions & 9 deletions data/shaders/gl/common/VertexColor.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,3 @@ vec4 coin_visual_color(vec4 vertexColor, vec4 uniformColor,
{
return useVertexColor > 0.5 ? vertexColor : uniformColor;
}

vec4 coin_visual_texture(vec4 color, sampler2D textureSampler,
vec2 texcoord, float textureEnabled,
vec4 textureModulation)
{
return textureEnabled > 0.5
? color * texture(textureSampler, texcoord) * textureModulation
: color;
}
31 changes: 31 additions & 0 deletions data/shaders/gl/material/AlphaTest.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Retained alpha-test comparison helper.
*
* The caller supplies the alpha whose coverage semantics apply to the
* producer. This module performs only the comparison; it does not decide
* pass ordering, blending, or which producer alpha should be tested.
*/

const int COIN_ALPHA_TEST_NONE = 0;
const int COIN_ALPHA_TEST_NEVER = 1;
const int COIN_ALPHA_TEST_ALWAYS = 2;
const int COIN_ALPHA_TEST_LESS = 3;
const int COIN_ALPHA_TEST_LEQUAL = 4;
const int COIN_ALPHA_TEST_EQUAL = 5;
const int COIN_ALPHA_TEST_GEQUAL = 6;
const int COIN_ALPHA_TEST_GREATER = 7;
const int COIN_ALPHA_TEST_NOTEQUAL = 8;

bool coin_material_alpha_test_pass(float alpha, int function,
float reference)
{
if (function == COIN_ALPHA_TEST_NEVER) return false;
if (function == COIN_ALPHA_TEST_ALWAYS) return true;
if (function == COIN_ALPHA_TEST_LESS) return alpha < reference;
if (function == COIN_ALPHA_TEST_LEQUAL) return alpha <= reference;
if (function == COIN_ALPHA_TEST_EQUAL) return alpha == reference;
if (function == COIN_ALPHA_TEST_GEQUAL) return alpha >= reference;
if (function == COIN_ALPHA_TEST_GREATER) return alpha > reference;
if (function == COIN_ALPHA_TEST_NOTEQUAL) return alpha != reference;
return true;
}
39 changes: 39 additions & 0 deletions data/shaders/gl/material/FragmentEvaluation.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Shared material and texture evaluation for surface fragments.
*
* The returned RGBA is the surface coverage used by visual, line, and point
* roots. Alpha testing remains a caller decision so alternate output roots
* can share coverage without sharing framebuffer or selection policy.
*/

uniform sampler2D u_texture;
uniform float u_textureEnabled;
uniform int u_textureModel;
uniform vec4 u_textureBlendColor;
uniform vec4 u_color;
uniform float u_useVertexColor;
uniform float u_vertexColorAlphaIncludesOpacity;
uniform float u_textureAlphaIncludesOpacity;
uniform float u_textureHasAlpha;
uniform int u_alphaTestFunction;
uniform float u_alphaTestReference;

#include "Texture.glsl"
#include "AlphaTest.glsl"

vec4
coin_surface_fragment_color(vec4 vertexColor, vec3 litColor, vec2 texcoord)
{
float materialAlpha = u_color.a;
if (u_useVertexColor > 0.5 &&
u_vertexColorAlphaIncludesOpacity > 0.5) {
materialAlpha = 1.0;
}
if (u_textureEnabled > 0.5) {
return coin_material_textured_color(
u_texture, texcoord, vec4(litColor, vertexColor.a), materialAlpha,
u_textureAlphaIncludesOpacity, u_textureHasAlpha, u_textureModel,
u_textureBlendColor);
}
return vec4(litColor, vertexColor.a * materialAlpha);
}
66 changes: 66 additions & 0 deletions data/shaders/gl/material/Lighting.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Retained Gouraud lighting evaluation.
*
* Inputs are the captured view-space light/material uniforms and the base
* surface color. This module computes lighting only; framebuffer, pass,
* texture and alpha-test policy belong to the calling shader roots.
*/

const int COIN_MAX_LIGHTS = 8;
const int COIN_LIGHT_DIRECTIONAL = 0;
const int COIN_LIGHT_POINT = 1;
const int COIN_LIGHT_SPOT = 2;

vec3 coin_material_compute_gouraud_color(vec3 eyePos, vec3 eyeNormal,
vec3 baseColor)
{
vec3 N = normalize(eyeNormal);
vec3 V = normalize(-eyePos);
// Coin's LegacyGL path leaves GL_LIGHT_MODEL_LOCAL_VIEWER at its default
// false value, so the fixed-function half-vector uses a viewer direction
// of (0, 0, 1) in eye space rather than a per-vertex eye position.
vec3 specularViewer = vec3(0.0, 0.0, 1.0);
if (u_twoSidedLighting > 0.5 && dot(N, V) < 0.0) {
N = -N;
}
vec3 litColor = u_ambientLight * u_materialAmbient;

for (int i = 0; i < COIN_MAX_LIGHTS; ++i) {
if (i >= u_lightCount) break;

vec3 L = u_lightDirection[i];
float attenuation = 1.0;
float spotFactor = 1.0;
if (u_lightType[i] != COIN_LIGHT_DIRECTIONAL) {
vec3 lightVector = u_lightPosition[i] - eyePos;
float distanceToLight = length(lightVector);
if (distanceToLight <= 0.0001) continue;
L = lightVector / distanceToLight;
vec3 att = u_lightAttenuation[i];
attenuation = 1.0 / max(att.z + att.y * distanceToLight +
att.x * distanceToLight * distanceToLight,
0.0001);
if (u_lightType[i] == COIN_LIGHT_SPOT) {
vec3 coneDir = normalize(u_lightDirection[i]);
vec3 fromLight = normalize(eyePos - u_lightPosition[i]);
float spotCos = dot(coneDir, fromLight);
if (spotCos < u_lightSpotParams[i].x) continue;
spotFactor = pow(max(spotCos, 0.0), u_lightSpotParams[i].y);
}
}

vec3 Ln = normalize(L);
float NdotL = max(dot(N, Ln), 0.0);
if (NdotL <= 0.0) continue;
vec3 H = normalize(Ln + specularViewer);
float NdotH = max(dot(N, H), 0.0);
float shininess = max(u_materialShininess * 128.0, 0.0);
float specularFactor = shininess > 0.0
? pow(NdotH, shininess) : 0.0;
vec3 diffuse = baseColor * NdotL;
vec3 specular = u_materialSpecular * specularFactor;
litColor += u_lightColor[i] * attenuation * spotFactor *
(diffuse + specular);
}
return clamp(litColor + u_emissiveColor, 0.0, 1.0);
}
47 changes: 47 additions & 0 deletions data/shaders/gl/material/Texture.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Retained material texture evaluation.
*
* Applies Coin's texture model and alpha semantics to a supplied surface
* color. It does not choose a render pass or perform alpha testing; callers
* retain those decisions explicitly so visual, picking, and selection roots
* can share coverage without sharing output policy.
*/

const int COIN_TEXTURE_MODEL_MODULATE = 0;
const int COIN_TEXTURE_MODEL_DECAL = 1;
const int COIN_TEXTURE_MODEL_BLEND = 2;
const int COIN_TEXTURE_MODEL_REPLACE = 3;

vec4 coin_material_textured_color(sampler2D textureSampler, vec2 texcoord,
vec4 visualColor, float materialAlpha,
float textureAlphaIncludesOpacity,
float textureHasAlpha,
int textureModel, vec4 blendColor)
{
vec4 texel = texture(textureSampler, texcoord);
float primaryAlpha = visualColor.a *
(textureAlphaIncludesOpacity > 0.5 ? 1.0 : materialAlpha);
float textureAlpha = textureHasAlpha > 0.5 ? texel.a : 1.0;
vec3 rgb = visualColor.rgb;
float alpha = primaryAlpha;

switch (textureModel) {
case COIN_TEXTURE_MODEL_DECAL:
rgb = mix(visualColor.rgb, texel.rgb, textureAlpha);
break;
case COIN_TEXTURE_MODEL_BLEND:
rgb = mix(visualColor.rgb, blendColor.rgb, texel.rgb);
alpha = primaryAlpha * textureAlpha;
break;
case COIN_TEXTURE_MODEL_REPLACE:
rgb = texel.rgb;
alpha = textureHasAlpha > 0.5 ? texel.a : primaryAlpha;
break;
case COIN_TEXTURE_MODEL_MODULATE:
default:
rgb = visualColor.rgb * texel.rgb;
alpha = primaryAlpha * textureAlpha;
break;
}
return vec4(rgb, alpha);
}
47 changes: 47 additions & 0 deletions data/shaders/gl/material/VertexEvaluation.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Shared surface evaluation for visual, wide-line, and point vertex stages.
*
* This module selects vertex color and computes optional view-space lighting.
* It owns no framebuffer output, raster-path selection, pass ordering, or
* alpha-test decision.
*/

#include "../common/VertexColor.glsl"

uniform mat4 u_proj;
uniform mat4 u_view;
uniform mat4 u_model;
uniform vec4 u_color;
uniform float u_useVertexColor;
uniform int u_shadingModel;
uniform vec3 u_emissiveColor;
uniform vec3 u_ambientLight;
uniform vec3 u_materialAmbient;
uniform vec3 u_materialSpecular;
uniform float u_materialShininess;
uniform float u_twoSidedLighting;
uniform int u_lightCount;
uniform int u_lightType[8];
uniform vec3 u_lightColor[8];
uniform vec3 u_lightDirection[8];
uniform vec3 u_lightPosition[8];
uniform vec3 u_lightAttenuation[8];
uniform vec2 u_lightSpotParams[8];

#include "Lighting.glsl"

vec4
coin_surface_vertex_color(vec4 vertexColor)
{
return coin_visual_color(vertexColor, vec4(u_color.rgb, 1.0),
u_useVertexColor);
}

vec3
coin_surface_lit_color(vec4 vertexColor, vec3 eyePosition, vec3 eyeNormal)
{
return u_shadingModel == 0
? vertexColor.rgb
: coin_material_compute_gouraud_color(eyePosition, eyeNormal,
vertexColor.rgb);
}
17 changes: 8 additions & 9 deletions data/shaders/gl/visual/Fragment.glsl
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#version 330 core

/* Base retained visual fragment root: evaluate the bound surface and emit
* framebuffer color. Coverage policy remains explicit at this root. */
#include "../common/VertexColor.glsl"

uniform sampler2D u_texture;
uniform float u_textureEnabled;
uniform vec4 u_texModColor;
/* Visual surface fragment root: shared surface evaluation, explicit alpha
* test, then framebuffer color. */
#include "../material/FragmentEvaluation.glsl"

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

out vec4 fragColor;

void main()
{
fragColor = coin_visual_texture(v_color, u_texture, v_texcoord,
u_textureEnabled, u_texModColor);
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;
fragColor = color;
}
33 changes: 16 additions & 17 deletions data/shaders/gl/visual/Vertex.glsl
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
#version 330 core

/*
* Base retained visual vertex root. The OpenGL backend requires 3.3 or newer;
* executable roots therefore use GLSL 330 core. Included files are semantic
* modules and intentionally provide no version directive or main().
*/
#include "../common/VertexColor.glsl"

/* Visual surface vertex root. The backend requires OpenGL 3.3 or newer, so
* executable roots use GLSL 330 core; this root wires shared vertex color and
* lighting evaluation into the ordinary triangle pipeline. */
#include "../material/VertexEvaluation.glsl"
layout(location = 0) in vec3 a_position;
layout(location = 1) in vec4 a_color;
layout(location = 2) in vec2 a_texcoord;

uniform mat4 u_proj;
uniform mat4 u_view;
uniform mat4 u_model;
uniform vec4 u_color;
uniform float u_useVertexColor;
layout(location = 1) in vec3 a_normal;
layout(location = 2) in vec4 a_color;
layout(location = 3) in vec2 a_texcoord;

out vec4 v_color;
out vec3 v_litColor;
out vec2 v_texcoord;

void main()
{
v_color = (u_useVertexColor > 0.5) ? a_color : u_color;
v_color = coin_surface_vertex_color(a_color);
v_texcoord = a_texcoord;
gl_Position = u_proj * u_view * u_model * vec4(a_position, 1.0);

vec4 worldPos = u_model * vec4(a_position, 1.0);
vec4 eyePos = u_view * worldPos;
mat3 normalMatrix = transpose(inverse(mat3(u_view * u_model)));
vec3 eyeNormal = normalMatrix * a_normal;
v_litColor = coin_surface_lit_color(v_color, eyePos.xyz, eyeNormal);
gl_Position = u_proj * eyePos;
}
8 changes: 8 additions & 0 deletions include/Inventor/actions/SoIRRenderAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ class COIN_DLL_API SoIRRenderAction : public SoAction {
*/
void * allocateGeometryStorage(size_t bytes, size_t alignment = alignof(float));

//! Copy one texture payload into the current frame, reusing an existing copy.
const unsigned char * allocateTextureStorage(const unsigned char * source,
size_t bytes,
int width,
int height,
int numComponents,
bool & hasTransparency);

//! Push a primitive collector for subsequent fallback primitive generation.
void pushPrimitiveCollector(PrimitiveCollector * collector);
//! Pop the current primitive collector. The caller must pop in stack order.
Expand Down
3 changes: 2 additions & 1 deletion include/Inventor/elements/SoLazyElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ class COIN_DLL_API SoLazyElement : public SoElement {
virtual void setAlphaTestElt(int func, float value);

private:
SoLazyElementP * pimpl; // for future use
friend class SoLazyElementP;
SoLazyElementP * pimpl = nullptr;

};

Expand Down
2 changes: 2 additions & 0 deletions include/Inventor/nodes/SoAlphaTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class COIN_DLL_API SoAlphaTest : public SoNode {
SoSFEnum function;
SoSFFloat value;

void doAction(SoAction * action) override;

#if COIN_HAVE_LEGACY_GL_RENDERER
void GLRender(SoGLRenderAction * action) override;
#endif
Expand Down
Loading
Loading