, __pLight(null)
, __pMaterial(null)
, __pShaderProgram(null)
+ , __activeLight()
{
-
+ __activeLight.Construct();
}
_GlNode::~_GlNode(void)
{
Destruct();
+ __activeLight.RemoveAll();
}
result
#include <FGrpFloatMatrix4.h>
#include <FUiAnimVisualElement.h>
#include <FUiAnimShaderProgram.h>
+#include <FBaseColArrayList.h>
#include "FUi_Colorf.h"
#include "FUi_Rectanglef.h"
unsigned int __textureId;
_NativeLayer* __pLayer;
-
+ Tizen::Base::Collection::ArrayList __activeLight;
Mesh* __pMesh;
Light* __pLight;
Material* __pMaterial;
#define VE_RENDER_OBJECT_VERTEX_COUNT_MAX 120
#define VE_RENDER_QUEUE_COUNT_MAX 100
+#define OFFSET (UNIFORM_VEC3_LIGHT_ATTENUATION - UNIFORM_INT_LIGHT_TYPE + 1)
namespace Tizen { namespace Ui { namespace Animations
{
__invModelview.Invert();
__invModelview.Transpose(); // TODO: optimize
+ __activeLightCount = 0;
+
+ Object* pObj = null;
+ for (int i = 0; i< pNode->__activeLight.GetCount(); i++)
+ {
+ pObj = pNode->__activeLight.GetAt(i);
+ if (__activeLightCount < MAX_LIGHT_COUNT)
+ {
+ __activeLight[__activeLightCount] = (Light*)pObj;
+ __activeLightCount++;
+ }
+ }
+#if 0
+ for (int i = 0; i < __globalLightCount; i++)
+ {
+ __activeLight[__activeLightCount] = __globalLight[i];
+ __activeLightCount++;
+ }
+#endif
if (likely(!pNode->__pMesh))
{
__isMesh = false;
}
// TODO: check
- if (pNode->__pLight && pNode->__pLight->IsEnabled())
+ //if (pNode->__pLight && pNode->__pLight->IsEnabled())
+ if (__activeLightCount > 0)
{
- __pLight = pNode->__pLight;
+ //__pLight = pNode->__pLight;
__pProgram = _GlRenderManager::GetInstance()->__pGlContext->__pLightShader;
}
__pLight = null;
__pMaterial = null;
-
+ __activeLightCount = 0;
return;
}
, __viewProjection()
, __pRenderQueue(null)
, __queueCount(0)
+ , __globalLightCount(0)
, __needClear(false)
, __pAnimationManager(0)
{
glUniformMatrix4fv(pProgramImpl->__uniformLocation[UNIFORM_MAT4_MODEL_VIEW], 1, GL_FALSE, __pRenderQueue[i].__modelview.GetItems());
glUniformMatrix4fv(pProgramImpl->__uniformLocation[UNIFORM_MAT4_INV_MODEL_VIEW], 1, GL_FALSE, __pRenderQueue[i].__invModelview.GetItems());
+ if (__pRenderQueue[i].__activeLightCount > 0)
+ {
+ static int offset = 0;
+ static _LightImpl* pLightImpl = null;
+ for (register int k = 0; k <__pRenderQueue[i]. __activeLightCount; k++)
+ {
+ offset = OFFSET * k;
+ pLightImpl = _LightImpl::GetInstance(*__pRenderQueue[i].__activeLight[k]);
+ glUniform1i(pProgramImpl->__uniformLocation[UNIFORM_INT_LIGHT_TYPE + offset], pLightImpl->GetType());
+ glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_LIGHT_AMBIENT + offset], 1, pLightImpl->GetAmbient());
+ glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_LIGHT_DIFFUSE + offset], 1, pLightImpl->GetDiffuse());
+ glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_LIGHT_SPECULAR + offset], 1, pLightImpl->GetSpecular());
+ glUniform4fv(pProgramImpl->__uniformLocation[UNIFORM_VEC4_LIGHT_POSITION + offset], 1, pLightImpl->GetPosition());
+ glUniform3fv(pProgramImpl->__uniformLocation[UNIFORM_VEC3_LIGHT_DIRECTION + offset], 1, pLightImpl->GetDirection());
+ glUniform1f(pProgramImpl->__uniformLocation[UNIFORM_FLOAT_LIGHT_EXPONENT + offset], pLightImpl->GetExponent());
+ glUniform1f(pProgramImpl->__uniformLocation[UNIFORM_FLOAT_LIGHT_CUTOFF + offset], pLightImpl->GetCutOff());
+ glUniform3fv(pProgramImpl->__uniformLocation[UNIFORM_VEC3_LIGHT_ATTENUATION + offset], 1, pLightImpl->GetAttenuations());
+ }
+ glUniform1i(pProgramImpl->__uniformLocation[UNIFORM_INT_ACTIVE_LIGHT_COUNT], __pRenderQueue[i].__activeLightCount);
+ // TODO glUniform3fv(pProgramImpl->__uniformLocation[UNIFORM_VEC3_EYE_POSITION], 1, CameraPos );
+ }
+ else
+ {
+ glUniform1i(pProgramImpl->__uniformLocation[UNIFORM_INT_ACTIVE_LIGHT_COUNT], 0);
+ }
+/*
if (__pRenderQueue[i].__pLight)
{
_LightImpl* pLightImpl = _LightImpl::GetInstance(*__pRenderQueue[i].__pLight);
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);
}
void
-_GlRenderManager::CompositeNode(VisualElement* pRenderObject, bool useStencil, unsigned int depth)
+_GlRenderManager::CompositeNode(VisualElement* pRenderObject, Tizen::Base::Collection::ArrayList &parentLight, bool useStencil, unsigned int depth)
{
bool updateStencil = false;
unsigned int stencilIndex = depth;
continue;
pNode->SyncStatus(pChildImpl->GetSharedData().pSurface, *pChildImpl);
+ _LightImpl* pLightImpl = null;
+ if (pNode->__pLight)
+ {
+ pLightImpl = _LightImpl::GetInstance(*pNode->__pLight);
+ if (pLightImpl->IsEnabled())
+ {
+ pNode->__activeLight.Add(pNode->__pLight);
+ }
+#if 0
+ if (__globalLightCount < MAX_LIGHT_COUNT)
+ {
+ __globalLight[__globalLightCount] = pNode->__pLight;
+ __globalLightCount++;
+ }
+#endif
+ }
+
+ for (register int i = 0; i<parentLight.GetCount(); i++ )
+ {
+ Object* pValue = null;
+ pValue = parentLight.GetAt(i);
+ _LightImpl* pLightImplParent = null;
+ pLightImplParent = _LightImpl::GetInstance(*(Light*)pValue);
+
+ if (pLightImpl != pLightImplParent)
+ {
+ pNode->__activeLight.Add(pValue);
+ }
+ }
+
+#ifndef BUILD_UI_CORE
if (!pNode->__isVisible || _FloatCompare(pNode->__opacity, 0.0f))
{
continue;
}
+#endif
// Mesh test
if (pNode->__pMesh)
{
EnqueueRenderObject(pNode, useStencil, stencilIndex, true);
- CompositeNode(pChild, useStencil, depth);
+ CompositeNode(pChild, pNode->__activeLight, useStencil, depth);
continue;
}
{
if (!pNode->__isClipChildren)
{
- CompositeNode(pChild, useStencil, depth);
+ CompositeNode(pChild, pNode->__activeLight, useStencil, depth);
}
continue;
}
{
if (_FloatCompare(pNode->__objectColor.Alpha(), 0.0f))
{
- CompositeNode(pChild, useStencil, depth);
+ CompositeNode(pChild, pNode->__activeLight, useStencil, depth);
continue;
}
}
if (updateStencil)
{
- CompositeNode(pChild, useStencil, depth + 1);
+ CompositeNode(pChild, pNode->__activeLight, useStencil, depth + 1);
EnqueueRenderObject(pNode, true, stencilIndex + 1, false);
}
else
{
- CompositeNode(pChild, useStencil, depth);
+ CompositeNode(pChild, pNode->__activeLight, useStencil, depth);
}
}
+ //clear light arrayList
+ _VisualElementImpl* pRenderObjectImpl = _VisualElementImpl::GetInstance(*pRenderObject);
+ _GlNode* pRenderObjectNode = dynamic_cast< _GlNode* >(pRenderObjectImpl->GetNativeNode());
+ pRenderObjectNode->__activeLight.RemoveAll();
+
delete pChildren;
}
__viewProjection.Translate(0.0f, bounds.height, 0.0f);
__viewProjection.Scale(1.0f, -1.0f, 1.0f);
- CompositeNode(pVeRoot, false, 0);
-
+ Tizen::Base::Collection::ArrayList clearColorArray;
+ __globalLightCount = 0;
+ clearColorArray.Construct();
+ CompositeNode(pVeRoot, clearColorArray, false, 0);
+ clearColorArray.RemoveAll();
FlushRenderQueue();
__pGlContext->SwapBuffers();
#include "FUiAnim_GlLayer.h"
#include "FUiAnim_Mutex.h"
#include "FUiAnim_Waiter.h"
-
+#include <FBaseColArrayList.h>
#include "FUi_Colorf.h"
#include "FUi_Matrix4f.h"
#include "FUi_Rectanglef.h"
+#define MAX_LIGHT_COUNT 8
+
namespace Tizen { namespace Ui { namespace Animations
{
void CommandHandlerDeleteShaderProgram(_ShaderProgramImpl* pShaderProgram);
void CompositeLayer(_GlLayer* pLayer);
- void CompositeNode(VisualElement* pRenderObject, bool useStencil, unsigned int depth);
+ void CompositeNode(VisualElement* pRenderObject, Tizen::Base::Collection::ArrayList &parentLight, bool useStencil, unsigned int depth);
bool Animate(void);
Light* __pLight;
Material* __pMaterial;
-
+ unsigned int __activeLightCount;
+ Light* __activeLight[MAX_LIGHT_COUNT];
float* __pVertexBuffer;
float* __pTexCoordBuffer;
_RenderObject* __pRenderQueue;
int __queueCount;
bool __needClear;
-
+ unsigned int __globalLightCount;
+ Light* __globalLight[MAX_LIGHT_COUNT];
_AnimationManager* __pAnimationManager;
friend class _RenderObject;
const wchar_t* VeUniformMV = L"u_modelview";
const wchar_t* VeUniformInvMV = L"u_inv_modelview";
-const wchar_t* VeUniformLightType = L"u_light.type";
-const wchar_t* VeUniformLightAmbient = L"u_light.ambient";
-const wchar_t* VeUniformLightDiffuse = L"u_light.diffuse";
-const wchar_t* VeUniformLightSpecular = L"u_light.specular";
-const wchar_t* VeUniformLightPosition = L"u_light.position";
-const wchar_t* VeUniformLightDirection = L"u_light.direction";
-const wchar_t* VeUniformLightExponent = L"u_light.exponent";
-const wchar_t* VeUniformLightCutoff = L"u_light.cutoff";
-const wchar_t* VeUniformLightAttenuation = L"u_light.attenuation";
+
+const wchar_t* VeUniformLightType = L"u_light[%d].type";
+const wchar_t* VeUniformLightAmbient = L"u_light[%d].ambient";
+const wchar_t* VeUniformLightDiffuse = L"u_light[%d].diffuse";
+const wchar_t* VeUniformLightSpecular = L"u_light[%d].specular";
+const wchar_t* VeUniformLightPosition = L"u_light[%d].position";
+const wchar_t* VeUniformLightDirection = L"u_light[%d].direction";
+const wchar_t* VeUniformLightExponent = L"u_light[%d].exponent";
+const wchar_t* VeUniformLightCutoff = L"u_light[%d].cutoff";
+const wchar_t* VeUniformLightAttenuation = L"u_light[%d].attenuation";
const wchar_t* VeUniformMaterialAmbient = L"u_material.ambient";
const wchar_t* VeUniformMaterialDiffuse = L"u_material.diffuse";
const wchar_t* VeUniformMaterialEmissive = L"u_material.emissive";
const wchar_t* VeUniformMaterialShininess = L"u_material.shininess";
+const wchar_t* VeUniformActiveLightCount = L"u_lightCount";
+const wchar_t* VeUniformEyePosition = L"u_eyePosition";
+
_ShaderProgramImpl::_ShaderProgramImpl(void)
: __program(0)
, __vertexShader(0)
__attributeLocation[i] = -1;
}
- for (i = 0; i < UNIFORM_LOCATION_MAX; i++)
+ for (i = 0; i < UNIFORM_LOCATION_MAX + (UNIFORM_VEC3_LIGHT_ATTENUATION - UNIFORM_INT_LIGHT_TYPE + 1) * (MAX_LIGHT_COUNT - 1); i++)
{
__uniformLocation[i] = -1;
}
MoveUniformItem(UNIFORM_MAT4_MODEL_VIEW, VeUniformMV);
MoveUniformItem(UNIFORM_MAT4_INV_MODEL_VIEW, VeUniformInvMV);
- MoveUniformItem(UNIFORM_INT_LIGHT_TYPE, VeUniformLightType);
- MoveUniformItem(UNIFORM_VEC4_LIGHT_AMBIENT, VeUniformLightAmbient);
- MoveUniformItem(UNIFORM_VEC4_LIGHT_DIFFUSE, VeUniformLightDiffuse);
- MoveUniformItem(UNIFORM_VEC4_LIGHT_SPECULAR, VeUniformLightSpecular);
- MoveUniformItem(UNIFORM_VEC4_LIGHT_POSITION, VeUniformLightPosition);
- MoveUniformItem(UNIFORM_VEC3_LIGHT_DIRECTION, VeUniformLightDirection);
- MoveUniformItem(UNIFORM_FLOAT_LIGHT_EXPONENT, VeUniformLightExponent);
- MoveUniformItem(UNIFORM_FLOAT_LIGHT_CUTOFF, VeUniformLightCutoff);
- MoveUniformItem(UNIFORM_VEC3_LIGHT_ATTENUATION, VeUniformLightAttenuation);
+
+ Tizen::Base::String str;
+ for (int i = 0; i < MAX_LIGHT_COUNT; i++)
+ {
+ int offset = (UNIFORM_VEC3_LIGHT_ATTENUATION - UNIFORM_INT_LIGHT_TYPE + 1) * i;
+ str.Format(MAX_STRING_LENGHT, VeUniformLightType, i);
+ MoveUniformItem(UNIFORM_INT_LIGHT_TYPE + offset, str.GetPointer());
+
+ str.Format(MAX_STRING_LENGHT, VeUniformLightAmbient, i);
+ MoveUniformItem(UNIFORM_VEC4_LIGHT_AMBIENT + offset, str.GetPointer());
+
+ str.Format(MAX_STRING_LENGHT, VeUniformLightDiffuse, i);
+ MoveUniformItem(UNIFORM_VEC4_LIGHT_DIFFUSE + offset, str.GetPointer());
+
+ str.Format(MAX_STRING_LENGHT, VeUniformLightSpecular, i);
+ MoveUniformItem(UNIFORM_VEC4_LIGHT_SPECULAR + offset, str.GetPointer());
+
+ str.Format(MAX_STRING_LENGHT, VeUniformLightPosition, i);
+ MoveUniformItem(UNIFORM_VEC4_LIGHT_POSITION + offset, str.GetPointer());
+
+ str.Format(MAX_STRING_LENGHT, VeUniformLightDirection, i);
+ MoveUniformItem(UNIFORM_VEC3_LIGHT_DIRECTION + offset, str.GetPointer());
+
+ str.Format(MAX_STRING_LENGHT, VeUniformLightExponent, i);
+ MoveUniformItem(UNIFORM_FLOAT_LIGHT_EXPONENT + offset, str.GetPointer());
+
+ str.Format(MAX_STRING_LENGHT, VeUniformLightCutoff, i);
+ MoveUniformItem(UNIFORM_FLOAT_LIGHT_CUTOFF + offset, str.GetPointer());
+
+ str.Format(MAX_STRING_LENGHT, VeUniformLightAttenuation, i);
+ MoveUniformItem(UNIFORM_VEC3_LIGHT_ATTENUATION + offset, str.GetPointer());
+ }
MoveUniformItem(UNIFORM_VEC4_MATERIAL_AMBIENT, VeUniformMaterialAmbient);
MoveUniformItem(UNIFORM_VEC4_MATERIAL_DIFFUSE, VeUniformMaterialDiffuse);
MoveUniformItem(UNIFORM_VEC4_MATERIAL_SPECULAR, VeUniformMaterialSpecular);
MoveUniformItem(UNIFORM_VEC4_MATERIAL_EMISSIVE, VeUniformMaterialEmissive);
MoveUniformItem(UNIFORM_FLOAT_MATERIAL_SHININESS, VeUniformMaterialShininess);
+
+ MoveUniformItem(UNIFORM_INT_ACTIVE_LIGHT_COUNT, VeUniformActiveLightCount);
+ MoveUniformItem(UNIFORM_VEC3_EYE_POSITION, VeUniformEyePosition);
}
void
extern const wchar_t* VeUniformMaterialEmissive;
extern const wchar_t* VeUniformMaterialShininess;
+extern const wchar_t* VeUniformActiveLightCount;
+extern const wchar_t* VeUniformEyePosition;
+
EXTERN_DYNAMIC_PROPERTY(L"uniform.#id", ShaderPropUniform ,2) //Variant
+#define MAX_LIGHT_COUNT 8
+#define MAX_STRING_LENGHT 50
enum AttributeLocation
{
UNIFORM_MAT4_MODEL_VIEW, /**< Uniform for model view matrix */
UNIFORM_MAT4_INV_MODEL_VIEW, /**< Uniform for inverted model view */
+ UNIFORM_VEC4_MATERIAL_AMBIENT, /**< Uniform for material ambient */
+ UNIFORM_VEC4_MATERIAL_DIFFUSE, /**< Uniform for material diffuse */
+ UNIFORM_VEC4_MATERIAL_SPECULAR, /**< Uniform for material specular */
+ UNIFORM_VEC4_MATERIAL_EMISSIVE, /**< Uniform for material emissive */
+ UNIFORM_FLOAT_MATERIAL_SHININESS, /**< Uniform for material shininess */
+
+ UNIFORM_INT_ACTIVE_LIGHT_COUNT,
+ UNIFORM_VEC3_EYE_POSITION,
+
UNIFORM_INT_LIGHT_TYPE, /**< Uniform for light type */
UNIFORM_VEC4_LIGHT_AMBIENT, /**< Uniform for light ambient */
UNIFORM_VEC4_LIGHT_DIFFUSE, /**< Uniform for light diffuse */
UNIFORM_FLOAT_LIGHT_CUTOFF, /**< Uniform for light cutoff */
UNIFORM_VEC3_LIGHT_ATTENUATION, /**< Uniform for light attenuation */
- UNIFORM_VEC4_MATERIAL_AMBIENT, /**< Uniform for material ambient */
- UNIFORM_VEC4_MATERIAL_DIFFUSE, /**< Uniform for material diffuse */
- UNIFORM_VEC4_MATERIAL_SPECULAR, /**< Uniform for material specular */
- UNIFORM_VEC4_MATERIAL_EMISSIVE, /**< Uniform for material emissive */
- UNIFORM_FLOAT_MATERIAL_SHININESS, /**< Uniform for material shininess */
-
UNIFORM_LOCATION_MAX /**< Maximum of uniform location */
};
unsigned int __fragmentShader;
int __attributeLocation[ATTRIBUTE_LOCATION_MAX];
- int __uniformLocation[UNIFORM_LOCATION_MAX];
+ int __uniformLocation[UNIFORM_LOCATION_MAX + (UNIFORM_VEC3_LIGHT_ATTENUATION - UNIFORM_INT_LIGHT_TYPE + 1) * (MAX_LIGHT_COUNT - 1)];
Tizen::Base::Collection::HashMapT<Tizen::Base::String, UniformValue*> __customUniformMap;
" gl_FragColor.rgba = texture2D(u_tex2d, v_texcoord).bgra * v_color;\n"
"}\n";
+
+
+ static const char strFragmentShader_PerPixellight[] =
+ " \n"
+ " precision highp float;\n"
+ " struct light\n"
+ " {\n"
+ " int type;\n"
+ " vec4 ambient;\n"
+ " vec4 diffuse;\n"
+ " vec4 specular;\n"
+ " vec4 position;\n"
+ " vec3 direction;\n"
+ " float exponent;\n"
+ " float cutoff;\n"
+ " vec3 attenuation;\n"
+ " };\n"
+ " struct material\n"
+ " {\n"
+ " vec4 ambient;\n"
+ " vec4 diffuse;\n"
+ " vec4 specular;\n"
+ " vec4 emissive;\n"
+ " float shininess;\n"
+ " };\n"
+ " \n"
+ " uniform vec3 u_eyePosition;\n"
+ " uniform int u_lightCount;\n"
+ " uniform sampler2D u_tex2d;\n"
+ " uniform material u_material;\n"
+ " uniform light u_light[8];\n"
+ " \n"
+ " varying vec4 v_position;\n"
+ " 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"
+ " vec4 diffuse = vec4(0.0, 0.0, 0.0, 0.0);\n"
+ " vec4 ambient = vec4(0.0, 0.0, 0.0, 0.0);\n"
+ " 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 r = reflect(-v, normal);\n"
+ " \n"
+ " float att = 0.0;\n"
+ " \n"
+ " lightdir = u_light[i].position.xyz - v_position.xyz;\n"
+ " lightdir = normalize(lightdir);\n"
+ " \n"
+ " float denum = (u_light[i].attenuation.x + u_light[i].attenuation.y*u_light[i].attenuation.x + u_light[i].attenuation.z*u_light[i].attenuation.z );\n"
+ " \n"
+ " if (denum > 0.0)\n"
+ " att = 1.0 / denum;\n"
+ " \n"
+ " ambient = u_light[i].ambient * u_material.ambient;\n"
+ " diffuse += u_light[i].diffuse *u_material.diffuse *texture2D(u_tex2d, v_texcoord).bgra* max(0.0, dot(lightdir, normal));\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"
+ " if (att > 0.0)\n"
+ " result*=att;\n"
+ " \n"
+ " return result;\n"
+ " \n"
+ " }\n"
+ " \n"
+ " vec4 spotLight(int i)\n"
+ " {\n"
+ " vec4 result = vec4(0.0, 0.0, 0.0, 0.0);\n"
+ " vec4 diffuse = vec4(0.0, 0.0, 0.0, 0.0);\n"
+ " vec4 ambient = vec4(0.0, 0.0, 0.0, 0.0);\n"
+ " vec4 specular = vec4(0.0, 0.0, 0.0, 0.0);\n"
+ " \n"
+ " vec3 normal = normalize(v_normal);\n"
+ " vec3 lightdir;\n"
+ " \n"
+ " vec3 v = normalize(eyePosition - v_position.xyz);\n"
+ " vec3 r = reflect(-v, normal);\n"
+ " vec3 d = normalize(u_light[i].direction.xyz);\n"
+ " \n"
+ " float att = 0.0;\n"
+ " float spotEffect = 0.0;\n"
+ " \n"
+ " lightdir = u_light[i].position.xyz - v_position.xyz;\n"
+ " lightdir = normalize(lightdir);\n"
+ " \n"
+ " spotEffect = dot( -lightdir, d);\n"
+ " \n"
+ " float denum = (u_light[i].attenuation.x + u_light[i].attenuation.y*u_light[i].attenuation.x + u_light[i].attenuation.z*u_light[i].attenuation.z );\n"
+ " if (denum > 0.0)\n"
+ " att = 1.0 / denum;\n"
+ " \n"
+ " if (spotEffect >= cos(radians(u_light[i].cutoff)))\n"
+ " spotEffect = pow(spotEffect, u_light[i].exponent);\n"
+ " else\n"
+ " spotEffect = 0.0;\n"
+ " \n"
+ " att*= spotEffect;\n"
+ " \n"
+ " \n"
+ " if (att > 0.0)\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"
+ " }\n"
+ " \n"
+ " result = (ambient + diffuse + specular) * att;\n"
+ " \n"
+ " return result;\n"
+ " }\n"
+ " \n"
+ " vec4 directionalLight(int i)\n"
+ " {\n"
+ " vec4 result = vec4(0.0, 0.0, 0.0, 0.0);\n"
+ " vec4 diffuse = vec4(0.0, 0.0, 0.0, 0.0);\n"
+ " vec4 ambient = vec4(0.0, 0.0, 0.0, 0.0);\n"
+ " vec4 specular = vec4(0.0, 0.0, 0.0, 0.0);\n"
+ " \n"
+ " vec3 normal = normalize(v_normal);\n"
+ " vec3 lightdir;\n"
+ " vec3 v = normalize(eyePosition - v_position.xyz);\n"
+ " vec3 r = reflect(-v, normal);\n"
+ " lightdir = normalize(u_light[i].direction);\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"
+ " \n"
+ " result = ambient + diffuse + specular;\n"
+ " \n"
+ " return result;\n"
+ " }\n"
+ " \n"
+ " void main()\n"
+ " {\n"
+ " vec4 res_color = vec4(0,0,0,1);\n"
+ " if (u_lightCount > 0 )\n"
+ " {\n"
+ " for (int i = 0; i < u_lightCount; i++)\n"
+ " {\n"
+ " if (u_light[i].type == 0)\n"
+ " res_color += pointLight(i);\n"
+ " if (u_light[i].type == 1)\n"
+ " res_color += spotLight(i);\n"
+ " if (u_light[i].type == 2)\n"
+ " res_color += directionalLight(i);\n"
+ " }\n"
+ " res_color += u_material.emissive;\n"
+ " res_color.a = u_material.diffuse.a;\n"
+ " }\n"
+ " gl_FragColor.rgba = res_color;\n"
+ " }";
+ static const char strVertexShader_PerPixellight[] =
+ "\n"
+ "uniform mat4 u_mvp;\n"
+ "uniform mat4 u_modelview;\n"
+ "//uniform mat3 u_inv_modelview;\n"
+ "uniform mat4 u_inv_modelview;\n"
+ "\n"
+ "attribute vec4 a_position;\n"
+ "attribute vec2 a_texcoord;\n"
+ "attribute vec3 a_normal;\n"
+ "varying vec4 v_position;\n"
+ "varying vec2 v_texcoord;\n"
+ "varying vec3 v_normal;\n"
+ "\n"
+ "void\n"
+ "main()\n"
+ "{\n"
+ " v_position = u_modelview * a_position;\n"
+ " vec4 normal = u_inv_modelview * vec4(a_normal, 0.0);\n"
+ " v_normal = normal.xyz;\n"
+ " v_texcoord = a_texcoord.xy;\n"
+ " gl_Position = u_mvp * a_position;\n"
+ "}\n";
+
+
Shader vertexColor, fragmentColor;
Shader vertexUniformColor, fragmentUniformColor;
Shader vertexTexture, fragmentTexture, fragmentOpacityTexture;
__pTextureShader->Construct(vertexTexture, fragmentTexture);
__pTextureOpacityShader->Construct(vertexTexture, fragmentOpacityTexture);
- vertexLight.Construct(Shader::SHADER_VERTEX, strVertexShader_light);
- fragmentLight.Construct(Shader::SHADER_FRAGMENT, strFragmentShader_light);
+ vertexLight.Construct(Shader::SHADER_VERTEX, strVertexShader_PerPixellight);
+ fragmentLight.Construct(Shader::SHADER_FRAGMENT, strFragmentShader_PerPixellight);
__pLightShader->Construct(vertexLight, fragmentLight);
}