diff --git a/data/ParticuleMesh.frag b/data/ParticuleMesh.frag new file mode 100644 index 0000000..3d6a4e7 --- /dev/null +++ b/data/ParticuleMesh.frag @@ -0,0 +1,41 @@ +#ifdef GL_ES +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; +uniform vec4 EW_mainColor; + +varying vec2 f_texcoord; +varying vec3 v_ecNormal; + +void main(void) { + vec4 tmpElementColor = texture2D(EW_texID, f_texcoord)*EW_mainColor; + + // Calculate ambient light + vec4 ambientLight = EW_directionalLight.ambientColor * EW_material.ambientFactor; + + vec4 light = ambientLight; + + gl_FragColor = tmpElementColor * light; +} diff --git a/data/ParticuleMesh.vert b/data/ParticuleMesh.vert new file mode 100644 index 0000000..1198fb1 --- /dev/null +++ b/data/ParticuleMesh.vert @@ -0,0 +1,20 @@ +#ifdef GL_ES +precision mediump float; +precision mediump int; +#endif +// Input : +attribute vec3 EW_coord3d; +attribute vec2 EW_texture2d; +attribute vec3 EW_normal; +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; + mat4 MatrixPosition = EW_MatrixPosition; +} diff --git a/ege/ParticuleSimple.cpp b/ege/ParticuleSimple.cpp index cce628e..3b2a114 100644 --- a/ege/ParticuleSimple.cpp +++ b/ege/ParticuleSimple.cpp @@ -26,7 +26,7 @@ void ege::ParticuleSimple::Init(void) m_life = m_lifeFull; m_level = 0; m_pos = vec3(0,0,0); - m_angle = vec4(0,0,0,0); + m_angle = 0; m_speed = vec3(0,0,0); m_scale = vec3(1,1,1); m_scaleExpand = vec3(0,0,0); @@ -62,7 +62,7 @@ void ege::ParticuleSimple::SetPosition(const vec3& _pos) m_pos = _pos; } -void ege::ParticuleSimple::SetAngleSpeed(const vec4& _angle) +void ege::ParticuleSimple::SetAngle(float _angle) { m_angle = _angle; } diff --git a/ege/ParticuleSimple.h b/ege/ParticuleSimple.h index 15f70be..3213043 100644 --- a/ege/ParticuleSimple.h +++ b/ege/ParticuleSimple.h @@ -50,7 +50,7 @@ namespace ege { float m_life; float m_level; vec3 m_pos; - vec4 m_angle; + float m_angle; vec3 m_speed; vec3 m_scale; vec3 m_scaleExpand; @@ -61,7 +61,7 @@ namespace ege { virtual void SetLife(float _life); virtual void SetLevel(float _level); virtual void SetPosition(const vec3& _pos); - virtual void SetAngleSpeed(const vec4& _angle); + virtual void SetAngle(float _angle); virtual void SetMoveSpeed(const vec3& _speed); virtual void SetScale(const vec3& _scale); virtual void SetScaleExpend(const vec3& _scaleExpand); diff --git a/ege/resource/ParticuleMesh.cpp b/ege/resource/ParticuleMesh.cpp new file mode 100644 index 0000000..7aaafde --- /dev/null +++ b/ege/resource/ParticuleMesh.cpp @@ -0,0 +1,152 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license BSD v3 (see license file) + */ + +#include +#include +#include + +ege::resource::ParticuleMesh::ParticuleMesh(const etk::UString& _fileName, const etk::UString& _shaderName) : + ewol::Mesh(_fileName, _shaderName) +{ + if (m_GLprogram != NULL) { + m_GLMainColor = m_GLprogram->GetUniform("EW_mainColor"); + } +} + +ege::resource::ParticuleMesh::~ParticuleMesh(void) +{ + +} + +void ege::resource::ParticuleMesh::Draw(mat4& _positionMatrix, + const etk::Color& _mainColor, + bool _enableDepthTest, + bool _enableDepthUpdate) +{ + if (m_GLprogram==NULL) { + EWOL_ERROR("No shader ..."); + return; + } + //EWOL_DEBUG(m_name << " " << m_light); + if (_enableDepthTest==true) { + ewol::openGL::Enable(ewol::openGL::FLAG_DEPTH_TEST); + if (false==_enableDepthUpdate) { + glDepthMask(GL_FALSE); + } + } else { + ewol::openGL::Disable(ewol::openGL::FLAG_DEPTH_TEST); + } + //EWOL_DEBUG(" Display " << m_coord.Size() << " elements" ); + m_GLprogram->Use(); + // set Matrix : translation/positionMatrix + mat4 projMatrix = ewol::openGL::GetMatrix(); + mat4 camMatrix = ewol::openGL::GetCameraMatrix(); + mat4 tmpMatrix = projMatrix * camMatrix; + m_GLprogram->UniformMatrix4fv(m_GLMatrix, 1, tmpMatrix.m_mat); + m_GLprogram->UniformMatrix4fv(m_GLMatrixPosition, 1, _positionMatrix.m_mat); + vec4 tmpColor(_mainColor.r(), _mainColor.g(), _mainColor.b(), _mainColor.a()); + m_GLprogram->Uniform4(m_GLMainColor, tmpColor); + // position : + m_GLprogram->SendAttributePointer(m_GLPosition, 3/*x,y,z*/, m_verticesVBO, MESH_VBO_VERTICES); + // Texture : + 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); + // draw lights : + m_light.Draw(m_GLprogram); + #ifdef DISPLAY_NB_VERTEX_DISPLAYED + int32_t nbElementDrawTheoric = 0; + int32_t nbElementDraw = 0; + #endif + for (esize_t kkk=0; kkkDraw(m_GLprogram, m_GLMaterial); + if (m_checkNormal==false) { + ewol::openGL::DrawElements(GL_TRIANGLES, m_listFaces.GetValue(kkk).m_index); + #ifdef DISPLAY_NB_VERTEX_DISPLAYED + nbElementDraw += m_listFaces.GetValue(kkk).m_index.Size(); + nbElementDrawTheoric += m_listFaces.GetValue(kkk).m_index.Size(); + #endif + } else { + mat4 mattttt = (projMatrix * camMatrix) * _positionMatrix; + mattttt.m_mat[3] = 0; + mattttt.m_mat[7] = 0; + mattttt.m_mat[11] = 0; + //vec3 cameraNormal = vec3(-mattttt.m_mat[2], -mattttt.m_mat[6], -mattttt.m_mat[10]); + vec3 cameraNormal = vec3(0,0,-1); + cameraNormal.normalized(); + // remove face that is notin the view ... + etk::Vector tmpIndexResult; + etk::Vector& tmppFaces = m_listFaces.GetValue(kkk).m_faces; + etk::Vector& tmppIndex = m_listFaces.GetValue(kkk).m_index; + if (normalModeFace == m_normalMode) { + for(int32_t iii=0; iii= 0.0f) { + tmpIndexResult.PushBack(iii*3); + tmpIndexResult.PushBack(iii*3+1); + tmpIndexResult.PushBack(iii*3+2); + } + } + } else { + for(int32_t iii=0; iii= -0.2f) + || (btDot(mattttt * m_listVertexNormal[tmppFaces[iii].m_normal[1]], cameraNormal) >= -0.2f) + || (btDot(mattttt * m_listVertexNormal[tmppFaces[iii].m_normal[2]], cameraNormal) >= -0.2f) ) { + tmpIndexResult.PushBack(iii*3); + tmpIndexResult.PushBack(iii*3+1); + tmpIndexResult.PushBack(iii*3+2); + } + } + } + ewol::openGL::DrawElements(GL_TRIANGLES, tmpIndexResult); + #ifdef DISPLAY_NB_VERTEX_DISPLAYED + nbElementDraw += tmpIndexResult.Size(); + nbElementDrawTheoric += m_listFaces.GetValue(kkk).m_index.Size(); + #endif + } + } + #ifdef DISPLAY_NB_VERTEX_DISPLAYED + EWOL_DEBUG(((float)nbElementDraw/(float)nbElementDrawTheoric*100.0f) << "% Request Draw : " << m_listFaces.Size() << ":" << nbElementDraw << "/" << nbElementDrawTheoric << " elements [" << m_name << "]"); + #endif + m_GLprogram->UnUse(); + if (_enableDepthTest==true){ + if (false==_enableDepthUpdate) { + glDepthMask(GL_TRUE); + } + ewol::openGL::Disable(ewol::openGL::FLAG_DEPTH_TEST); + } + glBindBuffer(GL_ARRAY_BUFFER,0); +} + +ege::resource::ParticuleMesh* ege::resource::ParticuleMesh::Keep(const etk::UString& _meshName, const etk::UString& _shaderName) +{ + ege::resource::ParticuleMesh* object = static_cast(GetManager().LocalKeep(_meshName)); + if (NULL != object) { + return object; + } + object = new ege::resource::ParticuleMesh(_meshName, _shaderName); + if (object == NULL) { + EWOL_ERROR("allocation error of a resource : ??Mesh??" << _meshName); + return NULL; + } + GetManager().LocalAdd(object); + return object; +} + +void ege::resource::ParticuleMesh::Release(ege::resource::ParticuleMesh*& _object) +{ + if (_object == NULL) { + return; + } + ewol::Resource* object2 = static_cast(_object); + GetManager().Release(object2); + _object = NULL; +} diff --git a/ege/resource/ParticuleMesh.h b/ege/resource/ParticuleMesh.h new file mode 100644 index 0000000..2ae2693 --- /dev/null +++ b/ege/resource/ParticuleMesh.h @@ -0,0 +1,46 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license BSD v3 (see license file) + */ + +#ifndef __EGE_RESOURCE_PARTICULE_MESH_H__ +#define __EGE_RESOURCE_PARTICULE_MESH_H__ + +#include + +namespace ege +{ + namespace resource + { + class ParticuleMesh : public ewol::Mesh + { + protected: + int32_t m_GLMainColor; + protected: + ParticuleMesh(const etk::UString& _fileName, const etk::UString& _shaderName); + virtual ~ParticuleMesh(void); + public: + virtual const char* GetType(void) { return "ege::resource::ParticuleMesh"; }; + virtual void Draw(mat4& _positionMatrix, const etk::Color& _mainColor, bool _enableDepthTest=true, bool _enableDepthUpdate=true); + public: + /** + * @brief Keep the resource pointer. + * @note Never free this pointer by your own... + * @param[in] _filename Name of the ewol mesh file. + * @return pointer on the resource or NULL if an error occured. + */ + static ege::resource::ParticuleMesh* Keep(const etk::UString& _meshName, const etk::UString& _shaderName="DATA:ParticuleMesh.prog"); + /** + * @brief Release the keeped resources + * @param[in,out] reference on the object pointer + */ + static void Release(ege::resource::ParticuleMesh*& _object); + }; + }; +}; + + +#endif diff --git a/lutin_ege.py b/lutin_ege.py index 7c6f3ac..7b2827f 100644 --- a/lutin_ege.py +++ b/lutin_ege.py @@ -18,9 +18,12 @@ def Create(target): 'ege/ParticuleEngine.cpp', 'ege/ParticuleSimple.cpp', 'ege/Scene.cpp', - 'ege/Environement.cpp' + 'ege/Environement.cpp', + 'ege/resource/ParticuleMesh.cpp' ]) + myModule.CopyFolder('data/ParticuleMesh.*','') + # name of the dependency myModule.AddModuleDepend(['ewol', 'bullet'])