Jump to content

How to make a variable that affects alpha?


irei1as
 Share

Recommended Posts

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:extending-the-torque3d-material-system

http://wiki.torque3d.org/coder:assigning-per-shape-shader-values-in-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:

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:

   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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 weeks later...

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.

http://i.imgur.com/UZhAUQb.png

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...