Changing Shader Values via Vex

   5888   6   0
User Avatar
Member
2164 posts
Joined: Sept. 2015
Offline
Hello,

I'm trying to expand my use of applying shaders on a per point(conditionaly like current frame) bases in vex wrangles.

I'm finding I cannot use the same ‘technique’ for all ‘attributes’ in the shader.

For example the gif attached(created from the attached hip file) is changing the color of opacolor from green to red as frames progress. I've included the hip file that shows this too.

'opacolor' is the opacity color of the principal shader being used.

The basic vex code I use for this is:

vector Col_A;
float Change_To_New_Color;

Change_To_New_Color = (@Frame - 1) * 15.0627;

if(@ptnum < Change_To_New_Color)
{
Col_A = set(1,0,0);
}
else
{
Col_A = set(0,1,0);
}

v@opaccolor = Col_A;


The above code works when I am using “principalshader_A” for my selection in the material node.

However, if I set the material node to use “principalshader_B” the above code does not work.

The difference between the two is that principalshader_B has a cell noise > colormix nodes attached to the shaders base color.

Strangely enough, I can still manually change the color of opacity - just not with the above code.

Ultimately I would like to use code similar to the above to drive changes to either the primary or secondary color of the colormix node.

When I tried using v@primary or v@secondary I wasn't able to get any results - which led me to further testing and trials which is how I discovered not being able to change opacity once the nodes were connected.

I'm hoping someone could explain what is happening and suggest a workflow to get me to be able to change the primary and secondary ‘attributes’ of the color mix.

I'm guessing I will have to ‘import’ all those points into the shader network and do the work from there?

Thanks for any feedback.
Edited by BabaJ - June 17, 2017 17:24:27

Attachments:
Shader Changes via Vex.gif (446.9 KB)
Transform Material Color Parameter with vex.hiplc (311.7 KB)

User Avatar
Member
2164 posts
Joined: Sept. 2015
Offline
So I've been trying all sorts of things.

This is the only one that doesn't give me error messages, but at the same time not any results.

Maybe I'm close but am missing something?

Attachments:
Change-VOP-node-values.jpg (152.2 KB)

User Avatar
Member
8177 posts
Joined: Sept. 2011
Online
Only parameter and bind vops in shaders can be overridden. A shader with input connected to it means that it must be wrapped in an auto-material, and none of the parameters from the inner shader will be real parameters in the outer shader. To pass through values, promote the parameters on the inner material. In the case of the input node, there is nowhere to bind to, as as the input value replaces the bound value.

The code looks a bit like this when you plug something into a shader parameter in /mat:
import principledshader
surface auto_mat(
  vector uv = {0,0,0};
  export vector Ce = {0,0,0};
)
{
    // colormix1
    float mix = 0.25; // assuming constant values for inputs to color mix
    vector primary = {1,0,0};
    vector secondary = {0,1,0};
    vector result = lerp(primary,secondary,mix);

    // principledshader1
    principledshader( "opaccolor", result, "uv", uv, "Cf", Cf, "Of", Of, "F", F, "Ce", Ce );
}

Only parameters connected to the principled shader are passed to the shader call. If you want ‘primary’ to come from the bound attribute ‘opaccolor’, create a parameter for “opaccolor” connected to the ‘primary’ input of the colormix. This will change the code to look like:

import principledshader
surface auto_mat(
  vector uv = {0,0,0};
  vector opaccolor = {1,1,1};
  export vector Ce = {0,0,0};
)
{
    // colormix1
    float mix = 0.25; // assuming constant values for inputs to color mix
    vector primary = opaccolor;
    vector secondary = {0,1,0};
    vector result = lerp(primary,secondary,mix);

    // principledshader1
    principledshader( "opaccolor", result, "uv", uv, "Cf", Cf, "Of", Of, "F", F, "Ce", Ce );
}
User Avatar
Member
2164 posts
Joined: Sept. 2015
Offline
Thank you very much for that explanation. Definitely a post I will be able to refer back to from time to time as I gradually learn more about shaders.

Perhaps I shouldn't have used opaccolor as reference to my issue.

What I really wanted to do was change the primary color of the color mix for only certain points as frames progress.

Your comment - “…create a parameter for “opaccolor” connected to the ‘primary’ input of the colormix…” was the one key that lit up my light bulb.

So I dropped down a parm node, plugging it into the primary of the colormix and gave that parm node a name of my preference.

Then, back at the object level in my point wrangle node I then referenced that ‘parameter’ - changing its' value on a per point, per frame conditional.

And it works exactly how I wanted it too.

I just think it's so awesome to be able to ‘tweek’ shaders like that with point wranglers. I see lots of potential with it.

I'm rendering off (at the moment) an example clip of what I did that shows the ‘technique’. Will post when it is done along with hip file.

In case someone in the future might want to do something similar.

Honestly, on this ‘technique’ alone. I was a bit lost as I couldn't find anything in a net search or combination of searches/tuts that gave me the clue as to what to do without your comment. (Maybe there was something I read about, but the lightbulb just didn't light up).

Might have been weeks before I finally found out or did a long workaround.(I was thinking I would just have to create seperate geometry that mimics the pattern created by the cellnoise vop; With each geometry object assigned their own shader.)

Thanks again jsmack.
User Avatar
Member
2164 posts
Joined: Sept. 2015
Offline
Here's the example gif and hip file.

Attachments:
Transform_Material_Color_Parameter_with_Vex.gif (948.4 KB)
Transform Material Color Parameter with vex.hiplc (1.4 MB)

User Avatar
Member
2164 posts
Joined: Sept. 2015
Offline
…Offtopic…but interesting how although I am only changing the blue borders to red borders ( the primary color paramter )…it appears the green ‘background’ ( secondary color ) is changing to another hue of green.

Although I know it's an ‘optical’ illusion. - Colors appear to be different depending on what they are juxtaposed against.
User Avatar
Member
4189 posts
Joined: June 2012
Offline
BabaJ
Although I know it's an ‘optical’ illusion. - Colors appear to be different depending on what they are juxtaposed against.


Welcome to the world. It's always surprising to see that people don't know they aren't seeing the world but interpreting it. i.e.

https://en.wikipedia.org/wiki/The_dress [en.wikipedia.org]

https://www.moillusions.com/table-tops-optical-illusion/ [www.moillusions.com]
  • Quick Links