Apply camera position
authorHeeyong Song <heeyong.song@samsung.com>
Wed, 27 Nov 2013 05:53:21 +0000 (14:53 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Wed, 27 Nov 2013 05:53:21 +0000 (14:53 +0900)
Change-Id: I373b1b7168b1193b85c9b562cb155234f728d3b4

src/ui/animations/FUiAnim_GlRenderManager.cpp
src/ui/animations/FUiAnim_GlRenderManager.h
src/ui/animations/platform/FUiAnim_GlContext.cpp

index 858f058..12e0b6c 100644 (file)
@@ -512,6 +512,10 @@ _GlRenderManager::_GlRenderManager(void)
                SysAssertf(false, "Creating render-thread failed");
        }
 
+       __eyePosition[0] = 0.0f;
+       __eyePosition[1] = 0.0f;
+       __eyePosition[2] = 0.0f;
+
        ClearLastResult();
 
        __pRenderQueue = new (std::nothrow) _RenderObject[VE_RENDER_QUEUE_COUNT_MAX];
@@ -794,28 +798,13 @@ _GlRenderManager::FlushRenderQueue(void)
                        }
 
                        glUniform1i(pProgramImpl->__uniformLocation[UNIFORM_INT_ACTIVE_LIGHT_COUNT], __pRenderQueue[i].__activeLightCount);
-                       // TODO glUniform3fv(pProgramImpl->__uniformLocation[UNIFORM_VEC3_EYE_POSITION], 1, CameraPos );
+                       glUniform3fv(pProgramImpl->__uniformLocation[UNIFORM_VEC3_EYE_POSITION], 1, __eyePosition);
                }
                else
                {
                        glUniform1i(pProgramImpl->__uniformLocation[UNIFORM_INT_ACTIVE_LIGHT_COUNT], 0);
                }
-/*
-               if (__pRenderQueue[i].__pLight)
-               {
-                       _LightImpl* pLightImpl = _LightImpl::GetInstance(*__pRenderQueue[i].__pLight);
-
-                       glUniform1i(pProgramImpl->__uniformLocation[UNIFORM_INT_LIGHT_TYPE], pLightImpl->GetType());
-                       glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_LIGHT_AMBIENT], 1, pLightImpl->GetAmbient());
-                       glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_LIGHT_DIFFUSE], 1, pLightImpl->GetDiffuse());
-                       glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_LIGHT_SPECULAR], 1, pLightImpl->GetSpecular());
-                       glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_LIGHT_POSITION], 1, pLightImpl->GetWorldPosition());
-                       glUniform3fv(pProgramImpl->__uniformLocation[UNIFORM_VEC3_LIGHT_DIRECTION], 1, pLightImpl->GetDirection());
-                       glUniform1f(pProgramImpl->__uniformLocation[UNIFORM_FLOAT_LIGHT_EXPONENT], pLightImpl->GetExponent());
-                       glUniform1f(pProgramImpl->__uniformLocation[UNIFORM_FLOAT_LIGHT_CUTOFF], pLightImpl->GetCutOff());
-                       glUniform3fv(pProgramImpl->__uniformLocation[UNIFORM_VEC3_LIGHT_ATTENUATION], 1, pLightImpl->GetAttenuations());
-               }
-*/
+
                if (__pRenderQueue[i].__pMaterial)
                {
                        _MaterialImpl* pMaterialImpl = _MaterialImpl::GetInstance(*__pRenderQueue[i].__pMaterial);
@@ -1116,11 +1105,10 @@ _GlRenderManager::CompositeNode(VisualElement* pRenderObject, Tizen::Base::Colle
 void
 _GlRenderManager::CompositeView(_GlLayer* pLayer, _RootVisualElement* pRoot, _View* pView)
 {
-
 #ifdef VE_USE_GL_MULTI_CONTEXT
-               __pGlContext = (_GlContext*)pLayer->GetContext();
-               __pGlContext->MakeCurrent();
-               __needClear = true;
+       __pGlContext = (_GlContext*)pLayer->GetContext();
+       __pGlContext->MakeCurrent();
+       __needClear = true;
 #else
        VisualElementSurface* pSurface = pView->GetRenderTarget();
        if(pSurface)
@@ -1131,29 +1119,41 @@ _GlRenderManager::CompositeView(_GlLayer* pLayer, _RootVisualElement* pRoot, _Vi
        }
 #endif
 
-
        Tizen::Graphics::FloatRectangle* pViewport = pView->GetViewport();
        if(pViewport)
        {
                glViewport(pViewport->x, pViewport->y, pViewport->width, pViewport->height);
        }
-       __needClear = true;
+
        Camera* pCamera = pView->GetCamera();
-       if(pCamera)
+       if (pCamera)
        {
                _CameraImpl* pCameraImpl = _CameraImpl::GetInstance(*pCamera);
+               FloatPoint3 eyePosition = pCameraImpl->GetEye();
+
                __view = pCameraImpl->GetMatrix();
+
+               __eyePosition[0] = eyePosition.x;
+               __eyePosition[1] = eyePosition.y;
+               __eyePosition[2] = eyePosition.z;
+       }
+       else
+       {
+               __eyePosition[0] = 0.0f;
+               __eyePosition[1] = 0.0f;
+               __eyePosition[2] = 0.0f;
        }
+
        FloatMatrix4* pProjection = pView->GetProjection();
-       if(pProjection)
+       if (pProjection)
        {
                __viewProjection.CopyFrom(*pProjection);
        }
+
        __viewProjection.MultiplyMatrix(__view);
        __viewProjection.Translate(0.0f, pViewport->height, 0.0f);
        __viewProjection.Scale(1.0f, -1.0f, 1.0f);
 
-
        __globalLightCount = 0;
 
        VisualElement* pRootRender = _VisualElementImpl::GetInstance(*pRoot)->GetRenderObject()->GetPublic();
index 5fb6777..105f79e 100644 (file)
@@ -223,6 +223,7 @@ private:
        _GlContext* __pGlContext;
        _Matrix4f __view;
        _Matrix4f __viewProjection;
+       float __eyePosition[3];
 
        _RenderObject* __pRenderQueue;
        int __queueCount;
index babd55d..2b6f411 100644 (file)
@@ -806,6 +806,7 @@ _GlContext::PrepareDefaultShaders(void)
                        "uniform mat4 u_modelview;\n"
                        "//uniform mat3 u_inv_modelview;\n"
                        "uniform mat4 u_inv_modelview;\n"
+                       "uniform vec3 u_eyePosition;\n"
                        "\n"
                        "uniform material u_material;\n"
                        "uniform light u_light[8];\n"
@@ -822,7 +823,7 @@ _GlContext::PrepareDefaultShaders(void)
                        "vec4\n"
                        "do_lighting(int i)\n"
                        "{\n"
-                       "       vec3 lightdir, n, h;\n"
+                       "       vec3 lightdir, n, h, eye;\n"
                        "       vec4 color = vec4(c_zero, c_zero, c_zero, c_zero);\n"
                        "       float ndotl, ndoth, attenuation;\n"
                        "\n"
@@ -872,7 +873,8 @@ _GlContext::PrepareDefaultShaders(void)
                        "               ndotl = max(c_zero, dot(n, lightdir));\n"
                        "               color += ndotl * u_light[i].diffuse * u_material.diffuse;\n"
                        "\n"
-                       "               h = normalize(lightdir + vec3(c_zero, c_zero, c_one));\n"
+                       "               eye = normalize(u_eyePosition - (u_modelview * a_position).xyz);\n"
+                       "               h = normalize(lightdir + eye);\n"
                        "               ndoth = dot(n, h);\n"
                        "\n"
                        "               if (ndoth > c_zero)\n"
@@ -949,8 +951,6 @@ _GlContext::PrepareDefaultShaders(void)
                        "varying vec2 v_texcoord;\n"
                        "varying vec3 v_normal;\n"
                        "\n"
-                       "const vec3 eyePosition = vec3(0, 0, -500); //TODO eyePosition is temporary while camera is implementing\n"
-                       "\n"
                        "vec4 pointLight(int i)\n"
                        "{\n"
                        "       vec4 result = vec4(0.0, 0.0, 0.0, 0.0);\n"
@@ -959,7 +959,7 @@ _GlContext::PrepareDefaultShaders(void)
                        "       vec4 specular = vec4(0.0, 0.0, 0.0, 0.0);\n"
                        "       vec3 normal = normalize(v_normal);\n"
                        "       vec3 lightdir;\n"
-                       "       vec3 v = normalize(eyePosition - v_position.xyz);\n"
+                       "       vec3 v = normalize(u_eyePosition - v_position.xyz);\n"
                        "       vec3 r = reflect(-v, normal);\n"
                        "\n"
                        "       float att = 0.0;\n"
@@ -995,7 +995,7 @@ _GlContext::PrepareDefaultShaders(void)
                        "       vec3 normal = normalize(v_normal);\n"
                        "       vec3 lightdir;\n"
                        "\n"
-                       "       vec3 v = normalize(eyePosition - v_position.xyz);\n"
+                       "       vec3 v = normalize(u_eyePosition - v_position.xyz);\n"
                        "       vec3 r = reflect(-v, normal);\n"
                        "       vec3 d =  normalize(u_light[i].direction.xyz);\n"
                        "\n"
@@ -1040,12 +1040,12 @@ _GlContext::PrepareDefaultShaders(void)
                        "       \n"
                        "       vec3 normal = normalize(v_normal);\n"
                        "       vec3 lightdir = normalize(u_light[i].position.xyz);\n"
-                       "       vec3 v = normalize(eyePosition - v_position.xyz);\n"
+                       "       vec3 v = normalize(u_eyePosition - v_position.xyz);\n"
                        "       vec3 r = reflect(-v, normal);\n"
                        "       \n"
                        "       diffuse =  u_light[i].diffuse * u_material.diffuse * texture2D(u_tex2d, v_texcoord).bgra * max(0.0, dot(lightdir, normal));\n"
                        "       ambient = u_light[i].ambient * u_material.ambient;\n"
-                       "       specular =  u_light[i].specular * u_material.specular * pow(max(dot(r, lightdir), 0.0), u_material.shininess );\n"
+                       "       specular =  u_light[i].specular * u_material.specular * pow(max(dot(r, lightdir), 0.0), u_material.shininess);\n"
                        "       \n"
                        "       result = ambient + diffuse  + specular;\n"
                        "       \n"