Working CLight

This commit is contained in:
Jack Andersen 2016-04-03 19:02:09 -10:00
parent dae2621d93
commit 408ce2ca8b
7 changed files with 39 additions and 31 deletions

View File

@ -64,6 +64,7 @@ void ViewManager::ParticleView::draw(boo::IGraphicsCommandQueue *gfxQ)
if (m_vm.m_modelTest.IsLoaded()) if (m_vm.m_modelTest.IsLoaded())
{ {
CModelFlags flags; CModelFlags flags;
flags.m_extendedShaderIdx = 1;
m_theta += 0.01f; m_theta += 0.01f;
CGraphics::SetModelMatrix(zeus::CTransform::RotateZ(m_theta)); CGraphics::SetModelMatrix(zeus::CTransform::RotateZ(m_theta));
@ -72,6 +73,10 @@ void ViewManager::ParticleView::draw(boo::IGraphicsCommandQueue *gfxQ)
float aspect = windowRect.size[0] / float(windowRect.size[1]); float aspect = windowRect.size[0] / float(windowRect.size[1]);
CGraphics::SetPerspective(55.0, aspect, 0.001f, 1000.f); CGraphics::SetPerspective(55.0, aspect, 0.001f, 1000.f);
std::vector<CLight> lights = {CLight::BuildLocalAmbient({}, {0.5f, 0.5f, 0.5f, 1.f}),
CLight::BuildCustom({0.f, -2.f, 1.f}, {0.f, 1.f, 0.f},
{20.f, 20.f, 20.f, 1.f}, 0.f, 0.f, 1.f, 1.f, 0.f, 0.f)};
m_vm.m_modelTest->GetInstance().ActivateLights(lights);
m_vm.m_modelTest->Draw(flags); m_vm.m_modelTest->Draw(flags);
} }
if (m_vm.m_partGen) if (m_vm.m_partGen)

View File

@ -60,8 +60,8 @@ CLight::CLight(ELightType type,
float cutoff) float cutoff)
: x0_pos(pos), xc_dir(dir), x18_color(color), : x0_pos(pos), xc_dir(dir), x18_color(color),
x1c_type(type), x20_spotCutoff(cutoff), x1c_type(type), x20_spotCutoff(cutoff),
x24_distC(0.f), x28_distL(1.f), x2c_distQ(0.f), x24_distC(1.f), x28_distL(0.f), x2c_distQ(0.f),
x30_angleC(0.f), x34_angleL(1.f), x38_angleQ(0.f), x30_angleC(1.f), x34_angleL(0.f), x38_angleQ(0.f),
x44_cachedRadius(0.f), x48_cachedIntensity(0.f), x44_cachedRadius(0.f), x48_cachedIntensity(0.f),
x4c_24_intensityDirty(true), x4c_25_radiusDirty(true) x4c_24_intensityDirty(true), x4c_25_radiusDirty(true)
{ {

View File

@ -155,6 +155,8 @@ public:
void Draw(const CModelFlags& flags) const; void Draw(const CModelFlags& flags) const;
void Touch(int shaderIdx) const; void Touch(int shaderIdx) const;
bool IsLoaded(int shaderIdx) const; bool IsLoaded(int shaderIdx) const;
CBooModel& GetInstance() {return *x28_modelInst;}
}; };
CFactoryFnReturn FModelFactory(const urde::SObjectTag& tag, CFactoryFnReturn FModelFactory(const urde::SObjectTag& tag,

View File

@ -107,18 +107,15 @@ void CBooModel::BuildGfxToken()
m_uniformData.reset(new u8[uniBufSize]); m_uniformData.reset(new u8[uniBufSize]);
m_uniformBuffer = ctx.newDynamicBuffer(boo::BufferUse::Uniform, uniBufSize, 1); m_uniformBuffer = ctx.newDynamicBuffer(boo::BufferUse::Uniform, uniBufSize, 1);
std::vector<boo::IGraphicsBuffer*> bufs; boo::IGraphicsBuffer* bufs[] = {m_uniformBuffer, m_uniformBuffer, m_uniformBuffer};
bufs.resize(3, m_uniformBuffer);
/* Binding for each surface */ /* Binding for each surface */
m_shaderDataBindings.clear(); m_shaderDataBindings.clear();
m_shaderDataBindings.reserve(x0_surfaces->size()); m_shaderDataBindings.reserve(x0_surfaces->size());
std::vector<boo::ITexture*> texs; std::vector<boo::ITexture*> texs;
std::vector<size_t> thisOffs; size_t thisOffs[3];
std::vector<size_t> thisSizes; size_t thisSizes[3];
thisOffs.reserve(3);
thisSizes.reserve(3);
/* Enumerate surfaces and build data bindings */ /* Enumerate surfaces and build data bindings */
for (const CBooSurface& surf : *x0_surfaces) for (const CBooSurface& surf : *x0_surfaces)
@ -133,28 +130,30 @@ void CBooModel::BuildGfxToken()
texs.push_back(tex.GetObj()->GetBooTexture()); texs.push_back(tex.GetObj()->GetBooTexture());
} }
size_t thisBufCount = 2;
if (m_skinBankCount) if (m_skinBankCount)
{ {
thisOffs.push_back(skinOffs[surf.m_data.skinMtxBankIdx]); thisOffs[0] = skinOffs[surf.m_data.skinMtxBankIdx];
thisSizes.push_back(skinSizes[surf.m_data.skinMtxBankIdx]); thisSizes[0] = skinSizes[surf.m_data.skinMtxBankIdx];
} }
else else
{ {
thisOffs.push_back(0); thisOffs[0] = 0;
thisSizes.push_back(256); thisSizes[0] = 256;
} }
if (mat.uvAnims.size()) if (mat.uvAnims.size())
{ {
thisOffs.push_back(uvOffs[surf.m_data.matIdx]); thisOffs[1] = uvOffs[surf.m_data.matIdx];
thisSizes.push_back(uvSizes[surf.m_data.matIdx]); thisSizes[1] = uvSizes[surf.m_data.matIdx];
++thisBufCount; }
else
{
thisOffs[1] = 0;
thisSizes[1] = 0;
} }
thisOffs.push_back(lightOff); thisOffs[2] = lightOff;
thisSizes.push_back(lightSz); thisSizes[2] = lightSz;
const std::vector<boo::IShaderPipeline*>& pipelines = m_pipelines->at(surf.m_data.matIdx); const std::vector<boo::IShaderPipeline*>& pipelines = m_pipelines->at(surf.m_data.matIdx);
@ -165,11 +164,8 @@ void CBooModel::BuildGfxToken()
for (boo::IShaderPipeline* pipeline : pipelines) for (boo::IShaderPipeline* pipeline : pipelines)
extendeds.push_back( extendeds.push_back(
ctx.newShaderDataBinding(pipeline, m_vtxFmt, ctx.newShaderDataBinding(pipeline, m_vtxFmt,
x8_vbo, nullptr, xc_ibo, thisBufCount, bufs.data(), x8_vbo, nullptr, xc_ibo, 3, bufs,
thisOffs.data(), thisSizes.data(), mat.textureIdxs.size(), texs.data())); thisOffs, thisSizes, mat.textureIdxs.size(), texs.data()));
thisOffs.clear();
thisSizes.clear();
} }
return true; return true;
}); });
@ -186,7 +182,7 @@ void CBooModel::MakeTexuresFromMats(const MaterialSet& matSet,
void CBooModel::ActivateLights(const std::vector<CLight>& lights) void CBooModel::ActivateLights(const std::vector<CLight>& lights)
{ {
zeus::CColor ambientAccum = zeus::CColor::skBlack; m_lightingData.ambient = zeus::CColor::skBlack;
size_t curLight = 0; size_t curLight = 0;
for (const CLight& light : lights) for (const CLight& light : lights)
@ -194,7 +190,7 @@ void CBooModel::ActivateLights(const std::vector<CLight>& lights)
switch (light.x1c_type) switch (light.x1c_type)
{ {
case ELightType::LocalAmbient: case ELightType::LocalAmbient:
ambientAccum += light.x18_color; m_lightingData.ambient += light.x18_color;
break; break;
case ELightType::Point: case ELightType::Point:
case ELightType::Spot: case ELightType::Spot:
@ -206,6 +202,7 @@ void CBooModel::ActivateLights(const std::vector<CLight>& lights)
CModelShaders::Light& lightOut = m_lightingData.lights[curLight++]; CModelShaders::Light& lightOut = m_lightingData.lights[curLight++];
lightOut.pos = CGraphics::g_CameraMatrix * light.x0_pos; lightOut.pos = CGraphics::g_CameraMatrix * light.x0_pos;
lightOut.dir = CGraphics::g_CameraMatrix.m_basis * light.xc_dir; lightOut.dir = CGraphics::g_CameraMatrix.m_basis * light.xc_dir;
lightOut.dir.normalize();
lightOut.color = light.x18_color; lightOut.color = light.x18_color;
lightOut.linAtt[0] = light.x24_distC; lightOut.linAtt[0] = light.x24_distC;
lightOut.linAtt[1] = light.x28_distL; lightOut.linAtt[1] = light.x28_distL;

View File

@ -1,4 +1,5 @@
#include "CModelShaders.hpp" #include "CModelShaders.hpp"
#include "hecl/Backend/GLSL.hpp"
namespace urde namespace urde
{ {
@ -27,14 +28,14 @@ static const char* LightingGLSL =
" {\n" " {\n"
" vec3 delta = mvPosIn.xyz - lights[i].pos.xyz;\n" " vec3 delta = mvPosIn.xyz - lights[i].pos.xyz;\n"
" float dist = length(delta);\n" " float dist = length(delta);\n"
" float angDot = dot(normalize(delta), lights[i].dir.xyz);\n" " float angDot = clamp(dot(normalize(delta), lights[i].dir.xyz), 0.0, 1.0);\n"
" float att = 1.0 / (lights[i].linAtt[2] * dist * dist +\n" " float att = 1.0 / (lights[i].linAtt[2] * dist * dist +\n"
" lights[i].linAtt[1] * dist +\n" " lights[i].linAtt[1] * dist +\n"
" lights[i].linAtt[0]);\n" " lights[i].linAtt[0]);\n"
" float angAtt = lights[i].angAtt[2] * angDot * angDot +\n" " float angAtt = lights[i].angAtt[2] * angDot * angDot +\n"
" lights[i].angAtt[1] * angDot +\n" " lights[i].angAtt[1] * angDot +\n"
" lights[i].angAtt[0];\n" " lights[i].angAtt[0];\n"
" ret += lights[i].color * clamp(angAtt, 0.0, 1.0) * att * dot(normalize(-delta), mvNormIn.xyz);\n" " ret += lights[i].color * clamp(angAtt, 0.0, 1.0) * att * clamp(dot(normalize(-delta), mvNormIn.xyz), 0.0, 1.0);\n"
" }\n" " }\n"
" \n" " \n"
" return clamp(ret, vec4(0.0,0.0,0.0,0.0), vec4(1.0,1.0,1.0,1.0));\n" " return clamp(ret, vec4(0.0,0.0,0.0,0.0), vec4(1.0,1.0,1.0,1.0));\n"
@ -43,8 +44,11 @@ static const char* LightingGLSL =
hecl::Runtime::ShaderCacheExtensions hecl::Runtime::ShaderCacheExtensions
CModelShaders::GetShaderExtensionsGLSL(boo::IGraphicsDataFactory::Platform plat) CModelShaders::GetShaderExtensionsGLSL(boo::IGraphicsDataFactory::Platform plat)
{ {
static const char* BlockNames[] = {HECL_GLSL_VERT_UNIFORM_BLOCK_NAME,
HECL_GLSL_TEXMTX_UNIFORM_BLOCK_NAME,
"LightingUniform"};
hecl::Runtime::ShaderCacheExtensions ext(plat); hecl::Runtime::ShaderCacheExtensions ext(plat);
ext.registerExtensionSlot({LightingGLSL, "LightingFunc"}, {}); ext.registerExtensionSlot({LightingGLSL, "LightingFunc"}, {}, 3, BlockNames);
return ext; return ext;
} }

2
hecl

@ -1 +1 @@
Subproject commit 11c8c744fd62770660506d271ea9eff858ea4138 Subproject commit d5f9da3914d0ae1f4b4a4d8d0fddde160e406a6e

@ -1 +1 @@
Subproject commit 33ce8bc20ba776e5868230aec459cd31c7e6554b Subproject commit d49a33ec1b936052ff1b4d02586748d59a27c174