<div dir="ltr"><br>Hello,<div><br></div><div>I have a triangle geometry and I'm displaying it in various material modes.</div><div>The standard is just a texture. What I want is the backside of the geometry to be slightly darker than the front.</div><div><br></div><div>So I configure my lighting like this</div><div><br></div><div class="prettyprint" style="background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; overflow-wrap: break-word;"><code class="prettyprint"><div class="subprettyprint"><span style="color: #000;" class="styled-by-prettify">osg</span><span style="color: #660;" class="styled-by-prettify">::</span><span style="color: #000;" class="styled-by-prettify">ref_ptr</span><span style="color: #660;" class="styled-by-prettify"><</span><span style="color: #000;" class="styled-by-prettify">osg</span><span style="color: #660;" class="styled-by-prettify">::</span><span style="color: #606;" class="styled-by-prettify">LightModel</span><span style="color: #660;" class="styled-by-prettify">></span><span style="color: #000;" class="styled-by-prettify"> lm </span><span style="color: #660;" class="styled-by-prettify">=</span><span style="color: #000;" class="styled-by-prettify"> </span><span style="color: #008;" class="styled-by-prettify">new</span><span style="color: #000;" class="styled-by-prettify"> osg</span><span style="color: #660;" class="styled-by-prettify">::</span><span style="color: #606;" class="styled-by-prettify">LightModel</span><span style="color: #660;" class="styled-by-prettify">;</span><span style="color: #000;" class="styled-by-prettify"><br>lm</span><span style="color: #660;" class="styled-by-prettify">-></span><span style="color: #000;" class="styled-by-prettify">setTwoSided</span><span style="color: #660;" class="styled-by-prettify">(</span><span style="color: #008;" class="styled-by-prettify">true</span><span style="color: #660;" class="styled-by-prettify">);</span><span style="color: #000;" class="styled-by-prettify"><br>m_geometry</span><span style="color: #660;" class="styled-by-prettify">-></span><span style="color: #000;" class="styled-by-prettify">getOrCreateStateSet</span><span style="color: #660;" class="styled-by-prettify">()-></span><span style="color: #000;" class="styled-by-prettify">setAttributeAndModes</span><span style="color: #660;" class="styled-by-prettify">(</span><span style="color: #000;" class="styled-by-prettify">lm</span><span style="color: #660;" class="styled-by-prettify">);</span></div></code></div><div><br></div><div>and then I set up my material like this, in addition to setting a texture.</div><div><br></div><div><div class="prettyprint" style="background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; overflow-wrap: break-word;"><code class="prettyprint"><div class="subprettyprint"><span style="color: #000;" class="styled-by-prettify">m_material</span><span style="color: #660;" class="styled-by-prettify">-></span><span style="color: #000;" class="styled-by-prettify">setAmbient</span><span style="color: #660;" class="styled-by-prettify">(</span><span style="color: #000;" class="styled-by-prettify">osg</span><span style="color: #660;" class="styled-by-prettify">::</span><span style="color: #606;" class="styled-by-prettify">Material</span><span style="color: #660;" class="styled-by-prettify">::</span><span style="color: #000;" class="styled-by-prettify">FRONT_AND_BACK</span><span style="color: #660;" class="styled-by-prettify">,</span><span style="color: #000;" class="styled-by-prettify"> xmx</span><span style="color: #660;" class="styled-by-prettify">::</span><span style="color: #000;" class="styled-by-prettify">osg</span><span style="color: #660;" class="styled-by-prettify">::</span><span style="color: #000;" class="styled-by-prettify">black</span><span style="color: #660;" class="styled-by-prettify">);</span><span style="color: #000;" class="styled-by-prettify"><br>m_material</span><span style="color: #660;" class="styled-by-prettify">-></span><span style="color: #000;" class="styled-by-prettify">setDiffuse</span><span style="color: #660;" class="styled-by-prettify">(</span><span style="color: #000;" class="styled-by-prettify">osg</span><span style="color: #660;" class="styled-by-prettify">::</span><span style="color: #606;" class="styled-by-prettify">Material</span><span style="color: #660;" class="styled-by-prettify">::</span><span style="color: #000;" class="styled-by-prettify">FRONT_AND_BACK</span><span style="color: #660;" class="styled-by-prettify">,</span><span style="color: #000;" class="styled-by-prettify"> xmx</span><span style="color: #660;" class="styled-by-prettify">::</span><span style="color: #000;" class="styled-by-prettify">osg</span><span style="color: #660;" class="styled-by-prettify">::</span><span style="color: #000;" class="styled-by-prettify">black</span><span style="color: #660;" class="styled-by-prettify">);</span><span style="color: #000;" class="styled-by-prettify"><br>m_material</span><span style="color: #660;" class="styled-by-prettify">-></span><span style="color: #000;" class="styled-by-prettify">setEmission</span><span style="color: #660;" class="styled-by-prettify">(</span><span style="color: #000;" class="styled-by-prettify">osg</span><span style="color: #660;" class="styled-by-prettify">::</span><span style="color: #606;" class="styled-by-prettify">Material</span><span style="color: #660;" class="styled-by-prettify">::</span><span style="color: #000;" class="styled-by-prettify">FRONT</span><span style="color: #660;" class="styled-by-prettify">,</span><span style="color: #000;" class="styled-by-prettify"> osg</span><span style="color: #660;" class="styled-by-prettify">::</span><span style="color: #606;" class="styled-by-prettify">Vec4</span><span style="color: #660;" class="styled-by-prettify">(</span><span style="color: #000;" class="styled-by-prettify">ff</span><span style="color: #660;" class="styled-by-prettify">,</span><span style="color: #000;" class="styled-by-prettify"> ff</span><span style="color: #660;" class="styled-by-prettify">,</span><span style="color: #000;" class="styled-by-prettify"> ff</span><span style="color: #660;" class="styled-by-prettify">,</span><span style="color: #000;" class="styled-by-prettify"> </span><span style="color: #066;" class="styled-by-prettify">1.0f</span><span style="color: #660;" class="styled-by-prettify">));</span><span style="color: #000;" class="styled-by-prettify"><br>m_material</span><span style="color: #660;" class="styled-by-prettify">-></span><span style="color: #000;" class="styled-by-prettify">setEmission</span><span style="color: #660;" class="styled-by-prettify">(</span><span style="color: #000;" class="styled-by-prettify">osg</span><span style="color: #660;" class="styled-by-prettify">::</span><span style="color: #606;" class="styled-by-prettify">Material</span><span style="color: #660;" class="styled-by-prettify">::</span><span style="color: #000;" class="styled-by-prettify">BACK</span><span style="color: #660;" class="styled-by-prettify">,</span><span style="color: #000;" class="styled-by-prettify"> osg</span><span style="color: #660;" class="styled-by-prettify">::</span><span style="color: #606;" class="styled-by-prettify">Vec4</span><span style="color: #660;" class="styled-by-prettify">(</span><span style="color: #000;" class="styled-by-prettify">fb</span><span style="color: #660;" class="styled-by-prettify">,</span><span style="color: #000;" class="styled-by-prettify"> fb</span><span style="color: #660;" class="styled-by-prettify">,</span><span style="color: #000;" class="styled-by-prettify"> fb</span><span style="color: #660;" class="styled-by-prettify">,</span><span style="color: #000;" class="styled-by-prettify"> </span><span style="color: #066;" class="styled-by-prettify">1.0f</span><span style="color: #660;" class="styled-by-prettify">));</span><span style="color: #000;" class="styled-by-prettify"><br>m_material</span><span style="color: #660;" class="styled-by-prettify">-></span><span style="color: #000;" class="styled-by-prettify">setColorMode</span><span style="color: #660;" class="styled-by-prettify">(</span><span style="color: #000;" class="styled-by-prettify">osg</span><span style="color: #660;" class="styled-by-prettify">::</span><span style="color: #606;" class="styled-by-prettify">Material</span><span style="color: #660;" class="styled-by-prettify">::</span><span style="color: #606;" class="styled-by-prettify">ColorMode</span><span style="color: #660;" class="styled-by-prettify">::</span><span style="color: #000;" class="styled-by-prettify">OFF</span><span style="color: #660;" class="styled-by-prettify">);</span></div></code></div><div><br></div></div><div>ff and fb here are two different values, ff usually being just 1 and fb something less than 1 to make the backside darker.</div><div>This works great for me.</div><div><br></div><div>Now I also have a mode where I can set per-vertex colors in addition to a texture, and I want to combine it.</div><div>This works if I just drop the material and set a color array with the provided colors,</div><div>but then I loose the feature of different front and back lighting, or generally the possibility to dampen front and back</div><div>intensity separately.</div><div><br></div><div>Is there any way to achieve this without writing my own shader?</div><div><br></div><div>I tried to set the color mode of the material to AMBIENT_AND_DIFFUSE or to EMISSION and added the material,</div><div>which resulted in no spectacular changes.</div><div>How could I combine the material with the texture and color array?</div><div><br></div><div>Thank you in advance,</div><div>Phil</div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups "OpenSceneGraph Users" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="mailto:osg-users+unsubscribe@googlegroups.com">osg-users+unsubscribe@googlegroups.com</a>.<br />
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/osg-users/109aa9e5-0fa3-4dda-bbd7-e6aff3e11131%40googlegroups.com?utm_medium=email&utm_source=footer">https://groups.google.com/d/msgid/osg-users/109aa9e5-0fa3-4dda-bbd7-e6aff3e11131%40googlegroups.com</a>.<br />