Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Effect - Billboard - 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##Billboard##__VA_ARGS__
#define T_TYPE( A, ... ) A##BILLBOARD##__VA_ARGS__
#define T_TEXT( ... ) __VA_ARGS__ TgT("Billboard")

#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__Billboard__Render_Point,)
{
    /* --------------- Input --------------- */
    P_STg2_FX__Billboard                        m_psBillboard;
    CP_STg2_FX_Billboard__File_Data             m_psFile_Data;
    TgVEC_M_F32_04                              m_vCam_Pos_W;
    TgVEC_M_F32_04                              m_vCam_Up;
    TgVEC_M_F32_04                              m_vCam_Forward;
    TgVEC_M_F32_04                              m_vUV_Mask[4];
    TgVEC_M_F32_04                              m_vBase_CL;

    /* --------------- Output -------------- */
    TgVEC_M_F32_04                              m_avPos_W[4];
    TgVEC_M_F32_04                              m_avBasis[2];
    TgVEC_M_F32_04                              m_vCL;
};




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

static TgVOID                                        tgFX_Effect__Billboard__Render_Init_Point( P_STg2_FX__Billboard__Render_Point, PC_STg2_FX_Rnd_Output );
static TgBOOL                                        tgFX_Effect__Billboard__Render_Common( P_STg2_FX__Billboard__Render_Point, TgVEC_M_F32_04 );
static TgVOID                                        tgFX_Effect__Billboard__Render_Reference_Frame( P_STg2_FX__Billboard__Render_Point );
TgFORCEINLINE TgVOID                                 tgFX_Effect__Billboard__Render_Write_Quad_00( P_STg2_RN_Vertex_Particle_00, P_STg2_FX__Billboard__Render_Point );
TgFORCEINLINE TgVOID                                 tgFX_Effect__Billboard__Render_Write_Quad_01( P_STg2_RN_Vertex_Particle_01, P_STg2_FX__Billboard__Render_Point );




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

/* ---- tgFX__Render__Billboard_Render_Memory_Particle_00 --------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
static TgSIZE tgFX__Render__Billboard_Render_Memory_Particle_00( P_STg2_FX__Billboard UNUSED_PARAM psBillboard )
{
    return (4 * sizeof( STg2_RN_Vertex_Particle_00 ));
}


/* ---- tgFX__Render__Billboard_Render_Memory_Particle_01 --------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
static TgSIZE tgFX__Render__Billboard_Render_Memory_Particle_01( P_STg2_FX__Billboard UNUSED_PARAM psBillboard )
{
    return (4 * sizeof( STg2_RN_Vertex_Particle_01 ));
}


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


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




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

/* ---- tgFX_Effect__Billboard__Render_Init_Point ----------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
static TgVOID tgFX_Effect__Billboard__Render_Init_Point( P_STg2_FX__Billboard__Render_Point psPoint, PC_STg2_FX_Rnd_Output psRndOut )
{
    psPoint->m_psFile_Data = psPoint->m_psBillboard->m_psFile_Data;
    psPoint->m_vCam_Pos_W = psRndOut->m_psCamera->m_sCamera.m_vCam_Position.m_mData;
    psPoint->m_vCam_Up = psRndOut->m_psCamera->m_vCam_Up.m_mData;
    psPoint->m_vCam_Forward = psRndOut->m_psCamera->m_vCam_Forward.m_mData;

    psPoint->m_vUV_Mask[0] = MS_SET_F32_04( 0.0F, 0.0F, 0.0F, 0.0F );
    psPoint->m_vUV_Mask[1] = MS_SET_F32_04( 0.0F, 1.0F, 0.0F, 1.0F );
    psPoint->m_vUV_Mask[2] = MS_SET_F32_04( 1.0F, 1.0F, 1.0F, 1.0F );
    psPoint->m_vUV_Mask[3] = MS_SET_F32_04( 1.0F, 0.0F, 1.0F, 0.0F );

    psPoint->m_vBase_CL = psPoint->m_psBillboard->m_sExtend.m_vColour;
}


/* ---- tgFX_Effect__Billboard__Render_Common --------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
static TgBOOL tgFX_Effect__Billboard__Render_Common( P_STg2_FX__Billboard__Render_Point psPoint, TgVEC_M_F32_04 vdT )
{
    CP_STg2_FX_Billboard__File_Data     psBillboard_File_Data;
    TgVEC_F32_04                        vAlpha;
    TgFLOAT32                           fAlpha;

    psBillboard_File_Data = psPoint->m_psFile_Data;

    vAlpha.m_mData = psPoint->m_vBase_CL;
    fAlpha = vAlpha.m_aData[3];

    /* Calculate the alpha value of the psBillboard */
    if (0 != (psBillboard_File_Data->m_uiFlags & ETgFX_BILLBOARD_FLAGS__HAS_FADE_ANGLE))
    {
        TgVEC_M_F32_04                      vView;
        TgVEC_M_F32_04                      vView_N;
        TgVEC_M_F32_04                      vDot_Angle;
        TgVEC_F32_04                        vFade_Percent;

        vView = M_SUB_F32_04( psPoint->m_vCam_Pos_W, psPoint->m_psBillboard->m_vPos_W );
        vView_N = M_NORM_F32_04( vView );

        if (psBillboard_File_Data->m_enOrientation == ETgFX_BILLBOARD_ORIENTATION__NONE)
        {
            TgVEC_M_F32_04                      vFace_Direction;

            vFace_Direction = M_QT_TX_F32_04( psBillboard_File_Data->m_vPlnZ, psPoint->m_psBillboard->m_qRot_W );
            vDot_Angle = M_DOT_F32_04( vView_N, vFace_Direction );
            vFade_Percent.m_mData = M_SUB_F32_04( vDot_Angle, psBillboard_File_Data->m_vFade_Start );
            vFade_Percent.m_mData = M_DIV_F32_04( vFade_Percent.m_mData, psBillboard_File_Data->m_vFade_RNG );
            vFade_Percent.m_mData = M_SUB_F32_04( KTgV_ONE_F32_04.m_mData, M_SAT_F32_04( vFade_Percent.m_mData ) );
            fAlpha = fAlpha * vFade_Percent.m.x;
        }
        else
        {
            vDot_Angle = M_DOT_F32_04( vView_N, psPoint->m_vCam_Forward );
            vFade_Percent.m_mData = M_SUB_F32_04( vDot_Angle, psBillboard_File_Data->m_vFade_Start );
            vFade_Percent.m_mData = M_DIV_F32_04( vFade_Percent.m_mData, psBillboard_File_Data->m_vFade_RNG );
            fAlpha = fAlpha * vFade_Percent.m.x;
        };
    };

    vAlpha.m_mData = MS_SET1_F32_04( fAlpha );
    psPoint->m_vCL = M_SEL_F32_04( psPoint->m_psBillboard->m_sExtend.m_vColour, vAlpha.m_mData, KTgV_FFF0.m_f32_v04.m_mData );

    tgRN_M_Calc_UV_Animation( /* Output */ &psPoint->m_psBillboard->m_sExtend.m_vUV_01_Constant, &psPoint->m_psBillboard->m_sExtend.m_vUV_01_Scale,
                              /* Input */ psPoint->m_psBillboard->m_tiMaterial, vdT, psPoint->m_psBillboard->m_vLive_Time );

    tgFX_Effect__Billboard__Render_Reference_Frame( psPoint );

    return (TgTRUE == tgCM_NR0_F32( fAlpha ) ? TgFALSE : TgTRUE);
}


/* ---- tgFX_Effect__Billboard__Render_Reference_Frame ------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
static TgVOID tgFX_Effect__Billboard__Render_Reference_Frame( P_STg2_FX__Billboard__Render_Point psPoint )
{
    CP_STg2_FX_Billboard__File_Data     psBillboard_File_Data;
    STg2_FX_Calc_Quad                   sData;
    TgVEC_M_F32_04                      vSize;

    psBillboard_File_Data = psPoint->m_psBillboard->m_psFile_Data;

    vSize = M_MUL_F32_04( psPoint->m_psBillboard->m_sExtend.m_vSize, psPoint->m_psBillboard->m_vScale );

    sData.m_vPivot_X = psBillboard_File_Data->m_vPivot_X;
    sData.m_vPivot_Y = psBillboard_File_Data->m_vPivot_Y;
    sData.m_vSize_X = M_SPX_F32_04( vSize );
    sData.m_vSize_Y = M_SPY_F32_04( vSize );
    sData.m_vPos_W = psPoint->m_psBillboard->m_vPos_W;

    switch (psBillboard_File_Data->m_enOrientation)
    {
        case ETgFX_BILLBOARD_ORIENTATION__CAMERA_FACE_SPHERE:
        {
            TgVEC_M_F32_04                      vLook_At;
            TgVEC_M_F32_04                      vNorm_Look_At;
            TgVEC_M_F32_04                      vNorm_Right;

            vLook_At = M_SUB_F32_04( psPoint->m_vCam_Pos_W, psPoint->m_psBillboard->m_vPos_W );
            vNorm_Look_At = M_NORM_F32_04( vLook_At );
            vNorm_Right = M_UCX_F32_04( psPoint->m_vCam_Up, vNorm_Look_At );

            sData.m_vDir_Right = vNorm_Right;
            sData.m_vDir_Up = M_UCX_F32_04( vNorm_Look_At, vNorm_Right );
            break;
        };

        case ETgFX_BILLBOARD_ORIENTATION__CAMERA_FACE_SPHERE__FIXED_Y:
        {
            TgVEC_F32_04                        vLook_At;
            TgVEC_M_F32_04                      vNorm_Look_At;

            vLook_At.m_mData = M_SUB_F32_04( psPoint->m_vCam_Pos_W, psPoint->m_psBillboard->m_vPos_W );
            vLook_At.m_aData[1] = 0.0F;
            vNorm_Look_At = M_NORM_F32_04( vLook_At.m_mData );

            sData.m_vDir_Up = KTgV_UNIT_Y_F32_04.m_mData;
            sData.m_vDir_Right = M_UCX_F32_04( sData.m_vDir_Up, vNorm_Look_At );
            break;
        };

        case ETgFX_BILLBOARD_ORIENTATION__CAMERA_FACE_PLANE:
        case ETgFX_BILLBOARD_ORIENTATION__CAMERA_FACE_PLANE__FIXED_Y:
        case ETgFX_BILLBOARD_ORIENTATION__NONE:
            sData.m_vDir_Right = M_QT_TX_F32_04( psBillboard_File_Data->m_vPlnX, psPoint->m_psBillboard->m_qRot_W );
            sData.m_vDir_Up = M_QT_TX_F32_04( psBillboard_File_Data->m_vPlnY, psPoint->m_psBillboard->m_qRot_W );
            break;

        default:
            TgS_NO_DEFAULT( break );
    }

    tgFX_Calc_Quad( /* Output */ psPoint->m_avPos_W, psPoint->m_avBasis, /* Input */ psPoint->m_psBillboard->m_sExtend.m_fSpin, &sData );
}


/* ---- tgFX_Effect__Billboard__Render_Write_Quad_00 -------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgFORCEINLINE TgVOID tgFX_Effect__Billboard__Render_Write_Quad_00( P_STg2_RN_Vertex_Particle_00 psVert, P_STg2_FX__Billboard__Render_Point psPoint )
{
    TgVEC_M_F32_04                      vUV;
    TgSINT32                            iVert;

    for (iVert = 0; iVert < 4; ++iVert)
    {
        vUV = M_MAD_F32_04( psPoint->m_vUV_Mask[iVert], psPoint->m_psBillboard->m_sExtend.m_vUV_01_Scale, psPoint->m_psBillboard->m_sExtend.m_vUV_01_Constant );

        psVert[iVert].m_vS0.m_mData = psPoint->m_avPos_W[iVert];
        psVert[iVert].m_vUV.m_mData = vUV;
        psVert[iVert].m_vCL.m_mData = psPoint->m_vCL;
    };
}


/* ---- tgFX_Effect__Billboard__Render_Write_Quad_01 -------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgFORCEINLINE TgVOID tgFX_Effect__Billboard__Render_Write_Quad_01( P_STg2_RN_Vertex_Particle_01 psVert, P_STg2_FX__Billboard__Render_Point psPoint )
{
    TgVEC_M_F32_04                      vUV;
    TgSINT32                            iVert;

    for (iVert = 0; iVert < 4; ++iVert)
    {
        vUV = M_MAD_F32_04( psPoint->m_vUV_Mask[iVert], psPoint->m_psBillboard->m_sExtend.m_vUV_01_Scale, psPoint->m_psBillboard->m_sExtend.m_vUV_01_Constant );

        psVert[iVert].m_vS0.m_mData = psPoint->m_avPos_W[iVert];
        psVert[iVert].m_vT0.m_mData = psPoint->m_avBasis[0];
        psVert[iVert].m_vB0.m_mData = psPoint->m_avBasis[1];
        psVert[iVert].m_vUV.m_mData = vUV;
        psVert[iVert].m_vCL.m_mData = psPoint->m_vCL;
    };
}