Guest User

Untitled

a guest
Dec 11th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. this.createProgramObject = function(vetexShaderSource, fragmentShaderSource) {
  2. var vertexShaderObject = this.ctx.createShader(this.ctx.VERTEX_SHADER);
  3. this.ctx.shaderSource(vertexShaderObject, vetexShaderSource);
  4. this.ctx.compileShader(vertexShaderObject);
  5. if (!this.ctx.getShaderParameter(vertexShaderObject, this.ctx.COMPILE_STATUS)) {
  6. throw this.ctx.getShaderInfoLog(vertexShaderObject);
  7. }
  8. var fragmentShaderObject = this.ctx.createShader(this.ctx.FRAGMENT_SHADER);
  9. this.ctx.shaderSource(fragmentShaderObject, fragmentShaderSource);
  10. this.ctx.compileShader(fragmentShaderObject);
  11. if (!this.ctx.getShaderParameter(fragmentShaderObject, this.ctx.COMPILE_STATUS)) {
  12. throw this.ctx.getShaderInfoLog(fragmentShaderObject);
  13. }
  14. var programObject = this.ctx.createProgram();
  15. this.ctx.attachShader(programObject, vertexShaderObject);
  16. this.ctx.attachShader(programObject, fragmentShaderObject);
  17. this.ctx.linkProgram(programObject);
  18. if (!this.ctx.getProgramParameter(programObject, this.ctx.LINK_STATUS)) {
  19. throw ("Error linking shaders:" + this.ctx.getProgramInfoLog(programObject));
  20. }
  21. return programObject;
  22. };
  23.  
  24. attribute vec3 aVertexPosition;
  25. attribute vec4 aVertexColor;
  26.  
  27. uniform mat4 uModelViewMatrix;
  28. uniform mat4 uProjectionMatrix;
  29. uniform float uPointSize;
  30.  
  31. //for undetermined point attenuation feature
  32. // uniform vec3 uAttenuation;
  33.  
  34. uniform vec3 uBias;
  35. uniform vec3 uScale;
  36. uniform int uCEMode;
  37.  
  38. varying vec4 vColor;
  39.  
  40. void main(void) {
  41. if(uCEMode == 1) {
  42. //use bias and scale unifroms for min max color enhancement
  43. vColor = (aVertexColor - vec4(uBias, 0.0)) * vec4(uScale, 1.0);
  44. }
  45. else {
  46. vColor = aVertexColor;
  47. }
  48.  
  49. vec4 ecPos4 = uModelViewMatrix * vec4(aVertexPosition, 1.0);
  50.  
  51. //make points larger as they get further away from the viewer
  52. //helps to make the cloud look less sparse when far enough to only see
  53. //the first level or two of the octree
  54. gl_PointSize = length(ecPos4) / uPointSize * 3.0;
  55.  
  56. //for undetermined point attenuation feature
  57. // float attn = uAttenuation[0] + (uAttenuation[1] * dist) + (uAttenuation[2] * dist * dist);
  58. // gl_PointSize = (attn > 0.0 && attn < uPointSize) ? uPointSize * sqrt(1.0/attn) : uPointSize;
  59.  
  60. gl_Position = uProjectionMatrix * ecPos4;
  61. }
  62.  
  63. varying highp vec4 vColor;
  64.  
  65. void main(void) {
  66. gl_FragColor = vColor;
  67. }
  68.  
  69. Uncaught Error linking shaders:Varyings with the same name but different type, or statically used varyings in fragment shader are not declared in vertex shader: vColor
  70.  
  71. #ifdef GL_FRAGMENT_PRECISION_HIGH
  72. precision highp float;
  73. #else
  74. precision mediump float;
  75. #endif
Add Comment
Please, Sign In to add comment