shaders.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2014 Google Inc. All Rights Reserved.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #include "tango-gl/shaders.h"
00017 
00018 namespace tango_gl {
00019 namespace shaders {
00020 std::string GetBasicVertexShader() {
00021   return "precision mediump float;\n"
00022          "precision mediump int;\n"
00023          "attribute vec4 vertex;\n"
00024          "uniform mat4 mvp;\n"
00025          "uniform vec4 color;\n"
00026          "varying vec4 v_color;\n"
00027          "void main() {\n"
00028          "  gl_Position = mvp*vertex;\n"
00029          "  v_color = color;\n"
00030          "}\n";
00031 }
00032 
00033 std::string GetBasicFragmentShader() {
00034   return "precision mediump float;\n"
00035          "varying vec4 v_color;\n"
00036          "void main() {\n"
00037          "  gl_FragColor = v_color;\n"
00038          "}\n";
00039 }
00040 
00041 std::string GetColorVertexShader() {
00042   return "precision mediump float;\n"
00043          "precision mediump int;\n"
00044          "attribute vec4 vertex;\n"
00045          "attribute vec4 color;\n"
00046          "uniform mat4 mvp;\n"
00047          "varying vec4 v_color;\n"
00048          "void main() {\n"
00049          "  gl_Position = mvp*vertex;\n"
00050          "  v_color = color;\n"
00051          "}\n";
00052 }
00053 
00054 std::string GetVideoOverlayVertexShader() {
00055   return "precision highp float;\n"
00056          "precision highp int;\n"
00057          "attribute vec4 vertex;\n"
00058          "attribute vec2 textureCoords;\n"
00059          "varying vec2 f_textureCoords;\n"
00060          "uniform mat4 mvp;\n"
00061          "void main() {\n"
00062          "  f_textureCoords = textureCoords;\n"
00063          "  gl_Position = mvp * vertex;\n"
00064          "}\n";
00065 }
00066 
00067 std::string GetVideoOverlayFragmentShader() {
00068   return "#extension GL_OES_EGL_image_external : require\n"
00069          "precision highp float;\n"
00070          "precision highp int;\n"
00071          "uniform samplerExternalOES texture;\n"
00072          "varying vec2 f_textureCoords;\n"
00073          "void main() {\n"
00074          "  gl_FragColor = texture2D(texture, f_textureCoords);\n"
00075          "}\n";
00076 }
00077 
00078 std::string GetShadedVertexShader() {
00079   return "attribute vec4 vertex;\n"
00080          "attribute vec3 normal;\n"
00081          "uniform mat4 mvp;\n"
00082          "uniform mat4 mv;\n"
00083          "uniform vec4 color;\n"
00084          "uniform vec3 lightVec;\n"
00085          "varying vec4 v_color;\n"
00086          "void main() {\n"
00087          "  vec3 mvNormal = vec3(mv * vec4(normal, 0.0));\n"
00088          "  float diffuse = max(-dot(mvNormal, lightVec), 0.0);\n"
00089          "  v_color.a = color.a;\n"
00090          "  v_color.xyz = color.xyz * diffuse + color.xyz * 0.3;\n"
00091          "  gl_Position = mvp*vertex;\n"
00092          "}\n";
00093 }
00094 }  // namespace shaders
00095 }  // namespace tango_gl


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jun 6 2019 21:59:22