Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | chimeforest |
Hello,
I’m creating a few nodes for creating random scalars/vec3s. I’ve already got two done (scalar → random scalar, scalar → semi-random vec3), but I’m having trouble on the third(vec3 → random vec3).
I thought it must be something to do with the input_vars at the end?
But I’ve tried:
[input_vars[0].x,input_vars[0].y,input_vars[0].z]
and
[input_vars[0].r,input_vars[0].g,input_vars[0].b]
and even
[input_vars[0][0],input_vars[0][1],input_vars[0][2]]
But none of them work. Instead of flashing random colors like the ones I have working, this one just output a solid white.
Below is my full code. Do you see anything wrong with it?
#RandomNode
tool
extends VisualShaderNodeCustom
class_name VisualShaderNodeVec3Random
func _get_name():
return "Vec3Random"
func _get_category():
return "Random"
func _get_description():
return "Random function (by Chimeforest)"
func _get_return_icon_type():
return VisualShaderNode.PORT_TYPE_VECTOR
func _get_input_port_count():
return 1
func _get_input_port_name(port):
match port:
0:
return "Seed"
func _get_input_port_type(port):
match port:
0:
return VisualShaderNode.PORT_TYPE_VECTOR
func _get_output_port_count():
return 1
func _get_output_port_name(port):
return "result"
func _get_output_port_type(port):
return VisualShaderNode.PORT_TYPE_VECTOR
func _get_code(input_vars, output_vars, mode, type):
return output_vars[0] + """ = vec3(
fract(sin(dot(vec2(%s,0.0), vec2(12.9898,78.233))) * 43758.5453),
fract(sin(dot(vec2(%s,0.0), vec2(12.9898,78.233))) * 43758.5453),
fract(sin(dot(vec2(%s,0.0), vec2(12.9898,78.233))) * 43758.5453));"""%[input_vars[0].x,input_vars[0].y,input_vars[0].z]