<html><head></head><body><p dir="ltr">Hi Phil,<br>
if you are working with your own shaders you can query front and back in the fragment shader.</p>
<p dir="ltr">Werner</p>
<br><br><div class="gmail_quote">On 7. Mai 2020 17:42:35 MESZ, OpenSceneGraph Users <osg-users@lists.openscenegraph.org> wrote:<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<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"></code><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></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"></code><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></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>
</blockquote></div></body></html>