fork download
  1.  
  2. #version 330 core
  3.  
  4. // Interpolated values from the vertex shaders
  5. in vec2 UV;
  6. in vec3 Position_worldspace;
  7. in vec3 Normal_cameraspace;
  8. in vec3 EyeDirection_cameraspace;
  9. in vec3 LightDirection_cameraspace;
  10.  
  11. // Ouput data
  12. out vec3 color;
  13.  
  14. // Values that stay constant for the whole mesh.
  15. uniform sampler2D myTextureSampler;
  16. uniform mat4 MV;
  17. uniform vec3 LightPosition_worldspace;
  18.  
  19. void main(){
  20.  
  21. // Light emission properties
  22. // You probably want to put them as uniforms
  23. vec3 LightColor = vec3(1,1,1);
  24. float LightPower = 50.0f;
  25.  
  26. // Material properties
  27. vec3 MaterialDiffuseColor = texture( myTextureSampler, UV ).rgb;
  28. vec3 MaterialAmbientColor = vec3(0.1,0.1,0.1) * MaterialDiffuseColor;
  29. vec3 MaterialSpecularColor = vec3(0.3,0.3,0.3);
  30.  
  31. // Distance to the light
  32. float distance = length( LightPosition_worldspace - Position_worldspace );
  33.  
  34. // Normal of the computed fragment, in camera space
  35. vec3 n = normalize( Normal_cameraspace );
  36. // Direction of the light (from the fragment to the light)
  37. vec3 l = normalize( LightDirection_cameraspace );
  38. // Cosine of the angle between the normal and the light direction,
  39. // clamped above 0
  40. // - light is at the vertical of the triangle -> 1
  41. // - light is perpendicular to the triangle -> 0
  42. // - light is behind the triangle -> 0
  43. float cosTheta = clamp( dot( n,l ), 0 ,1 );
  44.  
  45. // Eye vector (towards the camera)
  46. vec3 E = normalize(EyeDirection_cameraspace);
  47. // Direction in which the triangle reflects the light
  48. vec3 R = reflect(-l,n);
  49. // Cosine of the angle between the Eye vector and the Reflect vector,
  50. // clamped to 0
  51. // - Looking into the reflection -> 1
  52. // - Looking elsewhere -> < 1
  53. float cosAlpha = clamp( dot( E,R ), 0,1 );
  54.  
  55. color =
  56. // Ambient : simulates indirect lighting
  57. MaterialAmbientColor +
  58. // Diffuse : "color" of the object
  59. MaterialDiffuseColor * LightColor * LightPower * cosTheta / (distance*distance) +
  60. // Specular : reflective highlight, like a mirror
  61. MaterialSpecularColor * LightColor * LightPower * pow(cosAlpha,5) / (distance*distance);
  62.  
  63. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:2:2: error: invalid preprocessing directive #version
 #version 330 core
  ^~~~~~~
prog.cpp:5:1: error: ‘in’ does not name a type
 in vec2 UV;
 ^~
prog.cpp:6:1: error: ‘in’ does not name a type
 in vec3 Position_worldspace;
 ^~
prog.cpp:7:1: error: ‘in’ does not name a type
 in vec3 Normal_cameraspace;
 ^~
prog.cpp:8:1: error: ‘in’ does not name a type
 in vec3 EyeDirection_cameraspace;
 ^~
prog.cpp:9:1: error: ‘in’ does not name a type
 in vec3 LightDirection_cameraspace;
 ^~
prog.cpp:12:1: error: ‘out’ does not name a type
 out vec3 color;
 ^~~
prog.cpp:15:1: error: ‘uniform’ does not name a type
 uniform sampler2D myTextureSampler;
 ^~~~~~~
prog.cpp:16:1: error: ‘uniform’ does not name a type
 uniform mat4 MV;
 ^~~~~~~
prog.cpp:17:1: error: ‘uniform’ does not name a type
 uniform vec3 LightPosition_worldspace;
 ^~~~~~~
prog.cpp:19:11: error: ‘::main’ must return ‘int’
 void main(){
           ^
prog.cpp: In function ‘int main()’:
prog.cpp:23:9: error: ‘vec3’ was not declared in this scope
         vec3 LightColor = vec3(1,1,1);
         ^~~~
prog.cpp:27:7: error: expected ‘;’ before ‘MaterialDiffuseColor’
  vec3 MaterialDiffuseColor = texture( myTextureSampler, UV ).rgb;
       ^~~~~~~~~~~~~~~~~~~~
prog.cpp:28:14: error: expected ‘;’ before ‘MaterialAmbientColor’
         vec3 MaterialAmbientColor = vec3(0.1,0.1,0.1) * MaterialDiffuseColor;
              ^~~~~~~~~~~~~~~~~~~~
prog.cpp:29:7: error: expected ‘;’ before ‘MaterialSpecularColor’
  vec3 MaterialSpecularColor = vec3(0.3,0.3,0.3);
       ^~~~~~~~~~~~~~~~~~~~~
prog.cpp:32:27: error: ‘LightPosition_worldspace’ was not declared in this scope
  float distance = length( LightPosition_worldspace - Position_worldspace );
                           ^~~~~~~~~~~~~~~~~~~~~~~~
prog.cpp:32:54: error: ‘Position_worldspace’ was not declared in this scope
  float distance = length( LightPosition_worldspace - Position_worldspace );
                                                      ^~~~~~~~~~~~~~~~~~~
prog.cpp:32:74: error: ‘length’ was not declared in this scope
  float distance = length( LightPosition_worldspace - Position_worldspace );
                                                                          ^
prog.cpp:35:7: error: expected ‘;’ before ‘n’
  vec3 n = normalize( Normal_cameraspace );
       ^
prog.cpp:37:7: error: expected ‘;’ before ‘l’
  vec3 l = normalize( LightDirection_cameraspace );
       ^
prog.cpp:43:38: error: ‘n’ was not declared in this scope
         float cosTheta = clamp( dot( n,l ), 0 ,1 );
                                      ^
prog.cpp:43:40: error: ‘l’ was not declared in this scope
         float cosTheta = clamp( dot( n,l ), 0 ,1 );
                                        ^
prog.cpp:43:42: error: ‘dot’ was not declared in this scope
         float cosTheta = clamp( dot( n,l ), 0 ,1 );
                                          ^
prog.cpp:43:50: error: ‘clamp’ was not declared in this scope
         float cosTheta = clamp( dot( n,l ), 0 ,1 );
                                                  ^
prog.cpp:46:7: error: expected ‘;’ before ‘E’
  vec3 E = normalize(EyeDirection_cameraspace);
       ^
prog.cpp:48:7: error: expected ‘;’ before ‘R’
  vec3 R = reflect(-l,n);
       ^
prog.cpp:53:38: error: ‘E’ was not declared in this scope
         float cosAlpha = clamp( dot( E,R ), 0,1 );
                                      ^
prog.cpp:53:40: error: ‘R’ was not declared in this scope
         float cosAlpha = clamp( dot( E,R ), 0,1 );
                                        ^
prog.cpp:55:2: error: ‘color’ was not declared in this scope
  color =
  ^~~~~
prog.cpp:57:3: error: ‘MaterialAmbientColor’ was not declared in this scope
   MaterialAmbientColor +
   ^~~~~~~~~~~~~~~~~~~~
prog.cpp:59:3: error: ‘MaterialDiffuseColor’ was not declared in this scope
   MaterialDiffuseColor * LightColor * LightPower * cosTheta / (distance*distance) +
   ^~~~~~~~~~~~~~~~~~~~
prog.cpp:59:26: error: ‘LightColor’ was not declared in this scope
   MaterialDiffuseColor * LightColor * LightPower * cosTheta / (distance*distance) +
                          ^~~~~~~~~~
prog.cpp:61:3: error: ‘MaterialSpecularColor’ was not declared in this scope
   MaterialSpecularColor * LightColor * LightPower * pow(cosAlpha,5) / (distance*distance);
   ^~~~~~~~~~~~~~~~~~~~~
prog.cpp:61:67: error: ‘pow’ was not declared in this scope
   MaterialSpecularColor * LightColor * LightPower * pow(cosAlpha,5) / (distance*distance);
                                                                   ^
stdout
Standard output is empty