diff --git a/build b/build index cb8010af..57ef468e 160000 --- a/build +++ b/build @@ -1 +1 @@ -Subproject commit cb8010af47373f5d5b2c319153b2585b074b5b68 +Subproject commit 57ef468e1cbca4e6a6c4a9804024e7a684017441 diff --git a/data/textured3D2.frag b/data/textured3D2.frag index eef476af..65634b55 100644 --- a/data/textured3D2.frag +++ b/data/textured3D2.frag @@ -2,12 +2,57 @@ precision mediump float; precision mediump int; #endif +struct DirectionalLight { + vec3 direction; + vec3 halfplane; + vec4 ambientColor; + vec4 diffuseColor; + vec4 specularColor; +}; + +struct Material { + vec4 ambientFactor; + vec4 diffuseFactor; + vec4 specularFactor; + float shininess; +}; + +// Light +uniform DirectionalLight EW_directionalLight; +// Material +uniform Material EW_material; // Input : uniform sampler2D EW_texID; varying vec2 f_texcoord; +varying vec3 v_ecNormal; void main(void) { - gl_FragColor = texture2D(EW_texID, f_texcoord); + vec4 tmpElementColor = texture2D(EW_texID, f_texcoord); + + // Normalize v_ecNormal + vec3 ecNormal = v_ecNormal / length(v_ecNormal); + + float ecNormalDotLightDirection = max(0.0, dot(ecNormal, EW_directionalLight.direction)); + float ecNormalDotLightHalfplane = max(0.0, dot(ecNormal, EW_directionalLight.halfplane)); + + // Calculate ambient light + vec4 ambientLight = EW_directionalLight.ambientColor * EW_material.ambientFactor; + + // Calculate diffuse light + vec4 diffuseLight = ecNormalDotLightDirection * EW_directionalLight.diffuseColor * EW_material.diffuseFactor; + + // Calculate specular light + vec4 specularLight = vec4(0.0); + + if (ecNormalDotLightHalfplane > 0.0) { + specularLight = pow(ecNormalDotLightHalfplane, EW_material.shininess) * EW_directionalLight.specularColor * EW_material.specularFactor; + specularLight = EW_directionalLight.specularColor * EW_material.specularFactor; + } + + + vec4 light = ambientLight + diffuseLight + specularLight; + + gl_FragColor = tmpElementColor * light; } diff --git a/data/textured3D2.vert b/data/textured3D2.vert index 3f5eceee..4cfb34f8 100644 --- a/data/textured3D2.vert +++ b/data/textured3D2.vert @@ -6,14 +6,22 @@ precision mediump int; attribute vec3 EW_coord3d; attribute vec2 EW_texture2d; attribute vec3 EW_normal; +attribute vec3 EW_faceNormal; uniform mat4 EW_MatrixTransformation; uniform mat4 EW_MatrixPosition; // output : varying vec2 f_texcoord; +varying vec3 v_ecNormal; void main(void) { gl_Position = EW_MatrixTransformation * EW_MatrixPosition * vec4(EW_coord3d, 1.0); // set texture output coord f_texcoord = EW_texture2d; + mat4 MatrixPosition = EW_MatrixPosition; + MatrixPosition[3][0] = 0.0; + MatrixPosition[3][1] = 0.0; + MatrixPosition[3][2] = 0.0; + //v_ecNormal = vec3(MatrixPosition * vec4(EW_normal, 1.0) ); + v_ecNormal = vec3(MatrixPosition * vec4(EW_faceNormal, 1.0) ); } diff --git a/data/texturedNoMaterial.frag b/data/texturedNoMaterial.frag new file mode 100644 index 00000000..eef476af --- /dev/null +++ b/data/texturedNoMaterial.frag @@ -0,0 +1,13 @@ +#ifdef GL_ES +precision mediump float; +precision mediump int; +#endif + +// Input : +uniform sampler2D EW_texID; + +varying vec2 f_texcoord; + +void main(void) { + gl_FragColor = texture2D(EW_texID, f_texcoord); +} diff --git a/data/texturedNoMaterial.prog b/data/texturedNoMaterial.prog new file mode 100644 index 00000000..b9a1a8f9 --- /dev/null +++ b/data/texturedNoMaterial.prog @@ -0,0 +1,2 @@ +texturedNoMaterial.vert +texturedNoMaterial.frag \ No newline at end of file diff --git a/data/texturedNoMaterial.vert b/data/texturedNoMaterial.vert new file mode 100644 index 00000000..a757e9c9 --- /dev/null +++ b/data/texturedNoMaterial.vert @@ -0,0 +1,18 @@ +#ifdef GL_ES +precision mediump float; +precision mediump int; +#endif +// Input : +attribute vec3 EW_coord3d; +attribute vec2 EW_texture2d; +uniform mat4 EW_MatrixTransformation; +uniform mat4 EW_MatrixPosition; + +// output : +varying vec2 f_texcoord; + +void main(void) { + gl_Position = EW_MatrixTransformation * EW_MatrixPosition * vec4(EW_coord3d, 1.0); + // set texture output coord + f_texcoord = EW_texture2d; +} diff --git a/sources/ewol/compositing/Area.h b/sources/ewol/compositing/Area.h index 14116b88..06ec5f07 100644 --- a/sources/ewol/compositing/Area.h +++ b/sources/ewol/compositing/Area.h @@ -53,7 +53,7 @@ namespace ewol */ void Draw(void); /** - * @brief Clear alll tre registered element in the current element + * @brief Clear alll the registered element in the current element */ void Clear(void); /** diff --git a/sources/ewol/renderer/Light.cpp b/sources/ewol/renderer/Light.cpp index f91cc55e..af28d883 100644 --- a/sources/ewol/renderer/Light.cpp +++ b/sources/ewol/renderer/Light.cpp @@ -31,6 +31,9 @@ ewol::Light::~Light(void) void ewol::Light::Link(ewol::Program* prog, const etk::UString& baseName) { + if (NULL == prog) { + return; + } m_GL_direction = prog->GetUniform(baseName+".direction"); m_GL_halfplane = prog->GetUniform(baseName+".halfplane"); m_GL_ambientColor = prog->GetUniform(baseName+".ambientColor"); diff --git a/sources/ewol/renderer/Material.cpp b/sources/ewol/renderer/Material.cpp index 1a4cccb7..1a0841d3 100644 --- a/sources/ewol/renderer/Material.cpp +++ b/sources/ewol/renderer/Material.cpp @@ -29,6 +29,9 @@ ewol::Material::~Material(void) void ewol::Material::Link(ewol::Program* prog, const etk::UString& baseName) { + if (NULL == prog) { + return; + } m_GL_ambientFactor = prog->GetUniform(baseName+".ambientFactor"); m_GL_diffuseFactor = prog->GetUniform(baseName+".diffuseFactor"); m_GL_specularFactor = prog->GetUniform(baseName+".specularFactor"); diff --git a/sources/ewol/renderer/resources/Mesh.cpp b/sources/ewol/renderer/resources/Mesh.cpp index 816ee283..26a24857 100644 --- a/sources/ewol/renderer/resources/Mesh.cpp +++ b/sources/ewol/renderer/resources/Mesh.cpp @@ -60,20 +60,37 @@ class VertexNode { ewol::Mesh::Mesh(etk::UString genName, etk::UString shaderName) : ewol::Resource(genName), - m_enableFaceNormal(false), + m_enableFaceNormal(true), m_enableVertexNormal(true), m_numberOfElments(0), m_texture0(NULL) { // get the shader resource : m_GLPosition = 0; + + // set the element material properties : + m_material.SetAmbientFactor(vec4(0.200000,0.200000,0.200000, 1.0)); + m_material.SetDiffuseFactor(vec4(0.640000, 0.640000, 0.640000, 1.0)); + m_material.SetSpecularFactor(vec4(0.500000, 0.500000, 0.500000, 1.0)); + m_material.SetShininess(0.96078431); + + m_light.SetDirection(vec3(0,cos(M_PI/4),sin(M_PI/4))); + m_light.SetHalfPlane(vec3(1,0,0)); + m_light.SetAmbientColor(vec4(1,1,1,1)); + m_light.SetDiffuseColor(vec4(1.0,1.0,1.0,1)); + m_light.SetSpecularColor(vec4(0.0,0.0,0.0,1)); + if (true == ewol::resource::Keep(shaderName, m_GLprogram) ) { m_GLPosition = m_GLprogram->GetAttribute("EW_coord3d"); m_GLtexture = m_GLprogram->GetAttribute("EW_texture2d"); m_GLNormal = m_GLprogram->GetAttribute("EW_normal"); + m_GLNormalFace = m_GLprogram->GetAttribute("EW_faceNormal"); m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation"); m_GLMatrixPosition = m_GLprogram->GetUniform("EW_MatrixPosition"); m_GLtexID0 = m_GLprogram->GetUniform("EW_texID"); + // Link material and Lights + m_material.Link(m_GLprogram, "EW_material"); + m_light.Link(m_GLprogram, "EW_directionalLight"); } // this is the properties of the buffer requested : "r"/"w" + "-" + buffer type "f"=flaot "i"=integer ewol::resource::Keep("w-fff", m_verticesVBO); @@ -121,6 +138,12 @@ void ewol::Mesh::Draw(mat4& positionMatrix) m_GLprogram->SendAttributePointer(m_GLtexture, 2/*u,v*/, m_verticesVBO, MESH_VBO_TEXTURE); // position : m_GLprogram->SendAttributePointer(m_GLNormal, 3/*x,y,z*/, m_verticesVBO, MESH_VBO_VERTICES_NORMAL); + // position : + m_GLprogram->SendAttributePointer(m_GLNormalFace, 3/*x,y,z*/, m_verticesVBO, MESH_VBO_FACE_NORMAL); + // draw materials : + m_material.Draw(m_GLprogram); + m_light.Draw(m_GLprogram); + // Request the draw od the elements : glDrawArrays(GL_TRIANGLES, 0, m_numberOfElments); m_GLprogram->UnUse(); @@ -196,6 +219,9 @@ void ewol::Mesh::GenerateVBO(void) if(true==m_enableVertexNormal) { m_verticesVBO->PushOnBuffer(MESH_VBO_VERTICES_NORMAL,m_listVertexNormal[m_listFaces[iii].m_vertex[indice]]); } + if(true==m_enableFaceNormal) { + m_verticesVBO->PushOnBuffer(MESH_VBO_FACE_NORMAL,m_listFacesNormal[iii]); + } indice = 1; tmpUV = m_listUV[m_listFaces[iii].m_uv[indice]]; @@ -204,6 +230,9 @@ void ewol::Mesh::GenerateVBO(void) if(true==m_enableVertexNormal) { m_verticesVBO->PushOnBuffer(MESH_VBO_VERTICES_NORMAL,m_listVertexNormal[m_listFaces[iii].m_vertex[indice]]); } + if(true==m_enableFaceNormal) { + m_verticesVBO->PushOnBuffer(MESH_VBO_FACE_NORMAL,m_listFacesNormal[iii]); + } indice = 2; tmpUV = m_listUV[m_listFaces[iii].m_uv[indice]]; @@ -212,6 +241,9 @@ void ewol::Mesh::GenerateVBO(void) if(true==m_enableVertexNormal) { m_verticesVBO->PushOnBuffer(MESH_VBO_VERTICES_NORMAL,m_listVertexNormal[m_listFaces[iii].m_vertex[indice]]); } + if(true==m_enableFaceNormal) { + m_verticesVBO->PushOnBuffer(MESH_VBO_FACE_NORMAL,m_listFacesNormal[iii]); + } #ifndef PRINT_HALF if (m_listFaces[iii].m_nbElement==4) { indice = 0; @@ -221,6 +253,9 @@ void ewol::Mesh::GenerateVBO(void) if(true==m_enableVertexNormal) { m_verticesVBO->PushOnBuffer(MESH_VBO_VERTICES_NORMAL,m_listVertexNormal[m_listFaces[iii].m_vertex[indice]]); } + if(true==m_enableFaceNormal) { + m_verticesVBO->PushOnBuffer(MESH_VBO_FACE_NORMAL,m_listFacesNormal[iii]); + } indice = 2; tmpUV = m_listUV[m_listFaces[iii].m_uv[indice]]; @@ -229,6 +264,9 @@ void ewol::Mesh::GenerateVBO(void) if(true==m_enableVertexNormal) { m_verticesVBO->PushOnBuffer(MESH_VBO_VERTICES_NORMAL,m_listVertexNormal[m_listFaces[iii].m_vertex[indice]]); } + if(true==m_enableFaceNormal) { + m_verticesVBO->PushOnBuffer(MESH_VBO_FACE_NORMAL,m_listFacesNormal[iii]); + } indice = 3; tmpUV = m_listUV[m_listFaces[iii].m_uv[indice]]; @@ -237,6 +275,9 @@ void ewol::Mesh::GenerateVBO(void) if(true==m_enableVertexNormal) { m_verticesVBO->PushOnBuffer(MESH_VBO_VERTICES_NORMAL,m_listVertexNormal[m_listFaces[iii].m_vertex[indice]]); } + if(true==m_enableFaceNormal) { + m_verticesVBO->PushOnBuffer(MESH_VBO_FACE_NORMAL,m_listFacesNormal[iii]); + } } #endif } @@ -245,7 +286,7 @@ void ewol::Mesh::GenerateVBO(void) } -void ewol::Mesh::CreateCube(void) +void ewol::Mesh::CreateCube(float size) { m_listVertex.Clear(); m_listUV.Clear(); @@ -276,14 +317,14 @@ void ewol::Mesh::CreateCube(void) o---------------------o 0 3 */ - m_listVertex.PushBack(vec3( 1.0, -1.0, -1.0)); // 0 - m_listVertex.PushBack(vec3( 1.0, -1.0, 1.0)); // 1 - m_listVertex.PushBack(vec3(-1.0, -1.0, 1.0)); // 2 - m_listVertex.PushBack(vec3(-1.0, -1.0, -1.0)); // 3 - m_listVertex.PushBack(vec3( 1.0, 1.0, -1.0)); // 4 - m_listVertex.PushBack(vec3( 1.0, 1.0, 1.0)); // 5 - m_listVertex.PushBack(vec3(-1.0, 1.0, 1.0)); // 6 - m_listVertex.PushBack(vec3(-1.0, 1.0, -1.0)); // 7 + m_listVertex.PushBack(vec3( size, -size, -size)); // 0 + m_listVertex.PushBack(vec3( size, -size, size)); // 1 + m_listVertex.PushBack(vec3(-size, -size, size)); // 2 + m_listVertex.PushBack(vec3(-size, -size, -size)); // 3 + m_listVertex.PushBack(vec3( size, size, -size)); // 4 + m_listVertex.PushBack(vec3( size, size, size)); // 5 + m_listVertex.PushBack(vec3(-size, size, size)); // 6 + m_listVertex.PushBack(vec3(-size, size, -size)); // 7 m_listUV.PushBack(vec2(0.0, 0.0)); m_listUV.PushBack(vec2(1.0, 0.0)); @@ -299,6 +340,89 @@ void ewol::Mesh::CreateCube(void) } +void ewol::Mesh::CreateViewBox(float size) +{ + m_listVertex.Clear(); + m_listUV.Clear(); + m_listFaces.Clear(); + m_numberOfElments = 0; + // This is the direct generation basis on the .obj system + /* + 5 6 + o---------------------o + /. /| + / . / | + / . / | + / . / | + / . / | + 4 / . / | + o---------------------o | + | . |7 | + | . | | + | . | | + | . | | + | o..............|......o + | . 1 | / 2 + | . | / + | . | / + | . | / + | . | / + |. |/ + o---------------------o + 0 3 + */ + m_listVertex.PushBack(vec3( size, -size, -size)); // 0 + m_listVertex.PushBack(vec3( size, -size, size)); // 1 + m_listVertex.PushBack(vec3(-size, -size, size)); // 2 + m_listVertex.PushBack(vec3(-size, -size, -size)); // 3 + m_listVertex.PushBack(vec3( size, size, -size)); // 4 + m_listVertex.PushBack(vec3( size, size, size)); // 5 + m_listVertex.PushBack(vec3(-size, size, size)); // 6 + m_listVertex.PushBack(vec3(-size, size, -size)); // 7 + /* + o----------o----------o----------o + |8 |9 |10 |11 + | | | | + | | | | + | 0 | 1 | 2 | + | | | | + | | | | + | | | | + | | | | + o----------o----------o----------o + |4 |5 |6 |7 + | | | | + | | | | + | 3 | 4 | 5 | + | | | | + | | | | + | | | | + | | | | + o----------o----------o----------o + 0 1 2 3 + */ + m_listUV.PushBack(vec2(0.0 , 0.0 )); // 0 + m_listUV.PushBack(vec2(1.0/3.0, 0.0 )); // 1 + m_listUV.PushBack(vec2(2.0/3.0, 0.0 )); // 2 + m_listUV.PushBack(vec2(1.0 , 0.0 )); // 3 + m_listUV.PushBack(vec2(0.0 , 0.5 )); // 4 + m_listUV.PushBack(vec2(1.0/3.0, 0.5 )); // 5 + m_listUV.PushBack(vec2(2.0/3.0, 0.5 )); // 6 + m_listUV.PushBack(vec2(1.0 , 0.5 )); // 7 + m_listUV.PushBack(vec2(0.0 , 1.0 )); // 8 + m_listUV.PushBack(vec2(1.0/3.0, 1.0 )); // 9 + m_listUV.PushBack(vec2(2.0/3.0, 1.0 )); // 10 + m_listUV.PushBack(vec2(1.0 , 1.0 )); // 11 + + m_listFaces.PushBack(Face(0,1, 1,5, 2,6, 3,2)); // 4 + m_listFaces.PushBack(Face(4,4, 0,0, 3,1, 7,5)); // 3 + m_listFaces.PushBack(Face(2,6, 6,10, 7,11, 3,7)); // 2 + m_listFaces.PushBack(Face(4,2, 7,3, 6,7, 5,6)); // 5 + m_listFaces.PushBack(Face(1,5, 5,9, 6,10, 2,6)); // 1 + m_listFaces.PushBack(Face(0,4, 4,8, 5,9, 1,5)); // 0 + +} + void ewol::Mesh::SetTexture(const etk::UString& myTexture) { ivec2 tmpSize(256, 256); @@ -568,3 +692,17 @@ void ewol::Mesh::InternalSubdivide(bool smooth) } listVertex.Clear(); } + + + +void ewol::Mesh::LoadMaterial(const etk::UString& name) +{ + +} + +void ewol::Mesh::DisplaceElement(const ewol::DisplacementTable& displacement) +{ + +} + + diff --git a/sources/ewol/renderer/resources/Mesh.h b/sources/ewol/renderer/resources/Mesh.h index abff6d95..c44f9643 100644 --- a/sources/ewol/renderer/resources/Mesh.h +++ b/sources/ewol/renderer/resources/Mesh.h @@ -15,18 +15,55 @@ #include #include #include - +#include +#include // 3 "float" elements #define MESH_VBO_VERTICES (0) // 2 "float" elements #define MESH_VBO_TEXTURE (1) // 3 "float" elements #define MESH_VBO_VERTICES_NORMAL (2) +#define MESH_VBO_FACE_NORMAL (3) // 4 "float" elements -#define MESH_VBO_COLOR (3) +#define MESH_VBO_COLOR (4) namespace ewol { + class DisplacementTable + { + private: + ivec2 m_size; + public: + etk::Vector m_data; + DisplacementTable(const ivec2& size) : + m_size(size), + m_data(size.x()*size.y()) + { + // TODO : Check input ... + m_data.ReSize(m_size.x()*m_size.y(), 0); + for(int32_t iii=0; iii m_listVertex; //!< List of all vertex in the element etk::Vector m_listUV; //!< List of all UV point in the mesh (for the specify texture) @@ -95,9 +135,7 @@ namespace ewol void GenerateVBO(void); public: // some addition basic funtion that permit to create or overwrite some caracterstics : - void CreateCube(void); void SetTexture(const etk::UString& myTexture); - void Subdivide(int32_t numberOfTime, bool smooth); protected: void InternalSubdivide(bool smooth); public: @@ -110,6 +148,16 @@ namespace ewol private: void CalculateNormaleFace(void); void CalculateNormaleEdge(void); + public: + void LoadMaterial(const etk::UString& name); + /* + * Element modification area : + */ + public : + void CreateCube(float size=1.0); + void CreateViewBox(float size=1.0); + void Subdivide(int32_t numberOfTime, bool smooth); + void DisplaceElement(const ewol::DisplacementTable& displacement); }; }; diff --git a/sources/ewol/renderer/resources/VirtualBufferObject.h b/sources/ewol/renderer/resources/VirtualBufferObject.h index e3f898d2..ab75bb8b 100644 --- a/sources/ewol/renderer/resources/VirtualBufferObject.h +++ b/sources/ewol/renderer/resources/VirtualBufferObject.h @@ -34,7 +34,7 @@ namespace ewol * @brief Constructor of this VBO. * @param[in] accesMode Acces mode : ??? */ - VirtualBufferObject(const etk::UString& accesMode, int32_t nbElement=3); + VirtualBufferObject(const etk::UString& accesMode, int32_t nbElement=4); /** * @brief Destructor of this VBO. */ diff --git a/sources/file.mk b/sources/file.mk index ad743dfd..fae908cf 100644 --- a/sources/file.mk +++ b/sources/file.mk @@ -88,36 +88,19 @@ FILE_LIST+= ewol/widget/Scene.cpp \ ewol/game/Camera.cpp -LOCAL_COPY_FILES := ../data/textured3D.prog:textured3D.prog \ - ../data/textured3D.frag:textured3D.frag \ - ../data/textured3D.vert:textured3D.vert \ - \ - ../data/textured3D2.prog:textured3D2.prog \ - ../data/textured3D2.frag:textured3D2.frag \ - ../data/textured3D2.vert:textured3D2.vert \ - \ - ../data/color.prog:color.prog \ - ../data/color.frag:color.frag \ - ../data/color.vert:color.vert \ - \ - ../data/color3.prog:color3.prog \ - ../data/color3.frag:color3.frag \ - ../data/color3.vert:color3.vert \ - \ - ../data/simple3D.prog:simple3D.prog \ - ../data/simple3D.frag:simple3D.frag \ - ../data/simple3D.vert:simple3D.vert \ - \ - ../data/textured.prog:textured.prog \ - ../data/textured.frag:textured.frag \ - ../data/textured.vert:textured.vert \ - \ - ../data/text.prog:text.prog \ - ../data/text.frag:text.frag \ - ../data/text.vert:text.vert - LOCAL_COPY_FOLDERS := ../data/theme/default/widgetEntry.*:theme/default \ ../data/theme/rounded/widgetEntry.*:theme/rounded \ ../data/theme/default/widgetButton.*:theme/default \ ../data/theme/rounded/widgetButton.*:theme/rounded \ - + ../data/textured.*: \ + ../data/texturedNoMaterial.*: \ + ../data/text.*: \ + ../data/simple3D.*: \ + ../data/color.*: \ + ../data/color3.*: \ + ../data/textured3D2.*: \ + ../data/textured3D.*: + + + +