{"id":172,"date":"2023-02-21T16:18:01","date_gmt":"2023-02-21T16:18:01","guid":{"rendered":"https:\/\/oiv10wp.athena-dev.net\/?page_id=172"},"modified":"2024-10-14T09:06:13","modified_gmt":"2024-10-14T09:06:13","slug":"upgrade-oiv9-shader-code","status":"publish","type":"page","link":"https:\/\/developer.openinventor.com\/index.php\/general-documentation\/upgrade-oiv9-shader-code\/","title":{"rendered":"Upgrade your Open Inventor 9 shader code"},"content":{"rendered":"<div class=\"page-content\">\n<h3>Introduction<\/h3>\n<p style=\"text-align: justify;\">Starting with version 10, Open Inventor\u00ae provides a <strong>GLSL <strong>shader API<\/strong><\/strong>&nbsp;to access various state values from shaders. The classical GLSL built-in uniforms for OpenGL state (e.g. gl_ModelViewMatrix) now have a corresponding Open Inventor GLSL method (e.g. OivModelViewMatrix()).&nbsp; These methods are documented in the Reference Manual and in $OIVHOME\/shaders\/include\/Inventor\/oivShaderState.h.&nbsp; GLSL built-in constants (e.g. gl_MaxVertexAttribs) and GLSL built-in input\/output variables (e.g. gl_FragCoord) are still available. &nbsp;GLSL functions such as<u> <\/u><em>cos, mix, greaterThan<\/em>, and so on, are still available.<br \/>\n<strong>&nbsp;<\/strong><br \/>\n<strong><strong>Note:<\/strong><\/strong>&nbsp;Even if some of the built-in GLSL state variables continue to work,&nbsp;<strong>you should no longer use them<\/strong>.<br \/>\n<strong>Note:<\/strong>&nbsp;Some changes to existing GLSL shader code are <strong>mandatory<\/strong>.<br \/>\n<strong><br \/>\nTable of content<\/strong><\/p>\n<ul>\n<li><a href=\"#ExistingShader\">Converting existing shader<\/a><\/li>\n<li><a href=\"#GLSL\">GLSL Version<\/a><\/li>\n<li><a href=\"#VertextAtttrib\">Vertex attributes conversion<\/a><\/li>\n<li><a href=\"#BuiltIn-uniforms\">Built-in uniforms conversion<\/a>\n<ul>\n<li><a href=\"#matrices\">Matrices<\/a><\/li>\n<li><a href=\"#material\">Material<\/a><\/li>\n<li><a href=\"#Lighting\">Lighting<\/a><\/li>\n<li><a href=\"#Misc\">Misc<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#builtins-varyings\">Built-in varyings conversion<\/a>\n<ul>\n<li><a href=\"#inputs\">Inputs<\/a><\/li>\n<li><a href=\"#Outputs\">Outputs<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#transparency\">Manage transparency<\/a><\/li>\n<li><a href=\"#geomshader\">Geometry shader<\/a><\/li>\n<li><a href=\"#passthrough\">PassThrough Helpers<\/a><\/li>\n<\/ul>\n<hr>\n<h3><a id=\"ExistingShader\" name=\"ExistingShader\"><\/a>Converting existing shaders<\/h3>\n<p>A script is provided in $<strong>OIVHOME\\tools\\source\\Inventor\\GLSLConverter\\GLSLConverter.py<\/strong> to help converting existing shaders.<\/p>\n<p style=\"text-align: justify;\">It's a simple python script that can be used to replace GLSL built-in uniforms with OIV shader API calls. It provides a simple way to port shaders that work in Open Inventor 9.x to shaders working in Open Inventor 10.<\/p>\n<p><u>Usage<\/u>: python <strong>GLSLConverter.py filename [--remove-original]<\/strong><\/p>\n<p style=\"text-align: justify;\">Where <strong>filename<\/strong> is the path to a file needing to be converted. It can also be a folder in which case the script will look for every file which name ends in <strong>'.glsl'<\/strong> to apply the single-file operation on it. Please note that the conversion process renames the original file <em>filename.origin<\/em> and the parsed file is saved under <em>filename<\/em>.<br \/>\nWith the '--remove-original' option, <em>filename.origin<\/em> file is automatically removed by the script.<\/p>\n<p style=\"text-align: justify;\">Note that only built-in uniforms exposed in the Open Inventor Shader API are replaced and others uniforms have to be handled in another way.<\/p>\n<p>The script will automatically do the built-in variable's conversion and add <strong>\/\/!oiv_include<\/strong> directive if needed.<\/p>\n<hr>\n<h3><a id=\"GLSL\" name=\"GLSL\"><\/a>GLSL Version<\/h3>\n<p style=\"text-align: justify;\">By default, Open Inventor builds GLSL shaders in&nbsp;<strong>410 compatibility<\/strong>&nbsp;mode.&nbsp; So it is not mandatory to specify&nbsp;<em>#version 410 compatibility<\/em>&nbsp;in your shader. But if you need a more recent version or some specific extensions, you'll have to specify it in your shader.<\/p>\n<p><strong>If you specify a version older than 410, Open Inventor will override it and compile in 410 anyway.<\/strong><\/p>\n<p>Even if a shader is built-in compatibility mode, it is good practice to respect the&nbsp;<strong>GLSL 410 specification<\/strong>. Otherwise you'll have a lot of messages saying:&nbsp;<em>\"Warning deprecated...\"<\/em>.<\/p>\n<p>Here is a list of common errors and how to fix them to avoid issues:<\/p>\n<ul>\n<li>Using <em>varying<\/em> keyword instead of <em>in\/out<\/em>:\n<ul>\n<li><u>In vertex shader:<\/u> replace <em>varying float value;<\/em> by <em>out float value;<\/em><\/li>\n<li><u>In fragment shader:<\/u> replace <em>varying float value;<\/em> by <em>in float value<\/em><\/li>\n<\/ul>\n<\/li>\n<li>Using <strong><em>gl_TexCoord[0]<\/em><\/strong> to pass <em>texcoord<\/em> from vertex to fragment shader intead of using <strong><em>in\/out varying<\/em><\/strong><\/li>\n<li>Using <strong><em>texture2D\/3D<\/em><\/strong> function instead of generic <strong><em>texture<\/em><\/strong>.<\/li>\n<\/ul>\n<hr>\n<h3><a id=\"VertextAtttrib\" name=\"VertextAtttrib\"><\/a>Vertex attributes conversion<\/h3>\n<p>If your shader uses GLSL built-in vertex attributes like <em>gl_Vertex<\/em>, you should replace these calls with corresponding OIV calls and add the following include at the top of your shader:<\/p>\n<p class=\"rteindent1\"><strong>\/\/!oiv_include &lt;Inventor\/oivShapeAttribute.h&gt;<\/strong><\/p>\n<p>Correspondence between built-in GLSL and Oiv methods:<\/p>\n<p><u><strong>Vertex attributes<\/strong><\/u><\/p>\n<ul>\n<li><em>gl_Vertex<\/em> can be replaced by&nbsp;<a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shape_attribute_8h.html#aee0d011de087b3dfd2a1573f86eb2b30\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>OivVertexPosition()<\/strong><\/a><\/li>\n<li><em>gl_Normal <\/em>can be replaced by&nbsp;<a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shape_attribute_8h.html#acf958a732002f98ea5d893f9a4ebdfc7\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>OivVertexNormal()<\/strong><\/a><\/li>\n<li><em>gl_Color <\/em>can be replaced by&nbsp;<a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shape_attribute_8h.html#acb55da73003763b590ade84c943215a1\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>OivVertexColor()<\/strong><\/a><\/li>\n<li><em>gl_MultiTexCoord[i]<\/em> can be replaced by&nbsp;<a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shape_attribute_8h.html#a389bc77a83704508e87f81451cdca221\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>OivVertexTextureCoordinate(i)<\/strong><\/a><\/li>\n<li><em>gl_TextureMatrix[i<\/em>] can be replaced by&nbsp;<a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#a916f9b9e5fb949183a1a39cba509eb4b\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>OivTextureMatrix(i)<\/strong><\/a><\/li>\n<\/ul>\n<p><strong>Note<\/strong>: Using custom vertex attributes inputs to retrieve vertex positions, normals, colors and texture coordinates will not work.<\/p>\n<p class=\"rteindent1\"><span style=\"font-family: courier new,courier,monospace;\">\/\/ This will not work anymore in Vertex Shader<br \/>\nlayout(location=0) in vec3 VertexPosition;<\/span><\/p>\n<hr>\n<h3><a id=\"BuiltIn-uniforms\" name=\"BuiltIn-uniforms\"><\/a>Built-in uniforms conversion<\/h3>\n<p>If your shader uses GLSL built-in uniforms like&nbsp;<em>gl_ModelViewMatrix<\/em>, you should replace these calls with corresponding Open Inventor calls and add the following include at the top of your shader:<br \/>\n<strong><br \/>\n\/\/!oiv_include &lt;Inventor\/oivShaderState.h&gt;<\/strong><\/p>\n<p>Here is the list of correspondence between built-in GLSL and Open Inventor available methods:<\/p>\n<p><strong><u><a id=\"matrices\" name=\"matrices\"><\/a>Matrices<\/u><\/strong><\/p>\n<ul>\n<li><em>gl_ModelViewMatrixInverse<\/em> can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#afdbcb3593e69874da8f2854bfad61e41\" target=\"_blank\" rel=\"noopener noreferrer\">OivModelViewMatrixInverse<\/a>()<\/strong><\/li>\n<li><em>gl_ModelViewMatrix<\/em> can be replaced by <strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#a599958c41a7195cc5f9d8b8f5db5c3c0\" target=\"_blank\" rel=\"noopener noreferrer\">OivModelViewMatrix<\/a>()<\/strong><\/li>\n<li><em>gl_NormalMatrix<\/em> can be replaced by <strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#ad82a50c2829f4daf217f9f5bc07c9199\" target=\"_blank\" rel=\"noopener noreferrer\">OivNormalMatrix<\/a>()<\/strong><\/li>\n<li><em>gl_ProjectionMatrix<\/em> can be replaced by <strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#a58d630b0c48d50536100595fb2f241a1\" target=\"_blank\" rel=\"noopener noreferrer\">OivProjectionMatrix<\/a>()<\/strong><\/li>\n<li><em>gl_ModelViewProjectionMatrix<\/em> can be replaced by <strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#adee020476e1b8b738623603fedc3a97b\" target=\"_blank\" rel=\"noopener noreferrer\">OivModelViewProjectionMatrix<\/a>()<\/strong><\/li>\n<\/ul>\n<p><strong><u><a id=\"material\" name=\"material\"><\/a>Material<\/u><\/strong><\/p>\n<ul>\n<li><em>gl_FrontMaterial.ambient<\/em> can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#a423e4135a91d14db317bd11798f2895e\" target=\"_blank\" rel=\"noopener noreferrer\">OivFrontMaterialAmbient<\/a>()<\/strong><\/li>\n<li><em>gl_FrontMaterial.diffuse<\/em> can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#abd014c10b51ea4c0178d1ba6d45044b4\" target=\"_blank\" rel=\"noopener noreferrer\">OivFrontMaterialDiffuse<\/a>()<\/strong><\/li>\n<li><em>gl_FrontMaterial.specular<\/em> can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#ae0fe19a867964fe9bf33c71c43f8625b\" target=\"_blank\" rel=\"noopener noreferrer\">OivFrontMaterialSpecular<\/a>()<\/strong><\/li>\n<li><em>gl_FrontMaterial.shininess<\/em> can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#a0ccbc139154d20161aa8e223758e9f24\" target=\"_blank\" rel=\"noopener noreferrer\">OivFrontMaterialShininess<\/a>()<\/strong><\/li>\n<li><em>gl_FrontMaterial.emission<\/em> can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#acab0a8d12300afaaef3b94645ce27ddb\" target=\"_blank\" rel=\"noopener noreferrer\">OivFrontMaterialEmissive<\/a>()<\/strong><\/li>\n<li><em>gl_BackMaterial.ambient<\/em> can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#af70fcfe5aef3d7fafc8b05f4a3e81a63\" target=\"_blank\" rel=\"noopener noreferrer\">OivBackMaterialAmbient<\/a>()<\/strong><\/li>\n<li><em>gl_BackMaterial.diffuse<\/em> can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#ae17ddb05a316d726590efaab7c6bf691\" target=\"_blank\" rel=\"noopener noreferrer\">OivBackMaterialDiffuse<\/a>()<\/strong><\/li>\n<li><em>gl_BackMaterial.specular<\/em> can be replaced by&nbsp; <strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#adf0627954a16be5f2e924ffe6f83423e\" target=\"_blank\" rel=\"noopener noreferrer\">OivBackMaterialSpecular<\/a>()<\/strong><\/li>\n<li><em>gl_BackMaterial.shininess<\/em> can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#a78d5f23e92abebdf40cc565565159a72\" target=\"_blank\" rel=\"noopener noreferrer\">OivBackMaterialShininess<\/a>()<\/strong><\/li>\n<li><em>gl_BackMaterial.emission<\/em> can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#a62437f009d7bd7b4888ce325b45c4bb5\" target=\"_blank\" rel=\"noopener noreferrer\">OivBackMaterialEmissive<\/a>()<\/strong><\/li>\n<\/ul>\n<p><strong><u><a id=\"Lighting\" name=\"Lighting\"><\/a>Lighting<\/u><\/strong><\/p>\n<ul>\n<li><em>gl_LightSource[i].position<\/em> can be replaced by&nbsp;<a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#a7f6e1c712ad6da3fa48feea838e77d29\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>OivLightSourcePosition(i)<\/strong><\/a><\/li>\n<li><em>gl_LightSource[i].spotDirection<\/em> can be replaced by&nbsp;<a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#a1cf973b1ca1af8e29ed68cb9469966b5\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>OivLightSourceSpotDirection(i)<\/strong><\/a><\/li>\n<li><em>gl_LightSource[i].spotExponent<\/em> can be replaced by&nbsp;<a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#a0ed87aed2cfeaba3f7b74611fff8d6a9\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>OivLightSourceSpotExponent(i)<\/strong><\/a><\/li>\n<li><em>gl_LightSource[i].spotCutoff<\/em> can be replaced by&nbsp;<a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#a8f68d9ff7a1755b107eddea1317dff60\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>OivLightSourceSpotCutoff(i)<\/strong><\/a><\/li>\n<li><em>gl_LightSource[i].spotCosCutoff<\/em> can be replaced by&nbsp;<a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#a992b80331c545a21091ab883975fb508\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>OivLightSourceSpotCosCutoff(i)<\/strong><\/a><\/li>\n<li><em>gl_LightSource[i].ambient<\/em> can be replaced by&nbsp;<a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#ac6e8e9619b09e2fd6239c188285414ae\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>OivLightSourceAmbient(i)<\/strong><\/a><\/li>\n<li><em>gl_LightSource[i].diffuse<\/em> can be replaced by&nbsp;<a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#ac40e1b9a5e0a008ac89f9ffec7443de6\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>OivLightSourceDiffuse(i)<\/strong><\/a><\/li>\n<li><em>gl_LightSource[i].specular<\/em> can be replaced by&nbsp;<a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#a9a2c125ed8b5807acaa2b71ef9f74e32\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>OivLightSourceSpecular(i)<\/strong><\/a><\/li>\n<li><em>gl_LightSource[i].constantAttenuation<\/em> can be replaced by&nbsp;<a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#aadd4274061162536fffcd166cd41b0e8\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>OivLightSourceConstantAttenuation(i)<\/strong><\/a><\/li>\n<li><em>gl_LightSource[i].linearAttenuation<\/em> can be replaced by&nbsp;<a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#a0a27cdd7f05f4b563e8576edc1261e01\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>OivLightSourceLinearAttenuation(i)<\/strong><\/a><\/li>\n<li><em>gl_LightSource[i].quadraticAttenuation<\/em> can be replaced by&nbsp;<a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#ab9b75681cfcc9ea45974c63989259368\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>OivLightSourceQuadraticAttenuation(i)<\/strong><\/a><\/li>\n<li><em>gl_FrontLightProduct[i].ambient<\/em> can be replaced by&nbsp;<a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#a6f0341841140a755bef96ac5a25598b0\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>OivFrontLightProductAmbient(i)<\/strong><\/a><\/li>\n<li><em>gl_FrontLightProduct[i].diffuse<\/em> can be replaced by&nbsp;<a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#a06241a47806d4975ed963e2d3242c57e\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>OivFrontLightProductDiffuse(i)<\/strong><\/a><\/li>\n<li><em>gl_FrontLightProduct[i].specular<\/em> can be replaced by&nbsp;<a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#a65366414294323c3e214a3b818804631\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>OivFrontLightProductSpecular(i)<\/strong><\/a><\/li>\n<li><em>gl_BackLightProduct[i].ambient<\/em> can be replaced by&nbsp;<a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#ac04d2aa8346f4b89db8d1443ab510980\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>OivBackLightProductAmbient(i)<\/strong><\/a><\/li>\n<li><em>gl_BackLightProduct[i].diffuse<\/em> can be replaced by&nbsp;<a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#a754503a353b3e9455b02b74588036f68\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>OivBackLightProductDiffuse(i)<\/strong><\/a><\/li>\n<li><em>gl_BackLightProduct[i].specular<\/em> can be replaced by&nbsp;<a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#a5119d27df6b390ecf1ad7547a8bcae7c\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>OivBackLightProductSpecular(i)<\/strong><\/a><\/li>\n<\/ul>\n<p><u><strong><a id=\"Misc\" name=\"Misc\"><\/a>Misc<\/strong><\/u><\/p>\n<ul>\n<li><em>gl_ClipPlane[i]&nbsp;<\/em> can be replaced by&nbsp;<a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#a713bc1cf78b06cb3c4fdc3e32712b737\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>OivClipPlane(i)<\/strong><\/a><\/li>\n<li><em>ftransform() is replaced&nbsp;<\/em>by&nbsp;<a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_state_8h.html#adee020476e1b8b738623603fedc3a97b\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>OivModelViewProjectionMatrix()<\/strong><\/a> * <a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shape_attribute_8h.html#aee0d011de087b3dfd2a1573f86eb2b30\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>OivVertexPosition()<\/strong><\/a>;<\/li>\n<\/ul>\n<hr>\n<h3><a id=\"builtins-varyings\" name=\"builtins-varyings\"><\/a>Built-in varyings conversion<\/h3>\n<p>If your shader uses GLSL built in varyings like gl<em><em>TexCoord, gl<\/em><\/em>FrontColor, you should replace these calls with corresponding Open Inventor calls and add the following include at the top of your shader:<\/p>\n<p class=\"rteindent1\"><strong>\/\/!oiv_include &lt;Inventor\/oivShaderVariables.h&gt;<\/strong><\/p>\n<p>Here is the list of correspondence between built in GLSL and Open Inventor available methods:<\/p>\n<p><u><strong><a id=\"inputs\" name=\"inputs\"><\/a>Inputs<\/strong><\/u><\/p>\n<p><u>Vertex Shader<\/u><\/p>\n<ul>\n<li><em>gl_FogCoord<\/em>&nbsp;can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_variables_8h_source.html\" target=\"_blank\" rel=\"noopener noreferrer\">OivFogFragCoord()<\/a><\/strong><\/li>\n<\/ul>\n<p><u>Tessellation Control Shader \/ Tessellation Evaluation Shader \/ Geometry Shader<\/u><\/p>\n<ul>\n<li><em>gl_in[i].gl_FrontColor<\/em>&nbsp;can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_variables_8h_source.html\" target=\"_blank\" rel=\"noopener noreferrer\">OivFrontColor(i)<\/a><\/strong><\/li>\n<li><em>gl_in[i].gl_BackColor<\/em>&nbsp;can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_variables_8h_source.html\" target=\"_blank\" rel=\"noopener noreferrer\">OivBackColor(i)<\/a><\/strong><\/li>\n<li><em>gl_in[i].gl_TexCoord[u]<\/em>&nbsp;can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_variables_8h_source.html\" target=\"_blank\" rel=\"noopener noreferrer\">OivTexCoord(i, u)<\/a><\/strong><\/li>\n<li><em>gl_in[i].gl_FogFragCoord<\/em>&nbsp;can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_variables_8h_source.html\" target=\"_blank\" rel=\"noopener noreferrer\">OivFogFragCoord(i)<\/a><\/strong><\/li>\n<\/ul>\n<p><u>Fragment Shader<\/u><\/p>\n<ul>\n<li><em>gl_Color<\/em>&nbsp;can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_variables_8h_source.html\" target=\"_blank\" rel=\"noopener noreferrer\">OivFragmentColor()<\/a><\/strong><\/li>\n<li><em>gl_TexCoord[i]<\/em>&nbsp;can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_variables_8h_source.html\" target=\"_blank\" rel=\"noopener noreferrer\">OivFragmentTexCoord(i)<\/a><\/strong><\/li>\n<li><em>gl_FogFragCoord<\/em>&nbsp;can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_variables_8h_source.html\" target=\"_blank\" rel=\"noopener noreferrer\">OivFogFragCoord()<\/a><\/strong><\/li>\n<\/ul>\n<p><u><strong><a id=\"Outputs\" name=\"Outputs\"><\/a>Outputs<\/strong><\/u><\/p>\n<p><u>Vertex Shader \/ Tessellation Evaluation Shader \/ Geometry Shader<\/u><\/p>\n<ul>\n<li><em>gl_FrontColor = c<\/em>&nbsp;can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_variables_8h_source.html\" target=\"_blank\" rel=\"noopener noreferrer\">OivSetFrontColor(c)<\/a><\/strong><\/li>\n<li><em>gl_BackColor = c<\/em>&nbsp;can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_variables_8h_source.html\" target=\"_blank\" rel=\"noopener noreferrer\">OivSetBackColor(c)<\/a><\/strong><\/li>\n<li><em>gl_TexCoord[u] = c<\/em>&nbsp;can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_variables_8h_source.html\" target=\"_blank\" rel=\"noopener noreferrer\">OivSetTexCoord(u, c)<\/a><\/strong><\/li>\n<li><em>gl_FogFragCoord = c<\/em>&nbsp;can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_variables_8h_source.html\" target=\"_blank\" rel=\"noopener noreferrer\">OivSetFogFragCoord(c)<\/a><\/strong><\/li>\n<\/ul>\n<p><u>Tessellation Control Shader<\/u><\/p>\n<ul>\n<li><em>gl_out[gl_InvocationID].gl_FrontColor = c<\/em>&nbsp;can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_variables_8h_source.html\" target=\"_blank\" rel=\"noopener noreferrer\">OivSetFrontColor(c)<\/a><\/strong><\/li>\n<li><em>gl_out[gl_InvocationID].gl_BackColor = c<\/em>&nbsp;can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_variables_8h_source.html\" target=\"_blank\" rel=\"noopener noreferrer\">OivSetBackColor(c)<\/a><\/strong><\/li>\n<li><em>gl_out[gl_InvocationID].gl_TexCoord[u] = c<\/em>&nbsp;can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_variables_8h_source.html\" target=\"_blank\" rel=\"noopener noreferrer\">OivSetTexCoord(u, c)<\/a><\/strong><\/li>\n<li><em>gl_out[gl_InvocationID].gl_FogFragCoord = c<\/em>&nbsp;can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_variables_8h_source.html\" target=\"_blank\" rel=\"noopener noreferrer\">OivSetFogFragCoord(c)<\/a><\/strong><\/li>\n<\/ul>\n<p><u>Fragment Shader<\/u><\/p>\n<ul>\n<li><em>gl_FragColor = c<\/em>&nbsp;can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_variables_8h_source.html\" target=\"_blank\" rel=\"noopener noreferrer\">OivFragmentOutput(c)<\/a><\/strong><\/li>\n<li><em>gl_FragData[i] = c<\/em>&nbsp;can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_variables_8h_source.html\" target=\"_blank\" rel=\"noopener noreferrer\">OivFragmentOutput(i, c)<\/a><\/strong><\/li>\n<\/ul>\n<hr>\n<h3><a id=\"transparency\" name=\"transparency\"><\/a>Manage transparency<\/h3>\n<p>To properly handle transparency, your fragment shader should contains the following function calls:<\/p>\n<ul>\n<li>You should enclose your code in <em><strong>if ( <a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/group___transparency_shaders.html#ga3f1492747a3e9e9e17cc75b2400c033a\" target=\"_blank\" rel=\"noopener noreferrer\">OivDepthPeel<\/a>(gl_FragCoord.xyz) ) { }<\/strong> <\/em>condition<\/li>\n<li>You should output your color using <strong><em><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/group___transparency_shaders.html#ga3f1492747a3e9e9e17cc75b2400c033a\" target=\"_blank\" rel=\"noopener noreferrer\">OivDepthPeelingOutputColor<\/a>())<\/em><\/strong> method<\/li>\n<\/ul>\n<p>These methods are accessible by including the <strong>&lt;Inventor\/oivDepthPeeling_frag.h&gt;<\/strong> header in your shader:<\/p>\n<p><strong><u>Exemple:<\/u><\/strong><\/p>\n<p>\/\/!oiv_include &lt;Inventor\/oivDepthPeeling_frag.h&gt;<\/p>\n<p>void main()<br \/>\n{<br \/>\nif ( <strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/group___transparency_shaders.html#ga3f1492747a3e9e9e17cc75b2400c033a\" target=\"_blank\" rel=\"noopener noreferrer\">OivDepthPeel<\/a>(gl_FragCoord.xyz)<\/strong> )<br \/>\n{<br \/>\nVec4 color = vec4(1, 0, 0, 0.5);<br \/>\n<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/group___transparency_shaders.html#ga3f1492747a3e9e9e17cc75b2400c033a\" target=\"_blank\" rel=\"noopener noreferrer\">OivDepthPeelingOutputColor<\/a>(color);<\/strong><br \/>\n}<br \/>\n}<\/p>\n<p>You should also specify <em><strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/class_so_shader_program.html\" target=\"_blank\" rel=\"noopener noreferrer\">SoShaderProgram<\/a><\/strong><\/em>::<strong>generateTransparency<\/strong> = TRUE to indicate that your shader will override current <em><strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/class_so_material.html\" target=\"_blank\" rel=\"noopener noreferrer\">SoMaterial<\/a><\/strong><\/em> transparency.<\/p>\n<hr>\n<h3><a id=\"geomshader\" name=\"geomshader\"><\/a>Geometry shader<\/h3>\n<p>Layout of input and output primitives <strong>must<\/strong> be manually specified in your geometry shader. Your geometry shader should contain a header like :<\/p>\n<ul>\n<li><em><strong>layout(input_primitive\u200b) in;<\/strong> <\/em>where <em>input_primitive<\/em> is one of\n<ul>\n<li><em><em>points<\/em><\/em><\/li>\n<li><em><em>lines<\/em><\/em><\/li>\n<li><em><em>triangles<\/em><\/em><\/li>\n<\/ul>\n<p>depending on type of node you use. For example, when applying geometry shader to an <em><strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/class_so_point_set.html\" target=\"_blank\" rel=\"noopener noreferrer\">SoPointSet<\/a><\/strong><\/em>, <em>input_primitive<\/em> should be points.<\/p>\n<\/li>\n<li><em><strong>layout(output_primitive, max_vertices = vert_count\u200b) out;<\/strong>&nbsp;<\/em><strong>vert_count<\/strong> is number of vertices you want to emit and <em>output_primitive<\/em> is one of\n<ul>\n<li><em>points<\/em><\/li>\n<li><em>line_strip<\/em><\/li>\n<li><em>triangle_strip<\/em><\/li>\n<\/ul>\n<p>depending on type of primitive you want to emit.<br \/>\nEx: If your geometry shader take as input a point and generate a quad formed by two&nbsp;stripped triangles, to create some kind of billboard, your header will look like:<\/p>\n<ul>\n<li>layout(points) in;<\/li>\n<li>layout(triangle_strip, max_vertices = 4) out;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr>\n<h3><a id=\"passthrough\" name=\"passthrough\"><\/a>PassThrough Helpers<\/h3>\n<p>Functions are also available to copy all predefined varyings from one stage to the next:<\/p>\n<p><strong>Vertex Shader<\/strong><\/p>\n<p class=\"rteindent1\"><em>gl_FrontColor &nbsp; = gl_Color;<br \/>\ngl_BackColor &nbsp; &nbsp;= gl_Color;<br \/>\ngl_TexCoord[0] &nbsp;= gl_MultiTexCoord0;<br \/>\ngl_TexCoord[1] &nbsp;= gl_MultiTexCoord1;<br \/>\ngl_TexCoord[2] &nbsp;= gl_MultiTexCoord2;<br \/>\ngl_TexCoord[3] &nbsp;= gl_MultiTexCoord3;<br \/>\ngl_FogFragCoord = gl_FogCoord;<\/em><\/p>\n<p>can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_variables_8h_source.html\" target=\"_blank\" rel=\"noopener noreferrer\">OivSetupVertex()<\/a><\/strong><\/p>\n<p><strong>Tessellation Evaluation Shader \/ Geometry Shader<\/strong><\/p>\n<p class=\"rteindent1\"><em>gl_FrontColor = gl_in[i].gl_FrontColor;<br \/>\ngl_BackColor = gl_in[i].gl_BackColor;<br \/>\ngl_FrontSecondaryColor = gl_in[i].gl_FrontSecondaryColor;<br \/>\ngl_BackSecondaryColor &nbsp;= gl_in[i].gl_BackSecondaryColor;<br \/>\ngl_TexCoord = gl_in[i].gl_TexCoord;<br \/>\ngl_FogFragCoord = gl_in[i].gl_FogFragCoord;<\/em><\/p>\n<p>can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_variables_8h_source.html\" target=\"_blank\" rel=\"noopener noreferrer\">OivSetupVertex(i)<\/a><\/strong><\/p>\n<p><strong>Tessellation Control Shader<\/strong><\/p>\n<p class=\"rteindent1\"><em>gl_out[gl_InvocationID].gl_FrontColor&nbsp;= gl_in[i].gl_FrontColor;<br \/>\ngl_out[gl_InvocationID].gl_BackColor =&nbsp;gl_in[i].gl_BackColor;<br \/>\ngl_out[gl_InvocationID].gl_FrontSecondaryColor = gl_in[i].gl_FrontSecondaryColor;<br \/>\ngl_out[gl_InvocationID].gl_BackSecondaryColor = gl_in[i].gl_BackSecondaryColor;<br \/>\ngl_out[gl_InvocationID].gl_TexCoord = gl_in[i].gl_TexCoord;<br \/>\ngl_out[gl_InvocationID].gl_FogFragCoord = gl_in[i].gl_FogFragCoord;<\/em><\/p>\n<p>can be replaced by&nbsp;<strong><a href=\"https:\/\/developer.openinventor.com\/refmans\/latest\/RefManCpp\/oiv_shader_variables_8h_source.html\" target=\"_blank\" rel=\"noopener noreferrer\">OivSetupVertex(i)<\/a><\/strong><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Starting with version 10, Open Inventor\u00ae provides a GLSL shader API&nbsp;to access various state values from shaders. The classical&hellip;<\/p>\n","protected":false},"author":3,"featured_media":0,"parent":63,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-172","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/developer.openinventor.com\/index.php\/wp-json\/wp\/v2\/pages\/172","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/developer.openinventor.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/developer.openinventor.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/developer.openinventor.com\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/developer.openinventor.com\/index.php\/wp-json\/wp\/v2\/comments?post=172"}],"version-history":[{"count":24,"href":"https:\/\/developer.openinventor.com\/index.php\/wp-json\/wp\/v2\/pages\/172\/revisions"}],"predecessor-version":[{"id":631,"href":"https:\/\/developer.openinventor.com\/index.php\/wp-json\/wp\/v2\/pages\/172\/revisions\/631"}],"up":[{"embeddable":true,"href":"https:\/\/developer.openinventor.com\/index.php\/wp-json\/wp\/v2\/pages\/63"}],"wp:attachment":[{"href":"https:\/\/developer.openinventor.com\/index.php\/wp-json\/wp\/v2\/media?parent=172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}