Questions about files, code, and node management #129
Replies: 1 comment 2 replies
-
So if you have, for example: #include "Pipelines/NPR_Pipeline.glsl"
#include "Node Utils/node_utils.glsl"
#ifdef PIXEL_SHADER
#ifdef MAIN_PASS
layout (location = 3) out vec4 OUT_CustomA;
layout (location = 4) out vec4 OUT_CustomB;
layout (location = 5) out vec4 OUT_CustomC;
layout (location = 6) out vec4 OUT_CustomD;
#endif
#endif
void NODES_COMMON_PIXEL_SHADER(Surface S, inout PixelOutput PO , out vec4 CustomA, out vec4 CustomB, out vec4 CustomC, out vec4 CustomD);
void COMMON_PIXEL_SHADER(Surface S, inout PixelOutput PO)
{
vec4 CustomA = vec4(0);
vec4 CustomB = vec4(0);
vec4 CustomC = vec4(0);
vec4 CustomD = vec4(0);
NODES_COMMON_PIXEL_SHADER(S, PO , CustomA, CustomB, CustomC, CustomD);
#ifdef PIXEL_SHADER
#ifdef MAIN_PASS
{
OUT_CustomA = CustomA;
OUT_CustomB = CustomB;
OUT_CustomC = CustomC;
OUT_CustomD = CustomD;
}
#endif
#endif
}
uniform vec4 U_0_COMMON_PIXEL_SHADEROutput_0_CustomA;
uniform vec4 U_0_COMMON_PIXEL_SHADEROutput_0_CustomB;
uniform vec4 U_0_COMMON_PIXEL_SHADEROutput_0_CustomC;
uniform vec4 U_0_COMMON_PIXEL_SHADEROutput_0_CustomD;
uniform float U_0_get_toon_0_size;
uniform float U_0_get_toon_0_gradient_size;
uniform float U_0_get_toon_0_specularity;
uniform float U_0_get_toon_0_offset;
uniform float U_0_vec4_from_vec3_0_a;
void NODES_COMMON_PIXEL_SHADER(Surface S, inout PixelOutput PO , out vec4 CustomA, out vec4 CustomB, out vec4 CustomC, out vec4 CustomD)
{
vec3 _get_toon_0_result = get_toon(U_0_get_toon_0_size,U_0_get_toon_0_gradient_size,U_0_get_toon_0_specularity,U_0_get_toon_0_offset);
vec4 _vec4_from_vec3_0_result = vec4_from_vec3(_get_toon_0_result,U_0_vec4_from_vec3_0_a);
PixelOutput _PixelOutput = PO;
_PixelOutput.color = _vec4_from_vec3_0_result;
PO = _PixelOutput;
CustomA = U_0_COMMON_PIXEL_SHADEROutput_0_CustomA;
CustomB = U_0_COMMON_PIXEL_SHADEROutput_0_CustomB;
CustomC = U_0_COMMON_PIXEL_SHADEROutput_0_CustomC;
CustomD = U_0_COMMON_PIXEL_SHADEROutput_0_CustomD;
} You remove the mesh shader setup code: uniform vec4 U_0_COMMON_PIXEL_SHADEROutput_0_CustomA;
uniform vec4 U_0_COMMON_PIXEL_SHADEROutput_0_CustomB;
uniform vec4 U_0_COMMON_PIXEL_SHADEROutput_0_CustomC;
uniform vec4 U_0_COMMON_PIXEL_SHADEROutput_0_CustomD;
uniform float U_0_get_toon_0_size;
uniform float U_0_get_toon_0_gradient_size;
uniform float U_0_get_toon_0_specularity;
uniform float U_0_get_toon_0_offset;
uniform float U_0_vec4_from_vec3_0_a;
void NODES_COMMON_PIXEL_SHADER(Surface S, inout PixelOutput PO , out vec4 CustomA, out vec4 CustomB, out vec4 CustomC, out vec4 CustomD)
{
vec3 _get_toon_0_result = get_toon(U_0_get_toon_0_size,U_0_get_toon_0_gradient_size,U_0_get_toon_0_specularity,U_0_get_toon_0_offset);
vec4 _vec4_from_vec3_0_result = vec4_from_vec3(_get_toon_0_result,U_0_vec4_from_vec3_0_a);
PixelOutput _PixelOutput = PO;
_PixelOutput.color = _vec4_from_vec3_0_result;
PO = _PixelOutput;
CustomA = U_0_COMMON_PIXEL_SHADEROutput_0_CustomA;
CustomB = U_0_COMMON_PIXEL_SHADEROutput_0_CustomB;
CustomC = U_0_COMMON_PIXEL_SHADEROutput_0_CustomC;
CustomD = U_0_COMMON_PIXEL_SHADEROutput_0_CustomD;
} Rename the function and move the uniforms to the parameters list: void My_Custom_Node(Surface S, inout PixelOutput PO , out vec4 CustomA, out vec4 CustomB, out vec4 CustomC, out vec4 CustomD,
vec4 U_0_COMMON_PIXEL_SHADEROutput_0_CustomA,
vec4 U_0_COMMON_PIXEL_SHADEROutput_0_CustomB,
vec4 U_0_COMMON_PIXEL_SHADEROutput_0_CustomC,
vec4 U_0_COMMON_PIXEL_SHADEROutput_0_CustomD,
float U_0_get_toon_0_size,
float U_0_get_toon_0_gradient_size,
float U_0_get_toon_0_specularity,
float U_0_get_toon_0_offset,
float U_0_vec4_from_vec3_0_a)
{
vec3 _get_toon_0_result = get_toon(U_0_get_toon_0_size,U_0_get_toon_0_gradient_size,U_0_get_toon_0_specularity,U_0_get_toon_0_offset);
vec4 _vec4_from_vec3_0_result = vec4_from_vec3(_get_toon_0_result,U_0_vec4_from_vec3_0_a);
PixelOutput _PixelOutput = PO;
_PixelOutput.color = _vec4_from_vec3_0_result;
PO = _PixelOutput;
CustomA = U_0_COMMON_PIXEL_SHADEROutput_0_CustomA;
CustomB = U_0_COMMON_PIXEL_SHADEROutput_0_CustomB;
CustomC = U_0_COMMON_PIXEL_SHADEROutput_0_CustomC;
CustomD = U_0_COMMON_PIXEL_SHADEROutput_0_CustomD;
} And probably return just the _PixelOutput.color or whatever you are calculating in your nodes and remove unused stuff: vec4 My_Custom_Node(Surface S, in PixelOutput PO,
float U_0_get_toon_0_size,
float U_0_get_toon_0_gradient_size,
float U_0_get_toon_0_specularity,
float U_0_get_toon_0_offset,
float U_0_vec4_from_vec3_0_a)
{
vec3 _get_toon_0_result = get_toon(U_0_get_toon_0_size,U_0_get_toon_0_gradient_size,U_0_get_toon_0_specularity,U_0_get_toon_0_offset);
vec4 _vec4_from_vec3_0_result = vec4_from_vec3(_get_toon_0_result,U_0_vec4_from_vec3_0_a);
PixelOutput _PixelOutput = PO;
_PixelOutput.color = _vec4_from_vec3_0_result;
return _PixelOutput.color;
}
vec4 red() { return vec4(1,0,0,1); } You can also do this: void color(out vec4 red) { red = vec4(1,0,0,1); } (Notice the out keyword) void colors(out vec4 red, out vec4 green, out vec4 blue)
{
red = vec4(1,0,0,1);
green = vec4(0,1,0,1);
blue = vec4(0,0,1,1);
} You can also use inout if you want to get a variable both as input and output: void brighter(inout vec4 color) { color.rgb += vec3(0.1, 0.1, 0.1); }
|
Beta Was this translation helpful? Give feedback.
-
Some questions related to setting things up. Trying to figure out exactly what my options are and how I'm supposed to be doing things.
I've made a shader setup using nodes, and I see that I can take the .mesh.glsl file outputted from that and load it back in as the shader source instead of using the node tree. However, when I do this, it seems all the values are set to defaults of either 0 or 1. Is there a way to define what they should default to in the .mesh.glsl file? Or better yet, in the nodes that its generated from? (I have noticed that naming the nodes does translate to the property names, so that works.)
Is there a way to control which node inputs show up in the materials panel and which don't? How about if bringing the file in as a shader source? I'm trying to make essentially a big uber shader. It'll be unusable if every single input on any node is going to show up.
I have figured out how to add my own custom node_utils folder and custom utils. That's all working fine. Can I do something similar with a .mesh.glsl shader generated from nodes? Can that be brought back in as its own node somehow? (This would effectively be a node group.) I have tried including the file the same way you include node_utils files and it causes blender to freeze. But there's a lot going on in the .mesh.glsl files created from nodes.
If 3 can't be done, what is the proper approach to adding a new shader node? My shader is essentially a scene_diffuse * scene_toon * AO with some math inserted to adjust the strength of some of these. It is all existing things, just combined together with math. I want to get this as a single node with only the inputs I need. I assume if I look through the existing sample shader files, I can copy and paste bits together to build this up. But its already getting put together in the .mesh.glsl file being generated from these nodes, so it seems like it should be easier if I just knew what part of that is needed, what parts of it I can remove, and what else needs to be included or not?
Can I add a util node that is just a list of vec3's with no input, and each vec3 being its own output? Or return an entry in the list based on an index? The values of the vec3s would be defined in the file. The current schema I can see for existing utils always is multiple inputs, but only a single output. (This would be used for bringing in a color palette that can be used in multiple different materials in the project.)
There are a large amount of nodes that don't seem to work, or I can't figure out how to get the input they seem to need. For example:
These nodes seem to want image textures as inputs? My understanding is that these are components used elsewhere, and we're not actually intended to be using them in the node editor, and instead access these functions through different nodes. Is that correct?
Is every material's shader compiled separately, even if they are using the same shader source file or node tree?
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions