Advertisement
ThinMatrix

Materials Example

Jan 31st, 2016
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #version 330
  2.  
  3. layout(location = 0) in vec3 in_position;
  4. layout(location = 1) in vec3 in_normal;
  5. layout(location = 2) in vec3 in_colour;
  6.  
  7. out vec3 pass_colour;
  8.  
  9. uniform mat4 mvpMatrix;
  10.  
  11. uniform vec3 material1;
  12. uniform vec3 material2;
  13.  
  14.  
  15. vec3 decodeColourCode(float code){
  16.     vec3 weights = vec3(0.0);
  17.     weights.x = mod(code, 2.0);
  18.     code = (code - weights.x) * 0.5;
  19.     weights.y = mod(code, 2.0);
  20.     weights.z = (code - weights.y) * 0.5;
  21.     return weights;
  22. }
  23.  
  24. vec3 customizeColour(vec2 colourData, vec3 materialColour){
  25.     vec3 weights = decodeColourCode(colourData.x);
  26.     vec3 result = materialColour + (weights * colourData.y);
  27.     return clamp(result, 0.0, 1.0);
  28. }
  29.  
  30. void main(void){
  31.    
  32.     gl_Position = mvpMatrix * vec4(in_position, 1.0);
  33.  
  34.     pass_colour = in_colour;
  35.     if(colour.x < -1.5){
  36.         colour = customizeColour(colour.yz, material2);
  37.     }else if(colour.x < -0.5){
  38.         colour = customizeColour(colour.yz, material1);
  39.     }
  40.    
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement