Advertisement
Guest User

Untitled

a guest
Jul 31st, 2014
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 KB | None | 0 0
  1. <!-- language: java -->
  2. public void drawScatter() {
  3. // This is not the floor!
  4. GLES20.glUniform1f(mIsFloorParam, 0f);
  5.  
  6. // Set the Model in the shader, used to calculate lighting
  7. //GLES20.glUniformMatrix4fv(mModelParam, 1, false, mModelCube, 0);
  8.  
  9. // Set the ModelView in the shader, used to calculate lighting
  10. GLES20.glUniformMatrix4fv(mModelViewParam, 1, false, mModelView, 0);
  11.  
  12. // Set the position of the points
  13. GLES20.glVertexAttribPointer(mPositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT,
  14. false, 0, mPointVertices);
  15.  
  16. // Set the ModelViewProjection matrix in the shader.
  17. GLES20.glUniformMatrix4fv(mModelViewProjectionParam, 1, false, mModelViewProjection, 0);
  18.  
  19. // Set the normal positions of the cube, again for shading
  20. //GLES20.glVertexAttribPointer(mNormalParam, 3, GLES20.GL_FLOAT,
  21. // false, 0, mCubeNormals);
  22.  
  23.  
  24.  
  25.  
  26. GLES20.glVertexAttribPointer(mColorParam, 4, GLES20.GL_FLOAT, false,
  27. 0, mPointColors);
  28.  
  29. //36 -> number of points
  30. GLES20.glDrawArrays(GLES20.GL_POINTS, 0, (int) DATA.POINT_COORDS.length/3);
  31. checkGLError("Drawing points");
  32. }
  33.  
  34. uniform mat4 u_MVP;
  35. uniform mat4 u_MVMatrix;
  36. uniform mat4 u_Model;
  37. uniform vec3 u_LightPos;
  38. uniform float u_IsFloor;
  39. attribute vec4 a_Position;
  40. attribute vec4 a_Color;
  41. attribute vec3 a_Normal;
  42. varying vec4 v_Color;
  43. varying vec3 v_Grid;
  44. varying float v_isFloor;
  45.  
  46. void main()
  47. {
  48. vec3 modelVertex = vec3(u_Model * a_Position);
  49. v_Grid = modelVertex;
  50. v_isFloor = u_IsFloor;
  51. if (v_isFloor > 0.5) {
  52. vec3 modelViewVertex = vec3(u_MVMatrix * a_Position);
  53. vec3 modelViewNormal = vec3(u_MVMatrix * vec4(a_Normal, 0.0));
  54. float distance = length(u_LightPos - modelViewVertex);
  55. vec3 lightVector = normalize(u_LightPos - modelViewVertex);
  56. float diffuse = max(dot(modelViewNormal, lightVector), 0.5 );
  57. diffuse = diffuse * (1.0 / (1.0 + (0.00001 * distance * distance)));
  58. v_Color = a_Color * diffuse;
  59. gl_Position = u_MVP * a_Position;
  60. } else {
  61. vec3 modelViewVertex = vec3(u_MVMatrix * a_Position);
  62. float distance = length(u_LightPos - modelViewVertex);
  63. float diffuse = 1.0 / (1.0 + (0.00001 * distance * distance));
  64. v_Color = a_Color * diffuse;
  65. gl_Position = a_Position;
  66. gl_PointSize = 10.0/(distance*.15);
  67.  
  68. }
  69.  
  70. }
  71.  
  72. <!-- language: java -->
  73. @Override
  74. public void onNewFrame(HeadTransform headTransform) {
  75. GLES20.glUseProgram(mGlProgram);
  76. mModelViewProjectionParam = GLES20.glGetUniformLocation(mGlProgram, "u_MVP");
  77. mLightPosParam = GLES20.glGetUniformLocation(mGlProgram, "u_LightPos");
  78. mModelViewParam = GLES20.glGetUniformLocation(mGlProgram, "u_MVMatrix");
  79. mModelParam = GLES20.glGetUniformLocation(mGlProgram, "u_Model");
  80. mIsFloorParam = GLES20.glGetUniformLocation(mGlProgram, "u_IsFloor");
  81.  
  82. // Build the Model part of the ModelView matrix. I don't know if I want this
  83. Matrix.rotateM(mModelCube, 0, TIME_DELTA, 0.5f, 0.5f, 1.0f);
  84.  
  85. // Build the camera matrix and apply it to the ModelView.
  86. Matrix.setLookAtM(mCamera, 0, 0.0f, 0.0f, CAMERA_Z, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
  87.  
  88. headTransform.getHeadView(mHeadView, 0);
  89.  
  90. checkGLError("onReadyToDraw");
  91. }
  92.  
  93. @Override
  94. public void onDrawEye(EyeTransform transform) {
  95. GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
  96.  
  97. mPositionParam = GLES20.glGetAttribLocation(mGlProgram, "a_Position");
  98. mNormalParam = GLES20.glGetAttribLocation(mGlProgram, "a_Normal");
  99. mColorParam = GLES20.glGetAttribLocation(mGlProgram, "a_Color");
  100.  
  101. GLES20.glEnableVertexAttribArray(mPositionParam);
  102. GLES20.glEnableVertexAttribArray(mColorParam);
  103. checkGLError("mColorParam");
  104.  
  105. // Apply the eye transformation to the camera.
  106. Matrix.multiplyMM(mView, 0, transform.getEyeView(), 0, mCamera, 0);
  107.  
  108. // Set the position of the light
  109. Matrix.multiplyMV(mLightPosInEyeSpace, 0, mView, 0, mLightPosInWorldSpace, 0);
  110. GLES20.glUniform3f(mLightPosParam, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1],
  111. mLightPosInEyeSpace[2]);
  112.  
  113. // Build the ModelView and ModelViewProjection matrices
  114. // for calculating cube position and light.
  115. Matrix.multiplyMM(mModelView, 0, mView, 0, mModelCube, 0);
  116. Matrix.multiplyMM(mModelViewProjection, 0, transform.getPerspective(), 0, mModelView, 0);
  117. drawScatter();
  118.  
  119. // Set mModelView for the floor, so we draw floor in the correct location
  120. Matrix.multiplyMM(mModelView, 0, mView, 0, mModelFloor, 0);
  121. Matrix.multiplyMM(mModelViewProjection, 0, transform.getPerspective(), 0,
  122. mModelView, 0);
  123. drawFloor(transform.getPerspective());
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement