Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Effect - Emitter - Render.c_inc
    »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
    »Version«   4.51 / »GUID« A9981407-3EC9-42AF-8B6F-8BE6DD919615                                                                                                        */
/*   -------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
/*  Copyright: © 2002-2017, Andrew Aye.  All Rights Reserved.
    This software is free for non-commercial use.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
      following conditions are met:
        Redistribution of source code must retain this copyright notice, this list of conditions and the following disclaimers.
        Redistribution in binary form must reproduce this copyright notice, this list of conditions and the following disclaimers in the documentation and other materials
          provided with the distribution.
    The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
    The intellectual property rights of the algorithms used reside with Andrew Aye.
    You may not use this software, in whole or in part, in support of any commercial product without the express written consent of the author.
    There is no warranty or other guarantee of fitness of this software for any purpose. It is provided solely "as is".                                                   */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/* == Effect ============================================================================================================================================================ */

/* ---- T(tgFX__Render__Emitter_Render_Generate_Particle) --------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
static TgUINT32 T(tgFX__Render__Emitter_Render_Generate_Particle)( PC_STg2_FX_Rnd_Output psRndOut, PC_STg2_RN_Particle_Header psHeader, P_STg2_FX__Emitter psEmitter )
{
    union
    {
        P_TgUINT08                          pui;
        T(P_STg2_RN_Vertex_Particle)        ps;
    }                                   sVert;
    TgSIZE                              uiQuad_Size;
    TgSIZE                              nuiMaxQuad;
    STg2_FX__Emitter__Render_Point      sPoint;
    P_STg2_FX__Emitter__Particle        psParticle;
    TgUINT32                            nuiQuad;
    TgSINT32                            iVert;

    sVert.pui = psRndOut->m_puiBuffer + psHeader->m_uiBuffer_Offset;
    uiQuad_Size = 4 * sizeof( T(STg2_RN_Vertex_Particle) );
    nuiMaxQuad = psHeader->m_uiBuffer_Size / uiQuad_Size;
    TgERROR( nuiMaxQuad >= 1 );

    memset( &sPoint, 0, sizeof( sPoint ) );
    sPoint.m_psEmitter = psEmitter;
    tgFX_Effect__Emitter__Render_Init_Point( &sPoint, psRndOut );

    if (ETgFX_PARTICLE_ORIENTATION__VELOCITY_TANGENT == sPoint.m_psExtend->m_psFile_Data__Particle->m_enOrientation)
    {
        return (T(tgFX__Render__Emitter_Render_Generate_Particle_Tangent)( &sPoint, psRndOut, psHeader, psEmitter ));
    };

    tgFX_Effect__Emitter__Reference_Frame( &sPoint, psEmitter->m_vPos_W );

    psParticle = sPoint.m_psExtend->m_psParticle_Active;
    nuiQuad = 0;
    while ((nuiQuad < nuiMaxQuad) && (nullptr != psParticle))
    {
        tgRN_M_Calc_UV_Animation( &psParticle->m_vUV_01_Constant, &psParticle->m_vUV_01_Scale, psEmitter->m_tiMaterial, psRndOut->m_vdT, psParticle->m_vLive_Time );
        tgFX_Effect__Emitter__Render_Calculate_Point( &sPoint, psParticle );

        T(tgFX_Effect__Emitter__Render_Write_Quad)( sVert.ps + 4 * nuiQuad, &sPoint, psParticle );
        for (iVert = 0; iVert < 4; ++iVert)
        {
            psEmitter->m_vBA_Max_W = M_MAX_F32_04( psEmitter->m_vBA_Max_W, sPoint.m_avPos_W[iVert] );
            psEmitter->m_vBA_Min_W = M_MIN_F32_04( psEmitter->m_vBA_Min_W, sPoint.m_avPos_W[iVert] );
        };

        ++nuiQuad;
        psParticle = psParticle->m_psNext;
    }

    if (ETgFX_PARTICLE_ORIENTATION__SCREEN_SPACE == sPoint.m_psExtend->m_psFile_Data__Particle->m_enOrientation)
    {
        psEmitter->m_vBA_Max_W = MS_SET1_F32_04(  KTgMAX_F32 );
        psEmitter->m_vBA_Min_W = MS_SET1_F32_04( -KTgMAX_F32 );
    }

    return (TgUINT32)(4 * nuiQuad);
}


/* ---- T(tgFX__Render__Emitter_Render_Generate_Particle_Tangent) ------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
static TgUINT32 T(tgFX__Render__Emitter_Render_Generate_Particle_Tangent)(
    P_STg2_FX__Emitter__Render_Point psPoint, PC_STg2_FX_Rnd_Output psRndOut, PC_STg2_RN_Particle_Header psHeader, P_STg2_FX__Emitter psEmitter )
{
    union
    {
        P_TgUINT08                          pui;
        T(P_STg2_RN_Vertex_Particle)        ps;
    }                                   sVert;
    TgSIZE                              uiQuad_Size;
    TgSIZE                              nuiMaxQuad;
    TgVEC_M_F32_04                      vL_Vel_Acceleration_W;
    P_STg2_FX__Emitter__Particle        psParticle;
    TgUINT32                            nuiQuad;
    TgVEC_M_F32_04                      vLive_Time_Squared;
    TgVEC_M_F32_04                      vAccel_W;
    TgVEC_M_F32_04                      vVel_W;
    TgSINT32                            iVert;

    sVert.pui = psRndOut->m_puiBuffer + psHeader->m_uiBuffer_Offset;
    uiQuad_Size = 4 * sizeof( T(STg2_RN_Vertex_Particle) );
    nuiMaxQuad = psHeader->m_uiBuffer_Size / uiQuad_Size;
    TgERROR( nuiMaxQuad >= 1 );

    vL_Vel_Acceleration_W = psPoint->m_psExtend->m_psFile_Data__Particle->m_vL_Vel_Acceleration_W;

    psParticle = psPoint->m_psExtend->m_psParticle_Active;
    nuiQuad = 0;
    while ((nuiQuad < nuiMaxQuad) && (nullptr != psParticle))
    {
        vLive_Time_Squared = M_MUL_F32_04( psParticle->m_vLive_Time, psParticle->m_vLive_Time );
        vAccel_W = M_MUL_F32_04( vL_Vel_Acceleration_W, vLive_Time_Squared );
        vAccel_W = M_MUL_F32_04( MS_SET1_F32_04( 0.5F ), vAccel_W );
        vVel_W = M_ADD_F32_04( psParticle->m_vLVel_W, vAccel_W );

        psPoint->m_vRight = M_NORM_F32_04( vVel_W );
        psPoint->m_vUp = M_UCX_F32_04( psPoint->m_vCam_Forward, psPoint->m_vRight );

        tgRN_M_Calc_UV_Animation( &psParticle->m_vUV_01_Constant, &psParticle->m_vUV_01_Scale, psEmitter->m_tiMaterial, psRndOut->m_vdT, psParticle->m_vLive_Time );
        tgFX_Effect__Emitter__Render_Calculate_Point( psPoint, psParticle );

        T(tgFX_Effect__Emitter__Render_Write_Quad_Tangent)( sVert.ps + 4 * nuiQuad, psPoint, psParticle );

        for (iVert = 0; iVert < 4; ++iVert)
        {
            psEmitter->m_vBA_Max_W = M_MAX_F32_04( psEmitter->m_vBA_Max_W, psPoint->m_avPos_W[iVert] );
            psEmitter->m_vBA_Min_W = M_MIN_F32_04( psEmitter->m_vBA_Min_W, psPoint->m_avPos_W[iVert] );
        };

        ++nuiQuad;
    }

    return (TgUINT32)(4 * nuiQuad);
}