Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenGL/GLSL - Handling lighting from an old game (mixing ambient light and vertex colors)
    text
    copied!<p>I am writing a client that supports loading of an old game format. It uses fake lighting where for every vertex, there is often a vertex color supplied. I got the lighting to appear correctly by using:</p> <pre><code>vec4 textureColor = texture2D(texture, outtexture) * vertexColor; </code></pre> <p>The problem was that for vertices supplied that were 0.0, 0.0, 0.0 for RGB, the entire texture was of course black. I have been playing around with a few different algorithms but the textures still look a bit dark or the lights are too bright.</p> <p>Here is the shader:</p> <pre><code>float ambient = 1.0; vec4 textureColor = texture2D(texture, outtexture); vec4 lighting = vec4((vertexColor * vertexColor.a) + (ambient * textureColor)); gl_FragColor = textureColor * lighting; </code></pre> <p>Here is an example:</p> <p><img src="https://i.stack.imgur.com/8ZVrw.png" alt="Textures with no light are too dark"></p> <p>Now, the vertex color data is a bit weird too. Here's an example:</p> <pre><code>&lt;-!-&gt; R: 0.000000, G: 0.000000, B: 0.000000, A: 0.000000 &lt;-!-&gt; R: 0.000000, G: 0.000000, B: 0.000000, A: 0.000000 &lt;-!-&gt; R: 0.000000, G: 0.000000, B: 0.000000, A: 0.000000 &lt;-!-&gt; R: 0.023529, G: 0.023529, B: 0.003922, A: 0.858824 &lt;-!-&gt; R: 0.007843, G: 0.007843, B: 0.000000, A: 0.850980 &lt;-!-&gt; R: 0.007843, G: 0.007843, B: 0.000000, A: 0.858824 &lt;-!-&gt; R: 0.023529, G: 0.023529, B: 0.003922, A: 0.858824 &lt;-!-&gt; R: 0.050980, G: 0.050980, B: 0.011765, A: 0.882353 &lt;-!-&gt; R: 0.078431, G: 0.078431, B: 0.015686, A: 0.858824 &lt;-!-&gt; R: 0.078431, G: 0.078431, B: 0.015686, A: 0.858824 &lt;-!-&gt; R: 0.050980, G: 0.050980, B: 0.011765, A: 0.894118 &lt;-!-&gt; R: 0.031373, G: 0.031373, B: 0.007843, A: 0.862745 &lt;-!-&gt; R: 0.050980, G: 0.050980, B: 0.011765, A: 0.882353 &lt;-!-&gt; R: 0.050980, G: 0.050980, B: 0.011765, A: 0.894118 &lt;-!-&gt; R: 0.031373, G: 0.031373, B: 0.007843, A: 0.858824 &lt;-!-&gt; R: 0.000000, G: 0.000000, B: 0.000000, A: 0.858824 &lt;-!-&gt; R: 0.000000, G: 0.000000, B: 0.000000, A: 0.835294 </code></pre> <p>Notice that it contains some normal values (0, 0, 0, 0) and some regular ones with decimal numbers as well as values that are 0, 0, 0 and then have an alpha defined.</p> <p>Feel free to chime in if you have seen this method or have any suggestions for how to achieve a normal looking render. Yes, I realize this question is a bit different but hopefully someone should have some insight.</p> <p>Edit: If this helps at all, a friend of mine had a similar project. This was how he loaded the information and packaged it for DirectX:</p> <pre><code> int iBlue = GetByte( ); int iGreen = GetByte( ); int iRed = GetByte( ); int iAmb = GetByte( ); pVertex-&gt;m_dwDiffuse = D3DCOLOR_ARGB( (BYTE)( max( iAmb, 1 ) ), (BYTE)( max( iRed, 1 ) ), (BYTE)( max( iGreen, 1 ) ), (BYTE)( max( iBlue, 1 ) ) ); </code></pre> <p>I am assuming he does exactly what I do and converts the bytes to integers and then if they are negative, he replaces them with 1. Still wish I knew how he used them while rendering...</p> <p>What it's supposed to look like:</p> <p>Day (Much less/almost no light being seen) <img src="https://i.stack.imgur.com/Y6djc.png" alt="enter image description here"></p> <p>Night:</p> <p><img src="https://i.stack.imgur.com/GGu1Z.png" alt="enter image description here"></p> <p>Mine (with the above shader code): <img src="https://i.stack.imgur.com/9QoFP.png" alt="enter image description here"></p> <p>It appears that the lights are either too bright or their black contribution to the textures makes them too hard to see.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload