Guest User

Untitled

a guest
Dec 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. uniform vec4 uDiffuseColor;
  2. uniform vec4 uAmbientColor;
  3. uniform vec3 uSpecularColor;
  4. uniform float uShininess;
  5. uniform float uShadowStrength;
  6. uniform vec3 uShadowColor;
  7.  
  8. // these are our new uniforms
  9. uniform sampler2D s_scaleRef;
  10. uniform sampler2D s_rot;
  11. uniform vec2 u_inst_grid;
  12. uniform float u_disp_scale;
  13. uniform float u_rot_max;
  14.  
  15. // a new rotate funciton
  16. vec2 rotate2D(float angle, vec2 prevXY){
  17. mat2 transMat = mat2( cos(angle), -sin(angle),
  18. sin(angle), cos(angle));
  19. vec2 new_rot = transMat * prevXY;
  20. return new_rot;
  21. }
  22.  
  23. out Vertex
  24. {
  25. vec4 color;
  26. vec3 worldSpacePos;
  27. vec3 worldSpaceNorm;
  28. vec3 texCoord0;
  29. flat int cameraIndex;
  30. } oVert;
  31.  
  32. void main()
  33. {
  34. // here we use the grid size to crate a UV lookup for our texture
  35. vec2 samplerLookup = TDInstanceTranslate().xy / (u_inst_grid/2);
  36. samplerLookup = (samplerLookup / 2) + 0.5;
  37.  
  38. // here we grab the alpha value from our texture to determine scale
  39. float scale = texture(s_scaleRef, samplerLookup).a * u_disp_scale;
  40.  
  41. // let's also grab our texture for rotation
  42. float rotAngle = texture(s_rot, samplerLookup).r * u_rot_max;
  43.  
  44. // rotate the instance
  45. vec2 instRot = rotate2D(rotAngle, TDInstanceTranslate().xy);
  46.  
  47. vec3 new_p = P;
  48.  
  49. new_p.xy += instRot;
  50.  
  51. // scale the instance
  52. new_p *= scale;
  53.  
  54. // First deform the vertex and normal
  55. // TDDeform always returns values in world space
  56. vec4 worldSpacePos =TDDeform(new_p);
  57. gl_Position = TDWorldToProj(worldSpacePos);
  58.  
  59. // This is here to ensure we only execute lighting etc. code
  60. // when we need it. If picking is active we don't need this, so
  61. // this entire block of code will be ommited from the compile.
  62. // The TD_PICKING_ACTIVE define will be set automatically when
  63. // picking is active.
  64. #ifndef TD_PICKING_ACTIVE
  65.  
  66. { // Avoid duplicate variable defs
  67. vec3 texcoord = TDInstanceTexCoord(uv[0]);
  68. oVert.texCoord0.stp = texcoord.stp;
  69. }
  70. int cameraIndex = TDCameraIndex();
  71. oVert.cameraIndex = cameraIndex;
  72. oVert.worldSpacePos.xyz = worldSpacePos.xyz;
  73. oVert.color = TDInstanceColor(Cd);
  74. vec3 worldSpaceNorm = normalize(TDDeformNorm(N));
  75. oVert.worldSpaceNorm.xyz = worldSpaceNorm;
  76.  
  77. #else // TD_PICKING_ACTIVE
  78.  
  79. // This will automatically write out the nessessary values
  80. // for this shader to work with picking.
  81. // See the documentation if you want to write custom values for picking.
  82. TDWritePickingValues();
  83.  
  84. #endif // TD_PICKING_ACTIVE
  85. }
Add Comment
Please, Sign In to add comment