CElementGen TIND updates

This commit is contained in:
Jack Andersen 2016-02-24 16:55:38 -10:00
parent c8e0f886c6
commit 23688360c9
8 changed files with 64 additions and 30 deletions

View File

@ -21,10 +21,11 @@ namespace URDE
void ViewManager::BuildTestPART(pshag::IObjectStore& objStore)
{
//m_partGenDesc = objStore.GetObj({HECL::FOURCC('PART'), 0x972A5CD2});
m_partGenDesc = objStore.GetObj("WallSpark");
m_partGenDesc = objStore.GetObj("PART_EnvRainSplash");
m_partGen.reset(new pshag::CElementGen(m_partGenDesc,
pshag::CElementGen::EModelOrientationType::Normal,
pshag::CElementGen::EOptionalSystemFlags::None));
m_partGen->SetGlobalScale({5.f, 5.f, 5.f});
m_particleView.reset(new ParticleView(*this, m_viewResources, *m_rootView));
m_lineRenderer.reset(new pshag::CLineRenderer(pshag::CLineRenderer::EPrimitiveMode::LineStrip, 4, nullptr, true));
@ -218,7 +219,7 @@ void ViewManager::init(boo::IApplication* app)
m_mainWindow->setWaitCursor(false);
pshag::CGraphics::InitializeBoo(gf, m_mainWindow->getCommandQueue());
pshag::CGraphics::InitializeBoo(gf, m_mainWindow->getCommandQueue(), root->renderTex());
pshag::CElementGen::Initialize();
pshag::CLineRenderer::Initialize();
}

View File

@ -148,16 +148,14 @@ Zeus::CVector2i CGraphics::ProjectPoint(const Zeus::CVector3f& point)
{
Zeus::CVector3f projPt = GetPerspectiveProjectionMatrix().multiplyOneOverW(point);
return {int(projPt.x * g_ViewportResolutionHalf.x) + g_ViewportResolutionHalf.x,
int(projPt.y * g_ViewportResolutionHalf.y) + g_ViewportResolutionHalf.y};
g_ViewportResolution.y - (int(projPt.y * g_ViewportResolutionHalf.y) + g_ViewportResolutionHalf.y)};
}
SClipScreenRect CGraphics::ClipScreenRectFromMS(const Zeus::CVector3f& p1,
const Zeus::CVector3f& p2)
{
Zeus::CVector3f xf2 = (g_GXModelMatrix * p2) - g_ViewMatrix.m_origin;
xf2 = g_ViewMatrix.transposeRotate(xf2);
Zeus::CVector3f xf1 = (g_GXModelMatrix * p1) - g_ViewMatrix.m_origin;
xf1 = g_ViewMatrix.transposeRotate(xf1);
Zeus::CVector3f xf1 = g_GXModelView * p1;
Zeus::CVector3f xf2 = g_GXModelView * p2;
return ClipScreenRectFromVS(xf1, xf2);
}
@ -208,14 +206,13 @@ SClipScreenRect CGraphics::ClipScreenRectFromVS(const Zeus::CVector3f& p1,
int width = maxX2 - minX2;
int height = maxY2 - minY2;
return {true, minX2, minY2, width, height, width,
(finalMinX - minX2) / float(width), (finalMaxX - minX2) / float(width),
(finalMinY - minY2) / float(height), (finalMaxY - minY2) / float(height)};
minX2 / float(g_ViewportResolution.x), maxX2 / float(g_ViewportResolution.x),
minY2 / float(g_ViewportResolution.y), maxY2 / float(g_ViewportResolution.y)};
}
Zeus::CVector3f CGraphics::ProjectModelPointToViewportSpace(const Zeus::CVector3f& point)
{
CProjectionState& pst = g_Proj;
Zeus::CVector3f pt = g_GXModelView * point;
return GetPerspectiveProjectionMatrix().multiplyOneOverW(pt);
}

View File

@ -188,10 +188,13 @@ public:
static boo::IGraphicsCommandQueue* g_BooMainCommandQueue;
static boo::ITextureR* g_SpareTexture;
static void InitializeBoo(boo::IGraphicsDataFactory* factory, boo::IGraphicsCommandQueue* cc)
static void InitializeBoo(boo::IGraphicsDataFactory* factory,
boo::IGraphicsCommandQueue* cc,
boo::ITextureR* spareTex)
{
g_BooFactory = factory;
g_BooMainCommandQueue = cc;
g_SpareTexture = spareTex;
}
static boo::IGraphicsBufferD* NewDynamicGPUBuffer(boo::BufferUse use, size_t stride, size_t count)
@ -206,6 +209,11 @@ public:
{
g_BooMainCommandQueue->setShaderDataBinding(binding);
}
static void ResolveSpareTexture(const SClipScreenRect& rect)
{
boo::SWindowRect wrect = {rect.x4_left, rect.x8_top, rect.xc_width, rect.x10_height};
g_BooMainCommandQueue->resolveBindTexture(g_SpareTexture, wrect, true);
}
static void DrawInstances(size_t start, size_t count, size_t instCount)
{
g_BooMainCommandQueue->drawInstances(start, count, instCount);

View File

@ -238,7 +238,7 @@ int CMain::appMain(boo::IApplication* app)
boo::IGraphicsCommandQueue* gfxQ = mainWindow->getCommandQueue();
boo::SWindowRect windowRect = mainWindow->getWindowFrame();
boo::ITextureR* renderTex = mainWindow->getMainContextDataFactory()->newRenderTexture(windowRect.size[0], windowRect.size[1]);
boo::ITextureR* renderTex = mainWindow->getMainContextDataFactory()->newRenderTexture(windowRect.size[0], windowRect.size[1], true, true);
float rgba[4] = { 0.2f, 0.2f, 0.2f, 1.0f};
gfxQ->setClearColor(rgba);

View File

@ -361,6 +361,7 @@ CElementGen::CElementGen(const TToken<CGenDescription>& gen,
CIntElement* maxpElem = desc->x28_MAXP.get();
if (maxpElem)
maxpElem->GetValue(x50_curFrame, x70_MAXP);
x70_MAXP = 1;
x2c_particleLists.reserve(x70_MAXP);
if (x28_orientType == EModelOrientationType::One)
@ -526,6 +527,7 @@ bool CElementGen::InternalUpdate(double dt)
CIntElement* maxpElem = desc->x28_MAXP.get();
if (maxpElem)
maxpElem->GetValue(x50_curFrame, x70_MAXP);
x70_MAXP = 1;
UpdateExistingParticles();
@ -1511,7 +1513,7 @@ void CElementGen::RenderParticles()
CUVElement* tind = desc->x58_TIND.get();
if (texr && tind)
{
//RenderParticlesIndirectTexture();
RenderParticlesIndirectTexture();
return;
}
@ -1872,6 +1874,13 @@ void CElementGen::RenderParticlesIndirectTexture()
systemViewPointMatrix = ((Zeus::CTransform::Translate(x88_globalTranslation) * xac_globalScaleTransform) * systemViewPointMatrix) * x118_localScaleTransform;
CGraphics::SetModelMatrix(systemViewPointMatrix);
SParticleUniforms uniformData =
{
CGraphics::GetPerspectiveProjectionMatrix() * CGraphics::g_GXModelView.toMatrix4f(),
{1.f, 1.f, 1.f, 1.f}
};
m_uniformBuf->load(&uniformData, sizeof(SParticleUniforms));
CGraphics::SetAlphaCompare(ERglAlphaFunc::Always, 0, ERglAlphaOp::And, ERglAlphaFunc::Always, 0);
if (x224_26_AAPH)
@ -1935,6 +1944,11 @@ void CElementGen::RenderParticlesIndirectTexture()
{return a.x4_viewPoint[1] >= b.x4_viewPoint[1];});
}
CGraphics::SetShaderDataBinding(m_normalDataBind);
g_instIndTexData.clear();
g_instIndTexData.reserve(x2c_particleLists.size());
for (CParticleListItem& item : x2c_particleLists)
{
CParticle& particle = g_StaticParticleList[item.x0_partIdx];
@ -1971,7 +1985,6 @@ void CElementGen::RenderParticlesIndirectTexture()
if (!constIndUVs)
tind->GetValueUV(partFrame, uvsInd);
float size = 0.5f * particle.x2c_lineLengthOrSize;
Zeus::CVector3f p1 = {viewPoint.x - size, viewPoint.y, viewPoint.z - size};
Zeus::CVector3f p2 = {viewPoint.x + size, viewPoint.y, viewPoint.z + size};
@ -1980,14 +1993,27 @@ void CElementGen::RenderParticlesIndirectTexture()
if (!clipRect.x0_valid)
continue;
/* Perform render-to-texture */
CGraphics::ResolveSpareTexture(clipRect);
/* Draw: */
/* Pos: {viewPoint.x + size, viewPoint.y, viewPoint.z + size} Color: particle.color UV0: {uva[2], uva[3]} UV1: {clip.xmax, clip.ymax} UV2: {uvb[2], uvb[3]} */
/* Pos: {viewPoint.x - size, viewPoint.y, viewPoint.z + size} Color: particle.color UV0: {uva[0], uva[3]} UV1: {clip.xmin, clip.ymax} UV2: {uvb[0], uvb[3]} */
/* Pos: {viewPoint.x - size, viewPoint.y, viewPoint.z - size} Color: particle.color UV0: {uva[0], uva[1]} UV1: {clip.xmin, clip.ymin} UV2: {uvb[0], uvb[1]} */
/* Pos: {viewPoint.x + size, viewPoint.y, viewPoint.z - size} Color: particle.color UV0: {uva[2], uva[1]} UV1: {clip.xmax, clip.ymin} UV2: {uvb[2], uvb[1]} */
g_instIndTexData.emplace_back();
SParticleInstanceIndTex& inst = g_instIndTexData.back();
inst.pos[0] = Zeus::CVector4f{viewPoint.x + size, viewPoint.y, viewPoint.z + size, 1.f};
inst.pos[1] = Zeus::CVector4f{viewPoint.x - size, viewPoint.y, viewPoint.z + size, 1.f};
inst.pos[2] = Zeus::CVector4f{viewPoint.x + size, viewPoint.y, viewPoint.z - size, 1.f};
inst.pos[3] = Zeus::CVector4f{viewPoint.x - size, viewPoint.y, viewPoint.z - size, 1.f};
inst.color = particle.x34_color;
inst.texrTindUVs[0] = Zeus::CVector4f{uvs.xMax, uvs.yMax, uvsInd.xMax, uvsInd.yMax};
inst.texrTindUVs[1] = Zeus::CVector4f{uvs.xMin, uvs.yMax, uvsInd.xMin, uvsInd.yMax};
inst.texrTindUVs[2] = Zeus::CVector4f{uvs.xMax, uvs.yMin, uvsInd.xMax, uvsInd.yMin};
inst.texrTindUVs[3] = Zeus::CVector4f{uvs.xMin, uvs.yMin, uvsInd.xMin, uvsInd.yMin};
inst.sceneUVs[0] = {clipRect.x1c_uvXMax, clipRect.x24_uvYMax};
inst.sceneUVs[1] = {clipRect.x18_uvXMin, clipRect.x24_uvYMax};
inst.sceneUVs[2] = {clipRect.x1c_uvXMax, clipRect.x20_uvYMin};
inst.sceneUVs[3] = {clipRect.x18_uvXMin, clipRect.x20_uvYMin};
}
m_instBuf->load(g_instIndTexData.data(), g_instIndTexData.size() * sizeof(SParticleInstanceIndTex));
CGraphics::DrawInstances(0, 4, g_instIndTexData.size());
}
void CElementGen::SetOrientation(const Zeus::CTransform& orientation)

View File

@ -121,8 +121,9 @@ BOO_GLSL_BINDING_HEAD
" vec2 tindTexel = texture(texs[2], vtf.uvTind).ba;\n"
" vec4 sceneTexel = texture(texs[1], vtf.uvScene + tindTexel);\n"
" vec4 texrTexel = texture(texs[0], vtf.uvTexr);\n"
" colorOut = vtf.color * sceneTexel + texrTexel;\n"
" colorOut.a = vtf.color.a * texrTexel.a;"
" //colorOut = vtf.color * sceneTexel + texrTexel;\n"
" colorOut = sceneTexel + vec4(0.5, 0.0, 0.0, 1.0);\n"
" //colorOut.a = vtf.color.a * texrTexel.a;\n"
"}\n";
static const char* FS_GLSL_CINDTEX =
@ -144,6 +145,7 @@ BOO_GLSL_BINDING_HEAD
" vec2 tindTexel = texture(texs[2], vtf.uvTind).ba;\n"
" vec4 sceneTexel = texture(texs[1], vtf.uvScene + tindTexel);\n"
" colorOut = vtf.color * sceneTexel * texture(texs[0], vtf.uvTexr);\n"
" //colorOut = vec4(1.0,1.0,1.0,1.0);\n"
"}\n";
static const char* VS_GLSL_NOTEX =
@ -302,23 +304,23 @@ CElementGenShaders::IDataBindingFactory* CElementGenShaders::Initialize(boo::GLD
m_indTexZWrite = factory.newShaderPipeline(VS_GLSL_INDTEX, FS_GLSL_INDTEX, 3, "texs", 1, UniNames,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
true, true, false);
false, true, false);
m_indTexNoZWrite = factory.newShaderPipeline(VS_GLSL_INDTEX, FS_GLSL_INDTEX, 3, "texs", 1, UniNames,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
true, false, false);
false, false, false);
m_indTexAdditive = factory.newShaderPipeline(VS_GLSL_INDTEX, FS_GLSL_INDTEX, 3, "texs", 1, UniNames,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::One,
true, true, false);
false, true, false);
m_cindTexZWrite = factory.newShaderPipeline(VS_GLSL_INDTEX, FS_GLSL_CINDTEX, 3, "texs", 1, UniNames,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
true, true, false);
false, true, false);
m_cindTexNoZWrite = factory.newShaderPipeline(VS_GLSL_INDTEX, FS_GLSL_CINDTEX, 3, "texs", 1, UniNames,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
true, false, false);
false, false, false);
m_cindTexAdditive = factory.newShaderPipeline(VS_GLSL_INDTEX, FS_GLSL_CINDTEX, 3, "texs", 1, UniNames,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::One,
true, true, false);
false, true, false);
m_noTexZTestZWrite = factory.newShaderPipeline(VS_GLSL_NOTEX, FS_GLSL_NOTEX, 0, nullptr, 1, UniNames,
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,

2
hecl

@ -1 +1 @@
Subproject commit c9ab996170ff1b0c381324825188e8c4685b7ddb
Subproject commit eafdeee33bdb7d7a1230d687565c0ef5c0b2d6a2

@ -1 +1 @@
Subproject commit c7b25516f025e3c7d7eed30712145cdb249dad05
Subproject commit aac0b93f64ba8e5d6bdf718a5ea5d78226a80a49