| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" | 5 #include "chrome/browser/android/vr_shell/vr_shell_renderer.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 } | 201 } |
| 202 /* clang-format on */); | 202 /* clang-format on */); |
| 203 case vr_shell::ShaderID::LASER_FRAGMENT_SHADER: | 203 case vr_shell::ShaderID::LASER_FRAGMENT_SHADER: |
| 204 return SHADER( | 204 return SHADER( |
| 205 /* clang-format off */ | 205 /* clang-format off */ |
| 206 varying mediump vec2 v_TexCoordinate; | 206 varying mediump vec2 v_TexCoordinate; |
| 207 uniform sampler2D texture_unit; | 207 uniform sampler2D texture_unit; |
| 208 uniform lowp vec4 color; | 208 uniform lowp vec4 color; |
| 209 uniform mediump float fade_point; | 209 uniform mediump float fade_point; |
| 210 uniform mediump float fade_end; | 210 uniform mediump float fade_end; |
| 211 uniform mediump float u_Opacity; |
| 211 | 212 |
| 212 void main() { | 213 void main() { |
| 213 mediump vec2 uv = v_TexCoordinate; | 214 mediump vec2 uv = v_TexCoordinate; |
| 214 mediump float front_fade_factor = 1.0 - | 215 mediump float front_fade_factor = 1.0 - |
| 215 clamp(1.0 - (uv.y - fade_point) / (1.0 - fade_point), 0.0, 1.0); | 216 clamp(1.0 - (uv.y - fade_point) / (1.0 - fade_point), 0.0, 1.0); |
| 216 mediump float back_fade_factor = | 217 mediump float back_fade_factor = |
| 217 clamp((uv.y - fade_point) / (fade_end - fade_point), 0.0, 1.0); | 218 clamp((uv.y - fade_point) / (fade_end - fade_point), 0.0, 1.0); |
| 218 mediump float total_fade = front_fade_factor * back_fade_factor; | 219 mediump float total_fade = front_fade_factor * back_fade_factor; |
| 219 lowp vec4 texture_color = texture2D(texture_unit, uv); | 220 lowp vec4 texture_color = texture2D(texture_unit, uv); |
| 220 lowp vec4 final_color = color * texture_color; | 221 lowp vec4 final_color = color * texture_color; |
| 221 gl_FragColor = vec4(final_color.xyz, final_color.w * total_fade); | 222 gl_FragColor = vec4(final_color.xyz, |
| 223 final_color.w * total_fade * u_Opacity); |
| 222 } | 224 } |
| 223 /* clang-format on */); | 225 /* clang-format on */); |
| 224 case vr_shell::ShaderID::GRADIENT_QUAD_FRAGMENT_SHADER: | 226 case vr_shell::ShaderID::GRADIENT_QUAD_FRAGMENT_SHADER: |
| 225 case vr_shell::ShaderID::GRADIENT_GRID_FRAGMENT_SHADER: | 227 case vr_shell::ShaderID::GRADIENT_GRID_FRAGMENT_SHADER: |
| 226 return OEIE_SHADER( | 228 return OEIE_SHADER( |
| 227 /* clang-format off */ | 229 /* clang-format off */ |
| 228 precision highp float; | 230 precision highp float; |
| 229 varying vec2 v_GridPosition; | 231 varying vec2 v_GridPosition; |
| 230 uniform vec4 u_CenterColor; | 232 uniform vec4 u_CenterColor; |
| 231 uniform vec4 u_EdgeColor; | 233 uniform vec4 u_EdgeColor; |
| 232 uniform mediump float u_Opacity; | 234 uniform mediump float u_Opacity; |
| 233 | 235 |
| 234 void main() { | 236 void main() { |
| 235 float edgeColorWeight = clamp(length(v_GridPosition), 0.0, 1.0); | 237 float edgeColorWeight = clamp(length(v_GridPosition), 0.0, 1.0); |
| 236 float centerColorWeight = 1.0 - edgeColorWeight; | 238 float centerColorWeight = 1.0 - edgeColorWeight; |
| 237 gl_FragColor = (u_CenterColor * centerColorWeight + | 239 gl_FragColor = (u_CenterColor * centerColorWeight + |
| 238 u_EdgeColor * edgeColorWeight) * vec4(1.0, 1.0, 1.0, u_Opacity); | 240 u_EdgeColor * edgeColorWeight) * vec4(1.0, 1.0, 1.0, u_Opacity); |
| 239 } | 241 } |
| 240 /* clang-format on */); | 242 /* clang-format on */); |
| 241 case vr_shell::ShaderID::CONTROLLER_FRAGMENT_SHADER: | 243 case vr_shell::ShaderID::CONTROLLER_FRAGMENT_SHADER: |
| 242 return SHADER( | 244 return SHADER( |
| 243 /* clang-format off */ | 245 /* clang-format off */ |
| 244 precision mediump float; | 246 precision mediump float; |
| 245 uniform sampler2D u_texture; | 247 uniform sampler2D u_texture; |
| 246 varying vec2 v_TexCoordinate; | 248 varying vec2 v_TexCoordinate; |
| 249 uniform mediump float u_Opacity; |
| 247 | 250 |
| 248 void main() { | 251 void main() { |
| 249 gl_FragColor = texture2D(u_texture, v_TexCoordinate); | 252 lowp vec4 texture_color = texture2D(u_texture, v_TexCoordinate); |
| 253 gl_FragColor = vec4(texture_color.xyz, texture_color.w * u_Opacity); |
| 250 } | 254 } |
| 251 /* clang-format on */); | 255 /* clang-format on */); |
| 252 default: | 256 default: |
| 253 LOG(ERROR) << "Shader source requested for unknown shader"; | 257 LOG(ERROR) << "Shader source requested for unknown shader"; |
| 254 return ""; | 258 return ""; |
| 255 } | 259 } |
| 256 } | 260 } |
| 257 | 261 |
| 258 } // namespace | 262 } // namespace |
| 259 | 263 |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 ReticleRenderer::~ReticleRenderer() = default; | 541 ReticleRenderer::~ReticleRenderer() = default; |
| 538 | 542 |
| 539 LaserRenderer::LaserRenderer() | 543 LaserRenderer::LaserRenderer() |
| 540 : BaseQuadRenderer(LASER_VERTEX_SHADER, LASER_FRAGMENT_SHADER) { | 544 : BaseQuadRenderer(LASER_VERTEX_SHADER, LASER_FRAGMENT_SHADER) { |
| 541 model_view_proj_matrix_handle_ = | 545 model_view_proj_matrix_handle_ = |
| 542 glGetUniformLocation(program_handle_, "u_ModelViewProjMatrix"); | 546 glGetUniformLocation(program_handle_, "u_ModelViewProjMatrix"); |
| 543 texture_unit_handle_ = glGetUniformLocation(program_handle_, "texture_unit"); | 547 texture_unit_handle_ = glGetUniformLocation(program_handle_, "texture_unit"); |
| 544 color_handle_ = glGetUniformLocation(program_handle_, "color"); | 548 color_handle_ = glGetUniformLocation(program_handle_, "color"); |
| 545 fade_point_handle_ = glGetUniformLocation(program_handle_, "fade_point"); | 549 fade_point_handle_ = glGetUniformLocation(program_handle_, "fade_point"); |
| 546 fade_end_handle_ = glGetUniformLocation(program_handle_, "fade_end"); | 550 fade_end_handle_ = glGetUniformLocation(program_handle_, "fade_end"); |
| 551 opacity_handle_ = glGetUniformLocation(program_handle_, "u_Opacity"); |
| 547 | 552 |
| 548 glGenTextures(1, &texture_data_handle_); | 553 glGenTextures(1, &texture_data_handle_); |
| 549 glBindTexture(GL_TEXTURE_2D, texture_data_handle_); | 554 glBindTexture(GL_TEXTURE_2D, texture_data_handle_); |
| 550 | 555 |
| 551 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kLaserDataWidth, kLaserDataHeight, 0, | 556 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kLaserDataWidth, kLaserDataHeight, 0, |
| 552 GL_RGBA, GL_UNSIGNED_BYTE, kLaserData); | 557 GL_RGBA, GL_UNSIGNED_BYTE, kLaserData); |
| 553 | 558 |
| 554 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 559 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 555 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 560 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 556 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 561 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 557 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 562 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 558 } | 563 } |
| 559 | 564 |
| 560 void LaserRenderer::Draw(const vr::Mat4f& view_proj_matrix) { | 565 void LaserRenderer::Draw(float opacity, const vr::Mat4f& view_proj_matrix) { |
| 561 PrepareToDraw(model_view_proj_matrix_handle_, view_proj_matrix); | 566 PrepareToDraw(model_view_proj_matrix_handle_, view_proj_matrix); |
| 562 | 567 |
| 563 // Link texture data with texture unit. | 568 // Link texture data with texture unit. |
| 564 glActiveTexture(GL_TEXTURE0); | 569 glActiveTexture(GL_TEXTURE0); |
| 565 glBindTexture(GL_TEXTURE_2D, texture_data_handle_); | 570 glBindTexture(GL_TEXTURE_2D, texture_data_handle_); |
| 566 | 571 |
| 567 glUniform1i(texture_unit_handle_, 0); | 572 glUniform1i(texture_unit_handle_, 0); |
| 568 glUniform4f(color_handle_, kLaserColor[0], kLaserColor[1], kLaserColor[2], | 573 glUniform4f(color_handle_, kLaserColor[0], kLaserColor[1], kLaserColor[2], |
| 569 kLaserColor[3]); | 574 kLaserColor[3]); |
| 570 glUniform1f(fade_point_handle_, kFadePoint); | 575 glUniform1f(fade_point_handle_, kFadePoint); |
| 571 glUniform1f(fade_end_handle_, kFadeEnd); | 576 glUniform1f(fade_end_handle_, kFadeEnd); |
| 577 glUniform1f(opacity_handle_, opacity); |
| 572 | 578 |
| 573 glDrawArrays(GL_TRIANGLES, 0, kVerticesNumber); | 579 glDrawArrays(GL_TRIANGLES, 0, kVerticesNumber); |
| 574 | 580 |
| 575 glDisableVertexAttribArray(position_handle_); | 581 glDisableVertexAttribArray(position_handle_); |
| 576 glDisableVertexAttribArray(tex_coord_handle_); | 582 glDisableVertexAttribArray(tex_coord_handle_); |
| 577 } | 583 } |
| 578 | 584 |
| 579 LaserRenderer::~LaserRenderer() = default; | 585 LaserRenderer::~LaserRenderer() = default; |
| 580 | 586 |
| 581 ControllerRenderer::ControllerRenderer() | 587 ControllerRenderer::ControllerRenderer() |
| 582 : BaseRenderer(CONTROLLER_VERTEX_SHADER, CONTROLLER_FRAGMENT_SHADER), | 588 : BaseRenderer(CONTROLLER_VERTEX_SHADER, CONTROLLER_FRAGMENT_SHADER), |
| 583 texture_handles_(VrControllerModel::STATE_COUNT) { | 589 texture_handles_(VrControllerModel::STATE_COUNT) { |
| 584 model_view_proj_matrix_handle_ = | 590 model_view_proj_matrix_handle_ = |
| 585 glGetUniformLocation(program_handle_, "u_ModelViewProjMatrix"); | 591 glGetUniformLocation(program_handle_, "u_ModelViewProjMatrix"); |
| 586 tex_uniform_handle_ = glGetUniformLocation(program_handle_, "u_Texture"); | 592 tex_uniform_handle_ = glGetUniformLocation(program_handle_, "u_Texture"); |
| 593 opacity_handle_ = glGetUniformLocation(program_handle_, "u_Opacity"); |
| 587 } | 594 } |
| 588 | 595 |
| 589 ControllerRenderer::~ControllerRenderer() = default; | 596 ControllerRenderer::~ControllerRenderer() = default; |
| 590 | 597 |
| 591 void ControllerRenderer::SetUp(std::unique_ptr<VrControllerModel> model) { | 598 void ControllerRenderer::SetUp(std::unique_ptr<VrControllerModel> model) { |
| 592 glGenBuffersARB(1, &indices_buffer_); | 599 glGenBuffersARB(1, &indices_buffer_); |
| 593 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indices_buffer_); | 600 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indices_buffer_); |
| 594 glBufferData(GL_ELEMENT_ARRAY_BUFFER, model->IndicesBufferSize(), | 601 glBufferData(GL_ELEMENT_ARRAY_BUFFER, model->IndicesBufferSize(), |
| 595 model->IndicesBuffer(), GL_STATIC_DRAW); | 602 model->IndicesBuffer(), GL_STATIC_DRAW); |
| 596 | 603 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 625 | 632 |
| 626 draw_mode_ = model->DrawMode(); | 633 draw_mode_ = model->DrawMode(); |
| 627 accessor = model->IndicesAccessor(); | 634 accessor = model->IndicesAccessor(); |
| 628 indices_count_ = accessor->count; | 635 indices_count_ = accessor->count; |
| 629 indices_type_ = accessor->component_type; | 636 indices_type_ = accessor->component_type; |
| 630 indices_offset_ = VOID_OFFSET(accessor->byte_offset); | 637 indices_offset_ = VOID_OFFSET(accessor->byte_offset); |
| 631 setup_ = true; | 638 setup_ = true; |
| 632 } | 639 } |
| 633 | 640 |
| 634 void ControllerRenderer::Draw(VrControllerModel::State state, | 641 void ControllerRenderer::Draw(VrControllerModel::State state, |
| 642 float opacity, |
| 635 const vr::Mat4f& view_proj_matrix) { | 643 const vr::Mat4f& view_proj_matrix) { |
| 636 glUseProgram(program_handle_); | 644 glUseProgram(program_handle_); |
| 637 | 645 |
| 646 glUniform1f(opacity_handle_, opacity); |
| 647 |
| 638 glUniformMatrix4fv(model_view_proj_matrix_handle_, 1, false, | 648 glUniformMatrix4fv(model_view_proj_matrix_handle_, 1, false, |
| 639 MatrixToGLArray(view_proj_matrix).data()); | 649 MatrixToGLArray(view_proj_matrix).data()); |
| 640 | 650 |
| 641 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_); | 651 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_); |
| 642 | 652 |
| 643 glVertexAttribPointer(position_handle_, position_components_, position_type_, | 653 glVertexAttribPointer(position_handle_, position_components_, position_type_, |
| 644 GL_FALSE, position_stride_, position_offset_); | 654 GL_FALSE, position_stride_, position_offset_); |
| 645 glEnableVertexAttribArray(position_handle_); | 655 glEnableVertexAttribArray(position_handle_); |
| 646 | 656 |
| 647 glVertexAttribPointer(tex_coord_handle_, tex_coord_components_, | 657 glVertexAttribPointer(tex_coord_handle_, tex_coord_components_, |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 GradientGridRenderer* VrShellRenderer::GetGradientGridRenderer() { | 845 GradientGridRenderer* VrShellRenderer::GetGradientGridRenderer() { |
| 836 Flush(); | 846 Flush(); |
| 837 return gradient_grid_renderer_.get(); | 847 return gradient_grid_renderer_.get(); |
| 838 } | 848 } |
| 839 | 849 |
| 840 void VrShellRenderer::Flush() { | 850 void VrShellRenderer::Flush() { |
| 841 textured_quad_renderer_->Flush(); | 851 textured_quad_renderer_->Flush(); |
| 842 } | 852 } |
| 843 | 853 |
| 844 } // namespace vr_shell | 854 } // namespace vr_shell |
| OLD | NEW |