Port god ray to use SP

This commit is contained in:
Benau 2018-01-03 14:29:20 +08:00
parent 1400257a60
commit 345f2bc64b
6 changed files with 55 additions and 32 deletions

View File

@ -36,6 +36,7 @@
#include "graphics/shaders.hpp" #include "graphics/shaders.hpp"
#include "graphics/sp_mesh_loader.hpp" #include "graphics/sp_mesh_loader.hpp"
#include "graphics/sp/sp_base.hpp" #include "graphics/sp/sp_base.hpp"
#include "graphics/sp/sp_dynamic_draw_call.hpp"
#include "graphics/sp/sp_mesh.hpp" #include "graphics/sp/sp_mesh.hpp"
#include "graphics/sp/sp_mesh_node.hpp" #include "graphics/sp/sp_mesh_node.hpp"
#include "graphics/sp/sp_texture_manager.hpp" #include "graphics/sp/sp_texture_manager.hpp"
@ -63,6 +64,7 @@
#include "states_screens/dialogs/confirm_resolution_dialog.hpp" #include "states_screens/dialogs/confirm_resolution_dialog.hpp"
#include "states_screens/state_manager.hpp" #include "states_screens/state_manager.hpp"
#include "tracks/track_manager.hpp" #include "tracks/track_manager.hpp"
#include "tracks/track.hpp"
#include "utils/constants.hpp" #include "utils/constants.hpp"
#include "utils/log.hpp" #include "utils/log.hpp"
#include "utils/profiler.hpp" #include "utils/profiler.hpp"
@ -141,6 +143,7 @@ IrrDriver::IrrDriver()
m_clear_color = video::SColor(255, 100, 101, 140); m_clear_color = video::SColor(255, 100, 101, 140);
m_skinning_joint = 0; m_skinning_joint = 0;
m_recording = false; m_recording = false;
m_sun_interposer = NULL;
} // IrrDriver } // IrrDriver
@ -678,6 +681,7 @@ void IrrDriver::setMaxTextureSize()
void IrrDriver::cleanSunInterposer() void IrrDriver::cleanSunInterposer()
{ {
delete m_sun_interposer; delete m_sun_interposer;
m_sun_interposer = NULL;
} // cleanSunInterposer } // cleanSunInterposer
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -685,32 +689,33 @@ void IrrDriver::createSunInterposer()
{ {
#ifndef SERVER_ONLY #ifndef SERVER_ONLY
scene::IMesh * sphere = m_scene_manager->getGeometryCreator() scene::IMesh * sphere = m_scene_manager->getGeometryCreator()
->createSphereMesh(1, 16, 16); ->createSphereMesh(1, 16, 16);
for (unsigned i = 0; i < sphere->getMeshBufferCount(); ++i) Material* material = material_manager->getSPMaterial("solid");
m_sun_interposer = new SP::SPDynamicDrawCall
(scene::EPT_TRIANGLES, NULL/*shader*/, material);
for (unsigned i = 0; i < sphere->getMeshBufferCount(); i++)
{ {
scene::IMeshBuffer *mb = sphere->getMeshBuffer(i); scene::IMeshBuffer* mb = sphere->getMeshBuffer(i);
if (!mb) if (!mb)
{
continue; continue;
mb->getMaterial().setTexture(0, }
STKTexManager::getInstance()->getUnicolorTexture(video::SColor(255, 255, 255, 255))); assert(mb->getVertexType() == video::EVT_STANDARD);
mb->getMaterial().setTexture(1, video::S3DVertex* v_ptr = (video::S3DVertex*)mb->getVertices();
STKTexManager::getInstance()->getUnicolorTexture(video::SColor(0, 0, 0, 0))); uint16_t* idx_ptr = mb->getIndices();
mb->getMaterial().setTexture(2, for (unsigned j = 0; j < mb->getIndexCount(); j++)
STKTexManager::getInstance()->getUnicolorTexture(video::SColor(0, 0, 0, 0))); {
// For sun interposer we only need position for glow shader
video::S3DVertexSkinnedMesh sp;
const unsigned v_idx = idx_ptr[j];
sp.m_position = v_ptr[v_idx].Pos;
m_sun_interposer->addSPMVertex(sp);
}
} }
m_sun_interposer = new STKMeshSceneNode(sphere, m_sun_interposer->recalculateBoundingBox();
m_scene_manager->getRootSceneNode(), m_sun_interposer->setPosition(Track::getCurrentTrack()
NULL, -1, "sun_interposer"); ->getGodRaysPosition());
m_sun_interposer->grab();
m_sun_interposer->setParent(NULL);
m_sun_interposer->setScale(core::vector3df(20)); m_sun_interposer->setScale(core::vector3df(20));
m_sun_interposer->getMaterial(0).Lighting = false;
m_sun_interposer->getMaterial(0).ColorMask = video::ECP_NONE;
m_sun_interposer->getMaterial(0).ZWriteEnable = false;
m_sun_interposer->getMaterial(0).MaterialType = Shaders::getShader(ES_OBJECTPASS);
sphere->drop(); sphere->drop();
#endif #endif
} }

View File

@ -50,6 +50,12 @@
#endif #endif
namespace SP
{
class SPDynamicDrawCall;
}
namespace irr namespace irr
{ {
namespace scene { class ISceneManager; class IMesh; class IAnimatedMeshSceneNode; class IAnimatedMesh; namespace scene { class ISceneManager; class IMesh; class IAnimatedMeshSceneNode; class IAnimatedMesh;
@ -170,7 +176,7 @@ private:
unsigned m_last_light_bucket_distance; unsigned m_last_light_bucket_distance;
unsigned m_skinning_joint; unsigned m_skinning_joint;
u32 m_renderpass; u32 m_renderpass;
class STKMeshSceneNode *m_sun_interposer; SP::SPDynamicDrawCall* m_sun_interposer;
core::vector3df m_sun_direction; core::vector3df m_sun_direction;
video::SColorf m_suncolor; video::SColorf m_suncolor;
@ -462,7 +468,7 @@ public:
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
void clearLights(); void clearLights();
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
class STKMeshSceneNode *getSunInterposer() { return m_sun_interposer; } SP::SPDynamicDrawCall* getSunInterposer() { return m_sun_interposer; }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
void cleanSunInterposer(); void cleanSunInterposer();

View File

@ -31,10 +31,12 @@
#include "graphics/rtts.hpp" #include "graphics/rtts.hpp"
#include "graphics/shaders.hpp" #include "graphics/shaders.hpp"
#include "graphics/shared_gpu_objects.hpp" #include "graphics/shared_gpu_objects.hpp"
#include "graphics/stk_mesh_scene_node.hpp"
#include "graphics/stk_texture.hpp" #include "graphics/stk_texture.hpp"
#include "graphics/stk_tex_manager.hpp" #include "graphics/stk_tex_manager.hpp"
#include "graphics/weather.hpp" #include "graphics/weather.hpp"
#include "graphics/sp/sp_dynamic_draw_call.hpp"
#include "graphics/sp/sp_shader.hpp"
#include "graphics/sp/sp_uniform_assigner.hpp"
#include "io/file_manager.hpp" #include "io/file_manager.hpp"
#include "karts/abstract_kart.hpp" #include "karts/abstract_kart.hpp"
#include "karts/kart_model.hpp" #include "karts/kart_model.hpp"
@ -1316,12 +1318,17 @@ void PostProcessing::renderGodRays(scene::ICameraSceneNode * const camnode,
const SColor col = track->getGodRaysColor(); const SColor col = track->getGodRaysColor();
// The sun interposer // The sun interposer
STKMeshSceneNode *sun = irr_driver->getSunInterposer(); SP::SPDynamicDrawCall* sun = irr_driver->getSunInterposer();
sun->setGlowColors(col); // This will only do thing when you update the sun position
sun->setPosition(track->getGodRaysPosition()); sun->uploadInstanceData();
sun->updateAbsolutePosition(); SP::SPShader* glow_shader = SP::getGlowShader();
irr_driver->setPhase(GLOW_PASS); glow_shader->use();
sun->render(); SP::SPUniformAssigner* glow_color_assigner = glow_shader
->getUniformAssigner("col");
assert(glow_color_assigner != NULL);
glow_color_assigner->setValue(video::SColorf(track->getGodRaysColor()));
sun->draw();
glow_shader->unuse();
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
// Fade to quarter // Fade to quarter

View File

@ -1808,6 +1808,7 @@ void addDynamicDrawCall(std::shared_ptr<SPDynamicDrawCall> dy_dc)
{ {
g_dy_dc.push_back(dy_dc); g_dy_dc.push_back(dy_dc);
} // addDynamicDrawCall } // addDynamicDrawCall
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
SPMesh* convertEVTStandard(irr::scene::IMesh* mesh, SPMesh* convertEVTStandard(irr::scene::IMesh* mesh,
const irr::video::SColor* color) const irr::video::SColor* color)
@ -1818,6 +1819,10 @@ SPMesh* convertEVTStandard(irr::scene::IMesh* mesh,
{ {
std::vector<video::S3DVertexSkinnedMesh> vertices; std::vector<video::S3DVertexSkinnedMesh> vertices;
scene::IMeshBuffer* mb = mesh->getMeshBuffer(i); scene::IMeshBuffer* mb = mesh->getMeshBuffer(i);
if (!mb)
{
continue;
}
assert(mb->getVertexType() == video::EVT_STANDARD); assert(mb->getVertexType() == video::EVT_STANDARD);
video::S3DVertex* v_ptr = (video::S3DVertex*)mb->getVertices(); video::S3DVertex* v_ptr = (video::S3DVertex*)mb->getVertices();
for (unsigned j = 0; j < mb->getVertexCount(); j++) for (unsigned j = 0; j < mb->getVertexCount(); j++)

View File

@ -70,7 +70,7 @@ public:
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
~SPDynamicDrawCall() {} ~SPDynamicDrawCall() {}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
virtual void draw(DrawCallType dct, int material_id = -1, virtual void draw(DrawCallType dct = DCT_NORMAL, int material_id = -1,
bool bindless_texture = false) const bool bindless_texture = false) const
{ {
#ifndef SERVER_ONLY #ifndef SERVER_ONLY

View File

@ -109,7 +109,7 @@ public:
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
~SPMeshBuffer(); ~SPMeshBuffer();
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
virtual void draw(DrawCallType dct, int material_id = -1, virtual void draw(DrawCallType dct = DCT_NORMAL, int material_id = -1,
bool bindless_texture = false) const bool bindless_texture = false) const
{ {
glBindVertexArray(m_vao[dct]); glBindVertexArray(m_vao[dct]);