2018-08-29 22:38:13 +02:00
/*************************************************************************/
/* visual_shader_nodes.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
2022-01-03 21:27:34 +01:00
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
2018-08-29 22:38:13 +02:00
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
2018-07-14 23:15:42 +02:00
# include "visual_shader_nodes.h"
2019-09-18 18:04:40 +02:00
2022-02-01 09:32:01 +01:00
////////////// Vector Base
VisualShaderNodeVectorBase : : PortType VisualShaderNodeVectorBase : : get_input_port_type ( int p_port ) const {
switch ( op_type ) {
case OP_TYPE_VECTOR_2D :
return PORT_TYPE_VECTOR_2D ;
case OP_TYPE_VECTOR_3D :
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D :
return PORT_TYPE_VECTOR_4D ;
2022-02-01 09:32:01 +01:00
default :
break ;
}
return PORT_TYPE_SCALAR ;
}
VisualShaderNodeVectorBase : : PortType VisualShaderNodeVectorBase : : get_output_port_type ( int p_port ) const {
switch ( op_type ) {
case OP_TYPE_VECTOR_2D :
return PORT_TYPE_VECTOR_2D ;
case OP_TYPE_VECTOR_3D :
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D :
return PORT_TYPE_VECTOR_4D ;
2022-02-01 09:32:01 +01:00
default :
break ;
}
return PORT_TYPE_SCALAR ;
}
void VisualShaderNodeVectorBase : : set_op_type ( OpType p_op_type ) {
ERR_FAIL_INDEX ( int ( p_op_type ) , int ( OP_TYPE_MAX ) ) ;
if ( op_type = = p_op_type ) {
return ;
}
op_type = p_op_type ;
emit_changed ( ) ;
}
VisualShaderNodeVectorBase : : OpType VisualShaderNodeVectorBase : : get_op_type ( ) const {
return op_type ;
}
void VisualShaderNodeVectorBase : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_op_type " , " type " ) , & VisualShaderNodeVectorBase : : set_op_type ) ;
ClassDB : : bind_method ( D_METHOD ( " get_op_type " ) , & VisualShaderNodeVectorBase : : get_op_type ) ;
2022-04-12 19:09:29 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " op_type " , PROPERTY_HINT_ENUM , " Vector2,Vector3,Vector4 " ) , " set_op_type " , " get_op_type " ) ;
2022-02-01 09:32:01 +01:00
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_2D ) ;
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_3D ) ;
2022-04-12 19:09:29 +02:00
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_4D ) ;
2022-02-01 09:32:01 +01:00
BIND_ENUM_CONSTANT ( OP_TYPE_MAX ) ;
}
Vector < StringName > VisualShaderNodeVectorBase : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " op_type " ) ;
return props ;
}
VisualShaderNodeVectorBase : : VisualShaderNodeVectorBase ( ) {
}
2020-12-30 09:45:31 +01:00
////////////// Constants Base
VisualShaderNodeConstant : : VisualShaderNodeConstant ( ) {
}
2020-02-25 15:50:49 +01:00
////////////// Scalar(Float)
2018-07-14 23:15:42 +02:00
2020-02-25 15:50:49 +01:00
String VisualShaderNodeFloatConstant : : get_caption ( ) const {
2021-07-03 10:11:10 +02:00
return " FloatConstant " ;
2018-07-14 23:15:42 +02:00
}
2020-02-25 15:50:49 +01:00
int VisualShaderNodeFloatConstant : : get_input_port_count ( ) const {
2018-07-14 23:15:42 +02:00
return 0 ;
}
2019-09-18 18:04:40 +02:00
2020-02-25 15:50:49 +01:00
VisualShaderNodeFloatConstant : : PortType VisualShaderNodeFloatConstant : : get_input_port_type ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return PORT_TYPE_SCALAR ;
}
2019-09-18 18:04:40 +02:00
2020-02-25 15:50:49 +01:00
String VisualShaderNodeFloatConstant : : get_input_port_name ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return String ( ) ;
}
2020-02-25 15:50:49 +01:00
int VisualShaderNodeFloatConstant : : get_output_port_count ( ) const {
2018-07-14 23:15:42 +02:00
return 1 ;
}
2019-09-18 18:04:40 +02:00
2020-02-25 15:50:49 +01:00
VisualShaderNodeFloatConstant : : PortType VisualShaderNodeFloatConstant : : get_output_port_type ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return PORT_TYPE_SCALAR ;
}
2019-09-18 18:04:40 +02:00
2020-02-25 15:50:49 +01:00
String VisualShaderNodeFloatConstant : : get_output_port_name ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return " " ; //no output port means the editor will be used as port
}
2020-02-25 15:50:49 +01:00
String VisualShaderNodeFloatConstant : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = " + vformat ( " %.6f " , constant ) + " ; \n " ;
2018-07-14 23:15:42 +02:00
}
2021-08-14 12:38:22 +02:00
void VisualShaderNodeFloatConstant : : set_constant ( float p_constant ) {
if ( Math : : is_equal_approx ( constant , p_constant ) ) {
return ;
}
constant = p_constant ;
2018-07-14 23:15:42 +02:00
emit_changed ( ) ;
}
2020-02-25 15:50:49 +01:00
float VisualShaderNodeFloatConstant : : get_constant ( ) const {
2018-07-14 23:15:42 +02:00
return constant ;
}
2020-02-25 15:50:49 +01:00
Vector < StringName > VisualShaderNodeFloatConstant : : get_editable_properties ( ) const {
2018-07-14 23:15:42 +02:00
Vector < StringName > props ;
props . push_back ( " constant " ) ;
return props ;
}
2020-02-25 15:50:49 +01:00
void VisualShaderNodeFloatConstant : : _bind_methods ( ) {
2021-08-14 12:38:22 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_constant " , " constant " ) , & VisualShaderNodeFloatConstant : : set_constant ) ;
2020-02-25 15:50:49 +01:00
ClassDB : : bind_method ( D_METHOD ( " get_constant " ) , & VisualShaderNodeFloatConstant : : get_constant ) ;
2018-07-14 23:15:42 +02:00
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " constant " ) , " set_constant " , " get_constant " ) ;
2018-07-14 23:15:42 +02:00
}
2020-02-25 15:50:49 +01:00
VisualShaderNodeFloatConstant : : VisualShaderNodeFloatConstant ( ) {
}
////////////// Scalar(Int)
String VisualShaderNodeIntConstant : : get_caption ( ) const {
2021-07-03 10:11:10 +02:00
return " IntConstant " ;
2020-02-25 15:50:49 +01:00
}
int VisualShaderNodeIntConstant : : get_input_port_count ( ) const {
return 0 ;
}
VisualShaderNodeIntConstant : : PortType VisualShaderNodeIntConstant : : get_input_port_type ( int p_port ) const {
return PORT_TYPE_SCALAR_INT ;
}
String VisualShaderNodeIntConstant : : get_input_port_name ( int p_port ) const {
return String ( ) ;
}
int VisualShaderNodeIntConstant : : get_output_port_count ( ) const {
return 1 ;
}
VisualShaderNodeIntConstant : : PortType VisualShaderNodeIntConstant : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_SCALAR_INT ;
}
String VisualShaderNodeIntConstant : : get_output_port_name ( int p_port ) const {
return " " ; //no output port means the editor will be used as port
}
String VisualShaderNodeIntConstant : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = " + itos ( constant ) + " ; \n " ;
2020-02-25 15:50:49 +01:00
}
2021-08-14 12:38:22 +02:00
void VisualShaderNodeIntConstant : : set_constant ( int p_constant ) {
if ( constant = = p_constant ) {
return ;
}
constant = p_constant ;
2020-02-25 15:50:49 +01:00
emit_changed ( ) ;
}
int VisualShaderNodeIntConstant : : get_constant ( ) const {
return constant ;
}
Vector < StringName > VisualShaderNodeIntConstant : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " constant " ) ;
return props ;
}
void VisualShaderNodeIntConstant : : _bind_methods ( ) {
2021-08-14 12:38:22 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_constant " , " constant " ) , & VisualShaderNodeIntConstant : : set_constant ) ;
2020-02-25 15:50:49 +01:00
ClassDB : : bind_method ( D_METHOD ( " get_constant " ) , & VisualShaderNodeIntConstant : : get_constant ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " constant " ) , " set_constant " , " get_constant " ) ;
}
VisualShaderNodeIntConstant : : VisualShaderNodeIntConstant ( ) {
2018-07-14 23:15:42 +02:00
}
2019-02-22 18:38:58 +01:00
////////////// Boolean
String VisualShaderNodeBooleanConstant : : get_caption ( ) const {
2021-07-03 10:11:10 +02:00
return " BooleanConstant " ;
2019-02-22 18:38:58 +01:00
}
int VisualShaderNodeBooleanConstant : : get_input_port_count ( ) const {
return 0 ;
}
VisualShaderNodeBooleanConstant : : PortType VisualShaderNodeBooleanConstant : : get_input_port_type ( int p_port ) const {
return PORT_TYPE_BOOLEAN ;
}
String VisualShaderNodeBooleanConstant : : get_input_port_name ( int p_port ) const {
return String ( ) ;
}
int VisualShaderNodeBooleanConstant : : get_output_port_count ( ) const {
return 1 ;
}
VisualShaderNodeBooleanConstant : : PortType VisualShaderNodeBooleanConstant : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_BOOLEAN ;
}
String VisualShaderNodeBooleanConstant : : get_output_port_name ( int p_port ) const {
return " " ; //no output port means the editor will be used as port
}
String VisualShaderNodeBooleanConstant : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = " + ( constant ? " true " : " false " ) + " ; \n " ;
2019-02-22 18:38:58 +01:00
}
2021-08-14 12:38:22 +02:00
void VisualShaderNodeBooleanConstant : : set_constant ( bool p_constant ) {
if ( constant = = p_constant ) {
return ;
}
constant = p_constant ;
2019-02-22 18:38:58 +01:00
emit_changed ( ) ;
}
bool VisualShaderNodeBooleanConstant : : get_constant ( ) const {
return constant ;
}
Vector < StringName > VisualShaderNodeBooleanConstant : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " constant " ) ;
return props ;
}
void VisualShaderNodeBooleanConstant : : _bind_methods ( ) {
2021-08-14 12:38:22 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_constant " , " constant " ) , & VisualShaderNodeBooleanConstant : : set_constant ) ;
2019-02-22 18:38:58 +01:00
ClassDB : : bind_method ( D_METHOD ( " get_constant " ) , & VisualShaderNodeBooleanConstant : : get_constant ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " constant " ) , " set_constant " , " get_constant " ) ;
}
VisualShaderNodeBooleanConstant : : VisualShaderNodeBooleanConstant ( ) {
}
2018-07-14 23:15:42 +02:00
////////////// Color
String VisualShaderNodeColorConstant : : get_caption ( ) const {
2021-07-03 10:11:10 +02:00
return " ColorConstant " ;
2018-07-14 23:15:42 +02:00
}
int VisualShaderNodeColorConstant : : get_input_port_count ( ) const {
return 0 ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
VisualShaderNodeColorConstant : : PortType VisualShaderNodeColorConstant : : get_input_port_type ( int p_port ) const {
2022-04-22 19:31:23 +02:00
return PORT_TYPE_VECTOR_4D ;
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
String VisualShaderNodeColorConstant : : get_input_port_name ( int p_port ) const {
return String ( ) ;
}
int VisualShaderNodeColorConstant : : get_output_port_count ( ) const {
2022-04-22 19:31:23 +02:00
return 1 ;
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
VisualShaderNodeColorConstant : : PortType VisualShaderNodeColorConstant : : get_output_port_type ( int p_port ) const {
2022-04-22 19:31:23 +02:00
return p_port = = 0 ? PORT_TYPE_VECTOR_4D : PORT_TYPE_SCALAR ;
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
String VisualShaderNodeColorConstant : : get_output_port_name ( int p_port ) const {
2022-04-22 19:31:23 +02:00
return " " ;
2018-07-14 23:15:42 +02:00
}
2020-12-20 16:45:53 +01:00
bool VisualShaderNodeColorConstant : : is_output_port_expandable ( int p_port ) const {
if ( p_port = = 0 ) {
return true ;
}
return false ;
}
2019-01-21 20:07:53 +01:00
String VisualShaderNodeColorConstant : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2022-04-22 19:31:23 +02:00
return " " + p_output_vars [ 0 ] + " = " + vformat ( " vec4(%.6f, %.6f, %.6f, %.6f) " , constant . r , constant . g , constant . b , constant . a ) + " ; \n " ;
2018-07-14 23:15:42 +02:00
}
2021-08-14 12:38:22 +02:00
void VisualShaderNodeColorConstant : : set_constant ( const Color & p_constant ) {
if ( constant . is_equal_approx ( p_constant ) ) {
return ;
}
constant = p_constant ;
2018-07-14 23:15:42 +02:00
emit_changed ( ) ;
}
Color VisualShaderNodeColorConstant : : get_constant ( ) const {
return constant ;
}
Vector < StringName > VisualShaderNodeColorConstant : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " constant " ) ;
return props ;
}
void VisualShaderNodeColorConstant : : _bind_methods ( ) {
2021-08-14 12:38:22 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_constant " , " constant " ) , & VisualShaderNodeColorConstant : : set_constant ) ;
2018-07-14 23:15:42 +02:00
ClassDB : : bind_method ( D_METHOD ( " get_constant " ) , & VisualShaderNodeColorConstant : : get_constant ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : COLOR , " constant " ) , " set_constant " , " get_constant " ) ;
}
VisualShaderNodeColorConstant : : VisualShaderNodeColorConstant ( ) {
}
2022-02-01 09:32:01 +01:00
////////////// Vector2
String VisualShaderNodeVec2Constant : : get_caption ( ) const {
return " Vector2Constant " ;
}
int VisualShaderNodeVec2Constant : : get_input_port_count ( ) const {
return 0 ;
}
VisualShaderNodeVec2Constant : : PortType VisualShaderNodeVec2Constant : : get_input_port_type ( int p_port ) const {
return PORT_TYPE_VECTOR_2D ;
}
String VisualShaderNodeVec2Constant : : get_input_port_name ( int p_port ) const {
return String ( ) ;
}
int VisualShaderNodeVec2Constant : : get_output_port_count ( ) const {
return 1 ;
}
VisualShaderNodeVec2Constant : : PortType VisualShaderNodeVec2Constant : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_VECTOR_2D ;
}
String VisualShaderNodeVec2Constant : : get_output_port_name ( int p_port ) const {
return " " ; //no output port means the editor will be used as port
}
String VisualShaderNodeVec2Constant : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
return " " + p_output_vars [ 0 ] + " = " + vformat ( " vec2(%.6f, %.6f) " , constant . x , constant . y ) + " ; \n " ;
}
void VisualShaderNodeVec2Constant : : set_constant ( const Vector2 & p_constant ) {
if ( constant . is_equal_approx ( p_constant ) ) {
return ;
}
constant = p_constant ;
emit_changed ( ) ;
}
Vector2 VisualShaderNodeVec2Constant : : get_constant ( ) const {
return constant ;
}
Vector < StringName > VisualShaderNodeVec2Constant : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " constant " ) ;
return props ;
}
void VisualShaderNodeVec2Constant : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_constant " , " constant " ) , & VisualShaderNodeVec2Constant : : set_constant ) ;
ClassDB : : bind_method ( D_METHOD ( " get_constant " ) , & VisualShaderNodeVec2Constant : : get_constant ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : VECTOR2 , " constant " ) , " set_constant " , " get_constant " ) ;
}
VisualShaderNodeVec2Constant : : VisualShaderNodeVec2Constant ( ) {
}
////////////// Vector3
2018-07-14 23:15:42 +02:00
String VisualShaderNodeVec3Constant : : get_caption ( ) const {
2022-02-01 09:32:01 +01:00
return " Vector3Constant " ;
2018-07-14 23:15:42 +02:00
}
int VisualShaderNodeVec3Constant : : get_input_port_count ( ) const {
return 0 ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
VisualShaderNodeVec3Constant : : PortType VisualShaderNodeVec3Constant : : get_input_port_type ( int p_port ) const {
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
String VisualShaderNodeVec3Constant : : get_input_port_name ( int p_port ) const {
return String ( ) ;
}
int VisualShaderNodeVec3Constant : : get_output_port_count ( ) const {
return 1 ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
VisualShaderNodeVec3Constant : : PortType VisualShaderNodeVec3Constant : : get_output_port_type ( int p_port ) const {
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
String VisualShaderNodeVec3Constant : : get_output_port_name ( int p_port ) const {
return " " ; //no output port means the editor will be used as port
}
2019-01-21 20:07:53 +01:00
String VisualShaderNodeVec3Constant : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = " + vformat ( " vec3(%.6f, %.6f, %.6f) " , constant . x , constant . y , constant . z ) + " ; \n " ;
2018-07-14 23:15:42 +02:00
}
2021-08-14 12:38:22 +02:00
void VisualShaderNodeVec3Constant : : set_constant ( const Vector3 & p_constant ) {
if ( constant . is_equal_approx ( p_constant ) ) {
return ;
}
constant = p_constant ;
2018-07-14 23:15:42 +02:00
emit_changed ( ) ;
}
Vector3 VisualShaderNodeVec3Constant : : get_constant ( ) const {
return constant ;
}
Vector < StringName > VisualShaderNodeVec3Constant : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " constant " ) ;
return props ;
}
void VisualShaderNodeVec3Constant : : _bind_methods ( ) {
2021-08-14 12:38:22 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_constant " , " constant " ) , & VisualShaderNodeVec3Constant : : set_constant ) ;
2018-07-14 23:15:42 +02:00
ClassDB : : bind_method ( D_METHOD ( " get_constant " ) , & VisualShaderNodeVec3Constant : : get_constant ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : VECTOR3 , " constant " ) , " set_constant " , " get_constant " ) ;
}
VisualShaderNodeVec3Constant : : VisualShaderNodeVec3Constant ( ) {
}
2022-04-12 19:09:29 +02:00
////////////// Vector4
String VisualShaderNodeVec4Constant : : get_caption ( ) const {
return " Vector4Constant " ;
}
int VisualShaderNodeVec4Constant : : get_input_port_count ( ) const {
return 0 ;
}
VisualShaderNodeVec4Constant : : PortType VisualShaderNodeVec4Constant : : get_input_port_type ( int p_port ) const {
return PORT_TYPE_VECTOR_4D ;
}
String VisualShaderNodeVec4Constant : : get_input_port_name ( int p_port ) const {
return String ( ) ;
}
int VisualShaderNodeVec4Constant : : get_output_port_count ( ) const {
return 1 ;
}
VisualShaderNodeVec4Constant : : PortType VisualShaderNodeVec4Constant : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_VECTOR_4D ;
}
String VisualShaderNodeVec4Constant : : get_output_port_name ( int p_port ) const {
return " " ; // No output port means the editor will be used as port.
}
String VisualShaderNodeVec4Constant : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
return " " + p_output_vars [ 0 ] + " = " + vformat ( " vec4(%.6f, %.6f, %.6f, %.6f) " , constant . x , constant . y , constant . z , constant . w ) + " ; \n " ;
}
void VisualShaderNodeVec4Constant : : set_constant ( const Quaternion & p_constant ) {
if ( constant . is_equal_approx ( p_constant ) ) {
return ;
}
constant = p_constant ;
emit_changed ( ) ;
}
Quaternion VisualShaderNodeVec4Constant : : get_constant ( ) const {
return constant ;
}
Vector < StringName > VisualShaderNodeVec4Constant : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " constant " ) ;
return props ;
}
void VisualShaderNodeVec4Constant : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_constant " , " constant " ) , & VisualShaderNodeVec4Constant : : set_constant ) ;
ClassDB : : bind_method ( D_METHOD ( " get_constant " ) , & VisualShaderNodeVec4Constant : : get_constant ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : QUATERNION , " constant " ) , " set_constant " , " get_constant " ) ;
}
VisualShaderNodeVec4Constant : : VisualShaderNodeVec4Constant ( ) {
}
2020-10-17 07:08:21 +02:00
////////////// Transform3D
2018-07-14 23:15:42 +02:00
String VisualShaderNodeTransformConstant : : get_caption ( ) const {
2021-07-03 10:11:10 +02:00
return " TransformConstant " ;
2018-07-14 23:15:42 +02:00
}
int VisualShaderNodeTransformConstant : : get_input_port_count ( ) const {
return 0 ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
VisualShaderNodeTransformConstant : : PortType VisualShaderNodeTransformConstant : : get_input_port_type ( int p_port ) const {
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
String VisualShaderNodeTransformConstant : : get_input_port_name ( int p_port ) const {
return String ( ) ;
}
int VisualShaderNodeTransformConstant : : get_output_port_count ( ) const {
return 1 ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
VisualShaderNodeTransformConstant : : PortType VisualShaderNodeTransformConstant : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_TRANSFORM ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
String VisualShaderNodeTransformConstant : : get_output_port_name ( int p_port ) const {
return " " ; //no output port means the editor will be used as port
}
2019-01-21 20:07:53 +01:00
String VisualShaderNodeTransformConstant : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2020-10-17 07:08:21 +02:00
Transform3D t = constant ;
2018-07-14 23:15:42 +02:00
t . basis . transpose ( ) ;
2021-07-19 08:06:51 +02:00
String code = " " + p_output_vars [ 0 ] + " = mat4( " ;
2020-01-27 10:10:51 +01:00
code + = vformat ( " vec4(%.6f, %.6f, %.6f, 0.0), " , t . basis [ 0 ] . x , t . basis [ 0 ] . y , t . basis [ 0 ] . z ) ;
code + = vformat ( " vec4(%.6f, %.6f, %.6f, 0.0), " , t . basis [ 1 ] . x , t . basis [ 1 ] . y , t . basis [ 1 ] . z ) ;
code + = vformat ( " vec4(%.6f, %.6f, %.6f, 0.0), " , t . basis [ 2 ] . x , t . basis [ 2 ] . y , t . basis [ 2 ] . z ) ;
code + = vformat ( " vec4(%.6f, %.6f, %.6f, 1.0)); \n " , t . origin . x , t . origin . y , t . origin . z ) ;
2018-07-14 23:15:42 +02:00
return code ;
}
2021-08-14 12:38:22 +02:00
void VisualShaderNodeTransformConstant : : set_constant ( const Transform3D & p_constant ) {
if ( constant . is_equal_approx ( p_constant ) ) {
return ;
}
constant = p_constant ;
2018-07-14 23:15:42 +02:00
emit_changed ( ) ;
}
2020-10-17 07:08:21 +02:00
Transform3D VisualShaderNodeTransformConstant : : get_constant ( ) const {
2018-07-14 23:15:42 +02:00
return constant ;
}
Vector < StringName > VisualShaderNodeTransformConstant : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " constant " ) ;
return props ;
}
void VisualShaderNodeTransformConstant : : _bind_methods ( ) {
2021-08-14 12:38:22 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_constant " , " constant " ) , & VisualShaderNodeTransformConstant : : set_constant ) ;
2018-07-14 23:15:42 +02:00
ClassDB : : bind_method ( D_METHOD ( " get_constant " ) , & VisualShaderNodeTransformConstant : : get_constant ) ;
2021-04-28 09:36:08 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : TRANSFORM3D , " constant " ) , " set_constant " , " get_constant " ) ;
2018-07-14 23:15:42 +02:00
}
VisualShaderNodeTransformConstant : : VisualShaderNodeTransformConstant ( ) {
}
////////////// Texture
String VisualShaderNodeTexture : : get_caption ( ) const {
2019-06-11 20:43:37 +02:00
return " Texture2D " ;
2018-07-14 23:15:42 +02:00
}
int VisualShaderNodeTexture : : get_input_port_count ( ) const {
2019-10-01 10:51:50 +02:00
return 3 ;
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
VisualShaderNodeTexture : : PortType VisualShaderNodeTexture : : get_input_port_type ( int p_port ) const {
2019-10-01 10:51:50 +02:00
switch ( p_port ) {
case 0 :
2022-02-01 09:32:01 +01:00
return PORT_TYPE_VECTOR_2D ;
2019-10-01 10:51:50 +02:00
case 1 :
return PORT_TYPE_SCALAR ;
case 2 :
return PORT_TYPE_SAMPLER ;
default :
return PORT_TYPE_SCALAR ;
}
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
String VisualShaderNodeTexture : : get_input_port_name ( int p_port ) const {
2019-10-01 10:51:50 +02:00
switch ( p_port ) {
case 0 :
return " uv " ;
case 1 :
return " lod " ;
case 2 :
2019-10-11 09:26:57 +02:00
return " sampler2D " ;
2019-10-01 10:51:50 +02:00
default :
return " " ;
}
2018-07-14 23:15:42 +02:00
}
int VisualShaderNodeTexture : : get_output_port_count ( ) const {
2022-04-22 19:31:23 +02:00
return 1 ;
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
VisualShaderNodeTexture : : PortType VisualShaderNodeTexture : : get_output_port_type ( int p_port ) const {
2022-04-22 19:31:23 +02:00
switch ( p_port ) {
case 0 :
return PORT_TYPE_VECTOR_4D ;
default :
return PORT_TYPE_SCALAR ;
2020-05-14 16:41:43 +02:00
}
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
String VisualShaderNodeTexture : : get_output_port_name ( int p_port ) const {
2022-04-22 19:31:23 +02:00
switch ( p_port ) {
case 0 :
return " color " ;
default :
return " " ;
2020-05-14 16:41:43 +02:00
}
2018-07-14 23:15:42 +02:00
}
2020-12-20 16:45:53 +01:00
bool VisualShaderNodeTexture : : is_output_port_expandable ( int p_port ) const {
if ( p_port = = 0 ) {
return true ;
}
return false ;
}
2022-01-22 09:09:16 +01:00
bool VisualShaderNodeTexture : : is_input_port_default ( int p_port , Shader : : Mode p_mode ) const {
if ( p_mode = = Shader : : MODE_CANVAS_ITEM | | p_mode = = Shader : : MODE_SPATIAL ) {
if ( p_port = = 0 ) {
return true ;
}
2019-10-03 09:40:26 +02:00
}
2022-01-22 09:09:16 +01:00
return false ;
2019-10-03 09:40:26 +02:00
}
2018-07-14 23:15:42 +02:00
Vector < VisualShader : : DefaultTextureParam > VisualShaderNodeTexture : : get_default_texture_parameters ( VisualShader : : Type p_type , int p_id ) const {
VisualShader : : DefaultTextureParam dtp ;
dtp . name = make_unique_id ( p_type , p_id , " tex " ) ;
2021-11-12 16:23:45 +01:00
dtp . params . push_back ( texture ) ;
2018-07-14 23:15:42 +02:00
Vector < VisualShader : : DefaultTextureParam > ret ;
ret . push_back ( dtp ) ;
return ret ;
}
String VisualShaderNodeTexture : : generate_global ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id ) const {
if ( source = = SOURCE_TEXTURE ) {
String u = " uniform sampler2D " + make_unique_id ( p_type , p_id , " tex " ) ;
switch ( texture_type ) {
2020-05-10 13:00:47 +02:00
case TYPE_DATA :
break ;
case TYPE_COLOR :
2022-05-05 20:23:40 +02:00
u + = " : source_color " ;
2020-05-10 13:00:47 +02:00
break ;
2020-12-23 10:34:26 +01:00
case TYPE_NORMAL_MAP :
2020-05-10 13:00:47 +02:00
u + = " : hint_normal " ;
break ;
2021-08-14 12:38:22 +02:00
default :
break ;
2018-07-14 23:15:42 +02:00
}
2020-01-27 10:10:51 +01:00
return u + " ; \n " ;
2018-07-14 23:15:42 +02:00
}
return String ( ) ;
}
2019-01-21 20:07:53 +01:00
String VisualShaderNodeTexture : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2020-10-03 21:14:33 +02:00
String default_uv ;
2022-01-22 09:09:16 +01:00
if ( p_mode = = Shader : : MODE_CANVAS_ITEM | | p_mode = = Shader : : MODE_SPATIAL ) {
2022-02-01 09:32:01 +01:00
default_uv = " UV " ;
2020-10-03 21:14:33 +02:00
} else {
default_uv = " vec2(0.0) " ;
}
2022-04-22 19:31:23 +02:00
String code ;
2018-07-14 23:15:42 +02:00
if ( source = = SOURCE_TEXTURE ) {
String id = make_unique_id ( p_type , p_id , " tex " ) ;
2021-12-09 10:42:46 +01:00
if ( p_input_vars [ 0 ] . is_empty ( ) ) { // Use UV by default.
if ( p_input_vars [ 1 ] . is_empty ( ) ) {
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = texture( " + id + " , " + default_uv + " ); \n " ;
2019-10-10 12:11:04 +02:00
} else {
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = textureLod( " + id + " , " + default_uv + " , " + p_input_vars [ 1 ] + " ); \n " ;
2019-10-10 12:11:04 +02:00
}
2021-12-09 10:42:46 +01:00
} else if ( p_input_vars [ 1 ] . is_empty ( ) ) {
2018-07-14 23:15:42 +02:00
//no lod
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = texture( " + id + " , " + p_input_vars [ 0 ] + " ); \n " ;
2018-07-14 23:15:42 +02:00
} else {
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = textureLod( " + id + " , " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
2018-07-14 23:15:42 +02:00
}
return code ;
}
2019-10-01 10:51:50 +02:00
if ( source = = SOURCE_PORT ) {
String id = p_input_vars [ 2 ] ;
2021-12-09 10:42:46 +01:00
if ( id . is_empty ( ) ) {
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = vec4(0.0); \n " ;
2019-10-01 10:51:50 +02:00
} else {
2021-12-09 10:42:46 +01:00
if ( p_input_vars [ 0 ] . is_empty ( ) ) { // Use UV by default.
if ( p_input_vars [ 1 ] . is_empty ( ) ) {
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = texture( " + id + " , " + default_uv + " ); \n " ;
2019-10-11 09:26:57 +02:00
} else {
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = textureLod( " + id + " , " + default_uv + " , " + p_input_vars [ 1 ] + " ); \n " ;
2019-10-09 10:29:23 +02:00
}
2021-12-09 10:42:46 +01:00
} else if ( p_input_vars [ 1 ] . is_empty ( ) ) {
2019-10-01 10:51:50 +02:00
//no lod
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = texture( " + id + " , " + p_input_vars [ 0 ] + " ); \n " ;
2019-10-01 10:51:50 +02:00
} else {
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = textureLod( " + id + " , " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
2019-10-01 10:51:50 +02:00
}
}
return code ;
}
2018-07-14 23:15:42 +02:00
if ( source = = SOURCE_SCREEN & & ( p_mode = = Shader : : MODE_SPATIAL | | p_mode = = Shader : : MODE_CANVAS_ITEM ) & & p_type = = VisualShader : : TYPE_FRAGMENT ) {
2021-12-09 10:42:46 +01:00
if ( p_input_vars [ 0 ] . is_empty ( ) | | p_for_preview ) { // Use UV by default.
if ( p_input_vars [ 1 ] . is_empty ( ) ) {
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = textureLod(SCREEN_TEXTURE, " + default_uv + " , 0.0); \n " ;
2019-10-10 12:11:04 +02:00
} else {
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = textureLod(SCREEN_TEXTURE, " + default_uv + " , " + p_input_vars [ 1 ] + " ); \n " ;
2019-10-10 12:11:04 +02:00
}
2021-12-09 10:42:46 +01:00
} else if ( p_input_vars [ 1 ] . is_empty ( ) ) {
2018-07-14 23:15:42 +02:00
//no lod
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = textureLod(SCREEN_TEXTURE, " + p_input_vars [ 0 ] + " , 0.0); \n " ;
2018-07-14 23:15:42 +02:00
} else {
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = textureLod(SCREEN_TEXTURE, " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
2018-07-14 23:15:42 +02:00
}
return code ;
}
if ( source = = SOURCE_2D_TEXTURE & & p_mode = = Shader : : MODE_CANVAS_ITEM & & p_type = = VisualShader : : TYPE_FRAGMENT ) {
2021-12-09 10:42:46 +01:00
if ( p_input_vars [ 0 ] . is_empty ( ) ) { // Use UV by default.
if ( p_input_vars [ 1 ] . is_empty ( ) ) {
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = texture(TEXTURE, " + default_uv + " ); \n " ;
2019-10-10 12:11:04 +02:00
} else {
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = textureLod(TEXTURE, " + default_uv + " , " + p_input_vars [ 1 ] + " ); \n " ;
2019-10-10 12:11:04 +02:00
}
2021-12-09 10:42:46 +01:00
} else if ( p_input_vars [ 1 ] . is_empty ( ) ) {
2018-07-14 23:15:42 +02:00
//no lod
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = texture(TEXTURE, " + p_input_vars [ 0 ] + " ); \n " ;
2018-07-14 23:15:42 +02:00
} else {
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = textureLod(TEXTURE, " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
2018-07-14 23:15:42 +02:00
}
return code ;
}
if ( source = = SOURCE_2D_NORMAL & & p_mode = = Shader : : MODE_CANVAS_ITEM & & p_type = = VisualShader : : TYPE_FRAGMENT ) {
2021-12-09 10:42:46 +01:00
if ( p_input_vars [ 0 ] . is_empty ( ) ) { // Use UV by default.
if ( p_input_vars [ 1 ] . is_empty ( ) ) {
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = texture(NORMAL_TEXTURE, " + default_uv + " ); \n " ;
2019-10-10 12:11:04 +02:00
} else {
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = textureLod(NORMAL_TEXTURE, " + default_uv + " , " + p_input_vars [ 1 ] + " ); \n " ;
2019-10-10 12:11:04 +02:00
}
2021-12-09 10:42:46 +01:00
} else if ( p_input_vars [ 1 ] . is_empty ( ) ) {
2018-07-14 23:15:42 +02:00
//no lod
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = texture(NORMAL_TEXTURE, " + p_input_vars [ 0 ] + " .xy); \n " ;
2018-07-14 23:15:42 +02:00
} else {
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = textureLod(NORMAL_TEXTURE, " + p_input_vars [ 0 ] + " .xy, " + p_input_vars [ 1 ] + " ); \n " ;
2018-07-14 23:15:42 +02:00
}
return code ;
}
2022-04-22 19:31:23 +02:00
if ( source = = SOURCE_DEPTH ) {
if ( ! p_for_preview & & p_mode = = Shader : : MODE_SPATIAL & & p_type = = VisualShader : : TYPE_FRAGMENT ) {
code + = " { \n " ;
if ( p_input_vars [ 0 ] . is_empty ( ) ) { // Use UV by default.
if ( p_input_vars [ 1 ] . is_empty ( ) ) {
code + = " float _depth = texture(DEPTH_TEXTURE, " + default_uv + " ).r; \n " ;
} else {
code + = " float _depth = textureLod(DEPTH_TEXTURE, " + default_uv + " , " + p_input_vars [ 1 ] + " ).r; \n " ;
}
} else if ( p_input_vars [ 1 ] . is_empty ( ) ) {
//no lod
code + = " float _depth = texture(DEPTH_TEXTURE, " + p_input_vars [ 0 ] + " .xy).r; \n " ;
2019-10-10 12:11:04 +02:00
} else {
2022-04-22 19:31:23 +02:00
code + = " float _depth = textureLod(DEPTH_TEXTURE, " + p_input_vars [ 0 ] + " .xy, " + p_input_vars [ 1 ] + " ).r; \n " ;
2019-10-10 12:11:04 +02:00
}
2019-07-05 10:48:31 +02:00
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = vec4(_depth, _depth, _depth, 1.0); \n " ;
code + = " } \n " ;
return code ;
2019-07-05 10:48:31 +02:00
}
}
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = vec4(0.0); \n " ;
2018-07-14 23:15:42 +02:00
return code ;
}
void VisualShaderNodeTexture : : set_source ( Source p_source ) {
2021-08-14 12:38:22 +02:00
ERR_FAIL_INDEX ( int ( p_source ) , int ( SOURCE_MAX ) ) ;
if ( source = = p_source ) {
return ;
}
switch ( p_source ) {
2020-01-27 10:10:51 +01:00
case SOURCE_TEXTURE :
simple_decl = true ;
break ;
case SOURCE_SCREEN :
simple_decl = false ;
break ;
case SOURCE_2D_TEXTURE :
simple_decl = false ;
break ;
case SOURCE_2D_NORMAL :
simple_decl = false ;
break ;
case SOURCE_DEPTH :
simple_decl = false ;
break ;
case SOURCE_PORT :
simple_decl = false ;
break ;
2021-08-14 12:38:22 +02:00
default :
break ;
2020-01-27 10:10:51 +01:00
}
2021-08-14 12:38:22 +02:00
source = p_source ;
2018-07-14 23:15:42 +02:00
emit_changed ( ) ;
2021-07-17 23:22:52 +02:00
emit_signal ( SNAME ( " editor_refresh_request " ) ) ;
2018-07-14 23:15:42 +02:00
}
VisualShaderNodeTexture : : Source VisualShaderNodeTexture : : get_source ( ) const {
return source ;
}
2021-08-14 12:38:22 +02:00
void VisualShaderNodeTexture : : set_texture ( Ref < Texture2D > p_texture ) {
texture = p_texture ;
2018-07-14 23:15:42 +02:00
emit_changed ( ) ;
}
2019-06-11 20:43:37 +02:00
Ref < Texture2D > VisualShaderNodeTexture : : get_texture ( ) const {
2018-07-14 23:15:42 +02:00
return texture ;
}
2021-08-14 12:38:22 +02:00
void VisualShaderNodeTexture : : set_texture_type ( TextureType p_texture_type ) {
ERR_FAIL_INDEX ( int ( p_texture_type ) , int ( TYPE_MAX ) ) ;
if ( texture_type = = p_texture_type ) {
return ;
}
texture_type = p_texture_type ;
2018-07-14 23:15:42 +02:00
emit_changed ( ) ;
}
VisualShaderNodeTexture : : TextureType VisualShaderNodeTexture : : get_texture_type ( ) const {
return texture_type ;
}
Vector < StringName > VisualShaderNodeTexture : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " source " ) ;
if ( source = = SOURCE_TEXTURE ) {
props . push_back ( " texture " ) ;
props . push_back ( " texture_type " ) ;
}
return props ;
}
String VisualShaderNodeTexture : : get_warning ( Shader : : Mode p_mode , VisualShader : : Type p_type ) const {
2020-11-26 12:25:35 +01:00
if ( is_input_port_connected ( 2 ) & & source ! = SOURCE_PORT ) {
2022-03-28 15:24:14 +02:00
return RTR ( " The sampler port is connected but not used. Consider changing the source to 'SamplerPort'. " ) ;
2020-11-26 12:25:35 +01:00
}
2018-07-14 23:15:42 +02:00
if ( source = = SOURCE_TEXTURE ) {
return String ( ) ; // all good
}
2019-10-01 10:51:50 +02:00
if ( source = = SOURCE_PORT ) {
return String ( ) ; // all good
}
2018-07-14 23:15:42 +02:00
if ( source = = SOURCE_SCREEN & & ( p_mode = = Shader : : MODE_SPATIAL | | p_mode = = Shader : : MODE_CANVAS_ITEM ) & & p_type = = VisualShader : : TYPE_FRAGMENT ) {
return String ( ) ; // all good
}
if ( source = = SOURCE_2D_TEXTURE & & p_mode = = Shader : : MODE_CANVAS_ITEM & & p_type = = VisualShader : : TYPE_FRAGMENT ) {
return String ( ) ; // all good
}
if ( source = = SOURCE_2D_NORMAL & & p_mode = = Shader : : MODE_CANVAS_ITEM ) {
return String ( ) ; // all good
}
2019-07-05 10:48:31 +02:00
if ( source = = SOURCE_DEPTH & & p_mode = = Shader : : MODE_SPATIAL & & p_type = = VisualShader : : TYPE_FRAGMENT ) {
if ( get_output_port_for_preview ( ) = = 0 ) { // DEPTH_TEXTURE is not supported in preview(canvas_item) shader
2022-03-28 15:24:14 +02:00
return RTR ( " Invalid source for preview. " ) ;
2019-07-05 10:48:31 +02:00
}
return String ( ) ; // all good
}
2022-03-28 15:24:14 +02:00
return RTR ( " Invalid source for shader. " ) ;
2018-07-14 23:15:42 +02:00
}
void VisualShaderNodeTexture : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_source " , " value " ) , & VisualShaderNodeTexture : : set_source ) ;
ClassDB : : bind_method ( D_METHOD ( " get_source " ) , & VisualShaderNodeTexture : : get_source ) ;
ClassDB : : bind_method ( D_METHOD ( " set_texture " , " value " ) , & VisualShaderNodeTexture : : set_texture ) ;
ClassDB : : bind_method ( D_METHOD ( " get_texture " ) , & VisualShaderNodeTexture : : get_texture ) ;
ClassDB : : bind_method ( D_METHOD ( " set_texture_type " , " value " ) , & VisualShaderNodeTexture : : set_texture_type ) ;
ClassDB : : bind_method ( D_METHOD ( " get_texture_type " ) , & VisualShaderNodeTexture : : get_texture_type ) ;
2019-10-01 10:51:50 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " source " , PROPERTY_HINT_ENUM , " Texture,Screen,Texture2D,NormalMap2D,Depth,SamplerPort " ) , " set_source " , " get_source " ) ;
2019-06-11 20:43:37 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : OBJECT , " texture " , PROPERTY_HINT_RESOURCE_TYPE , " Texture2D " ) , " set_texture " , " get_texture " ) ;
2021-05-22 04:30:58 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " texture_type " , PROPERTY_HINT_ENUM , " Data,Color,Normal Map " ) , " set_texture_type " , " get_texture_type " ) ;
2018-07-14 23:15:42 +02:00
BIND_ENUM_CONSTANT ( SOURCE_TEXTURE ) ;
BIND_ENUM_CONSTANT ( SOURCE_SCREEN ) ;
BIND_ENUM_CONSTANT ( SOURCE_2D_TEXTURE ) ;
BIND_ENUM_CONSTANT ( SOURCE_2D_NORMAL ) ;
2019-07-05 10:48:31 +02:00
BIND_ENUM_CONSTANT ( SOURCE_DEPTH ) ;
2019-12-12 10:05:54 +01:00
BIND_ENUM_CONSTANT ( SOURCE_PORT ) ;
2021-08-14 12:38:22 +02:00
BIND_ENUM_CONSTANT ( SOURCE_MAX ) ;
2018-07-14 23:15:42 +02:00
BIND_ENUM_CONSTANT ( TYPE_DATA ) ;
BIND_ENUM_CONSTANT ( TYPE_COLOR ) ;
2020-12-23 10:34:26 +01:00
BIND_ENUM_CONSTANT ( TYPE_NORMAL_MAP ) ;
2021-08-14 12:38:22 +02:00
BIND_ENUM_CONSTANT ( TYPE_MAX ) ;
2018-07-14 23:15:42 +02:00
}
VisualShaderNodeTexture : : VisualShaderNodeTexture ( ) {
}
2021-07-04 10:56:21 +02:00
////////////// CurveTexture
2020-10-04 11:11:58 +02:00
String VisualShaderNodeCurveTexture : : get_caption ( ) const {
return " CurveTexture " ;
}
int VisualShaderNodeCurveTexture : : get_input_port_count ( ) const {
return 1 ;
}
VisualShaderNodeCurveTexture : : PortType VisualShaderNodeCurveTexture : : get_input_port_type ( int p_port ) const {
return PORT_TYPE_SCALAR ;
}
String VisualShaderNodeCurveTexture : : get_input_port_name ( int p_port ) const {
return String ( ) ;
}
int VisualShaderNodeCurveTexture : : get_output_port_count ( ) const {
return 1 ;
}
VisualShaderNodeCurveTexture : : PortType VisualShaderNodeCurveTexture : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_SCALAR ;
}
String VisualShaderNodeCurveTexture : : get_output_port_name ( int p_port ) const {
return String ( ) ;
}
void VisualShaderNodeCurveTexture : : set_texture ( Ref < CurveTexture > p_texture ) {
texture = p_texture ;
emit_changed ( ) ;
}
Ref < CurveTexture > VisualShaderNodeCurveTexture : : get_texture ( ) const {
return texture ;
}
Vector < StringName > VisualShaderNodeCurveTexture : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " texture " ) ;
return props ;
}
String VisualShaderNodeCurveTexture : : generate_global ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id ) const {
2022-08-06 15:14:40 +02:00
return " uniform sampler2D " + make_unique_id ( p_type , p_id , " curve " ) + " : repeat_disable; \n " ;
2020-10-04 11:11:58 +02:00
}
String VisualShaderNodeCurveTexture : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-12-09 10:42:46 +01:00
if ( p_input_vars [ 0 ] . is_empty ( ) ) {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = 0.0; \n " ;
2020-10-04 11:11:58 +02:00
}
String id = make_unique_id ( p_type , p_id , " curve " ) ;
String code ;
2021-07-19 08:06:51 +02:00
code + = " " + p_output_vars [ 0 ] + " = texture( " + id + " , vec2( " + p_input_vars [ 0 ] + " )).r; \n " ;
2020-10-04 11:11:58 +02:00
return code ;
}
Vector < VisualShader : : DefaultTextureParam > VisualShaderNodeCurveTexture : : get_default_texture_parameters ( VisualShader : : Type p_type , int p_id ) const {
VisualShader : : DefaultTextureParam dtp ;
dtp . name = make_unique_id ( p_type , p_id , " curve " ) ;
2021-11-12 16:23:45 +01:00
dtp . params . push_back ( texture ) ;
2020-10-04 11:11:58 +02:00
Vector < VisualShader : : DefaultTextureParam > ret ;
ret . push_back ( dtp ) ;
return ret ;
}
void VisualShaderNodeCurveTexture : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_texture " , " texture " ) , & VisualShaderNodeCurveTexture : : set_texture ) ;
ClassDB : : bind_method ( D_METHOD ( " get_texture " ) , & VisualShaderNodeCurveTexture : : get_texture ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : OBJECT , " texture " , PROPERTY_HINT_RESOURCE_TYPE , " CurveTexture " ) , " set_texture " , " get_texture " ) ;
}
bool VisualShaderNodeCurveTexture : : is_use_prop_slots ( ) const {
return true ;
}
VisualShaderNodeCurveTexture : : VisualShaderNodeCurveTexture ( ) {
2021-10-13 14:25:12 +02:00
set_input_port_default_value ( 0 , 0.0 ) ;
2020-10-04 11:11:58 +02:00
simple_decl = true ;
allow_v_resize = false ;
}
2021-07-14 00:06:44 +02:00
////////////// CurveXYZTexture
2021-07-04 10:56:21 +02:00
2021-07-14 00:06:44 +02:00
String VisualShaderNodeCurveXYZTexture : : get_caption ( ) const {
return " CurveXYZTexture " ;
2021-07-04 10:56:21 +02:00
}
2021-07-14 00:06:44 +02:00
int VisualShaderNodeCurveXYZTexture : : get_input_port_count ( ) const {
2021-07-04 10:56:21 +02:00
return 1 ;
}
2021-07-14 00:06:44 +02:00
VisualShaderNodeCurveXYZTexture : : PortType VisualShaderNodeCurveXYZTexture : : get_input_port_type ( int p_port ) const {
2021-07-04 10:56:21 +02:00
return PORT_TYPE_SCALAR ;
}
2021-07-14 00:06:44 +02:00
String VisualShaderNodeCurveXYZTexture : : get_input_port_name ( int p_port ) const {
2021-07-04 10:56:21 +02:00
return String ( ) ;
}
2021-07-14 00:06:44 +02:00
int VisualShaderNodeCurveXYZTexture : : get_output_port_count ( ) const {
2021-07-04 10:56:21 +02:00
return 1 ;
}
2021-07-14 00:06:44 +02:00
VisualShaderNodeCurveXYZTexture : : PortType VisualShaderNodeCurveXYZTexture : : get_output_port_type ( int p_port ) const {
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2021-07-04 10:56:21 +02:00
}
2021-07-14 00:06:44 +02:00
String VisualShaderNodeCurveXYZTexture : : get_output_port_name ( int p_port ) const {
2021-07-04 10:56:21 +02:00
return String ( ) ;
}
2021-07-14 00:06:44 +02:00
void VisualShaderNodeCurveXYZTexture : : set_texture ( Ref < CurveXYZTexture > p_texture ) {
2021-07-04 10:56:21 +02:00
texture = p_texture ;
emit_changed ( ) ;
}
2021-07-14 00:06:44 +02:00
Ref < CurveXYZTexture > VisualShaderNodeCurveXYZTexture : : get_texture ( ) const {
2021-07-04 10:56:21 +02:00
return texture ;
}
2021-07-14 00:06:44 +02:00
Vector < StringName > VisualShaderNodeCurveXYZTexture : : get_editable_properties ( ) const {
2021-07-04 10:56:21 +02:00
Vector < StringName > props ;
props . push_back ( " texture " ) ;
return props ;
}
2021-07-14 00:06:44 +02:00
String VisualShaderNodeCurveXYZTexture : : generate_global ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id ) const {
2021-07-04 10:56:21 +02:00
return " uniform sampler2D " + make_unique_id ( p_type , p_id , " curve3d " ) + " ; \n " ;
}
2021-07-14 00:06:44 +02:00
String VisualShaderNodeCurveXYZTexture : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-12-09 10:42:46 +01:00
if ( p_input_vars [ 0 ] . is_empty ( ) ) {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = vec3(0.0); \n " ;
2021-07-04 10:56:21 +02:00
}
String id = make_unique_id ( p_type , p_id , " curve3d " ) ;
String code ;
2021-07-19 08:06:51 +02:00
code + = " " + p_output_vars [ 0 ] + " = texture( " + id + " , vec2( " + p_input_vars [ 0 ] + " )).rgb; \n " ;
2021-07-04 10:56:21 +02:00
return code ;
}
2021-07-14 00:06:44 +02:00
Vector < VisualShader : : DefaultTextureParam > VisualShaderNodeCurveXYZTexture : : get_default_texture_parameters ( VisualShader : : Type p_type , int p_id ) const {
2021-07-04 10:56:21 +02:00
VisualShader : : DefaultTextureParam dtp ;
dtp . name = make_unique_id ( p_type , p_id , " curve3d " ) ;
2021-11-12 16:23:45 +01:00
dtp . params . push_back ( texture ) ;
2021-07-04 10:56:21 +02:00
Vector < VisualShader : : DefaultTextureParam > ret ;
ret . push_back ( dtp ) ;
return ret ;
}
2021-07-14 00:06:44 +02:00
void VisualShaderNodeCurveXYZTexture : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_texture " , " texture " ) , & VisualShaderNodeCurveXYZTexture : : set_texture ) ;
ClassDB : : bind_method ( D_METHOD ( " get_texture " ) , & VisualShaderNodeCurveXYZTexture : : get_texture ) ;
2021-07-04 10:56:21 +02:00
2021-07-14 00:06:44 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : OBJECT , " texture " , PROPERTY_HINT_RESOURCE_TYPE , " CurveXYZTexture " ) , " set_texture " , " get_texture " ) ;
2021-07-04 10:56:21 +02:00
}
2021-07-14 00:06:44 +02:00
bool VisualShaderNodeCurveXYZTexture : : is_use_prop_slots ( ) const {
2021-07-04 10:56:21 +02:00
return true ;
}
2021-07-14 00:06:44 +02:00
VisualShaderNodeCurveXYZTexture : : VisualShaderNodeCurveXYZTexture ( ) {
2021-10-13 14:25:12 +02:00
set_input_port_default_value ( 0 , 0.0 ) ;
2021-07-04 10:56:21 +02:00
simple_decl = true ;
allow_v_resize = false ;
}
2020-02-18 12:45:23 +01:00
////////////// Sample3D
int VisualShaderNodeSample3D : : get_input_port_count ( ) const {
return 3 ;
}
VisualShaderNodeSample3D : : PortType VisualShaderNodeSample3D : : get_input_port_type ( int p_port ) const {
switch ( p_port ) {
case 0 :
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2020-02-18 12:45:23 +01:00
case 1 :
return PORT_TYPE_SCALAR ;
case 2 :
return PORT_TYPE_SAMPLER ;
default :
return PORT_TYPE_SCALAR ;
}
}
String VisualShaderNodeSample3D : : get_input_port_name ( int p_port ) const {
switch ( p_port ) {
case 0 :
return " uvw " ;
case 1 :
return " lod " ;
default :
return " " ;
}
}
int VisualShaderNodeSample3D : : get_output_port_count ( ) const {
2022-04-22 19:31:23 +02:00
return 1 ;
2020-02-18 12:45:23 +01:00
}
VisualShaderNodeSample3D : : PortType VisualShaderNodeSample3D : : get_output_port_type ( int p_port ) const {
2022-04-22 19:31:23 +02:00
return p_port = = 0 ? PORT_TYPE_VECTOR_4D : PORT_TYPE_SCALAR ;
2020-02-18 12:45:23 +01:00
}
String VisualShaderNodeSample3D : : get_output_port_name ( int p_port ) const {
2022-04-22 19:31:23 +02:00
return " color " ;
2020-02-18 12:45:23 +01:00
}
2020-12-20 16:45:53 +01:00
bool VisualShaderNodeSample3D : : is_output_port_expandable ( int p_port ) const {
if ( p_port = = 0 ) {
return true ;
}
return false ;
}
2022-01-22 09:09:16 +01:00
bool VisualShaderNodeSample3D : : is_input_port_default ( int p_port , Shader : : Mode p_mode ) const {
if ( p_mode = = Shader : : MODE_CANVAS_ITEM | | p_mode = = Shader : : MODE_SPATIAL ) {
if ( p_port = = 0 ) {
return true ;
}
2020-02-18 12:45:23 +01:00
}
2022-01-22 09:09:16 +01:00
return false ;
2020-02-18 12:45:23 +01:00
}
String VisualShaderNodeSample3D : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2020-10-03 21:14:33 +02:00
String default_uv ;
2022-01-22 09:09:16 +01:00
if ( p_mode = = Shader : : MODE_CANVAS_ITEM | | p_mode = = Shader : : MODE_SPATIAL ) {
2020-10-03 21:14:33 +02:00
default_uv = " vec3(UV, 0.0) " ;
} else {
default_uv = " vec3(0.0) " ;
}
2020-02-18 12:45:23 +01:00
String code ;
if ( source = = SOURCE_TEXTURE | | source = = SOURCE_PORT ) {
String id ;
if ( source = = SOURCE_TEXTURE ) {
id = make_unique_id ( p_type , p_id , " tex3d " ) ;
} else {
id = p_input_vars [ 2 ] ;
}
2021-12-09 10:42:46 +01:00
if ( ! id . is_empty ( ) ) {
if ( p_input_vars [ 0 ] . is_empty ( ) ) { // Use UV by default.
if ( p_input_vars [ 1 ] . is_empty ( ) ) {
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = texture( " + id + " , " + default_uv + " ); \n " ;
2020-02-18 12:45:23 +01:00
} else {
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = textureLod( " + id + " , " + default_uv + " , " + p_input_vars [ 1 ] + " ); \n " ;
2020-02-18 12:45:23 +01:00
}
2021-12-09 10:42:46 +01:00
} else if ( p_input_vars [ 1 ] . is_empty ( ) ) {
2020-02-18 12:45:23 +01:00
//no lod
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = texture( " + id + " , " + p_input_vars [ 0 ] + " ); \n " ;
2020-02-18 12:45:23 +01:00
} else {
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = textureLod( " + id + " , " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
2020-02-18 12:45:23 +01:00
}
} else {
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = vec4(0.0); \n " ;
2020-02-18 12:45:23 +01:00
}
return code ;
}
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = vec4(0.0); \n " ;
2020-02-18 12:45:23 +01:00
return code ;
}
void VisualShaderNodeSample3D : : set_source ( Source p_source ) {
2021-08-14 12:38:22 +02:00
ERR_FAIL_INDEX ( int ( p_source ) , int ( SOURCE_MAX ) ) ;
if ( source = = p_source ) {
return ;
}
2020-02-18 12:45:23 +01:00
source = p_source ;
emit_changed ( ) ;
2021-07-17 23:22:52 +02:00
emit_signal ( SNAME ( " editor_refresh_request " ) ) ;
2020-02-18 12:45:23 +01:00
}
VisualShaderNodeSample3D : : Source VisualShaderNodeSample3D : : get_source ( ) const {
return source ;
}
void VisualShaderNodeSample3D : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_source " , " value " ) , & VisualShaderNodeSample3D : : set_source ) ;
ClassDB : : bind_method ( D_METHOD ( " get_source " ) , & VisualShaderNodeSample3D : : get_source ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " source " , PROPERTY_HINT_ENUM , " Texture,SamplerPort " ) , " set_source " , " get_source " ) ;
BIND_ENUM_CONSTANT ( SOURCE_TEXTURE ) ;
BIND_ENUM_CONSTANT ( SOURCE_PORT ) ;
2021-08-14 12:38:22 +02:00
BIND_ENUM_CONSTANT ( SOURCE_MAX ) ;
2020-02-18 12:45:23 +01:00
}
String VisualShaderNodeSample3D : : get_warning ( Shader : : Mode p_mode , VisualShader : : Type p_type ) const {
2020-11-26 12:25:35 +01:00
if ( is_input_port_connected ( 2 ) & & source ! = SOURCE_PORT ) {
2022-03-28 15:24:14 +02:00
return RTR ( " The sampler port is connected but not used. Consider changing the source to 'SamplerPort'. " ) ;
2020-11-26 12:25:35 +01:00
}
2020-02-18 12:45:23 +01:00
if ( source = = SOURCE_TEXTURE ) {
return String ( ) ; // all good
}
if ( source = = SOURCE_PORT ) {
return String ( ) ; // all good
}
2022-03-28 15:24:14 +02:00
return RTR ( " Invalid source for shader. " ) ;
2020-02-18 12:45:23 +01:00
}
VisualShaderNodeSample3D : : VisualShaderNodeSample3D ( ) {
2020-09-07 11:29:44 +02:00
simple_decl = false ;
2020-02-18 12:45:23 +01:00
}
////////////// Texture2DArray
String VisualShaderNodeTexture2DArray : : get_caption ( ) const {
return " Texture2DArray " ;
}
String VisualShaderNodeTexture2DArray : : get_input_port_name ( int p_port ) const {
if ( p_port = = 2 ) {
return " sampler2DArray " ;
}
return VisualShaderNodeSample3D : : get_input_port_name ( p_port ) ;
}
Vector < VisualShader : : DefaultTextureParam > VisualShaderNodeTexture2DArray : : get_default_texture_parameters ( VisualShader : : Type p_type , int p_id ) const {
VisualShader : : DefaultTextureParam dtp ;
dtp . name = make_unique_id ( p_type , p_id , " tex3d " ) ;
2021-11-12 16:23:45 +01:00
dtp . params . push_back ( texture_array ) ;
2020-02-18 12:45:23 +01:00
Vector < VisualShader : : DefaultTextureParam > ret ;
ret . push_back ( dtp ) ;
return ret ;
}
String VisualShaderNodeTexture2DArray : : generate_global ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id ) const {
if ( source = = SOURCE_TEXTURE ) {
return " uniform sampler2DArray " + make_unique_id ( p_type , p_id , " tex3d " ) + " ; \n " ;
}
return String ( ) ;
}
2021-08-14 12:38:22 +02:00
void VisualShaderNodeTexture2DArray : : set_texture_array ( Ref < Texture2DArray > p_texture_array ) {
texture_array = p_texture_array ;
2020-02-18 12:45:23 +01:00
emit_changed ( ) ;
}
Ref < Texture2DArray > VisualShaderNodeTexture2DArray : : get_texture_array ( ) const {
2021-08-14 12:38:22 +02:00
return texture_array ;
2020-02-18 12:45:23 +01:00
}
Vector < StringName > VisualShaderNodeTexture2DArray : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " source " ) ;
if ( source = = SOURCE_TEXTURE ) {
props . push_back ( " texture_array " ) ;
}
return props ;
}
void VisualShaderNodeTexture2DArray : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_texture_array " , " value " ) , & VisualShaderNodeTexture2DArray : : set_texture_array ) ;
ClassDB : : bind_method ( D_METHOD ( " get_texture_array " ) , & VisualShaderNodeTexture2DArray : : get_texture_array ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : OBJECT , " texture_array " , PROPERTY_HINT_RESOURCE_TYPE , " Texture2DArray " ) , " set_texture_array " , " get_texture_array " ) ;
}
VisualShaderNodeTexture2DArray : : VisualShaderNodeTexture2DArray ( ) {
}
2020-09-10 05:47:09 +02:00
////////////// Texture3D
String VisualShaderNodeTexture3D : : get_caption ( ) const {
return " Texture3D " ;
}
String VisualShaderNodeTexture3D : : get_input_port_name ( int p_port ) const {
if ( p_port = = 2 ) {
return " sampler3D " ;
}
return VisualShaderNodeSample3D : : get_input_port_name ( p_port ) ;
}
Vector < VisualShader : : DefaultTextureParam > VisualShaderNodeTexture3D : : get_default_texture_parameters ( VisualShader : : Type p_type , int p_id ) const {
VisualShader : : DefaultTextureParam dtp ;
dtp . name = make_unique_id ( p_type , p_id , " tex3d " ) ;
2021-11-12 16:23:45 +01:00
dtp . params . push_back ( texture ) ;
2020-09-10 05:47:09 +02:00
Vector < VisualShader : : DefaultTextureParam > ret ;
ret . push_back ( dtp ) ;
return ret ;
}
String VisualShaderNodeTexture3D : : generate_global ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id ) const {
if ( source = = SOURCE_TEXTURE ) {
return " uniform sampler3D " + make_unique_id ( p_type , p_id , " tex3d " ) + " ; \n " ;
}
return String ( ) ;
}
2021-08-14 12:38:22 +02:00
void VisualShaderNodeTexture3D : : set_texture ( Ref < Texture3D > p_texture ) {
texture = p_texture ;
2020-09-10 05:47:09 +02:00
emit_changed ( ) ;
}
Ref < Texture3D > VisualShaderNodeTexture3D : : get_texture ( ) const {
return texture ;
}
Vector < StringName > VisualShaderNodeTexture3D : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " source " ) ;
if ( source = = SOURCE_TEXTURE ) {
props . push_back ( " texture " ) ;
}
return props ;
}
void VisualShaderNodeTexture3D : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_texture " , " value " ) , & VisualShaderNodeTexture3D : : set_texture ) ;
ClassDB : : bind_method ( D_METHOD ( " get_texture " ) , & VisualShaderNodeTexture3D : : get_texture ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : OBJECT , " texture " , PROPERTY_HINT_RESOURCE_TYPE , " Texture3D " ) , " set_texture " , " get_texture " ) ;
}
VisualShaderNodeTexture3D : : VisualShaderNodeTexture3D ( ) {
}
2019-06-11 20:43:37 +02:00
////////////// Cubemap
2018-07-14 23:15:42 +02:00
2019-06-11 20:43:37 +02:00
String VisualShaderNodeCubemap : : get_caption ( ) const {
return " Cubemap " ;
2018-07-14 23:15:42 +02:00
}
2019-06-11 20:43:37 +02:00
int VisualShaderNodeCubemap : : get_input_port_count ( ) const {
2019-10-11 09:26:57 +02:00
return 3 ;
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2019-06-11 20:43:37 +02:00
VisualShaderNodeCubemap : : PortType VisualShaderNodeCubemap : : get_input_port_type ( int p_port ) const {
2019-10-11 09:26:57 +02:00
switch ( p_port ) {
case 0 :
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2019-10-11 09:26:57 +02:00
case 1 :
return PORT_TYPE_SCALAR ;
case 2 :
return PORT_TYPE_SAMPLER ;
default :
return PORT_TYPE_SCALAR ;
}
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2019-06-11 20:43:37 +02:00
String VisualShaderNodeCubemap : : get_input_port_name ( int p_port ) const {
2019-10-11 09:26:57 +02:00
switch ( p_port ) {
case 0 :
return " uv " ;
case 1 :
return " lod " ;
case 2 :
return " samplerCube " ;
default :
return " " ;
}
2018-07-14 23:15:42 +02:00
}
2019-06-11 20:43:37 +02:00
int VisualShaderNodeCubemap : : get_output_port_count ( ) const {
2022-04-22 19:31:23 +02:00
return 1 ;
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2019-06-11 20:43:37 +02:00
VisualShaderNodeCubemap : : PortType VisualShaderNodeCubemap : : get_output_port_type ( int p_port ) const {
2022-04-22 19:31:23 +02:00
return PORT_TYPE_VECTOR_4D ;
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2019-06-11 20:43:37 +02:00
String VisualShaderNodeCubemap : : get_output_port_name ( int p_port ) const {
2022-04-22 19:31:23 +02:00
return " color " ;
2018-07-14 23:15:42 +02:00
}
2020-12-20 16:45:53 +01:00
bool VisualShaderNodeCubemap : : is_output_port_expandable ( int p_port ) const {
if ( p_port = = 0 ) {
return true ;
}
return false ;
}
2019-06-11 20:43:37 +02:00
Vector < VisualShader : : DefaultTextureParam > VisualShaderNodeCubemap : : get_default_texture_parameters ( VisualShader : : Type p_type , int p_id ) const {
2018-07-14 23:15:42 +02:00
VisualShader : : DefaultTextureParam dtp ;
dtp . name = make_unique_id ( p_type , p_id , " cube " ) ;
2021-11-12 16:23:45 +01:00
dtp . params . push_back ( cube_map ) ;
2018-07-14 23:15:42 +02:00
Vector < VisualShader : : DefaultTextureParam > ret ;
ret . push_back ( dtp ) ;
return ret ;
}
2019-06-11 20:43:37 +02:00
String VisualShaderNodeCubemap : : generate_global ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id ) const {
2019-10-11 09:26:57 +02:00
if ( source = = SOURCE_TEXTURE ) {
String u = " uniform samplerCube " + make_unique_id ( p_type , p_id , " cube " ) ;
switch ( texture_type ) {
2020-05-10 13:00:47 +02:00
case TYPE_DATA :
break ;
case TYPE_COLOR :
2022-05-05 20:23:40 +02:00
u + = " : source_color " ;
2020-05-10 13:00:47 +02:00
break ;
2020-12-23 10:34:26 +01:00
case TYPE_NORMAL_MAP :
2020-05-10 13:00:47 +02:00
u + = " : hint_normal " ;
break ;
2021-08-14 12:38:22 +02:00
default :
break ;
2019-10-11 09:26:57 +02:00
}
2020-01-27 10:17:06 +01:00
return u + " ; \n " ;
2018-07-14 23:15:42 +02:00
}
2019-10-11 09:26:57 +02:00
return String ( ) ;
2018-07-14 23:15:42 +02:00
}
2019-06-11 20:43:37 +02:00
String VisualShaderNodeCubemap : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2020-10-03 21:14:33 +02:00
String default_uv ;
2022-01-22 09:09:16 +01:00
if ( p_mode = = Shader : : MODE_CANVAS_ITEM | | p_mode = = Shader : : MODE_SPATIAL ) {
2020-10-03 21:14:33 +02:00
default_uv = " vec3(UV, 0.0) " ;
} else {
default_uv = " vec3(0.0) " ;
}
2018-07-14 23:15:42 +02:00
String code ;
2019-10-11 09:26:57 +02:00
String id ;
if ( source = = SOURCE_TEXTURE ) {
id = make_unique_id ( p_type , p_id , " cube " ) ;
} else if ( source = = SOURCE_PORT ) {
id = p_input_vars [ 2 ] ;
} else {
2022-04-22 19:31:23 +02:00
return code ;
2019-10-11 09:26:57 +02:00
}
2021-12-09 10:42:46 +01:00
if ( id . is_empty ( ) ) {
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = vec4(0.0); \n " ;
2019-10-11 09:26:57 +02:00
return code ;
}
2021-12-09 10:42:46 +01:00
if ( p_input_vars [ 0 ] . is_empty ( ) ) { // Use UV by default.
2018-07-14 23:15:42 +02:00
2021-12-09 10:42:46 +01:00
if ( p_input_vars [ 1 ] . is_empty ( ) ) {
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = texture( " + id + " , " + default_uv + " ); \n " ;
2019-10-10 12:11:04 +02:00
} else {
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = textureLod( " + id + " , " + default_uv + " , " + p_input_vars [ 1 ] + " ); \n " ;
2019-10-10 12:11:04 +02:00
}
2018-07-14 23:15:42 +02:00
2021-12-09 10:42:46 +01:00
} else if ( p_input_vars [ 1 ] . is_empty ( ) ) {
2018-07-14 23:15:42 +02:00
//no lod
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = texture( " + id + " , " + p_input_vars [ 0 ] + " ); \n " ;
2018-07-14 23:15:42 +02:00
} else {
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = textureLod( " + id + " , " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
2018-07-14 23:15:42 +02:00
}
return code ;
}
2022-01-22 09:09:16 +01:00
bool VisualShaderNodeCubemap : : is_input_port_default ( int p_port , Shader : : Mode p_mode ) const {
if ( p_mode = = Shader : : MODE_CANVAS_ITEM | | p_mode = = Shader : : MODE_SPATIAL ) {
if ( p_port = = 0 ) {
return true ;
}
2019-10-09 10:29:23 +02:00
}
2022-01-22 09:09:16 +01:00
return false ;
2019-10-09 10:29:23 +02:00
}
2019-06-11 20:43:37 +02:00
void VisualShaderNodeCubemap : : set_source ( Source p_source ) {
2021-08-14 12:38:22 +02:00
ERR_FAIL_INDEX ( int ( p_source ) , int ( SOURCE_MAX ) ) ;
if ( source = = p_source ) {
return ;
}
2019-10-11 09:26:57 +02:00
source = p_source ;
emit_changed ( ) ;
2021-07-17 23:22:52 +02:00
emit_signal ( SNAME ( " editor_refresh_request " ) ) ;
2019-10-11 09:26:57 +02:00
}
2019-06-11 20:43:37 +02:00
VisualShaderNodeCubemap : : Source VisualShaderNodeCubemap : : get_source ( ) const {
2019-10-11 09:26:57 +02:00
return source ;
}
2021-08-14 12:38:22 +02:00
void VisualShaderNodeCubemap : : set_cube_map ( Ref < Cubemap > p_cube_map ) {
cube_map = p_cube_map ;
2018-07-14 23:15:42 +02:00
emit_changed ( ) ;
}
2019-06-11 20:43:37 +02:00
Ref < Cubemap > VisualShaderNodeCubemap : : get_cube_map ( ) const {
2018-07-14 23:15:42 +02:00
return cube_map ;
}
2021-08-14 12:38:22 +02:00
void VisualShaderNodeCubemap : : set_texture_type ( TextureType p_texture_type ) {
ERR_FAIL_INDEX ( int ( p_texture_type ) , int ( TYPE_MAX ) ) ;
if ( texture_type = = p_texture_type ) {
return ;
}
texture_type = p_texture_type ;
2018-07-14 23:15:42 +02:00
emit_changed ( ) ;
}
2019-06-11 20:43:37 +02:00
VisualShaderNodeCubemap : : TextureType VisualShaderNodeCubemap : : get_texture_type ( ) const {
2018-07-14 23:15:42 +02:00
return texture_type ;
}
2019-06-11 20:43:37 +02:00
Vector < StringName > VisualShaderNodeCubemap : : get_editable_properties ( ) const {
2018-07-14 23:15:42 +02:00
Vector < StringName > props ;
2019-10-11 09:26:57 +02:00
props . push_back ( " source " ) ;
if ( source = = SOURCE_TEXTURE ) {
props . push_back ( " cube_map " ) ;
props . push_back ( " texture_type " ) ;
}
2018-07-14 23:15:42 +02:00
return props ;
}
2020-11-26 12:25:35 +01:00
String VisualShaderNodeCubemap : : get_warning ( Shader : : Mode p_mode , VisualShader : : Type p_type ) const {
if ( is_input_port_connected ( 2 ) & & source ! = SOURCE_PORT ) {
2022-03-28 15:24:14 +02:00
return RTR ( " The sampler port is connected but not used. Consider changing the source to 'SamplerPort'. " ) ;
2020-11-26 12:25:35 +01:00
}
return String ( ) ;
}
2019-06-11 20:43:37 +02:00
void VisualShaderNodeCubemap : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_source " , " value " ) , & VisualShaderNodeCubemap : : set_source ) ;
ClassDB : : bind_method ( D_METHOD ( " get_source " ) , & VisualShaderNodeCubemap : : get_source ) ;
2019-10-11 09:26:57 +02:00
2019-06-11 20:43:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_cube_map " , " value " ) , & VisualShaderNodeCubemap : : set_cube_map ) ;
ClassDB : : bind_method ( D_METHOD ( " get_cube_map " ) , & VisualShaderNodeCubemap : : get_cube_map ) ;
2018-07-14 23:15:42 +02:00
2019-06-11 20:43:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_texture_type " , " value " ) , & VisualShaderNodeCubemap : : set_texture_type ) ;
ClassDB : : bind_method ( D_METHOD ( " get_texture_type " ) , & VisualShaderNodeCubemap : : get_texture_type ) ;
2018-07-14 23:15:42 +02:00
2019-10-11 09:26:57 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " source " , PROPERTY_HINT_ENUM , " Texture,SamplerPort " ) , " set_source " , " get_source " ) ;
2019-06-11 20:43:37 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : OBJECT , " cube_map " , PROPERTY_HINT_RESOURCE_TYPE , " Cubemap " ) , " set_cube_map " , " get_cube_map " ) ;
2021-05-22 04:30:58 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " texture_type " , PROPERTY_HINT_ENUM , " Data,Color,Normal Map " ) , " set_texture_type " , " get_texture_type " ) ;
2018-07-17 23:31:22 +02:00
2019-10-11 09:26:57 +02:00
BIND_ENUM_CONSTANT ( SOURCE_TEXTURE ) ;
BIND_ENUM_CONSTANT ( SOURCE_PORT ) ;
2021-08-14 12:38:22 +02:00
BIND_ENUM_CONSTANT ( SOURCE_MAX ) ;
2019-10-11 09:26:57 +02:00
2018-07-17 23:31:22 +02:00
BIND_ENUM_CONSTANT ( TYPE_DATA ) ;
BIND_ENUM_CONSTANT ( TYPE_COLOR ) ;
2020-12-23 10:34:26 +01:00
BIND_ENUM_CONSTANT ( TYPE_NORMAL_MAP ) ;
2021-08-14 12:38:22 +02:00
BIND_ENUM_CONSTANT ( TYPE_MAX ) ;
2018-07-14 23:15:42 +02:00
}
2019-06-11 20:43:37 +02:00
VisualShaderNodeCubemap : : VisualShaderNodeCubemap ( ) {
2020-09-07 11:29:44 +02:00
simple_decl = false ;
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2020-02-25 15:50:49 +01:00
////////////// Float Op
2018-07-14 23:15:42 +02:00
2020-02-25 15:50:49 +01:00
String VisualShaderNodeFloatOp : : get_caption ( ) const {
return " FloatOp " ;
2018-07-14 23:15:42 +02:00
}
2020-02-25 15:50:49 +01:00
int VisualShaderNodeFloatOp : : get_input_port_count ( ) const {
2018-07-14 23:15:42 +02:00
return 2 ;
}
2019-09-18 18:04:40 +02:00
2020-02-25 15:50:49 +01:00
VisualShaderNodeFloatOp : : PortType VisualShaderNodeFloatOp : : get_input_port_type ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return PORT_TYPE_SCALAR ;
}
2019-09-18 18:04:40 +02:00
2020-02-25 15:50:49 +01:00
String VisualShaderNodeFloatOp : : get_input_port_name ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return p_port = = 0 ? " a " : " b " ;
}
2020-02-25 15:50:49 +01:00
int VisualShaderNodeFloatOp : : get_output_port_count ( ) const {
2018-07-14 23:15:42 +02:00
return 1 ;
}
2019-09-18 18:04:40 +02:00
2020-02-25 15:50:49 +01:00
VisualShaderNodeFloatOp : : PortType VisualShaderNodeFloatOp : : get_output_port_type ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return PORT_TYPE_SCALAR ;
}
2019-09-18 18:04:40 +02:00
2020-02-25 15:50:49 +01:00
String VisualShaderNodeFloatOp : : get_output_port_name ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return " op " ; //no output port means the editor will be used as port
}
2020-02-25 15:50:49 +01:00
String VisualShaderNodeFloatOp : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-07-19 08:06:51 +02:00
String code = " " + p_output_vars [ 0 ] + " = " ;
2018-07-14 23:15:42 +02:00
switch ( op ) {
2020-05-10 13:00:47 +02:00
case OP_ADD :
code + = p_input_vars [ 0 ] + " + " + p_input_vars [ 1 ] + " ; \n " ;
break ;
case OP_SUB :
code + = p_input_vars [ 0 ] + " - " + p_input_vars [ 1 ] + " ; \n " ;
break ;
case OP_MUL :
code + = p_input_vars [ 0 ] + " * " + p_input_vars [ 1 ] + " ; \n " ;
break ;
case OP_DIV :
code + = p_input_vars [ 0 ] + " / " + p_input_vars [ 1 ] + " ; \n " ;
break ;
case OP_MOD :
code + = " mod( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
break ;
case OP_POW :
code + = " pow( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
break ;
case OP_MAX :
code + = " max( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
break ;
case OP_MIN :
code + = " min( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
break ;
case OP_ATAN2 :
code + = " atan( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
break ;
case OP_STEP :
code + = " step( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
break ;
2021-08-14 12:38:22 +02:00
default :
break ;
2018-07-14 23:15:42 +02:00
}
return code ;
}
2020-02-25 15:50:49 +01:00
void VisualShaderNodeFloatOp : : set_operator ( Operator p_op ) {
2021-08-14 12:38:22 +02:00
ERR_FAIL_INDEX ( int ( p_op ) , int ( OP_ENUM_SIZE ) ) ;
if ( op = = p_op ) {
return ;
}
2018-07-14 23:15:42 +02:00
op = p_op ;
emit_changed ( ) ;
}
2020-02-25 15:50:49 +01:00
VisualShaderNodeFloatOp : : Operator VisualShaderNodeFloatOp : : get_operator ( ) const {
2018-07-14 23:15:42 +02:00
return op ;
}
2020-02-25 15:50:49 +01:00
Vector < StringName > VisualShaderNodeFloatOp : : get_editable_properties ( ) const {
2018-07-14 23:15:42 +02:00
Vector < StringName > props ;
props . push_back ( " operator " ) ;
return props ;
}
2020-02-25 15:50:49 +01:00
void VisualShaderNodeFloatOp : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_operator " , " op " ) , & VisualShaderNodeFloatOp : : set_operator ) ;
ClassDB : : bind_method ( D_METHOD ( " get_operator " ) , & VisualShaderNodeFloatOp : : get_operator ) ;
2018-07-14 23:15:42 +02:00
2021-05-22 04:30:58 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " operator " , PROPERTY_HINT_ENUM , " Add,Subtract,Multiply,Divide,Remainder,Power,Max,Min,ATan2,Step " ) , " set_operator " , " get_operator " ) ;
2018-07-14 23:15:42 +02:00
BIND_ENUM_CONSTANT ( OP_ADD ) ;
BIND_ENUM_CONSTANT ( OP_SUB ) ;
BIND_ENUM_CONSTANT ( OP_MUL ) ;
BIND_ENUM_CONSTANT ( OP_DIV ) ;
BIND_ENUM_CONSTANT ( OP_MOD ) ;
BIND_ENUM_CONSTANT ( OP_POW ) ;
BIND_ENUM_CONSTANT ( OP_MAX ) ;
BIND_ENUM_CONSTANT ( OP_MIN ) ;
BIND_ENUM_CONSTANT ( OP_ATAN2 ) ;
2019-02-22 18:38:58 +01:00
BIND_ENUM_CONSTANT ( OP_STEP ) ;
2021-08-14 12:38:22 +02:00
BIND_ENUM_CONSTANT ( OP_ENUM_SIZE ) ;
2018-07-14 23:15:42 +02:00
}
2020-02-25 15:50:49 +01:00
VisualShaderNodeFloatOp : : VisualShaderNodeFloatOp ( ) {
2018-07-14 23:15:42 +02:00
set_input_port_default_value ( 0 , 0.0 ) ;
set_input_port_default_value ( 1 , 0.0 ) ;
}
2020-02-25 15:50:49 +01:00
////////////// Integer Op
String VisualShaderNodeIntOp : : get_caption ( ) const {
return " IntOp " ;
}
int VisualShaderNodeIntOp : : get_input_port_count ( ) const {
return 2 ;
}
VisualShaderNodeIntOp : : PortType VisualShaderNodeIntOp : : get_input_port_type ( int p_port ) const {
return PORT_TYPE_SCALAR_INT ;
}
String VisualShaderNodeIntOp : : get_input_port_name ( int p_port ) const {
return p_port = = 0 ? " a " : " b " ;
}
int VisualShaderNodeIntOp : : get_output_port_count ( ) const {
return 1 ;
}
VisualShaderNodeIntOp : : PortType VisualShaderNodeIntOp : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_SCALAR_INT ;
}
String VisualShaderNodeIntOp : : get_output_port_name ( int p_port ) const {
return " op " ; //no output port means the editor will be used as port
}
String VisualShaderNodeIntOp : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-07-19 08:06:51 +02:00
String code = " " + p_output_vars [ 0 ] + " = " ;
2020-02-25 15:50:49 +01:00
switch ( op ) {
2020-05-10 13:00:47 +02:00
case OP_ADD :
code + = p_input_vars [ 0 ] + " + " + p_input_vars [ 1 ] + " ; \n " ;
break ;
case OP_SUB :
code + = p_input_vars [ 0 ] + " - " + p_input_vars [ 1 ] + " ; \n " ;
break ;
case OP_MUL :
code + = p_input_vars [ 0 ] + " * " + p_input_vars [ 1 ] + " ; \n " ;
break ;
case OP_DIV :
code + = p_input_vars [ 0 ] + " / " + p_input_vars [ 1 ] + " ; \n " ;
break ;
case OP_MOD :
code + = p_input_vars [ 0 ] + " % " + p_input_vars [ 1 ] + " ; \n " ;
break ;
case OP_MAX :
code + = " max( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
break ;
case OP_MIN :
code + = " min( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
break ;
2021-12-03 09:35:38 +01:00
case OP_BITWISE_AND :
code + = p_input_vars [ 0 ] + " & " + p_input_vars [ 1 ] + " ; \n " ;
break ;
case OP_BITWISE_OR :
code + = p_input_vars [ 0 ] + " | " + p_input_vars [ 1 ] + " ; \n " ;
break ;
case OP_BITWISE_XOR :
code + = p_input_vars [ 0 ] + " ^ " + p_input_vars [ 1 ] + " ; \n " ;
break ;
case OP_BITWISE_LEFT_SHIFT :
code + = p_input_vars [ 0 ] + " << " + p_input_vars [ 1 ] + " ; \n " ;
break ;
case OP_BITWISE_RIGHT_SHIFT :
code + = p_input_vars [ 0 ] + " >> " + p_input_vars [ 1 ] + " ; \n " ;
break ;
2021-08-14 12:38:22 +02:00
default :
break ;
2020-02-25 15:50:49 +01:00
}
return code ;
}
void VisualShaderNodeIntOp : : set_operator ( Operator p_op ) {
2021-08-14 12:38:22 +02:00
ERR_FAIL_INDEX ( int ( p_op ) , OP_ENUM_SIZE ) ;
if ( op = = p_op ) {
return ;
}
2020-02-25 15:50:49 +01:00
op = p_op ;
emit_changed ( ) ;
}
VisualShaderNodeIntOp : : Operator VisualShaderNodeIntOp : : get_operator ( ) const {
return op ;
}
Vector < StringName > VisualShaderNodeIntOp : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " operator " ) ;
return props ;
}
void VisualShaderNodeIntOp : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_operator " , " op " ) , & VisualShaderNodeIntOp : : set_operator ) ;
ClassDB : : bind_method ( D_METHOD ( " get_operator " ) , & VisualShaderNodeIntOp : : get_operator ) ;
2021-12-03 09:35:38 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " operator " , PROPERTY_HINT_ENUM , " Add,Subtract,Multiply,Divide,Remainder,Max,Min,Bitwise AND,Bitwise OR,Bitwise XOR,Bitwise Left Shift,Bitwise Right Shift " ) , " set_operator " , " get_operator " ) ;
2020-02-25 15:50:49 +01:00
BIND_ENUM_CONSTANT ( OP_ADD ) ;
BIND_ENUM_CONSTANT ( OP_SUB ) ;
BIND_ENUM_CONSTANT ( OP_MUL ) ;
BIND_ENUM_CONSTANT ( OP_DIV ) ;
BIND_ENUM_CONSTANT ( OP_MOD ) ;
BIND_ENUM_CONSTANT ( OP_MAX ) ;
BIND_ENUM_CONSTANT ( OP_MIN ) ;
2021-12-03 09:35:38 +01:00
BIND_ENUM_CONSTANT ( OP_BITWISE_AND ) ;
BIND_ENUM_CONSTANT ( OP_BITWISE_OR ) ;
BIND_ENUM_CONSTANT ( OP_BITWISE_XOR ) ;
BIND_ENUM_CONSTANT ( OP_BITWISE_LEFT_SHIFT ) ;
BIND_ENUM_CONSTANT ( OP_BITWISE_RIGHT_SHIFT ) ;
2021-08-14 12:38:22 +02:00
BIND_ENUM_CONSTANT ( OP_ENUM_SIZE ) ;
2020-02-25 15:50:49 +01:00
}
VisualShaderNodeIntOp : : VisualShaderNodeIntOp ( ) {
set_input_port_default_value ( 0 , 0 ) ;
set_input_port_default_value ( 1 , 0 ) ;
}
2018-07-14 23:15:42 +02:00
////////////// Vector Op
String VisualShaderNodeVectorOp : : get_caption ( ) const {
2018-07-15 16:28:06 +02:00
return " VectorOp " ;
2018-07-14 23:15:42 +02:00
}
int VisualShaderNodeVectorOp : : get_input_port_count ( ) const {
return 2 ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
String VisualShaderNodeVectorOp : : get_input_port_name ( int p_port ) const {
return p_port = = 0 ? " a " : " b " ;
}
int VisualShaderNodeVectorOp : : get_output_port_count ( ) const {
return 1 ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
String VisualShaderNodeVectorOp : : get_output_port_name ( int p_port ) const {
2022-02-01 09:32:01 +01:00
return " op " ;
2018-07-14 23:15:42 +02:00
}
2019-01-21 20:07:53 +01:00
String VisualShaderNodeVectorOp : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-07-19 08:06:51 +02:00
String code = " " + p_output_vars [ 0 ] + " = " ;
2018-07-14 23:15:42 +02:00
switch ( op ) {
2020-05-10 13:00:47 +02:00
case OP_ADD :
code + = p_input_vars [ 0 ] + " + " + p_input_vars [ 1 ] + " ; \n " ;
break ;
case OP_SUB :
code + = p_input_vars [ 0 ] + " - " + p_input_vars [ 1 ] + " ; \n " ;
break ;
case OP_MUL :
code + = p_input_vars [ 0 ] + " * " + p_input_vars [ 1 ] + " ; \n " ;
break ;
case OP_DIV :
code + = p_input_vars [ 0 ] + " / " + p_input_vars [ 1 ] + " ; \n " ;
break ;
case OP_MOD :
code + = " mod( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
break ;
case OP_POW :
code + = " pow( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
break ;
case OP_MAX :
code + = " max( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
break ;
case OP_MIN :
code + = " min( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
break ;
case OP_CROSS :
2022-04-12 19:09:29 +02:00
if ( op_type = = OP_TYPE_VECTOR_2D ) { // Not supported.
2022-02-01 09:32:01 +01:00
code + = " vec2(0.0); \n " ;
2022-04-12 19:09:29 +02:00
} else if ( op_type = = OP_TYPE_VECTOR_4D ) { // Not supported.
code + = " vec4(0.0); \n " ;
2022-02-01 09:32:01 +01:00
} else {
code + = " cross( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
}
2020-05-10 13:00:47 +02:00
break ;
case OP_ATAN2 :
code + = " atan( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
break ;
case OP_REFLECT :
2022-08-07 18:03:16 +02:00
code + = " reflect( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
2020-05-10 13:00:47 +02:00
break ;
case OP_STEP :
code + = " step( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
break ;
2021-08-14 12:38:22 +02:00
default :
break ;
2018-07-14 23:15:42 +02:00
}
return code ;
}
2022-02-01 09:32:01 +01:00
void VisualShaderNodeVectorOp : : set_op_type ( OpType p_op_type ) {
ERR_FAIL_INDEX ( int ( p_op_type ) , int ( OP_TYPE_MAX ) ) ;
if ( op_type = = p_op_type ) {
return ;
}
switch ( p_op_type ) {
case OP_TYPE_VECTOR_2D : {
set_input_port_default_value ( 0 , Vector2 ( ) , get_input_port_default_value ( 0 ) ) ;
set_input_port_default_value ( 1 , Vector2 ( ) , get_input_port_default_value ( 1 ) ) ;
} break ;
case OP_TYPE_VECTOR_3D : {
set_input_port_default_value ( 0 , Vector3 ( ) , get_input_port_default_value ( 0 ) ) ;
set_input_port_default_value ( 1 , Vector3 ( ) , get_input_port_default_value ( 1 ) ) ;
} break ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D : {
set_input_port_default_value ( 0 , Quaternion ( ) , get_input_port_default_value ( 0 ) ) ;
set_input_port_default_value ( 1 , Quaternion ( ) , get_input_port_default_value ( 1 ) ) ;
} break ;
2022-02-01 09:32:01 +01:00
default :
break ;
}
op_type = p_op_type ;
emit_changed ( ) ;
}
2018-07-14 23:15:42 +02:00
void VisualShaderNodeVectorOp : : set_operator ( Operator p_op ) {
2021-08-14 12:38:22 +02:00
ERR_FAIL_INDEX ( int ( p_op ) , int ( OP_ENUM_SIZE ) ) ;
if ( op = = p_op ) {
return ;
}
2018-07-14 23:15:42 +02:00
op = p_op ;
emit_changed ( ) ;
}
VisualShaderNodeVectorOp : : Operator VisualShaderNodeVectorOp : : get_operator ( ) const {
return op ;
}
Vector < StringName > VisualShaderNodeVectorOp : : get_editable_properties ( ) const {
2022-02-01 09:32:01 +01:00
Vector < StringName > props = VisualShaderNodeVectorBase : : get_editable_properties ( ) ;
2018-07-14 23:15:42 +02:00
props . push_back ( " operator " ) ;
return props ;
}
2022-02-01 09:32:01 +01:00
String VisualShaderNodeVectorOp : : get_warning ( Shader : : Mode p_mode , VisualShader : : Type p_type ) const {
bool invalid_type = false ;
2022-04-12 19:09:29 +02:00
if ( op_type = = OP_TYPE_VECTOR_2D | | op_type = = OP_TYPE_VECTOR_4D ) {
2022-08-07 18:03:16 +02:00
if ( op = = OP_CROSS ) {
2022-02-01 09:32:01 +01:00
invalid_type = true ;
}
}
if ( invalid_type ) {
2022-03-28 15:24:14 +02:00
return RTR ( " Invalid operator for that type. " ) ;
2022-02-01 09:32:01 +01:00
}
return String ( ) ;
}
2018-07-14 23:15:42 +02:00
void VisualShaderNodeVectorOp : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_operator " , " op " ) , & VisualShaderNodeVectorOp : : set_operator ) ;
ClassDB : : bind_method ( D_METHOD ( " get_operator " ) , & VisualShaderNodeVectorOp : : get_operator ) ;
2021-05-22 04:30:58 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " operator " , PROPERTY_HINT_ENUM , " Add,Subtract,Multiply,Divide,Remainder,Power,Max,Min,Cross,ATan2,Reflect,Step " ) , " set_operator " , " get_operator " ) ;
2018-07-14 23:15:42 +02:00
BIND_ENUM_CONSTANT ( OP_ADD ) ;
BIND_ENUM_CONSTANT ( OP_SUB ) ;
BIND_ENUM_CONSTANT ( OP_MUL ) ;
BIND_ENUM_CONSTANT ( OP_DIV ) ;
BIND_ENUM_CONSTANT ( OP_MOD ) ;
BIND_ENUM_CONSTANT ( OP_POW ) ;
BIND_ENUM_CONSTANT ( OP_MAX ) ;
BIND_ENUM_CONSTANT ( OP_MIN ) ;
BIND_ENUM_CONSTANT ( OP_CROSS ) ;
2019-02-22 18:38:58 +01:00
BIND_ENUM_CONSTANT ( OP_ATAN2 ) ;
BIND_ENUM_CONSTANT ( OP_REFLECT ) ;
BIND_ENUM_CONSTANT ( OP_STEP ) ;
2021-08-14 12:38:22 +02:00
BIND_ENUM_CONSTANT ( OP_ENUM_SIZE ) ;
2018-07-14 23:15:42 +02:00
}
VisualShaderNodeVectorOp : : VisualShaderNodeVectorOp ( ) {
2022-02-01 09:32:01 +01:00
switch ( op_type ) {
case OP_TYPE_VECTOR_2D : {
set_input_port_default_value ( 0 , Vector2 ( ) ) ;
set_input_port_default_value ( 1 , Vector2 ( ) ) ;
} break ;
case OP_TYPE_VECTOR_3D : {
set_input_port_default_value ( 0 , Vector3 ( ) ) ;
set_input_port_default_value ( 1 , Vector3 ( ) ) ;
} break ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D : {
set_input_port_default_value ( 0 , Quaternion ( ) ) ;
set_input_port_default_value ( 1 , Quaternion ( ) ) ;
} break ;
2022-02-01 09:32:01 +01:00
default :
break ;
}
2018-07-14 23:15:42 +02:00
}
////////////// Color Op
String VisualShaderNodeColorOp : : get_caption ( ) const {
return " ColorOp " ;
}
int VisualShaderNodeColorOp : : get_input_port_count ( ) const {
return 2 ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
VisualShaderNodeColorOp : : PortType VisualShaderNodeColorOp : : get_input_port_type ( int p_port ) const {
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
String VisualShaderNodeColorOp : : get_input_port_name ( int p_port ) const {
return p_port = = 0 ? " a " : " b " ;
}
int VisualShaderNodeColorOp : : get_output_port_count ( ) const {
return 1 ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
VisualShaderNodeColorOp : : PortType VisualShaderNodeColorOp : : get_output_port_type ( int p_port ) const {
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
String VisualShaderNodeColorOp : : get_output_port_name ( int p_port ) const {
return " op " ; //no output port means the editor will be used as port
}
2019-01-21 20:07:53 +01:00
String VisualShaderNodeColorOp : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2018-07-14 23:15:42 +02:00
String code ;
static const char * axisn [ 3 ] = { " x " , " y " , " z " } ;
switch ( op ) {
case OP_SCREEN : {
2021-07-19 08:06:51 +02:00
code + = " " + p_output_vars [ 0 ] + " = vec3(1.0) - (vec3(1.0) - " + p_input_vars [ 0 ] + " ) * (vec3(1.0) - " + p_input_vars [ 1 ] + " ); \n " ;
2018-07-14 23:15:42 +02:00
} break ;
case OP_DIFFERENCE : {
2021-07-19 08:06:51 +02:00
code + = " " + p_output_vars [ 0 ] + " = abs( " + p_input_vars [ 0 ] + " - " + p_input_vars [ 1 ] + " ); \n " ;
2018-07-14 23:15:42 +02:00
} break ;
case OP_DARKEN : {
2021-07-19 08:06:51 +02:00
code + = " " + p_output_vars [ 0 ] + " = min( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
2018-07-14 23:15:42 +02:00
} break ;
case OP_LIGHTEN : {
2021-07-19 08:06:51 +02:00
code + = " " + p_output_vars [ 0 ] + " = max( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
2018-07-14 23:15:42 +02:00
} break ;
case OP_OVERLAY : {
for ( int i = 0 ; i < 3 ; i + + ) {
2021-07-19 08:06:51 +02:00
code + = " { \n " ;
code + = " float base = " + p_input_vars [ 0 ] + " . " + axisn [ i ] + " ; \n " ;
code + = " float blend = " + p_input_vars [ 1 ] + " . " + axisn [ i ] + " ; \n " ;
code + = " if (base < 0.5) { \n " ;
code + = " " + p_output_vars [ 0 ] + " . " + axisn [ i ] + " = 2.0 * base * blend; \n " ;
code + = " } else { \n " ;
code + = " " + p_output_vars [ 0 ] + " . " + axisn [ i ] + " = 1.0 - 2.0 * (1.0 - blend) * (1.0 - base); \n " ;
code + = " } \n " ;
code + = " } \n " ;
2018-07-14 23:15:42 +02:00
}
} break ;
case OP_DODGE : {
2021-07-19 08:06:51 +02:00
code + = " " + p_output_vars [ 0 ] + " = ( " + p_input_vars [ 0 ] + " ) / (vec3(1.0) - " + p_input_vars [ 1 ] + " ); \n " ;
2018-07-14 23:15:42 +02:00
} break ;
case OP_BURN : {
2021-07-19 08:06:51 +02:00
code + = " " + p_output_vars [ 0 ] + " = vec3(1.0) - (vec3(1.0) - " + p_input_vars [ 0 ] + " ) / ( " + p_input_vars [ 1 ] + " ); \n " ;
2018-07-14 23:15:42 +02:00
} break ;
case OP_SOFT_LIGHT : {
for ( int i = 0 ; i < 3 ; i + + ) {
2021-07-19 08:06:51 +02:00
code + = " { \n " ;
code + = " float base = " + p_input_vars [ 0 ] + " . " + axisn [ i ] + " ; \n " ;
code + = " float blend = " + p_input_vars [ 1 ] + " . " + axisn [ i ] + " ; \n " ;
code + = " if (base < 0.5) { \n " ;
code + = " " + p_output_vars [ 0 ] + " . " + axisn [ i ] + " = (base * (blend + 0.5)); \n " ;
code + = " } else { \n " ;
code + = " " + p_output_vars [ 0 ] + " . " + axisn [ i ] + " = (1.0 - (1.0 - base) * (1.0 - (blend - 0.5))); \n " ;
code + = " } \n " ;
code + = " } \n " ;
2018-07-14 23:15:42 +02:00
}
} break ;
case OP_HARD_LIGHT : {
for ( int i = 0 ; i < 3 ; i + + ) {
2021-07-19 08:06:51 +02:00
code + = " { \n " ;
code + = " float base = " + p_input_vars [ 0 ] + " . " + axisn [ i ] + " ; \n " ;
code + = " float blend = " + p_input_vars [ 1 ] + " . " + axisn [ i ] + " ; \n " ;
code + = " if (base < 0.5) { \n " ;
code + = " " + p_output_vars [ 0 ] + " . " + axisn [ i ] + " = (base * (2.0 * blend)); \n " ;
code + = " } else { \n " ;
code + = " " + p_output_vars [ 0 ] + " . " + axisn [ i ] + " = (1.0 - (1.0 - base) * (1.0 - 2.0 * (blend - 0.5))); \n " ;
code + = " } \n " ;
code + = " } \n " ;
2018-07-14 23:15:42 +02:00
}
} break ;
2021-08-14 12:38:22 +02:00
default :
break ;
2018-07-14 23:15:42 +02:00
}
return code ;
}
void VisualShaderNodeColorOp : : set_operator ( Operator p_op ) {
2021-08-14 12:38:22 +02:00
ERR_FAIL_INDEX ( int ( p_op ) , int ( OP_MAX ) ) ;
if ( op = = p_op ) {
return ;
}
switch ( p_op ) {
2020-01-27 10:10:51 +01:00
case OP_SCREEN :
simple_decl = true ;
break ;
case OP_DIFFERENCE :
simple_decl = true ;
break ;
case OP_DARKEN :
simple_decl = true ;
break ;
case OP_LIGHTEN :
simple_decl = true ;
break ;
case OP_OVERLAY :
simple_decl = false ;
break ;
case OP_DODGE :
simple_decl = true ;
break ;
case OP_BURN :
simple_decl = true ;
break ;
case OP_SOFT_LIGHT :
simple_decl = false ;
break ;
case OP_HARD_LIGHT :
simple_decl = false ;
break ;
2021-08-14 12:38:22 +02:00
default :
break ;
2020-01-27 10:10:51 +01:00
}
2021-08-14 12:38:22 +02:00
op = p_op ;
2018-07-14 23:15:42 +02:00
emit_changed ( ) ;
}
VisualShaderNodeColorOp : : Operator VisualShaderNodeColorOp : : get_operator ( ) const {
return op ;
}
Vector < StringName > VisualShaderNodeColorOp : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " operator " ) ;
return props ;
}
void VisualShaderNodeColorOp : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_operator " , " op " ) , & VisualShaderNodeColorOp : : set_operator ) ;
ClassDB : : bind_method ( D_METHOD ( " get_operator " ) , & VisualShaderNodeColorOp : : get_operator ) ;
2021-05-22 04:30:58 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " operator " , PROPERTY_HINT_ENUM , " Screen,Difference,Darken,Lighten,Overlay,Dodge,Burn,Soft Light,Hard Light " ) , " set_operator " , " get_operator " ) ;
2018-07-17 23:31:22 +02:00
BIND_ENUM_CONSTANT ( OP_SCREEN ) ;
BIND_ENUM_CONSTANT ( OP_DIFFERENCE ) ;
BIND_ENUM_CONSTANT ( OP_DARKEN ) ;
BIND_ENUM_CONSTANT ( OP_LIGHTEN ) ;
BIND_ENUM_CONSTANT ( OP_OVERLAY ) ;
BIND_ENUM_CONSTANT ( OP_DODGE ) ;
BIND_ENUM_CONSTANT ( OP_BURN ) ;
BIND_ENUM_CONSTANT ( OP_SOFT_LIGHT ) ;
BIND_ENUM_CONSTANT ( OP_HARD_LIGHT ) ;
2021-08-14 12:38:22 +02:00
BIND_ENUM_CONSTANT ( OP_MAX ) ;
2018-07-14 23:15:42 +02:00
}
VisualShaderNodeColorOp : : VisualShaderNodeColorOp ( ) {
set_input_port_default_value ( 0 , Vector3 ( ) ) ;
set_input_port_default_value ( 1 , Vector3 ( ) ) ;
}
2021-08-11 18:08:37 +02:00
////////////// Transform Op
2018-07-14 23:15:42 +02:00
2021-08-11 18:08:37 +02:00
String VisualShaderNodeTransformOp : : get_caption ( ) const {
return " TransformOp " ;
2018-07-14 23:15:42 +02:00
}
2021-08-11 18:08:37 +02:00
int VisualShaderNodeTransformOp : : get_input_port_count ( ) const {
2018-07-14 23:15:42 +02:00
return 2 ;
}
2019-09-18 18:04:40 +02:00
2021-08-11 18:08:37 +02:00
VisualShaderNodeTransformOp : : PortType VisualShaderNodeTransformOp : : get_input_port_type ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return PORT_TYPE_TRANSFORM ;
}
2019-09-18 18:04:40 +02:00
2021-08-11 18:08:37 +02:00
String VisualShaderNodeTransformOp : : get_input_port_name ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return p_port = = 0 ? " a " : " b " ;
}
2021-08-11 18:08:37 +02:00
int VisualShaderNodeTransformOp : : get_output_port_count ( ) const {
2018-07-14 23:15:42 +02:00
return 1 ;
}
2019-09-18 18:04:40 +02:00
2021-08-11 18:08:37 +02:00
VisualShaderNodeTransformOp : : PortType VisualShaderNodeTransformOp : : get_output_port_type ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return PORT_TYPE_TRANSFORM ;
}
2019-09-18 18:04:40 +02:00
2021-08-11 18:08:37 +02:00
String VisualShaderNodeTransformOp : : get_output_port_name ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return " mult " ; //no output port means the editor will be used as port
}
2021-08-11 18:08:37 +02:00
String VisualShaderNodeTransformOp : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
switch ( op ) {
case OP_AxB :
return " " + p_output_vars [ 0 ] + " = " + p_input_vars [ 0 ] + " * " + p_input_vars [ 1 ] + " ; \n " ;
case OP_BxA :
return " " + p_output_vars [ 0 ] + " = " + p_input_vars [ 1 ] + " * " + p_input_vars [ 0 ] + " ; \n " ;
case OP_AxB_COMP :
return " " + p_output_vars [ 0 ] + " = matrixCompMult( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
case OP_BxA_COMP :
return " " + p_output_vars [ 0 ] + " = matrixCompMult( " + p_input_vars [ 1 ] + " , " + p_input_vars [ 0 ] + " ); \n " ;
case OP_ADD :
return " " + p_output_vars [ 0 ] + " = " + p_input_vars [ 0 ] + " + " + p_input_vars [ 1 ] + " ; \n " ;
case OP_A_MINUS_B :
return " " + p_output_vars [ 0 ] + " = " + p_input_vars [ 0 ] + " - " + p_input_vars [ 1 ] + " ; \n " ;
case OP_B_MINUS_A :
return " " + p_output_vars [ 0 ] + " = " + p_input_vars [ 1 ] + " - " + p_input_vars [ 0 ] + " ; \n " ;
case OP_A_DIV_B :
return " " + p_output_vars [ 0 ] + " = " + p_input_vars [ 0 ] + " / " + p_input_vars [ 1 ] + " ; \n " ;
case OP_B_DIV_A :
return " " + p_output_vars [ 0 ] + " = " + p_input_vars [ 1 ] + " / " + p_input_vars [ 0 ] + " ; \n " ;
default :
return " " ;
2018-07-14 23:15:42 +02:00
}
}
2021-08-11 18:08:37 +02:00
void VisualShaderNodeTransformOp : : set_operator ( Operator p_op ) {
2021-08-14 12:38:22 +02:00
ERR_FAIL_INDEX ( int ( p_op ) , int ( OP_MAX ) ) ;
if ( op = = p_op ) {
return ;
}
2018-07-14 23:15:42 +02:00
op = p_op ;
emit_changed ( ) ;
}
2021-08-11 18:08:37 +02:00
VisualShaderNodeTransformOp : : Operator VisualShaderNodeTransformOp : : get_operator ( ) const {
2018-07-14 23:15:42 +02:00
return op ;
}
2021-08-11 18:08:37 +02:00
Vector < StringName > VisualShaderNodeTransformOp : : get_editable_properties ( ) const {
2018-07-14 23:15:42 +02:00
Vector < StringName > props ;
props . push_back ( " operator " ) ;
return props ;
}
2021-08-11 18:08:37 +02:00
void VisualShaderNodeTransformOp : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_operator " , " op " ) , & VisualShaderNodeTransformOp : : set_operator ) ;
ClassDB : : bind_method ( D_METHOD ( " get_operator " ) , & VisualShaderNodeTransformOp : : get_operator ) ;
2018-07-14 23:15:42 +02:00
2021-08-11 18:08:37 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " operator " , PROPERTY_HINT_ENUM , " A x B,B x A,A x B(per component),B x A(per component),A + B,A - B,B - A,A / B,B / A " ) , " set_operator " , " get_operator " ) ;
2018-07-17 23:31:22 +02:00
BIND_ENUM_CONSTANT ( OP_AxB ) ;
BIND_ENUM_CONSTANT ( OP_BxA ) ;
2019-02-22 18:38:58 +01:00
BIND_ENUM_CONSTANT ( OP_AxB_COMP ) ;
BIND_ENUM_CONSTANT ( OP_BxA_COMP ) ;
2021-08-11 18:08:37 +02:00
BIND_ENUM_CONSTANT ( OP_ADD ) ;
BIND_ENUM_CONSTANT ( OP_A_MINUS_B ) ;
BIND_ENUM_CONSTANT ( OP_B_MINUS_A ) ;
BIND_ENUM_CONSTANT ( OP_A_DIV_B ) ;
BIND_ENUM_CONSTANT ( OP_B_DIV_A ) ;
2021-08-14 12:38:22 +02:00
BIND_ENUM_CONSTANT ( OP_MAX ) ;
2018-07-14 23:15:42 +02:00
}
2021-08-11 18:08:37 +02:00
VisualShaderNodeTransformOp : : VisualShaderNodeTransformOp ( ) {
2020-10-17 07:08:21 +02:00
set_input_port_default_value ( 0 , Transform3D ( ) ) ;
set_input_port_default_value ( 1 , Transform3D ( ) ) ;
2018-07-14 23:15:42 +02:00
}
////////////// TransformVec Mult
String VisualShaderNodeTransformVecMult : : get_caption ( ) const {
2018-07-15 16:28:06 +02:00
return " TransformVectorMult " ;
2018-07-14 23:15:42 +02:00
}
int VisualShaderNodeTransformVecMult : : get_input_port_count ( ) const {
return 2 ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
VisualShaderNodeTransformVecMult : : PortType VisualShaderNodeTransformVecMult : : get_input_port_type ( int p_port ) const {
2022-02-06 18:15:28 +01:00
return p_port = = 0 ? PORT_TYPE_TRANSFORM : PORT_TYPE_VECTOR_3D ;
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
String VisualShaderNodeTransformVecMult : : get_input_port_name ( int p_port ) const {
return p_port = = 0 ? " a " : " b " ;
}
int VisualShaderNodeTransformVecMult : : get_output_port_count ( ) const {
return 1 ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
VisualShaderNodeTransformVecMult : : PortType VisualShaderNodeTransformVecMult : : get_output_port_type ( int p_port ) const {
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
String VisualShaderNodeTransformVecMult : : get_output_port_name ( int p_port ) const {
return " " ; //no output port means the editor will be used as port
}
2019-01-21 20:07:53 +01:00
String VisualShaderNodeTransformVecMult : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2018-07-14 23:15:42 +02:00
if ( op = = OP_AxB ) {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = ( " + p_input_vars [ 0 ] + " * vec4( " + p_input_vars [ 1 ] + " , 1.0)).xyz; \n " ;
2018-07-14 23:15:42 +02:00
} else if ( op = = OP_BxA ) {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = (vec4( " + p_input_vars [ 1 ] + " , 1.0) * " + p_input_vars [ 0 ] + " ).xyz; \n " ;
2018-07-14 23:15:42 +02:00
} else if ( op = = OP_3x3_AxB ) {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = ( " + p_input_vars [ 0 ] + " * vec4( " + p_input_vars [ 1 ] + " , 0.0)).xyz; \n " ;
2018-07-14 23:15:42 +02:00
} else {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = (vec4( " + p_input_vars [ 1 ] + " , 0.0) * " + p_input_vars [ 0 ] + " ).xyz; \n " ;
2018-07-14 23:15:42 +02:00
}
}
void VisualShaderNodeTransformVecMult : : set_operator ( Operator p_op ) {
2021-08-14 12:38:22 +02:00
ERR_FAIL_INDEX ( int ( p_op ) , int ( OP_MAX ) ) ;
if ( op = = p_op ) {
return ;
}
2018-07-14 23:15:42 +02:00
op = p_op ;
emit_changed ( ) ;
}
VisualShaderNodeTransformVecMult : : Operator VisualShaderNodeTransformVecMult : : get_operator ( ) const {
return op ;
}
Vector < StringName > VisualShaderNodeTransformVecMult : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " operator " ) ;
return props ;
}
void VisualShaderNodeTransformVecMult : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_operator " , " op " ) , & VisualShaderNodeTransformVecMult : : set_operator ) ;
ClassDB : : bind_method ( D_METHOD ( " get_operator " ) , & VisualShaderNodeTransformVecMult : : get_operator ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " operator " , PROPERTY_HINT_ENUM , " A x B,B x A,A x B (3x3),B x A (3x3) " ) , " set_operator " , " get_operator " ) ;
BIND_ENUM_CONSTANT ( OP_AxB ) ;
BIND_ENUM_CONSTANT ( OP_BxA ) ;
BIND_ENUM_CONSTANT ( OP_3x3_AxB ) ;
BIND_ENUM_CONSTANT ( OP_3x3_BxA ) ;
2021-08-14 12:38:22 +02:00
BIND_ENUM_CONSTANT ( OP_MAX ) ;
2018-07-14 23:15:42 +02:00
}
VisualShaderNodeTransformVecMult : : VisualShaderNodeTransformVecMult ( ) {
2020-10-17 07:08:21 +02:00
set_input_port_default_value ( 0 , Transform3D ( ) ) ;
2018-07-14 23:15:42 +02:00
set_input_port_default_value ( 1 , Vector3 ( ) ) ;
}
2020-02-25 15:50:49 +01:00
////////////// Float Func
2018-07-14 23:15:42 +02:00
2020-02-25 15:50:49 +01:00
String VisualShaderNodeFloatFunc : : get_caption ( ) const {
return " FloatFunc " ;
2018-07-14 23:15:42 +02:00
}
2020-02-25 15:50:49 +01:00
int VisualShaderNodeFloatFunc : : get_input_port_count ( ) const {
2018-07-14 23:15:42 +02:00
return 1 ;
}
2019-09-18 18:04:40 +02:00
2020-02-25 15:50:49 +01:00
VisualShaderNodeFloatFunc : : PortType VisualShaderNodeFloatFunc : : get_input_port_type ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return PORT_TYPE_SCALAR ;
}
2019-09-18 18:04:40 +02:00
2020-02-25 15:50:49 +01:00
String VisualShaderNodeFloatFunc : : get_input_port_name ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return " " ;
}
2020-02-25 15:50:49 +01:00
int VisualShaderNodeFloatFunc : : get_output_port_count ( ) const {
2018-07-14 23:15:42 +02:00
return 1 ;
}
2019-09-18 18:04:40 +02:00
2020-02-25 15:50:49 +01:00
VisualShaderNodeFloatFunc : : PortType VisualShaderNodeFloatFunc : : get_output_port_type ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return PORT_TYPE_SCALAR ;
}
2019-09-18 18:04:40 +02:00
2020-02-25 15:50:49 +01:00
String VisualShaderNodeFloatFunc : : get_output_port_name ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return " " ; //no output port means the editor will be used as port
}
2020-02-25 15:50:49 +01:00
String VisualShaderNodeFloatFunc : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-08-14 12:38:22 +02:00
static const char * functions [ FUNC_MAX ] = {
2018-07-14 23:15:42 +02:00
" sin($) " ,
" cos($) " ,
" tan($) " ,
" asin($) " ,
" acos($) " ,
" atan($) " ,
" sinh($) " ,
" cosh($) " ,
" tanh($) " ,
" log($) " ,
" exp($) " ,
" sqrt($) " ,
" abs($) " ,
" sign($) " ,
" floor($) " ,
" round($) " ,
" ceil($) " ,
" fract($) " ,
2020-01-27 10:10:51 +01:00
" min(max($, 0.0), 1.0) " ,
2018-07-14 23:15:42 +02:00
" -($) " ,
2019-02-22 18:38:58 +01:00
" acosh($) " ,
" asinh($) " ,
" atanh($) " ,
" degrees($) " ,
" exp2($) " ,
" inversesqrt($) " ,
" log2($) " ,
" radians($) " ,
2020-01-27 10:10:51 +01:00
" 1.0 / ($) " ,
2019-02-22 18:38:58 +01:00
" roundEven($) " ,
2019-05-19 12:07:00 +02:00
" trunc($) " ,
2020-01-27 10:10:51 +01:00
" 1.0 - $ "
2018-07-14 23:15:42 +02:00
} ;
2021-08-14 12:38:22 +02:00
return " " + p_output_vars [ 0 ] + " = " + String ( functions [ func ] ) . replace ( " $ " , p_input_vars [ 0 ] ) + " ; \n " ;
2018-07-14 23:15:42 +02:00
}
2020-02-25 15:50:49 +01:00
void VisualShaderNodeFloatFunc : : set_function ( Function p_func ) {
2021-08-14 12:38:22 +02:00
ERR_FAIL_INDEX ( int ( p_func ) , int ( FUNC_MAX ) ) ;
if ( func = = p_func ) {
return ;
}
2018-07-14 23:15:42 +02:00
func = p_func ;
emit_changed ( ) ;
}
2020-02-25 15:50:49 +01:00
VisualShaderNodeFloatFunc : : Function VisualShaderNodeFloatFunc : : get_function ( ) const {
2018-07-14 23:15:42 +02:00
return func ;
}
2020-02-25 15:50:49 +01:00
Vector < StringName > VisualShaderNodeFloatFunc : : get_editable_properties ( ) const {
2018-07-14 23:15:42 +02:00
Vector < StringName > props ;
props . push_back ( " function " ) ;
return props ;
}
2020-02-25 15:50:49 +01:00
void VisualShaderNodeFloatFunc : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_function " , " func " ) , & VisualShaderNodeFloatFunc : : set_function ) ;
ClassDB : : bind_method ( D_METHOD ( " get_function " ) , & VisualShaderNodeFloatFunc : : get_function ) ;
2018-07-14 23:15:42 +02:00
2022-06-06 02:15:10 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " function " , PROPERTY_HINT_ENUM , " Sin,Cos,Tan,ASin,ACos,ATan,SinH,CosH,TanH,Log,Exp,Sqrt,Abs,Sign,Floor,Round,Ceil,Fract,Saturate,Negate,ACosH,ASinH,ATanH,Degrees,Exp2,InverseSqrt,Log2,Radians,Reciprocal,RoundEven,Trunc,OneMinus " ) , " set_function " , " get_function " ) ;
2018-07-14 23:15:42 +02:00
BIND_ENUM_CONSTANT ( FUNC_SIN ) ;
BIND_ENUM_CONSTANT ( FUNC_COS ) ;
BIND_ENUM_CONSTANT ( FUNC_TAN ) ;
BIND_ENUM_CONSTANT ( FUNC_ASIN ) ;
BIND_ENUM_CONSTANT ( FUNC_ACOS ) ;
BIND_ENUM_CONSTANT ( FUNC_ATAN ) ;
BIND_ENUM_CONSTANT ( FUNC_SINH ) ;
BIND_ENUM_CONSTANT ( FUNC_COSH ) ;
BIND_ENUM_CONSTANT ( FUNC_TANH ) ;
BIND_ENUM_CONSTANT ( FUNC_LOG ) ;
BIND_ENUM_CONSTANT ( FUNC_EXP ) ;
BIND_ENUM_CONSTANT ( FUNC_SQRT ) ;
BIND_ENUM_CONSTANT ( FUNC_ABS ) ;
BIND_ENUM_CONSTANT ( FUNC_SIGN ) ;
BIND_ENUM_CONSTANT ( FUNC_FLOOR ) ;
BIND_ENUM_CONSTANT ( FUNC_ROUND ) ;
BIND_ENUM_CONSTANT ( FUNC_CEIL ) ;
2022-06-06 02:15:10 +02:00
BIND_ENUM_CONSTANT ( FUNC_FRACT ) ;
2018-07-14 23:15:42 +02:00
BIND_ENUM_CONSTANT ( FUNC_SATURATE ) ;
BIND_ENUM_CONSTANT ( FUNC_NEGATE ) ;
2019-02-22 18:38:58 +01:00
BIND_ENUM_CONSTANT ( FUNC_ACOSH ) ;
BIND_ENUM_CONSTANT ( FUNC_ASINH ) ;
BIND_ENUM_CONSTANT ( FUNC_ATANH ) ;
BIND_ENUM_CONSTANT ( FUNC_DEGREES ) ;
BIND_ENUM_CONSTANT ( FUNC_EXP2 ) ;
BIND_ENUM_CONSTANT ( FUNC_INVERSE_SQRT ) ;
BIND_ENUM_CONSTANT ( FUNC_LOG2 ) ;
BIND_ENUM_CONSTANT ( FUNC_RADIANS ) ;
BIND_ENUM_CONSTANT ( FUNC_RECIPROCAL ) ;
BIND_ENUM_CONSTANT ( FUNC_ROUNDEVEN ) ;
BIND_ENUM_CONSTANT ( FUNC_TRUNC ) ;
2019-05-19 12:07:00 +02:00
BIND_ENUM_CONSTANT ( FUNC_ONEMINUS ) ;
2021-08-14 12:38:22 +02:00
BIND_ENUM_CONSTANT ( FUNC_MAX ) ;
2018-07-14 23:15:42 +02:00
}
2020-02-25 15:50:49 +01:00
VisualShaderNodeFloatFunc : : VisualShaderNodeFloatFunc ( ) {
2018-07-14 23:15:42 +02:00
set_input_port_default_value ( 0 , 0.0 ) ;
}
2020-02-25 15:50:49 +01:00
////////////// Int Func
String VisualShaderNodeIntFunc : : get_caption ( ) const {
return " IntFunc " ;
}
int VisualShaderNodeIntFunc : : get_input_port_count ( ) const {
return 1 ;
}
VisualShaderNodeIntFunc : : PortType VisualShaderNodeIntFunc : : get_input_port_type ( int p_port ) const {
return PORT_TYPE_SCALAR_INT ;
}
String VisualShaderNodeIntFunc : : get_input_port_name ( int p_port ) const {
return " " ;
}
int VisualShaderNodeIntFunc : : get_output_port_count ( ) const {
return 1 ;
}
VisualShaderNodeIntFunc : : PortType VisualShaderNodeIntFunc : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_SCALAR_INT ;
}
String VisualShaderNodeIntFunc : : get_output_port_name ( int p_port ) const {
return " " ; //no output port means the editor will be used as port
}
String VisualShaderNodeIntFunc : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-08-14 12:38:22 +02:00
static const char * functions [ FUNC_MAX ] = {
2020-02-25 15:50:49 +01:00
" abs($) " ,
" -($) " ,
2021-12-03 09:35:38 +01:00
" sign($) " ,
" ~($) "
2020-02-25 15:50:49 +01:00
} ;
2021-08-14 12:38:22 +02:00
return " " + p_output_vars [ 0 ] + " = " + String ( functions [ func ] ) . replace ( " $ " , p_input_vars [ 0 ] ) + " ; \n " ;
2020-02-25 15:50:49 +01:00
}
void VisualShaderNodeIntFunc : : set_function ( Function p_func ) {
2021-08-14 12:38:22 +02:00
ERR_FAIL_INDEX ( int ( p_func ) , int ( FUNC_MAX ) ) ;
if ( func = = p_func ) {
return ;
}
2020-02-25 15:50:49 +01:00
func = p_func ;
emit_changed ( ) ;
}
VisualShaderNodeIntFunc : : Function VisualShaderNodeIntFunc : : get_function ( ) const {
return func ;
}
Vector < StringName > VisualShaderNodeIntFunc : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " function " ) ;
return props ;
}
void VisualShaderNodeIntFunc : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_function " , " func " ) , & VisualShaderNodeIntFunc : : set_function ) ;
ClassDB : : bind_method ( D_METHOD ( " get_function " ) , & VisualShaderNodeIntFunc : : get_function ) ;
2021-12-03 09:35:38 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " function " , PROPERTY_HINT_ENUM , " Abs,Negate,Sign,Bitwise NOT " ) , " set_function " , " get_function " ) ;
2020-02-25 15:50:49 +01:00
BIND_ENUM_CONSTANT ( FUNC_ABS ) ;
BIND_ENUM_CONSTANT ( FUNC_NEGATE ) ;
BIND_ENUM_CONSTANT ( FUNC_SIGN ) ;
2021-12-03 09:35:38 +01:00
BIND_ENUM_CONSTANT ( FUNC_BITWISE_NOT ) ;
2021-08-14 12:38:22 +02:00
BIND_ENUM_CONSTANT ( FUNC_MAX ) ;
2020-02-25 15:50:49 +01:00
}
VisualShaderNodeIntFunc : : VisualShaderNodeIntFunc ( ) {
set_input_port_default_value ( 0 , 0 ) ;
}
2018-07-14 23:15:42 +02:00
////////////// Vector Func
String VisualShaderNodeVectorFunc : : get_caption ( ) const {
2018-07-15 16:28:06 +02:00
return " VectorFunc " ;
2018-07-14 23:15:42 +02:00
}
int VisualShaderNodeVectorFunc : : get_input_port_count ( ) const {
return 1 ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
String VisualShaderNodeVectorFunc : : get_input_port_name ( int p_port ) const {
return " " ;
}
int VisualShaderNodeVectorFunc : : get_output_port_count ( ) const {
return 1 ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
String VisualShaderNodeVectorFunc : : get_output_port_name ( int p_port ) const {
2022-02-01 09:32:01 +01:00
return " result " ;
2018-07-14 23:15:42 +02:00
}
2019-01-21 20:07:53 +01:00
String VisualShaderNodeVectorFunc : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2022-02-01 09:32:01 +01:00
static const char * funcs [ FUNC_MAX ] = {
2018-07-14 23:15:42 +02:00
" normalize($) " ,
2022-02-01 09:32:01 +01:00
" " , // FUNC_SATURATE
2018-07-14 23:15:42 +02:00
" -($) " ,
2020-01-27 10:10:51 +01:00
" 1.0 / ($) " ,
2019-02-22 18:38:58 +01:00
" abs($) " ,
" acos($) " ,
" acosh($) " ,
" asin($) " ,
" asinh($) " ,
" atan($) " ,
" atanh($) " ,
" ceil($) " ,
" cos($) " ,
" cosh($) " ,
" degrees($) " ,
" exp($) " ,
" exp2($) " ,
" floor($) " ,
" fract($) " ,
" inversesqrt($) " ,
" log($) " ,
" log2($) " ,
" radians($) " ,
" round($) " ,
" roundEven($) " ,
" sign($) " ,
" sin($) " ,
" sinh($) " ,
" sqrt($) " ,
" tan($) " ,
" tanh($) " ,
2019-05-19 12:07:00 +02:00
" trunc($) " ,
2022-02-01 09:32:01 +01:00
" " // FUNC_ONEMINUS
2018-07-14 23:15:42 +02:00
} ;
2022-02-01 09:32:01 +01:00
if ( func = = FUNC_SATURATE ) {
String code ;
if ( op_type = = OP_TYPE_VECTOR_2D ) {
code = " max(min($, vec2(1.0)), vec2(0.0)) " ;
2022-04-12 19:09:29 +02:00
} else if ( op_type = = OP_TYPE_VECTOR_3D ) {
2022-02-01 09:32:01 +01:00
code = " max(min($, vec3(1.0)), vec3(0.0)) " ;
2022-04-12 19:09:29 +02:00
} else {
code = " max(min($, vec4(1.0)), vec4(0.0)) " ;
2022-02-01 09:32:01 +01:00
}
return " " + p_output_vars [ 0 ] + " = " + code . replace ( " $ " , p_input_vars [ 0 ] ) + " ; \n " ;
}
if ( func = = FUNC_ONEMINUS ) {
String code ;
if ( op_type = = OP_TYPE_VECTOR_2D ) {
2022-04-12 19:09:29 +02:00
code = " vec2(1.0) - $ " ;
} else if ( op_type = = OP_TYPE_VECTOR_3D ) {
code = " vec3(1.0) - $ " ;
2022-02-01 09:32:01 +01:00
} else {
2022-04-12 19:09:29 +02:00
code = " vec4(1.0) - $ " ;
2022-02-01 09:32:01 +01:00
}
return " " + p_output_vars [ 0 ] + " = " + code . replace ( " $ " , p_input_vars [ 0 ] ) + " ; \n " ;
}
2022-05-07 08:49:12 +02:00
return " " + p_output_vars [ 0 ] + " = " + String ( funcs [ func ] ) . replace ( " $ " , p_input_vars [ 0 ] ) + " ; \n " ;
2018-07-14 23:15:42 +02:00
}
2022-02-01 09:32:01 +01:00
void VisualShaderNodeVectorFunc : : set_op_type ( OpType p_op_type ) {
ERR_FAIL_INDEX ( int ( p_op_type ) , int ( OP_TYPE_MAX ) ) ;
if ( op_type = = p_op_type ) {
return ;
}
switch ( p_op_type ) {
case OP_TYPE_VECTOR_2D : {
set_input_port_default_value ( 0 , Vector2 ( ) , get_input_port_default_value ( 0 ) ) ;
} break ;
case OP_TYPE_VECTOR_3D : {
set_input_port_default_value ( 0 , Vector3 ( ) , get_input_port_default_value ( 0 ) ) ;
} break ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D : {
set_input_port_default_value ( 0 , Quaternion ( ) , get_input_port_default_value ( 0 ) ) ;
} break ;
2022-02-01 09:32:01 +01:00
default :
break ;
}
op_type = p_op_type ;
emit_changed ( ) ;
}
2018-07-14 23:15:42 +02:00
void VisualShaderNodeVectorFunc : : set_function ( Function p_func ) {
2021-08-14 12:38:22 +02:00
ERR_FAIL_INDEX ( int ( p_func ) , int ( FUNC_MAX ) ) ;
if ( func = = p_func ) {
return ;
}
func = p_func ;
2018-07-14 23:15:42 +02:00
emit_changed ( ) ;
}
VisualShaderNodeVectorFunc : : Function VisualShaderNodeVectorFunc : : get_function ( ) const {
return func ;
}
Vector < StringName > VisualShaderNodeVectorFunc : : get_editable_properties ( ) const {
2022-02-01 09:32:01 +01:00
Vector < StringName > props = VisualShaderNodeVectorBase : : get_editable_properties ( ) ;
2018-07-14 23:15:42 +02:00
props . push_back ( " function " ) ;
return props ;
}
void VisualShaderNodeVectorFunc : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_function " , " func " ) , & VisualShaderNodeVectorFunc : : set_function ) ;
ClassDB : : bind_method ( D_METHOD ( " get_function " ) , & VisualShaderNodeVectorFunc : : get_function ) ;
2022-06-06 02:15:10 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " function " , PROPERTY_HINT_ENUM , " Normalize,Saturate,Negate,Reciprocal,Abs,ACos,ACosH,ASin,ASinH,ATan,ATanH,Ceil,Cos,CosH,Degrees,Exp,Exp2,Floor,Fract,InverseSqrt,Log,Log2,Radians,Round,RoundEven,Sign,Sin,SinH,Sqrt,Tan,TanH,Trunc,OneMinus " ) , " set_function " , " get_function " ) ;
2018-07-14 23:15:42 +02:00
BIND_ENUM_CONSTANT ( FUNC_NORMALIZE ) ;
BIND_ENUM_CONSTANT ( FUNC_SATURATE ) ;
BIND_ENUM_CONSTANT ( FUNC_NEGATE ) ;
BIND_ENUM_CONSTANT ( FUNC_RECIPROCAL ) ;
2019-02-22 18:38:58 +01:00
BIND_ENUM_CONSTANT ( FUNC_ABS ) ;
BIND_ENUM_CONSTANT ( FUNC_ACOS ) ;
BIND_ENUM_CONSTANT ( FUNC_ACOSH ) ;
BIND_ENUM_CONSTANT ( FUNC_ASIN ) ;
BIND_ENUM_CONSTANT ( FUNC_ASINH ) ;
BIND_ENUM_CONSTANT ( FUNC_ATAN ) ;
BIND_ENUM_CONSTANT ( FUNC_ATANH ) ;
BIND_ENUM_CONSTANT ( FUNC_CEIL ) ;
BIND_ENUM_CONSTANT ( FUNC_COS ) ;
BIND_ENUM_CONSTANT ( FUNC_COSH ) ;
BIND_ENUM_CONSTANT ( FUNC_DEGREES ) ;
BIND_ENUM_CONSTANT ( FUNC_EXP ) ;
BIND_ENUM_CONSTANT ( FUNC_EXP2 ) ;
BIND_ENUM_CONSTANT ( FUNC_FLOOR ) ;
2022-06-06 02:15:10 +02:00
BIND_ENUM_CONSTANT ( FUNC_FRACT ) ;
2019-02-22 18:38:58 +01:00
BIND_ENUM_CONSTANT ( FUNC_INVERSE_SQRT ) ;
BIND_ENUM_CONSTANT ( FUNC_LOG ) ;
BIND_ENUM_CONSTANT ( FUNC_LOG2 ) ;
BIND_ENUM_CONSTANT ( FUNC_RADIANS ) ;
BIND_ENUM_CONSTANT ( FUNC_ROUND ) ;
BIND_ENUM_CONSTANT ( FUNC_ROUNDEVEN ) ;
BIND_ENUM_CONSTANT ( FUNC_SIGN ) ;
BIND_ENUM_CONSTANT ( FUNC_SIN ) ;
BIND_ENUM_CONSTANT ( FUNC_SINH ) ;
BIND_ENUM_CONSTANT ( FUNC_SQRT ) ;
BIND_ENUM_CONSTANT ( FUNC_TAN ) ;
BIND_ENUM_CONSTANT ( FUNC_TANH ) ;
BIND_ENUM_CONSTANT ( FUNC_TRUNC ) ;
2019-05-19 12:07:00 +02:00
BIND_ENUM_CONSTANT ( FUNC_ONEMINUS ) ;
2021-08-14 12:38:22 +02:00
BIND_ENUM_CONSTANT ( FUNC_MAX ) ;
2018-07-14 23:15:42 +02:00
}
VisualShaderNodeVectorFunc : : VisualShaderNodeVectorFunc ( ) {
2022-02-01 09:32:01 +01:00
switch ( op_type ) {
case OP_TYPE_VECTOR_2D : {
set_input_port_default_value ( 0 , Vector2 ( ) ) ;
} break ;
case OP_TYPE_VECTOR_3D : {
set_input_port_default_value ( 0 , Vector3 ( ) ) ;
} break ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D : {
set_input_port_default_value ( 0 , Quaternion ( ) ) ;
} break ;
2022-02-01 09:32:01 +01:00
default :
break ;
}
2018-07-14 23:15:42 +02:00
}
2019-02-22 18:38:58 +01:00
////////////// ColorFunc
String VisualShaderNodeColorFunc : : get_caption ( ) const {
return " ColorFunc " ;
}
int VisualShaderNodeColorFunc : : get_input_port_count ( ) const {
return 1 ;
}
VisualShaderNodeColorFunc : : PortType VisualShaderNodeColorFunc : : get_input_port_type ( int p_port ) const {
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2019-02-22 18:38:58 +01:00
}
String VisualShaderNodeColorFunc : : get_input_port_name ( int p_port ) const {
return " " ;
}
int VisualShaderNodeColorFunc : : get_output_port_count ( ) const {
return 1 ;
}
VisualShaderNodeColorFunc : : PortType VisualShaderNodeColorFunc : : get_output_port_type ( int p_port ) const {
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2019-02-22 18:38:58 +01:00
}
String VisualShaderNodeColorFunc : : get_output_port_name ( int p_port ) const {
return " " ;
}
String VisualShaderNodeColorFunc : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
String code ;
switch ( func ) {
case FUNC_GRAYSCALE :
2021-07-19 08:06:51 +02:00
code + = " { \n " ;
code + = " vec3 c = " + p_input_vars [ 0 ] + " ; \n " ;
code + = " float max1 = max(c.r, c.g); \n " ;
code + = " float max2 = max(max1, c.b); \n " ;
2022-02-20 18:36:46 +01:00
code + = " " + p_output_vars [ 0 ] + " = vec3(max2, max2, max2); \n " ;
2021-07-19 08:06:51 +02:00
code + = " } \n " ;
2019-02-22 18:38:58 +01:00
break ;
2022-05-07 08:49:12 +02:00
case FUNC_HSV2RGB :
code + = " { \n " ;
code + = " vec3 c = " + p_input_vars [ 0 ] + " ; \n " ;
code + = " vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); \n " ;
code + = " vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); \n " ;
code + = " " + p_output_vars [ 0 ] + " = c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); \n " ;
code + = " } \n " ;
break ;
case FUNC_RGB2HSV :
code + = " { \n " ;
code + = " vec3 c = " + p_input_vars [ 0 ] + " ; \n " ;
code + = " vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); \n " ;
code + = " vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); \n " ;
code + = " vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); \n " ;
code + = " float d = q.x - min(q.w, q.y); \n " ;
code + = " float e = 1.0e-10; \n " ;
code + = " " + p_output_vars [ 0 ] + " = vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); \n " ;
code + = " } \n " ;
break ;
2019-02-22 18:38:58 +01:00
case FUNC_SEPIA :
2021-07-19 08:06:51 +02:00
code + = " { \n " ;
code + = " vec3 c = " + p_input_vars [ 0 ] + " ; \n " ;
code + = " float r = (c.r * .393) + (c.g *.769) + (c.b * .189); \n " ;
code + = " float g = (c.r * .349) + (c.g *.686) + (c.b * .168); \n " ;
code + = " float b = (c.r * .272) + (c.g *.534) + (c.b * .131); \n " ;
code + = " " + p_output_vars [ 0 ] + " = vec3(r, g, b); \n " ;
code + = " } \n " ;
2019-02-22 18:38:58 +01:00
break ;
2021-08-14 12:38:22 +02:00
default :
break ;
2019-02-22 18:38:58 +01:00
}
return code ;
}
void VisualShaderNodeColorFunc : : set_function ( Function p_func ) {
2021-08-14 12:38:22 +02:00
ERR_FAIL_INDEX ( int ( p_func ) , int ( FUNC_MAX ) ) ;
if ( func = = p_func ) {
return ;
}
2019-02-22 18:38:58 +01:00
func = p_func ;
emit_changed ( ) ;
}
VisualShaderNodeColorFunc : : Function VisualShaderNodeColorFunc : : get_function ( ) const {
return func ;
}
Vector < StringName > VisualShaderNodeColorFunc : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " function " ) ;
return props ;
}
void VisualShaderNodeColorFunc : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_function " , " func " ) , & VisualShaderNodeColorFunc : : set_function ) ;
ClassDB : : bind_method ( D_METHOD ( " get_function " ) , & VisualShaderNodeColorFunc : : get_function ) ;
2022-05-07 08:49:12 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " function " , PROPERTY_HINT_ENUM , " Grayscale,HSV2RGB,RGB2HSV,Sepia " ) , " set_function " , " get_function " ) ;
2019-02-22 18:38:58 +01:00
BIND_ENUM_CONSTANT ( FUNC_GRAYSCALE ) ;
2022-05-07 08:49:12 +02:00
BIND_ENUM_CONSTANT ( FUNC_HSV2RGB ) ;
BIND_ENUM_CONSTANT ( FUNC_RGB2HSV ) ;
2019-02-22 18:38:58 +01:00
BIND_ENUM_CONSTANT ( FUNC_SEPIA ) ;
2021-08-14 12:38:22 +02:00
BIND_ENUM_CONSTANT ( FUNC_MAX ) ;
2019-02-22 18:38:58 +01:00
}
VisualShaderNodeColorFunc : : VisualShaderNodeColorFunc ( ) {
2020-09-07 11:29:44 +02:00
simple_decl = false ;
2019-02-22 18:38:58 +01:00
set_input_port_default_value ( 0 , Vector3 ( ) ) ;
}
////////////// Transform Func
String VisualShaderNodeTransformFunc : : get_caption ( ) const {
return " TransformFunc " ;
}
int VisualShaderNodeTransformFunc : : get_input_port_count ( ) const {
return 1 ;
}
VisualShaderNodeTransformFunc : : PortType VisualShaderNodeTransformFunc : : get_input_port_type ( int p_port ) const {
return PORT_TYPE_TRANSFORM ;
}
String VisualShaderNodeTransformFunc : : get_input_port_name ( int p_port ) const {
return " " ;
}
int VisualShaderNodeTransformFunc : : get_output_port_count ( ) const {
return 1 ;
}
VisualShaderNodeTransformFunc : : PortType VisualShaderNodeTransformFunc : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_TRANSFORM ;
}
String VisualShaderNodeTransformFunc : : get_output_port_name ( int p_port ) const {
return " " ;
}
String VisualShaderNodeTransformFunc : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-08-14 12:38:22 +02:00
static const char * functions [ FUNC_MAX ] = {
2019-02-22 18:38:58 +01:00
" inverse($) " ,
" transpose($) "
} ;
String code ;
2021-08-14 12:38:22 +02:00
code + = " " + p_output_vars [ 0 ] + " = " + String ( functions [ func ] ) . replace ( " $ " , p_input_vars [ 0 ] ) + " ; \n " ;
2019-02-22 18:38:58 +01:00
return code ;
}
void VisualShaderNodeTransformFunc : : set_function ( Function p_func ) {
2021-08-14 12:38:22 +02:00
ERR_FAIL_INDEX ( int ( p_func ) , int ( FUNC_MAX ) ) ;
if ( func = = p_func ) {
return ;
}
2019-02-22 18:38:58 +01:00
func = p_func ;
emit_changed ( ) ;
}
VisualShaderNodeTransformFunc : : Function VisualShaderNodeTransformFunc : : get_function ( ) const {
return func ;
}
Vector < StringName > VisualShaderNodeTransformFunc : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " function " ) ;
return props ;
}
void VisualShaderNodeTransformFunc : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_function " , " func " ) , & VisualShaderNodeTransformFunc : : set_function ) ;
ClassDB : : bind_method ( D_METHOD ( " get_function " ) , & VisualShaderNodeTransformFunc : : get_function ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " function " , PROPERTY_HINT_ENUM , " Inverse,Transpose " ) , " set_function " , " get_function " ) ;
BIND_ENUM_CONSTANT ( FUNC_INVERSE ) ;
BIND_ENUM_CONSTANT ( FUNC_TRANSPOSE ) ;
2021-08-14 12:38:22 +02:00
BIND_ENUM_CONSTANT ( FUNC_MAX ) ;
2019-02-22 18:38:58 +01:00
}
VisualShaderNodeTransformFunc : : VisualShaderNodeTransformFunc ( ) {
2020-10-17 07:08:21 +02:00
set_input_port_default_value ( 0 , Transform3D ( ) ) ;
2019-02-22 18:38:58 +01:00
}
2021-06-05 14:53:53 +02:00
////////////// UV Func
String VisualShaderNodeUVFunc : : get_caption ( ) const {
return " UVFunc " ;
}
int VisualShaderNodeUVFunc : : get_input_port_count ( ) const {
return 3 ;
}
VisualShaderNodeUVFunc : : PortType VisualShaderNodeUVFunc : : get_input_port_type ( int p_port ) const {
switch ( p_port ) {
case 0 :
2022-02-01 09:32:01 +01:00
return PORT_TYPE_VECTOR_2D ; // uv
2021-06-05 14:53:53 +02:00
case 1 :
2022-02-01 09:32:01 +01:00
return PORT_TYPE_VECTOR_2D ; // scale
2021-06-05 14:53:53 +02:00
case 2 :
2022-02-01 09:32:01 +01:00
return PORT_TYPE_VECTOR_2D ; // offset & pivot
2021-06-05 14:53:53 +02:00
default :
break ;
}
return PORT_TYPE_SCALAR ;
}
String VisualShaderNodeUVFunc : : get_input_port_name ( int p_port ) const {
switch ( p_port ) {
case 0 :
return " uv " ;
case 1 :
return " scale " ;
case 2 :
switch ( func ) {
case FUNC_PANNING :
return " offset " ;
case FUNC_SCALING :
return " pivot " ;
default :
break ;
}
break ;
default :
break ;
}
return " " ;
}
2022-01-22 09:09:16 +01:00
bool VisualShaderNodeUVFunc : : is_input_port_default ( int p_port , Shader : : Mode p_mode ) const {
if ( p_mode = = Shader : : MODE_CANVAS_ITEM | | p_mode = = Shader : : MODE_SPATIAL ) {
if ( p_port = = 0 ) {
return true ;
}
2021-06-05 14:53:53 +02:00
}
2022-01-22 09:09:16 +01:00
return false ;
2021-06-05 14:53:53 +02:00
}
int VisualShaderNodeUVFunc : : get_output_port_count ( ) const {
return 1 ;
}
VisualShaderNodeUVFunc : : PortType VisualShaderNodeUVFunc : : get_output_port_type ( int p_port ) const {
2022-02-01 09:32:01 +01:00
return PORT_TYPE_VECTOR_2D ;
2021-06-05 14:53:53 +02:00
}
String VisualShaderNodeUVFunc : : get_output_port_name ( int p_port ) const {
return " uv " ;
}
bool VisualShaderNodeUVFunc : : is_show_prop_names ( ) const {
return true ;
}
String VisualShaderNodeUVFunc : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
String code ;
String uv ;
if ( p_input_vars [ 0 ] . is_empty ( ) ) {
2022-01-22 09:09:16 +01:00
if ( p_mode = = Shader : : MODE_CANVAS_ITEM | | p_mode = = Shader : : MODE_SPATIAL ) {
2022-02-01 09:32:01 +01:00
uv = " UV " ;
2022-01-22 09:09:16 +01:00
} else {
2022-02-01 09:32:01 +01:00
uv = " vec2(0.0) " ;
2022-01-22 09:09:16 +01:00
}
2021-06-05 14:53:53 +02:00
} else {
uv = vformat ( " %s " , p_input_vars [ 0 ] ) ;
}
String scale = vformat ( " %s " , p_input_vars [ 1 ] ) ;
String offset_pivot = vformat ( " %s " , p_input_vars [ 2 ] ) ;
switch ( func ) {
case FUNC_PANNING : {
2021-07-19 08:06:51 +02:00
code + = vformat ( " %s = fma(%s, %s, %s); \n " , p_output_vars [ 0 ] , offset_pivot , scale , uv ) ;
2021-06-05 14:53:53 +02:00
} break ;
case FUNC_SCALING : {
2021-07-19 08:06:51 +02:00
code + = vformat ( " %s = fma((%s - %s), %s, %s); \n " , p_output_vars [ 0 ] , uv , offset_pivot , scale , offset_pivot ) ;
2021-06-05 14:53:53 +02:00
} break ;
2021-08-14 12:38:22 +02:00
default :
2021-06-05 14:53:53 +02:00
break ;
}
return code ;
}
void VisualShaderNodeUVFunc : : set_function ( VisualShaderNodeUVFunc : : Function p_func ) {
2021-08-14 12:38:22 +02:00
ERR_FAIL_INDEX ( int ( p_func ) , int ( FUNC_MAX ) ) ;
2021-06-05 14:53:53 +02:00
if ( func = = p_func ) {
return ;
}
if ( p_func = = FUNC_PANNING ) {
2022-02-01 09:32:01 +01:00
set_input_port_default_value ( 2 , Vector2 ( ) ) ; // offset
2021-06-05 14:53:53 +02:00
} else { // FUNC_SCALING
2022-02-01 09:32:01 +01:00
set_input_port_default_value ( 2 , Vector2 ( 0.5 , 0.5 ) ) ; // pivot
2021-06-05 14:53:53 +02:00
}
2021-08-14 12:38:22 +02:00
func = p_func ;
2021-06-05 14:53:53 +02:00
emit_changed ( ) ;
}
VisualShaderNodeUVFunc : : Function VisualShaderNodeUVFunc : : get_function ( ) const {
return func ;
}
Vector < StringName > VisualShaderNodeUVFunc : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " function " ) ;
return props ;
}
void VisualShaderNodeUVFunc : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_function " , " func " ) , & VisualShaderNodeUVFunc : : set_function ) ;
ClassDB : : bind_method ( D_METHOD ( " get_function " ) , & VisualShaderNodeUVFunc : : get_function ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " function " , PROPERTY_HINT_ENUM , " Panning,Scaling " ) , " set_function " , " get_function " ) ;
BIND_ENUM_CONSTANT ( FUNC_PANNING ) ;
BIND_ENUM_CONSTANT ( FUNC_SCALING ) ;
BIND_ENUM_CONSTANT ( FUNC_MAX ) ;
}
VisualShaderNodeUVFunc : : VisualShaderNodeUVFunc ( ) {
2022-02-01 09:32:01 +01:00
set_input_port_default_value ( 1 , Vector2 ( 1.0 , 1.0 ) ) ; // scale
set_input_port_default_value ( 2 , Vector2 ( ) ) ; // offset
2021-06-05 14:53:53 +02:00
}
2018-07-14 23:15:42 +02:00
////////////// Dot Product
String VisualShaderNodeDotProduct : : get_caption ( ) const {
2018-07-15 16:28:06 +02:00
return " DotProduct " ;
2018-07-14 23:15:42 +02:00
}
int VisualShaderNodeDotProduct : : get_input_port_count ( ) const {
return 2 ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
VisualShaderNodeDotProduct : : PortType VisualShaderNodeDotProduct : : get_input_port_type ( int p_port ) const {
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
String VisualShaderNodeDotProduct : : get_input_port_name ( int p_port ) const {
return p_port = = 0 ? " a " : " b " ;
}
int VisualShaderNodeDotProduct : : get_output_port_count ( ) const {
return 1 ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
VisualShaderNodeDotProduct : : PortType VisualShaderNodeDotProduct : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_SCALAR ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
String VisualShaderNodeDotProduct : : get_output_port_name ( int p_port ) const {
return " dot " ;
}
2019-01-21 20:07:53 +01:00
String VisualShaderNodeDotProduct : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = dot( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
2018-07-14 23:15:42 +02:00
}
VisualShaderNodeDotProduct : : VisualShaderNodeDotProduct ( ) {
set_input_port_default_value ( 0 , Vector3 ( ) ) ;
set_input_port_default_value ( 1 , Vector3 ( ) ) ;
}
////////////// Vector Len
String VisualShaderNodeVectorLen : : get_caption ( ) const {
2018-07-15 16:28:06 +02:00
return " VectorLen " ;
2018-07-14 23:15:42 +02:00
}
int VisualShaderNodeVectorLen : : get_input_port_count ( ) const {
return 1 ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
String VisualShaderNodeVectorLen : : get_input_port_name ( int p_port ) const {
return " " ;
}
int VisualShaderNodeVectorLen : : get_output_port_count ( ) const {
return 1 ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
VisualShaderNodeVectorLen : : PortType VisualShaderNodeVectorLen : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_SCALAR ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
String VisualShaderNodeVectorLen : : get_output_port_name ( int p_port ) const {
return " length " ;
}
2022-02-01 09:32:01 +01:00
void VisualShaderNodeVectorLen : : set_op_type ( OpType p_op_type ) {
ERR_FAIL_INDEX ( int ( p_op_type ) , int ( OP_TYPE_MAX ) ) ;
if ( op_type = = p_op_type ) {
return ;
}
switch ( p_op_type ) {
case OP_TYPE_VECTOR_2D : {
set_input_port_default_value ( 0 , Vector2 ( ) , get_input_port_default_value ( 0 ) ) ;
} break ;
case OP_TYPE_VECTOR_3D : {
set_input_port_default_value ( 0 , Vector3 ( ) , get_input_port_default_value ( 0 ) ) ;
} break ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D : {
set_input_port_default_value ( 0 , Quaternion ( ) , get_input_port_default_value ( 0 ) ) ;
} break ;
2022-02-01 09:32:01 +01:00
default :
break ;
}
op_type = p_op_type ;
emit_changed ( ) ;
}
2019-01-21 20:07:53 +01:00
String VisualShaderNodeVectorLen : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = length( " + p_input_vars [ 0 ] + " ); \n " ;
2018-07-14 23:15:42 +02:00
}
VisualShaderNodeVectorLen : : VisualShaderNodeVectorLen ( ) {
2022-02-01 09:32:01 +01:00
set_input_port_default_value ( 0 , Vector3 ( 0.0 , 0.0 , 0.0 ) ) ;
2018-07-14 23:15:42 +02:00
}
2019-02-22 18:38:58 +01:00
////////////// Determinant
2018-07-14 23:15:42 +02:00
2019-02-22 18:38:58 +01:00
String VisualShaderNodeDeterminant : : get_caption ( ) const {
return " Determinant " ;
2018-07-14 23:15:42 +02:00
}
2019-02-22 18:38:58 +01:00
int VisualShaderNodeDeterminant : : get_input_port_count ( ) const {
return 1 ;
2018-07-14 23:15:42 +02:00
}
2019-02-22 18:38:58 +01:00
2019-09-18 18:04:40 +02:00
VisualShaderNodeDeterminant : : PortType VisualShaderNodeDeterminant : : get_input_port_type ( int p_port ) const {
2019-02-22 18:38:58 +01:00
return PORT_TYPE_TRANSFORM ;
2018-07-14 23:15:42 +02:00
}
2019-02-22 18:38:58 +01:00
String VisualShaderNodeDeterminant : : get_input_port_name ( int p_port ) const {
return " " ;
2018-07-14 23:15:42 +02:00
}
2019-02-22 18:38:58 +01:00
int VisualShaderNodeDeterminant : : get_output_port_count ( ) const {
2018-07-14 23:15:42 +02:00
return 1 ;
}
2019-02-22 18:38:58 +01:00
VisualShaderNodeDeterminant : : PortType VisualShaderNodeDeterminant : : get_output_port_type ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return PORT_TYPE_SCALAR ;
}
2019-02-22 18:38:58 +01:00
String VisualShaderNodeDeterminant : : get_output_port_name ( int p_port ) const {
return " " ;
2018-07-14 23:15:42 +02:00
}
2019-02-22 18:38:58 +01:00
String VisualShaderNodeDeterminant : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = determinant( " + p_input_vars [ 0 ] + " ); \n " ;
2018-07-14 23:15:42 +02:00
}
2019-02-22 18:38:58 +01:00
VisualShaderNodeDeterminant : : VisualShaderNodeDeterminant ( ) {
2020-10-17 07:08:21 +02:00
set_input_port_default_value ( 0 , Transform3D ( ) ) ;
2018-07-14 23:15:42 +02:00
}
2022-01-28 19:36:10 +01:00
////////////// Derivative Function
2018-07-14 23:15:42 +02:00
2022-01-28 19:36:10 +01:00
String VisualShaderNodeDerivativeFunc : : get_caption ( ) const {
return " DerivativeFunc " ;
2018-07-14 23:15:42 +02:00
}
2022-01-28 19:36:10 +01:00
int VisualShaderNodeDerivativeFunc : : get_input_port_count ( ) const {
2019-02-22 18:38:58 +01:00
return 1 ;
2018-07-14 23:15:42 +02:00
}
2019-02-22 18:38:58 +01:00
2022-01-28 19:36:10 +01:00
VisualShaderNodeDerivativeFunc : : PortType VisualShaderNodeDerivativeFunc : : get_input_port_type ( int p_port ) const {
2022-02-01 09:32:01 +01:00
switch ( op_type ) {
case OP_TYPE_VECTOR_2D :
return PORT_TYPE_VECTOR_2D ;
case OP_TYPE_VECTOR_3D :
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D :
return PORT_TYPE_VECTOR_4D ;
2022-02-01 09:32:01 +01:00
default :
break ;
2022-01-28 19:36:10 +01:00
}
2019-02-22 18:38:58 +01:00
return PORT_TYPE_SCALAR ;
2018-07-14 23:15:42 +02:00
}
2019-02-22 18:38:58 +01:00
2022-01-28 19:36:10 +01:00
String VisualShaderNodeDerivativeFunc : : get_input_port_name ( int p_port ) const {
return " p " ;
2018-07-14 23:15:42 +02:00
}
2022-01-28 19:36:10 +01:00
int VisualShaderNodeDerivativeFunc : : get_output_port_count ( ) const {
2018-07-14 23:15:42 +02:00
return 1 ;
}
2022-01-28 19:36:10 +01:00
VisualShaderNodeDerivativeFunc : : PortType VisualShaderNodeDerivativeFunc : : get_output_port_type ( int p_port ) const {
2022-02-01 09:32:01 +01:00
switch ( op_type ) {
case OP_TYPE_VECTOR_2D :
return PORT_TYPE_VECTOR_2D ;
case OP_TYPE_VECTOR_3D :
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D :
return PORT_TYPE_VECTOR_4D ;
2022-02-01 09:32:01 +01:00
default :
break ;
2022-01-28 19:36:10 +01:00
}
2019-02-22 18:38:58 +01:00
return PORT_TYPE_SCALAR ;
2018-07-14 23:15:42 +02:00
}
2022-01-28 19:36:10 +01:00
String VisualShaderNodeDerivativeFunc : : get_output_port_name ( int p_port ) const {
return " result " ;
2018-07-14 23:15:42 +02:00
}
2022-01-28 19:36:10 +01:00
String VisualShaderNodeDerivativeFunc : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-08-14 12:38:22 +02:00
static const char * functions [ FUNC_MAX ] = {
2019-02-22 18:38:58 +01:00
" fwidth($) " ,
" dFdx($) " ,
" dFdy($) "
} ;
String code ;
2021-08-14 12:38:22 +02:00
code + = " " + p_output_vars [ 0 ] + " = " + String ( functions [ func ] ) . replace ( " $ " , p_input_vars [ 0 ] ) + " ; \n " ;
2019-02-22 18:38:58 +01:00
return code ;
}
2022-01-28 19:36:10 +01:00
void VisualShaderNodeDerivativeFunc : : set_op_type ( OpType p_op_type ) {
ERR_FAIL_INDEX ( ( int ) p_op_type , int ( OP_TYPE_MAX ) ) ;
if ( op_type = = p_op_type ) {
2021-08-14 12:38:22 +02:00
return ;
}
2022-01-28 19:36:10 +01:00
switch ( p_op_type ) {
2022-02-01 09:32:01 +01:00
case OP_TYPE_SCALAR : {
set_input_port_default_value ( 0 , 0.0 , get_input_port_default_value ( 0 ) ) ;
} break ;
case OP_TYPE_VECTOR_2D : {
set_input_port_default_value ( 0 , Vector2 ( ) , get_input_port_default_value ( 0 ) ) ;
} break ;
case OP_TYPE_VECTOR_3D : {
set_input_port_default_value ( 0 , Vector3 ( ) , get_input_port_default_value ( 0 ) ) ;
} break ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D : {
set_input_port_default_value ( 0 , Quaternion ( ) , get_input_port_default_value ( 0 ) ) ;
} break ;
2022-01-28 19:36:10 +01:00
default :
break ;
}
op_type = p_op_type ;
2019-02-22 18:38:58 +01:00
emit_changed ( ) ;
}
2022-01-28 19:36:10 +01:00
VisualShaderNodeDerivativeFunc : : OpType VisualShaderNodeDerivativeFunc : : get_op_type ( ) const {
return op_type ;
2019-02-22 18:38:58 +01:00
}
2022-01-28 19:36:10 +01:00
void VisualShaderNodeDerivativeFunc : : set_function ( Function p_func ) {
2021-08-14 12:38:22 +02:00
ERR_FAIL_INDEX ( int ( p_func ) , int ( FUNC_MAX ) ) ;
if ( func = = p_func ) {
return ;
}
2019-02-22 18:38:58 +01:00
func = p_func ;
emit_changed ( ) ;
}
2022-01-28 19:36:10 +01:00
VisualShaderNodeDerivativeFunc : : Function VisualShaderNodeDerivativeFunc : : get_function ( ) const {
2019-02-22 18:38:58 +01:00
return func ;
}
2022-01-28 19:36:10 +01:00
Vector < StringName > VisualShaderNodeDerivativeFunc : : get_editable_properties ( ) const {
2019-02-22 18:38:58 +01:00
Vector < StringName > props ;
2022-01-28 19:36:10 +01:00
props . push_back ( " op_type " ) ;
2019-02-22 18:38:58 +01:00
props . push_back ( " function " ) ;
return props ;
}
2022-01-28 19:36:10 +01:00
void VisualShaderNodeDerivativeFunc : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_op_type " , " type " ) , & VisualShaderNodeDerivativeFunc : : set_op_type ) ;
ClassDB : : bind_method ( D_METHOD ( " get_op_type " ) , & VisualShaderNodeDerivativeFunc : : get_op_type ) ;
2019-02-22 18:38:58 +01:00
2022-01-28 19:36:10 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_function " , " func " ) , & VisualShaderNodeDerivativeFunc : : set_function ) ;
ClassDB : : bind_method ( D_METHOD ( " get_function " ) , & VisualShaderNodeDerivativeFunc : : get_function ) ;
2022-04-12 19:09:29 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " op_type " , PROPERTY_HINT_ENUM , " Scalar,Vector2,Vector3,Vector4 " ) , " set_op_type " , " get_op_type " ) ;
2019-02-22 18:38:58 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " function " , PROPERTY_HINT_ENUM , " Sum,X,Y " ) , " set_function " , " get_function " ) ;
2022-01-28 19:36:10 +01:00
BIND_ENUM_CONSTANT ( OP_TYPE_SCALAR ) ;
2022-02-01 09:32:01 +01:00
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_2D ) ;
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_3D ) ;
2022-04-12 19:09:29 +02:00
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_4D ) ;
2022-01-28 19:36:10 +01:00
BIND_ENUM_CONSTANT ( OP_TYPE_MAX ) ;
2019-02-22 18:38:58 +01:00
BIND_ENUM_CONSTANT ( FUNC_SUM ) ;
BIND_ENUM_CONSTANT ( FUNC_X ) ;
BIND_ENUM_CONSTANT ( FUNC_Y ) ;
2021-08-14 12:38:22 +02:00
BIND_ENUM_CONSTANT ( FUNC_MAX ) ;
2019-02-22 18:38:58 +01:00
}
2022-01-28 19:36:10 +01:00
VisualShaderNodeDerivativeFunc : : VisualShaderNodeDerivativeFunc ( ) {
set_input_port_default_value ( 0 , 0.0 ) ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
////////////// Clamp
2019-02-22 18:38:58 +01:00
2021-01-18 10:23:04 +01:00
String VisualShaderNodeClamp : : get_caption ( ) const {
return " Clamp " ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
int VisualShaderNodeClamp : : get_input_port_count ( ) const {
2019-02-22 18:38:58 +01:00
return 3 ;
}
2021-01-18 10:23:04 +01:00
VisualShaderNodeClamp : : PortType VisualShaderNodeClamp : : get_input_port_type ( int p_port ) const {
switch ( op_type ) {
case OP_TYPE_INT :
return PORT_TYPE_SCALAR_INT ;
2022-02-01 09:32:01 +01:00
case OP_TYPE_VECTOR_2D :
return PORT_TYPE_VECTOR_2D ;
case OP_TYPE_VECTOR_3D :
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D :
return PORT_TYPE_VECTOR_4D ;
2021-01-18 10:23:04 +01:00
default :
break ;
}
2019-02-22 18:38:58 +01:00
return PORT_TYPE_SCALAR ;
}
2021-01-18 10:23:04 +01:00
String VisualShaderNodeClamp : : get_input_port_name ( int p_port ) const {
2020-05-14 16:41:43 +02:00
if ( p_port = = 0 ) {
2019-02-22 18:38:58 +01:00
return " " ;
2020-05-14 16:41:43 +02:00
} else if ( p_port = = 1 ) {
2019-02-22 18:38:58 +01:00
return " min " ;
2020-05-14 16:41:43 +02:00
} else if ( p_port = = 2 ) {
2019-02-22 18:38:58 +01:00
return " max " ;
2020-05-14 16:41:43 +02:00
}
2019-02-22 18:38:58 +01:00
return " " ;
}
2021-01-18 10:23:04 +01:00
int VisualShaderNodeClamp : : get_output_port_count ( ) const {
2019-02-22 18:38:58 +01:00
return 1 ;
}
2021-01-18 10:23:04 +01:00
VisualShaderNodeClamp : : PortType VisualShaderNodeClamp : : get_output_port_type ( int p_port ) const {
switch ( op_type ) {
case OP_TYPE_INT :
return PORT_TYPE_SCALAR_INT ;
2022-02-01 09:32:01 +01:00
case OP_TYPE_VECTOR_2D :
return PORT_TYPE_VECTOR_2D ;
case OP_TYPE_VECTOR_3D :
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D :
return PORT_TYPE_VECTOR_4D ;
2021-01-18 10:23:04 +01:00
default :
break ;
}
2019-02-22 18:38:58 +01:00
return PORT_TYPE_SCALAR ;
}
2021-01-18 10:23:04 +01:00
String VisualShaderNodeClamp : : get_output_port_name ( int p_port ) const {
2019-02-22 18:38:58 +01:00
return " " ;
}
2021-01-18 10:23:04 +01:00
String VisualShaderNodeClamp : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = clamp( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " , " + p_input_vars [ 2 ] + " ); \n " ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
void VisualShaderNodeClamp : : set_op_type ( OpType p_op_type ) {
2021-08-14 12:38:22 +02:00
ERR_FAIL_INDEX ( ( int ) p_op_type , int ( OP_TYPE_MAX ) ) ;
2021-01-18 10:23:04 +01:00
if ( op_type = = p_op_type ) {
return ;
2020-05-14 16:41:43 +02:00
}
2021-01-18 10:23:04 +01:00
switch ( p_op_type ) {
case OP_TYPE_FLOAT :
2022-02-01 09:32:01 +01:00
set_input_port_default_value ( 0 , 0.0 , get_input_port_default_value ( 0 ) ) ;
set_input_port_default_value ( 1 , 0.0 , get_input_port_default_value ( 1 ) ) ;
set_input_port_default_value ( 2 , 0.0 , get_input_port_default_value ( 2 ) ) ;
2021-01-18 10:23:04 +01:00
break ;
case OP_TYPE_INT :
2022-02-01 09:32:01 +01:00
set_input_port_default_value ( 0 , 0 , get_input_port_default_value ( 0 ) ) ;
set_input_port_default_value ( 1 , 0 , get_input_port_default_value ( 1 ) ) ;
set_input_port_default_value ( 2 , 0 , get_input_port_default_value ( 2 ) ) ;
break ;
case OP_TYPE_VECTOR_2D :
set_input_port_default_value ( 0 , Vector2 ( ) , get_input_port_default_value ( 0 ) ) ;
set_input_port_default_value ( 1 , Vector2 ( ) , get_input_port_default_value ( 1 ) ) ;
set_input_port_default_value ( 2 , Vector2 ( ) , get_input_port_default_value ( 2 ) ) ;
2021-01-18 10:23:04 +01:00
break ;
2022-02-01 09:32:01 +01:00
case OP_TYPE_VECTOR_3D :
set_input_port_default_value ( 0 , Vector3 ( ) , get_input_port_default_value ( 0 ) ) ;
set_input_port_default_value ( 1 , Vector3 ( ) , get_input_port_default_value ( 1 ) ) ;
set_input_port_default_value ( 2 , Vector3 ( ) , get_input_port_default_value ( 2 ) ) ;
2021-01-18 10:23:04 +01:00
break ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D :
set_input_port_default_value ( 0 , Quaternion ( ) , get_input_port_default_value ( 0 ) ) ;
set_input_port_default_value ( 1 , Quaternion ( ) , get_input_port_default_value ( 1 ) ) ;
set_input_port_default_value ( 2 , Quaternion ( ) , get_input_port_default_value ( 2 ) ) ;
break ;
2021-01-18 10:23:04 +01:00
default :
break ;
}
op_type = p_op_type ;
emit_changed ( ) ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
VisualShaderNodeClamp : : OpType VisualShaderNodeClamp : : get_op_type ( ) const {
return op_type ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
Vector < StringName > VisualShaderNodeClamp : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " op_type " ) ;
return props ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
void VisualShaderNodeClamp : : _bind_methods ( ) {
2021-08-14 12:38:22 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_op_type " , " op_type " ) , & VisualShaderNodeClamp : : set_op_type ) ;
2021-01-18 10:23:04 +01:00
ClassDB : : bind_method ( D_METHOD ( " get_op_type " ) , & VisualShaderNodeClamp : : get_op_type ) ;
2019-02-22 18:38:58 +01:00
2022-04-12 19:09:29 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " op_type " , PROPERTY_HINT_ENUM , " Float,Int,Vector2,Vector3,Vector4 " ) , " set_op_type " , " get_op_type " ) ;
2021-01-18 10:23:04 +01:00
BIND_ENUM_CONSTANT ( OP_TYPE_FLOAT ) ;
BIND_ENUM_CONSTANT ( OP_TYPE_INT ) ;
2022-02-01 09:32:01 +01:00
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_2D ) ;
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_3D ) ;
2022-04-12 19:09:29 +02:00
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_4D ) ;
2021-01-18 10:23:04 +01:00
BIND_ENUM_CONSTANT ( OP_TYPE_MAX ) ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
VisualShaderNodeClamp : : VisualShaderNodeClamp ( ) {
set_input_port_default_value ( 0 , 0.0 ) ;
set_input_port_default_value ( 1 , 0.0 ) ;
set_input_port_default_value ( 2 , 1.0 ) ;
2019-02-22 18:38:58 +01:00
}
////////////// FaceForward
String VisualShaderNodeFaceForward : : get_caption ( ) const {
return " FaceForward " ;
}
int VisualShaderNodeFaceForward : : get_input_port_count ( ) const {
return 3 ;
}
String VisualShaderNodeFaceForward : : get_input_port_name ( int p_port ) const {
switch ( p_port ) {
case 0 :
return " N " ;
case 1 :
return " I " ;
case 2 :
return " Nref " ;
default :
return " " ;
}
}
int VisualShaderNodeFaceForward : : get_output_port_count ( ) const {
return 1 ;
}
String VisualShaderNodeFaceForward : : get_output_port_name ( int p_port ) const {
return " " ;
}
2022-02-01 09:32:01 +01:00
void VisualShaderNodeFaceForward : : set_op_type ( OpType p_op_type ) {
ERR_FAIL_INDEX ( int ( p_op_type ) , int ( OP_TYPE_MAX ) ) ;
if ( op_type = = p_op_type ) {
return ;
}
switch ( p_op_type ) {
case OP_TYPE_VECTOR_2D : {
set_input_port_default_value ( 0 , Vector2 ( ) , get_input_port_default_value ( 0 ) ) ;
set_input_port_default_value ( 1 , Vector2 ( ) , get_input_port_default_value ( 1 ) ) ;
set_input_port_default_value ( 2 , Vector2 ( ) , get_input_port_default_value ( 2 ) ) ;
} break ;
case OP_TYPE_VECTOR_3D : {
set_input_port_default_value ( 0 , Vector3 ( ) , get_input_port_default_value ( 0 ) ) ;
set_input_port_default_value ( 1 , Vector3 ( ) , get_input_port_default_value ( 1 ) ) ;
set_input_port_default_value ( 2 , Vector3 ( ) , get_input_port_default_value ( 2 ) ) ;
} break ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D : {
set_input_port_default_value ( 0 , Quaternion ( ) , get_input_port_default_value ( 0 ) ) ;
set_input_port_default_value ( 1 , Quaternion ( ) , get_input_port_default_value ( 1 ) ) ;
set_input_port_default_value ( 2 , Quaternion ( ) , get_input_port_default_value ( 2 ) ) ;
} break ;
2022-02-01 09:32:01 +01:00
default :
break ;
}
op_type = p_op_type ;
emit_changed ( ) ;
}
2019-02-22 18:38:58 +01:00
String VisualShaderNodeFaceForward : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = faceforward( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " , " + p_input_vars [ 2 ] + " ); \n " ;
2019-02-22 18:38:58 +01:00
}
VisualShaderNodeFaceForward : : VisualShaderNodeFaceForward ( ) {
set_input_port_default_value ( 0 , Vector3 ( 0.0 , 0.0 , 0.0 ) ) ;
set_input_port_default_value ( 1 , Vector3 ( 0.0 , 0.0 , 0.0 ) ) ;
set_input_port_default_value ( 2 , Vector3 ( 0.0 , 0.0 , 0.0 ) ) ;
}
////////////// Outer Product
String VisualShaderNodeOuterProduct : : get_caption ( ) const {
return " OuterProduct " ;
}
int VisualShaderNodeOuterProduct : : get_input_port_count ( ) const {
return 2 ;
}
2019-09-18 18:04:40 +02:00
VisualShaderNodeOuterProduct : : PortType VisualShaderNodeOuterProduct : : get_input_port_type ( int p_port ) const {
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2019-02-22 18:38:58 +01:00
}
String VisualShaderNodeOuterProduct : : get_input_port_name ( int p_port ) const {
switch ( p_port ) {
case 0 :
return " c " ;
case 1 :
return " r " ;
default :
return " " ;
}
}
int VisualShaderNodeOuterProduct : : get_output_port_count ( ) const {
return 1 ;
}
VisualShaderNodeOuterProduct : : PortType VisualShaderNodeOuterProduct : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_TRANSFORM ;
}
String VisualShaderNodeOuterProduct : : get_output_port_name ( int p_port ) const {
return " " ;
}
String VisualShaderNodeOuterProduct : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = outerProduct(vec4( " + p_input_vars [ 0 ] + " , 0.0), vec4( " + p_input_vars [ 1 ] + " , 0.0)); \n " ;
2019-02-22 18:38:58 +01:00
}
VisualShaderNodeOuterProduct : : VisualShaderNodeOuterProduct ( ) {
set_input_port_default_value ( 0 , Vector3 ( 0.0 , 0.0 , 0.0 ) ) ;
set_input_port_default_value ( 1 , Vector3 ( 0.0 , 0.0 , 0.0 ) ) ;
}
2021-01-18 10:23:04 +01:00
////////////// Step
2019-02-22 18:38:58 +01:00
2021-01-18 10:23:04 +01:00
String VisualShaderNodeStep : : get_caption ( ) const {
return " Step " ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
int VisualShaderNodeStep : : get_input_port_count ( ) const {
2019-02-22 18:38:58 +01:00
return 2 ;
}
2021-01-18 10:23:04 +01:00
VisualShaderNodeStep : : PortType VisualShaderNodeStep : : get_input_port_type ( int p_port ) const {
switch ( op_type ) {
2022-02-01 09:32:01 +01:00
case OP_TYPE_VECTOR_2D :
return PORT_TYPE_VECTOR_2D ;
case OP_TYPE_VECTOR_2D_SCALAR :
if ( p_port = = 1 ) {
return PORT_TYPE_VECTOR_2D ;
}
break ;
case OP_TYPE_VECTOR_3D :
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2022-02-01 09:32:01 +01:00
case OP_TYPE_VECTOR_3D_SCALAR :
2021-03-01 06:03:49 +01:00
if ( p_port = = 1 ) {
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2021-01-18 10:23:04 +01:00
}
break ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D :
return PORT_TYPE_VECTOR_4D ;
case OP_TYPE_VECTOR_4D_SCALAR :
if ( p_port = = 1 ) {
return PORT_TYPE_VECTOR_4D ;
}
break ;
2021-01-18 10:23:04 +01:00
default :
break ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
return PORT_TYPE_SCALAR ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
String VisualShaderNodeStep : : get_input_port_name ( int p_port ) const {
2022-02-01 09:32:01 +01:00
switch ( p_port ) {
case 0 :
return " edge " ;
case 1 :
return " x " ;
2020-05-14 16:41:43 +02:00
}
2022-02-01 09:32:01 +01:00
return String ( ) ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
int VisualShaderNodeStep : : get_output_port_count ( ) const {
2019-02-22 18:38:58 +01:00
return 1 ;
}
2021-01-18 10:23:04 +01:00
VisualShaderNodeStep : : PortType VisualShaderNodeStep : : get_output_port_type ( int p_port ) const {
switch ( op_type ) {
2022-02-01 09:32:01 +01:00
case OP_TYPE_VECTOR_2D :
return PORT_TYPE_VECTOR_2D ;
case OP_TYPE_VECTOR_2D_SCALAR :
return PORT_TYPE_VECTOR_2D ;
case OP_TYPE_VECTOR_3D :
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2022-02-01 09:32:01 +01:00
case OP_TYPE_VECTOR_3D_SCALAR :
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D :
return PORT_TYPE_VECTOR_4D ;
case OP_TYPE_VECTOR_4D_SCALAR :
return PORT_TYPE_VECTOR_4D ;
2021-01-18 10:23:04 +01:00
default :
break ;
}
return PORT_TYPE_SCALAR ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
String VisualShaderNodeStep : : get_output_port_name ( int p_port ) const {
2019-02-22 18:38:58 +01:00
return " " ;
}
2021-01-18 10:23:04 +01:00
void VisualShaderNodeStep : : set_op_type ( OpType p_op_type ) {
2021-08-14 12:38:22 +02:00
ERR_FAIL_INDEX ( int ( p_op_type ) , int ( OP_TYPE_MAX ) ) ;
2021-01-18 10:23:04 +01:00
if ( op_type = = p_op_type ) {
return ;
}
switch ( p_op_type ) {
2022-02-01 09:32:01 +01:00
case OP_TYPE_SCALAR : {
set_input_port_default_value ( 0 , 0.0 , get_input_port_default_value ( 0 ) ) ;
set_input_port_default_value ( 1 , 0.0 , get_input_port_default_value ( 1 ) ) ;
} break ;
case OP_TYPE_VECTOR_2D : {
set_input_port_default_value ( 0 , Vector2 ( ) , get_input_port_default_value ( 0 ) ) ;
set_input_port_default_value ( 1 , Vector2 ( ) , get_input_port_default_value ( 1 ) ) ;
} break ;
case OP_TYPE_VECTOR_2D_SCALAR : {
set_input_port_default_value ( 0 , 0.0 , get_input_port_default_value ( 0 ) ) ;
set_input_port_default_value ( 1 , Vector2 ( ) , get_input_port_default_value ( 1 ) ) ;
} break ;
case OP_TYPE_VECTOR_3D : {
set_input_port_default_value ( 0 , Vector3 ( ) , get_input_port_default_value ( 0 ) ) ;
set_input_port_default_value ( 1 , Vector3 ( ) , get_input_port_default_value ( 1 ) ) ;
} break ;
case OP_TYPE_VECTOR_3D_SCALAR : {
set_input_port_default_value ( 0 , 0.0 , get_input_port_default_value ( 0 ) ) ;
set_input_port_default_value ( 1 , Vector3 ( ) , get_input_port_default_value ( 1 ) ) ;
} break ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D : {
set_input_port_default_value ( 0 , Quaternion ( ) , get_input_port_default_value ( 0 ) ) ;
set_input_port_default_value ( 1 , Quaternion ( ) , get_input_port_default_value ( 1 ) ) ;
} break ;
case OP_TYPE_VECTOR_4D_SCALAR : {
set_input_port_default_value ( 0 , 0.0 , get_input_port_default_value ( 0 ) ) ;
set_input_port_default_value ( 1 , Quaternion ( ) , get_input_port_default_value ( 1 ) ) ;
} break ;
2021-01-18 10:23:04 +01:00
default :
break ;
}
op_type = p_op_type ;
emit_changed ( ) ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
VisualShaderNodeStep : : OpType VisualShaderNodeStep : : get_op_type ( ) const {
return op_type ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
String VisualShaderNodeStep : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = step( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
Vector < StringName > VisualShaderNodeStep : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " op_type " ) ;
return props ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
void VisualShaderNodeStep : : _bind_methods ( ) {
2021-08-14 12:38:22 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_op_type " , " op_type " ) , & VisualShaderNodeStep : : set_op_type ) ;
2021-01-18 10:23:04 +01:00
ClassDB : : bind_method ( D_METHOD ( " get_op_type " ) , & VisualShaderNodeStep : : get_op_type ) ;
2019-02-22 18:38:58 +01:00
2022-04-12 19:09:29 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " op_type " , PROPERTY_HINT_ENUM , " Scalar,Vector2,Vector2Scalar,Vector3,Vector3Scalar,Vector4,Vector4Scalar " ) , " set_op_type " , " get_op_type " ) ;
2019-02-22 18:38:58 +01:00
2021-01-18 10:23:04 +01:00
BIND_ENUM_CONSTANT ( OP_TYPE_SCALAR ) ;
2022-02-01 09:32:01 +01:00
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_2D ) ;
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_2D_SCALAR ) ;
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_3D ) ;
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_3D_SCALAR ) ;
2022-04-12 19:09:29 +02:00
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_4D ) ;
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_4D_SCALAR ) ;
2021-01-18 10:23:04 +01:00
BIND_ENUM_CONSTANT ( OP_TYPE_MAX ) ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
VisualShaderNodeStep : : VisualShaderNodeStep ( ) {
2019-02-22 18:38:58 +01:00
set_input_port_default_value ( 0 , 0.0 ) ;
set_input_port_default_value ( 1 , 0.0 ) ;
}
2021-01-18 10:23:04 +01:00
////////////// SmoothStep
2019-02-22 18:38:58 +01:00
2021-01-18 10:23:04 +01:00
String VisualShaderNodeSmoothStep : : get_caption ( ) const {
return " SmoothStep " ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
int VisualShaderNodeSmoothStep : : get_input_port_count ( ) const {
2019-02-22 18:38:58 +01:00
return 3 ;
}
2021-01-18 10:23:04 +01:00
VisualShaderNodeSmoothStep : : PortType VisualShaderNodeSmoothStep : : get_input_port_type ( int p_port ) const {
switch ( op_type ) {
2022-02-01 09:32:01 +01:00
case OP_TYPE_VECTOR_2D :
return PORT_TYPE_VECTOR_2D ;
case OP_TYPE_VECTOR_2D_SCALAR :
if ( p_port = = 2 ) {
return PORT_TYPE_VECTOR_2D ; // x
}
break ;
case OP_TYPE_VECTOR_3D :
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2022-02-01 09:32:01 +01:00
case OP_TYPE_VECTOR_3D_SCALAR :
2021-03-01 06:03:49 +01:00
if ( p_port = = 2 ) {
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ; // x
2021-01-18 10:23:04 +01:00
}
break ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D :
return PORT_TYPE_VECTOR_4D ;
case OP_TYPE_VECTOR_4D_SCALAR :
if ( p_port = = 2 ) {
return PORT_TYPE_VECTOR_4D ; // x
}
break ;
2021-01-18 10:23:04 +01:00
default :
break ;
}
return PORT_TYPE_SCALAR ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
String VisualShaderNodeSmoothStep : : get_input_port_name ( int p_port ) const {
2022-02-01 09:32:01 +01:00
switch ( p_port ) {
case 0 :
return " edge0 " ;
case 1 :
return " edge1 " ;
case 2 :
return " x " ;
2020-05-14 16:41:43 +02:00
}
2022-02-01 09:32:01 +01:00
return String ( ) ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
int VisualShaderNodeSmoothStep : : get_output_port_count ( ) const {
2019-02-22 18:38:58 +01:00
return 1 ;
}
2021-01-18 10:23:04 +01:00
VisualShaderNodeSmoothStep : : PortType VisualShaderNodeSmoothStep : : get_output_port_type ( int p_port ) const {
switch ( op_type ) {
2022-02-01 09:32:01 +01:00
case OP_TYPE_VECTOR_2D :
return PORT_TYPE_VECTOR_2D ;
case OP_TYPE_VECTOR_2D_SCALAR :
return PORT_TYPE_VECTOR_2D ;
case OP_TYPE_VECTOR_3D :
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2022-02-01 09:32:01 +01:00
case OP_TYPE_VECTOR_3D_SCALAR :
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D :
return PORT_TYPE_VECTOR_4D ;
case OP_TYPE_VECTOR_4D_SCALAR :
return PORT_TYPE_VECTOR_4D ;
2021-01-18 10:23:04 +01:00
default :
break ;
}
return PORT_TYPE_SCALAR ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
String VisualShaderNodeSmoothStep : : get_output_port_name ( int p_port ) const {
2019-02-22 18:38:58 +01:00
return " " ;
}
2021-01-18 10:23:04 +01:00
void VisualShaderNodeSmoothStep : : set_op_type ( OpType p_op_type ) {
2021-08-14 12:38:22 +02:00
ERR_FAIL_INDEX ( int ( p_op_type ) , int ( OP_TYPE_MAX ) ) ;
2021-01-18 10:23:04 +01:00
if ( op_type = = p_op_type ) {
return ;
}
switch ( p_op_type ) {
case OP_TYPE_SCALAR :
2022-02-01 09:32:01 +01:00
set_input_port_default_value ( 0 , 0.0 , get_input_port_default_value ( 0 ) ) ; // edge0
set_input_port_default_value ( 1 , 0.0 , get_input_port_default_value ( 1 ) ) ; // edge1
set_input_port_default_value ( 2 , 0.0 , get_input_port_default_value ( 2 ) ) ; // x
break ;
case OP_TYPE_VECTOR_2D :
set_input_port_default_value ( 0 , Vector2 ( ) , get_input_port_default_value ( 0 ) ) ; // edge0
set_input_port_default_value ( 1 , Vector2 ( ) , get_input_port_default_value ( 1 ) ) ; // edge1
set_input_port_default_value ( 2 , Vector2 ( ) , get_input_port_default_value ( 2 ) ) ; // x
break ;
case OP_TYPE_VECTOR_2D_SCALAR :
set_input_port_default_value ( 0 , 0.0 , get_input_port_default_value ( 0 ) ) ; // edge0
set_input_port_default_value ( 1 , 0.0 , get_input_port_default_value ( 1 ) ) ; // edge1
set_input_port_default_value ( 2 , Vector2 ( ) , get_input_port_default_value ( 2 ) ) ; // x
break ;
case OP_TYPE_VECTOR_3D :
set_input_port_default_value ( 0 , Vector3 ( ) , get_input_port_default_value ( 0 ) ) ; // edge0
set_input_port_default_value ( 1 , Vector3 ( ) , get_input_port_default_value ( 1 ) ) ; // edge1
set_input_port_default_value ( 2 , Vector3 ( ) , get_input_port_default_value ( 2 ) ) ; // x
break ;
case OP_TYPE_VECTOR_3D_SCALAR :
set_input_port_default_value ( 0 , 0.0 , get_input_port_default_value ( 0 ) ) ; // edge0
set_input_port_default_value ( 1 , 0.0 , get_input_port_default_value ( 1 ) ) ; // edge1
set_input_port_default_value ( 2 , Vector3 ( ) , get_input_port_default_value ( 2 ) ) ; // x
2021-01-18 10:23:04 +01:00
break ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D :
set_input_port_default_value ( 0 , Quaternion ( ) , get_input_port_default_value ( 0 ) ) ; // edge0
set_input_port_default_value ( 1 , Quaternion ( ) , get_input_port_default_value ( 1 ) ) ; // edge1
set_input_port_default_value ( 2 , Quaternion ( ) , get_input_port_default_value ( 2 ) ) ; // x
break ;
case OP_TYPE_VECTOR_4D_SCALAR :
set_input_port_default_value ( 0 , 0.0 , get_input_port_default_value ( 0 ) ) ; // edge0
set_input_port_default_value ( 1 , 0.0 , get_input_port_default_value ( 1 ) ) ; // edge1
set_input_port_default_value ( 2 , Quaternion ( ) , get_input_port_default_value ( 2 ) ) ; // x
break ;
2021-01-18 10:23:04 +01:00
default :
break ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
op_type = p_op_type ;
emit_changed ( ) ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
VisualShaderNodeSmoothStep : : OpType VisualShaderNodeSmoothStep : : get_op_type ( ) const {
return op_type ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
String VisualShaderNodeSmoothStep : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = smoothstep( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " , " + p_input_vars [ 2 ] + " ); \n " ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
Vector < StringName > VisualShaderNodeSmoothStep : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " op_type " ) ;
return props ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
void VisualShaderNodeSmoothStep : : _bind_methods ( ) {
2021-08-14 12:38:22 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_op_type " , " op_type " ) , & VisualShaderNodeSmoothStep : : set_op_type ) ;
2021-01-18 10:23:04 +01:00
ClassDB : : bind_method ( D_METHOD ( " get_op_type " ) , & VisualShaderNodeSmoothStep : : get_op_type ) ;
2019-02-22 18:38:58 +01:00
2022-04-12 19:09:29 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " op_type " , PROPERTY_HINT_ENUM , " Scalar,Vector2,Vector2Scalar,Vector3,Vector3Scalar,Vector4,Vector4Scalar " ) , " set_op_type " , " get_op_type " ) ;
2021-01-18 10:23:04 +01:00
BIND_ENUM_CONSTANT ( OP_TYPE_SCALAR ) ;
2022-02-01 09:32:01 +01:00
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_2D ) ;
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_2D_SCALAR ) ;
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_3D ) ;
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_3D_SCALAR ) ;
2022-04-12 19:09:29 +02:00
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_4D ) ;
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_4D_SCALAR ) ;
2021-01-18 10:23:04 +01:00
BIND_ENUM_CONSTANT ( OP_TYPE_MAX ) ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
VisualShaderNodeSmoothStep : : VisualShaderNodeSmoothStep ( ) {
2022-02-01 09:32:01 +01:00
set_input_port_default_value ( 0 , 0.0 ) ; // edge0
set_input_port_default_value ( 1 , 1.0 ) ; // edge1
set_input_port_default_value ( 2 , 0.5 ) ; // x
2019-02-22 18:38:58 +01:00
}
////////////// Distance
String VisualShaderNodeVectorDistance : : get_caption ( ) const {
return " Distance " ;
}
int VisualShaderNodeVectorDistance : : get_input_port_count ( ) const {
return 2 ;
}
String VisualShaderNodeVectorDistance : : get_input_port_name ( int p_port ) const {
2022-02-01 09:32:01 +01:00
switch ( p_port ) {
case 0 :
return " a " ;
case 1 :
return " b " ;
2019-02-22 18:38:58 +01:00
}
2022-02-01 09:32:01 +01:00
return String ( ) ;
2019-02-22 18:38:58 +01:00
}
int VisualShaderNodeVectorDistance : : get_output_port_count ( ) const {
return 1 ;
}
VisualShaderNodeVectorDistance : : PortType VisualShaderNodeVectorDistance : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_SCALAR ;
}
String VisualShaderNodeVectorDistance : : get_output_port_name ( int p_port ) const {
return " " ;
}
2022-02-01 09:32:01 +01:00
void VisualShaderNodeVectorDistance : : set_op_type ( OpType p_op_type ) {
ERR_FAIL_INDEX ( int ( p_op_type ) , int ( OP_TYPE_MAX ) ) ;
if ( op_type = = p_op_type ) {
return ;
}
switch ( p_op_type ) {
case OP_TYPE_VECTOR_2D : {
set_input_port_default_value ( 0 , Vector2 ( ) , get_input_port_default_value ( 0 ) ) ; // a
set_input_port_default_value ( 1 , Vector2 ( ) , get_input_port_default_value ( 1 ) ) ; // b
} break ;
case OP_TYPE_VECTOR_3D : {
set_input_port_default_value ( 0 , Vector3 ( ) , get_input_port_default_value ( 0 ) ) ; // a
set_input_port_default_value ( 1 , Vector3 ( ) , get_input_port_default_value ( 1 ) ) ; // b
} break ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D : {
set_input_port_default_value ( 0 , Quaternion ( ) , get_input_port_default_value ( 0 ) ) ; // a
set_input_port_default_value ( 1 , Quaternion ( ) , get_input_port_default_value ( 1 ) ) ; // b
} break ;
2022-02-01 09:32:01 +01:00
default :
break ;
}
op_type = p_op_type ;
emit_changed ( ) ;
}
2019-02-22 18:38:58 +01:00
String VisualShaderNodeVectorDistance : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = distance( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
2019-02-22 18:38:58 +01:00
}
VisualShaderNodeVectorDistance : : VisualShaderNodeVectorDistance ( ) {
2022-02-01 09:32:01 +01:00
set_input_port_default_value ( 0 , Vector3 ( 0.0 , 0.0 , 0.0 ) ) ; // a
set_input_port_default_value ( 1 , Vector3 ( 0.0 , 0.0 , 0.0 ) ) ; // b
2019-02-22 18:38:58 +01:00
}
////////////// Refract Vector
String VisualShaderNodeVectorRefract : : get_caption ( ) const {
return " Refract " ;
}
int VisualShaderNodeVectorRefract : : get_input_port_count ( ) const {
return 3 ;
}
String VisualShaderNodeVectorRefract : : get_input_port_name ( int p_port ) const {
2022-02-01 09:32:01 +01:00
switch ( p_port ) {
case 0 :
return " I " ;
case 1 :
return " N " ;
case 2 :
return " eta " ;
2019-02-22 18:38:58 +01:00
}
2022-02-01 09:32:01 +01:00
return String ( ) ;
2019-02-22 18:38:58 +01:00
}
int VisualShaderNodeVectorRefract : : get_output_port_count ( ) const {
return 1 ;
}
String VisualShaderNodeVectorRefract : : get_output_port_name ( int p_port ) const {
return " " ;
}
String VisualShaderNodeVectorRefract : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = refract( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " , " + p_input_vars [ 2 ] + " ); \n " ;
2019-02-22 18:38:58 +01:00
}
2022-08-07 18:03:16 +02:00
void VisualShaderNodeVectorRefract : : set_op_type ( OpType p_op_type ) {
ERR_FAIL_INDEX ( int ( p_op_type ) , int ( OP_TYPE_MAX ) ) ;
if ( op_type = = p_op_type ) {
return ;
}
switch ( p_op_type ) {
case OP_TYPE_VECTOR_2D : {
set_input_port_default_value ( 0 , Vector2 ( ) , get_input_port_default_value ( 0 ) ) ;
set_input_port_default_value ( 1 , Vector2 ( ) , get_input_port_default_value ( 1 ) ) ;
} break ;
case OP_TYPE_VECTOR_3D : {
set_input_port_default_value ( 0 , Vector3 ( ) , get_input_port_default_value ( 0 ) ) ;
set_input_port_default_value ( 1 , Vector3 ( ) , get_input_port_default_value ( 1 ) ) ;
} break ;
case OP_TYPE_VECTOR_4D : {
set_input_port_default_value ( 0 , Quaternion ( ) , get_input_port_default_value ( 0 ) ) ;
set_input_port_default_value ( 1 , Quaternion ( ) , get_input_port_default_value ( 1 ) ) ;
} break ;
default :
break ;
}
op_type = p_op_type ;
emit_changed ( ) ;
}
2019-02-22 18:38:58 +01:00
VisualShaderNodeVectorRefract : : VisualShaderNodeVectorRefract ( ) {
set_input_port_default_value ( 0 , Vector3 ( 0.0 , 0.0 , 0.0 ) ) ;
set_input_port_default_value ( 1 , Vector3 ( 0.0 , 0.0 , 0.0 ) ) ;
set_input_port_default_value ( 2 , 0.0 ) ;
}
2021-01-18 10:23:04 +01:00
////////////// Mix
2019-02-22 18:38:58 +01:00
2021-01-18 10:23:04 +01:00
String VisualShaderNodeMix : : get_caption ( ) const {
return " Mix " ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
int VisualShaderNodeMix : : get_input_port_count ( ) const {
2019-02-22 18:38:58 +01:00
return 3 ;
}
2019-08-03 17:12:33 +02:00
2021-01-18 10:23:04 +01:00
VisualShaderNodeMix : : PortType VisualShaderNodeMix : : get_input_port_type ( int p_port ) const {
switch ( op_type ) {
2022-02-01 09:32:01 +01:00
case OP_TYPE_VECTOR_2D :
return PORT_TYPE_VECTOR_2D ;
case OP_TYPE_VECTOR_2D_SCALAR :
if ( p_port = = 2 ) {
break ;
}
return PORT_TYPE_VECTOR_2D ;
case OP_TYPE_VECTOR_3D :
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2022-02-01 09:32:01 +01:00
case OP_TYPE_VECTOR_3D_SCALAR :
2021-01-18 10:23:04 +01:00
if ( p_port = = 2 ) {
2021-03-01 06:03:49 +01:00
break ;
2021-01-18 10:23:04 +01:00
}
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D :
return PORT_TYPE_VECTOR_4D ;
case OP_TYPE_VECTOR_4D_SCALAR :
if ( p_port = = 2 ) {
break ;
}
return PORT_TYPE_VECTOR_4D ;
2021-01-18 10:23:04 +01:00
default :
break ;
}
2019-02-22 18:38:58 +01:00
return PORT_TYPE_SCALAR ;
}
2019-08-03 17:12:33 +02:00
2021-01-18 10:23:04 +01:00
String VisualShaderNodeMix : : get_input_port_name ( int p_port ) const {
2019-02-22 18:38:58 +01:00
if ( p_port = = 0 ) {
return " a " ;
} else if ( p_port = = 1 ) {
return " b " ;
} else {
2019-08-03 17:12:33 +02:00
return " weight " ;
2019-02-22 18:38:58 +01:00
}
}
2021-01-18 10:23:04 +01:00
int VisualShaderNodeMix : : get_output_port_count ( ) const {
2019-02-22 18:38:58 +01:00
return 1 ;
}
2019-08-03 17:12:33 +02:00
2021-01-18 10:23:04 +01:00
VisualShaderNodeMix : : PortType VisualShaderNodeMix : : get_output_port_type ( int p_port ) const {
switch ( op_type ) {
2022-02-01 09:32:01 +01:00
case OP_TYPE_VECTOR_2D :
return PORT_TYPE_VECTOR_2D ;
case OP_TYPE_VECTOR_2D_SCALAR :
return PORT_TYPE_VECTOR_2D ;
case OP_TYPE_VECTOR_3D :
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2022-02-01 09:32:01 +01:00
case OP_TYPE_VECTOR_3D_SCALAR :
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D :
return PORT_TYPE_VECTOR_4D ;
case OP_TYPE_VECTOR_4D_SCALAR :
return PORT_TYPE_VECTOR_4D ;
2021-01-18 10:23:04 +01:00
default :
break ;
}
2019-02-22 18:38:58 +01:00
return PORT_TYPE_SCALAR ;
}
2019-08-03 17:12:33 +02:00
2021-01-18 10:23:04 +01:00
String VisualShaderNodeMix : : get_output_port_name ( int p_port ) const {
2019-02-22 18:38:58 +01:00
return " mix " ;
}
2021-01-18 10:23:04 +01:00
void VisualShaderNodeMix : : set_op_type ( OpType p_op_type ) {
2021-08-14 12:38:22 +02:00
ERR_FAIL_INDEX ( int ( p_op_type ) , int ( OP_TYPE_MAX ) ) ;
2021-01-18 10:23:04 +01:00
if ( op_type = = p_op_type ) {
return ;
}
switch ( p_op_type ) {
2022-02-01 09:32:01 +01:00
case OP_TYPE_SCALAR : {
set_input_port_default_value ( 0 , 0.0 , get_input_port_default_value ( 0 ) ) ; // a
set_input_port_default_value ( 1 , 0.0 , get_input_port_default_value ( 1 ) ) ; // b
set_input_port_default_value ( 2 , 0.0 , get_input_port_default_value ( 2 ) ) ; // weight
} break ;
case OP_TYPE_VECTOR_2D : {
set_input_port_default_value ( 0 , Vector2 ( ) , get_input_port_default_value ( 0 ) ) ; // a
set_input_port_default_value ( 1 , Vector2 ( ) , get_input_port_default_value ( 1 ) ) ; // b
set_input_port_default_value ( 2 , Vector2 ( ) , get_input_port_default_value ( 2 ) ) ; // weight
} break ;
case OP_TYPE_VECTOR_2D_SCALAR : {
set_input_port_default_value ( 0 , Vector2 ( ) , get_input_port_default_value ( 0 ) ) ; // a
set_input_port_default_value ( 1 , Vector2 ( ) , get_input_port_default_value ( 1 ) ) ; // b
set_input_port_default_value ( 2 , 0.0 , get_input_port_default_value ( 2 ) ) ; // weight
} break ;
case OP_TYPE_VECTOR_3D : {
set_input_port_default_value ( 0 , Vector3 ( ) , get_input_port_default_value ( 0 ) ) ; // a
set_input_port_default_value ( 1 , Vector3 ( ) , get_input_port_default_value ( 1 ) ) ; // b
set_input_port_default_value ( 2 , Vector3 ( ) , get_input_port_default_value ( 2 ) ) ; // weight
} break ;
case OP_TYPE_VECTOR_3D_SCALAR : {
set_input_port_default_value ( 0 , Vector3 ( ) , get_input_port_default_value ( 0 ) ) ; // a
set_input_port_default_value ( 1 , Vector3 ( ) , get_input_port_default_value ( 1 ) ) ; // b
set_input_port_default_value ( 2 , 0.0 , get_input_port_default_value ( 2 ) ) ; // weight
} break ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D : {
set_input_port_default_value ( 0 , Quaternion ( ) , get_input_port_default_value ( 0 ) ) ; // a
set_input_port_default_value ( 1 , Quaternion ( ) , get_input_port_default_value ( 1 ) ) ; // b
set_input_port_default_value ( 2 , Quaternion ( ) , get_input_port_default_value ( 2 ) ) ; // weight
} break ;
case OP_TYPE_VECTOR_4D_SCALAR : {
set_input_port_default_value ( 0 , Quaternion ( ) , get_input_port_default_value ( 0 ) ) ; // a
set_input_port_default_value ( 1 , Quaternion ( ) , get_input_port_default_value ( 1 ) ) ; // b
set_input_port_default_value ( 2 , 0.0 , get_input_port_default_value ( 2 ) ) ; // weight
} break ;
2021-01-18 10:23:04 +01:00
default :
break ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
op_type = p_op_type ;
emit_changed ( ) ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
VisualShaderNodeMix : : OpType VisualShaderNodeMix : : get_op_type ( ) const {
return op_type ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
String VisualShaderNodeMix : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = mix( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " , " + p_input_vars [ 2 ] + " ); \n " ;
2019-02-22 18:38:58 +01:00
}
2021-01-18 10:23:04 +01:00
Vector < StringName > VisualShaderNodeMix : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " op_type " ) ;
return props ;
2019-08-03 17:12:33 +02:00
}
2021-01-18 10:23:04 +01:00
void VisualShaderNodeMix : : _bind_methods ( ) {
2021-08-14 12:38:22 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_op_type " , " op_type " ) , & VisualShaderNodeMix : : set_op_type ) ;
2021-01-18 10:23:04 +01:00
ClassDB : : bind_method ( D_METHOD ( " get_op_type " ) , & VisualShaderNodeMix : : get_op_type ) ;
2019-08-03 17:12:33 +02:00
2022-04-12 19:09:29 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " op_type " , PROPERTY_HINT_ENUM , " Scalar,Vector2,Vector2Scalar,Vector3,Vector3Scalar,Vector4,Vector4Scalar " ) , " set_op_type " , " get_op_type " ) ;
2019-08-03 17:12:33 +02:00
2021-01-18 10:23:04 +01:00
BIND_ENUM_CONSTANT ( OP_TYPE_SCALAR ) ;
2022-02-01 09:32:01 +01:00
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_2D ) ;
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_2D_SCALAR ) ;
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_3D ) ;
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_3D_SCALAR ) ;
2022-04-12 19:09:29 +02:00
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_4D ) ;
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_4D_SCALAR ) ;
2021-01-18 10:23:04 +01:00
BIND_ENUM_CONSTANT ( OP_TYPE_MAX ) ;
2019-08-03 17:12:33 +02:00
}
2021-01-18 10:23:04 +01:00
VisualShaderNodeMix : : VisualShaderNodeMix ( ) {
set_input_port_default_value ( 0 , 0.0 ) ; // a
set_input_port_default_value ( 1 , 1.0 ) ; // b
set_input_port_default_value ( 2 , 0.5 ) ; // weight
2019-02-22 18:38:58 +01:00
}
////////////// Vector Compose
2019-09-18 18:04:40 +02:00
2019-02-22 18:38:58 +01:00
String VisualShaderNodeVectorCompose : : get_caption ( ) const {
return " VectorCompose " ;
}
2018-07-14 23:15:42 +02:00
2018-07-15 16:28:06 +02:00
int VisualShaderNodeVectorCompose : : get_input_port_count ( ) const {
2022-02-01 09:32:01 +01:00
switch ( op_type ) {
case OP_TYPE_VECTOR_2D :
return 2 ;
case OP_TYPE_VECTOR_3D :
return 3 ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D :
return 4 ;
2022-02-01 09:32:01 +01:00
default :
break ;
}
return 0 ;
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2018-07-15 16:28:06 +02:00
VisualShaderNodeVectorCompose : : PortType VisualShaderNodeVectorCompose : : get_input_port_type ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return PORT_TYPE_SCALAR ;
}
2019-09-18 18:04:40 +02:00
2018-07-15 16:28:06 +02:00
String VisualShaderNodeVectorCompose : : get_input_port_name ( int p_port ) const {
2022-02-01 09:32:01 +01:00
switch ( op_type ) {
case OP_TYPE_VECTOR_2D : {
switch ( p_port ) {
case 0 :
return " x " ;
case 1 :
return " y " ;
}
} break ;
case OP_TYPE_VECTOR_3D : {
switch ( p_port ) {
case 0 :
return " x " ;
case 1 :
return " y " ;
case 2 :
return " z " ;
}
} break ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D : {
switch ( p_port ) {
case 0 :
return " x " ;
case 1 :
return " y " ;
case 2 :
return " z " ;
case 3 :
return " w " ;
}
} break ;
2022-02-01 09:32:01 +01:00
default :
break ;
2018-07-14 23:15:42 +02:00
}
2022-02-01 09:32:01 +01:00
return String ( ) ;
2018-07-14 23:15:42 +02:00
}
2018-07-15 16:28:06 +02:00
int VisualShaderNodeVectorCompose : : get_output_port_count ( ) const {
2018-07-14 23:15:42 +02:00
return 1 ;
}
2019-09-18 18:04:40 +02:00
2018-07-15 16:28:06 +02:00
String VisualShaderNodeVectorCompose : : get_output_port_name ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return " vec " ;
}
2022-02-01 09:32:01 +01:00
void VisualShaderNodeVectorCompose : : set_op_type ( OpType p_op_type ) {
ERR_FAIL_INDEX ( int ( p_op_type ) , int ( OP_TYPE_MAX ) ) ;
if ( op_type = = p_op_type ) {
return ;
}
switch ( p_op_type ) {
case OP_TYPE_VECTOR_2D : {
float p1 = get_input_port_default_value ( 0 ) ;
float p2 = get_input_port_default_value ( 1 ) ;
set_input_port_default_value ( 0 , p1 ) ;
set_input_port_default_value ( 1 , p2 ) ;
} break ;
case OP_TYPE_VECTOR_3D : {
float p1 = get_input_port_default_value ( 0 ) ;
float p2 = get_input_port_default_value ( 1 ) ;
set_input_port_default_value ( 0 , p1 ) ;
set_input_port_default_value ( 1 , p2 ) ;
set_input_port_default_value ( 2 , 0.0 ) ;
} break ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D : {
float p1 = get_input_port_default_value ( 0 ) ;
float p2 = get_input_port_default_value ( 1 ) ;
set_input_port_default_value ( 0 , p1 ) ;
set_input_port_default_value ( 1 , p2 ) ;
set_input_port_default_value ( 2 , 0.0 ) ;
set_input_port_default_value ( 3 , 0.0 ) ;
} break ;
2022-02-01 09:32:01 +01:00
default :
break ;
}
op_type = p_op_type ;
emit_changed ( ) ;
}
2019-01-21 20:07:53 +01:00
String VisualShaderNodeVectorCompose : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2022-02-01 09:32:01 +01:00
String code ;
switch ( op_type ) {
case OP_TYPE_VECTOR_2D : {
code + = " " + p_output_vars [ 0 ] + " = vec2( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
} break ;
case OP_TYPE_VECTOR_3D : {
code + = " " + p_output_vars [ 0 ] + " = vec3( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " , " + p_input_vars [ 2 ] + " ); \n " ;
} break ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D : {
code + = " " + p_output_vars [ 0 ] + " = vec4( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " , " + p_input_vars [ 2 ] + " , " + p_input_vars [ 3 ] + " ); \n " ;
} break ;
2022-02-01 09:32:01 +01:00
default :
break ;
}
return code ;
2018-07-14 23:15:42 +02:00
}
2018-07-15 16:28:06 +02:00
VisualShaderNodeVectorCompose : : VisualShaderNodeVectorCompose ( ) {
2018-07-14 23:15:42 +02:00
set_input_port_default_value ( 0 , 0.0 ) ;
set_input_port_default_value ( 1 , 0.0 ) ;
set_input_port_default_value ( 2 , 0.0 ) ;
}
2018-07-15 16:28:06 +02:00
////////////// Transform Compose
2018-07-14 23:15:42 +02:00
2018-07-15 16:28:06 +02:00
String VisualShaderNodeTransformCompose : : get_caption ( ) const {
return " TransformCompose " ;
2018-07-14 23:15:42 +02:00
}
2018-07-15 16:28:06 +02:00
int VisualShaderNodeTransformCompose : : get_input_port_count ( ) const {
2018-07-14 23:15:42 +02:00
return 4 ;
}
2019-09-18 18:04:40 +02:00
2018-07-15 16:28:06 +02:00
VisualShaderNodeTransformCompose : : PortType VisualShaderNodeTransformCompose : : get_input_port_type ( int p_port ) const {
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2018-07-15 16:28:06 +02:00
String VisualShaderNodeTransformCompose : : get_input_port_name ( int p_port ) const {
2018-07-14 23:15:42 +02:00
if ( p_port = = 0 ) {
return " x " ;
} else if ( p_port = = 1 ) {
return " y " ;
} else if ( p_port = = 2 ) {
return " z " ;
} else {
return " origin " ;
}
}
2018-07-15 16:28:06 +02:00
int VisualShaderNodeTransformCompose : : get_output_port_count ( ) const {
2018-07-14 23:15:42 +02:00
return 1 ;
}
2019-09-18 18:04:40 +02:00
2018-07-15 16:28:06 +02:00
VisualShaderNodeTransformCompose : : PortType VisualShaderNodeTransformCompose : : get_output_port_type ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return PORT_TYPE_TRANSFORM ;
}
2019-09-18 18:04:40 +02:00
2018-07-15 16:28:06 +02:00
String VisualShaderNodeTransformCompose : : get_output_port_name ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return " xform " ;
}
2019-01-21 20:07:53 +01:00
String VisualShaderNodeTransformCompose : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = mat4(vec4( " + p_input_vars [ 0 ] + " , 0.0), vec4( " + p_input_vars [ 1 ] + " , 0.0), vec4( " + p_input_vars [ 2 ] + " , 0.0), vec4( " + p_input_vars [ 3 ] + " , 1.0)); \n " ;
2018-07-14 23:15:42 +02:00
}
2018-07-15 16:28:06 +02:00
VisualShaderNodeTransformCompose : : VisualShaderNodeTransformCompose ( ) {
2018-07-14 23:15:42 +02:00
set_input_port_default_value ( 0 , Vector3 ( ) ) ;
set_input_port_default_value ( 1 , Vector3 ( ) ) ;
set_input_port_default_value ( 2 , Vector3 ( ) ) ;
set_input_port_default_value ( 3 , Vector3 ( ) ) ;
}
2018-07-15 16:28:06 +02:00
////////////// Vector Decompose
String VisualShaderNodeVectorDecompose : : get_caption ( ) const {
return " VectorDecompose " ;
2018-07-14 23:15:42 +02:00
}
2018-07-15 16:28:06 +02:00
int VisualShaderNodeVectorDecompose : : get_input_port_count ( ) const {
2018-07-14 23:15:42 +02:00
return 1 ;
}
2019-09-18 18:04:40 +02:00
2018-07-15 16:28:06 +02:00
String VisualShaderNodeVectorDecompose : : get_input_port_name ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return " vec " ;
}
2018-07-15 16:28:06 +02:00
int VisualShaderNodeVectorDecompose : : get_output_port_count ( ) const {
2022-02-01 09:32:01 +01:00
switch ( op_type ) {
case OP_TYPE_VECTOR_2D :
return 2 ;
case OP_TYPE_VECTOR_3D :
return 3 ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D :
return 4 ;
2022-02-01 09:32:01 +01:00
default :
break ;
}
return 0 ;
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2018-07-15 16:28:06 +02:00
VisualShaderNodeVectorDecompose : : PortType VisualShaderNodeVectorDecompose : : get_output_port_type ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return PORT_TYPE_SCALAR ;
}
2019-09-18 18:04:40 +02:00
2018-07-15 16:28:06 +02:00
String VisualShaderNodeVectorDecompose : : get_output_port_name ( int p_port ) const {
2022-02-01 09:32:01 +01:00
switch ( op_type ) {
case OP_TYPE_VECTOR_2D : {
switch ( p_port ) {
case 0 :
return " x " ;
case 1 :
return " y " ;
}
} break ;
case OP_TYPE_VECTOR_3D : {
switch ( p_port ) {
case 0 :
return " x " ;
case 1 :
return " y " ;
case 2 :
return " z " ;
}
} break ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D : {
switch ( p_port ) {
case 0 :
return " x " ;
case 1 :
return " y " ;
case 2 :
return " z " ;
case 3 :
return " w " ;
}
} break ;
2022-02-01 09:32:01 +01:00
default :
break ;
2018-07-14 23:15:42 +02:00
}
2022-02-01 09:32:01 +01:00
return String ( ) ;
}
void VisualShaderNodeVectorDecompose : : set_op_type ( OpType p_op_type ) {
ERR_FAIL_INDEX ( int ( p_op_type ) , int ( OP_TYPE_MAX ) ) ;
if ( op_type = = p_op_type ) {
return ;
}
switch ( p_op_type ) {
case OP_TYPE_VECTOR_2D : {
set_input_port_default_value ( 0 , Vector2 ( ) , get_input_port_default_value ( 0 ) ) ;
} break ;
case OP_TYPE_VECTOR_3D : {
set_input_port_default_value ( 0 , Vector3 ( ) , get_input_port_default_value ( 0 ) ) ;
} break ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D : {
set_input_port_default_value ( 0 , Quaternion ( ) , get_input_port_default_value ( 0 ) ) ;
} break ;
2022-02-01 09:32:01 +01:00
default :
break ;
}
op_type = p_op_type ;
emit_changed ( ) ;
2018-07-14 23:15:42 +02:00
}
2019-01-21 20:07:53 +01:00
String VisualShaderNodeVectorDecompose : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2018-07-14 23:15:42 +02:00
String code ;
2022-02-01 09:32:01 +01:00
switch ( op_type ) {
case OP_TYPE_VECTOR_2D : {
code + = " " + p_output_vars [ 0 ] + " = " + p_input_vars [ 0 ] + " .x; \n " ;
code + = " " + p_output_vars [ 1 ] + " = " + p_input_vars [ 0 ] + " .y; \n " ;
} break ;
case OP_TYPE_VECTOR_3D : {
code + = " " + p_output_vars [ 0 ] + " = " + p_input_vars [ 0 ] + " .x; \n " ;
code + = " " + p_output_vars [ 1 ] + " = " + p_input_vars [ 0 ] + " .y; \n " ;
code + = " " + p_output_vars [ 2 ] + " = " + p_input_vars [ 0 ] + " .z; \n " ;
} break ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D : {
code + = " " + p_output_vars [ 0 ] + " = " + p_input_vars [ 0 ] + " .x; \n " ;
code + = " " + p_output_vars [ 1 ] + " = " + p_input_vars [ 0 ] + " .y; \n " ;
code + = " " + p_output_vars [ 2 ] + " = " + p_input_vars [ 0 ] + " .z; \n " ;
code + = " " + p_output_vars [ 3 ] + " = " + p_input_vars [ 0 ] + " .w; \n " ;
} break ;
2022-02-01 09:32:01 +01:00
default :
break ;
}
2018-07-14 23:15:42 +02:00
return code ;
}
2018-07-15 16:28:06 +02:00
VisualShaderNodeVectorDecompose : : VisualShaderNodeVectorDecompose ( ) {
2022-02-01 09:32:01 +01:00
set_input_port_default_value ( 0 , Vector3 ( 0.0 , 0.0 , 0.0 ) ) ;
2018-07-14 23:15:42 +02:00
}
2018-07-15 16:28:06 +02:00
////////////// Transform Decompose
2018-07-14 23:15:42 +02:00
2018-07-15 16:28:06 +02:00
String VisualShaderNodeTransformDecompose : : get_caption ( ) const {
return " TransformDecompose " ;
2018-07-14 23:15:42 +02:00
}
2018-07-15 16:28:06 +02:00
int VisualShaderNodeTransformDecompose : : get_input_port_count ( ) const {
2018-07-14 23:15:42 +02:00
return 1 ;
}
2019-09-18 18:04:40 +02:00
2018-07-15 16:28:06 +02:00
VisualShaderNodeTransformDecompose : : PortType VisualShaderNodeTransformDecompose : : get_input_port_type ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return PORT_TYPE_TRANSFORM ;
}
2019-09-18 18:04:40 +02:00
2018-07-15 16:28:06 +02:00
String VisualShaderNodeTransformDecompose : : get_input_port_name ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return " xform " ;
}
2018-07-15 16:28:06 +02:00
int VisualShaderNodeTransformDecompose : : get_output_port_count ( ) const {
2018-07-14 23:15:42 +02:00
return 4 ;
}
2019-09-18 18:04:40 +02:00
2018-07-15 16:28:06 +02:00
VisualShaderNodeTransformDecompose : : PortType VisualShaderNodeTransformDecompose : : get_output_port_type ( int p_port ) const {
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2018-07-15 16:28:06 +02:00
String VisualShaderNodeTransformDecompose : : get_output_port_name ( int p_port ) const {
2018-07-14 23:15:42 +02:00
if ( p_port = = 0 ) {
return " x " ;
} else if ( p_port = = 1 ) {
return " y " ;
} else if ( p_port = = 2 ) {
return " z " ;
} else {
return " origin " ;
}
}
2019-01-21 20:07:53 +01:00
String VisualShaderNodeTransformDecompose : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2018-07-14 23:15:42 +02:00
String code ;
2021-07-19 08:06:51 +02:00
code + = " " + p_output_vars [ 0 ] + " = " + p_input_vars [ 0 ] + " [0].xyz; \n " ;
code + = " " + p_output_vars [ 1 ] + " = " + p_input_vars [ 0 ] + " [1].xyz; \n " ;
code + = " " + p_output_vars [ 2 ] + " = " + p_input_vars [ 0 ] + " [2].xyz; \n " ;
code + = " " + p_output_vars [ 3 ] + " = " + p_input_vars [ 0 ] + " [3].xyz; \n " ;
2018-07-14 23:15:42 +02:00
return code ;
}
2018-07-15 16:28:06 +02:00
VisualShaderNodeTransformDecompose : : VisualShaderNodeTransformDecompose ( ) {
2020-10-17 07:08:21 +02:00
set_input_port_default_value ( 0 , Transform3D ( ) ) ;
2018-07-14 23:15:42 +02:00
}
2020-02-25 15:50:49 +01:00
////////////// Float Uniform
2018-07-14 23:15:42 +02:00
2020-02-25 15:50:49 +01:00
String VisualShaderNodeFloatUniform : : get_caption ( ) const {
return " FloatUniform " ;
2018-07-14 23:15:42 +02:00
}
2020-02-25 15:50:49 +01:00
int VisualShaderNodeFloatUniform : : get_input_port_count ( ) const {
2018-07-14 23:15:42 +02:00
return 0 ;
}
2019-09-18 18:04:40 +02:00
2020-02-25 15:50:49 +01:00
VisualShaderNodeFloatUniform : : PortType VisualShaderNodeFloatUniform : : get_input_port_type ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return PORT_TYPE_SCALAR ;
}
2019-09-18 18:04:40 +02:00
2020-02-25 15:50:49 +01:00
String VisualShaderNodeFloatUniform : : get_input_port_name ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return String ( ) ;
}
2020-02-25 15:50:49 +01:00
int VisualShaderNodeFloatUniform : : get_output_port_count ( ) const {
2018-07-14 23:15:42 +02:00
return 1 ;
}
2019-09-18 18:04:40 +02:00
2020-02-25 15:50:49 +01:00
VisualShaderNodeFloatUniform : : PortType VisualShaderNodeFloatUniform : : get_output_port_type ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return PORT_TYPE_SCALAR ;
}
2019-09-18 18:04:40 +02:00
2020-02-25 15:50:49 +01:00
String VisualShaderNodeFloatUniform : : get_output_port_name ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return " " ; //no output port means the editor will be used as port
}
2020-02-25 15:50:49 +01:00
String VisualShaderNodeFloatUniform : : generate_global ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id ) const {
2020-07-27 13:33:27 +02:00
String code = " " ;
2020-02-06 13:11:03 +01:00
if ( hint = = HINT_RANGE ) {
2020-07-27 13:33:27 +02:00
code + = _get_qual_str ( ) + " uniform float " + get_uniform_name ( ) + " : hint_range( " + rtos ( hint_range_min ) + " , " + rtos ( hint_range_max ) + " ) " ;
2020-02-06 13:11:03 +01:00
} else if ( hint = = HINT_RANGE_STEP ) {
2020-07-27 13:33:27 +02:00
code + = _get_qual_str ( ) + " uniform float " + get_uniform_name ( ) + " : hint_range( " + rtos ( hint_range_min ) + " , " + rtos ( hint_range_max ) + " , " + rtos ( hint_range_step ) + " ) " ;
} else {
code + = _get_qual_str ( ) + " uniform float " + get_uniform_name ( ) ;
}
if ( default_value_enabled ) {
code + = " = " + rtos ( default_value ) ;
2020-02-06 13:11:03 +01:00
}
2020-07-27 13:33:27 +02:00
code + = " ; \n " ;
return code ;
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2020-02-25 15:50:49 +01:00
String VisualShaderNodeFloatUniform : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = " + get_uniform_name ( ) + " ; \n " ;
2018-07-14 23:15:42 +02:00
}
2020-09-21 13:32:59 +02:00
bool VisualShaderNodeFloatUniform : : is_show_prop_names ( ) const {
return true ;
}
bool VisualShaderNodeFloatUniform : : is_use_prop_slots ( ) const {
return true ;
}
2020-02-25 15:50:49 +01:00
void VisualShaderNodeFloatUniform : : set_hint ( Hint p_hint ) {
2021-08-14 12:38:22 +02:00
ERR_FAIL_INDEX ( int ( p_hint ) , int ( HINT_MAX ) ) ;
if ( hint = = p_hint ) {
return ;
}
2020-02-06 13:11:03 +01:00
hint = p_hint ;
emit_changed ( ) ;
}
2020-02-25 15:50:49 +01:00
VisualShaderNodeFloatUniform : : Hint VisualShaderNodeFloatUniform : : get_hint ( ) const {
2020-02-06 13:11:03 +01:00
return hint ;
}
2020-02-25 15:50:49 +01:00
void VisualShaderNodeFloatUniform : : set_min ( float p_value ) {
2021-08-14 12:38:22 +02:00
if ( Math : : is_equal_approx ( hint_range_min , p_value ) ) {
return ;
}
2020-02-06 13:11:03 +01:00
hint_range_min = p_value ;
emit_changed ( ) ;
}
2020-02-25 15:50:49 +01:00
float VisualShaderNodeFloatUniform : : get_min ( ) const {
2020-02-06 13:11:03 +01:00
return hint_range_min ;
}
2020-02-25 15:50:49 +01:00
void VisualShaderNodeFloatUniform : : set_max ( float p_value ) {
2021-08-14 12:38:22 +02:00
if ( Math : : is_equal_approx ( hint_range_max , p_value ) ) {
return ;
}
2020-02-06 13:11:03 +01:00
hint_range_max = p_value ;
emit_changed ( ) ;
}
2020-02-25 15:50:49 +01:00
float VisualShaderNodeFloatUniform : : get_max ( ) const {
2020-02-06 13:11:03 +01:00
return hint_range_max ;
}
2020-02-25 15:50:49 +01:00
void VisualShaderNodeFloatUniform : : set_step ( float p_value ) {
2021-08-14 12:38:22 +02:00
if ( Math : : is_equal_approx ( hint_range_step , p_value ) ) {
return ;
}
2020-02-06 13:11:03 +01:00
hint_range_step = p_value ;
emit_changed ( ) ;
}
2020-02-25 15:50:49 +01:00
float VisualShaderNodeFloatUniform : : get_step ( ) const {
2020-02-06 13:11:03 +01:00
return hint_range_step ;
}
2020-07-27 13:33:27 +02:00
void VisualShaderNodeFloatUniform : : set_default_value_enabled ( bool p_enabled ) {
2021-08-14 12:38:22 +02:00
if ( default_value_enabled = = p_enabled ) {
return ;
}
2020-07-27 13:33:27 +02:00
default_value_enabled = p_enabled ;
emit_changed ( ) ;
}
bool VisualShaderNodeFloatUniform : : is_default_value_enabled ( ) const {
return default_value_enabled ;
}
void VisualShaderNodeFloatUniform : : set_default_value ( float p_value ) {
2021-08-14 12:38:22 +02:00
if ( Math : : is_equal_approx ( default_value , p_value ) ) {
return ;
}
2020-07-27 13:33:27 +02:00
default_value = p_value ;
emit_changed ( ) ;
}
float VisualShaderNodeFloatUniform : : get_default_value ( ) const {
return default_value ;
}
2020-02-25 15:50:49 +01:00
void VisualShaderNodeFloatUniform : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_hint " , " hint " ) , & VisualShaderNodeFloatUniform : : set_hint ) ;
ClassDB : : bind_method ( D_METHOD ( " get_hint " ) , & VisualShaderNodeFloatUniform : : get_hint ) ;
2020-02-06 13:11:03 +01:00
2020-02-25 15:50:49 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_min " , " value " ) , & VisualShaderNodeFloatUniform : : set_min ) ;
ClassDB : : bind_method ( D_METHOD ( " get_min " ) , & VisualShaderNodeFloatUniform : : get_min ) ;
2020-02-06 13:11:03 +01:00
2020-02-25 15:50:49 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_max " , " value " ) , & VisualShaderNodeFloatUniform : : set_max ) ;
ClassDB : : bind_method ( D_METHOD ( " get_max " ) , & VisualShaderNodeFloatUniform : : get_max ) ;
2020-02-06 13:11:03 +01:00
2020-02-25 15:50:49 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_step " , " value " ) , & VisualShaderNodeFloatUniform : : set_step ) ;
ClassDB : : bind_method ( D_METHOD ( " get_step " ) , & VisualShaderNodeFloatUniform : : get_step ) ;
2020-02-06 13:11:03 +01:00
2020-07-27 13:33:27 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_default_value_enabled " , " enabled " ) , & VisualShaderNodeFloatUniform : : set_default_value_enabled ) ;
ClassDB : : bind_method ( D_METHOD ( " is_default_value_enabled " ) , & VisualShaderNodeFloatUniform : : is_default_value_enabled ) ;
ClassDB : : bind_method ( D_METHOD ( " set_default_value " , " value " ) , & VisualShaderNodeFloatUniform : : set_default_value ) ;
ClassDB : : bind_method ( D_METHOD ( " get_default_value " ) , & VisualShaderNodeFloatUniform : : get_default_value ) ;
2020-02-06 13:11:03 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " hint " , PROPERTY_HINT_ENUM , " None,Range,Range+Step " ) , " set_hint " , " get_hint " ) ;
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " min " ) , " set_min " , " get_min " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " max " ) , " set_max " , " get_max " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " step " ) , " set_step " , " get_step " ) ;
2020-07-27 13:33:27 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " default_value_enabled " ) , " set_default_value_enabled " , " is_default_value_enabled " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " default_value " ) , " set_default_value " , " get_default_value " ) ;
2020-02-06 13:11:03 +01:00
BIND_ENUM_CONSTANT ( HINT_NONE ) ;
BIND_ENUM_CONSTANT ( HINT_RANGE ) ;
BIND_ENUM_CONSTANT ( HINT_RANGE_STEP ) ;
2021-08-14 12:38:22 +02:00
BIND_ENUM_CONSTANT ( HINT_MAX ) ;
2020-02-06 13:11:03 +01:00
}
2020-05-05 10:25:48 +02:00
bool VisualShaderNodeFloatUniform : : is_qualifier_supported ( Qualifier p_qual ) const {
return true ; // all qualifiers are supported
}
2021-04-04 14:09:29 +02:00
bool VisualShaderNodeFloatUniform : : is_convertible_to_constant ( ) const {
return true ; // conversion is allowed
}
2020-02-25 15:50:49 +01:00
Vector < StringName > VisualShaderNodeFloatUniform : : get_editable_properties ( ) const {
2020-05-05 10:25:48 +02:00
Vector < StringName > props = VisualShaderNodeUniform : : get_editable_properties ( ) ;
2020-02-06 13:11:03 +01:00
props . push_back ( " hint " ) ;
if ( hint = = HINT_RANGE | | hint = = HINT_RANGE_STEP ) {
props . push_back ( " min " ) ;
props . push_back ( " max " ) ;
}
if ( hint = = HINT_RANGE_STEP ) {
props . push_back ( " step " ) ;
}
2020-07-27 13:33:27 +02:00
props . push_back ( " default_value_enabled " ) ;
if ( default_value_enabled ) {
props . push_back ( " default_value " ) ;
}
2020-02-06 13:11:03 +01:00
return props ;
}
2020-02-25 15:50:49 +01:00
VisualShaderNodeFloatUniform : : VisualShaderNodeFloatUniform ( ) {
2018-07-14 23:15:42 +02:00
}
2020-02-25 15:50:49 +01:00
////////////// Integer Uniform
String VisualShaderNodeIntUniform : : get_caption ( ) const {
return " IntUniform " ;
}
int VisualShaderNodeIntUniform : : get_input_port_count ( ) const {
return 0 ;
}
VisualShaderNodeIntUniform : : PortType VisualShaderNodeIntUniform : : get_input_port_type ( int p_port ) const {
return PORT_TYPE_SCALAR_INT ;
}
String VisualShaderNodeIntUniform : : get_input_port_name ( int p_port ) const {
return String ( ) ;
}
int VisualShaderNodeIntUniform : : get_output_port_count ( ) const {
return 1 ;
}
VisualShaderNodeIntUniform : : PortType VisualShaderNodeIntUniform : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_SCALAR_INT ;
}
String VisualShaderNodeIntUniform : : get_output_port_name ( int p_port ) const {
return " " ; //no output port means the editor will be used as port
}
String VisualShaderNodeIntUniform : : generate_global ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id ) const {
2020-07-27 13:33:27 +02:00
String code = " " ;
2020-02-25 15:50:49 +01:00
if ( hint = = HINT_RANGE ) {
2020-07-27 13:33:27 +02:00
code + = _get_qual_str ( ) + " uniform int " + get_uniform_name ( ) + " : hint_range( " + itos ( hint_range_min ) + " , " + itos ( hint_range_max ) + " ) " ;
2020-02-25 15:50:49 +01:00
} else if ( hint = = HINT_RANGE_STEP ) {
2020-07-27 13:33:27 +02:00
code + = _get_qual_str ( ) + " uniform int " + get_uniform_name ( ) + " : hint_range( " + itos ( hint_range_min ) + " , " + itos ( hint_range_max ) + " , " + itos ( hint_range_step ) + " ) " ;
} else {
code + = _get_qual_str ( ) + " uniform int " + get_uniform_name ( ) ;
2020-02-25 15:50:49 +01:00
}
2020-07-27 13:33:27 +02:00
if ( default_value_enabled ) {
code + = " = " + itos ( default_value ) ;
}
code + = " ; \n " ;
return code ;
2020-02-25 15:50:49 +01:00
}
String VisualShaderNodeIntUniform : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = " + get_uniform_name ( ) + " ; \n " ;
2020-02-25 15:50:49 +01:00
}
2020-09-21 13:32:59 +02:00
bool VisualShaderNodeIntUniform : : is_show_prop_names ( ) const {
return true ;
}
bool VisualShaderNodeIntUniform : : is_use_prop_slots ( ) const {
return true ;
}
2020-02-25 15:50:49 +01:00
void VisualShaderNodeIntUniform : : set_hint ( Hint p_hint ) {
2021-08-14 12:38:22 +02:00
ERR_FAIL_INDEX ( int ( p_hint ) , int ( HINT_MAX ) ) ;
if ( hint = = p_hint ) {
return ;
}
2020-02-25 15:50:49 +01:00
hint = p_hint ;
emit_changed ( ) ;
}
VisualShaderNodeIntUniform : : Hint VisualShaderNodeIntUniform : : get_hint ( ) const {
return hint ;
}
void VisualShaderNodeIntUniform : : set_min ( int p_value ) {
2021-08-14 12:38:22 +02:00
if ( hint_range_min = = p_value ) {
return ;
}
2020-02-25 15:50:49 +01:00
hint_range_min = p_value ;
emit_changed ( ) ;
}
int VisualShaderNodeIntUniform : : get_min ( ) const {
return hint_range_min ;
}
void VisualShaderNodeIntUniform : : set_max ( int p_value ) {
2021-08-14 12:38:22 +02:00
if ( hint_range_max = = p_value ) {
return ;
}
2020-02-25 15:50:49 +01:00
hint_range_max = p_value ;
emit_changed ( ) ;
}
int VisualShaderNodeIntUniform : : get_max ( ) const {
return hint_range_max ;
}
void VisualShaderNodeIntUniform : : set_step ( int p_value ) {
2021-08-14 12:38:22 +02:00
if ( hint_range_step = = p_value ) {
return ;
}
2020-02-25 15:50:49 +01:00
hint_range_step = p_value ;
emit_changed ( ) ;
}
int VisualShaderNodeIntUniform : : get_step ( ) const {
return hint_range_step ;
}
2021-08-14 12:38:22 +02:00
void VisualShaderNodeIntUniform : : set_default_value_enabled ( bool p_default_value_enabled ) {
if ( default_value_enabled = = p_default_value_enabled ) {
return ;
}
default_value_enabled = p_default_value_enabled ;
2020-07-27 13:33:27 +02:00
emit_changed ( ) ;
}
bool VisualShaderNodeIntUniform : : is_default_value_enabled ( ) const {
return default_value_enabled ;
}
2021-08-14 12:38:22 +02:00
void VisualShaderNodeIntUniform : : set_default_value ( int p_default_value ) {
if ( default_value = = p_default_value ) {
return ;
}
default_value = p_default_value ;
2020-07-27 13:33:27 +02:00
emit_changed ( ) ;
}
int VisualShaderNodeIntUniform : : get_default_value ( ) const {
return default_value ;
}
2020-02-25 15:50:49 +01:00
void VisualShaderNodeIntUniform : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_hint " , " hint " ) , & VisualShaderNodeIntUniform : : set_hint ) ;
ClassDB : : bind_method ( D_METHOD ( " get_hint " ) , & VisualShaderNodeIntUniform : : get_hint ) ;
ClassDB : : bind_method ( D_METHOD ( " set_min " , " value " ) , & VisualShaderNodeIntUniform : : set_min ) ;
ClassDB : : bind_method ( D_METHOD ( " get_min " ) , & VisualShaderNodeIntUniform : : get_min ) ;
ClassDB : : bind_method ( D_METHOD ( " set_max " , " value " ) , & VisualShaderNodeIntUniform : : set_max ) ;
ClassDB : : bind_method ( D_METHOD ( " get_max " ) , & VisualShaderNodeIntUniform : : get_max ) ;
ClassDB : : bind_method ( D_METHOD ( " set_step " , " value " ) , & VisualShaderNodeIntUniform : : set_step ) ;
ClassDB : : bind_method ( D_METHOD ( " get_step " ) , & VisualShaderNodeIntUniform : : get_step ) ;
2020-07-27 13:33:27 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_default_value_enabled " , " enabled " ) , & VisualShaderNodeIntUniform : : set_default_value_enabled ) ;
ClassDB : : bind_method ( D_METHOD ( " is_default_value_enabled " ) , & VisualShaderNodeIntUniform : : is_default_value_enabled ) ;
ClassDB : : bind_method ( D_METHOD ( " set_default_value " , " value " ) , & VisualShaderNodeIntUniform : : set_default_value ) ;
ClassDB : : bind_method ( D_METHOD ( " get_default_value " ) , & VisualShaderNodeIntUniform : : get_default_value ) ;
2021-05-22 04:30:58 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " hint " , PROPERTY_HINT_ENUM , " None,Range,Range + Step " ) , " set_hint " , " get_hint " ) ;
2020-02-25 15:50:49 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " min " ) , " set_min " , " get_min " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " max " ) , " set_max " , " get_max " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " step " ) , " set_step " , " get_step " ) ;
2020-07-27 13:33:27 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " default_value_enabled " ) , " set_default_value_enabled " , " is_default_value_enabled " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " default_value " ) , " set_default_value " , " get_default_value " ) ;
2020-02-25 15:50:49 +01:00
BIND_ENUM_CONSTANT ( HINT_NONE ) ;
BIND_ENUM_CONSTANT ( HINT_RANGE ) ;
BIND_ENUM_CONSTANT ( HINT_RANGE_STEP ) ;
2021-08-14 12:38:22 +02:00
BIND_ENUM_CONSTANT ( HINT_MAX ) ;
2020-02-25 15:50:49 +01:00
}
2020-05-05 10:25:48 +02:00
bool VisualShaderNodeIntUniform : : is_qualifier_supported ( Qualifier p_qual ) const {
return true ; // all qualifiers are supported
}
2021-04-04 14:09:29 +02:00
bool VisualShaderNodeIntUniform : : is_convertible_to_constant ( ) const {
return true ; // conversion is allowed
}
2020-02-25 15:50:49 +01:00
Vector < StringName > VisualShaderNodeIntUniform : : get_editable_properties ( ) const {
2020-05-05 10:25:48 +02:00
Vector < StringName > props = VisualShaderNodeUniform : : get_editable_properties ( ) ;
2020-02-25 15:50:49 +01:00
props . push_back ( " hint " ) ;
if ( hint = = HINT_RANGE | | hint = = HINT_RANGE_STEP ) {
props . push_back ( " min " ) ;
props . push_back ( " max " ) ;
}
if ( hint = = HINT_RANGE_STEP ) {
props . push_back ( " step " ) ;
}
2020-07-27 13:33:27 +02:00
props . push_back ( " default_value_enabled " ) ;
if ( default_value_enabled ) {
props . push_back ( " default_value " ) ;
}
2020-02-25 15:50:49 +01:00
return props ;
}
VisualShaderNodeIntUniform : : VisualShaderNodeIntUniform ( ) {
}
2019-02-22 18:38:58 +01:00
////////////// Boolean Uniform
String VisualShaderNodeBooleanUniform : : get_caption ( ) const {
return " BooleanUniform " ;
}
int VisualShaderNodeBooleanUniform : : get_input_port_count ( ) const {
return 0 ;
}
VisualShaderNodeBooleanUniform : : PortType VisualShaderNodeBooleanUniform : : get_input_port_type ( int p_port ) const {
return PORT_TYPE_BOOLEAN ;
}
String VisualShaderNodeBooleanUniform : : get_input_port_name ( int p_port ) const {
return String ( ) ;
}
int VisualShaderNodeBooleanUniform : : get_output_port_count ( ) const {
return 1 ;
}
VisualShaderNodeBooleanUniform : : PortType VisualShaderNodeBooleanUniform : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_BOOLEAN ;
}
String VisualShaderNodeBooleanUniform : : get_output_port_name ( int p_port ) const {
return " " ; //no output port means the editor will be used as port
}
2021-08-14 12:38:22 +02:00
void VisualShaderNodeBooleanUniform : : set_default_value_enabled ( bool p_default_value_enabled ) {
if ( default_value_enabled = = p_default_value_enabled ) {
return ;
}
default_value_enabled = p_default_value_enabled ;
2020-07-27 13:33:27 +02:00
emit_changed ( ) ;
}
bool VisualShaderNodeBooleanUniform : : is_default_value_enabled ( ) const {
return default_value_enabled ;
}
2021-08-14 12:38:22 +02:00
void VisualShaderNodeBooleanUniform : : set_default_value ( bool p_default_value ) {
if ( default_value = = p_default_value ) {
return ;
}
default_value = p_default_value ;
2020-07-27 13:33:27 +02:00
emit_changed ( ) ;
}
bool VisualShaderNodeBooleanUniform : : get_default_value ( ) const {
return default_value ;
}
2019-02-22 18:38:58 +01:00
String VisualShaderNodeBooleanUniform : : generate_global ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id ) const {
2020-07-27 13:33:27 +02:00
String code = _get_qual_str ( ) + " uniform bool " + get_uniform_name ( ) ;
if ( default_value_enabled ) {
if ( default_value ) {
code + = " = true " ;
} else {
code + = " = false " ;
}
}
code + = " ; \n " ;
return code ;
2019-02-22 18:38:58 +01:00
}
String VisualShaderNodeBooleanUniform : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = " + get_uniform_name ( ) + " ; \n " ;
2019-02-22 18:38:58 +01:00
}
2020-09-21 13:32:59 +02:00
bool VisualShaderNodeBooleanUniform : : is_show_prop_names ( ) const {
return true ;
}
bool VisualShaderNodeBooleanUniform : : is_use_prop_slots ( ) const {
return true ;
}
2020-07-27 13:33:27 +02:00
void VisualShaderNodeBooleanUniform : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_default_value_enabled " , " enabled " ) , & VisualShaderNodeBooleanUniform : : set_default_value_enabled ) ;
ClassDB : : bind_method ( D_METHOD ( " is_default_value_enabled " ) , & VisualShaderNodeBooleanUniform : : is_default_value_enabled ) ;
ClassDB : : bind_method ( D_METHOD ( " set_default_value " , " value " ) , & VisualShaderNodeBooleanUniform : : set_default_value ) ;
ClassDB : : bind_method ( D_METHOD ( " get_default_value " ) , & VisualShaderNodeBooleanUniform : : get_default_value ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " default_value_enabled " ) , " set_default_value_enabled " , " is_default_value_enabled " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " default_value " ) , " set_default_value " , " get_default_value " ) ;
}
2020-05-05 10:25:48 +02:00
bool VisualShaderNodeBooleanUniform : : is_qualifier_supported ( Qualifier p_qual ) const {
return true ; // all qualifiers are supported
}
2021-04-04 14:09:29 +02:00
bool VisualShaderNodeBooleanUniform : : is_convertible_to_constant ( ) const {
return true ; // conversion is allowed
}
2020-07-27 13:33:27 +02:00
Vector < StringName > VisualShaderNodeBooleanUniform : : get_editable_properties ( ) const {
Vector < StringName > props = VisualShaderNodeUniform : : get_editable_properties ( ) ;
props . push_back ( " default_value_enabled " ) ;
if ( default_value_enabled ) {
props . push_back ( " default_value " ) ;
}
return props ;
}
2019-02-22 18:38:58 +01:00
VisualShaderNodeBooleanUniform : : VisualShaderNodeBooleanUniform ( ) {
}
2018-07-14 23:15:42 +02:00
////////////// Color Uniform
String VisualShaderNodeColorUniform : : get_caption ( ) const {
return " ColorUniform " ;
}
int VisualShaderNodeColorUniform : : get_input_port_count ( ) const {
return 0 ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
VisualShaderNodeColorUniform : : PortType VisualShaderNodeColorUniform : : get_input_port_type ( int p_port ) const {
2022-05-07 07:40:19 +02:00
return PORT_TYPE_SCALAR ;
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
String VisualShaderNodeColorUniform : : get_input_port_name ( int p_port ) const {
return String ( ) ;
}
int VisualShaderNodeColorUniform : : get_output_port_count ( ) const {
2022-05-07 07:40:19 +02:00
return 1 ;
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
VisualShaderNodeColorUniform : : PortType VisualShaderNodeColorUniform : : get_output_port_type ( int p_port ) const {
2022-05-07 07:40:19 +02:00
return p_port = = 0 ? PORT_TYPE_VECTOR_4D : PORT_TYPE_SCALAR ;
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
String VisualShaderNodeColorUniform : : get_output_port_name ( int p_port ) const {
2022-05-07 07:40:19 +02:00
return " color " ;
}
bool VisualShaderNodeColorUniform : : is_output_port_expandable ( int p_port ) const {
if ( p_port = = 0 ) {
return true ;
}
return false ;
2018-07-14 23:15:42 +02:00
}
2020-07-27 13:33:27 +02:00
void VisualShaderNodeColorUniform : : set_default_value_enabled ( bool p_enabled ) {
2021-08-14 12:38:22 +02:00
if ( default_value_enabled = = p_enabled ) {
return ;
}
2020-07-27 13:33:27 +02:00
default_value_enabled = p_enabled ;
emit_changed ( ) ;
}
bool VisualShaderNodeColorUniform : : is_default_value_enabled ( ) const {
return default_value_enabled ;
}
void VisualShaderNodeColorUniform : : set_default_value ( const Color & p_value ) {
2021-08-14 12:38:22 +02:00
if ( default_value . is_equal_approx ( p_value ) ) {
return ;
}
2020-07-27 13:33:27 +02:00
default_value = p_value ;
emit_changed ( ) ;
}
Color VisualShaderNodeColorUniform : : get_default_value ( ) const {
return default_value ;
}
2018-07-14 23:15:42 +02:00
String VisualShaderNodeColorUniform : : generate_global ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id ) const {
2022-05-05 20:23:40 +02:00
String code = _get_qual_str ( ) + " uniform vec4 " + get_uniform_name ( ) + " : source_color " ;
2020-07-27 13:33:27 +02:00
if ( default_value_enabled ) {
code + = vformat ( " = vec4(%.6f, %.6f, %.6f, %.6f) " , default_value . r , default_value . g , default_value . b , default_value . a ) ;
}
code + = " ; \n " ;
return code ;
2018-07-14 23:15:42 +02:00
}
2019-01-21 20:07:53 +01:00
String VisualShaderNodeColorUniform : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2022-05-07 07:40:19 +02:00
return " " + p_output_vars [ 0 ] + " = " + get_uniform_name ( ) + " ; \n " ;
2018-07-14 23:15:42 +02:00
}
2020-09-21 13:32:59 +02:00
bool VisualShaderNodeColorUniform : : is_show_prop_names ( ) const {
return true ;
}
2020-07-27 13:33:27 +02:00
void VisualShaderNodeColorUniform : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_default_value_enabled " , " enabled " ) , & VisualShaderNodeColorUniform : : set_default_value_enabled ) ;
ClassDB : : bind_method ( D_METHOD ( " is_default_value_enabled " ) , & VisualShaderNodeColorUniform : : is_default_value_enabled ) ;
ClassDB : : bind_method ( D_METHOD ( " set_default_value " , " value " ) , & VisualShaderNodeColorUniform : : set_default_value ) ;
ClassDB : : bind_method ( D_METHOD ( " get_default_value " ) , & VisualShaderNodeColorUniform : : get_default_value ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " default_value_enabled " ) , " set_default_value_enabled " , " is_default_value_enabled " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : COLOR , " default_value " ) , " set_default_value " , " get_default_value " ) ;
}
2020-05-05 10:25:48 +02:00
bool VisualShaderNodeColorUniform : : is_qualifier_supported ( Qualifier p_qual ) const {
return true ; // all qualifiers are supported
}
2021-04-04 14:09:29 +02:00
bool VisualShaderNodeColorUniform : : is_convertible_to_constant ( ) const {
return true ; // conversion is allowed
}
2020-07-27 13:33:27 +02:00
Vector < StringName > VisualShaderNodeColorUniform : : get_editable_properties ( ) const {
Vector < StringName > props = VisualShaderNodeUniform : : get_editable_properties ( ) ;
props . push_back ( " default_value_enabled " ) ;
if ( default_value_enabled ) {
props . push_back ( " default_value " ) ;
}
return props ;
}
2018-07-14 23:15:42 +02:00
VisualShaderNodeColorUniform : : VisualShaderNodeColorUniform ( ) {
}
2022-02-01 09:32:01 +01:00
////////////// Vector2 Uniform
String VisualShaderNodeVec2Uniform : : get_caption ( ) const {
return " Vector2Uniform " ;
}
int VisualShaderNodeVec2Uniform : : get_input_port_count ( ) const {
return 0 ;
}
VisualShaderNodeVec2Uniform : : PortType VisualShaderNodeVec2Uniform : : get_input_port_type ( int p_port ) const {
return PORT_TYPE_VECTOR_2D ;
}
String VisualShaderNodeVec2Uniform : : get_input_port_name ( int p_port ) const {
return String ( ) ;
}
int VisualShaderNodeVec2Uniform : : get_output_port_count ( ) const {
return 1 ;
}
VisualShaderNodeVec2Uniform : : PortType VisualShaderNodeVec2Uniform : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_VECTOR_2D ;
}
String VisualShaderNodeVec2Uniform : : get_output_port_name ( int p_port ) const {
return String ( ) ;
}
void VisualShaderNodeVec2Uniform : : set_default_value_enabled ( bool p_enabled ) {
default_value_enabled = p_enabled ;
emit_changed ( ) ;
}
bool VisualShaderNodeVec2Uniform : : is_default_value_enabled ( ) const {
return default_value_enabled ;
}
void VisualShaderNodeVec2Uniform : : set_default_value ( const Vector2 & p_value ) {
default_value = p_value ;
emit_changed ( ) ;
}
Vector2 VisualShaderNodeVec2Uniform : : get_default_value ( ) const {
return default_value ;
}
String VisualShaderNodeVec2Uniform : : generate_global ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id ) const {
String code = _get_qual_str ( ) + " uniform vec2 " + get_uniform_name ( ) ;
if ( default_value_enabled ) {
code + = vformat ( " = vec2(%.6f, %.6f) " , default_value . x , default_value . y ) ;
}
code + = " ; \n " ;
return code ;
}
String VisualShaderNodeVec2Uniform : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
return " " + p_output_vars [ 0 ] + " = " + get_uniform_name ( ) + " ; \n " ;
}
void VisualShaderNodeVec2Uniform : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_default_value_enabled " , " enabled " ) , & VisualShaderNodeVec2Uniform : : set_default_value_enabled ) ;
ClassDB : : bind_method ( D_METHOD ( " is_default_value_enabled " ) , & VisualShaderNodeVec2Uniform : : is_default_value_enabled ) ;
ClassDB : : bind_method ( D_METHOD ( " set_default_value " , " value " ) , & VisualShaderNodeVec2Uniform : : set_default_value ) ;
ClassDB : : bind_method ( D_METHOD ( " get_default_value " ) , & VisualShaderNodeVec2Uniform : : get_default_value ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " default_value_enabled " ) , " set_default_value_enabled " , " is_default_value_enabled " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : VECTOR2 , " default_value " ) , " set_default_value " , " get_default_value " ) ;
}
bool VisualShaderNodeVec2Uniform : : is_show_prop_names ( ) const {
return true ;
}
bool VisualShaderNodeVec2Uniform : : is_use_prop_slots ( ) const {
return true ;
}
bool VisualShaderNodeVec2Uniform : : is_qualifier_supported ( Qualifier p_qual ) const {
return true ; // all qualifiers are supported
}
bool VisualShaderNodeVec2Uniform : : is_convertible_to_constant ( ) const {
return true ; // conversion is allowed
}
Vector < StringName > VisualShaderNodeVec2Uniform : : get_editable_properties ( ) const {
Vector < StringName > props = VisualShaderNodeUniform : : get_editable_properties ( ) ;
props . push_back ( " default_value_enabled " ) ;
if ( default_value_enabled ) {
props . push_back ( " default_value " ) ;
}
return props ;
}
VisualShaderNodeVec2Uniform : : VisualShaderNodeVec2Uniform ( ) {
}
////////////// Vector3 Uniform
2018-07-14 23:15:42 +02:00
String VisualShaderNodeVec3Uniform : : get_caption ( ) const {
2022-02-01 09:32:01 +01:00
return " Vector3Uniform " ;
2018-07-14 23:15:42 +02:00
}
int VisualShaderNodeVec3Uniform : : get_input_port_count ( ) const {
return 0 ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
VisualShaderNodeVec3Uniform : : PortType VisualShaderNodeVec3Uniform : : get_input_port_type ( int p_port ) const {
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
String VisualShaderNodeVec3Uniform : : get_input_port_name ( int p_port ) const {
return String ( ) ;
}
int VisualShaderNodeVec3Uniform : : get_output_port_count ( ) const {
return 1 ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
VisualShaderNodeVec3Uniform : : PortType VisualShaderNodeVec3Uniform : : get_output_port_type ( int p_port ) const {
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
String VisualShaderNodeVec3Uniform : : get_output_port_name ( int p_port ) const {
return " " ; //no output port means the editor will be used as port
}
2019-09-18 18:04:40 +02:00
2020-07-27 13:33:27 +02:00
void VisualShaderNodeVec3Uniform : : set_default_value_enabled ( bool p_enabled ) {
default_value_enabled = p_enabled ;
emit_changed ( ) ;
}
bool VisualShaderNodeVec3Uniform : : is_default_value_enabled ( ) const {
return default_value_enabled ;
}
void VisualShaderNodeVec3Uniform : : set_default_value ( const Vector3 & p_value ) {
default_value = p_value ;
emit_changed ( ) ;
}
Vector3 VisualShaderNodeVec3Uniform : : get_default_value ( ) const {
return default_value ;
}
2018-07-14 23:15:42 +02:00
String VisualShaderNodeVec3Uniform : : generate_global ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id ) const {
2020-07-27 13:33:27 +02:00
String code = _get_qual_str ( ) + " uniform vec3 " + get_uniform_name ( ) ;
if ( default_value_enabled ) {
code + = vformat ( " = vec3(%.6f, %.6f, %.6f) " , default_value . x , default_value . y , default_value . z ) ;
}
code + = " ; \n " ;
return code ;
2018-07-14 23:15:42 +02:00
}
2019-01-21 20:07:53 +01:00
String VisualShaderNodeVec3Uniform : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = " + get_uniform_name ( ) + " ; \n " ;
2018-07-14 23:15:42 +02:00
}
2020-07-27 13:33:27 +02:00
void VisualShaderNodeVec3Uniform : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_default_value_enabled " , " enabled " ) , & VisualShaderNodeVec3Uniform : : set_default_value_enabled ) ;
ClassDB : : bind_method ( D_METHOD ( " is_default_value_enabled " ) , & VisualShaderNodeVec3Uniform : : is_default_value_enabled ) ;
ClassDB : : bind_method ( D_METHOD ( " set_default_value " , " value " ) , & VisualShaderNodeVec3Uniform : : set_default_value ) ;
ClassDB : : bind_method ( D_METHOD ( " get_default_value " ) , & VisualShaderNodeVec3Uniform : : get_default_value ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " default_value_enabled " ) , " set_default_value_enabled " , " is_default_value_enabled " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : VECTOR3 , " default_value " ) , " set_default_value " , " get_default_value " ) ;
}
2020-09-21 13:32:59 +02:00
bool VisualShaderNodeVec3Uniform : : is_show_prop_names ( ) const {
return true ;
}
bool VisualShaderNodeVec3Uniform : : is_use_prop_slots ( ) const {
return true ;
}
2020-05-05 10:25:48 +02:00
bool VisualShaderNodeVec3Uniform : : is_qualifier_supported ( Qualifier p_qual ) const {
return true ; // all qualifiers are supported
}
2021-04-04 14:09:29 +02:00
bool VisualShaderNodeVec3Uniform : : is_convertible_to_constant ( ) const {
return true ; // conversion is allowed
}
2020-07-27 13:33:27 +02:00
Vector < StringName > VisualShaderNodeVec3Uniform : : get_editable_properties ( ) const {
Vector < StringName > props = VisualShaderNodeUniform : : get_editable_properties ( ) ;
props . push_back ( " default_value_enabled " ) ;
if ( default_value_enabled ) {
props . push_back ( " default_value " ) ;
}
return props ;
}
2018-07-14 23:15:42 +02:00
VisualShaderNodeVec3Uniform : : VisualShaderNodeVec3Uniform ( ) {
}
2022-04-12 19:09:29 +02:00
////////////// Vector4 Uniform
String VisualShaderNodeVec4Uniform : : get_caption ( ) const {
return " Vector4Uniform " ;
}
int VisualShaderNodeVec4Uniform : : get_input_port_count ( ) const {
return 0 ;
}
VisualShaderNodeVec4Uniform : : PortType VisualShaderNodeVec4Uniform : : get_input_port_type ( int p_port ) const {
return PORT_TYPE_VECTOR_4D ;
}
String VisualShaderNodeVec4Uniform : : get_input_port_name ( int p_port ) const {
return String ( ) ;
}
int VisualShaderNodeVec4Uniform : : get_output_port_count ( ) const {
return 1 ;
}
VisualShaderNodeVec4Uniform : : PortType VisualShaderNodeVec4Uniform : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_VECTOR_4D ;
}
String VisualShaderNodeVec4Uniform : : get_output_port_name ( int p_port ) const {
return " " ; // No output port means the editor will be used as port.
}
void VisualShaderNodeVec4Uniform : : set_default_value_enabled ( bool p_enabled ) {
default_value_enabled = p_enabled ;
emit_changed ( ) ;
}
bool VisualShaderNodeVec4Uniform : : is_default_value_enabled ( ) const {
return default_value_enabled ;
}
void VisualShaderNodeVec4Uniform : : set_default_value ( const Quaternion & p_value ) {
default_value = p_value ;
emit_changed ( ) ;
}
Quaternion VisualShaderNodeVec4Uniform : : get_default_value ( ) const {
return default_value ;
}
String VisualShaderNodeVec4Uniform : : generate_global ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id ) const {
String code = _get_qual_str ( ) + " uniform vec4 " + get_uniform_name ( ) ;
if ( default_value_enabled ) {
code + = vformat ( " = vec4(%.6f, %.6f, %.6f, %.6f) " , default_value . x , default_value . y , default_value . z , default_value . w ) ;
}
code + = " ; \n " ;
return code ;
}
String VisualShaderNodeVec4Uniform : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
return " " + p_output_vars [ 0 ] + " = " + get_uniform_name ( ) + " ; \n " ;
}
void VisualShaderNodeVec4Uniform : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_default_value_enabled " , " enabled " ) , & VisualShaderNodeVec4Uniform : : set_default_value_enabled ) ;
ClassDB : : bind_method ( D_METHOD ( " is_default_value_enabled " ) , & VisualShaderNodeVec4Uniform : : is_default_value_enabled ) ;
ClassDB : : bind_method ( D_METHOD ( " set_default_value " , " value " ) , & VisualShaderNodeVec4Uniform : : set_default_value ) ;
ClassDB : : bind_method ( D_METHOD ( " get_default_value " ) , & VisualShaderNodeVec4Uniform : : get_default_value ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " default_value_enabled " ) , " set_default_value_enabled " , " is_default_value_enabled " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : QUATERNION , " default_value " ) , " set_default_value " , " get_default_value " ) ;
}
bool VisualShaderNodeVec4Uniform : : is_show_prop_names ( ) const {
return true ;
}
bool VisualShaderNodeVec4Uniform : : is_use_prop_slots ( ) const {
return true ;
}
bool VisualShaderNodeVec4Uniform : : is_qualifier_supported ( Qualifier p_qual ) const {
return true ; // All qualifiers are supported.
}
bool VisualShaderNodeVec4Uniform : : is_convertible_to_constant ( ) const {
return true ; // Conversion is allowed.
}
Vector < StringName > VisualShaderNodeVec4Uniform : : get_editable_properties ( ) const {
Vector < StringName > props = VisualShaderNodeUniform : : get_editable_properties ( ) ;
props . push_back ( " default_value_enabled " ) ;
if ( default_value_enabled ) {
props . push_back ( " default_value " ) ;
}
return props ;
}
VisualShaderNodeVec4Uniform : : VisualShaderNodeVec4Uniform ( ) {
}
2018-07-14 23:15:42 +02:00
////////////// Transform Uniform
String VisualShaderNodeTransformUniform : : get_caption ( ) const {
2018-07-15 16:28:06 +02:00
return " TransformUniform " ;
2018-07-14 23:15:42 +02:00
}
int VisualShaderNodeTransformUniform : : get_input_port_count ( ) const {
return 0 ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
VisualShaderNodeTransformUniform : : PortType VisualShaderNodeTransformUniform : : get_input_port_type ( int p_port ) const {
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
String VisualShaderNodeTransformUniform : : get_input_port_name ( int p_port ) const {
return String ( ) ;
}
int VisualShaderNodeTransformUniform : : get_output_port_count ( ) const {
return 1 ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
VisualShaderNodeTransformUniform : : PortType VisualShaderNodeTransformUniform : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_TRANSFORM ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
String VisualShaderNodeTransformUniform : : get_output_port_name ( int p_port ) const {
return " " ; //no output port means the editor will be used as port
}
2019-09-18 18:04:40 +02:00
2020-07-27 13:33:27 +02:00
void VisualShaderNodeTransformUniform : : set_default_value_enabled ( bool p_enabled ) {
default_value_enabled = p_enabled ;
emit_changed ( ) ;
}
bool VisualShaderNodeTransformUniform : : is_default_value_enabled ( ) const {
return default_value_enabled ;
}
2020-10-17 07:08:21 +02:00
void VisualShaderNodeTransformUniform : : set_default_value ( const Transform3D & p_value ) {
2020-07-27 13:33:27 +02:00
default_value = p_value ;
emit_changed ( ) ;
}
2020-10-17 07:08:21 +02:00
Transform3D VisualShaderNodeTransformUniform : : get_default_value ( ) const {
2020-07-27 13:33:27 +02:00
return default_value ;
}
2018-07-14 23:15:42 +02:00
String VisualShaderNodeTransformUniform : : generate_global ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id ) const {
2020-07-27 13:33:27 +02:00
String code = _get_qual_str ( ) + " uniform mat4 " + get_uniform_name ( ) ;
if ( default_value_enabled ) {
2022-05-03 14:50:35 +02:00
Vector3 row0 = default_value . basis . rows [ 0 ] ;
Vector3 row1 = default_value . basis . rows [ 1 ] ;
Vector3 row2 = default_value . basis . rows [ 2 ] ;
2020-07-27 13:33:27 +02:00
Vector3 origin = default_value . origin ;
code + = " = mat4( " + vformat ( " vec4(%.6f, %.6f, %.6f, 0.0) " , row0 . x , row0 . y , row0 . z ) + vformat ( " , vec4(%.6f, %.6f, %.6f, 0.0) " , row1 . x , row1 . y , row1 . z ) + vformat ( " , vec4(%.6f, %.6f, %.6f, 0.0) " , row2 . x , row2 . y , row2 . z ) + vformat ( " , vec4(%.6f, %.6f, %.6f, 1.0) " , origin . x , origin . y , origin . z ) + " ) " ;
}
code + = " ; \n " ;
return code ;
2018-07-14 23:15:42 +02:00
}
2019-01-21 20:07:53 +01:00
String VisualShaderNodeTransformUniform : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = " + get_uniform_name ( ) + " ; \n " ;
2018-07-14 23:15:42 +02:00
}
2020-07-27 13:33:27 +02:00
void VisualShaderNodeTransformUniform : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_default_value_enabled " , " enabled " ) , & VisualShaderNodeTransformUniform : : set_default_value_enabled ) ;
ClassDB : : bind_method ( D_METHOD ( " is_default_value_enabled " ) , & VisualShaderNodeTransformUniform : : is_default_value_enabled ) ;
ClassDB : : bind_method ( D_METHOD ( " set_default_value " , " value " ) , & VisualShaderNodeTransformUniform : : set_default_value ) ;
ClassDB : : bind_method ( D_METHOD ( " get_default_value " ) , & VisualShaderNodeTransformUniform : : get_default_value ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " default_value_enabled " ) , " set_default_value_enabled " , " is_default_value_enabled " ) ;
2021-04-28 09:36:08 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : TRANSFORM3D , " default_value " ) , " set_default_value " , " get_default_value " ) ;
2020-07-27 13:33:27 +02:00
}
2020-09-21 13:32:59 +02:00
bool VisualShaderNodeTransformUniform : : is_show_prop_names ( ) const {
return true ;
}
bool VisualShaderNodeTransformUniform : : is_use_prop_slots ( ) const {
return true ;
}
2020-05-05 10:25:48 +02:00
bool VisualShaderNodeTransformUniform : : is_qualifier_supported ( Qualifier p_qual ) const {
2021-08-12 15:55:14 +02:00
if ( p_qual = = Qualifier : : QUAL_INSTANCE ) {
return false ;
}
return true ;
2020-05-05 10:25:48 +02:00
}
2021-04-04 14:09:29 +02:00
bool VisualShaderNodeTransformUniform : : is_convertible_to_constant ( ) const {
return true ; // conversion is allowed
}
2020-07-27 13:33:27 +02:00
Vector < StringName > VisualShaderNodeTransformUniform : : get_editable_properties ( ) const {
Vector < StringName > props = VisualShaderNodeUniform : : get_editable_properties ( ) ;
props . push_back ( " default_value_enabled " ) ;
if ( default_value_enabled ) {
props . push_back ( " default_value " ) ;
}
return props ;
}
2018-07-14 23:15:42 +02:00
VisualShaderNodeTransformUniform : : VisualShaderNodeTransformUniform ( ) {
}
2022-05-05 20:23:40 +02:00
//////////////
2018-07-14 23:15:42 +02:00
2022-05-05 20:23:40 +02:00
String get_sampler_hint ( VisualShaderNodeTextureUniform : : TextureType p_texture_type , VisualShaderNodeTextureUniform : : ColorDefault p_color_default , VisualShaderNodeTextureUniform : : TextureFilter p_texture_filter , VisualShaderNodeTextureUniform : : TextureRepeat p_texture_repeat ) {
String code ;
2021-12-16 09:41:29 +01:00
bool has_colon = false ;
2018-07-14 23:15:42 +02:00
2021-12-16 09:41:29 +01:00
// type
{
String type_code ;
2022-05-05 20:23:40 +02:00
switch ( p_texture_type ) {
case VisualShaderNodeTextureUniform : : TYPE_DATA :
if ( p_color_default = = VisualShaderNodeTextureUniform : : COLOR_DEFAULT_BLACK ) {
type_code = " hint_default_black " ;
2021-08-14 18:29:52 +02:00
} else if ( p_color_default = = VisualShaderNodeTextureUniform : : COLOR_DEFAULT_TRANSPARENT ) {
type_code = " hint_default_transparent " ;
2021-12-16 09:41:29 +01:00
}
break ;
2022-05-05 20:23:40 +02:00
case VisualShaderNodeTextureUniform : : TYPE_COLOR :
type_code = " source_color " ;
if ( p_color_default = = VisualShaderNodeTextureUniform : : COLOR_DEFAULT_BLACK ) {
type_code + = " , hint_default_black " ;
2021-08-14 18:29:52 +02:00
} else if ( p_color_default = = VisualShaderNodeTextureUniform : : COLOR_DEFAULT_TRANSPARENT ) {
type_code + = " , hint_default_transparent " ;
2021-12-16 09:41:29 +01:00
}
break ;
2022-05-05 20:23:40 +02:00
case VisualShaderNodeTextureUniform : : TYPE_NORMAL_MAP :
2021-12-16 09:41:29 +01:00
type_code = " hint_normal " ;
break ;
2022-05-05 20:23:40 +02:00
case VisualShaderNodeTextureUniform : : TYPE_ANISOTROPY :
2021-12-16 09:41:29 +01:00
type_code = " hint_anisotropy " ;
break ;
default :
break ;
}
if ( ! type_code . is_empty ( ) ) {
code + = " : " + type_code ;
has_colon = true ;
}
}
// filter
{
String filter_code ;
2022-05-05 20:23:40 +02:00
switch ( p_texture_filter ) {
case VisualShaderNodeTextureUniform : : FILTER_NEAREST :
2021-12-16 09:41:29 +01:00
filter_code = " filter_nearest " ;
break ;
2022-05-05 20:23:40 +02:00
case VisualShaderNodeTextureUniform : : FILTER_LINEAR :
2021-12-16 09:41:29 +01:00
filter_code = " filter_linear " ;
break ;
2022-05-05 20:23:40 +02:00
case VisualShaderNodeTextureUniform : : FILTER_NEAREST_MIPMAP :
2021-12-16 09:41:29 +01:00
filter_code = " filter_nearest_mipmap " ;
break ;
2022-05-05 20:23:40 +02:00
case VisualShaderNodeTextureUniform : : FILTER_LINEAR_MIPMAP :
2021-12-16 09:41:29 +01:00
filter_code = " filter_linear_mipmap " ;
break ;
2022-05-05 20:23:40 +02:00
case VisualShaderNodeTextureUniform : : FILTER_NEAREST_MIPMAP_ANISOTROPIC :
2021-12-16 09:41:29 +01:00
filter_code = " filter_nearest_mipmap_anisotropic " ;
break ;
2022-05-05 20:23:40 +02:00
case VisualShaderNodeTextureUniform : : FILTER_LINEAR_MIPMAP_ANISOTROPIC :
2021-12-16 09:41:29 +01:00
filter_code = " filter_linear_mipmap_anisotropic " ;
break ;
default :
break ;
}
if ( ! filter_code . is_empty ( ) ) {
if ( ! has_colon ) {
code + = " : " ;
has_colon = true ;
2020-05-14 16:41:43 +02:00
} else {
2021-12-16 09:41:29 +01:00
code + = " , " ;
2020-05-14 16:41:43 +02:00
}
2021-12-16 09:41:29 +01:00
code + = filter_code ;
}
}
// repeat
{
String repeat_code ;
2022-05-05 20:23:40 +02:00
switch ( p_texture_repeat ) {
case VisualShaderNodeTextureUniform : : REPEAT_ENABLED :
2021-12-16 09:41:29 +01:00
repeat_code = " repeat_enable " ;
break ;
2022-05-05 20:23:40 +02:00
case VisualShaderNodeTextureUniform : : REPEAT_DISABLED :
2021-12-16 09:41:29 +01:00
repeat_code = " repeat_disable " ;
break ;
default :
break ;
}
if ( ! repeat_code . is_empty ( ) ) {
if ( ! has_colon ) {
code + = " : " ;
2020-05-14 16:41:43 +02:00
} else {
2021-12-16 09:41:29 +01:00
code + = " , " ;
2020-05-14 16:41:43 +02:00
}
2021-12-16 09:41:29 +01:00
code + = repeat_code ;
}
2018-07-14 23:15:42 +02:00
}
2022-05-05 20:23:40 +02:00
return code ;
}
////////////// Texture Uniform
String VisualShaderNodeTextureUniform : : get_caption ( ) const {
return " TextureUniform " ;
}
int VisualShaderNodeTextureUniform : : get_input_port_count ( ) const {
return 0 ;
}
VisualShaderNodeTextureUniform : : PortType VisualShaderNodeTextureUniform : : get_input_port_type ( int p_port ) const {
return PORT_TYPE_SCALAR ;
}
String VisualShaderNodeTextureUniform : : get_input_port_name ( int p_port ) const {
return " " ;
}
int VisualShaderNodeTextureUniform : : get_output_port_count ( ) const {
return 1 ;
}
VisualShaderNodeTextureUniform : : PortType VisualShaderNodeTextureUniform : : get_output_port_type ( int p_port ) const {
switch ( p_port ) {
case 0 :
return PORT_TYPE_SAMPLER ;
default :
return PORT_TYPE_SCALAR ;
}
}
String VisualShaderNodeTextureUniform : : get_output_port_name ( int p_port ) const {
switch ( p_port ) {
case 0 :
return " sampler2D " ;
default :
return " " ;
}
}
String VisualShaderNodeTextureUniform : : generate_global ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id ) const {
String code = _get_qual_str ( ) + " uniform sampler2D " + get_uniform_name ( ) ;
code + = get_sampler_hint ( texture_type , color_default , texture_filter , texture_repeat ) ;
2021-12-16 09:41:29 +01:00
code + = " ; \n " ;
2018-07-14 23:15:42 +02:00
return code ;
}
2019-01-21 20:07:53 +01:00
String VisualShaderNodeTextureUniform : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2022-04-22 19:31:23 +02:00
return " " ;
2018-07-14 23:15:42 +02:00
}
2021-08-14 12:38:22 +02:00
void VisualShaderNodeTextureUniform : : set_texture_type ( TextureType p_texture_type ) {
ERR_FAIL_INDEX ( int ( p_texture_type ) , int ( TYPE_MAX ) ) ;
if ( texture_type = = p_texture_type ) {
return ;
}
texture_type = p_texture_type ;
2018-07-14 23:15:42 +02:00
emit_changed ( ) ;
}
VisualShaderNodeTextureUniform : : TextureType VisualShaderNodeTextureUniform : : get_texture_type ( ) const {
return texture_type ;
}
2021-08-14 12:38:22 +02:00
void VisualShaderNodeTextureUniform : : set_color_default ( ColorDefault p_color_default ) {
ERR_FAIL_INDEX ( int ( p_color_default ) , int ( COLOR_DEFAULT_MAX ) ) ;
if ( color_default = = p_color_default ) {
return ;
}
color_default = p_color_default ;
2018-07-14 23:15:42 +02:00
emit_changed ( ) ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
VisualShaderNodeTextureUniform : : ColorDefault VisualShaderNodeTextureUniform : : get_color_default ( ) const {
return color_default ;
}
2021-12-16 09:41:29 +01:00
void VisualShaderNodeTextureUniform : : set_texture_filter ( TextureFilter p_filter ) {
ERR_FAIL_INDEX ( int ( p_filter ) , int ( FILTER_MAX ) ) ;
if ( texture_filter = = p_filter ) {
return ;
}
texture_filter = p_filter ;
emit_changed ( ) ;
}
VisualShaderNodeTextureUniform : : TextureFilter VisualShaderNodeTextureUniform : : get_texture_filter ( ) const {
return texture_filter ;
}
void VisualShaderNodeTextureUniform : : set_texture_repeat ( TextureRepeat p_repeat ) {
ERR_FAIL_INDEX ( int ( p_repeat ) , int ( REPEAT_MAX ) ) ;
if ( texture_repeat = = p_repeat ) {
return ;
}
texture_repeat = p_repeat ;
emit_changed ( ) ;
}
VisualShaderNodeTextureUniform : : TextureRepeat VisualShaderNodeTextureUniform : : get_texture_repeat ( ) const {
return texture_repeat ;
}
2018-07-14 23:15:42 +02:00
Vector < StringName > VisualShaderNodeTextureUniform : : get_editable_properties ( ) const {
2020-05-05 10:25:48 +02:00
Vector < StringName > props = VisualShaderNodeUniform : : get_editable_properties ( ) ;
2018-07-14 23:15:42 +02:00
props . push_back ( " texture_type " ) ;
2021-12-16 09:41:29 +01:00
if ( texture_type = = TYPE_DATA | | texture_type = = TYPE_COLOR ) {
props . push_back ( " color_default " ) ;
}
props . push_back ( " texture_filter " ) ;
props . push_back ( " texture_repeat " ) ;
2018-07-14 23:15:42 +02:00
return props ;
}
2021-12-16 09:41:29 +01:00
bool VisualShaderNodeTextureUniform : : is_show_prop_names ( ) const {
return true ;
}
2022-05-13 15:04:37 +02:00
HashMap < StringName , String > VisualShaderNodeTextureUniform : : get_editable_properties_names ( ) const {
HashMap < StringName , String > names ;
2022-03-28 15:24:14 +02:00
names . insert ( " texture_type " , RTR ( " Type " ) ) ;
names . insert ( " color_default " , RTR ( " Default Color " ) ) ;
names . insert ( " texture_filter " , RTR ( " Filter " ) ) ;
names . insert ( " texture_repeat " , RTR ( " Repeat " ) ) ;
2021-12-16 09:41:29 +01:00
return names ;
}
2018-07-14 23:15:42 +02:00
void VisualShaderNodeTextureUniform : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_texture_type " , " type " ) , & VisualShaderNodeTextureUniform : : set_texture_type ) ;
ClassDB : : bind_method ( D_METHOD ( " get_texture_type " ) , & VisualShaderNodeTextureUniform : : get_texture_type ) ;
ClassDB : : bind_method ( D_METHOD ( " set_color_default " , " type " ) , & VisualShaderNodeTextureUniform : : set_color_default ) ;
ClassDB : : bind_method ( D_METHOD ( " get_color_default " ) , & VisualShaderNodeTextureUniform : : get_color_default ) ;
2021-12-16 09:41:29 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_texture_filter " , " filter " ) , & VisualShaderNodeTextureUniform : : set_texture_filter ) ;
ClassDB : : bind_method ( D_METHOD ( " get_texture_filter " ) , & VisualShaderNodeTextureUniform : : get_texture_filter ) ;
ClassDB : : bind_method ( D_METHOD ( " set_texture_repeat " , " type " ) , & VisualShaderNodeTextureUniform : : set_texture_repeat ) ;
ClassDB : : bind_method ( D_METHOD ( " get_texture_repeat " ) , & VisualShaderNodeTextureUniform : : get_texture_repeat ) ;
2021-05-22 04:30:58 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " texture_type " , PROPERTY_HINT_ENUM , " Data,Color,Normal Map,Anisotropic " ) , " set_texture_type " , " get_texture_type " ) ;
2021-08-14 18:29:52 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " color_default " , PROPERTY_HINT_ENUM , " White,Black,Transparent " ) , " set_color_default " , " get_color_default " ) ;
2021-12-16 09:41:29 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " texture_filter " , PROPERTY_HINT_ENUM , " Default,Nearest,Linear,Nearest Mipmap,Linear Mipmap,Nearest Mipmap Anisotropic,Linear Mipmap Anisotropic " ) , " set_texture_filter " , " get_texture_filter " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " texture_repeat " , PROPERTY_HINT_ENUM , " Default,Enabled,Disabled " ) , " set_texture_repeat " , " get_texture_repeat " ) ;
2018-07-14 23:15:42 +02:00
BIND_ENUM_CONSTANT ( TYPE_DATA ) ;
BIND_ENUM_CONSTANT ( TYPE_COLOR ) ;
2020-12-23 10:34:26 +01:00
BIND_ENUM_CONSTANT ( TYPE_NORMAL_MAP ) ;
2021-12-09 20:29:06 +01:00
BIND_ENUM_CONSTANT ( TYPE_ANISOTROPY ) ;
2021-08-14 12:38:22 +02:00
BIND_ENUM_CONSTANT ( TYPE_MAX ) ;
2018-07-14 23:15:42 +02:00
BIND_ENUM_CONSTANT ( COLOR_DEFAULT_WHITE ) ;
BIND_ENUM_CONSTANT ( COLOR_DEFAULT_BLACK ) ;
2021-08-14 18:29:52 +02:00
BIND_ENUM_CONSTANT ( COLOR_DEFAULT_TRANSPARENT ) ;
2021-08-14 12:38:22 +02:00
BIND_ENUM_CONSTANT ( COLOR_DEFAULT_MAX ) ;
2021-12-16 09:41:29 +01:00
BIND_ENUM_CONSTANT ( FILTER_DEFAULT ) ;
BIND_ENUM_CONSTANT ( FILTER_NEAREST ) ;
BIND_ENUM_CONSTANT ( FILTER_LINEAR ) ;
BIND_ENUM_CONSTANT ( FILTER_NEAREST_MIPMAP ) ;
BIND_ENUM_CONSTANT ( FILTER_LINEAR_MIPMAP ) ;
BIND_ENUM_CONSTANT ( FILTER_NEAREST_MIPMAP_ANISOTROPIC ) ;
BIND_ENUM_CONSTANT ( FILTER_LINEAR_MIPMAP_ANISOTROPIC ) ;
BIND_ENUM_CONSTANT ( FILTER_MAX ) ;
BIND_ENUM_CONSTANT ( REPEAT_DEFAULT ) ;
BIND_ENUM_CONSTANT ( REPEAT_ENABLED ) ;
BIND_ENUM_CONSTANT ( REPEAT_DISABLED ) ;
BIND_ENUM_CONSTANT ( REPEAT_MAX ) ;
2018-07-14 23:15:42 +02:00
}
2020-05-05 10:25:48 +02:00
bool VisualShaderNodeTextureUniform : : is_qualifier_supported ( Qualifier p_qual ) const {
switch ( p_qual ) {
case Qualifier : : QUAL_NONE :
return true ;
case Qualifier : : QUAL_GLOBAL :
return true ;
case Qualifier : : QUAL_INSTANCE :
return false ;
2021-08-14 12:38:22 +02:00
default :
break ;
2020-05-05 10:25:48 +02:00
}
return false ;
}
2021-04-04 14:09:29 +02:00
bool VisualShaderNodeTextureUniform : : is_convertible_to_constant ( ) const {
return false ; // conversion is not allowed
}
2018-07-14 23:15:42 +02:00
VisualShaderNodeTextureUniform : : VisualShaderNodeTextureUniform ( ) {
}
2019-07-12 11:14:34 +02:00
////////////// Texture Uniform (Triplanar)
String VisualShaderNodeTextureUniformTriplanar : : get_caption ( ) const {
return " TextureUniformTriplanar " ;
}
int VisualShaderNodeTextureUniformTriplanar : : get_input_port_count ( ) const {
return 2 ;
}
2022-04-22 19:31:23 +02:00
VisualShaderNodeTextureUniformTriplanar : : PortType VisualShaderNodeTextureUniformTriplanar : : get_input_port_type ( int p_port ) const {
2021-03-01 06:03:49 +01:00
if ( p_port = = 0 | | p_port = = 1 ) {
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2019-07-12 11:14:34 +02:00
}
return PORT_TYPE_SCALAR ;
}
String VisualShaderNodeTextureUniformTriplanar : : get_input_port_name ( int p_port ) const {
if ( p_port = = 0 ) {
return " weights " ;
} else if ( p_port = = 1 ) {
return " pos " ;
}
return " " ;
}
2022-04-22 19:31:23 +02:00
int VisualShaderNodeTextureUniformTriplanar : : get_output_port_count ( ) const {
return 2 ;
}
VisualShaderNodeTextureUniformTriplanar : : PortType VisualShaderNodeTextureUniformTriplanar : : get_output_port_type ( int p_port ) const {
switch ( p_port ) {
case 0 :
return PORT_TYPE_VECTOR_4D ;
case 1 :
return PORT_TYPE_SAMPLER ;
default :
return PORT_TYPE_SCALAR ;
}
}
String VisualShaderNodeTextureUniformTriplanar : : get_output_port_name ( int p_port ) const {
switch ( p_port ) {
case 0 :
return " color " ;
case 1 :
return " sampler2D " ;
default :
return " " ;
}
}
2022-02-07 06:46:51 +01:00
String VisualShaderNodeTextureUniformTriplanar : : generate_global_per_node ( Shader : : Mode p_mode , int p_id ) const {
2019-07-12 11:14:34 +02:00
String code ;
2022-02-07 20:58:37 +01:00
code + = " // " + get_caption ( ) + " \n " ;
2021-07-19 08:06:51 +02:00
code + = " vec4 triplanar_texture(sampler2D p_sampler, vec3 p_weights, vec3 p_triplanar_pos) { \n " ;
code + = " vec4 samp = vec4(0.0); \n " ;
code + = " samp += texture(p_sampler, p_triplanar_pos.xy) * p_weights.z; \n " ;
code + = " samp += texture(p_sampler, p_triplanar_pos.xz) * p_weights.y; \n " ;
code + = " samp += texture(p_sampler, p_triplanar_pos.zy * vec2(-1.0, 1.0)) * p_weights.x; \n " ;
code + = " return samp; \n " ;
code + = " } \n " ;
2019-07-12 11:14:34 +02:00
code + = " \n " ;
2021-07-19 08:06:51 +02:00
code + = " uniform vec3 triplanar_scale = vec3(1.0, 1.0, 1.0); \n " ;
code + = " uniform vec3 triplanar_offset; \n " ;
code + = " uniform float triplanar_sharpness = 0.5; \n " ;
2019-07-12 11:14:34 +02:00
code + = " \n " ;
2021-07-19 08:06:51 +02:00
code + = " varying vec3 triplanar_power_normal; \n " ;
code + = " varying vec3 triplanar_pos; \n " ;
2019-07-12 11:14:34 +02:00
return code ;
}
String VisualShaderNodeTextureUniformTriplanar : : generate_global_per_func ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id ) const {
String code ;
if ( p_type = = VisualShader : : TYPE_VERTEX ) {
2022-02-07 20:58:37 +01:00
code + = " // " + get_caption ( ) + " \n " ;
code + = " { \n " ;
2021-07-19 08:06:51 +02:00
code + = " triplanar_power_normal = pow(abs(NORMAL), vec3(triplanar_sharpness)); \n " ;
code + = " triplanar_power_normal /= dot(triplanar_power_normal, vec3(1.0)); \n " ;
code + = " triplanar_pos = VERTEX * triplanar_scale + triplanar_offset; \n " ;
code + = " triplanar_pos *= vec3(1.0, -1.0, 1.0); \n " ;
2022-02-07 20:58:37 +01:00
code + = " } \n " ;
2019-07-12 11:14:34 +02:00
}
return code ;
}
String VisualShaderNodeTextureUniformTriplanar : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
String id = get_uniform_name ( ) ;
2022-04-22 19:31:23 +02:00
String code ;
2021-12-09 10:42:46 +01:00
if ( p_input_vars [ 0 ] . is_empty ( ) & & p_input_vars [ 1 ] . is_empty ( ) ) {
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = triplanar_texture( " + id + " , triplanar_power_normal, triplanar_pos); \n " ;
2021-12-09 10:42:46 +01:00
} else if ( ! p_input_vars [ 0 ] . is_empty ( ) & & p_input_vars [ 1 ] . is_empty ( ) ) {
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = triplanar_texture( " + id + " , " + p_input_vars [ 0 ] + " , triplanar_pos); \n " ;
2021-12-09 10:42:46 +01:00
} else if ( p_input_vars [ 0 ] . is_empty ( ) & & ! p_input_vars [ 1 ] . is_empty ( ) ) {
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = triplanar_texture( " + id + " , triplanar_power_normal, " + p_input_vars [ 1 ] + " ); \n " ;
2019-07-12 11:14:34 +02:00
} else {
2022-04-22 19:31:23 +02:00
code + = " " + p_output_vars [ 0 ] + " = triplanar_texture( " + id + " , " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
2019-07-12 11:14:34 +02:00
}
return code ;
}
2022-01-22 09:09:16 +01:00
bool VisualShaderNodeTextureUniformTriplanar : : is_input_port_default ( int p_port , Shader : : Mode p_mode ) const {
2019-10-03 09:40:26 +02:00
if ( p_port = = 0 ) {
2022-01-22 09:09:16 +01:00
return true ;
2019-10-03 09:40:26 +02:00
} else if ( p_port = = 1 ) {
2022-01-22 09:09:16 +01:00
return true ;
2019-10-03 09:40:26 +02:00
}
2022-01-22 09:09:16 +01:00
return false ;
2019-10-03 09:40:26 +02:00
}
2019-07-12 11:14:34 +02:00
VisualShaderNodeTextureUniformTriplanar : : VisualShaderNodeTextureUniformTriplanar ( ) {
}
2020-02-18 12:45:23 +01:00
////////////// Texture2DArray Uniform
String VisualShaderNodeTexture2DArrayUniform : : get_caption ( ) const {
return " Texture2DArrayUniform " ;
}
String VisualShaderNodeTexture2DArrayUniform : : get_output_port_name ( int p_port ) const {
return " sampler2DArray " ;
}
String VisualShaderNodeTexture2DArrayUniform : : generate_global ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id ) const {
String code = _get_qual_str ( ) + " uniform sampler2DArray " + get_uniform_name ( ) ;
2022-05-05 20:23:40 +02:00
code + = get_sampler_hint ( texture_type , color_default , texture_filter , texture_repeat ) ;
code + = " ; \n " ;
2020-02-18 12:45:23 +01:00
return code ;
}
String VisualShaderNodeTexture2DArrayUniform : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
return String ( ) ;
}
VisualShaderNodeTexture2DArrayUniform : : VisualShaderNodeTexture2DArrayUniform ( ) {
}
2020-09-10 05:47:09 +02:00
////////////// Texture3D Uniform
String VisualShaderNodeTexture3DUniform : : get_caption ( ) const {
return " Texture3DUniform " ;
}
String VisualShaderNodeTexture3DUniform : : get_output_port_name ( int p_port ) const {
return " sampler3D " ;
}
String VisualShaderNodeTexture3DUniform : : generate_global ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id ) const {
String code = _get_qual_str ( ) + " uniform sampler3D " + get_uniform_name ( ) ;
2022-05-05 20:23:40 +02:00
code + = get_sampler_hint ( texture_type , color_default , texture_filter , texture_repeat ) ;
code + = " ; \n " ;
2020-09-10 05:47:09 +02:00
return code ;
}
String VisualShaderNodeTexture3DUniform : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
return String ( ) ;
}
VisualShaderNodeTexture3DUniform : : VisualShaderNodeTexture3DUniform ( ) {
}
2019-06-11 20:43:37 +02:00
////////////// Cubemap Uniform
2018-07-14 23:15:42 +02:00
2019-06-11 20:43:37 +02:00
String VisualShaderNodeCubemapUniform : : get_caption ( ) const {
return " CubemapUniform " ;
2018-07-14 23:15:42 +02:00
}
2019-06-11 20:43:37 +02:00
String VisualShaderNodeCubemapUniform : : get_output_port_name ( int p_port ) const {
2019-10-11 09:26:57 +02:00
return " samplerCube " ;
2019-10-09 10:29:23 +02:00
}
2019-06-11 20:43:37 +02:00
String VisualShaderNodeCubemapUniform : : generate_global ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id ) const {
2020-05-05 10:25:48 +02:00
String code = _get_qual_str ( ) + " uniform samplerCube " + get_uniform_name ( ) ;
2022-05-05 20:23:40 +02:00
code + = get_sampler_hint ( texture_type , color_default , texture_filter , texture_repeat ) ;
code + = " ; \n " ;
2019-10-09 10:29:23 +02:00
return code ;
2018-07-14 23:15:42 +02:00
}
2019-06-11 20:43:37 +02:00
String VisualShaderNodeCubemapUniform : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2018-07-14 23:15:42 +02:00
return String ( ) ;
}
2019-06-11 20:43:37 +02:00
VisualShaderNodeCubemapUniform : : VisualShaderNodeCubemapUniform ( ) {
2018-07-14 23:15:42 +02:00
}
2019-04-13 14:24:04 +02:00
////////////// If
String VisualShaderNodeIf : : get_caption ( ) const {
return " If " ;
}
int VisualShaderNodeIf : : get_input_port_count ( ) const {
return 6 ;
}
VisualShaderNodeIf : : PortType VisualShaderNodeIf : : get_input_port_type ( int p_port ) const {
if ( p_port = = 0 | | p_port = = 1 | | p_port = = 2 ) {
return PORT_TYPE_SCALAR ;
}
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2019-04-13 14:24:04 +02:00
}
String VisualShaderNodeIf : : get_input_port_name ( int p_port ) const {
switch ( p_port ) {
case 0 :
return " a " ;
case 1 :
return " b " ;
case 2 :
return " tolerance " ;
case 3 :
return " a == b " ;
case 4 :
return " a > b " ;
case 5 :
return " a < b " ;
default :
return " " ;
}
}
int VisualShaderNodeIf : : get_output_port_count ( ) const {
return 1 ;
}
VisualShaderNodeIf : : PortType VisualShaderNodeIf : : get_output_port_type ( int p_port ) const {
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2019-04-13 14:24:04 +02:00
}
String VisualShaderNodeIf : : get_output_port_name ( int p_port ) const {
return " result " ;
}
String VisualShaderNodeIf : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
String code ;
2021-07-19 08:06:51 +02:00
code + = " if(abs( " + p_input_vars [ 0 ] + " - " + p_input_vars [ 1 ] + " ) < " + p_input_vars [ 2 ] + " ) \n " ; // abs(a - b) < tolerance eg. a == b
code + = " { \n " ;
code + = " " + p_output_vars [ 0 ] + " = " + p_input_vars [ 3 ] + " ; \n " ;
code + = " } \n " ;
code + = " else if( " + p_input_vars [ 0 ] + " < " + p_input_vars [ 1 ] + " ) \n " ; // a < b
code + = " { \n " ;
code + = " " + p_output_vars [ 0 ] + " = " + p_input_vars [ 5 ] + " ; \n " ;
code + = " } \n " ;
code + = " else \n " ; // a > b (or a >= b if abs(a - b) < tolerance is false)
code + = " { \n " ;
code + = " " + p_output_vars [ 0 ] + " = " + p_input_vars [ 4 ] + " ; \n " ;
code + = " } \n " ;
2019-04-13 14:24:04 +02:00
return code ;
}
VisualShaderNodeIf : : VisualShaderNodeIf ( ) {
2020-09-07 11:29:44 +02:00
simple_decl = false ;
2019-04-13 14:24:04 +02:00
set_input_port_default_value ( 0 , 0.0 ) ;
set_input_port_default_value ( 1 , 0.0 ) ;
set_input_port_default_value ( 2 , CMP_EPSILON ) ;
set_input_port_default_value ( 3 , Vector3 ( 0.0 , 0.0 , 0.0 ) ) ;
set_input_port_default_value ( 4 , Vector3 ( 0.0 , 0.0 , 0.0 ) ) ;
set_input_port_default_value ( 5 , Vector3 ( 0.0 , 0.0 , 0.0 ) ) ;
}
////////////// Switch
String VisualShaderNodeSwitch : : get_caption ( ) const {
2021-01-18 10:23:04 +01:00
return " Switch " ;
2019-04-13 14:24:04 +02:00
}
int VisualShaderNodeSwitch : : get_input_port_count ( ) const {
return 3 ;
}
VisualShaderNodeSwitch : : PortType VisualShaderNodeSwitch : : get_input_port_type ( int p_port ) const {
if ( p_port = = 0 ) {
return PORT_TYPE_BOOLEAN ;
}
2021-01-18 10:23:04 +01:00
if ( p_port = = 1 | | p_port = = 2 ) {
switch ( op_type ) {
case OP_TYPE_INT :
return PORT_TYPE_SCALAR_INT ;
2022-02-01 09:32:01 +01:00
case OP_TYPE_VECTOR_2D :
return PORT_TYPE_VECTOR_2D ;
case OP_TYPE_VECTOR_3D :
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D :
return PORT_TYPE_VECTOR_4D ;
2021-01-18 10:23:04 +01:00
case OP_TYPE_BOOLEAN :
return PORT_TYPE_BOOLEAN ;
case OP_TYPE_TRANSFORM :
return PORT_TYPE_TRANSFORM ;
default :
break ;
}
}
return PORT_TYPE_SCALAR ;
2019-04-13 14:24:04 +02:00
}
String VisualShaderNodeSwitch : : get_input_port_name ( int p_port ) const {
switch ( p_port ) {
case 0 :
return " value " ;
case 1 :
return " true " ;
case 2 :
return " false " ;
default :
return " " ;
}
}
int VisualShaderNodeSwitch : : get_output_port_count ( ) const {
return 1 ;
}
VisualShaderNodeSwitch : : PortType VisualShaderNodeSwitch : : get_output_port_type ( int p_port ) const {
2021-01-18 10:23:04 +01:00
switch ( op_type ) {
case OP_TYPE_INT :
return PORT_TYPE_SCALAR_INT ;
2022-02-01 09:32:01 +01:00
case OP_TYPE_VECTOR_2D :
return PORT_TYPE_VECTOR_2D ;
case OP_TYPE_VECTOR_3D :
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D :
return PORT_TYPE_VECTOR_4D ;
2021-01-18 10:23:04 +01:00
case OP_TYPE_BOOLEAN :
return PORT_TYPE_BOOLEAN ;
case OP_TYPE_TRANSFORM :
return PORT_TYPE_TRANSFORM ;
default :
break ;
}
return PORT_TYPE_SCALAR ;
2019-04-13 14:24:04 +02:00
}
String VisualShaderNodeSwitch : : get_output_port_name ( int p_port ) const {
return " result " ;
}
2021-01-18 10:23:04 +01:00
void VisualShaderNodeSwitch : : set_op_type ( OpType p_op_type ) {
2021-08-14 12:38:22 +02:00
ERR_FAIL_INDEX ( int ( p_op_type ) , int ( OP_TYPE_MAX ) ) ;
2021-01-18 10:23:04 +01:00
if ( op_type = = p_op_type ) {
return ;
}
switch ( p_op_type ) {
case OP_TYPE_FLOAT :
2022-02-01 09:32:01 +01:00
set_input_port_default_value ( 1 , 1.0 , get_input_port_default_value ( 1 ) ) ;
set_input_port_default_value ( 2 , 0.0 , get_input_port_default_value ( 2 ) ) ;
2021-01-18 10:23:04 +01:00
break ;
case OP_TYPE_INT :
2022-02-01 09:32:01 +01:00
set_input_port_default_value ( 1 , 1 , get_input_port_default_value ( 1 ) ) ;
set_input_port_default_value ( 2 , 0 , get_input_port_default_value ( 2 ) ) ;
2021-01-18 10:23:04 +01:00
break ;
2022-02-01 09:32:01 +01:00
case OP_TYPE_VECTOR_2D :
set_input_port_default_value ( 1 , Vector2 ( 1.0 , 1.0 ) , get_input_port_default_value ( 1 ) ) ;
set_input_port_default_value ( 2 , Vector2 ( 0.0 , 0.0 ) , get_input_port_default_value ( 2 ) ) ;
break ;
case OP_TYPE_VECTOR_3D :
set_input_port_default_value ( 1 , Vector3 ( 1.0 , 1.0 , 1.0 ) , get_input_port_default_value ( 1 ) ) ;
set_input_port_default_value ( 2 , Vector3 ( 0.0 , 0.0 , 0.0 ) , get_input_port_default_value ( 2 ) ) ;
2021-01-18 10:23:04 +01:00
break ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D :
set_input_port_default_value ( 1 , Quaternion ( 1.0 , 1.0 , 1.0 , 1.0 ) , get_input_port_default_value ( 1 ) ) ;
set_input_port_default_value ( 2 , Quaternion ( 0.0 , 0.0 , 0.0 , 0.0 ) , get_input_port_default_value ( 2 ) ) ;
break ;
2021-01-18 10:23:04 +01:00
case OP_TYPE_BOOLEAN :
set_input_port_default_value ( 1 , true ) ;
set_input_port_default_value ( 2 , false ) ;
break ;
case OP_TYPE_TRANSFORM :
2020-10-17 07:08:21 +02:00
set_input_port_default_value ( 1 , Transform3D ( ) ) ;
set_input_port_default_value ( 2 , Transform3D ( ) ) ;
2021-01-18 10:23:04 +01:00
break ;
default :
break ;
}
op_type = p_op_type ;
emit_changed ( ) ;
}
VisualShaderNodeSwitch : : OpType VisualShaderNodeSwitch : : get_op_type ( ) const {
return op_type ;
}
Vector < StringName > VisualShaderNodeSwitch : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " op_type " ) ;
return props ;
}
void VisualShaderNodeSwitch : : _bind_methods ( ) { // static
ClassDB : : bind_method ( D_METHOD ( " set_op_type " , " type " ) , & VisualShaderNodeSwitch : : set_op_type ) ;
ClassDB : : bind_method ( D_METHOD ( " get_op_type " ) , & VisualShaderNodeSwitch : : get_op_type ) ;
2022-04-12 19:09:29 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " op_type " , PROPERTY_HINT_ENUM , " Float,Int,Vector2,Vector3,Vector4,Boolean,Transform " ) , " set_op_type " , " get_op_type " ) ;
2021-01-18 10:23:04 +01:00
BIND_ENUM_CONSTANT ( OP_TYPE_FLOAT ) ;
BIND_ENUM_CONSTANT ( OP_TYPE_INT ) ;
2022-02-01 09:32:01 +01:00
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_2D ) ;
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_3D ) ;
2022-04-12 19:09:29 +02:00
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_4D ) ;
2021-01-18 10:23:04 +01:00
BIND_ENUM_CONSTANT ( OP_TYPE_BOOLEAN ) ;
BIND_ENUM_CONSTANT ( OP_TYPE_TRANSFORM ) ;
BIND_ENUM_CONSTANT ( OP_TYPE_MAX ) ;
}
2019-04-13 14:24:04 +02:00
String VisualShaderNodeSwitch : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
String code ;
2021-07-19 08:06:51 +02:00
code + = " if( " + p_input_vars [ 0 ] + " ) \n " ;
code + = " { \n " ;
code + = " " + p_output_vars [ 0 ] + " = " + p_input_vars [ 1 ] + " ; \n " ;
code + = " } \n " ;
code + = " else \n " ;
code + = " { \n " ;
code + = " " + p_output_vars [ 0 ] + " = " + p_input_vars [ 2 ] + " ; \n " ;
code + = " } \n " ;
2019-04-13 14:24:04 +02:00
return code ;
}
VisualShaderNodeSwitch : : VisualShaderNodeSwitch ( ) {
2020-09-07 11:29:44 +02:00
simple_decl = false ;
2019-09-03 13:46:31 +02:00
set_input_port_default_value ( 0 , false ) ;
set_input_port_default_value ( 1 , 1.0 ) ;
set_input_port_default_value ( 2 , 0.0 ) ;
}
2019-05-19 12:07:00 +02:00
////////////// Fresnel
String VisualShaderNodeFresnel : : get_caption ( ) const {
return " Fresnel " ;
}
int VisualShaderNodeFresnel : : get_input_port_count ( ) const {
return 4 ;
}
VisualShaderNodeFresnel : : PortType VisualShaderNodeFresnel : : get_input_port_type ( int p_port ) const {
switch ( p_port ) {
case 0 :
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2019-05-19 12:07:00 +02:00
case 1 :
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2019-05-19 12:07:00 +02:00
case 2 :
return PORT_TYPE_BOOLEAN ;
case 3 :
return PORT_TYPE_SCALAR ;
default :
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2019-05-19 12:07:00 +02:00
}
}
String VisualShaderNodeFresnel : : get_input_port_name ( int p_port ) const {
switch ( p_port ) {
case 0 :
return " normal " ;
case 1 :
return " view " ;
case 2 :
return " invert " ;
case 3 :
return " power " ;
default :
return " " ;
}
}
int VisualShaderNodeFresnel : : get_output_port_count ( ) const {
return 1 ;
}
VisualShaderNodeFresnel : : PortType VisualShaderNodeFresnel : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_SCALAR ;
}
String VisualShaderNodeFresnel : : get_output_port_name ( int p_port ) const {
return " result " ;
}
2020-07-27 08:18:37 +02:00
bool VisualShaderNodeFresnel : : is_generate_input_var ( int p_port ) const {
if ( p_port = = 2 ) {
return false ;
}
return true ;
}
2019-05-19 12:07:00 +02:00
String VisualShaderNodeFresnel : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2019-11-22 16:28:59 +01:00
String normal ;
String view ;
2021-12-09 10:42:46 +01:00
if ( p_input_vars [ 0 ] . is_empty ( ) ) {
2022-01-22 09:09:16 +01:00
if ( p_mode = = Shader : : MODE_CANVAS_ITEM | | p_mode = = Shader : : MODE_SPATIAL ) {
normal = " NORMAL " ;
} else {
normal = " vec3(0.0) " ;
}
2019-11-22 16:28:59 +01:00
} else {
normal = p_input_vars [ 0 ] ;
}
2021-12-09 10:42:46 +01:00
if ( p_input_vars [ 1 ] . is_empty ( ) ) {
2022-01-22 09:09:16 +01:00
if ( p_mode = = Shader : : MODE_SPATIAL ) {
view = " VIEW " ;
} else {
view = " vec3(0.0) " ;
}
2019-11-22 16:28:59 +01:00
} else {
view = p_input_vars [ 1 ] ;
}
2020-07-27 08:18:37 +02:00
if ( is_input_port_connected ( 2 ) ) {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = " + p_input_vars [ 2 ] + " ? (pow(clamp(dot( " + normal + " , " + view + " ), 0.0, 1.0), " + p_input_vars [ 3 ] + " )) : (pow(1.0 - clamp(dot( " + normal + " , " + view + " ), 0.0, 1.0), " + p_input_vars [ 3 ] + " )); \n " ;
2020-07-27 08:18:37 +02:00
} else {
if ( get_input_port_default_value ( 2 ) ) {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = pow(clamp(dot( " + normal + " , " + view + " ), 0.0, 1.0), " + p_input_vars [ 3 ] + " ); \n " ;
2020-07-27 08:18:37 +02:00
} else {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = pow(1.0 - clamp(dot( " + normal + " , " + view + " ), 0.0, 1.0), " + p_input_vars [ 3 ] + " ); \n " ;
2020-07-27 08:18:37 +02:00
}
}
2019-11-22 16:28:59 +01:00
}
2022-01-22 09:09:16 +01:00
bool VisualShaderNodeFresnel : : is_input_port_default ( int p_port , Shader : : Mode p_mode ) const {
2019-11-22 16:28:59 +01:00
if ( p_port = = 0 ) {
2022-01-22 09:09:16 +01:00
if ( p_mode = = Shader : : MODE_CANVAS_ITEM | | p_mode = = Shader : : MODE_SPATIAL ) {
return true ;
}
2019-11-22 16:28:59 +01:00
} else if ( p_port = = 1 ) {
2022-01-22 09:09:16 +01:00
if ( p_mode = = Shader : : MODE_SPATIAL ) {
return true ;
}
2019-11-22 16:28:59 +01:00
}
2022-01-22 09:09:16 +01:00
return false ;
2019-05-19 12:07:00 +02:00
}
VisualShaderNodeFresnel : : VisualShaderNodeFresnel ( ) {
set_input_port_default_value ( 2 , false ) ;
set_input_port_default_value ( 3 , 1.0 ) ;
}
2019-07-08 09:05:33 +02:00
////////////// Is
String VisualShaderNodeIs : : get_caption ( ) const {
return " Is " ;
}
int VisualShaderNodeIs : : get_input_port_count ( ) const {
return 1 ;
}
VisualShaderNodeIs : : PortType VisualShaderNodeIs : : get_input_port_type ( int p_port ) const {
return PORT_TYPE_SCALAR ;
}
String VisualShaderNodeIs : : get_input_port_name ( int p_port ) const {
return " " ;
}
int VisualShaderNodeIs : : get_output_port_count ( ) const {
return 1 ;
}
VisualShaderNodeIs : : PortType VisualShaderNodeIs : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_BOOLEAN ;
}
String VisualShaderNodeIs : : get_output_port_name ( int p_port ) const {
return " " ;
}
String VisualShaderNodeIs : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-08-14 12:38:22 +02:00
static const char * functions [ FUNC_MAX ] = {
2019-07-08 09:05:33 +02:00
" isinf($) " ,
" isnan($) "
} ;
String code ;
2021-08-14 12:38:22 +02:00
code + = " " + p_output_vars [ 0 ] + " = " + String ( functions [ func ] ) . replace ( " $ " , p_input_vars [ 0 ] ) + " ; \n " ;
2019-07-08 09:05:33 +02:00
return code ;
}
void VisualShaderNodeIs : : set_function ( Function p_func ) {
2021-08-14 12:38:22 +02:00
ERR_FAIL_INDEX ( int ( p_func ) , int ( FUNC_MAX ) ) ;
if ( func = = p_func ) {
return ;
}
2019-07-08 09:05:33 +02:00
func = p_func ;
emit_changed ( ) ;
}
VisualShaderNodeIs : : Function VisualShaderNodeIs : : get_function ( ) const {
return func ;
}
Vector < StringName > VisualShaderNodeIs : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " function " ) ;
return props ;
}
void VisualShaderNodeIs : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_function " , " func " ) , & VisualShaderNodeIs : : set_function ) ;
ClassDB : : bind_method ( D_METHOD ( " get_function " ) , & VisualShaderNodeIs : : get_function ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " function " , PROPERTY_HINT_ENUM , " Inf,NaN " ) , " set_function " , " get_function " ) ;
BIND_ENUM_CONSTANT ( FUNC_IS_INF ) ;
BIND_ENUM_CONSTANT ( FUNC_IS_NAN ) ;
2021-08-14 12:38:22 +02:00
BIND_ENUM_CONSTANT ( FUNC_MAX ) ;
2019-07-08 09:05:33 +02:00
}
VisualShaderNodeIs : : VisualShaderNodeIs ( ) {
set_input_port_default_value ( 0 , 0.0 ) ;
}
////////////// Compare
String VisualShaderNodeCompare : : get_caption ( ) const {
return " Compare " ;
}
int VisualShaderNodeCompare : : get_input_port_count ( ) const {
2021-08-14 12:38:22 +02:00
if ( comparison_type = = CTYPE_SCALAR & & ( func = = FUNC_EQUAL | | func = = FUNC_NOT_EQUAL ) ) {
2019-07-08 09:05:33 +02:00
return 3 ;
}
return 2 ;
}
VisualShaderNodeCompare : : PortType VisualShaderNodeCompare : : get_input_port_type ( int p_port ) const {
2021-08-14 12:38:22 +02:00
switch ( comparison_type ) {
2019-07-08 09:05:33 +02:00
case CTYPE_SCALAR :
return PORT_TYPE_SCALAR ;
2020-02-25 15:50:49 +01:00
case CTYPE_SCALAR_INT :
return PORT_TYPE_SCALAR_INT ;
2022-02-01 09:32:01 +01:00
case CTYPE_VECTOR_2D :
return PORT_TYPE_VECTOR_2D ;
case CTYPE_VECTOR_3D :
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2022-04-12 19:09:29 +02:00
case CTYPE_VECTOR_4D :
return PORT_TYPE_VECTOR_4D ;
2019-07-08 09:05:33 +02:00
case CTYPE_BOOLEAN :
return PORT_TYPE_BOOLEAN ;
case CTYPE_TRANSFORM :
return PORT_TYPE_TRANSFORM ;
2021-03-01 06:03:49 +01:00
default :
return PORT_TYPE_SCALAR ;
2019-07-08 09:05:33 +02:00
}
}
String VisualShaderNodeCompare : : get_input_port_name ( int p_port ) const {
2020-05-14 16:41:43 +02:00
if ( p_port = = 0 ) {
2019-07-08 09:05:33 +02:00
return " a " ;
2020-05-14 16:41:43 +02:00
} else if ( p_port = = 1 ) {
2019-07-08 09:05:33 +02:00
return " b " ;
2020-05-14 16:41:43 +02:00
} else if ( p_port = = 2 ) {
2019-07-08 09:05:33 +02:00
return " tolerance " ;
2020-05-14 16:41:43 +02:00
}
2019-07-08 09:05:33 +02:00
return " " ;
}
int VisualShaderNodeCompare : : get_output_port_count ( ) const {
return 1 ;
}
VisualShaderNodeCompare : : PortType VisualShaderNodeCompare : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_BOOLEAN ;
}
String VisualShaderNodeCompare : : get_output_port_name ( int p_port ) const {
2020-05-14 16:41:43 +02:00
if ( p_port = = 0 ) {
2019-07-08 09:05:33 +02:00
return " result " ;
2020-05-14 16:41:43 +02:00
}
2019-07-08 09:05:33 +02:00
return " " ;
}
String VisualShaderNodeCompare : : get_warning ( Shader : : Mode p_mode , VisualShader : : Type p_type ) const {
2021-08-14 12:38:22 +02:00
if ( comparison_type = = CTYPE_BOOLEAN | | comparison_type = = CTYPE_TRANSFORM ) {
2019-07-08 09:05:33 +02:00
if ( func > FUNC_NOT_EQUAL ) {
2022-03-28 15:24:14 +02:00
return RTR ( " Invalid comparison function for that type. " ) ;
2019-07-08 09:05:33 +02:00
}
}
return " " ;
}
String VisualShaderNodeCompare : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-08-14 12:38:22 +02:00
static const char * operators [ FUNC_MAX ] = {
2019-07-08 09:05:33 +02:00
" == " ,
" != " ,
" > " ,
" >= " ,
" < " ,
" <= " ,
} ;
2021-08-14 12:38:22 +02:00
static const char * functions [ FUNC_MAX ] = {
2019-07-08 09:05:33 +02:00
" equal($) " ,
" notEqual($) " ,
" greaterThan($) " ,
" greaterThanEqual($) " ,
" lessThan($) " ,
" lessThanEqual($) " ,
} ;
2021-08-14 12:38:22 +02:00
static const char * conditions [ COND_MAX ] = {
2019-07-08 09:05:33 +02:00
" all($) " ,
" any($) " ,
} ;
String code ;
2021-08-14 12:38:22 +02:00
switch ( comparison_type ) {
2022-02-01 09:32:01 +01:00
case CTYPE_SCALAR : {
2019-07-08 09:05:33 +02:00
if ( func = = FUNC_EQUAL ) {
2021-07-19 08:06:51 +02:00
code + = " " + p_output_vars [ 0 ] + " = (abs( " + p_input_vars [ 0 ] + " - " + p_input_vars [ 1 ] + " ) < " + p_input_vars [ 2 ] + " ); " ;
2019-07-08 09:05:33 +02:00
} else if ( func = = FUNC_NOT_EQUAL ) {
2021-07-19 08:06:51 +02:00
code + = " " + p_output_vars [ 0 ] + " = !(abs( " + p_input_vars [ 0 ] + " - " + p_input_vars [ 1 ] + " ) < " + p_input_vars [ 2 ] + " ); " ;
2019-07-08 09:05:33 +02:00
} else {
2021-08-14 12:38:22 +02:00
code + = " " + p_output_vars [ 0 ] + " = " + ( p_input_vars [ 0 ] + " $ " + p_input_vars [ 1 ] ) . replace ( " $ " , operators [ func ] ) + " ; \n " ;
2019-07-08 09:05:33 +02:00
}
2022-02-01 09:32:01 +01:00
} break ;
case CTYPE_SCALAR_INT : {
2021-08-14 12:38:22 +02:00
code + = " " + p_output_vars [ 0 ] + " = " + ( p_input_vars [ 0 ] + " $ " + p_input_vars [ 1 ] ) . replace ( " $ " , operators [ func ] ) + " ; \n " ;
2022-02-01 09:32:01 +01:00
} break ;
case CTYPE_VECTOR_2D : {
code + = " { \n " ;
code + = " bvec2 _bv = " + String ( functions [ func ] ) . replace ( " $ " , p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] ) + " ; \n " ;
code + = " " + p_output_vars [ 0 ] + " = " + String ( conditions [ condition ] ) . replace ( " $ " , " _bv " ) + " ; \n " ;
code + = " } \n " ;
} break ;
case CTYPE_VECTOR_3D : {
2021-07-19 08:06:51 +02:00
code + = " { \n " ;
2021-08-14 12:38:22 +02:00
code + = " bvec3 _bv = " + String ( functions [ func ] ) . replace ( " $ " , p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] ) + " ; \n " ;
code + = " " + p_output_vars [ 0 ] + " = " + String ( conditions [ condition ] ) . replace ( " $ " , " _bv " ) + " ; \n " ;
2021-07-19 08:06:51 +02:00
code + = " } \n " ;
2022-02-01 09:32:01 +01:00
} break ;
2022-04-12 19:09:29 +02:00
case CTYPE_VECTOR_4D : {
code + = " { \n " ;
code + = " bvec4 _bv = " + String ( functions [ func ] ) . replace ( " $ " , p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] ) + " ; \n " ;
code + = " " + p_output_vars [ 0 ] + " = " + String ( conditions [ condition ] ) . replace ( " $ " , " _bv " ) + " ; \n " ;
code + = " } \n " ;
} break ;
2022-02-01 09:32:01 +01:00
case CTYPE_BOOLEAN : {
2020-05-14 16:41:43 +02:00
if ( func > FUNC_NOT_EQUAL ) {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = false; \n " ;
2020-05-14 16:41:43 +02:00
}
2021-08-14 12:38:22 +02:00
code + = " " + p_output_vars [ 0 ] + " = " + ( p_input_vars [ 0 ] + " $ " + p_input_vars [ 1 ] ) . replace ( " $ " , operators [ func ] ) + " ; \n " ;
2022-02-01 09:32:01 +01:00
} break ;
case CTYPE_TRANSFORM : {
2020-05-14 16:41:43 +02:00
if ( func > FUNC_NOT_EQUAL ) {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = false; \n " ;
2020-05-14 16:41:43 +02:00
}
2021-08-14 12:38:22 +02:00
code + = " " + p_output_vars [ 0 ] + " = " + ( p_input_vars [ 0 ] + " $ " + p_input_vars [ 1 ] ) . replace ( " $ " , operators [ func ] ) + " ; \n " ;
2022-02-01 09:32:01 +01:00
} break ;
2019-07-08 09:05:33 +02:00
default :
break ;
}
return code ;
}
2021-08-14 12:38:22 +02:00
void VisualShaderNodeCompare : : set_comparison_type ( ComparisonType p_comparison_type ) {
ERR_FAIL_INDEX ( int ( p_comparison_type ) , int ( CTYPE_MAX ) ) ;
if ( comparison_type = = p_comparison_type ) {
return ;
}
switch ( p_comparison_type ) {
2019-07-08 09:05:33 +02:00
case CTYPE_SCALAR :
2022-02-01 09:32:01 +01:00
set_input_port_default_value ( 0 , 0.0 , get_input_port_default_value ( 0 ) ) ;
set_input_port_default_value ( 1 , 0.0 , get_input_port_default_value ( 1 ) ) ;
2020-01-27 10:10:51 +01:00
simple_decl = true ;
2019-07-08 09:05:33 +02:00
break ;
2020-02-25 15:50:49 +01:00
case CTYPE_SCALAR_INT :
2022-02-01 09:32:01 +01:00
set_input_port_default_value ( 0 , 0 , get_input_port_default_value ( 0 ) ) ;
set_input_port_default_value ( 1 , 0 , get_input_port_default_value ( 1 ) ) ;
2020-02-25 15:50:49 +01:00
simple_decl = true ;
break ;
2022-02-01 09:32:01 +01:00
case CTYPE_VECTOR_2D :
set_input_port_default_value ( 0 , Vector2 ( ) , get_input_port_default_value ( 0 ) ) ;
set_input_port_default_value ( 1 , Vector2 ( ) , get_input_port_default_value ( 1 ) ) ;
simple_decl = false ;
break ;
case CTYPE_VECTOR_3D :
set_input_port_default_value ( 0 , Vector3 ( ) , get_input_port_default_value ( 0 ) ) ;
set_input_port_default_value ( 1 , Vector3 ( ) , get_input_port_default_value ( 1 ) ) ;
2020-01-27 10:10:51 +01:00
simple_decl = false ;
2019-07-08 09:05:33 +02:00
break ;
2022-04-12 19:09:29 +02:00
case CTYPE_VECTOR_4D :
set_input_port_default_value ( 0 , Quaternion ( ) , get_input_port_default_value ( 0 ) ) ;
set_input_port_default_value ( 1 , Quaternion ( ) , get_input_port_default_value ( 1 ) ) ;
simple_decl = false ;
break ;
2019-07-08 09:05:33 +02:00
case CTYPE_BOOLEAN :
set_input_port_default_value ( 0 , false ) ;
set_input_port_default_value ( 1 , false ) ;
2020-01-27 10:10:51 +01:00
simple_decl = true ;
2019-07-08 09:05:33 +02:00
break ;
case CTYPE_TRANSFORM :
2020-10-17 07:08:21 +02:00
set_input_port_default_value ( 0 , Transform3D ( ) ) ;
set_input_port_default_value ( 1 , Transform3D ( ) ) ;
2020-01-27 10:10:51 +01:00
simple_decl = true ;
2019-07-08 09:05:33 +02:00
break ;
2021-08-14 12:38:22 +02:00
default :
break ;
2019-07-08 09:05:33 +02:00
}
2021-08-14 12:38:22 +02:00
comparison_type = p_comparison_type ;
2019-07-08 09:05:33 +02:00
emit_changed ( ) ;
}
2020-01-23 08:31:45 +01:00
VisualShaderNodeCompare : : ComparisonType VisualShaderNodeCompare : : get_comparison_type ( ) const {
2021-08-14 12:38:22 +02:00
return comparison_type ;
2019-07-08 09:05:33 +02:00
}
void VisualShaderNodeCompare : : set_function ( Function p_func ) {
2021-08-14 12:38:22 +02:00
ERR_FAIL_INDEX ( int ( p_func ) , int ( FUNC_MAX ) ) ;
if ( func = = p_func ) {
return ;
}
2019-07-08 09:05:33 +02:00
func = p_func ;
emit_changed ( ) ;
}
VisualShaderNodeCompare : : Function VisualShaderNodeCompare : : get_function ( ) const {
return func ;
}
2021-08-14 12:38:22 +02:00
void VisualShaderNodeCompare : : set_condition ( Condition p_condition ) {
ERR_FAIL_INDEX ( int ( p_condition ) , int ( COND_MAX ) ) ;
if ( condition = = p_condition ) {
return ;
}
condition = p_condition ;
2019-07-08 09:05:33 +02:00
emit_changed ( ) ;
}
VisualShaderNodeCompare : : Condition VisualShaderNodeCompare : : get_condition ( ) const {
return condition ;
}
Vector < StringName > VisualShaderNodeCompare : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " type " ) ;
props . push_back ( " function " ) ;
2022-04-12 19:09:29 +02:00
if ( comparison_type = = CTYPE_VECTOR_2D | | comparison_type = = CTYPE_VECTOR_3D | | comparison_type = = CTYPE_VECTOR_4D ) {
2019-07-08 09:05:33 +02:00
props . push_back ( " condition " ) ;
2020-05-14 16:41:43 +02:00
}
2019-07-08 09:05:33 +02:00
return props ;
}
void VisualShaderNodeCompare : : _bind_methods ( ) {
2020-01-23 08:31:45 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_comparison_type " , " type " ) , & VisualShaderNodeCompare : : set_comparison_type ) ;
ClassDB : : bind_method ( D_METHOD ( " get_comparison_type " ) , & VisualShaderNodeCompare : : get_comparison_type ) ;
2019-07-08 09:05:33 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_function " , " func " ) , & VisualShaderNodeCompare : : set_function ) ;
ClassDB : : bind_method ( D_METHOD ( " get_function " ) , & VisualShaderNodeCompare : : get_function ) ;
ClassDB : : bind_method ( D_METHOD ( " set_condition " , " condition " ) , & VisualShaderNodeCompare : : set_condition ) ;
ClassDB : : bind_method ( D_METHOD ( " get_condition " ) , & VisualShaderNodeCompare : : get_condition ) ;
2022-04-12 19:09:29 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " type " , PROPERTY_HINT_ENUM , " Float,Int,Vector2,Vector3,Vector4,Boolean,Transform " ) , " set_comparison_type " , " get_comparison_type " ) ;
2019-07-08 09:05:33 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " function " , PROPERTY_HINT_ENUM , " a == b,a != b,a > b,a >= b,a < b,a <= b " ) , " set_function " , " get_function " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " condition " , PROPERTY_HINT_ENUM , " All,Any " ) , " set_condition " , " get_condition " ) ;
BIND_ENUM_CONSTANT ( CTYPE_SCALAR ) ;
2020-02-25 15:50:49 +01:00
BIND_ENUM_CONSTANT ( CTYPE_SCALAR_INT ) ;
2022-02-01 09:32:01 +01:00
BIND_ENUM_CONSTANT ( CTYPE_VECTOR_2D ) ;
BIND_ENUM_CONSTANT ( CTYPE_VECTOR_3D ) ;
2022-04-12 19:09:29 +02:00
BIND_ENUM_CONSTANT ( CTYPE_VECTOR_4D ) ;
2019-07-08 09:05:33 +02:00
BIND_ENUM_CONSTANT ( CTYPE_BOOLEAN ) ;
BIND_ENUM_CONSTANT ( CTYPE_TRANSFORM ) ;
2021-08-14 12:38:22 +02:00
BIND_ENUM_CONSTANT ( CTYPE_MAX ) ;
2019-07-08 09:05:33 +02:00
BIND_ENUM_CONSTANT ( FUNC_EQUAL ) ;
BIND_ENUM_CONSTANT ( FUNC_NOT_EQUAL ) ;
BIND_ENUM_CONSTANT ( FUNC_GREATER_THAN ) ;
BIND_ENUM_CONSTANT ( FUNC_GREATER_THAN_EQUAL ) ;
BIND_ENUM_CONSTANT ( FUNC_LESS_THAN ) ;
BIND_ENUM_CONSTANT ( FUNC_LESS_THAN_EQUAL ) ;
2021-08-14 12:38:22 +02:00
BIND_ENUM_CONSTANT ( FUNC_MAX ) ;
2019-07-08 09:05:33 +02:00
BIND_ENUM_CONSTANT ( COND_ALL ) ;
BIND_ENUM_CONSTANT ( COND_ANY ) ;
2021-08-14 12:38:22 +02:00
BIND_ENUM_CONSTANT ( COND_MAX ) ;
2019-07-08 09:05:33 +02:00
}
VisualShaderNodeCompare : : VisualShaderNodeCompare ( ) {
set_input_port_default_value ( 0 , 0.0 ) ;
set_input_port_default_value ( 1 , 0.0 ) ;
set_input_port_default_value ( 2 , CMP_EPSILON ) ;
}
2020-02-14 21:09:53 +01:00
////////////// Fma
String VisualShaderNodeMultiplyAdd : : get_caption ( ) const {
return " MultiplyAdd " ;
}
int VisualShaderNodeMultiplyAdd : : get_input_port_count ( ) const {
return 3 ;
}
VisualShaderNodeMultiplyAdd : : PortType VisualShaderNodeMultiplyAdd : : get_input_port_type ( int p_port ) const {
2022-02-01 09:32:01 +01:00
switch ( op_type ) {
case OP_TYPE_VECTOR_2D :
return PORT_TYPE_VECTOR_2D ;
case OP_TYPE_VECTOR_3D :
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D :
return PORT_TYPE_VECTOR_4D ;
2022-02-01 09:32:01 +01:00
default :
break ;
2020-02-14 21:09:53 +01:00
}
2021-03-01 06:03:49 +01:00
return PORT_TYPE_SCALAR ;
2020-02-14 21:09:53 +01:00
}
String VisualShaderNodeMultiplyAdd : : get_input_port_name ( int p_port ) const {
if ( p_port = = 0 ) {
return " a " ;
} else if ( p_port = = 1 ) {
return " b(*) " ;
} else if ( p_port = = 2 ) {
return " c(+) " ;
}
return " " ;
}
int VisualShaderNodeMultiplyAdd : : get_output_port_count ( ) const {
return 1 ;
}
VisualShaderNodeMultiplyAdd : : PortType VisualShaderNodeMultiplyAdd : : get_output_port_type ( int p_port ) const {
2022-02-01 09:32:01 +01:00
switch ( op_type ) {
case OP_TYPE_VECTOR_2D :
return PORT_TYPE_VECTOR_2D ;
case OP_TYPE_VECTOR_3D :
2022-02-06 18:15:28 +01:00
return PORT_TYPE_VECTOR_3D ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D :
return PORT_TYPE_VECTOR_4D ;
2022-02-01 09:32:01 +01:00
default :
break ;
2020-02-14 21:09:53 +01:00
}
2022-02-01 09:32:01 +01:00
return PORT_TYPE_SCALAR ;
2020-02-14 21:09:53 +01:00
}
String VisualShaderNodeMultiplyAdd : : get_output_port_name ( int p_port ) const {
return " " ;
}
String VisualShaderNodeMultiplyAdd : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
2021-07-19 08:06:51 +02:00
return " " + p_output_vars [ 0 ] + " = fma( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " , " + p_input_vars [ 2 ] + " ); \n " ;
2020-02-14 21:09:53 +01:00
}
2020-09-15 10:06:18 +02:00
void VisualShaderNodeMultiplyAdd : : set_op_type ( OpType p_op_type ) {
2021-08-14 12:38:22 +02:00
ERR_FAIL_INDEX ( ( int ) p_op_type , int ( OP_TYPE_MAX ) ) ;
2021-01-18 10:23:04 +01:00
if ( op_type = = p_op_type ) {
return ;
}
switch ( p_op_type ) {
2022-02-01 09:32:01 +01:00
case OP_TYPE_SCALAR : {
set_input_port_default_value ( 0 , 0.0 , get_input_port_default_value ( 0 ) ) ;
2022-08-06 15:14:40 +02:00
set_input_port_default_value ( 1 , 1.0 , get_input_port_default_value ( 1 ) ) ;
2022-02-01 09:32:01 +01:00
set_input_port_default_value ( 2 , 0.0 , get_input_port_default_value ( 2 ) ) ;
} break ;
case OP_TYPE_VECTOR_2D : {
set_input_port_default_value ( 0 , Vector2 ( ) , get_input_port_default_value ( 0 ) ) ;
2022-08-06 15:14:40 +02:00
set_input_port_default_value ( 1 , Vector2 ( 1.0 , 1.0 ) , get_input_port_default_value ( 1 ) ) ;
2022-02-01 09:32:01 +01:00
set_input_port_default_value ( 2 , Vector2 ( ) , get_input_port_default_value ( 2 ) ) ;
} break ;
case OP_TYPE_VECTOR_3D : {
set_input_port_default_value ( 0 , Vector3 ( ) , get_input_port_default_value ( 0 ) ) ;
2022-08-06 15:14:40 +02:00
set_input_port_default_value ( 1 , Vector3 ( 1.0 , 1.0 , 1.0 ) , get_input_port_default_value ( 1 ) ) ;
2022-02-01 09:32:01 +01:00
set_input_port_default_value ( 2 , Vector3 ( ) , get_input_port_default_value ( 2 ) ) ;
} break ;
2022-04-12 19:09:29 +02:00
case OP_TYPE_VECTOR_4D : {
2022-08-06 15:14:40 +02:00
set_input_port_default_value ( 0 , Vector4 ( ) , get_input_port_default_value ( 0 ) ) ;
set_input_port_default_value ( 1 , Vector4 ( 1.0 , 1.0 , 1.0 , 1.0 ) , get_input_port_default_value ( 1 ) ) ;
set_input_port_default_value ( 2 , Vector4 ( ) , get_input_port_default_value ( 2 ) ) ;
2022-04-12 19:09:29 +02:00
} break ;
2021-01-18 10:23:04 +01:00
default :
break ;
2020-02-14 21:09:53 +01:00
}
2020-09-15 10:06:18 +02:00
op_type = p_op_type ;
2020-02-14 21:09:53 +01:00
emit_changed ( ) ;
}
2020-09-15 10:06:18 +02:00
VisualShaderNodeMultiplyAdd : : OpType VisualShaderNodeMultiplyAdd : : get_op_type ( ) const {
return op_type ;
2020-02-14 21:09:53 +01:00
}
Vector < StringName > VisualShaderNodeMultiplyAdd : : get_editable_properties ( ) const {
Vector < StringName > props ;
2020-09-15 10:06:18 +02:00
props . push_back ( " op_type " ) ;
2020-02-14 21:09:53 +01:00
return props ;
}
void VisualShaderNodeMultiplyAdd : : _bind_methods ( ) {
2020-09-15 10:06:18 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_op_type " , " type " ) , & VisualShaderNodeMultiplyAdd : : set_op_type ) ;
ClassDB : : bind_method ( D_METHOD ( " get_op_type " ) , & VisualShaderNodeMultiplyAdd : : get_op_type ) ;
2020-02-14 21:09:53 +01:00
2022-04-12 19:09:29 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " op_type " , PROPERTY_HINT_ENUM , " Scalar,Vector2,Vector3,Vector4 " ) , " set_op_type " , " get_op_type " ) ;
2020-02-14 21:09:53 +01:00
2020-09-15 10:06:18 +02:00
BIND_ENUM_CONSTANT ( OP_TYPE_SCALAR ) ;
2022-02-01 09:32:01 +01:00
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_2D ) ;
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_3D ) ;
2022-04-12 19:09:29 +02:00
BIND_ENUM_CONSTANT ( OP_TYPE_VECTOR_4D ) ;
2020-09-15 10:06:18 +02:00
BIND_ENUM_CONSTANT ( OP_TYPE_MAX ) ;
2020-02-14 21:09:53 +01:00
}
VisualShaderNodeMultiplyAdd : : VisualShaderNodeMultiplyAdd ( ) {
set_input_port_default_value ( 0 , 0.0 ) ;
2022-08-06 15:14:40 +02:00
set_input_port_default_value ( 1 , 1.0 ) ;
2020-02-14 21:09:53 +01:00
set_input_port_default_value ( 2 , 0.0 ) ;
}
2021-05-27 21:17:58 +02:00
////////////// Billboard
String VisualShaderNodeBillboard : : get_caption ( ) const {
return " GetBillboardMatrix " ;
}
int VisualShaderNodeBillboard : : get_input_port_count ( ) const {
return 0 ;
}
VisualShaderNodeBillboard : : PortType VisualShaderNodeBillboard : : get_input_port_type ( int p_port ) const {
return PORT_TYPE_SCALAR ;
}
String VisualShaderNodeBillboard : : get_input_port_name ( int p_port ) const {
return " " ;
}
int VisualShaderNodeBillboard : : get_output_port_count ( ) const {
return 1 ;
}
VisualShaderNodeBillboard : : PortType VisualShaderNodeBillboard : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_TRANSFORM ;
}
String VisualShaderNodeBillboard : : get_output_port_name ( int p_port ) const {
return " model_view_matrix " ;
}
String VisualShaderNodeBillboard : : generate_code ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id , const String * p_input_vars , const String * p_output_vars , bool p_for_preview ) const {
String code ;
switch ( billboard_type ) {
case BILLBOARD_TYPE_ENABLED :
2021-07-19 08:06:51 +02:00
code + = " { \n " ;
2022-03-18 10:10:55 +01:00
code + = " mat4 __mvm = VIEW_MATRIX * mat4(INV_VIEW_MATRIX[0], INV_VIEW_MATRIX[1], INV_VIEW_MATRIX[2], MODEL_MATRIX[3]); \n " ;
2021-05-27 21:17:58 +02:00
if ( keep_scale ) {
2022-03-18 10:10:55 +01:00
code + = " __mvm = __mvm * mat4(vec4(length(MODEL_MATRIX[0].xyz), 0.0, 0.0, 0.0), vec4(0.0, length(MODEL_MATRIX[1].xyz), 0.0, 0.0), vec4(0.0, 0.0, length(MODEL_MATRIX[2].xyz), 0.0), vec4(0.0, 0.0, 0.0, 1.0)); \n " ;
2021-05-27 21:17:58 +02:00
}
2021-07-19 08:06:51 +02:00
code + = " " + p_output_vars [ 0 ] + " = __mvm; \n " ;
code + = " } \n " ;
2021-05-27 21:17:58 +02:00
break ;
case BILLBOARD_TYPE_FIXED_Y :
2021-07-19 08:06:51 +02:00
code + = " { \n " ;
2022-03-18 10:10:55 +01:00
code + = " mat4 __mvm = VIEW_MATRIX * mat4(INV_VIEW_MATRIX[0], MODEL_MATRIX[1], vec4(normalize(cross(INV_VIEW_MATRIX[0].xyz, MODEL_MATRIX[1].xyz)), 0.0), MODEL_MATRIX[3]); \n " ;
2021-05-27 21:17:58 +02:00
if ( keep_scale ) {
2022-03-18 10:10:55 +01:00
code + = " __mvm = __mvm * mat4(vec4(length(MODEL_MATRIX[0].xyz), 0.0, 0.0, 0.0), vec4(0.0, 1.0, 0.0, 0.0), vec4(0.0, 0.0, length(MODEL_MATRIX[2].xyz), 0.0), vec4(0.0, 0.0, 0.0, 1.0)); \n " ;
2021-05-27 21:17:58 +02:00
} else {
2022-03-18 10:10:55 +01:00
code + = " __mvm = __mvm * mat4(vec4(1.0, 0.0, 0.0, 0.0), vec4(0.0, 1.0 / length(MODEL_MATRIX[1].xyz), 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0)); \n " ;
2021-05-27 21:17:58 +02:00
}
2021-07-19 08:06:51 +02:00
code + = " " + p_output_vars [ 0 ] + " = __mvm; \n " ;
code + = " } \n " ;
2021-05-27 21:17:58 +02:00
break ;
case BILLBOARD_TYPE_PARTICLES :
2021-07-19 08:06:51 +02:00
code + = " { \n " ;
2022-03-18 10:10:55 +01:00
code + = " mat4 __wm = mat4(normalize(INV_VIEW_MATRIX[0]) * length(MODEL_MATRIX[0]), normalize(INV_VIEW_MATRIX[1]) * length(MODEL_MATRIX[0]), normalize(INV_VIEW_MATRIX[2]) * length(MODEL_MATRIX[2]), MODEL_MATRIX[3]); \n " ;
2021-07-19 08:06:51 +02:00
code + = " __wm = __wm * mat4(vec4(cos(INSTANCE_CUSTOM.x), -sin(INSTANCE_CUSTOM.x), 0.0, 0.0), vec4(sin(INSTANCE_CUSTOM.x), cos(INSTANCE_CUSTOM.x), 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0)); \n " ;
2022-03-18 10:10:55 +01:00
code + = " " + p_output_vars [ 0 ] + " = VIEW_MATRIX * __wm; \n " ;
2021-07-19 08:06:51 +02:00
code + = " } \n " ;
2021-05-27 21:17:58 +02:00
break ;
default :
2021-07-19 08:06:51 +02:00
code + = " " + p_output_vars [ 0 ] + " = mat4(1.0); \n " ;
2021-05-27 21:17:58 +02:00
break ;
}
return code ;
}
bool VisualShaderNodeBillboard : : is_show_prop_names ( ) const {
return true ;
}
void VisualShaderNodeBillboard : : set_billboard_type ( BillboardType p_billboard_type ) {
2021-08-14 12:38:22 +02:00
ERR_FAIL_INDEX ( int ( p_billboard_type ) , int ( BILLBOARD_TYPE_MAX ) ) ;
if ( billboard_type = = p_billboard_type ) {
return ;
}
2021-05-27 21:17:58 +02:00
billboard_type = p_billboard_type ;
simple_decl = bool ( billboard_type = = BILLBOARD_TYPE_DISABLED ) ;
set_disabled ( simple_decl ) ;
emit_changed ( ) ;
}
VisualShaderNodeBillboard : : BillboardType VisualShaderNodeBillboard : : get_billboard_type ( ) const {
return billboard_type ;
}
void VisualShaderNodeBillboard : : set_keep_scale_enabled ( bool p_enabled ) {
keep_scale = p_enabled ;
emit_changed ( ) ;
}
bool VisualShaderNodeBillboard : : is_keep_scale_enabled ( ) const {
return keep_scale ;
}
Vector < StringName > VisualShaderNodeBillboard : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " billboard_type " ) ;
if ( billboard_type = = BILLBOARD_TYPE_ENABLED | | billboard_type = = BILLBOARD_TYPE_FIXED_Y ) {
props . push_back ( " keep_scale " ) ;
}
return props ;
}
void VisualShaderNodeBillboard : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_billboard_type " , " billboard_type " ) , & VisualShaderNodeBillboard : : set_billboard_type ) ;
ClassDB : : bind_method ( D_METHOD ( " get_billboard_type " ) , & VisualShaderNodeBillboard : : get_billboard_type ) ;
ClassDB : : bind_method ( D_METHOD ( " set_keep_scale_enabled " , " enabled " ) , & VisualShaderNodeBillboard : : set_keep_scale_enabled ) ;
ClassDB : : bind_method ( D_METHOD ( " is_keep_scale_enabled " ) , & VisualShaderNodeBillboard : : is_keep_scale_enabled ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " billboard_type " , PROPERTY_HINT_ENUM , " Disabled,Enabled,Y-Billboard,Particles " ) , " set_billboard_type " , " get_billboard_type " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " keep_scale " ) , " set_keep_scale_enabled " , " is_keep_scale_enabled " ) ;
BIND_ENUM_CONSTANT ( BILLBOARD_TYPE_DISABLED ) ;
BIND_ENUM_CONSTANT ( BILLBOARD_TYPE_ENABLED ) ;
BIND_ENUM_CONSTANT ( BILLBOARD_TYPE_FIXED_Y ) ;
BIND_ENUM_CONSTANT ( BILLBOARD_TYPE_PARTICLES ) ;
BIND_ENUM_CONSTANT ( BILLBOARD_TYPE_MAX ) ;
}
VisualShaderNodeBillboard : : VisualShaderNodeBillboard ( ) {
simple_decl = false ;
}