Torque3D Documentation / _generateds / afxZodiacPlane_T3D.cpp

afxZodiacPlane_T3D.cpp

Engine/source/afx/ce/afxZodiacPlane_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/afxZodiacPlane.h"
 34
 35void afxZodiacPlane::prepRenderImage(SceneRenderState* state)
 36{
 37  if (!is_visible)
 38    return;
 39
 40  ObjectRenderInst *ri = state->getRenderPass()->allocInst<ObjectRenderInst>();
 41  ri->renderDelegate.bind(this, &afxZodiacPlane::_renderZodiacPlane);
 42  ri->type = RenderPassManager::RIT_ObjectTranslucent;
 43  ri->translucentSort = true;
 44  ri->defaultKey = (U32)(dsize_t)mDataBlock;
 45
 46  if (false)
 47  {
 48    ri->sortDistSq = getWorldBox().getSqDistanceToPoint( state->getCameraPosition() );      
 49  }
 50  else // (sort by radius distance)
 51  {
 52    Point3F xyz_scale = getScale();
 53    F32 uni_scalar = getMax(xyz_scale.x, xyz_scale.y);
 54    uni_scalar = getMax(uni_scalar, xyz_scale.z);
 55    Point3F uni_scale(uni_scalar, uni_scalar, uni_scalar);
 56
 57    Point3F local_cam_pos = state->getCameraPosition();
 58    getRenderWorldTransform().mulP(local_cam_pos);
 59    local_cam_pos.convolveInverse(uni_scale);
 60
 61    switch (mDataBlock->face_dir)
 62    {
 63    case afxZodiacPlaneData::FACES_UP:
 64    case afxZodiacPlaneData::FACES_DOWN:
 65      local_cam_pos.z = 0;
 66      break;  
 67    case afxZodiacPlaneData::FACES_FORWARD:
 68    case afxZodiacPlaneData::FACES_BACK:
 69      local_cam_pos.y = 0;
 70      break;  
 71    case afxZodiacPlaneData::FACES_RIGHT:
 72    case afxZodiacPlaneData::FACES_LEFT:
 73      local_cam_pos.x = 0;
 74      break;  
 75    }
 76
 77    /* AFX_T3D_BROKEN -- enhanced transparency sorting of ZodiacPlanes JTF Note: evaluate this
 78    if (local_cam_pos.lenSquared() <= radius*radius)
 79    {
 80    ri->sortPoint = local_cam_pos;
 81    }
 82    else
 83    {
 84    local_cam_pos.normalize();
 85    ri->sortPoint = local_cam_pos*radius;
 86    }
 87
 88    ri->sortPoint.convolve(uni_scale);
 89    getRenderTransform().mulP(ri->sortPoint);      
 90    */
 91  }
 92  state->getRenderPass()->addInst(ri);
 93}
 94
 95void afxZodiacPlane::_renderZodiacPlane(ObjectRenderInst *ri, SceneRenderState* state, BaseMatInstance* overrideMat)
 96{
 97  if (overrideMat)
 98    return;
 99
100  // projection
101
102  // predraw
103  if (normal_sb.isNull())
104  {
105    GFXStateBlockDesc desc;
106
107    // Culling
108    desc.setCullMode((mDataBlock->double_sided) ? GFXCullNone : GFXCullCW);
109
110    // Blending
111    U32 blend = (mDataBlock->zflags & BLEND_MASK);
112    switch (blend)
113    {
114    case BLEND_ADDITIVE:
115      desc.setBlend(true, GFXBlendSrcAlpha, GFXBlendOne);
116      break;
117    case BLEND_SUBTRACTIVE:
118      desc.setBlend(true, GFXBlendZero, GFXBlendInvSrcColor);
119      break;
120    case BLEND_NORMAL:
121      desc.setBlend(true, GFXBlendSrcAlpha, GFXBlendInvSrcAlpha);
122      break;
123    }
124
125    // JTF Note: check this desc.setAlphaTest((blend != BLEND_SUBTRACTIVE), GFXCmpGreater, 0);
126    desc.setAlphaTest(true, GFXCmpGreater, 0);
127
128    desc.setZReadWrite(true);
129    desc.zFunc = GFXCmpLessEqual;
130    desc.zWriteEnable = false;
131    desc.samplersDefined = true;
132
133    normal_sb = GFX->createStateBlock(desc);
134    if (mDataBlock->double_sided)
135      reflected_sb = normal_sb;
136    else
137    {
138      desc.setCullMode(GFXCullCCW);
139      reflected_sb = GFX->createStateBlock(desc);
140    }
141  }
142
143  if (state->isReflectPass())
144    GFX->setStateBlock(reflected_sb);
145  else
146    GFX->setStateBlock(normal_sb);
147
148  Point3F basePoints[4];
149
150  switch (mDataBlock->face_dir)
151  {
152  case afxZodiacPlaneData::FACES_UP:
153    basePoints[0].set( 0.5f, -0.5f, 0.0f);
154    basePoints[1].set(-0.5f, -0.5f, 0.0f);
155    basePoints[2].set(-0.5f,  0.5f, 0.0f);
156    basePoints[3].set( 0.5f,  0.5f, 0.0f);
157    break;
158  case afxZodiacPlaneData::FACES_DOWN:
159    basePoints[3].set(-0.5f,  0.5f, 0.0f);
160    basePoints[2].set( 0.5f,  0.5f, 0.0f);
161    basePoints[1].set( 0.5f, -0.5f, 0.0f);
162    basePoints[0].set(-0.5f, -0.5f, 0.0f);
163    break;  
164  case afxZodiacPlaneData::FACES_FORWARD:
165    basePoints[0].set( 0.5f, 0.0f, -0.5f);
166    basePoints[1].set(-0.5f, 0.0f, -0.5f);
167    basePoints[2].set(-0.5f, 0.0f,  0.5f);
168    basePoints[3].set( 0.5f, 0.0f,  0.5f);
169    break;
170  case afxZodiacPlaneData::FACES_BACK:
171    basePoints[3].set(-0.5f, 0.0f,  0.5f);
172    basePoints[2].set( 0.5f, 0.0f,  0.5f);
173    basePoints[1].set( 0.5f, 0.0f, -0.5f);
174    basePoints[0].set(-0.5f, 0.0f, -0.5f);
175    break;  
176  case afxZodiacPlaneData::FACES_RIGHT:
177    basePoints[0].set(0.0f,  0.5f, -0.5f);
178    basePoints[1].set(0.0f, -0.5f, -0.5f);
179    basePoints[2].set(0.0f, -0.5f,  0.5f);
180    basePoints[3].set(0.0f,  0.5f,  0.5f);
181    break;
182  case afxZodiacPlaneData::FACES_LEFT:
183    basePoints[3].set(0.0f, -0.5f,  0.5f);
184    basePoints[2].set(0.0f,  0.5f,  0.5f);
185    basePoints[1].set(0.0f,  0.5f, -0.5f);
186    basePoints[0].set(0.0f, -0.5f, -0.5f);
187    break;  
188  }
189
190  F32 len = 2*radius;
191
192  Point3F points[4];
193
194  Point2F texCoords[4];   // default: {{"{"}}0.0,0.0}, {0.0,1.0}, {1.0,1.0}, {1.0,0.0}}
195  texCoords[0].set(1.0,1.0);
196  texCoords[1].set(0.0,1.0);
197  texCoords[2].set(0.0,0.0);
198  texCoords[3].set(1.0,0.0);
199
200  for( int i=0; i<4; i++ )
201  {
202    points[i].x = basePoints[i].x;
203    points[i].y = basePoints[i].y;
204    points[i].z = basePoints[i].z;
205    points[i] *= len;
206  }
207
208  GFXTransformSaver saver;
209  GFX->multWorld(getRenderTransform());
210
211  GFX->setTexture(0, mDataBlock->txr);
212
213  PrimBuild::begin(GFXTriangleStrip, 4);
214  {
215    PrimBuild::color4f(color.red, color.green, color.blue, color.alpha);
216    PrimBuild::texCoord2f(texCoords[1].x, texCoords[1].y);
217    PrimBuild::vertex3f(points[1].x,  points[1].y,  points[1].z);
218    PrimBuild::texCoord2f(texCoords[0].x, texCoords[0].y);
219    PrimBuild::vertex3f(points[0].x,  points[0].y,  points[0].z);
220    PrimBuild::texCoord2f(texCoords[2].x, texCoords[2].y);
221    PrimBuild::vertex3f(points[2].x,  points[2].y,  points[2].z);
222    PrimBuild::texCoord2f(texCoords[3].x, texCoords[3].y);
223    PrimBuild::vertex3f(points[3].x,  points[3].y,  points[3].z);
224  }
225  PrimBuild::end();
226}
227
228//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
229