How to make a variable that affects alpha?

Expanding and utilizing the engine via C++.
4 posts Page 1 of 1
Posts: 63
Joined: Fri Feb 27, 2015 5:13 pm
by irei1as » Sun Apr 30, 2017 7:17 pm
I thought there was a way to change a trasparency attribute to an object to change the alpha independent of the material but I wasn't able to find it. If that exists it would be what I'm looking for.

But without that I'm trying to add an attribute to change the shader and add a color multiplier.
The documentation I'm using is these two pages in the torque 3d wiki: ... ial-system ... n-torque3d

But I'm failing. The program just explodes when I add the TSStatic with the variable using a function.
This is what I've done for now:

The material is:

Code: Select all

singleton Material(cube_Reddes)
   mapTo = "Reddes";
   diffuseColor[0] = "0.64 0.0492256 0.0569901 1";
   specular[0] = "0.5 0.5 0.5 1";
   specularPower[0] = "50";
   translucentBlendOp = "LerpAlpha";
   translucent = true ;
   multConstant = true;

And the TSStatic is:

Code: Select all

   new TSStatic(TheCube) {
      shapeName = "./cube.dae";
      playAmbient = "1";
      meshCulling = "0";
      originSort = "0";
      collisionType = "Collision Mesh";
      decalType = "Collision Mesh";
      allowPlayerStep = "0";
      alphaFadeEnable = "0";
      alphaFadeStart = "100";
      alphaFadeEnd = "150";
      alphaFadeInverse = "0";
      renderNormals = "0";
      forceDetail = "-1";
      position = "0 0 0";
      Rotation = "1 0 0 0";
      scale = "1 1 1";
      canSave = "1";
      canSaveDynamicFields = "1";
      visibility = 0.5;
      multConstant = "0.1 0.1 0.1 0.1";

Thanks for your help.
Steering Committee
Steering Committee
Posts: 682
Joined: Tue Feb 03, 2015 9:49 pm
by JeffR » Mon May 08, 2017 6:07 am
Are you trying to change the alpha dynamically during runtime, like for a cloaking effect or the like?

If so, you could look at the visibilty/cloaking stuff in shapebase for a reference. If you wanna do it raw in the shader, you'll have to have some hooks so the given shape instance can inform it's specific material instance(not the material definition) what values to use for the alpha.

You can get an idea of how you'd do that by looking at any rendering object that uses a custom material, such as the sky, water, ribbon particles, etc. They get the material instance and then specifically set 'Shader Handles' to inform the shader what values to use for what.

Note to self: we really need a Render Example that do these sorts of hooks. Coincidentally, I was working on something similar the other day, and it can indeed get pretty squirrely depending on what values you're trying to set. It's on the todo for 4.0 to do a revision pass on the material/shader stuffs to make it make a lot more sense if you're trying to do custom effects because yeah, as-is it can get weird.

Lemme know if you need any other pointers on where to look for how the engine tells a material instance what values to use and how they hook back to the shader or whatnot.
Posts: 63
Joined: Fri Feb 27, 2015 5:13 pm
by irei1as » Tue May 16, 2017 4:55 pm
Thanks a lot for the advice.
I made a large re-read of all the code and found some wrong stuff I had (& instead of pointers and an incorrect name of a define).
It took me some time but I got it working.
Note: cloned cubes with a shared material. The alpha comes from a dynamic variable in the client object.

This is the code I got at the end for if anybody wants to give it a try:

I plan on making the shader a bit more complicated so I can create holes to objects that are between the camera and a 3rd person player (with script raycasts). Another similar use could be to make a x-ray visor.

And if I can move the texture I could use them as a base for sprites with a spriteset as texture (just a "quad"* and move the xy for the 2Dtexture). But I'm not sure yet if I can do that with the GenOp.
Steering Committee
Steering Committee
Posts: 682
Joined: Tue Feb 03, 2015 9:49 pm
by JeffR » Wed May 17, 2017 5:49 am
Oooh, very nice good sir!
4 posts Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest