Torque3D Documentation / _generateds / afxBillboard_T3D.cpp

afxBillboard_T3D.cpp

Engine/source/afx/ce/afxBillboard_T3D.cpp

More...

Detailed Description

  1
  2
  3//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  4// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  5// Copyright (C) 2015 Faust Logic, Inc.
  6//
  7// Permission is hereby granted, free of charge, to any person obtaining a copy
  8// of this software and associated documentation files (the "Software"), to
  9// deal in the Software without restriction, including without limitation the
 10// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 11// sell copies of the Software, and to permit persons to whom the Software is
 12// furnished to do so, subject to the following conditions:
 13//
 14// The above copyright notice and this permission notice shall be included in
 15// all copies or substantial portions of the Software.
 16//
 17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 23// IN THE SOFTWARE.
 24//
 25//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 26
 27#include "afx/arcaneFX.h"
 28
 29#include "gfx/gfxTransformSaver.h"
 30#include "gfx/primBuilder.h"
 31
 32#include "afx/afxChoreographer.h"
 33#include "afx/ce/afxBillboard.h"
 34
 35//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 36
 37void afxBillboard::prepRenderImage(SceneRenderState* state)
 38{
 39  if (!is_visible)
 40    return;
 41
 42  ObjectRenderInst *ri = state->getRenderPass()->allocInst<ObjectRenderInst>();
 43  ri->renderDelegate.bind(this, &afxBillboard::_renderBillboard);
 44  ri->type = RenderPassManager::RIT_ObjectTranslucent;
 45  ri->translucentSort = true;
 46  ri->defaultKey = (U32)(dsize_t)mDataBlock;
 47  ri->sortDistSq = getWorldBox().getSqDistanceToPoint( state->getCameraPosition() );      
 48  state->getRenderPass()->addInst(ri);
 49}
 50
 51void afxBillboard::_renderBillboard(ObjectRenderInst *ri, SceneRenderState* state, BaseMatInstance* overrideMat)
 52{
 53  if (overrideMat)
 54    return;
 55
 56  // predraw
 57  if (normal_sb.isNull())
 58  {
 59    GFXStateBlockDesc desc;
 60
 61    // Culling -- it's a billboard, so no backfaces
 62    desc.setCullMode(GFXCullCW);
 63
 64    // Blending
 65    desc.setBlend(true, mDataBlock->srcBlendFactor, mDataBlock->dstBlendFactor);
 66    desc.alphaTestEnable = (desc.blendSrc == GFXBlendSrcAlpha && 
 67                            (desc.blendDest == GFXBlendInvSrcAlpha || desc.blendDest == GFXBlendOne));
 68    desc.alphaTestRef = 1;
 69    desc.alphaTestFunc = GFXCmpGreaterEqual;
 70    
 71    desc.setZReadWrite(true);
 72    desc.zFunc = GFXCmpLessEqual;
 73    desc.zWriteEnable = false;
 74
 75    desc.samplersDefined = true;
 76
 77    normal_sb = GFX->createStateBlock(desc);
 78
 79    desc.setCullMode(GFXCullCCW);
 80    reflected_sb = GFX->createStateBlock(desc);
 81  }
 82
 83  if (state->isReflectPass())
 84    GFX->setStateBlock(reflected_sb);
 85  else
 86    GFX->setStateBlock(normal_sb);
 87
 88  GFXTransformSaver saver;
 89  GFX->multWorld(getRenderTransform());
 90
 91  GFX->setTexture(0, mDataBlock->txr);
 92
 93   MatrixF worldmod = GFX->getWorldMatrix();
 94   MatrixF viewmod = GFX->getViewMatrix();
 95
 96  Point4F Position;
 97  MatrixF ModelView;
 98   ModelView.mul(viewmod, worldmod);
 99   ModelView.getColumn(3, &Position);
100   ModelView.identity();
101   ModelView.setColumn(3, Position);
102
103   GFX->setWorldMatrix(ModelView);
104   MatrixF ident;
105   ident.identity();
106   GFX->setViewMatrix(ident);
107
108  F32 width = mDataBlock->dimensions.x * 0.5f * mObjScale.x;
109  F32 height = mDataBlock->dimensions.y * 0.5f * mObjScale.z;
110
111  Point3F points[4];
112  points[0].set( width, 0.0f, -height);
113  points[1].set(-width, 0.0f, -height);
114  points[2].set(-width, 0.0f,  height);
115  points[3].set( width, 0.0f,  height);
116
117  PrimBuild::begin(GFXTriangleStrip, 4);
118  {
119     PrimBuild::color4f(live_color.red, live_color.green, live_color.blue, live_color.alpha*fade_amt);
120    PrimBuild::texCoord2f(mDataBlock->texCoords[1].x, mDataBlock->texCoords[1].y);
121    PrimBuild::vertex3fv(points[1]);
122    PrimBuild::texCoord2f(mDataBlock->texCoords[2].x, mDataBlock->texCoords[2].y);
123    PrimBuild::vertex3fv(points[0]);
124    PrimBuild::texCoord2f(mDataBlock->texCoords[0].x, mDataBlock->texCoords[0].y);
125    PrimBuild::vertex3fv(points[2]);
126    PrimBuild::texCoord2f(mDataBlock->texCoords[3].x, mDataBlock->texCoords[3].y);
127    PrimBuild::vertex3fv(points[3]);
128  }
129  PrimBuild::end();
130}
131
132//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
133