mirror of https://github.com/AxioDL/metaforce.git
Working CLight
This commit is contained in:
parent
dae2621d93
commit
408ce2ca8b
|
@ -64,6 +64,7 @@ void ViewManager::ParticleView::draw(boo::IGraphicsCommandQueue *gfxQ)
|
|||
if (m_vm.m_modelTest.IsLoaded())
|
||||
{
|
||||
CModelFlags flags;
|
||||
flags.m_extendedShaderIdx = 1;
|
||||
|
||||
m_theta += 0.01f;
|
||||
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]);
|
||||
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);
|
||||
}
|
||||
if (m_vm.m_partGen)
|
||||
|
|
|
@ -60,8 +60,8 @@ CLight::CLight(ELightType type,
|
|||
float cutoff)
|
||||
: x0_pos(pos), xc_dir(dir), x18_color(color),
|
||||
x1c_type(type), x20_spotCutoff(cutoff),
|
||||
x24_distC(0.f), x28_distL(1.f), x2c_distQ(0.f),
|
||||
x30_angleC(0.f), x34_angleL(1.f), x38_angleQ(0.f),
|
||||
x24_distC(1.f), x28_distL(0.f), x2c_distQ(0.f),
|
||||
x30_angleC(1.f), x34_angleL(0.f), x38_angleQ(0.f),
|
||||
x44_cachedRadius(0.f), x48_cachedIntensity(0.f),
|
||||
x4c_24_intensityDirty(true), x4c_25_radiusDirty(true)
|
||||
{
|
||||
|
|
|
@ -155,6 +155,8 @@ public:
|
|||
void Draw(const CModelFlags& flags) const;
|
||||
void Touch(int shaderIdx) const;
|
||||
bool IsLoaded(int shaderIdx) const;
|
||||
|
||||
CBooModel& GetInstance() {return *x28_modelInst;}
|
||||
};
|
||||
|
||||
CFactoryFnReturn FModelFactory(const urde::SObjectTag& tag,
|
||||
|
|
|
@ -107,18 +107,15 @@ void CBooModel::BuildGfxToken()
|
|||
m_uniformData.reset(new u8[uniBufSize]);
|
||||
m_uniformBuffer = ctx.newDynamicBuffer(boo::BufferUse::Uniform, uniBufSize, 1);
|
||||
|
||||
std::vector<boo::IGraphicsBuffer*> bufs;
|
||||
bufs.resize(3, m_uniformBuffer);
|
||||
boo::IGraphicsBuffer* bufs[] = {m_uniformBuffer, m_uniformBuffer, m_uniformBuffer};
|
||||
|
||||
/* Binding for each surface */
|
||||
m_shaderDataBindings.clear();
|
||||
m_shaderDataBindings.reserve(x0_surfaces->size());
|
||||
|
||||
std::vector<boo::ITexture*> texs;
|
||||
std::vector<size_t> thisOffs;
|
||||
std::vector<size_t> thisSizes;
|
||||
thisOffs.reserve(3);
|
||||
thisSizes.reserve(3);
|
||||
size_t thisOffs[3];
|
||||
size_t thisSizes[3];
|
||||
|
||||
/* Enumerate surfaces and build data bindings */
|
||||
for (const CBooSurface& surf : *x0_surfaces)
|
||||
|
@ -133,28 +130,30 @@ void CBooModel::BuildGfxToken()
|
|||
texs.push_back(tex.GetObj()->GetBooTexture());
|
||||
}
|
||||
|
||||
size_t thisBufCount = 2;
|
||||
|
||||
if (m_skinBankCount)
|
||||
{
|
||||
thisOffs.push_back(skinOffs[surf.m_data.skinMtxBankIdx]);
|
||||
thisSizes.push_back(skinSizes[surf.m_data.skinMtxBankIdx]);
|
||||
thisOffs[0] = skinOffs[surf.m_data.skinMtxBankIdx];
|
||||
thisSizes[0] = skinSizes[surf.m_data.skinMtxBankIdx];
|
||||
}
|
||||
else
|
||||
{
|
||||
thisOffs.push_back(0);
|
||||
thisSizes.push_back(256);
|
||||
thisOffs[0] = 0;
|
||||
thisSizes[0] = 256;
|
||||
}
|
||||
|
||||
if (mat.uvAnims.size())
|
||||
{
|
||||
thisOffs.push_back(uvOffs[surf.m_data.matIdx]);
|
||||
thisSizes.push_back(uvSizes[surf.m_data.matIdx]);
|
||||
++thisBufCount;
|
||||
thisOffs[1] = uvOffs[surf.m_data.matIdx];
|
||||
thisSizes[1] = uvSizes[surf.m_data.matIdx];
|
||||
}
|
||||
else
|
||||
{
|
||||
thisOffs[1] = 0;
|
||||
thisSizes[1] = 0;
|
||||
}
|
||||
|
||||
thisOffs.push_back(lightOff);
|
||||
thisSizes.push_back(lightSz);
|
||||
thisOffs[2] = lightOff;
|
||||
thisSizes[2] = lightSz;
|
||||
|
||||
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)
|
||||
extendeds.push_back(
|
||||
ctx.newShaderDataBinding(pipeline, m_vtxFmt,
|
||||
x8_vbo, nullptr, xc_ibo, thisBufCount, bufs.data(),
|
||||
thisOffs.data(), thisSizes.data(), mat.textureIdxs.size(), texs.data()));
|
||||
|
||||
thisOffs.clear();
|
||||
thisSizes.clear();
|
||||
x8_vbo, nullptr, xc_ibo, 3, bufs,
|
||||
thisOffs, thisSizes, mat.textureIdxs.size(), texs.data()));
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
@ -186,7 +182,7 @@ void CBooModel::MakeTexuresFromMats(const MaterialSet& matSet,
|
|||
|
||||
void CBooModel::ActivateLights(const std::vector<CLight>& lights)
|
||||
{
|
||||
zeus::CColor ambientAccum = zeus::CColor::skBlack;
|
||||
m_lightingData.ambient = zeus::CColor::skBlack;
|
||||
size_t curLight = 0;
|
||||
|
||||
for (const CLight& light : lights)
|
||||
|
@ -194,7 +190,7 @@ void CBooModel::ActivateLights(const std::vector<CLight>& lights)
|
|||
switch (light.x1c_type)
|
||||
{
|
||||
case ELightType::LocalAmbient:
|
||||
ambientAccum += light.x18_color;
|
||||
m_lightingData.ambient += light.x18_color;
|
||||
break;
|
||||
case ELightType::Point:
|
||||
case ELightType::Spot:
|
||||
|
@ -206,6 +202,7 @@ void CBooModel::ActivateLights(const std::vector<CLight>& lights)
|
|||
CModelShaders::Light& lightOut = m_lightingData.lights[curLight++];
|
||||
lightOut.pos = CGraphics::g_CameraMatrix * light.x0_pos;
|
||||
lightOut.dir = CGraphics::g_CameraMatrix.m_basis * light.xc_dir;
|
||||
lightOut.dir.normalize();
|
||||
lightOut.color = light.x18_color;
|
||||
lightOut.linAtt[0] = light.x24_distC;
|
||||
lightOut.linAtt[1] = light.x28_distL;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "CModelShaders.hpp"
|
||||
#include "hecl/Backend/GLSL.hpp"
|
||||
|
||||
namespace urde
|
||||
{
|
||||
|
@ -27,14 +28,14 @@ static const char* LightingGLSL =
|
|||
" {\n"
|
||||
" vec3 delta = mvPosIn.xyz - lights[i].pos.xyz;\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"
|
||||
" lights[i].linAtt[1] * dist +\n"
|
||||
" lights[i].linAtt[0]);\n"
|
||||
" float angAtt = lights[i].angAtt[2] * angDot * angDot +\n"
|
||||
" lights[i].angAtt[1] * angDot +\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"
|
||||
" 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
|
||||
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);
|
||||
ext.registerExtensionSlot({LightingGLSL, "LightingFunc"}, {});
|
||||
ext.registerExtensionSlot({LightingGLSL, "LightingFunc"}, {}, 3, BlockNames);
|
||||
return ext;
|
||||
}
|
||||
|
||||
|
|
2
hecl
2
hecl
|
@ -1 +1 @@
|
|||
Subproject commit 11c8c744fd62770660506d271ea9eff858ea4138
|
||||
Subproject commit d5f9da3914d0ae1f4b4a4d8d0fddde160e406a6e
|
2
specter
2
specter
|
@ -1 +1 @@
|
|||
Subproject commit 33ce8bc20ba776e5868230aec459cd31c7e6554b
|
||||
Subproject commit d49a33ec1b936052ff1b4d02586748d59a27c174
|
Loading…
Reference in New Issue