From c7948ea314ba23b6b1a81289eee0208c8306ffa4 Mon Sep 17 00:00:00 2001 From: Kearwood Gilbert Date: Tue, 3 Dec 2013 01:15:17 -0800 Subject: [PATCH] KRSprite objects now have their own shader, rather than sharing the "Flare" shader. Implemented per-sprite alpha. --HG-- branch : nfb --- KREngine/Kraken.xcodeproj/project.pbxproj | 40 +++++++++++------- KREngine/kraken/KRLight.cpp | 1 + KREngine/kraken/KRMeshQuad.cpp | 22 ++++------ KREngine/kraken/KRNode.cpp | 7 +++- KREngine/kraken/KRNode.h | 11 +++++ KREngine/kraken/KRSprite.cpp | 24 +++++++++-- KREngine/kraken/KRSprite.h | 3 ++ .../Shaders/flare.fsh | 13 +++--- .../Shaders/flare.vsh | 10 ++--- .../Shaders/sprite.fsh | 38 +++++++++++++++++ .../Shaders/sprite.vsh | 42 +++++++++++++++++++ .../Shaders/flare_osx.fsh | 13 +++--- .../Shaders/flare_osx.vsh | 10 ++--- .../Shaders/sprite_osx.fsh | 38 +++++++++++++++++ .../Shaders/sprite_osx.vsh | 42 +++++++++++++++++++ 15 files changed, 257 insertions(+), 57 deletions(-) create mode 100644 KREngine/kraken_standard_assets_ios/Shaders/sprite.fsh create mode 100644 KREngine/kraken_standard_assets_ios/Shaders/sprite.vsh create mode 100644 KREngine/kraken_standard_assets_osx/Shaders/sprite_osx.fsh create mode 100644 KREngine/kraken_standard_assets_osx/Shaders/sprite_osx.vsh diff --git a/KREngine/Kraken.xcodeproj/project.pbxproj b/KREngine/Kraken.xcodeproj/project.pbxproj index f66c598..eef1240 100644 --- a/KREngine/Kraken.xcodeproj/project.pbxproj +++ b/KREngine/Kraken.xcodeproj/project.pbxproj @@ -291,8 +291,8 @@ E4E6F68716BA5DF700E410F8 /* debug_font.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F64B16BA5D9400E410F8 /* debug_font.vsh */; }; E4E6F68816BA5DF700E410F8 /* dust_particle.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F64C16BA5D9400E410F8 /* dust_particle.fsh */; }; E4E6F68916BA5DF700E410F8 /* dust_particle.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F64D16BA5D9400E410F8 /* dust_particle.vsh */; }; - E4E6F68A16BA5DF700E410F8 /* flare.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F64E16BA5D9400E410F8 /* flare.fsh */; }; - E4E6F68B16BA5DF700E410F8 /* flare.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F64F16BA5D9400E410F8 /* flare.vsh */; }; + E4E6F68A16BA5DF700E410F8 /* sprite.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F64E16BA5D9400E410F8 /* sprite.fsh */; }; + E4E6F68B16BA5DF700E410F8 /* sprite.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F64F16BA5D9400E410F8 /* sprite.vsh */; }; E4E6F68C16BA5DF700E410F8 /* light_directional.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F65016BA5D9400E410F8 /* light_directional.fsh */; }; E4E6F68D16BA5DF700E410F8 /* light_directional.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F65116BA5D9400E410F8 /* light_directional.vsh */; }; E4E6F68E16BA5DF700E410F8 /* light_point_inside.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F65216BA5D9400E410F8 /* light_point_inside.fsh */; }; @@ -323,8 +323,8 @@ E4E6F6A716BA5E0A00E410F8 /* debug_font_osx.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F61116BA5D8300E410F8 /* debug_font_osx.vsh */; }; E4E6F6A816BA5E0A00E410F8 /* dust_particle_osx.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F61216BA5D8300E410F8 /* dust_particle_osx.fsh */; }; E4E6F6A916BA5E0A00E410F8 /* dust_particle_osx.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F61316BA5D8300E410F8 /* dust_particle_osx.vsh */; }; - E4E6F6AA16BA5E0A00E410F8 /* flare_osx.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F61416BA5D8300E410F8 /* flare_osx.fsh */; }; - E4E6F6AB16BA5E0A00E410F8 /* flare_osx.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F61516BA5D8300E410F8 /* flare_osx.vsh */; }; + E4E6F6AA16BA5E0A00E410F8 /* sprite_osx.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F61416BA5D8300E410F8 /* sprite_osx.fsh */; }; + E4E6F6AB16BA5E0A00E410F8 /* sprite_osx.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F61516BA5D8300E410F8 /* sprite_osx.vsh */; }; E4E6F6AC16BA5E0A00E410F8 /* light_directional_osx.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F61616BA5D8300E410F8 /* light_directional_osx.fsh */; }; E4E6F6AD16BA5E0A00E410F8 /* light_directional_osx.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F61716BA5D8300E410F8 /* light_directional_osx.vsh */; }; E4E6F6AE16BA5E0A00E410F8 /* light_point_inside_osx.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4E6F61816BA5D8300E410F8 /* light_point_inside_osx.fsh */; }; @@ -428,6 +428,10 @@ E41AE1DD16B124CA00980428 /* font.tga */ = {isa = PBXFileReference; lastKnownFileType = file; path = font.tga; sourceTree = ""; }; E41B6BA716BE436100B510EB /* CoreAudio.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreAudio.framework; path = System/Library/Frameworks/CoreAudio.framework; sourceTree = SDKROOT; }; E41B6BA916BE437800B510EB /* CoreAudio.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreAudio.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/CoreAudio.framework; sourceTree = DEVELOPER_DIR; }; + E42559AA184DD4490081BB20 /* flare.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = flare.fsh; sourceTree = ""; }; + E42559AC184DD45A0081BB20 /* flare.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = flare.vsh; sourceTree = ""; }; + E42559AE184DD4730081BB20 /* flare_osx.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = flare_osx.fsh; sourceTree = ""; }; + E42559B0184DD48B0081BB20 /* flare_osx.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = flare_osx.vsh; sourceTree = ""; }; E428C2F11669610500A16EDF /* KRAnimationManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRAnimationManager.h; sourceTree = ""; }; E428C2F41669611600A16EDF /* KRAnimationManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KRAnimationManager.cpp; sourceTree = ""; }; E428C2F71669612500A16EDF /* KRAnimation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRAnimation.h; sourceTree = ""; }; @@ -581,8 +585,8 @@ E4E6F61116BA5D8300E410F8 /* debug_font_osx.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = debug_font_osx.vsh; sourceTree = ""; }; E4E6F61216BA5D8300E410F8 /* dust_particle_osx.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = dust_particle_osx.fsh; sourceTree = ""; }; E4E6F61316BA5D8300E410F8 /* dust_particle_osx.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = dust_particle_osx.vsh; sourceTree = ""; }; - E4E6F61416BA5D8300E410F8 /* flare_osx.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = flare_osx.fsh; sourceTree = ""; }; - E4E6F61516BA5D8300E410F8 /* flare_osx.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = flare_osx.vsh; sourceTree = ""; }; + E4E6F61416BA5D8300E410F8 /* sprite_osx.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = sprite_osx.fsh; sourceTree = ""; }; + E4E6F61516BA5D8300E410F8 /* sprite_osx.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = sprite_osx.vsh; sourceTree = ""; }; E4E6F61616BA5D8300E410F8 /* light_directional_osx.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = light_directional_osx.fsh; sourceTree = ""; }; E4E6F61716BA5D8300E410F8 /* light_directional_osx.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = light_directional_osx.vsh; sourceTree = ""; }; E4E6F61816BA5D8300E410F8 /* light_point_inside_osx.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = light_point_inside_osx.fsh; sourceTree = ""; }; @@ -609,8 +613,8 @@ E4E6F64B16BA5D9400E410F8 /* debug_font.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = debug_font.vsh; sourceTree = ""; }; E4E6F64C16BA5D9400E410F8 /* dust_particle.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = dust_particle.fsh; sourceTree = ""; }; E4E6F64D16BA5D9400E410F8 /* dust_particle.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = dust_particle.vsh; sourceTree = ""; }; - E4E6F64E16BA5D9400E410F8 /* flare.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = flare.fsh; sourceTree = ""; }; - E4E6F64F16BA5D9400E410F8 /* flare.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = flare.vsh; sourceTree = ""; }; + E4E6F64E16BA5D9400E410F8 /* sprite.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = sprite.fsh; sourceTree = ""; }; + E4E6F64F16BA5D9400E410F8 /* sprite.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = sprite.vsh; sourceTree = ""; }; E4E6F65016BA5D9400E410F8 /* light_directional.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = light_directional.fsh; sourceTree = ""; }; E4E6F65116BA5D9400E410F8 /* light_directional.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = light_directional.vsh; sourceTree = ""; }; E4E6F65216BA5D9400E410F8 /* light_point_inside.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = light_point_inside.fsh; sourceTree = ""; }; @@ -734,8 +738,8 @@ E4E6F64B16BA5D9400E410F8 /* debug_font.vsh */, E4E6F64C16BA5D9400E410F8 /* dust_particle.fsh */, E4E6F64D16BA5D9400E410F8 /* dust_particle.vsh */, - E4E6F64E16BA5D9400E410F8 /* flare.fsh */, - E4E6F64F16BA5D9400E410F8 /* flare.vsh */, + E4E6F64E16BA5D9400E410F8 /* sprite.fsh */, + E4E6F64F16BA5D9400E410F8 /* sprite.vsh */, E4E6F65016BA5D9400E410F8 /* light_directional.fsh */, E4E6F65116BA5D9400E410F8 /* light_directional.vsh */, E4E6F65216BA5D9400E410F8 /* light_point_inside.fsh */, @@ -759,6 +763,8 @@ E4E6F66416BA5D9400E410F8 /* volumetric_fog_downsampled.vsh */, E4E6F66516BA5D9400E410F8 /* volumetric_fog.fsh */, E4E6F66616BA5D9400E410F8 /* volumetric_fog.vsh */, + E42559AA184DD4490081BB20 /* flare.fsh */, + E42559AC184DD45A0081BB20 /* flare.vsh */, ); path = Shaders; sourceTree = ""; @@ -1153,8 +1159,8 @@ E4E6F61116BA5D8300E410F8 /* debug_font_osx.vsh */, E4E6F61216BA5D8300E410F8 /* dust_particle_osx.fsh */, E4E6F61316BA5D8300E410F8 /* dust_particle_osx.vsh */, - E4E6F61416BA5D8300E410F8 /* flare_osx.fsh */, - E4E6F61516BA5D8300E410F8 /* flare_osx.vsh */, + E4E6F61416BA5D8300E410F8 /* sprite_osx.fsh */, + E4E6F61516BA5D8300E410F8 /* sprite_osx.vsh */, E4E6F61616BA5D8300E410F8 /* light_directional_osx.fsh */, E4E6F61716BA5D8300E410F8 /* light_directional_osx.vsh */, E4E6F61816BA5D8300E410F8 /* light_point_inside_osx.fsh */, @@ -1176,6 +1182,8 @@ E4E6F62816BA5D8300E410F8 /* volumetric_fog_downsampled_osx.vsh */, E4E6F62916BA5D8300E410F8 /* volumetric_fog_osx.fsh */, E4E6F62A16BA5D8300E410F8 /* volumetric_fog_osx.vsh */, + E42559AE184DD4730081BB20 /* flare_osx.fsh */, + E42559B0184DD48B0081BB20 /* flare_osx.vsh */, ); path = Shaders; sourceTree = ""; @@ -1511,8 +1519,8 @@ E4E6F68716BA5DF700E410F8 /* debug_font.vsh in Resources */, E4E6F68816BA5DF700E410F8 /* dust_particle.fsh in Resources */, E4E6F68916BA5DF700E410F8 /* dust_particle.vsh in Resources */, - E4E6F68A16BA5DF700E410F8 /* flare.fsh in Resources */, - E4E6F68B16BA5DF700E410F8 /* flare.vsh in Resources */, + E4E6F68A16BA5DF700E410F8 /* sprite.fsh in Resources */, + E4E6F68B16BA5DF700E410F8 /* sprite.vsh in Resources */, E4E6F68C16BA5DF700E410F8 /* light_directional.fsh in Resources */, E4E6F68D16BA5DF700E410F8 /* light_directional.vsh in Resources */, E4E6F68E16BA5DF700E410F8 /* light_point_inside.fsh in Resources */, @@ -1551,8 +1559,8 @@ E4E6F6A716BA5E0A00E410F8 /* debug_font_osx.vsh in Resources */, E4E6F6A816BA5E0A00E410F8 /* dust_particle_osx.fsh in Resources */, E4E6F6A916BA5E0A00E410F8 /* dust_particle_osx.vsh in Resources */, - E4E6F6AA16BA5E0A00E410F8 /* flare_osx.fsh in Resources */, - E4E6F6AB16BA5E0A00E410F8 /* flare_osx.vsh in Resources */, + E4E6F6AA16BA5E0A00E410F8 /* sprite_osx.fsh in Resources */, + E4E6F6AB16BA5E0A00E410F8 /* sprite_osx.vsh in Resources */, E4E6F6AC16BA5E0A00E410F8 /* light_directional_osx.fsh in Resources */, E4E6F6AD16BA5E0A00E410F8 /* light_directional_osx.vsh in Resources */, E4E6F6AE16BA5E0A00E410F8 /* light_point_inside_osx.fsh in Resources */, diff --git a/KREngine/kraken/KRLight.cpp b/KREngine/kraken/KRLight.cpp index d6162f5..80a5e3d 100644 --- a/KREngine/kraken/KRLight.cpp +++ b/KREngine/kraken/KRLight.cpp @@ -333,6 +333,7 @@ void KRLight::render(KRCamera *pCamera, std::vector &point_light // Render light flare on transparency pass KRShader *pShader = getContext().getShaderManager()->getShader("flare", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass)) { + pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_ALPHA, 1.0f); pShader->setUniform(KRShader::KRENGINE_UNIFORM_FLARE_SIZE, m_flareSize); m_pContext->getTextureManager()->selectTexture(0, m_pFlareTexture); m_pContext->getModelManager()->bindVBO(getContext().getModelManager()->KRENGINE_VBO_2D_SQUARE_VERTICES, getContext().getModelManager()->KRENGINE_VBO_2D_SQUARE_INDEXES, getContext().getModelManager()->KRENGINE_VBO_2D_SQUARE_ATTRIBS, true); diff --git a/KREngine/kraken/KRMeshQuad.cpp b/KREngine/kraken/KRMeshQuad.cpp index 6ca1f55..875f8a7 100644 --- a/KREngine/kraken/KRMeshQuad.cpp +++ b/KREngine/kraken/KRMeshQuad.cpp @@ -36,21 +36,15 @@ KRMeshQuad::KRMeshQuad(KRContext &context) : KRMesh(context, "__quad") { KRMesh::mesh_info mi; + mi.vertices.push_back(KRVector3(-1.0f, -1.0f, 0.0f)); + mi.vertices.push_back(KRVector3(1.0f, -1.0f, 0.0f)); + mi.vertices.push_back(KRVector3(-1.0f, 1.0f, 0.0f)); + mi.vertices.push_back(KRVector3(1.0f, 1.0f, 0.0f)); - mi.vertices.push_back(KRVector3(1.0, 1.0, 1.0)); - mi.vertices.push_back(KRVector3(-1.0, 1.0, 1.0)); - mi.vertices.push_back(KRVector3(1.0,-1.0, 1.0)); - mi.vertices.push_back(KRVector3(-1.0,-1.0, 1.0)); - mi.vertices.push_back(KRVector3(-1.0,-1.0,-1.0)); - mi.vertices.push_back(KRVector3(-1.0, 1.0, 1.0)); - mi.vertices.push_back(KRVector3(-1.0, 1.0,-1.0)); - mi.vertices.push_back(KRVector3(1.0, 1.0, 1.0)); - mi.vertices.push_back(KRVector3(1.0, 1.0,-1.0)); - mi.vertices.push_back(KRVector3(1.0,-1.0, 1.0)); - mi.vertices.push_back(KRVector3(1.0,-1.0,-1.0)); - mi.vertices.push_back(KRVector3(-1.0,-1.0,-1.0)); - mi.vertices.push_back(KRVector3(1.0, 1.0,-1.0)); - mi.vertices.push_back(KRVector3(-1.0, 1.0,-1.0)); + mi.uva.push_back(KRVector2(0.0f, 0.0f)); + mi.uva.push_back(KRVector2(1.0f, 0.0f)); + mi.uva.push_back(KRVector2(0.0f, 1.0f)); + mi.uva.push_back(KRVector2(1.0f, 1.0f)); mi.submesh_starts.push_back(0); diff --git a/KREngine/kraken/KRNode.cpp b/KREngine/kraken/KRNode.cpp index b307036..e8ac49e 100644 --- a/KREngine/kraken/KRNode.cpp +++ b/KREngine/kraken/KRNode.cpp @@ -920,4 +920,9 @@ void KRNode::addBehavior(KRBehavior *behavior) m_behaviors.insert(behavior); behavior->__setNode(this); getScene().notify_sceneGraphModify(this); -} \ No newline at end of file +} + +std::set &KRNode::getBehaviors() +{ + return m_behaviors; +} diff --git a/KREngine/kraken/KRNode.h b/KREngine/kraken/KRNode.h index e8d0f9d..eb074fa 100644 --- a/KREngine/kraken/KRNode.h +++ b/KREngine/kraken/KRNode.h @@ -227,6 +227,17 @@ private: public: void addBehavior(KRBehavior *behavior); + std::set &getBehaviors(); + template T *getBehavior() + { + for(std::set::iterator itr=m_behaviors.begin(); itr != m_behaviors.end(); itr++) { + T *behavior = dynamic_cast(*itr); + if(behavior) { + return behavior; + } + } + return NULL; + } void removeFromOctreeNodes(); void addToOctreeNode(KROctreeNode *octree_node); void childDeleted(KRNode *child_node); diff --git a/KREngine/kraken/KRSprite.cpp b/KREngine/kraken/KRSprite.cpp index 949f433..33807a0 100644 --- a/KREngine/kraken/KRSprite.cpp +++ b/KREngine/kraken/KRSprite.cpp @@ -28,7 +28,8 @@ KRSprite::KRSprite(KRScene &scene, std::string name) : KRNode(scene, name) { m_spriteTexture = ""; m_pSpriteTexture = NULL; - m_spriteSize = 0.0; + m_spriteSize = 0.0f; + m_spriteAlpha = 1.0f; } KRSprite::~KRSprite() @@ -44,6 +45,7 @@ tinyxml2::XMLElement *KRSprite::saveXML( tinyxml2::XMLNode *parent) tinyxml2::XMLElement *e = KRNode::saveXML(parent); e->SetAttribute("sprite_size", m_spriteSize); e->SetAttribute("sprite_texture", m_spriteTexture.c_str()); + e->SetAttribute("sprite_alpha", m_spriteAlpha); return e; } @@ -51,7 +53,10 @@ void KRSprite::loadXML(tinyxml2::XMLElement *e) { KRNode::loadXML(e); if(e->QueryFloatAttribute("sprite_size", &m_spriteSize) != tinyxml2::XML_SUCCESS) { - m_spriteSize = 0.0; + m_spriteSize = 0.0f; + } + if(e->QueryFloatAttribute("sprite_alpha", &m_spriteAlpha) != tinyxml2::XML_SUCCESS) { + m_spriteAlpha = 1.0f; } const char *szSpriteTexture = e->Attribute("sprite_texture"); @@ -73,6 +78,16 @@ void KRSprite::setSpriteSize(float sprite_size) { m_spriteSize = sprite_size; } +void KRSprite::setSpriteAlpha(float alpha) +{ + m_spriteAlpha = alpha; +} + +float KRSprite::getSpriteAlpha() const +{ + return m_spriteAlpha; +} + KRAABB KRSprite::getBounds() { return KRAABB(KRVector3(-m_spriteSize), KRVector3(m_spriteSize), getModelMatrix()); } @@ -84,7 +99,7 @@ void KRSprite::render(KRCamera *pCamera, std::vector &point_ligh if(renderPass == KRNode::RENDER_PASS_ADDITIVE_PARTICLES) { - if(m_spriteTexture.size() && m_spriteSize > 0.0f) { + if(m_spriteTexture.size() && m_spriteSize > 0.0f && m_spriteAlpha > 0.0f) { if(!m_pSpriteTexture && m_spriteTexture.size()) { @@ -109,8 +124,9 @@ void KRSprite::render(KRCamera *pCamera, std::vector &point_ligh GLDEBUG(glDepthRangef(0.0, 1.0)); // Render light sprite on transparency pass - KRShader *pShader = getContext().getShaderManager()->getShader("flare", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); + KRShader *pShader = getContext().getShaderManager()->getShader("sprite", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass)) { + pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_ALPHA, m_spriteAlpha); pShader->setUniform(KRShader::KRENGINE_UNIFORM_FLARE_SIZE, m_spriteSize); m_pContext->getTextureManager()->selectTexture(0, m_pSpriteTexture); m_pContext->getModelManager()->bindVBO(getContext().getModelManager()->KRENGINE_VBO_2D_SQUARE_VERTICES, getContext().getModelManager()->KRENGINE_VBO_2D_SQUARE_INDEXES, getContext().getModelManager()->KRENGINE_VBO_2D_SQUARE_ATTRIBS, true); diff --git a/KREngine/kraken/KRSprite.h b/KREngine/kraken/KRSprite.h index dbe5f2f..e64be0f 100644 --- a/KREngine/kraken/KRSprite.h +++ b/KREngine/kraken/KRSprite.h @@ -24,6 +24,8 @@ public: void setSpriteTexture(std::string sprite_texture); void setSpriteSize(float sprite_size); + void setSpriteAlpha(float alpha); + float getSpriteAlpha() const; virtual void render(KRCamera *pCamera, std::vector &point_lights, std::vector &directional_lights, std::vector&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass); @@ -34,6 +36,7 @@ protected: std::string m_spriteTexture; KRTexture *m_pSpriteTexture; float m_spriteSize; + float m_spriteAlpha; }; #endif diff --git a/KREngine/kraken_standard_assets_ios/Shaders/flare.fsh b/KREngine/kraken_standard_assets_ios/Shaders/flare.fsh index aa8d43b..7fce713 100644 --- a/KREngine/kraken_standard_assets_ios/Shaders/flare.fsh +++ b/KREngine/kraken_standard_assets_ios/Shaders/flare.fsh @@ -3,17 +3,17 @@ // KREngine // // Copyright 2012 Kearwood Gilbert. All rights reserved. -// +// // Redistribution and use in source and binary forms, with or without modification, are // permitted provided that the following conditions are met: -// +// // 1. Redistributions of source code must retain the above copyright notice, this list of // conditions and the following disclaimer. -// +// // 2. Redistributions in binary form must reproduce the above copyright notice, this list // of conditions and the following disclaimer in the documentation and/or other materials // provided with the distribution. -// +// // THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR @@ -23,7 +23,7 @@ // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// +// // The views and conclusions contained in the software and documentation are those of the // authors and should not be interpreted as representing official policies, either expressed // or implied, of Kearwood Gilbert. @@ -31,7 +31,8 @@ varying mediump vec2 texCoord; uniform sampler2D diffuseTexture; +uniform lowp float material_alpha; void main() { - gl_FragColor = vec4(vec3(texture2D(diffuseTexture, texCoord)), 1.0); + gl_FragColor = vec4(vec3(texture2D(diffuseTexture, texCoord)), 1.0) * material_alpha; } \ No newline at end of file diff --git a/KREngine/kraken_standard_assets_ios/Shaders/flare.vsh b/KREngine/kraken_standard_assets_ios/Shaders/flare.vsh index 785bf5e..fc0c4d4 100644 --- a/KREngine/kraken_standard_assets_ios/Shaders/flare.vsh +++ b/KREngine/kraken_standard_assets_ios/Shaders/flare.vsh @@ -3,17 +3,17 @@ // KREngine // // Copyright 2012 Kearwood Gilbert. All rights reserved. -// +// // Redistribution and use in source and binary forms, with or without modification, are // permitted provided that the following conditions are met: -// +// // 1. Redistributions of source code must retain the above copyright notice, this list of // conditions and the following disclaimer. -// +// // 2. Redistributions in binary form must reproduce the above copyright notice, this list // of conditions and the following disclaimer in the documentation and/or other materials // provided with the distribution. -// +// // THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR @@ -23,7 +23,7 @@ // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// +// // The views and conclusions contained in the software and documentation are those of the // authors and should not be interpreted as representing official policies, either expressed // or implied, of Kearwood Gilbert. diff --git a/KREngine/kraken_standard_assets_ios/Shaders/sprite.fsh b/KREngine/kraken_standard_assets_ios/Shaders/sprite.fsh new file mode 100644 index 0000000..4519d5d --- /dev/null +++ b/KREngine/kraken_standard_assets_ios/Shaders/sprite.fsh @@ -0,0 +1,38 @@ +// +// sprite.fsh +// KREngine +// +// Copyright 2012 Kearwood Gilbert. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other materials +// provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// The views and conclusions contained in the software and documentation are those of the +// authors and should not be interpreted as representing official policies, either expressed +// or implied, of Kearwood Gilbert. +// + +varying mediump vec2 texCoord; +uniform sampler2D diffuseTexture; +uniform lowp float material_alpha; + +void main() { + gl_FragColor = vec4(vec3(texture2D(diffuseTexture, texCoord)), 1.0) * material_alpha; +} \ No newline at end of file diff --git a/KREngine/kraken_standard_assets_ios/Shaders/sprite.vsh b/KREngine/kraken_standard_assets_ios/Shaders/sprite.vsh new file mode 100644 index 0000000..347191e --- /dev/null +++ b/KREngine/kraken_standard_assets_ios/Shaders/sprite.vsh @@ -0,0 +1,42 @@ +// +// sprite.vsh +// KREngine +// +// Copyright 2012 Kearwood Gilbert. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other materials +// provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// The views and conclusions contained in the software and documentation are those of the +// authors and should not be interpreted as representing official policies, either expressed +// or implied, of Kearwood Gilbert. +// + +attribute mediump vec2 vertex_uv; +uniform highp mat4 mvp_matrix; // mvp_matrix is the result of multiplying the model, view, and projection matrices +uniform mediump vec4 viewport; +uniform mediump float flare_size; + +varying mediump vec2 texCoord; + +void main() { + texCoord = vertex_uv; + gl_Position = mvp_matrix * vec4(0.0, 0.0, 0.0, 1.0) + vec4(vertex_uv.x * viewport.w / viewport.z * 2.0 - 1.0, vertex_uv.y * 2.0 - 1.0, 0.0, 0.0) * flare_size; +} diff --git a/KREngine/kraken_standard_assets_osx/Shaders/flare_osx.fsh b/KREngine/kraken_standard_assets_osx/Shaders/flare_osx.fsh index aa8d43b..7fce713 100644 --- a/KREngine/kraken_standard_assets_osx/Shaders/flare_osx.fsh +++ b/KREngine/kraken_standard_assets_osx/Shaders/flare_osx.fsh @@ -3,17 +3,17 @@ // KREngine // // Copyright 2012 Kearwood Gilbert. All rights reserved. -// +// // Redistribution and use in source and binary forms, with or without modification, are // permitted provided that the following conditions are met: -// +// // 1. Redistributions of source code must retain the above copyright notice, this list of // conditions and the following disclaimer. -// +// // 2. Redistributions in binary form must reproduce the above copyright notice, this list // of conditions and the following disclaimer in the documentation and/or other materials // provided with the distribution. -// +// // THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR @@ -23,7 +23,7 @@ // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// +// // The views and conclusions contained in the software and documentation are those of the // authors and should not be interpreted as representing official policies, either expressed // or implied, of Kearwood Gilbert. @@ -31,7 +31,8 @@ varying mediump vec2 texCoord; uniform sampler2D diffuseTexture; +uniform lowp float material_alpha; void main() { - gl_FragColor = vec4(vec3(texture2D(diffuseTexture, texCoord)), 1.0); + gl_FragColor = vec4(vec3(texture2D(diffuseTexture, texCoord)), 1.0) * material_alpha; } \ No newline at end of file diff --git a/KREngine/kraken_standard_assets_osx/Shaders/flare_osx.vsh b/KREngine/kraken_standard_assets_osx/Shaders/flare_osx.vsh index 785bf5e..fc0c4d4 100644 --- a/KREngine/kraken_standard_assets_osx/Shaders/flare_osx.vsh +++ b/KREngine/kraken_standard_assets_osx/Shaders/flare_osx.vsh @@ -3,17 +3,17 @@ // KREngine // // Copyright 2012 Kearwood Gilbert. All rights reserved. -// +// // Redistribution and use in source and binary forms, with or without modification, are // permitted provided that the following conditions are met: -// +// // 1. Redistributions of source code must retain the above copyright notice, this list of // conditions and the following disclaimer. -// +// // 2. Redistributions in binary form must reproduce the above copyright notice, this list // of conditions and the following disclaimer in the documentation and/or other materials // provided with the distribution. -// +// // THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR @@ -23,7 +23,7 @@ // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// +// // The views and conclusions contained in the software and documentation are those of the // authors and should not be interpreted as representing official policies, either expressed // or implied, of Kearwood Gilbert. diff --git a/KREngine/kraken_standard_assets_osx/Shaders/sprite_osx.fsh b/KREngine/kraken_standard_assets_osx/Shaders/sprite_osx.fsh new file mode 100644 index 0000000..4519d5d --- /dev/null +++ b/KREngine/kraken_standard_assets_osx/Shaders/sprite_osx.fsh @@ -0,0 +1,38 @@ +// +// sprite.fsh +// KREngine +// +// Copyright 2012 Kearwood Gilbert. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other materials +// provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// The views and conclusions contained in the software and documentation are those of the +// authors and should not be interpreted as representing official policies, either expressed +// or implied, of Kearwood Gilbert. +// + +varying mediump vec2 texCoord; +uniform sampler2D diffuseTexture; +uniform lowp float material_alpha; + +void main() { + gl_FragColor = vec4(vec3(texture2D(diffuseTexture, texCoord)), 1.0) * material_alpha; +} \ No newline at end of file diff --git a/KREngine/kraken_standard_assets_osx/Shaders/sprite_osx.vsh b/KREngine/kraken_standard_assets_osx/Shaders/sprite_osx.vsh new file mode 100644 index 0000000..347191e --- /dev/null +++ b/KREngine/kraken_standard_assets_osx/Shaders/sprite_osx.vsh @@ -0,0 +1,42 @@ +// +// sprite.vsh +// KREngine +// +// Copyright 2012 Kearwood Gilbert. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other materials +// provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// The views and conclusions contained in the software and documentation are those of the +// authors and should not be interpreted as representing official policies, either expressed +// or implied, of Kearwood Gilbert. +// + +attribute mediump vec2 vertex_uv; +uniform highp mat4 mvp_matrix; // mvp_matrix is the result of multiplying the model, view, and projection matrices +uniform mediump vec4 viewport; +uniform mediump float flare_size; + +varying mediump vec2 texCoord; + +void main() { + texCoord = vertex_uv; + gl_Position = mvp_matrix * vec4(0.0, 0.0, 0.0, 1.0) + vec4(vertex_uv.x * viewport.w / viewport.z * 2.0 - 1.0, vertex_uv.y * 2.0 - 1.0, 0.0, 0.0) * flare_size; +}