[Libreoffice-commits] core.git: 3 commits - chart2/opengl chart2/Package_opengl.mk chart2/source

weigao weigao at multicorewareinc.com
Mon Jun 16 23:33:25 PDT 2014


 chart2/Package_opengl.mk                     |    2 
 chart2/opengl/shape3DFragmentShaderV300.glsl |   87 ++++++++++
 chart2/opengl/shape3DVertexShaderV300.glsl   |   29 +++
 chart2/source/view/inc/GL3DRenderer.hxx      |   20 ++
 chart2/source/view/main/GL3DRenderer.cxx     |  228 +++++++++++++++++++++------
 5 files changed, 321 insertions(+), 45 deletions(-)

New commits:
commit 7c5580874ccb403baec7a067a6fb55182a2bd354
Author: weigao <weigao at multicorewareinc.com>
Date:   Sat Jun 14 08:59:07 2014 -0700

    add codes for calling the 3.0 shaders
    
    Change-Id: I0e95879c04047ccb836543d801bda6a01ae469ef

diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index 3566fb3..4178467 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -195,6 +195,7 @@ void OpenGL3DRenderer::CheckGLSLVersion()
     if (iVersion > 3)
     {
         maResources.m_b330Support = true;
+        maResources.m_b330Support = false;
         return;
     }
     p++;
@@ -834,11 +835,6 @@ void OpenGL3DRenderer::RenderPolygon3D(const Polygon3DInfo& polygon)
     {
         return ;
     }
-    //update ubo
-    Update3DUniformBlock();
-    glBindBuffer(GL_UNIFORM_BUFFER, m_3DUBOBuffer);
-    glBufferSubData(GL_UNIFORM_BUFFER, m_3DActualSizeLight, sizeof(MaterialParameters), &polygon.material);
-    CHECK_GL_ERROR();
     glBindBuffer(GL_UNIFORM_BUFFER, 0);
     if(mbPickingMode)
     {
@@ -849,6 +845,31 @@ void OpenGL3DRenderer::RenderPolygon3D(const Polygon3DInfo& polygon)
         glUseProgram(maResources.m_3DProID);
         glUniformMatrix4fv(maResources.m_3DViewID, 1, GL_FALSE, &m_3DView[0][0]);
         glUniformMatrix4fv(maResources.m_3DProjectionID, 1, GL_FALSE, &m_3DProjection[0][0]);
+        if (maResources.m_b330Support)
+        {
+            //update ubo
+            Update3DUniformBlock();
+            glBindBuffer(GL_UNIFORM_BUFFER, m_3DUBOBuffer);
+            glBufferSubData(GL_UNIFORM_BUFFER, m_3DActualSizeLight, sizeof(MaterialParameters), &polygon.material);
+            CHECK_GL_ERROR();
+        }
+        else
+        {
+            //update light information
+            glUniform4fv(maResources.m_3DLightColorID, m_iLightNum, (GLfloat*)m_LightColor);
+            glUniform4fv(maResources.m_3DLightPosID, m_iLightNum, (GLfloat*)m_PositionWorldspace);
+            glUniform1fv(maResources.m_3DLightPowerID, m_iLightNum, m_fLightPower);
+            glUniform1i(maResources.m_3DLightNumID, m_iLightNum);
+            glUniform4fv(maResources.m_3DLightAmbientID, 1, &m_Ambient[0]);
+            //update meterial information
+            glUniform4fv(maResources.m_3DMaterialAmbientID, 1, &polygon.material.ambient[0]);
+            glUniform4fv(maResources.m_3DMaterialDiffuseID, 1, &polygon.material.diffuse[0]);
+            glUniform4fv(maResources.m_3DMaterialSpecularID, 1, &polygon.material.specular[0]);
+            glUniform4fv(maResources.m_3DMaterialColorID, 1, &polygon.material.materialColor[0]);
+            glUniform1i(maResources.m_3DMaterialTwoSidesID, polygon.material.twoSidesLighting);
+            glUniform1f(maResources.m_3DMaterialShininessID, polygon.material.shininess);
+            CHECK_GL_ERROR();
+        }
     }
     for (size_t i = 0; i < verticesNum; i++)
     {
@@ -968,26 +989,45 @@ void OpenGL3DRenderer::RenderPolygon3DObject()
 void OpenGL3DRenderer::Set3DSenceInfo(sal_uInt32 nColor, bool twoSidesLighting)
 {
     m_Polygon3DInfo.material.twoSidesLighting = twoSidesLighting;
-
-    m_LightsInfo.ambient = getColorAsVector(nColor);
-
-    m_LightsInfo.lightNum = 0;
+    if (maResources.m_b330Support)
+    {
+        m_LightsInfo.ambient = getColorAsVector(nColor);
+        m_LightsInfo.lightNum = 0;
+    }
+    else
+    {
+        m_iLightNum = 0;
+        m_Ambient = getColorAsVector(nColor);;
+    }
     SetLightInfo(true, 0xFFFFFF, glm::vec4(1.0, 1.0, 1.0, 0.0));
 }
 
 void OpenGL3DRenderer::SetLightInfo(bool lightOn, sal_uInt32 nColor, const glm::vec4& direction)
 {
-    if (m_LightsInfo.lightNum >= MAX_LIGHT_NUM)
-    {
-        return;
-    }
-
     if (lightOn)
     {
-        m_LightsInfo.light[m_LightsInfo.lightNum].lightColor = getColorAsVector(nColor);
-        m_LightsInfo.light[m_LightsInfo.lightNum].positionWorldspace = direction;
-        m_LightsInfo.light[m_LightsInfo.lightNum].lightPower = 1.0;
-        m_LightsInfo.lightNum++;
+        if (maResources.m_b330Support)
+        {
+            if (m_LightsInfo.lightNum >= MAX_LIGHT_NUM)
+            {
+                return;
+            }
+            m_LightsInfo.light[m_LightsInfo.lightNum].lightColor = getColorAsVector(nColor);
+            m_LightsInfo.light[m_LightsInfo.lightNum].positionWorldspace = direction;
+            m_LightsInfo.light[m_LightsInfo.lightNum].lightPower = 1.0;
+            m_LightsInfo.lightNum++;
+        }
+        else
+        {
+            if (m_iLightNum >= MAX_LIGHT_NUM)
+            {
+                return;
+            }
+            m_LightColor[m_iLightNum] = getColorAsVector(nColor);
+            m_PositionWorldspace[m_iLightNum] = direction;
+            m_fLightPower[m_iLightNum] = 1.0;
+            m_iLightNum++;
+        }
     }
 }
 
@@ -1389,7 +1429,6 @@ void OpenGL3DRenderer::RenderExtrudeTopSurface(const Extrude3DInfo& extrude3D)
         glUniform4fv(maResources.m_2DColorID, 1, &extrude3D.id[0]);
     }
     glDrawElements(GL_TRIANGLES, extrude3D.size[TOP_SURFACE], GL_UNSIGNED_SHORT, reinterpret_cast<GLvoid*>(extrude3D.startIndex[TOP_SURFACE]));
-    RenderExtrudeFlatSurface(extrude3D, FLAT_BOTTOM_SURFACE);
 }
 
 void OpenGL3DRenderer::RenderNonRoundedBar(const Extrude3DInfo& extrude3D)
@@ -1453,12 +1492,26 @@ void OpenGL3DRenderer::RenderExtrude3DObject()
     }
     else
     {
-        Update3DUniformBlock();
         glUseProgram(maResources.m_3DProID);
         glUniformMatrix4fv(maResources.m_3DViewID, 1, GL_FALSE, &m_3DView[0][0]);
         glUniformMatrix4fv(maResources.m_3DProjectionID, 1, GL_FALSE, &m_3DProjection[0][0]);
+        if (maResources.m_b330Support)
+        {
+            //update ubo
+            Update3DUniformBlock();
+            CHECK_GL_ERROR();
+        }
+        else
+        {
+            //update light information
+            glUniform4fv(maResources.m_3DLightColorID, m_iLightNum, (GLfloat*)m_LightColor);
+            glUniform4fv(maResources.m_3DLightPosID, m_iLightNum, (GLfloat*)m_PositionWorldspace);
+            glUniform1fv(maResources.m_3DLightPowerID, m_iLightNum, m_fLightPower);
+            glUniform1i(maResources.m_3DLightNumID, m_iLightNum);
+            glUniform4fv(maResources.m_3DLightAmbientID, 1, &m_Ambient[0]);
+            CHECK_GL_ERROR();
+        }
     }
-    CHECK_GL_ERROR();
     size_t extrude3DNum = m_Extrude3DList.size();
     for (size_t i = 0; i < extrude3DNum; i++)
     {
@@ -1498,10 +1551,23 @@ void OpenGL3DRenderer::RenderExtrude3DObject()
         extrude3DInfo.zScale *= m_fHeightWeight;
         if(!mbPickingMode)
         {
-            glBindBuffer(GL_UNIFORM_BUFFER, m_3DUBOBuffer);
-            glBufferSubData(GL_UNIFORM_BUFFER, m_3DActualSizeLight, sizeof(MaterialParameters), &extrude3DInfo.material);
-            CHECK_GL_ERROR();
-            glBindBuffer(GL_UNIFORM_BUFFER, 0);
+            if (maResources.m_b330Support)
+            {
+                glBindBuffer(GL_UNIFORM_BUFFER, m_3DUBOBuffer);
+                glBufferSubData(GL_UNIFORM_BUFFER, m_3DActualSizeLight, sizeof(MaterialParameters), &extrude3DInfo.material);
+                CHECK_GL_ERROR();
+                glBindBuffer(GL_UNIFORM_BUFFER, 0);
+            }
+            else
+            {
+                //update meterial information
+                glUniform4fv(maResources.m_3DMaterialAmbientID, 1, &extrude3DInfo.material.ambient[0]);
+                glUniform4fv(maResources.m_3DMaterialDiffuseID, 1, &extrude3DInfo.material.diffuse[0]);
+                glUniform4fv(maResources.m_3DMaterialSpecularID, 1, &extrude3DInfo.material.specular[0]);
+                glUniform4fv(maResources.m_3DMaterialColorID, 1, &extrude3DInfo.material.materialColor[0]);
+                glUniform1i(maResources.m_3DMaterialTwoSidesID, extrude3DInfo.material.twoSidesLighting);
+                glUniform1f(maResources.m_3DMaterialShininessID, extrude3DInfo.material.shininess);
+            }
         }
         extrude3DInfo.reverse = 0;
         if (extrude3DInfo.rounded)
@@ -1796,7 +1862,16 @@ void OpenGL3DRenderer::ProcessUnrenderedShape(bool bNewScene)
     if(mbPickingMode)
         RenderExtrude3DObject();
     else
-        RenderBatchBars(bNewScene);
+    {
+        if (maResources.m_b330Support)
+        {
+            RenderBatchBars(bNewScene);
+        }
+        else
+        {
+            RenderExtrude3DObject();
+        }
+    }
     //render text
     RenderTextShape();
     // render screen text
commit 1e3a1a050916bf530f900e4ef0241e8e9adc7158
Author: weigao <weigao at multicorewareinc.com>
Date:   Sat Jun 14 08:51:43 2014 -0700

    add codes for compile the 3.0 shaders
    
    Conflicts:
    	chart2/source/view/inc/GL3DRenderer.hxx
    
    Change-Id: Idc58635cc1604208317319bfa399a1574979a909

diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx
index ad013e9..6218fbc 100644
--- a/chart2/source/view/inc/GL3DRenderer.hxx
+++ b/chart2/source/view/inc/GL3DRenderer.hxx
@@ -230,10 +230,12 @@ private:
     void InitBatch3DUniformBlock();
     void UpdateBatch3DUniformBlock();
     void RenderBatchBars(bool bNewScene);
+    void CheckGLSLVersion();
 private:
 
     struct ShaderResources
     {
+        bool m_b330Support;
         // 3DProID
         GLint m_3DProID;
         GLint m_3DProjectionID;
@@ -242,6 +244,18 @@ private:
         GLint m_3DNormalMatrixID;
         GLint m_3DVertexID;
         GLint m_3DNormalID;
+        //300 verson;
+        GLint m_3DMaterialAmbientID;
+        GLint m_3DMaterialDiffuseID;
+        GLint m_3DMaterialSpecularID;
+        GLint m_3DMaterialColorID;
+        GLint m_3DMaterialTwoSidesID;
+        GLint m_3DMaterialShininessID;
+        GLint m_3DLightColorID;
+        GLint m_3DLightPosID;
+        GLint m_3DLightPowerID;
+        GLint m_3DLightNumID;
+        GLint m_3DLightAmbientID;
 
         // TextProID
         GLint m_TextProID;
@@ -376,6 +390,12 @@ private:
     GLint m_Batch3DActualSizeLight;
 
     glm::mat4 m_GlobalScaleMatrix;
+    //for 3.0 version
+    int m_iLightNum;
+    glm::vec4 m_Ambient;
+    glm::vec4 m_LightColor[MAX_LIGHT_NUM];
+    glm::vec4 m_PositionWorldspace[MAX_LIGHT_NUM];
+    float m_fLightPower[MAX_LIGHT_NUM];
 };
 
 }
diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index 52199c5..3566fb3 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -134,7 +134,8 @@ OpenGL3DRenderer::~OpenGL3DRenderer()
 }
 
 OpenGL3DRenderer::ShaderResources::ShaderResources()
-    : m_3DProID(0)
+    : m_b330Support(false)
+    , m_3DProID(0)
     , m_3DProjectionID(0)
     , m_3DViewID(0)
     , m_3DModelID(0)
@@ -174,16 +175,82 @@ OpenGL3DRenderer::ShaderResources::~ShaderResources()
     glDeleteProgram(m_3DBatchProID);
 }
 
+void OpenGL3DRenderer::CheckGLSLVersion()
+{
+    char version[256] = {0};
+    strcpy(version, (char *)glGetString(GL_SHADING_LANGUAGE_VERSION));
+    char *p = version;
+    int iVersion = 0;
+    //get the first point
+    while ((*p != '\0') && (*p != '.'))
+    {
+        iVersion = iVersion * 10 + ((*p) - 0x30);
+        p++;
+    }
+    if (iVersion < 3)
+    {
+        maResources.m_b330Support = false;
+        return;
+    }
+    if (iVersion > 3)
+    {
+        maResources.m_b330Support = true;
+        return;
+    }
+    p++;
+    iVersion = *p - 0x30;
+    if (iVersion >= 3)
+    {
+        maResources.m_b330Support = true;
+        return;
+    }
+    maResources.m_b330Support = false;
+}
+
 void OpenGL3DRenderer::ShaderResources::LoadShaders()
 {
-    m_3DProID = OpenGLHelper::LoadShaders("shape3DVertexShader", "shape3DFragmentShader");
-    m_3DProjectionID = glGetUniformLocation(m_3DProID, "P");
-    m_3DViewID = glGetUniformLocation(m_3DProID, "V");
-    m_3DModelID = glGetUniformLocation(m_3DProID, "M");
-    m_3DNormalMatrixID = glGetUniformLocation(m_3DProID, "normalMatrix");
-    m_3DVertexID = glGetAttribLocation(m_3DProID, "vertexPositionModelspace");
-    m_3DNormalID = glGetAttribLocation(m_3DProID, "vertexNormalModelspace");
 
+    if (m_b330Support)
+    {
+        m_3DProID = OpenGLHelper::LoadShaders("shape3DVertexShader", "shape3DFragmentShader");
+        m_3DProjectionID = glGetUniformLocation(m_3DProID, "P");
+        m_3DViewID = glGetUniformLocation(m_3DProID, "V");
+        m_3DModelID = glGetUniformLocation(m_3DProID, "M");
+        m_3DNormalMatrixID = glGetUniformLocation(m_3DProID, "normalMatrix");
+        m_3DVertexID = glGetAttribLocation(m_3DProID, "vertexPositionModelspace");
+        m_3DNormalID = glGetAttribLocation(m_3DProID, "vertexNormalModelspace");
+
+        m_3DBatchProID = OpenGLHelper::LoadShaders("shape3DVertexShaderBatch", "shape3DFragmentShaderBatch");
+        m_3DBatchProjectionID = glGetUniformLocation(m_3DBatchProID, "P");
+        m_3DBatchViewID = glGetUniformLocation(m_3DBatchProID, "V");
+        m_3DBatchModelID = glGetAttribLocation(m_3DBatchProID, "M");
+        m_3DBatchNormalMatrixID = glGetAttribLocation(m_3DBatchProID, "normalMatrix");
+        m_3DBatchVertexID = glGetAttribLocation(m_3DBatchProID, "vertexPositionModelspace");
+        m_3DBatchNormalID = glGetAttribLocation(m_3DBatchProID, "vertexNormalModelspace");
+        m_3DBatchColorID = glGetAttribLocation(m_3DBatchProID, "barColor");
+    }
+    else
+    {
+        //use 300
+        m_3DProID = OpenGLHelper::LoadShaders("shape3DVertexShaderV300", "shape3DFragmentShaderV300");
+        m_3DProjectionID = glGetUniformLocation(m_3DProID, "P");
+        m_3DViewID = glGetUniformLocation(m_3DProID, "V");
+        m_3DModelID = glGetUniformLocation(m_3DProID, "M");
+        m_3DNormalMatrixID = glGetUniformLocation(m_3DProID, "normalMatrix");
+        m_3DMaterialAmbientID = glGetUniformLocation(m_3DProID, "materialAmbient");
+        m_3DMaterialDiffuseID = glGetUniformLocation(m_3DProID, "materialDiffuse");
+        m_3DMaterialSpecularID = glGetUniformLocation(m_3DProID, "materialSpecular");
+        m_3DMaterialColorID = glGetUniformLocation(m_3DProID, "materialColor");
+        m_3DMaterialTwoSidesID = glGetUniformLocation(m_3DProID, "twoSidesLighting");
+        m_3DMaterialShininessID = glGetUniformLocation(m_3DProID, "materialShininess");
+        m_3DLightColorID = glGetUniformLocation(m_3DProID, "lightColor");
+        m_3DLightPosID = glGetUniformLocation(m_3DProID, "lightPosWorldspace");
+        m_3DLightPowerID = glGetUniformLocation(m_3DProID, "lightPower");
+        m_3DLightNumID = glGetUniformLocation(m_3DProID, "lightNum");
+        m_3DLightAmbientID = glGetUniformLocation(m_3DProID, "lightAmbient");
+        m_3DVertexID = glGetAttribLocation(m_3DProID, "vertexPositionModelspace");
+        m_3DNormalID = glGetAttribLocation(m_3DProID, "vertexNormalModelspace");
+    }
     m_TextProID = OpenGLHelper::LoadShaders("textVertexShader", "textFragmentShader");
     m_TextMatrixID = glGetUniformLocation(m_TextProID, "MVP");
     m_TextVertexID = glGetAttribLocation(m_TextProID, "vPosition");
@@ -200,14 +267,6 @@ void OpenGL3DRenderer::ShaderResources::LoadShaders()
     m_2DVertexID = glGetAttribLocation(m_CommonProID, "vPosition");
     m_2DColorID = glGetUniformLocation(m_CommonProID, "vColor");
 
-    m_3DBatchProID = OpenGLHelper::LoadShaders("shape3DVertexShaderBatch", "shape3DFragmentShaderBatch");
-    m_3DBatchProjectionID = glGetUniformLocation(m_3DBatchProID, "P");
-    m_3DBatchViewID = glGetUniformLocation(m_3DBatchProID, "V");
-    m_3DBatchModelID = glGetAttribLocation(m_3DBatchProID, "M");
-    m_3DBatchNormalMatrixID = glGetAttribLocation(m_3DBatchProID, "normalMatrix");
-    m_3DBatchVertexID = glGetAttribLocation(m_3DBatchProID, "vertexPositionModelspace");
-    m_3DBatchNormalID = glGetAttribLocation(m_3DBatchProID, "vertexNormalModelspace");
-    m_3DBatchColorID = glGetAttribLocation(m_3DBatchProID, "barColor");
     CHECK_GL_ERROR();
 }
 
@@ -281,6 +340,7 @@ void OpenGL3DRenderer::init()
     m_fViewAngle = 30.0f;
     m_3DProjection = glm::perspective(m_fViewAngle, (float)m_iWidth / (float)m_iHeight, 0.01f, 6000.0f);
 
+    CheckGLSLVersion();
     maResources.LoadShaders();
     maPickingResources.LoadShaders();
 
@@ -303,9 +363,12 @@ void OpenGL3DRenderer::init()
 
     m_Extrude3DInfo.rounded = false;
     CHECK_GL_ERROR();
-    Init3DUniformBlock();
-    InitBatch3DUniformBlock();
-
+    if (maResources.m_b330Support)
+    {
+        Init3DUniformBlock();
+        InitBatch3DUniformBlock();
+    }
+    CHECK_GL_ERROR();
     glViewport(0, 0, m_iWidth, m_iHeight);
     Set3DSenceInfo(0xFFFFFF, true);
     m_GlobalScaleMatrix = glm::scale(0.01f, 0.01f, 0.01f);
commit 33a40a317ade7dd3fc1b2d3dd6662820e104e67c
Author: weigao <weigao at multicorewareinc.com>
Date:   Sat Jun 14 08:00:02 2014 -0700

    add shaders for 3.0 glsl version
    
    Change-Id: I52dd49132a9b625e8be51b4d5feb7e567ffa0a6e

diff --git a/chart2/Package_opengl.mk b/chart2/Package_opengl.mk
index d8f9fa7..3d68a93 100644
--- a/chart2/Package_opengl.mk
+++ b/chart2/Package_opengl.mk
@@ -30,6 +30,8 @@ $(eval $(call gb_Package_add_files,chart2_opengl_shader,$(LIBO_BIN_FOLDER)/openg
 	renderTextureFragmentShader.glsl \
 	shape3DFragmentShaderBatch.glsl \
 	shape3DVertexShaderBatch.glsl \
+	shape3DFragmentShaderV300.glsl \
+	shape3DVertexShaderV300.glsl \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/chart2/opengl/shape3DFragmentShaderV300.glsl b/chart2/opengl/shape3DFragmentShaderV300.glsl
new file mode 100644
index 0000000..31a32e0
--- /dev/null
+++ b/chart2/opengl/shape3DFragmentShaderV300.glsl
@@ -0,0 +1,87 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+#define MAX_LIGHT_NUM 8
+
+varying vec3 positionWorldspace;
+varying vec3 normalCameraspace;
+
+uniform mat4 V;
+uniform vec4 materialAmbient;
+uniform vec4 materialDiffuse;
+uniform vec4 materialSpecular;
+uniform vec4 materialColor;
+uniform int twoSidesLighting;
+uniform float materialShininess;
+uniform vec4 lightColor[MAX_LIGHT_NUM];
+uniform vec4 lightPosWorldspace[MAX_LIGHT_NUM];
+uniform float lightPower[MAX_LIGHT_NUM];
+uniform int lightNum;
+uniform vec4 lightAmbient;
+
+void main()
+{
+    vec3 colorTotal = vec3(0.0f, 0.0f, 0.0f);
+
+    vec3 vertexPositionCameraspace = (V * vec4(positionWorldspace,1)).xyz;
+
+    vec3 MaterialDiffuseColor = materialColor.rgb;
+
+    vec3 normalDirectionCameraspace = normalCameraspace;
+    vec3 eyeDirectionCameraspace = normalize(vec3(0, 0, 0) - vertexPositionCameraspace);
+    float attenuation = 1.0;
+    int i = 0;
+    vec3 lightDirectionCameraspace;
+    vec3 vertexToLightSource;
+
+    vec3 totalAmbient = lightAmbient.rgb *
+                        MaterialDiffuseColor *
+                        materialAmbient.rgb
+                        * 5.0;
+
+    if ((twoSidesLighting == 1) && (!gl_FrontFacing))
+    {
+        normalDirectionCameraspace = -normalDirectionCameraspace;
+    }
+    for (i = 0; i < lightNum; i++)
+    {
+        float  LightPower = lightPower[i];
+        lightDirectionCameraspace = normalize((V * lightPosWorldspace[i]).xyz);
+
+        float cosTheta = clamp(dot(normalDirectionCameraspace,lightDirectionCameraspace), 0,1);
+        vec3 lightDiffuse = LightPower *
+                            attenuation *
+                            lightColor[i].rgb *
+                            MaterialDiffuseColor *
+                            materialDiffuse.rgb *
+                            cosTheta;
+
+        vec3 specularReflection;
+        if (dot(normalDirectionCameraspace, lightDirectionCameraspace) < 0)
+        {
+            specularReflection = vec3(0.0, 0.0, 0.0);
+        }
+        else
+        {
+            vec3 R = reflect(-lightDirectionCameraspace,normalDirectionCameraspace);
+            float cosAlpha = clamp(dot(eyeDirectionCameraspace, R), 0,1);
+            specularReflection = attenuation *
+                                 LightPower *
+                                 lightColor[i].rgb *
+                                 materialSpecular.rgb *
+                                 MaterialDiffuseColor *
+                                 pow(max(0.0, cosAlpha), materialShininess);
+        }
+        colorTotal += lightDiffuse + specularReflection;
+
+    }
+    colorTotal += totalAmbient;
+    gl_FragColor = vec4(colorTotal, 1.0);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/opengl/shape3DVertexShaderV300.glsl b/chart2/opengl/shape3DVertexShaderV300.glsl
new file mode 100644
index 0000000..6737004
--- /dev/null
+++ b/chart2/opengl/shape3DVertexShaderV300.glsl
@@ -0,0 +1,29 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+attribute vec3 vertexPositionModelspace;
+attribute vec3 vertexNormalModelspace;
+
+varying vec3 positionWorldspace;
+varying vec3 normalCameraspace;
+
+uniform mat4 P;
+uniform mat4 M;
+uniform mat4 V;
+uniform mat3 normalMatrix;
+
+void main()
+{
+    gl_Position =  P * V * M * vec4(vertexPositionModelspace,1);
+
+    positionWorldspace = (M * vec4(vertexPositionModelspace,1)).xyz;
+
+    normalCameraspace = normalize(mat3(V) * normalMatrix * vertexNormalModelspace);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list