DudeAwesome Posted April 7, 2014 Share Posted April 7, 2014 hey guys I´m reading opengl 4.0 shading cook book to get a feeling for shaders and learn the basics but I fail with my first simple diffuse shader example. thats my code: Vertex #version 400 layout (location = 0) in vec3 VertexPosition; layout (location = 1) in vec3 VertexNormal; out vec3 LightIntensity; uniform vec4 LightPosition; // Light position in eye coords. uniform vec3 Kd; // Diffuse reflectivity uniform vec3 Ld; // Light source intensity uniform mat4 ModelViewMatrix; uniform mat3 NormalMatrix; uniform mat4 ProjectionMatrix; uniform mat4 MVP; // Projection * ModelView void main(){ // Convert normal and position to eye coords vec3 tnorm = normalize( NormalMatrix * VertexNormal); vec4 eyeCoords = ModelViewMatrix * vec4(VertexPosition,1.0); vec3 s = normalize(vec3(LightPosition - eyeCoords)); // The diffuse shading equation LightIntensity = Ld * Kd * max( dot( s, tnorm ), 0.0 ); // Convert position to clip coordinates and pass along gl_Position = MVP * vec4(VertexPosition,1.0); } Fragment #version 400 in vec3 LightIntensity; layout( location = 0 ) out vec4 FragColor; void main() { FragColor = vec4(LightIntensity, 1.0); } I attached the shader to a material and to a ground but it is still invisible and the screen is black. Quote It doesn´t work... why? mhmmm It works... why? Link to comment Share on other sites More sharing options...
Rastar Posted April 8, 2014 Share Posted April 8, 2014 It's not working for two reasons: 1) All those special variables for vertex normal, light position, transformation matrices are not part of GLSL. They are passed in by name by the engine, and every engine has its own naming convention. If you have a look in a Leadwerks shader, the uniforms there have names like vertex_normal, entity_matrix ('M' of the model-view-perspective transform) and projectioncameramatrix (the 'VP'). So the variables you're using in your code don't carry any values. But even if you used the Leadwerks variables, this concrete shader wouldn't work in Leadwerks 3.1 because 2) it's written for a forward renderer, and Leadwerks 3.1 has a a deferred renderer. In a deferred renderer, the lighting calculations (here the diffuse shading with the NdotL term) are done for you behind the scenes. The shader's main job is to fill the fragData G buffers for diffuse color, normal, emission etc. that the engine needs for its calculations. 1 Quote Link to comment Share on other sites More sharing options...
DudeAwesome Posted April 8, 2014 Author Share Posted April 8, 2014 Thx ! you know some good tutorials for deferred shader ? well I wanted to try to read glsl 4.0 Cook Book but its bad when I cant Test the shader Examples :/ I really want to get more involved into shaders but its like the holy grail. Quote It doesn´t work... why? mhmmm It works... why? Link to comment Share on other sites More sharing options...
Rastar Posted April 8, 2014 Share Posted April 8, 2014 Actually - no, I don't (maybe shadmar and klepto know something?) It might be better to start with a forward renderer to learn shader programming, because everything is right in front of your eyes, and playing around with different light types, lighting models etc is possible. I started digging into shaders with Leadwerks 3.0 (which has a forward renderer), and that was helpful at least for me. And it might be easier to understand what is going on in a deferred renderer if you have done everything for yourself first. Quote Link to comment Share on other sites More sharing options...
DudeAwesome Posted April 8, 2014 Author Share Posted April 8, 2014 where can I read about the leadwerks engine shader variables? there is nothing in the documentation about it or may i missed it? Quote It doesn´t work... why? mhmmm It works... why? Link to comment Share on other sites More sharing options...
shadmar Posted April 8, 2014 Share Posted April 8, 2014 This isn't actual docs, but better than nothing : Have a look here : http://www.leadwerks.com/werkspace/topic/8203-internal-shader-uniforms/page__hl__uniforms 1 Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.