View Issue Details

IDProjectCategoryView StatusLast Update
0024192Open CASCADEOCCT:Visualizationpublic2021-04-09 12:10
ReporterdbpAssigned Toabv  
PrioritynormalSeverityfeature 
Status closedResolutionfixed 
PlatformAOSL 
Target Version6.7.0Fixed in Version6.7.0 
Summary0024192: Adding support for shaders to OCCT visualization toolkit
DescriptionThe purpose of this feature is implementing the following functionality:

1. Support of both modern (3.0 and higher) and old versions of OpenGL and GLSL. Interoperability between 'old' and 'new' shader sources - by implementing custom shader programming interface.

2. Setting individual shader programs for different types of primitives.

3. Possibility of setting shader program 'by default', for presentation and for individual group inside presentation.

4. Possibility of manipulating shaders from application level, including adding and removing shader programs and setting non-standard shader variables. Thus, application developer can implement custom rendering techniques.
Additional information
and documentation updates
The purpose of this feature is adding support of GLSL shaders to OCCT visualization core. Shaders allow to implement different rendering effects on graphics hardware with a high degree of flexibility, such as per-pixel lighting, custom shading models, bump mapping, procedural texturing and others. Currently OCCT supports only vertex and fragment GLSL shader, but this functionality will be extended in future releases.


To set custom vertex and fragment GLSL shaders in DRAW the following command is used:

vshaderprog <ShapeName> <Path to Vertex Shader> <Path to Fragment Shader>

To detach shader program from specific shape, use the following command:

vshaderprog <ShapeName> off

Note, that to execute shader programs the OpenGL 2.0+ GPU is required.


To enable custom shader for specific AISShape in your application, the following API functions are used:

// Create shader program
Handle(Graphic3d_ShaderProgram) aProgram = new Graphic3d_ShaderProgram();

// Attach vertex shader
aProgram->AttachShader (Graphic3d_ShaderObject::CreateFromFile(
                               Graphic3d_TOS_VERTEX, "<Path to VS>"));

// Attach fragment shader
aProgram->AttachShader (Graphic3d_ShaderObject::CreateFromFile(
                               Graphic3d_TOS_FRAGMENT, "<Path to FS>"));

// Set values for custom uniform variables (if they are)
aProgram->PushVariable ("MyColor", Graphic3d_Vec3(0.f, 1.f, 0.f));

// Set aspect property for specific AISShape
AISShape->Attributes()->ShadingAspect()->Aspect()->SetShaderProgram (aProgram);



TagsNo tags attached.
Test case numberNot needed

Attached Files

  • Normal.vs (211 bytes)
  • Normal.fs (85 bytes)

Relationships

parent of 0024241 closeddbp Open CASCADE Adding shaders directory to OCCT resources 
parent of 0030126 newkgv Open CASCADE Visualization, Graphic3d_ShaderManager - define standard Lighting & Clipping within custom GLSL programs as template functions 
parent of 0031715 closedbugmaster Open CASCADE Visualization, OpenGl_ShaderProgram - add access to proxy shader program 
parent of 0032289 closedbugmaster Open CASCADE Visualization - add NCollection_Mat3 for 3x3 matrix similar to NCollection_Mat4 
related to 0024228 closedabv Open CASCADE TKOpenGL - destroy GL context at view close 
related to 0026275 closedbugmaster Open CASCADE Visualization, TKOpenGl - add public constructor for OpenGl_ShaderProgram 
Not all the children of this issue are yet resolved or closed.

Activities

kgv

2013-10-08 13:03

developer   ~0025955

Dear dbp,

please post/attach the following info as soon as patch will be available:
- Image comparison on several test cases (with/without shaders).
- Performance comparison (including CPU times) on several test cases (including big number of simple objects with different presentation mode / interleaved presentation mode).

dbp

2013-10-08 17:12

developer   ~0025973

Dear kgv,

Preliminary version of shader fucntionality is ready for review (branch CR24192_2).

Could you please have a look at it?

dbp

2013-10-09 19:10

developer   ~0026001

Dear apl,

the patch CR24192 is ready for review (branch CR24192).

Could you please have a look at it?

apl

2013-10-09 21:43

developer   ~0026002

Dear Bugmaster,

The branch CR24192 is ready for tests.

Please test.

mkv

2013-10-10 08:34

tester   ~0026004

Dear BugMaster,

Branch CR24192 (and products from GIT master) was compiled on Linux and Windows platforms.

There is compilation error on Linux platform:
http://jenkins-test-02.nnov.opencascade.com:8080/user/mnt/my-views/view/CR24192/job/mnt-CR24192-master_build_occt_linux/1/parsed_console/?
In file included from ../../../../inc/Graphic3d_ShaderVariable.hxx:179,
from ../../../../inc/Graphic3d_ShaderProgram.hxx:25,
from ../../../../src/Graphic3d/Graphic3d_Group_8.cxx:49:
../../../../inc/Graphic3d_ShaderVariable_Impl.lxx:61: error: cannot declare member function ‘static Graphic3d_ShaderVariable* Graphic3d_ShaderVariable::Create(const TCollection_AsciiString&, const T&)’ to have static linkage
make[2]: *** [Graphic3d_Group_8.lo] Error 1

kgv

2013-10-10 10:56

developer   ~0026015

Patch CR24192 has been updated.

apl

2013-10-10 12:51

developer   ~0026020

Dear Bugmaster,

The compilation error corrected.

Please proceed.

dbp

2013-10-10 15:38

developer   ~0026025

According to frame rate comparison, there is no a performance regression when the feature is not used (no shader programs are used). The results shown for 6400 small boxes.

Before the patch:
----------------------------------
FPS: 56.800739991127884
CPU: 17.78411399999996 msec

After the patch:
----------------------------------
FPS: 58.451109685153412
CPU: 17.31611099999995 msec

For performance estimation the following script was used:

pload ALL
vinit w=1024 h=768
vsetdispmode 1
set N 1
for {set X 1} {$X <= 80} {incr X} { for {set Y 1} {$Y <= 80} {incr Y} { box b${N} [expr $X * 20] [expr $Y * 20] [expr 50 * ( sin($X) + sin($Y) )] 10 10 25; vdisplay b${N}; incr N; } }
vfit
vfps

dbp

2013-10-10 16:11

developer   ~0026029

Last edited: 2013-10-10 16:47

Then using individual 'Phong Shading' shader (per-pixel lighting) for each box, the performance regression for previous test is about 50% (6400 boxes):

FPS: 28.340777629084517
CPU: 35.256225999999913 msec

Then using the same 'Phong Shading' shader program (per-pixel lighting) for all boxes, the performance regression is about 33%:

FPS: 37.848268270758574
CPU: 26.208168000000001 msec

Then using the same 'Gouraud Shading' shader program (per-vertex lighting like FFP) for all boxes, the performance regression is about 14%:

FPS: 48.030730269723115
CPU: 20.904133999999885 msec

So, it seems that shader functionality does not increase the CPU load significantly. Simple profiling showed, that performance decrease is largely due to switching graphics pipeline state (calling of glUseProgram).

All tests were performed with Windows 7 PC: Core i5 3.1 GHz, AMD Radeon 7870.

abv

2013-10-10 16:25

manager   ~0026031

Could you please test also on some real-case model, like Vessel_Head?

dbp

2013-10-10 16:56

developer   ~0026032

For real-life shape with fine tesselation (6M triangles) the results are the following.

Before the patch
----------------------------------
FPS: 137.43942063408832
CPU: 5.6160359999999798 msec

After the patch (NO shaders)
----------------------------------
FPS: 145.7065051774959
CPU: 5.9280379999999866 msec

After the patch + 'Gouraud Shading' shader
-------------------------------------------
FPS: 143.91671800136763
CPU: 5.6160359999999798 msec

After the patch + 'Phong Shading' shader
-------------------------------------------
FPS: 143.1793642049785
CPU: 6.2400399999999934 msec

So, then using custom shaders for single object (or small number of objects) thre is no performance regression.

dbp

2013-10-10 17:00

developer  

Normal.vs (211 bytes)

dbp

2013-10-10 17:00

developer  

Normal.fs (85 bytes)

dbp

2013-10-10 17:04

developer   ~0026033

For testing shader functionality the simplest 'Normal' shaders can be used (attached to this issue).

To set up custom shader program for AIS interactive object, the following DRAW script can be used:

pload ALL
vinit
vsetdispmode 1
restore <PATH TO SHAPE> SHAPE
vdisplay SHAPE
vshaderprog SHAPE <PATH TO VERTEX SHADER> <PATH TO FRAGMENT SHADER>

mkv

2013-10-11 06:58

tester   ~0026036

Dear BugMaster,

Branch CR24192 (and products from GIT master) was compiled on Linux and Windows platforms.

There is compilation error on Linux platform:
http://jenkins-test-02.nnov.opencascade.com:8080/user/mnt/my-views/view/CR24192/job/mnt-CR24192-master_build_occt_linux/1/parsed_console/?
../../../../src/Graphic3d/Graphic3d_ShaderVariable.cxx:30: error: expected unqualified-id before ‘;’ token
../../../../src/Graphic3d/Graphic3d_ShaderVariable.cxx:31: error: expected unqualified-id before ‘;’ token
../../../../src/Graphic3d/Graphic3d_ShaderVariable.cxx:32: error: expected unqualified-id before ‘;’ token
../../../../src/Graphic3d/Graphic3d_ShaderVariable.cxx:33: error: expected unqualified-id before ‘;’ token
../../../../src/Graphic3d/Graphic3d_ShaderVariable.cxx:34: error: expected unqualified-id before ‘;’ token
../../../../src/Graphic3d/Graphic3d_ShaderVariable.cxx:35: error: expected unqualified-id before ‘;’ token
../../../../src/Graphic3d/Graphic3d_ShaderVariable.cxx:36: error: expected unqualified-id before ‘;’ token
../../../../src/Graphic3d/Graphic3d_ShaderVariable.cxx:37: error: expected unqualified-id before ‘;’ token
make[2]: *** [Graphic3d_ShaderVariable.lo] Error 1

apl

2013-10-17 19:30

developer   ~0026130

Dear dbp,

The solution for proper initialization of resources is implemented in branch CR24192. The branch is based on CR24228 (the original version of the patch for resources).

Could you please review it?

dbp

2013-10-18 14:06

developer   ~0026141

Dear Bugmaster,

The compilation error was corrected (branch CR24192).

Please proceed.

mkv

2013-10-21 12:18

tester   ~0026156

Dear BugMaster,

Branch CR24192 (and products from GIT master) was compiled on Linux and Windows platforms and tested.
SHA-1: 14a2a50abeb4268a8dfe48b8c663355575ebec90

Number of compiler warnings:

occt component :
Linux: 365 (368 on master)
Windows: 6 (6 on master)

products component :
Linux: 189 (190 on master)
Windows: 287 (287 on master)

Regressions/Differences:
http://occt-tests/CR24192-master-occt/Windows-32-VC9/bugs/vis/bug23654_MarkersRecompute.html
bugs vis(004) bug23654_MarkersRecompute: FAILED (exception)

Testing cases:
Not needed

Testing on Linux:
Total MEMORY difference: 355386952 / 353811788
Total CPU difference: 41218.42000000063 / 42952.64000000077

Testing on Windows:
Total MEMORY difference: 407624752 / 406995556
Total CPU difference: 25346.65625 / 37404.296875

There are not differences in images found by testdiff.

apl

2013-10-21 12:37

developer   ~0026157

Dear dbp,

The branch CR24192 is rebased for the current state of CR24228. CR24228 improves approach to managing resources and contains changes necessary for CR24192. The reported problem is already fixed in its current state.

Please review.

dbp

2013-10-21 12:55

developer   ~0026158

Dear Bugmaster,

please re-test (branch CR24192).

dbp

2013-10-21 14:25

developer   ~0026167

Dear mkv,

The crash in DrawElements function when using shaders is produced by Mesa's software OpenGL implementation. Patch is ok, and testing my be continued.

mkv

2013-10-23 08:46

tester   ~0026224

Dear BugMaster,

Branch CR24192 (and products from GIT master) was compiled on Linux and Windows platforms and tested.
SHA-1: 7c67468be1f9f118485f2fd42484b7b4c42c57a2

Number of compiler warnings:

occt component :
Linux: 362 (368 on master)
Windows: 6 (6 on master)

products component :
Linux: 189 (190 on master)
Windows: 287 (287 on master)

Regressions/Differences:
No regressions/differences

Testing cases:
Not needed

Testing on Linux:
Total MEMORY difference: 355499732 / 353799020
Total CPU difference: 43739.12000000061 / 42953.02000000077

Testing on Windows:
Total MEMORY difference: 408358948 / 407073520
Total CPU difference: 31213.734375 / 37415.03125

There are not differences in images found by testdiff.

apl

2013-10-23 09:03

developer   ~0026231

Dear dbp,

Please fill in description sections.

Related Changesets

occt: master 30f0ad28

2013-10-21 07:47:10

abv


Committer: abv Details Diff
0024192: Adding support for shaders to OCCT visualization toolkit Affected Issues
0024192
mod - src/Graphic3d/FILES Diff File
mod - src/Graphic3d/Graphic3d.cdl Diff File
mod - src/Graphic3d/Graphic3d_AspectFillArea3d.cdl Diff File
mod - src/Graphic3d/Graphic3d_AspectFillArea3d.cxx Diff File
mod - src/Graphic3d/Graphic3d_AspectLine3d.cdl Diff File
mod - src/Graphic3d/Graphic3d_AspectLine3d.cxx Diff File
mod - src/Graphic3d/Graphic3d_AspectMarker3d.cdl Diff File
mod - src/Graphic3d/Graphic3d_AspectMarker3d.cxx Diff File
mod - src/Graphic3d/Graphic3d_AspectText3d.cdl Diff File
mod - src/Graphic3d/Graphic3d_AspectText3d.cxx Diff File
mod - src/Graphic3d/Graphic3d_CGroup.hxx Diff File
mod - src/Graphic3d/Graphic3d_Group_8.cxx Diff File
add - src/Graphic3d/Graphic3d_ShaderObject.cxx Diff File
add - src/Graphic3d/Graphic3d_ShaderObject.hxx Diff File
add - src/Graphic3d/Graphic3d_ShaderObject_Handle.hxx Diff File
add - src/Graphic3d/Graphic3d_ShaderProgram.cxx Diff File
add - src/Graphic3d/Graphic3d_ShaderProgram.hxx Diff File
add - src/Graphic3d/Graphic3d_ShaderProgram_Handle.hxx Diff File
add - src/Graphic3d/Graphic3d_ShaderVariable.cxx Diff File
add - src/Graphic3d/Graphic3d_ShaderVariable.hxx Diff File
add - src/Graphic3d/Graphic3d_ShaderVariable.lxx Diff File
add - src/Graphic3d/Graphic3d_ShaderVariable_Handle.hxx Diff File
add - src/Graphic3d/Graphic3d_TypeOfShaderObject.hxx Diff File
mod - src/InterfaceGraphic/InterfaceGraphic_Graphic3d.hxx Diff File
mod - src/NCollection/FILES Diff File
add - src/NCollection/NCollection_Mat4.hxx Diff File
mod - src/OpenGl/FILES Diff File
add - src/OpenGl/Handle_OpenGl_ShaderManager.hxx Diff File
add - src/OpenGl/Handle_OpenGl_ShaderObject.hxx Diff File
add - src/OpenGl/Handle_OpenGl_ShaderProgram.hxx Diff File
mod - src/OpenGl/OpenGl_AspectFace.cxx Diff File
mod - src/OpenGl/OpenGl_AspectFace.hxx Diff File
mod - src/OpenGl/OpenGl_AspectLine.cxx Diff File
mod - src/OpenGl/OpenGl_AspectLine.hxx Diff File
mod - src/OpenGl/OpenGl_AspectMarker.cxx Diff File
mod - src/OpenGl/OpenGl_AspectMarker.hxx Diff File
mod - src/OpenGl/OpenGl_AspectText.cxx Diff File
mod - src/OpenGl/OpenGl_AspectText.hxx Diff File
mod - src/OpenGl/OpenGl_Context.cxx Diff File
mod - src/OpenGl/OpenGl_Context.hxx Diff File
mod - src/OpenGl/OpenGl_GraphicDriver_Layer.cxx Diff File
mod - src/OpenGl/OpenGl_Group.cxx Diff File
mod - src/OpenGl/OpenGl_PrimitiveArray.cxx Diff File
add - src/OpenGl/OpenGl_ShaderManager.cxx Diff File
add - src/OpenGl/OpenGl_ShaderManager.hxx Diff File
add - src/OpenGl/OpenGl_ShaderObject.cxx Diff File
add - src/OpenGl/OpenGl_ShaderObject.hxx Diff File
add - src/OpenGl/OpenGl_ShaderProgram.cxx Diff File
add - src/OpenGl/OpenGl_ShaderProgram.hxx Diff File
add - src/OpenGl/OpenGl_ShaderStates.cxx Diff File
add - src/OpenGl/OpenGl_ShaderStates.hxx Diff File
mod - src/OpenGl/OpenGl_Structure.cxx Diff File
mod - src/OpenGl/OpenGl_Structure.hxx Diff File
mod - src/OpenGl/OpenGl_Text.cxx Diff File
mod - src/OpenGl/OpenGl_TextFormatter.cxx Diff File
mod - src/OpenGl/OpenGl_Trihedron.cxx Diff File
mod - src/OpenGl/OpenGl_Vec.hxx Diff File
mod - src/OpenGl/OpenGl_View.cxx Diff File
mod - src/OpenGl/OpenGl_View.hxx Diff File
mod - src/OpenGl/OpenGl_View_2.cxx Diff File
mod - src/OpenGl/OpenGl_Workspace.hxx Diff File
mod - src/OpenGl/OpenGl_Workspace_5.cxx Diff File
add - src/Shaders/Declarations.glsl Diff File
mod - src/ViewerTest/ViewerTest.cxx Diff File

Issue History

Date Modified Username Field Change
2013-09-19 11:40 dbp New Issue
2013-09-19 11:40 dbp Assigned To => san
2013-10-04 17:10 san Assigned To san => dbp
2013-10-04 17:10 san Status new => assigned
2013-10-08 13:03 kgv Note Added: 0025955
2013-10-08 15:29 dbp Relationship added parent of 0024241
2013-10-08 17:12 dbp Note Added: 0025973
2013-10-08 17:12 dbp Assigned To dbp => kgv
2013-10-08 17:12 dbp Status assigned => resolved
2013-10-09 08:48 kgv Assigned To kgv => dbp
2013-10-09 08:48 kgv Status resolved => assigned
2013-10-09 19:10 dbp Note Added: 0026001
2013-10-09 19:10 dbp Assigned To dbp => apl
2013-10-09 19:10 dbp Status assigned => resolved
2013-10-09 21:43 apl Note Added: 0026002
2013-10-09 21:43 apl Assigned To apl => bugmaster
2013-10-09 21:43 apl Status resolved => reviewed
2013-10-10 08:34 mkv Assigned To bugmaster => mkv
2013-10-10 08:34 mkv Note Added: 0026004
2013-10-10 08:35 mkv Assigned To mkv => dbp
2013-10-10 08:35 mkv Status reviewed => assigned
2013-10-10 10:56 kgv Note Added: 0026015
2013-10-10 12:49 apl Assigned To dbp => apl
2013-10-10 12:49 apl Status assigned => resolved
2013-10-10 12:51 apl Note Added: 0026020
2013-10-10 12:51 apl Assigned To apl => bugmaster
2013-10-10 12:51 apl Status resolved => reviewed
2013-10-10 13:52 mkv Assigned To bugmaster => mkv
2013-10-10 15:38 dbp Note Added: 0026025
2013-10-10 16:11 dbp Note Added: 0026029
2013-10-10 16:25 abv Note Added: 0026031
2013-10-10 16:42 dbp Note Edited: 0026029
2013-10-10 16:47 dbp Note Edited: 0026029
2013-10-10 16:56 dbp Note Added: 0026032
2013-10-10 17:00 dbp File Added: Normal.vs
2013-10-10 17:00 dbp File Added: Normal.fs
2013-10-10 17:04 dbp Note Added: 0026033
2013-10-11 06:58 mkv Note Added: 0026036
2013-10-11 06:59 mkv Assigned To mkv => dbp
2013-10-11 06:59 mkv Status reviewed => assigned
2013-10-17 15:28 apl Relationship added related to 0024228
2013-10-17 19:30 apl Note Added: 0026130
2013-10-17 19:30 apl Status assigned => resolved
2013-10-18 14:06 dbp Note Added: 0026141
2013-10-18 14:06 dbp Assigned To dbp => bugmaster
2013-10-18 14:06 dbp Status resolved => reviewed
2013-10-18 14:37 mkv Assigned To bugmaster => mkv
2013-10-21 12:18 mkv Note Added: 0026156
2013-10-21 12:18 mkv Test case number => Not needed
2013-10-21 12:18 mkv Assigned To mkv => apl
2013-10-21 12:18 mkv Status reviewed => assigned
2013-10-21 12:37 apl Note Added: 0026157
2013-10-21 12:37 apl Assigned To apl => dbp
2013-10-21 12:37 apl Status assigned => resolved
2013-10-21 12:55 dbp Note Added: 0026158
2013-10-21 12:55 dbp Assigned To dbp => bugmaster
2013-10-21 12:55 dbp Status resolved => reviewed
2013-10-21 13:39 bugmaster Assigned To bugmaster => mkv
2013-10-21 13:42 mkv Assigned To mkv => dbp
2013-10-21 13:42 mkv Status reviewed => feedback
2013-10-21 14:25 dbp Note Added: 0026167
2013-10-21 14:25 dbp Assigned To dbp => mkv
2013-10-21 14:25 dbp Status feedback => reviewed
2013-10-22 09:55 abv Target Version => 6.7.0
2013-10-23 08:46 mkv Note Added: 0026224
2013-10-23 08:47 mkv Assigned To mkv => bugmaster
2013-10-23 08:47 mkv Status reviewed => tested
2013-10-23 09:03 apl Note Added: 0026231
2013-10-25 14:42 abv Changeset attached => occt master 30f0ad28
2013-10-25 14:42 abv Assigned To bugmaster => abv
2013-10-25 14:42 abv Status tested => verified
2013-10-25 14:42 abv Resolution open => fixed
2013-10-28 17:17 dbp Additional Information Updated
2013-12-19 13:51 bugmaster Status verified => closed
2013-12-19 13:58 bugmaster Fixed in Version => 6.7.0
2015-05-29 12:16 kgv Relationship added related to 0026275
2018-09-11 14:13 kgv Relationship added parent of 0030126
2020-08-18 16:08 kgv Relationship added parent of 0031715
2021-04-09 12:10 kgv Relationship added parent of 0032289