Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- language: java -->
- public void drawScatter() {
- // This is not the floor!
- GLES20.glUniform1f(mIsFloorParam, 0f);
- // Set the Model in the shader, used to calculate lighting
- //GLES20.glUniformMatrix4fv(mModelParam, 1, false, mModelCube, 0);
- // Set the ModelView in the shader, used to calculate lighting
- GLES20.glUniformMatrix4fv(mModelViewParam, 1, false, mModelView, 0);
- // Set the position of the points
- GLES20.glVertexAttribPointer(mPositionParam, COORDS_PER_VERTEX, GLES20.GL_FLOAT,
- false, 0, mPointVertices);
- // Set the ModelViewProjection matrix in the shader.
- GLES20.glUniformMatrix4fv(mModelViewProjectionParam, 1, false, mModelViewProjection, 0);
- // Set the normal positions of the cube, again for shading
- //GLES20.glVertexAttribPointer(mNormalParam, 3, GLES20.GL_FLOAT,
- // false, 0, mCubeNormals);
- GLES20.glVertexAttribPointer(mColorParam, 4, GLES20.GL_FLOAT, false,
- 0, mPointColors);
- //36 -> number of points
- GLES20.glDrawArrays(GLES20.GL_POINTS, 0, (int) DATA.POINT_COORDS.length/3);
- checkGLError("Drawing points");
- }
- uniform mat4 u_MVP;
- uniform mat4 u_MVMatrix;
- uniform mat4 u_Model;
- uniform vec3 u_LightPos;
- uniform float u_IsFloor;
- attribute vec4 a_Position;
- attribute vec4 a_Color;
- attribute vec3 a_Normal;
- varying vec4 v_Color;
- varying vec3 v_Grid;
- varying float v_isFloor;
- void main()
- {
- vec3 modelVertex = vec3(u_Model * a_Position);
- v_Grid = modelVertex;
- v_isFloor = u_IsFloor;
- if (v_isFloor > 0.5) {
- vec3 modelViewVertex = vec3(u_MVMatrix * a_Position);
- vec3 modelViewNormal = vec3(u_MVMatrix * vec4(a_Normal, 0.0));
- float distance = length(u_LightPos - modelViewVertex);
- vec3 lightVector = normalize(u_LightPos - modelViewVertex);
- float diffuse = max(dot(modelViewNormal, lightVector), 0.5 );
- diffuse = diffuse * (1.0 / (1.0 + (0.00001 * distance * distance)));
- v_Color = a_Color * diffuse;
- gl_Position = u_MVP * a_Position;
- } else {
- vec3 modelViewVertex = vec3(u_MVMatrix * a_Position);
- float distance = length(u_LightPos - modelViewVertex);
- float diffuse = 1.0 / (1.0 + (0.00001 * distance * distance));
- v_Color = a_Color * diffuse;
- gl_Position = a_Position;
- gl_PointSize = 10.0/(distance*.15);
- }
- }
- <!-- language: java -->
- @Override
- public void onNewFrame(HeadTransform headTransform) {
- GLES20.glUseProgram(mGlProgram);
- mModelViewProjectionParam = GLES20.glGetUniformLocation(mGlProgram, "u_MVP");
- mLightPosParam = GLES20.glGetUniformLocation(mGlProgram, "u_LightPos");
- mModelViewParam = GLES20.glGetUniformLocation(mGlProgram, "u_MVMatrix");
- mModelParam = GLES20.glGetUniformLocation(mGlProgram, "u_Model");
- mIsFloorParam = GLES20.glGetUniformLocation(mGlProgram, "u_IsFloor");
- // Build the Model part of the ModelView matrix. I don't know if I want this
- Matrix.rotateM(mModelCube, 0, TIME_DELTA, 0.5f, 0.5f, 1.0f);
- // Build the camera matrix and apply it to the ModelView.
- Matrix.setLookAtM(mCamera, 0, 0.0f, 0.0f, CAMERA_Z, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
- headTransform.getHeadView(mHeadView, 0);
- checkGLError("onReadyToDraw");
- }
- @Override
- public void onDrawEye(EyeTransform transform) {
- GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
- mPositionParam = GLES20.glGetAttribLocation(mGlProgram, "a_Position");
- mNormalParam = GLES20.glGetAttribLocation(mGlProgram, "a_Normal");
- mColorParam = GLES20.glGetAttribLocation(mGlProgram, "a_Color");
- GLES20.glEnableVertexAttribArray(mPositionParam);
- GLES20.glEnableVertexAttribArray(mColorParam);
- checkGLError("mColorParam");
- // Apply the eye transformation to the camera.
- Matrix.multiplyMM(mView, 0, transform.getEyeView(), 0, mCamera, 0);
- // Set the position of the light
- Matrix.multiplyMV(mLightPosInEyeSpace, 0, mView, 0, mLightPosInWorldSpace, 0);
- GLES20.glUniform3f(mLightPosParam, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1],
- mLightPosInEyeSpace[2]);
- // Build the ModelView and ModelViewProjection matrices
- // for calculating cube position and light.
- Matrix.multiplyMM(mModelView, 0, mView, 0, mModelCube, 0);
- Matrix.multiplyMM(mModelViewProjection, 0, transform.getPerspective(), 0, mModelView, 0);
- drawScatter();
- // Set mModelView for the floor, so we draw floor in the correct location
- Matrix.multiplyMM(mModelView, 0, mView, 0, mModelFloor, 0);
- Matrix.multiplyMM(mModelViewProjection, 0, transform.getPerspective(), 0,
- mModelView, 0);
- drawFloor(transform.getPerspective());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement