Note that there are some explanatory texts on larger screens.

plurals
  1. POglsl light doesn't seem to be working
    primarykey
    data
    text
    <p>I'm working on some basic lighting in my application, and am unable to get a simple light to work (so far..).</p> <p>Here's the vertex shader:</p> <pre><code>#version 150 core uniform mat4 projectionMatrix; uniform mat4 viewMatrix; uniform mat4 modelMatrix; uniform mat4 pvmMatrix; uniform mat3 normalMatrix; in vec3 in_Position; in vec2 in_Texture; in vec3 in_Normal; out vec2 textureCoord; out vec4 pass_Color; uniform LightSources { vec4 ambient = vec4(0.5, 0.5, 0.5, 1.0); vec4 diffuse = vec4(0.5, 0.5, 0.5, 1.0); vec4 specular = vec4(0.5, 0.5, 0.5, 1.0); vec4 position = vec4(1.5, 7, 0.5, 1.0); vec4 direction = vec4(0.0, -1.0, 0.0, 1.0); } lightSources; struct Material { vec4 ambient; vec4 diffuse; vec4 specular; float shininess; }; Material mymaterial = Material( vec4(1.0, 0.8, 0.8, 1.0), vec4(1.0, 0.8, 0.8, 1.0), vec4(1.0, 0.8, 0.8, 1.0), 0.995 ); void main() { gl_Position = pvmMatrix * vec4(in_Position, 1.0); textureCoord = in_Texture; vec3 normalDirection = normalize(normalMatrix * in_Normal); vec3 lightDirection = normalize(vec3(lightSources.direction)); vec3 diffuseReflection = vec3(lightSources.diffuse) * vec3(mymaterial.diffuse) * max(0.0, dot(normalDirection, lightDirection)); /* float bug = 0.0; bvec3 result = equal( diffuseReflection, vec3(0.0, 0.0, 0.0) ); if(result[0] &amp;&amp; result[1] &amp;&amp; result[2]) bug = 1.0; diffuseReflection.x += bug; */ pass_Color = vec4(diffuseReflection, 1.0); } </code></pre> <p>And here's the fragment shader:</p> <pre><code>#version 150 core uniform sampler2D texture; in vec4 pass_Color; in vec2 textureCoord; void main() { vec4 out_Color = texture2D(texture, textureCoord); gl_FragColor = pass_Color; //gl_FragColor = out_Color; } </code></pre> <p>I'm rendering a textured wolf to the screen as a test. If I change the fragment shader to use <code>out_Color</code>, I see the wolf rendered properly. If I use the <code>pass_Color</code>, I see nothing on the screen. </p> <p>This is what the screen looks like when I use <code>out_Color</code> in the fragment shader: <img src="https://i.stack.imgur.com/RWUtk.jpg" alt="enter image description here"></p> <p>I know the <code>diffuseReflection</code> vector is full of 0's, by uncommenting this code in the vertex shader:</p> <pre><code>... /* float bug = 0.0; bvec3 result = equal( diffuseReflection, vec3(0.0, 0.0, 0.0) ); if(result[0] &amp;&amp; result[1] &amp;&amp; result[2]) bug = 1.0; diffuseReflection.x += bug; */ ... </code></pre> <p>This will make the <code>x</code> component of the <code>diffuseReflection</code> vector <code>1.0</code>, which turns the wolf red.</p> <p>Does anyone see anything obvious I'm doing wrong here?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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