Game Development Community

Rendering Alpha on GFXVertexPCN

by Robert Fritzen · in Torque 3D Professional · 07/30/2014 (10:41 am) · 2 replies

Well, I appear to be on a roll for finding little "issues" this week with stuff in the engine, now I've got something more interesting in terms of a find.

Most of the cube rendering examples in the engine use GFXVertexPCN, and I'm lacking a good example of doing the same with the PrimBuilder, which would eliminate this problem altogether because it uses ColorF, which has an alpha parameter.

My problem today is that when rendering a cube instance, there is no "alpha" on the color, so I can't make a slightly transparent object instance.

what I have so far is something along the lines of:

void createGeometries() {
   //Some code stuff here
   .
   .
   .
   GFXVertexPCN *pVert = NULL;

   mVertexBuffer.set( GFX, 36, GFXBufferTypeStatic );
   pVert = mVertexBuffer.lock();

   Point3F halfSize = getObjBox().getExtents() * 0.5f;

   for (U32 i = 0; i < 36; i++) {
      const U32& vdx = cubeFaces[i][0];
      const U32& ndx = cubeFaces[i][1];

      pVert[i].point  = cubePoints[vdx] * halfSize;
      pVert[i].normal = cubeNormals[ndx];
      pVert[i].color  = mColor; //<--- ColorF
   }

   mVertexBuffer.unlock();
   GFXStateBlockDesc desc;
   mNormalSB = GFX->createStateBlock( desc );
   desc.cullDefined = true;
   desc.cullMode = GFXCullCW;
   mReflectSB = GFX->createStateBlock( desc );
}

In terms of actually getting color on the object, this works, but there is no alpha to the object, it's always a static and solidly colored cube instance.

So, today, I want to know how I can apply alpha color a GFXVertexPCN so I can make transparently colored cubes.

Thanks!

#1
07/30/2014 (11:30 am)
This is a blend operation.
Just make sure that you have enabled alpha blending, set a blend operation.
Make sure your fragment shader output alpha different from 1.0

PCN is the vertex format, the attribute interleaved stream data. It means that you feed your vertex shader with position, vertex color and normals.
#2
07/30/2014 (12:31 pm)
Worked like a charm! Thanks a bunch!