Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Effect - Trail - Render.c
    »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".                                                   */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */

#define T_NAME( A, ... ) A##Trail##__VA_ARGS__
#define T_TYPE( A, ... ) A##TRAIL##__VA_ARGS__
#define T_TEXT( ... ) __VA_ARGS__ TgT("Trail")
#define T_EFFECT_FRAME 0
#define T_EFFECT_TIME_DEFAULT 0
#define T_EFFECT_PROCESS_COMMMAND_DEFAULT 0

#include "TgS Effect - Effect - Type.h_inc"
#include "TgS Effect - Render.inl"


/* == Effect ============================================================================================================================================================ */

/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Shared Implementation                                                                                                                                                 */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

#include "TgS Effect - Effect - Render.c_inc"




/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  File Local Types                                                                                                                                                      */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

TgTYPE_STRUCT(STg2_FX__Trail__Render_Point,)
{
    /* --------------- Input --------------- */
    P_STg2_FX__Trail                            m_psTrail;
    CP_STg2_FX_Trail__File_Data                 m_psFile_Data;
    TgVEC_M_F32_04                              m_vCam_Forward;
    TgVEC_M_F32_04                              m_vCL;

    /* --------------- Output -------------- */
    TgVEC_M_F32_04                              m_vS0_W;
    TgVEC_M_F32_04                              m_vS1_W;
    TgVEC_M_F32_04                              m_vT0_W;
    TgVEC_M_F32_04                              m_vB0_W;
    TgVEC_M_F32_04                              m_vScale_U;
    TgVEC_M_F32_04                              m_vN0;
    TgUINT32                                    m_uiNext_Point;
    TgUINT32                                    m_uiPad0[3];
};




/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  File Local Functions                                                                                                                                                  */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

static TgSIZE                                        tgFX_Effect__Trail__Render_Quad_Count( P_STg2_FX__Trail );
static TgVOID                                        tgFX_Effect__Trail__Render_Calculate_Point( P_STg2_FX__Trail, P_STg2_FX__Trail__Render_Point, C_TgUINT32 );
TgFORCEINLINE TgBOOL                                 tgFX_Effect__Trail__Render_Calculate_Vertex_00(
                                                         P_STg2_RN_Vertex_Particle_00, C_TgSIZE, C_TgSIZE, P_STg2_FX__Trail__Render_Point );
TgFORCEINLINE TgBOOL                                 tgFX_Effect__Trail__Render_Calculate_Vertex_01(
                                                         P_STg2_RN_Vertex_Particle_01, C_TgSIZE, C_TgSIZE, P_STg2_FX__Trail__Render_Point );




/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Parent File Local Functions                                                                                                                                           */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

/* ---- tgFX__Render__Trail_Render_Memory_Particle_00 --------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgSIZE tgFX__Render__Trail_Render_Memory_Particle_00( P_STg2_FX__Trail psTrail )
{
    return (4 * tgFX_Effect__Trail__Render_Quad_Count( psTrail ) * sizeof( STg2_RN_Vertex_Particle_00 ));
}


/* ---- tgFX__Render__Trail_Render_Memory_Particle_01 --------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgSIZE tgFX__Render__Trail_Render_Memory_Particle_01( P_STg2_FX__Trail psTrail )
{
    return (4 * tgFX_Effect__Trail__Render_Quad_Count( psTrail ) * sizeof( STg2_RN_Vertex_Particle_01 ));
}


/* ---- tgFX__Render__Trail_Render_Generate_Particle_00 ----------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
#define T(A) A##_00
#include "TgS Effect - Trail - Render.c_inc"
#undef T


/* ---- tgFX__Render__Trail_Render_Generate_Particle_01 ----------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
#define T(A) A##_01
#include "TgS Effect - Trail - Render.c_inc"
#undef T




/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  File Local Functions                                                                                                                                                  */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

/* ---- tgFX_Effect__Trail__Render_Quad_Count --------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgSIZE tgFX_Effect__Trail__Render_Quad_Count( P_STg2_FX__Trail psTrail )
{
    P_STg2_FX__Trail__Extend_Data       psExtend;
    TgUINT32                            uiPoint;
    TgSIZE                              nuiQuad;

    psExtend = &(psTrail->m_sExtend);
    if (psExtend->m_uiPoint_Head == psExtend->m_uiPoint_Tail)
    {
        return (0);
    };

    uiPoint = (psExtend->m_uiPoint_Head + KTgFX_MAX_POINTS_IN_TRAIL - 1) % KTgFX_MAX_POINTS_IN_TRAIL;
    nuiQuad = 0;
    if (uiPoint != psExtend->m_uiPoint_Tail)
    {
        uiPoint = (uiPoint + KTgFX_MAX_POINTS_IN_TRAIL - 1) % KTgFX_MAX_POINTS_IN_TRAIL;
        ++nuiQuad;
    };

    return (nuiQuad);
}


/* ---- tgFX_Effect__Trail__Render_Calculate_Point ---------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
static TgVOID tgFX_Effect__Trail__Render_Calculate_Point( P_STg2_FX__Trail psTrail, P_STg2_FX__Trail__Render_Point psPoint, C_TgUINT32 uiPoint )
{
    P_STg2_FX__Trail__Extend_Data       psExtend;
    TgVEC_M_F32_04                      vPrev_S0_W;
    TgVEC_M_F32_04                      vPrev_T0_W;
    TgVEC_M_F32_04                      vSN0_W;
    TgVEC_M_F32_04                      vSN1_W;
    TgVEC_M_F32_04                      vQuad_BI;
    TgVEC_M_F32_04                      vB1;

    psExtend = &(psTrail->m_sExtend);
    vPrev_S0_W = psPoint->m_vS0_W;
    vPrev_T0_W = psPoint->m_vT0_W;

    psPoint->m_uiNext_Point = (uiPoint + KTgFX_MAX_POINTS_IN_TRAIL - 1) % KTgFX_MAX_POINTS_IN_TRAIL;
    vSN0_W = psExtend->m_vPos_W[uiPoint];
    vSN1_W = psExtend->m_vPos_W[psPoint->m_uiNext_Point];

    psPoint->m_vT0_W = M_NORM_F32_04( M_SUB_F32_04( vSN1_W, vSN0_W ) );
    psPoint->m_vB0_W = M_UCX_F32_04( psPoint->m_vCam_Forward, psPoint->m_vT0_W );
    vQuad_BI = M_MUL_F32_04( psPoint->m_vB0_W, psExtend->m_vWidth );
    psPoint->m_vScale_U = M_MUL_F32_04( MS_SET1_F32_04( psExtend->m_fU[uiPoint] ), psTrail->m_psFile_Data->m_vScale_U );
    psPoint->m_vS0_W = M_SUB_F32_04( vSN0_W, vQuad_BI );
    psPoint->m_vS1_W = M_ADD_F32_04( vSN0_W, vQuad_BI );

    if (uiPoint != psExtend->m_uiPoint_Head)
    {
        vB1 = M_NORM_F32_04( M_SUB_F32_04( psPoint->m_vS1_W, vPrev_S0_W ) );
        psPoint->m_vN0 = M_CX_F32_04( vPrev_T0_W, vB1 );
    };
}


/* ---- tgFX_Effect__Trail__Render_Calculate_Vertex_00 ------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgFORCEINLINE TgBOOL tgFX_Effect__Trail__Render_Calculate_Vertex_00(
    P_STg2_RN_Vertex_Particle_00 psVert, C_TgSIZE uiPoint0, C_TgSIZE uiPoint1, P_STg2_FX__Trail__Render_Point psPoint )
{
    TgBOOL                              bQuad_Camera_Facing;
    TgVEC_F32_04                        vDirTest;

    vDirTest.m_mData = M_DOT_F32_04( psPoint->m_vN0, psPoint->m_vCam_Forward );
    bQuad_Camera_Facing = tgCM_NR0_F32( vDirTest.m.x );
    if (TgTRUE == bQuad_Camera_Facing)
    {
        psVert[uiPoint0].m_vS0.m_mData = psPoint->m_vS0_W;
        psVert[uiPoint0].m_vUV.m_mData = M_MAD_F32_04( psPoint->m_vScale_U, psPoint->m_psTrail->m_sExtend.m_vUV_01_Scale, psPoint->m_psTrail->m_sExtend.m_vUV_01_Constant );
        psVert[uiPoint1].m_vS0.m_mData = psPoint->m_vS1_W;
        psVert[uiPoint1].m_vUV.m_mData = M_MAD_F32_04( psPoint->m_psFile_Data->m_vScale_V, psPoint->m_psTrail->m_sExtend.m_vUV_01_Scale, psVert[uiPoint0].m_vUV.m_mData );
    }
    else
    {
        psVert[uiPoint1].m_vS0.m_mData = psPoint->m_vS0_W;
        psVert[uiPoint1].m_vUV.m_mData = M_MAD_F32_04( psPoint->m_vScale_U, psPoint->m_psTrail->m_sExtend.m_vUV_01_Scale, psPoint->m_psTrail->m_sExtend.m_vUV_01_Constant );
        psVert[uiPoint0].m_vS0.m_mData = psPoint->m_vS1_W;
        psVert[uiPoint0].m_vUV.m_mData = M_MAD_F32_04( psPoint->m_psFile_Data->m_vScale_V, psPoint->m_psTrail->m_sExtend.m_vUV_01_Scale, psVert[uiPoint1].m_vUV.m_mData );
    };

    psVert[uiPoint0].m_vCL.m_mData = psPoint->m_vCL;
    psVert[uiPoint1].m_vCL.m_mData = psPoint->m_vCL;

    return (bQuad_Camera_Facing);
}


/* ---- tgFX_Effect__Trail__Render_Calculate_Vertex_01 ------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgFORCEINLINE TgBOOL tgFX_Effect__Trail__Render_Calculate_Vertex_01(
    P_STg2_RN_Vertex_Particle_01 psVert, C_TgSIZE uiPoint0, C_TgSIZE uiPoint1, P_STg2_FX__Trail__Render_Point psPoint )
{
    TgBOOL                              bQuad_Camera_Facing;
    TgVEC_F32_04                        vDirTest;

    vDirTest.m_mData = M_DOT_F32_04( psPoint->m_vN0, psPoint->m_vCam_Forward );
    bQuad_Camera_Facing = tgCM_NR0_F32( vDirTest.m.x );
    if (TgTRUE == bQuad_Camera_Facing)
    {
        psVert[uiPoint0].m_vS0.m_mData = psPoint->m_vS0_W;
        psVert[uiPoint0].m_vUV.m_mData = M_MAD_F32_04( psPoint->m_vScale_U, psPoint->m_psTrail->m_sExtend.m_vUV_01_Scale, psPoint->m_psTrail->m_sExtend.m_vUV_01_Constant );
        psVert[uiPoint1].m_vS0.m_mData = psPoint->m_vS1_W;
        psVert[uiPoint1].m_vUV.m_mData = M_MAD_F32_04( psPoint->m_psFile_Data->m_vScale_V, psPoint->m_psTrail->m_sExtend.m_vUV_01_Scale, psVert[uiPoint0].m_vUV.m_mData );
    }
    else
    {
        psVert[uiPoint1].m_vS0.m_mData = psPoint->m_vS0_W;
        psVert[uiPoint1].m_vUV.m_mData = M_MAD_F32_04( psPoint->m_vScale_U, psPoint->m_psTrail->m_sExtend.m_vUV_01_Scale, psPoint->m_psTrail->m_sExtend.m_vUV_01_Constant );
        psVert[uiPoint0].m_vS0.m_mData = psPoint->m_vS1_W;
        psVert[uiPoint0].m_vUV.m_mData = M_MAD_F32_04( psPoint->m_psFile_Data->m_vScale_V, psPoint->m_psTrail->m_sExtend.m_vUV_01_Scale, psVert[uiPoint1].m_vUV.m_mData );
    };

    psVert[uiPoint0].m_vT0.m_mData = psPoint->m_vT0_W;
    psVert[uiPoint0].m_vB0.m_mData = psPoint->m_vB0_W;
    psVert[uiPoint0].m_vCL.m_mData = psPoint->m_vCL;
    psVert[uiPoint1].m_vT0.m_mData = psPoint->m_vT0_W;
    psVert[uiPoint1].m_vB0.m_mData = psPoint->m_vB0_W;
    psVert[uiPoint1].m_vCL.m_mData = psPoint->m_vCL;

    return (bQuad_Camera_Facing);
}