### How to make a variable that affects alpha?

Expanding and utilizing the engine via C++.

#### How to make a variable that affects alpha?

irei1as
Posts: 74
Joined: Fri Feb 27, 2015 5:13 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:
http://wiki.torque3d.org/coder:extendin ... ial-system
http://wiki.torque3d.org/coder:assignin ... 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:
https://pastebin.com/x6PRgd7j

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";   };

#### Re: How to make a variable that affects alpha?

JeffR
Steering Committee
Posts: 790
Joined: Tue Feb 03, 2015 9:49 pm

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.

#### Re: How to make a variable that affects alpha?

irei1as
Posts: 74
Joined: Fri Feb 27, 2015 5:13 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:
https://pastebin.com/xLYKEdkY

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.

#### Re: How to make a variable that affects alpha?

JeffR
Steering Committee
Posts: 790
Joined: Tue Feb 03, 2015 9:49 pm

Oooh, very nice good sir!

#### Who is online

Users browsing this forum: No registered users and 1 guest