From f49abf6a9d4a209e414c86191f707f1ced318f3b Mon Sep 17 00:00:00 2001 From: kearwood Date: Thu, 29 Nov 2012 21:28:49 +0000 Subject: [PATCH] Minor code cleanup Implemented new constructor for KRQuaternion for creating "from - to" rotation quaternions Implemented billboards by adding a "faces_camera" boolean attribute to KRInstance --HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%40169 --- KREngine/KREngine.xcodeproj/project.pbxproj | 34 ++- KREngine/KREngine/Classes/KRAABB.cpp | 9 +- KREngine/KREngine/Classes/KRAABB.h | 1 + KREngine/KREngine/Classes/KRInstance.cpp | 25 ++- KREngine/KREngine/Classes/KRInstance.h | 3 +- KREngine/KREngine/Classes/KRLight.cpp | 2 +- KREngine/KREngine/Classes/KRNode.cpp | 34 ++- ...nian.cpp => KRParticleSystemNewtonian.cpp} | 24 +- ...Brownian.h => KRParticleSystemNewtonian.h} | 12 +- KREngine/KREngine/Classes/KRQuaternion.cpp | 10 + KREngine/KREngine/Classes/KRQuaternion.h | 1 + KREngine/KREngine/Classes/KRResource+fbx.cpp | 206 ++++++++++++------ .../{particle.fsh => dust_particle.fsh} | 7 +- .../{particle.vsh => dust_particle.vsh} | 3 +- 14 files changed, 247 insertions(+), 124 deletions(-) rename KREngine/KREngine/Classes/{KRParticleSystemBrownian.cpp => KRParticleSystemNewtonian.cpp} (80%) rename KREngine/KREngine/Classes/{KRParticleSystemBrownian.h => KRParticleSystemNewtonian.h} (71%) rename KREngine/KREngine/Shaders/{particle.fsh => dust_particle.fsh} (88%) rename KREngine/KREngine/Shaders/{particle.vsh => dust_particle.vsh} (96%) diff --git a/KREngine/KREngine.xcodeproj/project.pbxproj b/KREngine/KREngine.xcodeproj/project.pbxproj index 86ef886..571b6ce 100644 --- a/KREngine/KREngine.xcodeproj/project.pbxproj +++ b/KREngine/KREngine.xcodeproj/project.pbxproj @@ -21,14 +21,13 @@ E42CB1ED158446940066E0D8 /* KRQuaternion.h in Headers */ = {isa = PBXBuildFile; fileRef = E42CB1EB158446940066E0D8 /* KRQuaternion.h */; settings = {ATTRIBUTES = (Public, ); }; }; E42CB1F0158446AB0066E0D8 /* KRQuaternion.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E42CB1EF158446AB0066E0D8 /* KRQuaternion.cpp */; }; E42CB1F1158446AB0066E0D8 /* KRQuaternion.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E42CB1EF158446AB0066E0D8 /* KRQuaternion.cpp */; }; - E431C1B8164DB7B200BE1575 /* volumetric_fog_downsampled.fsh in Sources */ = {isa = PBXBuildFile; fileRef = E431C1B7164DB7B200BE1575 /* volumetric_fog_downsampled.fsh */; }; E4324BA416444C0D0043185B /* KRParticleSystem.h in Headers */ = {isa = PBXBuildFile; fileRef = E4324BA316444C0D0043185B /* KRParticleSystem.h */; }; E4324BA516444C0D0043185B /* KRParticleSystem.h in Headers */ = {isa = PBXBuildFile; fileRef = E4324BA316444C0D0043185B /* KRParticleSystem.h */; }; E4324BA816444C230043185B /* KRParticleSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4324BA716444C230043185B /* KRParticleSystem.cpp */; }; - E4324BAB16444DEF0043185B /* KRParticleSystemBrownian.h in Headers */ = {isa = PBXBuildFile; fileRef = E4324BAA16444DEF0043185B /* KRParticleSystemBrownian.h */; }; - E4324BAC16444DEF0043185B /* KRParticleSystemBrownian.h in Headers */ = {isa = PBXBuildFile; fileRef = E4324BAA16444DEF0043185B /* KRParticleSystemBrownian.h */; }; - E4324BAE16444E120043185B /* KRParticleSystemBrownian.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4324BAD16444E120043185B /* KRParticleSystemBrownian.cpp */; }; - E4324BAF16444E120043185B /* KRParticleSystemBrownian.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4324BAD16444E120043185B /* KRParticleSystemBrownian.cpp */; }; + E4324BAB16444DEF0043185B /* KRParticleSystemNewtonian.h in Headers */ = {isa = PBXBuildFile; fileRef = E4324BAA16444DEF0043185B /* KRParticleSystemNewtonian.h */; }; + E4324BAC16444DEF0043185B /* KRParticleSystemNewtonian.h in Headers */ = {isa = PBXBuildFile; fileRef = E4324BAA16444DEF0043185B /* KRParticleSystemNewtonian.h */; }; + E4324BAE16444E120043185B /* KRParticleSystemNewtonian.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4324BAD16444E120043185B /* KRParticleSystemNewtonian.cpp */; }; + E4324BAF16444E120043185B /* KRParticleSystemNewtonian.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4324BAD16444E120043185B /* KRParticleSystemNewtonian.cpp */; }; E4324BB0164458930043185B /* KRParticleSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4324BA716444C230043185B /* KRParticleSystem.cpp */; }; E43B0AD615DDCA0F00A5CB9F /* KRContextObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43B0AD415DDCA0C00A5CB9F /* KRContextObject.cpp */; }; E43B0AD715DDCA0F00A5CB9F /* KRContextObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43B0AD415DDCA0C00A5CB9F /* KRContextObject.cpp */; }; @@ -220,8 +219,8 @@ E431C1B7164DB7B200BE1575 /* volumetric_fog_downsampled.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = volumetric_fog_downsampled.fsh; path = Shaders/volumetric_fog_downsampled.fsh; sourceTree = ""; }; E4324BA316444C0D0043185B /* KRParticleSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRParticleSystem.h; path = Classes/KRParticleSystem.h; sourceTree = ""; }; E4324BA716444C230043185B /* KRParticleSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRParticleSystem.cpp; path = Classes/KRParticleSystem.cpp; sourceTree = ""; }; - E4324BAA16444DEF0043185B /* KRParticleSystemBrownian.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRParticleSystemBrownian.h; path = Classes/KRParticleSystemBrownian.h; sourceTree = ""; }; - E4324BAD16444E120043185B /* KRParticleSystemBrownian.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRParticleSystemBrownian.cpp; path = Classes/KRParticleSystemBrownian.cpp; sourceTree = ""; }; + E4324BAA16444DEF0043185B /* KRParticleSystemNewtonian.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRParticleSystemNewtonian.h; path = Classes/KRParticleSystemNewtonian.h; sourceTree = ""; }; + E4324BAD16444E120043185B /* KRParticleSystemNewtonian.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRParticleSystemNewtonian.cpp; path = Classes/KRParticleSystemNewtonian.cpp; sourceTree = ""; }; E43B0AD415DDCA0C00A5CB9F /* KRContextObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRContextObject.cpp; path = Classes/KRContextObject.cpp; sourceTree = ""; }; E43B0AD515DDCA0D00A5CB9F /* KRContextObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRContextObject.h; path = Classes/KRContextObject.h; sourceTree = ""; }; E443C612164B5BE500FC4FD8 /* volumetric_fog.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = volumetric_fog.fsh; path = Shaders/volumetric_fog.fsh; sourceTree = ""; }; @@ -236,8 +235,8 @@ E45AC0331641D67300DC3C3B /* simple_blit.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = simple_blit.fsh; path = Shaders/simple_blit.fsh; sourceTree = ""; }; E45AC03E1641DE5D00DC3C3B /* debug_font.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = debug_font.vsh; path = Shaders/debug_font.vsh; sourceTree = ""; }; E45AC0411641DE6D00DC3C3B /* debug_font.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = debug_font.fsh; path = Shaders/debug_font.fsh; sourceTree = ""; }; - E45AC0461643451200DC3C3B /* particle.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = particle.fsh; path = Shaders/particle.fsh; sourceTree = ""; }; - E45AC0491643452000DC3C3B /* particle.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = particle.vsh; path = Shaders/particle.vsh; sourceTree = ""; }; + E45AC0461643451200DC3C3B /* dust_particle.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = dust_particle.fsh; path = Shaders/dust_particle.fsh; sourceTree = ""; }; + E45AC0491643452000DC3C3B /* dust_particle.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = dust_particle.vsh; path = Shaders/dust_particle.vsh; sourceTree = ""; }; E461A151152E54B500F2044A /* KRLight.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRLight.h; path = Classes/KRLight.h; sourceTree = ""; }; E461A155152E54F700F2044A /* KRLight.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRLight.cpp; path = Classes/KRLight.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; E461A157152E555400F2044A /* KRPointLight.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRPointLight.h; path = Classes/KRPointLight.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; @@ -378,8 +377,8 @@ children = ( E4324BA316444C0D0043185B /* KRParticleSystem.h */, E4324BA716444C230043185B /* KRParticleSystem.cpp */, - E4324BAA16444DEF0043185B /* KRParticleSystemBrownian.h */, - E4324BAD16444E120043185B /* KRParticleSystemBrownian.cpp */, + E4324BAA16444DEF0043185B /* KRParticleSystemNewtonian.h */, + E4324BAD16444E120043185B /* KRParticleSystemNewtonian.cpp */, ); name = "Particle Systems"; sourceTree = ""; @@ -411,8 +410,8 @@ E45AC0331641D67300DC3C3B /* simple_blit.fsh */, E45AC03E1641DE5D00DC3C3B /* debug_font.vsh */, E45AC0411641DE6D00DC3C3B /* debug_font.fsh */, - E45AC0461643451200DC3C3B /* particle.fsh */, - E45AC0491643452000DC3C3B /* particle.vsh */, + E45AC0461643451200DC3C3B /* dust_particle.fsh */, + E45AC0491643452000DC3C3B /* dust_particle.vsh */, E443C612164B5BE500FC4FD8 /* volumetric_fog.fsh */, E443C615164B5BFB00FC4FD8 /* volumetric_fog.vsh */, E431C1B6164DB79A00BE1575 /* volumetric_fog_downsampled.vsh */, @@ -754,7 +753,7 @@ E4CA10EC1637BD47005D9400 /* KRTextureTGA.h in Headers */, E4CA11741639CBD6005D9400 /* KRViewport.h in Headers */, E4324BA416444C0D0043185B /* KRParticleSystem.h in Headers */, - E4324BAB16444DEF0043185B /* KRParticleSystemBrownian.h in Headers */, + E4324BAB16444DEF0043185B /* KRParticleSystemNewtonian.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -807,7 +806,7 @@ E461A15D152E563100F2044A /* KRDirectionalLight.h in Headers */, E461A169152E570700F2044A /* KRSpotLight.h in Headers */, E4324BA516444C0D0043185B /* KRParticleSystem.h in Headers */, - E4324BAC16444DEF0043185B /* KRParticleSystemBrownian.h in Headers */, + E4324BAC16444DEF0043185B /* KRParticleSystemNewtonian.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -933,8 +932,7 @@ E4CA10EF1637BD58005D9400 /* KRTextureTGA.cpp in Sources */, E4CA11781639CC90005D9400 /* KRViewport.cpp in Sources */, E4324BA816444C230043185B /* KRParticleSystem.cpp in Sources */, - E4324BAE16444E120043185B /* KRParticleSystemBrownian.cpp in Sources */, - E431C1B8164DB7B200BE1575 /* volumetric_fog_downsampled.fsh in Sources */, + E4324BAE16444E120043185B /* KRParticleSystemNewtonian.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -982,7 +980,7 @@ E4CA10EA1637BD2B005D9400 /* KRTexturePVR.cpp in Sources */, E4CA10F01637BD58005D9400 /* KRTextureTGA.cpp in Sources */, E4CA11791639CC90005D9400 /* KRViewport.cpp in Sources */, - E4324BAF16444E120043185B /* KRParticleSystemBrownian.cpp in Sources */, + E4324BAF16444E120043185B /* KRParticleSystemNewtonian.cpp in Sources */, E4324BB0164458930043185B /* KRParticleSystem.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/KREngine/KREngine/Classes/KRAABB.cpp b/KREngine/KREngine/Classes/KRAABB.cpp index 89592cf..be7ef6e 100644 --- a/KREngine/KREngine/Classes/KRAABB.cpp +++ b/KREngine/KREngine/Classes/KRAABB.cpp @@ -222,4 +222,11 @@ float KRAABB::coverage(const KRMat4 &matVP, const KRVector2 viewportSize) const return (screen_max.x - screen_min.x) * (screen_max.y - screen_min.y); } -} \ No newline at end of file +} + +float KRAABB::longest_radius() const +{ + float radius1 = (center() - min).magnitude(); + float radius2 = (max - center()).magnitude(); + return radius1 > radius2 ? radius1 : radius2; +} diff --git a/KREngine/KREngine/Classes/KRAABB.h b/KREngine/KREngine/Classes/KRAABB.h index 9d45ada..6108409 100644 --- a/KREngine/KREngine/Classes/KRAABB.h +++ b/KREngine/KREngine/Classes/KRAABB.h @@ -46,6 +46,7 @@ public: static KRAABB Infinite(); float coverage(const KRMat4 &matVP, const KRVector2 viewportSize) const; + float longest_radius() const; }; diff --git a/KREngine/KREngine/Classes/KRInstance.cpp b/KREngine/KREngine/Classes/KRInstance.cpp index c07e028..ea9b6cd 100644 --- a/KREngine/KREngine/Classes/KRInstance.cpp +++ b/KREngine/KREngine/Classes/KRInstance.cpp @@ -33,14 +33,16 @@ #import "KRInstance.h" #import "KRContext.h" #import "KRModel.h" +#import "KRQuaternion.h" #include -KRInstance::KRInstance(KRScene &scene, std::string instance_name, std::string model_name, std::string light_map, float lod_min_coverage, bool receives_shadow) : KRNode(scene, instance_name) { +KRInstance::KRInstance(KRScene &scene, std::string instance_name, std::string model_name, std::string light_map, float lod_min_coverage, bool receives_shadow, bool faces_camera) : KRNode(scene, instance_name) { m_lightMap = light_map; m_pLightMap = NULL; m_model_name = model_name; m_min_lod_coverage = lod_min_coverage; m_receivesShadow = receives_shadow; + m_faces_camera = faces_camera; } KRInstance::~KRInstance() { @@ -58,6 +60,7 @@ tinyxml2::XMLElement *KRInstance::saveXML( tinyxml2::XMLNode *parent) e->SetAttribute("light_map", m_lightMap.c_str()); e->SetAttribute("lod_min_coverage", m_min_lod_coverage); e->SetAttribute("receives_shadow", m_receivesShadow ? "true" : "false"); + e->SetAttribute("faces_camera", m_faces_camera ? "true" : "false"); return e; } @@ -67,9 +70,6 @@ void KRInstance::loadModel() { if(m_models.size() > 0) { getScene().notify_sceneGraphModify(this); } -// if(m_pModel == NULL) { -// fprintf(stderr, "KREngine - Model not found: %s\n", m_model_name.c_str()); -// } } } @@ -110,7 +110,14 @@ void KRInstance::render(KRCamera *pCamera, std::vector &lights, const m_pContext->getTextureManager()->selectTexture(5, m_pLightMap); } - pModel->render(pCamera, lights, viewport, getModelMatrix(), m_pLightMap, renderPass); + KRMat4 matModel = getModelMatrix(); + if(m_faces_camera) { + KRVector3 model_center = KRMat4::Dot(matModel, KRVector3::Zero()); + KRVector3 camera_pos = viewport.getCameraPosition(); + matModel = KRQuaternion(KRVector3::Forward(), KRVector3::Normalize(camera_pos - model_center)).rotationMatrix() * matModel; + } + + pModel->render(pCamera, lights, viewport, matModel, m_pLightMap, renderPass); } } } @@ -129,7 +136,13 @@ bool KRInstance::hasTransparency() { KRAABB KRInstance::getBounds() { loadModel(); if(m_models.size() > 0) { - return KRAABB(m_models[0]->getMinPoint(), m_models[0]->getMaxPoint(), getModelMatrix()); + if(m_faces_camera) { + KRAABB normal_bounds = KRAABB(m_models[0]->getMinPoint(), m_models[0]->getMaxPoint(), getModelMatrix()); + float max_dimension = normal_bounds.longest_radius(); + return KRAABB(normal_bounds.center()-KRVector3(max_dimension), normal_bounds.center() + KRVector3(max_dimension)); + } else { + return KRAABB(m_models[0]->getMinPoint(), m_models[0]->getMaxPoint(), getModelMatrix()); + } } else { return KRAABB::Infinite(); } diff --git a/KREngine/KREngine/Classes/KRInstance.h b/KREngine/KREngine/Classes/KRInstance.h index 65ccecf..0b80c7e 100644 --- a/KREngine/KREngine/Classes/KRInstance.h +++ b/KREngine/KREngine/Classes/KRInstance.h @@ -50,7 +50,7 @@ class KRInstance : public KRNode { public: - KRInstance(KRScene &scene, std::string instance_name, std::string model_name, std::string light_map, float lod_min_coverage, bool receives_shadow); + KRInstance(KRScene &scene, std::string instance_name, std::string model_name, std::string light_map, float lod_min_coverage, bool receives_shadow, bool faces_camera); virtual ~KRInstance(); virtual std::string getElementName(); @@ -77,6 +77,7 @@ private: void loadModel(); bool m_receivesShadow; + bool m_faces_camera; }; diff --git a/KREngine/KREngine/Classes/KRLight.cpp b/KREngine/KREngine/Classes/KRLight.cpp index cfc7ee8..0e63e5a 100644 --- a/KREngine/KREngine/Classes/KRLight.cpp +++ b/KREngine/KREngine/Classes/KRLight.cpp @@ -191,7 +191,7 @@ void KRLight::render(KRCamera *pCamera, std::vector &lights, const KR std::vector this_light; this_light.push_back(this); - KRShader *pParticleShader = m_pContext->getShaderManager()->getShader("particle", pCamera, this_light, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); + KRShader *pParticleShader = m_pContext->getShaderManager()->getShader("dust_particle", pCamera, this_light, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); if(getContext().getShaderManager()->selectShader(*pCamera, pParticleShader, viewport, particleModelMatrix, this_light, renderPass)) { diff --git a/KREngine/KREngine/Classes/KRNode.cpp b/KREngine/KREngine/Classes/KRNode.cpp index b76d529..a89e876 100644 --- a/KREngine/KREngine/Classes/KRNode.cpp +++ b/KREngine/KREngine/Classes/KRNode.cpp @@ -16,7 +16,7 @@ #import "KRDirectionalLight.h" #import "KRInstance.h" #import "KRParticleSystem.h" -#import "KRParticleSystemBrownian.h" +#import "KRParticleSystemNewtonian.h" #import "KRAABB.h" #import "KRQuaternion.h" @@ -53,7 +53,7 @@ tinyxml2::XMLElement *KRNode::saveXML(tinyxml2::XMLNode *parent) { tinyxml2::XMLElement *e = doc->NewElement(getElementName().c_str()); tinyxml2::XMLNode *n = parent->InsertEndChild(e); e->SetAttribute("name", m_name.c_str()); - e->SetAttribute("translate_x", m_localTranslation.x); + e->SetAttribute("translate_x", m_localTranslation.x); // TODO - Increase number of digits after the decimal in floating point format (6 -> 12?) e->SetAttribute("translate_y", m_localTranslation.y); e->SetAttribute("translate_z", m_localTranslation.z); e->SetAttribute("scale_x", m_localScale.x); @@ -145,8 +145,8 @@ KRNode *KRNode::LoadXML(KRScene &scene, tinyxml2::XMLElement *e) { new_node = new KRDirectionalLight(scene, szName); } else if(strcmp(szElementName, "spot_light") == 0) { new_node = new KRSpotLight(scene, szName); - } else if(strcmp(szElementName, "brownian_particles") == 0) { - new_node = new KRParticleSystemBrownian(scene, szName); + } else if(strcmp(szElementName, "particles_newtonian") == 0) { + new_node = new KRParticleSystemNewtonian(scene, szName); } else if(strcmp(szElementName, "mesh") == 0) { float lod_min_coverage = 0.0f; if(e->QueryFloatAttribute("lod_min_coverage", &lod_min_coverage) != tinyxml2::XML_SUCCESS) { @@ -156,7 +156,11 @@ KRNode *KRNode::LoadXML(KRScene &scene, tinyxml2::XMLElement *e) { if(e->QueryBoolAttribute("receives_shadow", &receives_shadow) != tinyxml2::XML_SUCCESS) { receives_shadow = true; } - new_node = new KRInstance(scene, szName, szName, e->Attribute("light_map"), lod_min_coverage, receives_shadow); + bool faces_camera = false; + if(e->QueryBoolAttribute("faces_camera", &faces_camera) != tinyxml2::XML_SUCCESS) { + faces_camera = false; + } + new_node = new KRInstance(scene, szName, szName, e->Attribute("light_map"), lod_min_coverage, receives_shadow, faces_camera); } if(new_node) { @@ -203,14 +207,24 @@ const KRMat4 &KRNode::getModelMatrix() { if(!m_modelMatrixValid) { + m_modelMatrix = KRMat4(); if(m_parentNode) { - m_modelMatrix = m_parentNode->getModelMatrix(); - } else { - m_modelMatrix = KRMat4(); + m_modelMatrix *= m_parentNode->getModelMatrix(); } - m_modelMatrix.scale(m_localScale); - m_modelMatrix.rotate(KRQuaternion(m_localRotation)); m_modelMatrix.translate(m_localTranslation); + m_modelMatrix.rotate(KRQuaternion(m_localRotation)); + m_modelMatrix.scale(m_localScale); + +// m_modelMatrix = KRMat4(); +// +// m_modelMatrix.scale(m_localScale); +// m_modelMatrix.rotate(KRQuaternion(m_localRotation)); +// m_modelMatrix.translate(m_localTranslation); +// +// if(m_parentNode) { +// m_modelMatrix *= m_parentNode->getModelMatrix(); +// } + m_modelMatrixValid = true; } diff --git a/KREngine/KREngine/Classes/KRParticleSystemBrownian.cpp b/KREngine/KREngine/Classes/KRParticleSystemNewtonian.cpp similarity index 80% rename from KREngine/KREngine/Classes/KRParticleSystemBrownian.cpp rename to KREngine/KREngine/Classes/KRParticleSystemNewtonian.cpp index 024a6f0..755cb77 100644 --- a/KREngine/KREngine/Classes/KRParticleSystemBrownian.cpp +++ b/KREngine/KREngine/Classes/KRParticleSystemNewtonian.cpp @@ -1,49 +1,49 @@ // -// KRParticleSystemBrownian.cpp +// KRParticleSystemNewtonian.cpp // KREngine // // Created by Kearwood Gilbert on 2012-11-02. // Copyright (c) 2012 Kearwood Software. All rights reserved. // -#include "KRParticleSystemBrownian.h" +#include "KRParticleSystemNewtonian.h" #include "KRAABB.h" #include "KRTexture.h" #include "KRContext.h" -KRParticleSystemBrownian::KRParticleSystemBrownian(KRScene &scene, std::string name) : KRParticleSystem(scene, name) +KRParticleSystemNewtonian::KRParticleSystemNewtonian(KRScene &scene, std::string name) : KRParticleSystem(scene, name) { m_particlesAbsoluteTime = 0.0f; } -KRParticleSystemBrownian::~KRParticleSystemBrownian() +KRParticleSystemNewtonian::~KRParticleSystemNewtonian() { } -std::string KRParticleSystemBrownian::getElementName() +std::string KRParticleSystemNewtonian::getElementName() { - return "brownian_particles"; + return "newtonian_particles"; } -void KRParticleSystemBrownian::loadXML(tinyxml2::XMLElement *e) +void KRParticleSystemNewtonian::loadXML(tinyxml2::XMLElement *e) { KRParticleSystem::loadXML(e); } -tinyxml2::XMLElement *KRParticleSystemBrownian::saveXML( tinyxml2::XMLNode *parent) +tinyxml2::XMLElement *KRParticleSystemNewtonian::saveXML( tinyxml2::XMLNode *parent) { tinyxml2::XMLElement *e = KRParticleSystem::saveXML(parent); return e; } -KRAABB KRParticleSystemBrownian::getBounds() +KRAABB KRParticleSystemNewtonian::getBounds() { return KRAABB(-KRVector3::One(), KRVector3::One(), getModelMatrix()); } -void KRParticleSystemBrownian::physicsUpdate(float deltaTime) +void KRParticleSystemNewtonian::physicsUpdate(float deltaTime) { KRParticleSystem::physicsUpdate(deltaTime); m_particlesAbsoluteTime += deltaTime; @@ -52,7 +52,7 @@ void KRParticleSystemBrownian::physicsUpdate(float deltaTime) #if TARGET_OS_IPHONE -void KRParticleSystemBrownian::render(KRCamera *pCamera, std::vector &lights, const KRViewport &viewport, KRNode::RenderPass renderPass) { +void KRParticleSystemNewtonian::render(KRCamera *pCamera, std::vector &lights, const KRViewport &viewport, KRNode::RenderPass renderPass) { KRNode::render(pCamera, lights, viewport, renderPass); @@ -71,7 +71,7 @@ void KRParticleSystemBrownian::render(KRCamera *pCamera, std::vector int particle_count = 10000; - KRShader *pParticleShader = m_pContext->getShaderManager()->getShader("particle", pCamera, lights, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); + KRShader *pParticleShader = m_pContext->getShaderManager()->getShader("dust_particle", pCamera, lights, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); if(getContext().getShaderManager()->selectShader(*pCamera, pParticleShader, viewport, getModelMatrix(), lights, renderPass)) { GLDEBUG(glUniform1f( diff --git a/KREngine/KREngine/Classes/KRParticleSystemBrownian.h b/KREngine/KREngine/Classes/KRParticleSystemNewtonian.h similarity index 71% rename from KREngine/KREngine/Classes/KRParticleSystemBrownian.h rename to KREngine/KREngine/Classes/KRParticleSystemNewtonian.h index 7aed5fa..cf1472f 100644 --- a/KREngine/KREngine/Classes/KRParticleSystemBrownian.h +++ b/KREngine/KREngine/Classes/KRParticleSystemNewtonian.h @@ -1,20 +1,20 @@ // -// KRParticleSystemBrownian.h +// KRParticleSystemNewtonian.h // KREngine // // Created by Kearwood Gilbert on 2012-11-02. // Copyright (c) 2012 Kearwood Software. All rights reserved. // -#ifndef KRPARTICLESYSTEMBROWNIAN_H -#define KRPARTICLESYSTEMBROWNIAN_H +#ifndef KRPARTICLESYSTEMNEWTONIAN_H +#define KRPARTICLESYSTEMNEWTONIAN_H #import "KRParticleSystem.h" -class KRParticleSystemBrownian : public KRParticleSystem { +class KRParticleSystemNewtonian : public KRParticleSystem { public: - KRParticleSystemBrownian(KRScene &scene, std::string name); - virtual ~KRParticleSystemBrownian(); + KRParticleSystemNewtonian(KRScene &scene, std::string name); + virtual ~KRParticleSystemNewtonian(); virtual std::string getElementName(); virtual void loadXML(tinyxml2::XMLElement *e); diff --git a/KREngine/KREngine/Classes/KRQuaternion.cpp b/KREngine/KREngine/Classes/KRQuaternion.cpp index 60e935c..8a383bc 100644 --- a/KREngine/KREngine/Classes/KRQuaternion.cpp +++ b/KREngine/KREngine/Classes/KRQuaternion.cpp @@ -65,6 +65,16 @@ KRQuaternion::KRQuaternion(const KRVector3 &euler) { setEuler(euler); } +KRQuaternion::KRQuaternion(const KRVector3 &from_vector, const KRVector3 &to_vector) { + + KRVector3 a = KRVector3::Cross(from_vector, to_vector); + m_val[0] = a[0]; + m_val[1] = a[1]; + m_val[2] = a[2]; + m_val[3] = sqrt(from_vector.sqrMagnitude() * to_vector.sqrMagnitude()) + KRVector3::Dot(from_vector, to_vector); + normalize(); +} + KRQuaternion::~KRQuaternion() { } diff --git a/KREngine/KREngine/Classes/KRQuaternion.h b/KREngine/KREngine/Classes/KRQuaternion.h index a68f732..3e3670e 100644 --- a/KREngine/KREngine/Classes/KRQuaternion.h +++ b/KREngine/KREngine/Classes/KRQuaternion.h @@ -44,6 +44,7 @@ public: KRQuaternion(float w, float x, float y, float z); KRQuaternion(const KRQuaternion& p); KRQuaternion(const KRVector3 &euler); + KRQuaternion(const KRVector3 &from_vector, const KRVector3 &to_vector); ~KRQuaternion(); KRQuaternion& operator =( const KRQuaternion& p ); diff --git a/KREngine/KREngine/Classes/KRResource+fbx.cpp b/KREngine/KREngine/Classes/KRResource+fbx.cpp index bc25931..45f3af2 100644 --- a/KREngine/KREngine/Classes/KRResource+fbx.cpp +++ b/KREngine/KREngine/Classes/KRResource+fbx.cpp @@ -30,6 +30,7 @@ #include "KRSpotLight.h" #include "KRNode.h" #include "KRScene.h" +#include "KRQuaternion.h" #ifdef IOS_REF #undef IOS_REF @@ -40,11 +41,15 @@ void InitializeSdkObjects(KFbxSdkManager*& pSdkManager, KFbxScene*& pScene); void DestroySdkObjects(KFbxSdkManager* pSdkManager); bool LoadScene(KFbxSdkManager* pSdkManager, KFbxDocument* pScene, const char* pFilename); void LoadNode(KRNode *parent_node, std::vector &resources, KFbxGeometryConverter *pGeometryConverter, KFbxNode* pNode); +void BakeNode(KFbxNode* pNode); KRNode *LoadMesh(KRNode *parent_node, std::vector &resources, KFbxGeometryConverter *pGeometryConverter, KFbxNode* pNode); KRNode *LoadLight(KRNode *parent_node, std::vector &resources, KFbxNode* pNode); +const float KRAKEN_FBX_ANIMATION_FRAMERATE = 30.0f; // FINDME - This should be configurable + std::vector KRResource::LoadFbx(KRContext &context, const std::string& path) { + std::vector resources; KRScene *pScene = new KRScene(context, KRResource::GetFileBase(path)); resources.push_back(pScene); @@ -163,49 +168,52 @@ bool LoadScene(KFbxSdkManager* pSdkManager, KFbxDocument* pScene, const char* pF printf("FBX version number for this FBX SDK is %d.%d.%d\n", lSDKMajor, lSDKMinor, lSDKRevision); - if (lImporter->IsFBX()) - { - printf("FBX version number for file %s is %d.%d.%d\n\n", pFilename, lFileMajor, lFileMinor, lFileRevision); - - // From this point, it is possible to access animation stack information without - // the expense of loading the entire file. - - printf("Animation Stack Information\n"); - - lAnimStackCount = lImporter->GetAnimStackCount(); - - printf(" Number of Animation Stacks: %d\n", lAnimStackCount); - printf(" Current Animation Stack: \"%s\"\n", lImporter->GetActiveAnimStackName().Buffer()); - printf("\n"); - - for(i = 0; i < lAnimStackCount; i++) - { - KFbxTakeInfo* lTakeInfo = lImporter->GetTakeInfo(i); - - printf(" Animation Stack %d\n", i); - printf(" Name: \"%s\"\n", lTakeInfo->mName.Buffer()); - printf(" Description: \"%s\"\n", lTakeInfo->mDescription.Buffer()); - - // Change the value of the import name if the animation stack should be imported - // under a different name. - printf(" Import Name: \"%s\"\n", lTakeInfo->mImportName.Buffer()); - - // Set the value of the import state to false if the animation stack should be not - // be imported. - printf(" Import State: %s\n", lTakeInfo->mSelect ? "true" : "false"); - printf("\n"); - } - - // Set the import states. By default, the import states are always set to - // true. The code below shows how to change these states. - IOS_REF.SetBoolProp(IMP_FBX_MATERIAL, true); - IOS_REF.SetBoolProp(IMP_FBX_TEXTURE, true); - IOS_REF.SetBoolProp(IMP_FBX_LINK, true); - IOS_REF.SetBoolProp(IMP_FBX_SHAPE, true); - IOS_REF.SetBoolProp(IMP_FBX_GOBO, true); - IOS_REF.SetBoolProp(IMP_FBX_ANIMATION, true); - IOS_REF.SetBoolProp(IMP_FBX_GLOBAL_SETTINGS, true); + if(!lImporter->IsFBX()) { + printf("ERROR Unrecognized FBX File\n"); + return false; } + + + printf("FBX version number for file %s is %d.%d.%d\n\n", pFilename, lFileMajor, lFileMinor, lFileRevision); + + // From this point, it is possible to access animation stack information without + // the expense of loading the entire file. + + printf("Animation Stack Information\n"); + + lAnimStackCount = lImporter->GetAnimStackCount(); + + printf(" Number of Animation Stacks: %d\n", lAnimStackCount); + printf(" Current Animation Stack: \"%s\"\n", lImporter->GetActiveAnimStackName().Buffer()); + printf("\n"); + + for(i = 0; i < lAnimStackCount; i++) + { + KFbxTakeInfo* lTakeInfo = lImporter->GetTakeInfo(i); + + printf(" Animation Stack %d\n", i); + printf(" Name: \"%s\"\n", lTakeInfo->mName.Buffer()); + printf(" Description: \"%s\"\n", lTakeInfo->mDescription.Buffer()); + + // Change the value of the import name if the animation stack should be imported + // under a different name. + printf(" Import Name: \"%s\"\n", lTakeInfo->mImportName.Buffer()); + + // Set the value of the import state to false if the animation stack should be not + // be imported. + printf(" Import State: %s\n", lTakeInfo->mSelect ? "true" : "false"); + printf("\n"); + } + + // Set the import states. By default, the import states are always set to + // true. The code below shows how to change these states. + IOS_REF.SetBoolProp(IMP_FBX_MATERIAL, true); + IOS_REF.SetBoolProp(IMP_FBX_TEXTURE, true); + IOS_REF.SetBoolProp(IMP_FBX_LINK, true); + IOS_REF.SetBoolProp(IMP_FBX_SHAPE, true); + IOS_REF.SetBoolProp(IMP_FBX_GOBO, true); + IOS_REF.SetBoolProp(IMP_FBX_ANIMATION, true); + IOS_REF.SetBoolProp(IMP_FBX_GLOBAL_SETTINGS, true); // Import the scene. lStatus = lImporter->Import(pScene); @@ -230,24 +238,110 @@ bool LoadScene(KFbxSdkManager* pSdkManager, KFbxDocument* pScene, const char* pF } } + // ----====---- Start: Bake pivots into transforms, as Kraken doesn't support them directly ----====---- + + printf("Baking pivots...\n"); + KFbxNode* pNode = ((KFbxScene*)pScene)->GetRootNode(); +// BakeNode(pNode); + + for(i = 0; i < lAnimStackCount; i++) + { + KFbxTakeInfo* lTakeInfo = lImporter->GetTakeInfo(i); + + printf(" Animation: \"%s\"\n", lTakeInfo->mName.Buffer()); +// pNode->ConvertPivotAnimationRecursive(lTakeInfo->mName.Buffer(), KFbxNode::eDESTINATION_SET, KRAKEN_FBX_ANIMATION_FRAMERATE); + pNode->ResetPivotSetAndConvertAnimation(); + pNode->UpdatePropertiesFromPivotsAndLimits(); + } + + // ----====---- End: Bake pivots into transforms, as Kraken doesn't support them directly ----====---- + // Destroy the importer. lImporter->Destroy(); return lStatus; } +void BakeNode(KFbxNode *pNode) { + pNode->SetPivotState(KFbxNode::eSOURCE_SET, KFbxNode::ePIVOT_STATE_ACTIVE); + pNode->SetPivotState(KFbxNode::eDESTINATION_SET, KFbxNode::ePIVOT_STATE_ACTIVE); + + // Pass the current value to the source pivot. +// * - Rotation offset (Roff) +// * - Rotation pivot (Rp) +// * - Pre-rotation (Rpre) +// * - Post-rotation (Rpost) +// * - Scaling offset (Soff) +// * - Scaling pivot (Sp) +// * - Geometric translation (Gt) +// * - Geometric rotation (Gr) +// * - Geometric scaling (Gs) + pNode->SetPostRotation(KFbxNode::eSOURCE_SET, pNode->PostRotation.Get()); + pNode->SetPreRotation(KFbxNode::eSOURCE_SET, pNode->PreRotation.Get()); + pNode->SetRotationOffset(KFbxNode::eSOURCE_SET, pNode->RotationOffset.Get()); + pNode->SetScalingOffset(KFbxNode::eSOURCE_SET, pNode->ScalingOffset.Get()); + pNode->SetRotationPivot(KFbxNode::eSOURCE_SET, pNode->RotationPivot.Get()); + pNode->SetScalingPivot(KFbxNode::eSOURCE_SET, pNode->ScalingPivot.Get()); + pNode->SetGeometricRotation(KFbxNode::eSOURCE_SET, pNode->GeometricRotation.Get()); + pNode->SetGeometricTranslation(KFbxNode::eSOURCE_SET, pNode->GeometricTranslation.Get()); + pNode->SetGeometricScaling(KFbxNode::eSOURCE_SET, pNode->GeometricScaling.Get()); + pNode->SetRotationOrder(KFbxNode::eSOURCE_SET, pNode->RotationOrder.Get()); + + // We want to set all these to 0 and bake them into the transforms. + KFbxVector4 lZero(0, 0, 0); + KFbxVector4 lOne(1.0, 1.0, 1.0); + pNode->SetPostRotation(KFbxNode::eDESTINATION_SET, lZero); + pNode->SetPreRotation(KFbxNode::eDESTINATION_SET, lZero); + pNode->SetRotationOffset(KFbxNode::eDESTINATION_SET, lZero); + pNode->SetScalingOffset(KFbxNode::eDESTINATION_SET, lZero); + pNode->SetRotationPivot(KFbxNode::eDESTINATION_SET, lZero); + pNode->SetScalingPivot(KFbxNode::eDESTINATION_SET, lZero); + pNode->SetGeometricRotation(KFbxNode::eDESTINATION_SET, lZero); + pNode->SetGeometricTranslation(KFbxNode::eDESTINATION_SET, lZero); + pNode->SetGeometricScaling(KFbxNode::eDESTINATION_SET, lOne); + pNode->SetRotationOrder(KFbxNode::eDESTINATION_SET, eEULER_XYZ); + + // Bake child nodes + for(int i = 0; i < pNode->GetChildCount(); i++) + { + BakeNode(pNode->GetChild(i)); + } +} + void LoadNode(KRNode *parent_node, std::vector &resources, KFbxGeometryConverter *pGeometryConverter, KFbxNode* pNode) { KFbxVector4 lTmpVector; - - + pNode->UpdatePropertiesFromPivotsAndLimits(); + // Transform = T * Roff * Rp * Rpre * R * Rpost * inverse(Rp) * Soff * Sp * S * inverse(Sp) fbxDouble3 local_rotation = pNode->LclRotation.Get(); // pNode->GetGeometricRotation(KFbxNode::eSOURCE_SET); fbxDouble3 local_translation = pNode->LclTranslation.Get(); // pNode->GetGeometricTranslation(KFbxNode::eSOURCE_SET); fbxDouble3 local_scale = pNode->LclScaling.Get(); // pNode->GetGeometricScaling(KFbxNode::eSOURCE_SET); - printf(" Translation: %f %f %f\n", local_translation[0], local_translation[1], local_translation[2]); - printf(" Rotation: %f %f %f\n", local_rotation[0], local_rotation[1], local_rotation[2]); - printf(" Scaling: %f %f %f\n", local_scale[0], local_scale[1], local_scale[2]); +// fbxDouble3 post_rotation = pNode->PostRotation.Get(); +// fbxDouble3 pre_rotation = pNode->PreRotation.Get(); +// fbxDouble3 rotation_offset = pNode->RotationOffset.Get(); +// fbxDouble3 scaling_offset = pNode->ScalingOffset.Get(); +// fbxDouble3 rotation_pivot = pNode->RotationPivot.Get(); +// fbxDouble3 scaling_pivot = pNode->ScalingPivot.Get(); +// fbxDouble3 geometric_rotation = pNode->GeometricRotation.Get(); +// fbxDouble3 geometric_translation = pNode->GeometricTranslation.Get(); +// fbxDouble3 geometric_scaling = pNode->GeometricScaling.Get(); +// ERotationOrder rotation_order = pNode->RotationOrder.Get(); +// +// bool rotation_active = pNode->RotationActive.Get(); +// KRVector3 node_translation = KRVector3(local_translation[0] + rotation_offset[0] + rotation_pivot[0], local_translation[1] + rotation_offset[1] + rotation_pivot[1], local_translation[2] + rotation_offset[2] + rotation_pivot[2]); // T * Roff * Rp + KRVector3 node_translation = KRVector3(local_translation[0], local_translation[1], local_translation[2]); // T * Roff * Rp + + KRVector3 node_rotation = KRQuaternion(KRVector3(local_rotation[0], local_rotation[1], local_rotation[2]) / 180.0 * M_PI).euler(); // R +// if(rotation_active) { +// node_rotation = (KRQuaternion(KRVector3(post_rotation[0], post_rotation[1], post_rotation[2]) / 180.0 * M_PI) * KRQuaternion(KRVector3(local_rotation[0], local_rotation[1], local_rotation[2]) / 180.0 * M_PI) * KRQuaternion(KRVector3(pre_rotation[0], pre_rotation[1], pre_rotation[2]) / 180.0 * M_PI)).euler(); // Rpre * R * Rpost +// } + + KRVector3 node_scale = KRVector3(local_scale[0], local_scale[1], local_scale[2]); + + printf(" Local Translation: %f %f %f\n", local_translation[0], local_translation[1], local_translation[2]); + printf(" Local Rotation: %f %f %f\n", local_rotation[0], local_rotation[1], local_rotation[2]); + printf(" Local Scaling: %f %f %f\n", local_scale[0], local_scale[1], local_scale[2]); KRNode *new_node = NULL; @@ -271,9 +365,9 @@ void LoadNode(KRNode *parent_node, std::vector &resources, KFbxGeo if(new_node != NULL) { - new_node->setLocalRotation(KRVector3(local_rotation[0], local_rotation[1], local_rotation[2]) / 180.0 * M_PI); - new_node->setLocalTranslation(KRVector3(local_translation[0], local_translation[1], local_translation[2])); - new_node->setLocalScale(KRVector3(local_scale[0], local_scale[1], local_scale[2])); + new_node->setLocalRotation(node_rotation); + new_node->setLocalTranslation(node_translation); + new_node->setLocalScale(node_scale); parent_node->addChild(new_node); // Load child nodes @@ -615,17 +709,7 @@ KRNode *LoadLight(KRNode *parent_node, std::vector &resources, KFb // KFbxLight::eNONE - does not attenuate with distance // KFbxLight::eLINEAR - attenuation of 1/d // KFbxLight::eQUADRATIC - attenuation of 1/d^2 -// KFbxLight::eCUBIC - attenuation of - - KFbxVector4 v4; // Default translation values - v4 = pNode->LclTranslation.Get(); - - //KFbxVector4 light_translation = pNode->GetGeometricTranslation(KFbxNode::eSOURCE_SET); - //KFbxVector4 light_rotation = pNode->GetGeometricRotation(KFbxNode::eSOURCE_SET); - //KFbxVector4 light_scaling = pNode->GetGeometricScaling(KFbxNode::eSOURCE_SET); - - - //KRVector3 translation = KRVector3(light_translation[0], light_translation[1], light_translation[2]); +// KFbxLight::eCUBIC - attenuation of KRLight *new_light = NULL; diff --git a/KREngine/KREngine/Shaders/particle.fsh b/KREngine/KREngine/Shaders/dust_particle.fsh similarity index 88% rename from KREngine/KREngine/Shaders/particle.fsh rename to KREngine/KREngine/Shaders/dust_particle.fsh index fdb0654..468a31e 100644 --- a/KREngine/KREngine/Shaders/particle.fsh +++ b/KREngine/KREngine/Shaders/dust_particle.fsh @@ -1,5 +1,5 @@ // -// particle.fsh +// dust_particle.fsh // KREngine // // Copyright 2012 Kearwood Gilbert. All rights reserved. @@ -39,10 +39,5 @@ uniform mediump vec3 light_color; varying lowp float intensity_modulate; void main() { - //gl_FragColor = vec4(vec3(texture2D(diffuseTexture, texCoord)), 1.0); -// gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); gl_FragColor = vec4(light_color, 1.0) * shadow2DProjEXT(shadowTexture1, shadowMapCoord1) * max(1.0 - texCoord.x*texCoord.x-texCoord.y*texCoord.y, 0.0) * intensity_modulate; -// gl_FragColor.rgb = shadowMapCoord1.xyz / shadowMapCoord1.w; -// gl_FragColor.a = 1.0; -// gl_FragColor.b = 1.0; } \ No newline at end of file diff --git a/KREngine/KREngine/Shaders/particle.vsh b/KREngine/KREngine/Shaders/dust_particle.vsh similarity index 96% rename from KREngine/KREngine/Shaders/particle.vsh rename to KREngine/KREngine/Shaders/dust_particle.vsh index 29db6d0..c49fb87 100644 --- a/KREngine/KREngine/Shaders/particle.vsh +++ b/KREngine/KREngine/Shaders/dust_particle.vsh @@ -1,5 +1,5 @@ // -// particle.vsh +// dust_particle.vsh // KREngine // // Copyright 2012 Kearwood Gilbert. All rights reserved. @@ -44,7 +44,6 @@ uniform highp float time_absolute; varying lowp float intensity_modulate; void main() { -// highp vec4 particle_center = mvp_matrix * (mod(vertex_position - vec4(particle_origin, 0.0), 2.0) - 1.0); highp vec4 offset_center = vertex_position + vec4(particle_origin, 0.0); offset_center.xyz += vec3(sin((time_absolute + vertex_position.x * 100.0) * 0.05), sin((time_absolute + vertex_position.y * 100.0) * 0.07), sin((time_absolute + vertex_position.z * 100.0) * 0.03)) * 0.05; offset_center = vec4(mod(offset_center.x + 1.0, 2.0) - 1.0, mod(offset_center.y + 1.0, 2.0) - 1.0, mod(offset_center.z + 1.0, 2.0) - 1.0, 1.0);