2018-08-29 22:38:13 +02:00
/*************************************************************************/
/* visual_shader_nodes.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
2020-01-01 11:16:22 +01:00
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 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
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 {
return " ScalarFloat " ;
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 {
2018-07-14 23:15:42 +02:00
return " \t " + p_output_vars [ 0 ] + " = " + vformat ( " %.6f " , constant ) + " ; \n " ;
}
2020-02-25 15:50:49 +01:00
void VisualShaderNodeFloatConstant : : set_constant ( float p_value ) {
2018-07-14 23:15:42 +02:00
constant = p_value ;
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 ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_constant " , " value " ) , & VisualShaderNodeFloatConstant : : set_constant ) ;
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 ( ) {
constant = 0.0 ;
}
////////////// Scalar(Int)
String VisualShaderNodeIntConstant : : get_caption ( ) const {
return " ScalarInt " ;
}
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 {
return " \t " + p_output_vars [ 0 ] + " = " + itos ( constant ) + " ; \n " ;
}
void VisualShaderNodeIntConstant : : set_constant ( int p_value ) {
constant = p_value ;
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 ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_constant " , " value " ) , & VisualShaderNodeIntConstant : : set_constant ) ;
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
constant = 0 ;
}
2019-02-22 18:38:58 +01:00
////////////// Boolean
String VisualShaderNodeBooleanConstant : : get_caption ( ) const {
return " Boolean " ;
}
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 {
return " \t " + p_output_vars [ 0 ] + " = " + ( constant ? " true " : " false " ) + " ; \n " ;
}
void VisualShaderNodeBooleanConstant : : set_constant ( bool p_value ) {
constant = p_value ;
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 ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_constant " , " value " ) , & VisualShaderNodeBooleanConstant : : set_constant ) ;
ClassDB : : bind_method ( D_METHOD ( " get_constant " ) , & VisualShaderNodeBooleanConstant : : get_constant ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " constant " ) , " set_constant " , " get_constant " ) ;
}
VisualShaderNodeBooleanConstant : : VisualShaderNodeBooleanConstant ( ) {
constant = false ;
}
2018-07-14 23:15:42 +02:00
////////////// Color
String VisualShaderNodeColorConstant : : get_caption ( ) const {
return " Color " ;
}
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 {
return PORT_TYPE_VECTOR ;
}
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 {
return 2 ;
}
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 {
return p_port = = 0 ? PORT_TYPE_VECTOR : PORT_TYPE_SCALAR ;
}
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 {
return p_port = = 0 ? " " : " alpha " ; //no output port means the editor will be used as port
}
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 {
2018-07-14 23:15:42 +02:00
String code ;
2020-01-27 10:10:51 +01:00
code + = " \t " + p_output_vars [ 0 ] + " = " + vformat ( " vec3(%.6f, %.6f, %.6f) " , constant . r , constant . g , constant . b ) + " ; \n " ;
2018-07-14 23:15:42 +02:00
code + = " \t " + p_output_vars [ 1 ] + " = " + vformat ( " %.6f " , constant . a ) + " ; \n " ;
return code ;
}
void VisualShaderNodeColorConstant : : set_constant ( Color p_value ) {
constant = p_value ;
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 ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_constant " , " value " ) , & VisualShaderNodeColorConstant : : set_constant ) ;
ClassDB : : bind_method ( D_METHOD ( " get_constant " ) , & VisualShaderNodeColorConstant : : get_constant ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : COLOR , " constant " ) , " set_constant " , " get_constant " ) ;
}
VisualShaderNodeColorConstant : : VisualShaderNodeColorConstant ( ) {
constant = Color ( 1 , 1 , 1 , 1 ) ;
}
////////////// Vector
String VisualShaderNodeVec3Constant : : get_caption ( ) const {
return " Vector " ;
}
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 {
return PORT_TYPE_VECTOR ;
}
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 {
return PORT_TYPE_VECTOR ;
}
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 {
2020-01-27 10:10:51 +01:00
return " \t " + p_output_vars [ 0 ] + " = " + vformat ( " vec3(%.6f, %.6f, %.6f) " , constant . x , constant . y , constant . z ) + " ; \n " ;
2018-07-14 23:15:42 +02:00
}
void VisualShaderNodeVec3Constant : : set_constant ( Vector3 p_value ) {
constant = p_value ;
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 ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_constant " , " value " ) , & VisualShaderNodeVec3Constant : : set_constant ) ;
ClassDB : : bind_method ( D_METHOD ( " get_constant " ) , & VisualShaderNodeVec3Constant : : get_constant ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : VECTOR3 , " constant " ) , " set_constant " , " get_constant " ) ;
}
VisualShaderNodeVec3Constant : : VisualShaderNodeVec3Constant ( ) {
}
////////////// Transform
String VisualShaderNodeTransformConstant : : get_caption ( ) const {
2018-07-15 16:28:06 +02:00
return " Transform " ;
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 {
return PORT_TYPE_VECTOR ;
}
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 {
2018-07-14 23:15:42 +02:00
Transform t = constant ;
t . basis . transpose ( ) ;
String code = " \t " + 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 ;
}
void VisualShaderNodeTransformConstant : : set_constant ( Transform p_value ) {
constant = p_value ;
emit_changed ( ) ;
}
Transform VisualShaderNodeTransformConstant : : get_constant ( ) const {
return constant ;
}
Vector < StringName > VisualShaderNodeTransformConstant : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " constant " ) ;
return props ;
}
void VisualShaderNodeTransformConstant : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_constant " , " value " ) , & VisualShaderNodeTransformConstant : : set_constant ) ;
ClassDB : : bind_method ( D_METHOD ( " get_constant " ) , & VisualShaderNodeTransformConstant : : get_constant ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : TRANSFORM , " constant " ) , " set_constant " , " get_constant " ) ;
}
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 :
return PORT_TYPE_VECTOR ;
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 {
return 2 ;
}
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 {
2020-05-14 16:41:43 +02:00
if ( p_port = = 0 & & source = = SOURCE_DEPTH ) {
2019-07-05 10:48:31 +02:00
return PORT_TYPE_SCALAR ;
2020-05-14 16:41:43 +02:00
}
2018-07-14 23:15:42 +02:00
return p_port = = 0 ? PORT_TYPE_VECTOR : PORT_TYPE_SCALAR ;
}
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 {
2020-05-14 16:41:43 +02:00
if ( p_port = = 0 & & source = = SOURCE_DEPTH ) {
2019-07-05 10:48:31 +02:00
return " depth " ;
2020-05-14 16:41:43 +02:00
}
2018-07-14 23:15:42 +02:00
return p_port = = 0 ? " rgb " : " alpha " ;
}
2019-10-03 09:40:26 +02:00
String VisualShaderNodeTexture : : get_input_port_default_hint ( int p_port ) const {
if ( p_port = = 0 ) {
return " UV.xy " ;
}
return " " ;
}
2018-07-14 23:15:42 +02:00
static String make_unique_id ( VisualShader : : Type p_type , int p_id , const String & p_name ) {
static const char * typepf [ VisualShader : : TYPE_MAX ] = { " vtx " , " frg " , " lgt " } ;
return p_name + " _ " + String ( typepf [ p_type ] ) + " _ " + itos ( p_id ) ;
}
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 " ) ;
dtp . param = texture ;
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 :
u + = " : hint_albedo " ;
break ;
case TYPE_NORMALMAP :
u + = " : hint_normal " ;
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 {
2018-07-14 23:15:42 +02:00
if ( source = = SOURCE_TEXTURE ) {
String id = make_unique_id ( p_type , p_id , " tex " ) ;
String code ;
2019-10-03 09:40:26 +02:00
if ( p_input_vars [ 0 ] = = String ( ) ) { // Use UV by default.
2018-07-14 23:15:42 +02:00
2019-10-10 12:11:04 +02:00
if ( p_input_vars [ 1 ] = = String ( ) ) {
2020-01-27 10:10:51 +01:00
code + = " \t vec4 " + id + " _read = texture( " + id + " , UV.xy); \n " ;
2019-10-10 12:11:04 +02:00
} else {
2020-01-27 10:10:51 +01:00
code + = " \t vec4 " + id + " _read = textureLod( " + id + " , UV.xy, " + p_input_vars [ 1 ] + " ); \n " ;
2019-10-10 12:11:04 +02:00
}
2018-07-14 23:15:42 +02:00
} else if ( p_input_vars [ 1 ] = = String ( ) ) {
//no lod
2020-01-27 10:10:51 +01:00
code + = " \t vec4 " + id + " _read = texture( " + id + " , " + p_input_vars [ 0 ] + " .xy); \n " ;
2018-07-14 23:15:42 +02:00
} else {
2020-01-27 10:10:51 +01:00
code + = " \t vec4 " + id + " _read = textureLod( " + id + " , " + p_input_vars [ 0 ] + " .xy, " + p_input_vars [ 1 ] + " ); \n " ;
2018-07-14 23:15:42 +02:00
}
code + = " \t " + p_output_vars [ 0 ] + " = " + id + " _read.rgb; \n " ;
code + = " \t " + p_output_vars [ 1 ] + " = " + id + " _read.a; \n " ;
return code ;
}
2019-10-01 10:51:50 +02:00
if ( source = = SOURCE_PORT ) {
String id = p_input_vars [ 2 ] ;
2019-10-09 10:29:23 +02:00
2019-10-01 10:51:50 +02:00
String code ;
2019-11-03 14:38:03 +01:00
code + = " \t { \n " ;
2019-10-01 10:51:50 +02:00
if ( id = = String ( ) ) {
2019-11-03 14:38:03 +01:00
code + = " \t \t vec4 " + id + " _tex_read = vec4(0.0); \n " ;
2019-10-01 10:51:50 +02:00
} else {
2019-10-03 09:40:26 +02:00
if ( p_input_vars [ 0 ] = = String ( ) ) { // Use UV by default.
2019-10-11 09:26:57 +02:00
if ( p_input_vars [ 1 ] = = String ( ) ) {
2020-01-27 10:10:51 +01:00
code + = " \t \t vec4 " + id + " _tex_read = texture( " + id + " , UV.xy); \n " ;
2019-10-11 09:26:57 +02:00
} else {
2020-01-27 10:10:51 +01:00
code + = " \t \t vec4 " + id + " _tex_read = textureLod( " + id + " , UV.xy, " + p_input_vars [ 1 ] + " ); \n " ;
2019-10-09 10:29:23 +02:00
}
2019-10-11 09:26:57 +02:00
2019-10-01 10:51:50 +02:00
} else if ( p_input_vars [ 1 ] = = String ( ) ) {
//no lod
2020-01-27 10:10:51 +01:00
code + = " \t \t vec4 " + id + " _tex_read = texture( " + id + " , " + p_input_vars [ 0 ] + " .xy); \n " ;
2019-10-01 10:51:50 +02:00
} else {
2020-01-27 10:10:51 +01:00
code + = " \t \t vec4 " + id + " _tex_read = textureLod( " + id + " , " + p_input_vars [ 0 ] + " .xy, " + p_input_vars [ 1 ] + " ); \n " ;
2019-10-01 10:51:50 +02:00
}
2019-11-03 14:38:03 +01:00
code + = " \t \t " + p_output_vars [ 0 ] + " = " + id + " _tex_read.rgb; \n " ;
code + = " \t \t " + p_output_vars [ 1 ] + " = " + id + " _tex_read.a; \n " ;
2019-10-01 10:51:50 +02:00
}
2019-11-03 14:38:03 +01:00
code + = " \t } \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 ) {
String code = " \t { \n " ;
2019-10-03 09:40:26 +02:00
if ( p_input_vars [ 0 ] = = String ( ) | | p_for_preview ) { // Use UV by default.
2018-07-14 23:15:42 +02:00
2019-10-10 12:11:04 +02:00
if ( p_input_vars [ 1 ] = = String ( ) ) {
2020-01-27 10:10:51 +01:00
code + = " \t \t vec4 _tex_read = textureLod(SCREEN_TEXTURE, UV.xy, 0.0 ); \n " ;
2019-10-10 12:11:04 +02:00
} else {
2020-01-27 10:10:51 +01:00
code + = " \t \t vec4 _tex_read = textureLod(SCREEN_TEXTURE, UV.xy, " + p_input_vars [ 1 ] + " ); \n " ;
2019-10-10 12:11:04 +02:00
}
2018-07-14 23:15:42 +02:00
} else if ( p_input_vars [ 1 ] = = String ( ) ) {
//no lod
2020-01-27 10:10:51 +01:00
code + = " \t \t vec4 _tex_read = textureLod(SCREEN_TEXTURE, " + p_input_vars [ 0 ] + " .xy, 0.0); \n " ;
2018-07-14 23:15:42 +02:00
} else {
2020-01-27 10:10:51 +01:00
code + = " \t \t vec4 _tex_read = textureLod(SCREEN_TEXTURE, " + p_input_vars [ 0 ] + " .xy, " + p_input_vars [ 1 ] + " ); \n " ;
2018-07-14 23:15:42 +02:00
}
code + = " \t \t " + p_output_vars [ 0 ] + " = _tex_read.rgb; \n " ;
code + = " \t \t " + p_output_vars [ 1 ] + " = _tex_read.a; \n " ;
code + = " \t } \n " ;
return code ;
}
if ( source = = SOURCE_2D_TEXTURE & & p_mode = = Shader : : MODE_CANVAS_ITEM & & p_type = = VisualShader : : TYPE_FRAGMENT ) {
String code = " \t { \n " ;
2019-10-03 09:40:26 +02:00
if ( p_input_vars [ 0 ] = = String ( ) ) { // Use UV by default.
2018-07-14 23:15:42 +02:00
2019-10-10 12:11:04 +02:00
if ( p_input_vars [ 1 ] = = String ( ) ) {
2020-01-27 10:10:51 +01:00
code + = " \t \t vec4 _tex_read = texture(TEXTURE , UV.xy); \n " ;
2019-10-10 12:11:04 +02:00
} else {
2020-01-27 10:10:51 +01:00
code + = " \t \t vec4 _tex_read = textureLod(TEXTURE, UV.xy, " + p_input_vars [ 1 ] + " ); \n " ;
2019-10-10 12:11:04 +02:00
}
2018-07-14 23:15:42 +02:00
} else if ( p_input_vars [ 1 ] = = String ( ) ) {
//no lod
2020-01-27 10:10:51 +01:00
code + = " \t \t vec4 _tex_read = texture(TEXTURE, " + p_input_vars [ 0 ] + " .xy); \n " ;
2018-07-14 23:15:42 +02:00
} else {
2020-01-27 10:10:51 +01:00
code + = " \t \t vec4 _tex_read = textureLod(TEXTURE, " + p_input_vars [ 0 ] + " .xy, " + p_input_vars [ 1 ] + " ); \n " ;
2018-07-14 23:15:42 +02:00
}
code + = " \t \t " + p_output_vars [ 0 ] + " = _tex_read.rgb; \n " ;
code + = " \t \t " + p_output_vars [ 1 ] + " = _tex_read.a; \n " ;
code + = " \t } \n " ;
return code ;
}
if ( source = = SOURCE_2D_NORMAL & & p_mode = = Shader : : MODE_CANVAS_ITEM & & p_type = = VisualShader : : TYPE_FRAGMENT ) {
String code = " \t { \n " ;
2019-10-03 09:40:26 +02:00
if ( p_input_vars [ 0 ] = = String ( ) ) { // Use UV by default.
2018-07-14 23:15:42 +02:00
2019-10-10 12:11:04 +02:00
if ( p_input_vars [ 1 ] = = String ( ) ) {
2020-01-27 10:10:51 +01:00
code + = " \t \t vec4 _tex_read = texture(NORMAL_TEXTURE, UV.xy); \n " ;
2019-10-10 12:11:04 +02:00
} else {
2020-01-27 10:10:51 +01:00
code + = " \t \t vec4 _tex_read = textureLod(NORMAL_TEXTURE, UV.xy, " + p_input_vars [ 1 ] + " ); \n " ;
2019-10-10 12:11:04 +02:00
}
2018-07-14 23:15:42 +02:00
} else if ( p_input_vars [ 1 ] = = String ( ) ) {
//no lod
2020-01-27 10:10:51 +01:00
code + = " \t \t vec4 _tex_read = texture(NORMAL_TEXTURE, " + p_input_vars [ 0 ] + " .xy); \n " ;
2018-07-14 23:15:42 +02:00
} else {
2020-01-27 10:10:51 +01:00
code + = " \t \t vec4 _tex_read = textureLod(NORMAL_TEXTURE, " + p_input_vars [ 0 ] + " .xy, " + p_input_vars [ 1 ] + " ); \n " ;
2018-07-14 23:15:42 +02:00
}
code + = " \t \t " + p_output_vars [ 0 ] + " = _tex_read.rgb; \n " ;
code + = " \t \t " + p_output_vars [ 1 ] + " = _tex_read.a; \n " ;
code + = " \t } \n " ;
return code ;
}
2019-07-05 10:48:31 +02:00
if ( p_for_preview ) // DEPTH_TEXTURE is not supported in preview(canvas_item) shader
{
if ( source = = SOURCE_DEPTH ) {
String code ;
code + = " \t " + p_output_vars [ 0 ] + " = 0.0; \n " ;
code + = " \t " + p_output_vars [ 1 ] + " = 1.0; \n " ;
return code ;
}
}
if ( source = = SOURCE_DEPTH & & p_mode = = Shader : : MODE_SPATIAL & & p_type = = VisualShader : : TYPE_FRAGMENT ) {
String code = " \t { \n " ;
2019-10-03 09:40:26 +02:00
if ( p_input_vars [ 0 ] = = String ( ) ) { // Use UV by default.
2019-07-05 10:48:31 +02:00
2019-10-10 12:11:04 +02:00
if ( p_input_vars [ 1 ] = = String ( ) ) {
2020-01-27 10:10:51 +01:00
code + = " \t \t float _depth = texture(DEPTH_TEXTURE, UV.xy).r; \n " ;
2019-10-10 12:11:04 +02:00
} else {
2020-01-27 10:10:51 +01:00
code + = " \t \t float _depth = textureLod(DEPTH_TEXTURE, UV.xy, " + p_input_vars [ 1 ] + " ).r; \n " ;
2019-10-10 12:11:04 +02:00
}
2019-07-05 10:48:31 +02:00
} else if ( p_input_vars [ 1 ] = = String ( ) ) {
//no lod
2020-01-27 10:10:51 +01:00
code + = " \t \t float _depth = texture(DEPTH_TEXTURE, " + p_input_vars [ 0 ] + " .xy).r; \n " ;
2019-07-05 10:48:31 +02:00
} else {
2020-01-27 10:10:51 +01:00
code + = " \t \t float _depth = textureLod(DEPTH_TEXTURE, " + p_input_vars [ 0 ] + " .xy, " + p_input_vars [ 1 ] + " ).r; \n " ;
2019-07-05 10:48:31 +02:00
}
code + = " \t \t " + p_output_vars [ 0 ] + " = _depth; \n " ;
code + = " \t \t " + p_output_vars [ 1 ] + " = 1.0; \n " ;
code + = " \t } \n " ;
return code ;
} else if ( source = = SOURCE_DEPTH ) {
String code ;
code + = " \t " + p_output_vars [ 0 ] + " = 0.0; \n " ;
code + = " \t " + p_output_vars [ 1 ] + " = 1.0; \n " ;
return code ;
}
2018-07-14 23:15:42 +02:00
//none
String code ;
code + = " \t " + p_output_vars [ 0 ] + " = vec3(0.0); \n " ;
code + = " \t " + p_output_vars [ 1 ] + " = 1.0; \n " ;
return code ;
}
void VisualShaderNodeTexture : : set_source ( Source p_source ) {
source = p_source ;
2020-01-27 10:10:51 +01:00
switch ( source ) {
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 ;
}
2018-07-14 23:15:42 +02:00
emit_changed ( ) ;
emit_signal ( " editor_refresh_request " ) ;
}
VisualShaderNodeTexture : : Source VisualShaderNodeTexture : : get_source ( ) const {
return source ;
}
2019-06-11 20:43:37 +02:00
void VisualShaderNodeTexture : : set_texture ( Ref < Texture2D > p_value ) {
2018-07-14 23:15:42 +02:00
texture = p_value ;
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 ;
}
void VisualShaderNodeTexture : : set_texture_type ( TextureType p_type ) {
texture_type = p_type ;
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 {
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
return TTR ( " Invalid source for preview. " ) ;
}
return String ( ) ; // all good
}
2018-07-14 23:15:42 +02:00
return TTR ( " Invalid source for shader. " ) ;
}
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 " ) ;
2018-07-14 23:15:42 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " texture_type " , PROPERTY_HINT_ENUM , " Data,Color,Normalmap " ) , " set_texture_type " , " get_texture_type " ) ;
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 ) ;
2018-07-14 23:15:42 +02:00
BIND_ENUM_CONSTANT ( TYPE_DATA ) ;
BIND_ENUM_CONSTANT ( TYPE_COLOR ) ;
BIND_ENUM_CONSTANT ( TYPE_NORMALMAP ) ;
}
VisualShaderNodeTexture : : VisualShaderNodeTexture ( ) {
texture_type = TYPE_DATA ;
source = SOURCE_TEXTURE ;
}
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 :
return PORT_TYPE_VECTOR ;
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 {
2018-07-14 23:15:42 +02:00
return 2 ;
}
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 {
2018-07-14 23:15:42 +02:00
return p_port = = 0 ? PORT_TYPE_VECTOR : PORT_TYPE_SCALAR ;
}
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 {
2018-07-14 23:15:42 +02:00
return p_port = = 0 ? " rgb " : " alpha " ;
}
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 " ) ;
dtp . param = cube_map ;
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 :
u + = " : hint_albedo " ;
break ;
case TYPE_NORMALMAP :
u + = " : hint_normal " ;
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 {
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 {
return String ( ) ;
}
2020-01-27 10:17:06 +01:00
code + = " \t { \n " ;
2019-10-11 09:26:57 +02:00
if ( id = = String ( ) ) {
2020-01-27 10:17:06 +01:00
code + = " \t \t vec4 " + id + " _read = vec4(0.0); \n " ;
code + = " \t \t " + p_output_vars [ 0 ] + " = " + id + " _read.rgb; \n " ;
code + = " \t \t " + p_output_vars [ 1 ] + " = " + id + " _read.a; \n " ;
2020-01-27 11:09:15 +01:00
code + = " \t } \n " ;
2019-10-11 09:26:57 +02:00
return code ;
}
2019-10-09 10:29:23 +02:00
if ( p_input_vars [ 0 ] = = String ( ) ) { // Use UV by default.
2018-07-14 23:15:42 +02:00
2019-10-10 12:11:04 +02:00
if ( p_input_vars [ 1 ] = = String ( ) ) {
2020-01-27 10:10:51 +01:00
code + = " \t \t vec4 " + id + " _read = texture( " + id + " , vec3(UV, 0.0)); \n " ;
2019-10-10 12:11:04 +02:00
} else {
2020-01-27 10:10:51 +01:00
code + = " \t \t vec4 " + id + " _read = textureLod( " + id + " , vec3(UV, 0.0) " + " , " + p_input_vars [ 1 ] + " ); \n " ;
2019-10-10 12:11:04 +02:00
}
2018-07-14 23:15:42 +02:00
} else if ( p_input_vars [ 1 ] = = String ( ) ) {
//no lod
2020-01-27 10:10:51 +01:00
code + = " \t \t vec4 " + id + " _read = texture( " + id + " , " + p_input_vars [ 0 ] + " ); \n " ;
2018-07-14 23:15:42 +02:00
} else {
2020-01-27 10:10:51 +01:00
code + = " \t \t vec4 " + id + " _read = textureLod( " + id + " , " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
2018-07-14 23:15:42 +02:00
}
2020-01-27 10:17:06 +01:00
code + = " \t \t " + p_output_vars [ 0 ] + " = " + id + " _read.rgb; \n " ;
code + = " \t \t " + p_output_vars [ 1 ] + " = " + id + " _read.a; \n " ;
code + = " \t } \n " ;
2019-10-11 09:26:57 +02:00
2018-07-14 23:15:42 +02:00
return code ;
}
2019-06-11 20:43:37 +02:00
String VisualShaderNodeCubemap : : get_input_port_default_hint ( int p_port ) const {
2019-10-09 10:29:23 +02:00
if ( p_port = = 0 ) {
return " vec3(UV, 0.0) " ;
}
return " " ;
}
2019-06-11 20:43:37 +02:00
void VisualShaderNodeCubemap : : set_source ( Source p_source ) {
2019-10-11 09:26:57 +02:00
source = p_source ;
emit_changed ( ) ;
emit_signal ( " editor_refresh_request " ) ;
}
2019-06-11 20:43:37 +02:00
VisualShaderNodeCubemap : : Source VisualShaderNodeCubemap : : get_source ( ) const {
2019-10-11 09:26:57 +02:00
return source ;
}
2019-06-11 20:43:37 +02:00
void VisualShaderNodeCubemap : : set_cube_map ( Ref < Cubemap > p_value ) {
2018-07-14 23:15:42 +02:00
cube_map = p_value ;
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 ;
}
2019-06-11 20:43:37 +02:00
void VisualShaderNodeCubemap : : set_texture_type ( TextureType p_type ) {
2018-07-14 23:15:42 +02:00
texture_type = p_type ;
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 ;
}
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 " ) ;
2018-07-14 23:15:42 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " texture_type " , PROPERTY_HINT_ENUM , " Data,Color,Normalmap " ) , " 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 ) ;
2018-07-17 23:31:22 +02:00
BIND_ENUM_CONSTANT ( TYPE_DATA ) ;
BIND_ENUM_CONSTANT ( TYPE_COLOR ) ;
BIND_ENUM_CONSTANT ( TYPE_NORMALMAP ) ;
2018-07-14 23:15:42 +02:00
}
2019-06-11 20:43:37 +02:00
VisualShaderNodeCubemap : : VisualShaderNodeCubemap ( ) {
2018-07-14 23:15:42 +02:00
texture_type = TYPE_DATA ;
2019-11-01 16:16:31 +01:00
source = SOURCE_TEXTURE ;
2020-01-27 10:10:51 +01: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 {
2018-07-14 23:15:42 +02:00
String code = " \t " + p_output_vars [ 0 ] + " = " ;
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 ;
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 ) {
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
2019-02-22 18:38:58 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " operator " , PROPERTY_HINT_ENUM , " Add,Sub,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 ) ;
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
op = OP_ADD ;
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 {
String code = " \t " + p_output_vars [ 0 ] + " = " ;
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 ;
2020-02-25 15:50:49 +01:00
}
return code ;
}
void VisualShaderNodeIntOp : : set_operator ( Operator p_op ) {
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 ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " operator " , PROPERTY_HINT_ENUM , " Add,Sub,Multiply,Divide,Remainder,Max,Min " ) , " set_operator " , " get_operator " ) ;
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 ) ;
}
VisualShaderNodeIntOp : : VisualShaderNodeIntOp ( ) {
op = OP_ADD ;
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
VisualShaderNodeVectorOp : : PortType VisualShaderNodeVectorOp : : get_input_port_type ( int p_port ) const {
return PORT_TYPE_VECTOR ;
}
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
VisualShaderNodeVectorOp : : PortType VisualShaderNodeVectorOp : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_VECTOR ;
}
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 {
return " op " ; //no output port means the editor will be used as port
}
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 {
2018-07-14 23:15:42 +02:00
String code = " \t " + p_output_vars [ 0 ] + " = " ;
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 :
code + = " cross( " + 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_REFLECT :
code + = " reflect( " + 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 ;
2018-07-14 23:15:42 +02:00
}
return code ;
}
void VisualShaderNodeVectorOp : : set_operator ( Operator p_op ) {
op = p_op ;
emit_changed ( ) ;
}
VisualShaderNodeVectorOp : : Operator VisualShaderNodeVectorOp : : get_operator ( ) const {
return op ;
}
Vector < StringName > VisualShaderNodeVectorOp : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " operator " ) ;
return props ;
}
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 ) ;
2019-02-22 18:38:58 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " operator " , PROPERTY_HINT_ENUM , " Add,Sub,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 ) ;
2018-07-14 23:15:42 +02:00
}
VisualShaderNodeVectorOp : : VisualShaderNodeVectorOp ( ) {
op = OP_ADD ;
set_input_port_default_value ( 0 , Vector3 ( ) ) ;
set_input_port_default_value ( 1 , Vector3 ( ) ) ;
}
////////////// 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 {
return PORT_TYPE_VECTOR ;
}
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 {
return PORT_TYPE_VECTOR ;
}
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 : {
2020-01-27 10:10:51 +01:00
code + = " \t " + 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 : {
2020-01-27 10:10:51 +01:00
code + = " \t " + 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 : {
2020-01-27 10:10:51 +01:00
code + = " \t " + 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 : {
2020-01-27 10:10:51 +01:00
code + = " \t " + 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 + + ) {
code + = " \t { \n " ;
2020-01-27 10:10:51 +01:00
code + = " \t \t float base = " + p_input_vars [ 0 ] + " . " + axisn [ i ] + " ; \n " ;
code + = " \t \t float blend = " + p_input_vars [ 1 ] + " . " + axisn [ i ] + " ; \n " ;
2018-07-14 23:15:42 +02:00
code + = " \t \t if (base < 0.5) { \n " ;
code + = " \t \t \t " + p_output_vars [ 0 ] + " . " + axisn [ i ] + " = 2.0 * base * blend; \n " ;
code + = " \t \t } else { \n " ;
code + = " \t \t \t " + p_output_vars [ 0 ] + " . " + axisn [ i ] + " = 1.0 - 2.0 * (1.0 - blend) * (1.0 - base); \n " ;
code + = " \t \t } \n " ;
code + = " \t } \n " ;
}
} break ;
case OP_DODGE : {
2020-01-27 10:10:51 +01:00
code + = " \t " + 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 : {
2020-01-27 10:10:51 +01:00
code + = " \t " + 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 + + ) {
code + = " \t { \n " ;
2020-01-27 10:10:51 +01:00
code + = " \t \t float base = " + p_input_vars [ 0 ] + " . " + axisn [ i ] + " ; \n " ;
code + = " \t \t float blend = " + p_input_vars [ 1 ] + " . " + axisn [ i ] + " ; \n " ;
2018-07-14 23:15:42 +02:00
code + = " \t \t if (base < 0.5) { \n " ;
2020-01-27 10:10:51 +01:00
code + = " \t \t \t " + p_output_vars [ 0 ] + " . " + axisn [ i ] + " = (base * (blend + 0.5)); \n " ;
2018-07-14 23:15:42 +02:00
code + = " \t \t } else { \n " ;
2020-01-27 10:10:51 +01:00
code + = " \t \t \t " + p_output_vars [ 0 ] + " . " + axisn [ i ] + " = (1.0 - (1.0 - base) * (1.0 - (blend - 0.5))); \n " ;
2018-07-14 23:15:42 +02:00
code + = " \t \t } \n " ;
code + = " \t } \n " ;
}
} break ;
case OP_HARD_LIGHT : {
for ( int i = 0 ; i < 3 ; i + + ) {
code + = " \t { \n " ;
2020-01-27 10:10:51 +01:00
code + = " \t \t float base = " + p_input_vars [ 0 ] + " . " + axisn [ i ] + " ; \n " ;
code + = " \t \t float blend = " + p_input_vars [ 1 ] + " . " + axisn [ i ] + " ; \n " ;
2018-07-14 23:15:42 +02:00
code + = " \t \t if (base < 0.5) { \n " ;
2020-01-27 10:10:51 +01:00
code + = " \t \t \t " + p_output_vars [ 0 ] + " . " + axisn [ i ] + " = (base * (2.0 * blend)); \n " ;
2018-07-14 23:15:42 +02:00
code + = " \t \t } else { \n " ;
2020-01-27 10:10:51 +01:00
code + = " \t \t \t " + p_output_vars [ 0 ] + " . " + axisn [ i ] + " = (1.0 - (1.0 - base) * (1.0 - 2.0 * (blend - 0.5))); \n " ;
2018-07-14 23:15:42 +02:00
code + = " \t \t } \n " ;
code + = " \t } \n " ;
}
} break ;
}
return code ;
}
void VisualShaderNodeColorOp : : set_operator ( Operator p_op ) {
op = p_op ;
2020-01-27 10:10:51 +01:00
switch ( op ) {
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 ;
}
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 ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " operator " , PROPERTY_HINT_ENUM , " Screen,Difference,Darken,Lighten,Overlay,Dodge,Burn,SoftLight,HardLight " ) , " 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 ) ;
2018-07-14 23:15:42 +02:00
}
VisualShaderNodeColorOp : : VisualShaderNodeColorOp ( ) {
op = OP_SCREEN ;
set_input_port_default_value ( 0 , Vector3 ( ) ) ;
set_input_port_default_value ( 1 , Vector3 ( ) ) ;
}
////////////// Transform Mult
String VisualShaderNodeTransformMult : : get_caption ( ) const {
2018-07-15 16:28:06 +02:00
return " TransformMult " ;
2018-07-14 23:15:42 +02:00
}
int VisualShaderNodeTransformMult : : get_input_port_count ( ) const {
return 2 ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
VisualShaderNodeTransformMult : : PortType VisualShaderNodeTransformMult : : get_input_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 VisualShaderNodeTransformMult : : get_input_port_name ( int p_port ) const {
return p_port = = 0 ? " a " : " b " ;
}
int VisualShaderNodeTransformMult : : get_output_port_count ( ) const {
return 1 ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
VisualShaderNodeTransformMult : : PortType VisualShaderNodeTransformMult : : 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 VisualShaderNodeTransformMult : : get_output_port_name ( int p_port ) const {
return " mult " ; //no output port means the editor will be used as port
}
2019-01-21 20:07:53 +01:00
String VisualShaderNodeTransformMult : : 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 ) {
return " \t " + p_output_vars [ 0 ] + " = " + p_input_vars [ 0 ] + " * " + p_input_vars [ 1 ] + " ; \n " ;
2019-02-22 18:38:58 +01:00
} else if ( op = = OP_BxA ) {
2018-07-14 23:15:42 +02:00
return " \t " + p_output_vars [ 0 ] + " = " + p_input_vars [ 1 ] + " * " + p_input_vars [ 0 ] + " ; \n " ;
2019-02-22 18:38:58 +01:00
} else if ( op = = OP_AxB_COMP ) {
2020-01-27 10:10:51 +01:00
return " \t " + p_output_vars [ 0 ] + " = matrixCompMult( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
2019-02-22 18:38:58 +01:00
} else {
2020-01-27 10:10:51 +01:00
return " \t " + p_output_vars [ 0 ] + " = matrixCompMult( " + p_input_vars [ 1 ] + " , " + p_input_vars [ 0 ] + " ); \n " ;
2018-07-14 23:15:42 +02:00
}
}
void VisualShaderNodeTransformMult : : set_operator ( Operator p_op ) {
op = p_op ;
emit_changed ( ) ;
}
VisualShaderNodeTransformMult : : Operator VisualShaderNodeTransformMult : : get_operator ( ) const {
return op ;
}
Vector < StringName > VisualShaderNodeTransformMult : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " operator " ) ;
return props ;
}
void VisualShaderNodeTransformMult : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_operator " , " op " ) , & VisualShaderNodeTransformMult : : set_operator ) ;
ClassDB : : bind_method ( D_METHOD ( " get_operator " ) , & VisualShaderNodeTransformMult : : get_operator ) ;
2019-02-22 18:38:58 +01: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) " ) , " 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 ) ;
2018-07-14 23:15:42 +02:00
}
VisualShaderNodeTransformMult : : VisualShaderNodeTransformMult ( ) {
op = OP_AxB ;
set_input_port_default_value ( 0 , Transform ( ) ) ;
set_input_port_default_value ( 1 , Transform ( ) ) ;
}
////////////// 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 {
return p_port = = 0 ? PORT_TYPE_TRANSFORM : PORT_TYPE_VECTOR ;
}
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 {
return PORT_TYPE_VECTOR ;
}
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 ) {
2020-01-27 10:10:51 +01:00
return " \t " + 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 ) {
2020-01-27 10:10:51 +01:00
return " \t " + 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 ) {
2020-01-27 10:10:51 +01:00
return " \t " + 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 {
2020-01-27 10:10:51 +01:00
return " \t " + 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 ) {
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 ) ;
}
VisualShaderNodeTransformVecMult : : VisualShaderNodeTransformVecMult ( ) {
op = OP_AxB ;
set_input_port_default_value ( 0 , Transform ( ) ) ;
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 {
2019-05-19 12:07:00 +02:00
static const char * scalar_func_id [ FUNC_ONEMINUS + 1 ] = {
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
} ;
return " \t " + p_output_vars [ 0 ] + " = " + String ( scalar_func_id [ func ] ) . replace ( " $ " , p_input_vars [ 0 ] ) + " ; \n " ;
}
2020-02-25 15:50:49 +01:00
void VisualShaderNodeFloatFunc : : set_function ( Function p_func ) {
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
2019-05-19 12:07:00 +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,Frac,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 ) ;
BIND_ENUM_CONSTANT ( FUNC_FRAC ) ;
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 ) ;
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
func = FUNC_SIGN ;
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 {
if ( func = = FUNC_CLAMP ) {
return 3 ;
}
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 {
if ( func = = FUNC_CLAMP ) {
if ( p_port = = 0 ) {
return " " ;
} else if ( p_port = = 1 ) {
return " min " ;
} else if ( p_port = = 2 ) {
return " max " ;
}
}
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 {
if ( func = = FUNC_CLAMP ) {
return " \t " + p_output_vars [ 0 ] + " = clamp( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " , " + p_input_vars [ 2 ] + " ); \n " ;
}
static const char * int_func_id [ FUNC_SIGN + 1 ] = {
" abs($) " ,
" " ,
" -($) " ,
" sign($) "
} ;
return " \t " + p_output_vars [ 0 ] + " = " + String ( int_func_id [ func ] ) . replace ( " $ " , p_input_vars [ 0 ] ) + " ; \n " ;
}
void VisualShaderNodeIntFunc : : set_function ( Function p_func ) {
if ( func ! = p_func ) {
if ( p_func = = FUNC_CLAMP ) {
set_input_port_default_value ( 1 , 0 ) ;
set_input_port_default_value ( 2 , 0 ) ;
}
}
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 ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " function " , PROPERTY_HINT_ENUM , " Abs,Clamp,Negate,Sign " ) , " set_function " , " get_function " ) ;
BIND_ENUM_CONSTANT ( FUNC_ABS ) ;
BIND_ENUM_CONSTANT ( FUNC_CLAMP ) ;
BIND_ENUM_CONSTANT ( FUNC_NEGATE ) ;
BIND_ENUM_CONSTANT ( FUNC_SIGN ) ;
}
VisualShaderNodeIntFunc : : VisualShaderNodeIntFunc ( ) {
func = FUNC_SIGN ;
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
VisualShaderNodeVectorFunc : : PortType VisualShaderNodeVectorFunc : : get_input_port_type ( int p_port ) const {
return PORT_TYPE_VECTOR ;
}
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
VisualShaderNodeVectorFunc : : PortType VisualShaderNodeVectorFunc : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_VECTOR ;
}
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 {
return " " ; //no output port means the editor will be used as port
}
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 {
2019-05-19 12:07:00 +02:00
static const char * vec_func_id [ FUNC_ONEMINUS + 1 ] = {
2018-07-14 23:15:42 +02:00
" normalize($) " ,
2020-01-27 10:10:51 +01:00
" max(min($, vec3(1.0)), vec3(0.0)) " ,
2018-07-14 23:15:42 +02:00
" -($) " ,
2020-01-27 10:10:51 +01:00
" 1.0 / ($) " ,
2018-07-14 23:15:42 +02:00
" " ,
" " ,
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($) " ,
2020-01-27 10:10:51 +01:00
" vec3(1.0, 1.0, 1.0) - $ "
2018-07-14 23:15:42 +02:00
} ;
String code ;
if ( func = = FUNC_RGB2HSV ) {
code + = " \t { \n " ;
code + = " \t \t vec3 c = " + p_input_vars [ 0 ] + " ; \n " ;
code + = " \t \t vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); \n " ;
code + = " \t \t vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); \n " ;
code + = " \t \t vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); \n " ;
code + = " \t \t float d = q.x - min(q.w, q.y); \n " ;
code + = " \t \t float e = 1.0e-10; \n " ;
2020-01-27 10:10:51 +01:00
code + = " \t \t " + p_output_vars [ 0 ] + " = vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); \n " ;
2018-07-14 23:15:42 +02:00
code + = " \t } \n " ;
} else if ( func = = FUNC_HSV2RGB ) {
code + = " \t { \n " ;
code + = " \t \t vec3 c = " + p_input_vars [ 0 ] + " ; \n " ;
code + = " \t \t vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); \n " ;
code + = " \t \t vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); \n " ;
2020-01-27 10:10:51 +01:00
code + = " \t \t " + p_output_vars [ 0 ] + " = c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); \n " ;
2018-07-14 23:15:42 +02:00
code + = " \t } \n " ;
} else {
2020-01-27 10:10:51 +01:00
code + = " \t " + p_output_vars [ 0 ] + " = " + String ( vec_func_id [ func ] ) . replace ( " $ " , p_input_vars [ 0 ] ) + " ; \n " ;
2018-07-14 23:15:42 +02:00
}
return code ;
}
void VisualShaderNodeVectorFunc : : set_function ( Function p_func ) {
func = p_func ;
2020-01-27 10:10:51 +01:00
if ( func = = FUNC_RGB2HSV ) {
simple_decl = false ;
} else if ( func = = FUNC_HSV2RGB ) {
simple_decl = false ;
} else {
simple_decl = true ;
}
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 {
Vector < StringName > props ;
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 ) ;
2019-05-19 12:07:00 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " function " , PROPERTY_HINT_ENUM , " Normalize,Saturate,Negate,Reciprocal,RGB2HSV,HSV2RGB,Abs,ACos,ACosH,ASin,ASinH,ATan,ATanH,Ceil,Cos,CosH,Degrees,Exp,Exp2,Floor,Frac,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 ) ;
BIND_ENUM_CONSTANT ( FUNC_RGB2HSV ) ;
BIND_ENUM_CONSTANT ( FUNC_HSV2RGB ) ;
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 ) ;
BIND_ENUM_CONSTANT ( FUNC_FRAC ) ;
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 ) ;
2018-07-14 23:15:42 +02:00
}
VisualShaderNodeVectorFunc : : VisualShaderNodeVectorFunc ( ) {
func = FUNC_NORMALIZE ;
set_input_port_default_value ( 0 , Vector3 ( ) ) ;
}
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 {
return PORT_TYPE_VECTOR ;
}
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 {
return PORT_TYPE_VECTOR ;
}
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 :
code + = " \t { \n " ;
code + = " \t \t vec3 c = " + p_input_vars [ 0 ] + " ; \n " ;
code + = " \t \t float max1 = max(c.r, c.g); \n " ;
code + = " \t \t float max2 = max(max1, c.b); \n " ;
code + = " \t \t float max3 = max(max1, max2); \n " ;
code + = " \t \t " + p_output_vars [ 0 ] + " = vec3(max3, max3, max3); \n " ;
code + = " \t } \n " ;
break ;
case FUNC_SEPIA :
code + = " \t { \n " ;
code + = " \t \t vec3 c = " + p_input_vars [ 0 ] + " ; \n " ;
code + = " \t \t float r = (c.r * .393) + (c.g *.769) + (c.b * .189); \n " ;
code + = " \t \t float g = (c.r * .349) + (c.g *.686) + (c.b * .168); \n " ;
code + = " \t \t float b = (c.r * .272) + (c.g *.534) + (c.b * .131); \n " ;
code + = " \t \t " + p_output_vars [ 0 ] + " = vec3(r, g, b); \n " ;
code + = " \t } \n " ;
break ;
}
return code ;
}
void VisualShaderNodeColorFunc : : set_function ( Function p_func ) {
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 ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " function " , PROPERTY_HINT_ENUM , " Grayscale,Sepia " ) , " set_function " , " get_function " ) ;
BIND_ENUM_CONSTANT ( FUNC_GRAYSCALE ) ;
BIND_ENUM_CONSTANT ( FUNC_SEPIA ) ;
}
VisualShaderNodeColorFunc : : VisualShaderNodeColorFunc ( ) {
func = FUNC_GRAYSCALE ;
set_input_port_default_value ( 0 , Vector3 ( ) ) ;
2020-01-27 10:10:51 +01:00
simple_decl = false ;
2019-02-22 18:38:58 +01:00
}
////////////// 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 {
static const char * funcs [ FUNC_TRANSPOSE + 1 ] = {
" inverse($) " ,
" transpose($) "
} ;
String code ;
2020-01-27 10:10:51 +01:00
code + = " \t " + p_output_vars [ 0 ] + " = " + String ( funcs [ func ] ) . replace ( " $ " , p_input_vars [ 0 ] ) + " ; \n " ;
2019-02-22 18:38:58 +01:00
return code ;
}
void VisualShaderNodeTransformFunc : : set_function ( Function p_func ) {
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 ) ;
}
VisualShaderNodeTransformFunc : : VisualShaderNodeTransformFunc ( ) {
func = FUNC_INVERSE ;
set_input_port_default_value ( 0 , Transform ( ) ) ;
}
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 {
return PORT_TYPE_VECTOR ;
}
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 {
2020-01-27 10:10:51 +01:00
return " \t " + 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
VisualShaderNodeVectorLen : : PortType VisualShaderNodeVectorLen : : get_input_port_type ( int p_port ) const {
return PORT_TYPE_VECTOR ;
}
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 " ;
}
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 {
2020-01-27 10:10:51 +01:00
return " \t " + p_output_vars [ 0 ] + " = length( " + p_input_vars [ 0 ] + " ); \n " ;
2018-07-14 23:15:42 +02:00
}
VisualShaderNodeVectorLen : : VisualShaderNodeVectorLen ( ) {
set_input_port_default_value ( 0 , Vector3 ( ) ) ;
}
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 {
2020-01-27 10:10:51 +01:00
return " \t " + 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 ( ) {
set_input_port_default_value ( 0 , Transform ( ) ) ;
2018-07-14 23:15:42 +02:00
}
2019-02-22 18:38:58 +01:00
////////////// Scalar Derivative Function
2018-07-14 23:15:42 +02:00
2019-02-22 18:38:58 +01:00
String VisualShaderNodeScalarDerivativeFunc : : get_caption ( ) const {
return " ScalarDerivativeFunc " ;
2018-07-14 23:15:42 +02:00
}
2019-02-22 18:38:58 +01:00
int VisualShaderNodeScalarDerivativeFunc : : get_input_port_count ( ) const {
return 1 ;
2018-07-14 23:15:42 +02:00
}
2019-02-22 18:38:58 +01:00
VisualShaderNodeScalarDerivativeFunc : : PortType VisualShaderNodeScalarDerivativeFunc : : get_input_port_type ( int p_port ) const {
return PORT_TYPE_SCALAR ;
2018-07-14 23:15:42 +02:00
}
2019-02-22 18:38:58 +01:00
String VisualShaderNodeScalarDerivativeFunc : : 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 VisualShaderNodeScalarDerivativeFunc : : get_output_port_count ( ) const {
2018-07-14 23:15:42 +02:00
return 1 ;
}
2019-02-22 18:38:58 +01:00
VisualShaderNodeScalarDerivativeFunc : : PortType VisualShaderNodeScalarDerivativeFunc : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_SCALAR ;
2018-07-14 23:15:42 +02:00
}
2019-02-22 18:38:58 +01:00
String VisualShaderNodeScalarDerivativeFunc : : 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 VisualShaderNodeScalarDerivativeFunc : : 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 {
static const char * funcs [ FUNC_Y + 1 ] = {
" fwidth($) " ,
" dFdx($) " ,
" dFdy($) "
} ;
String code ;
2020-01-27 10:10:51 +01:00
code + = " \t " + p_output_vars [ 0 ] + " = " + String ( funcs [ func ] ) . replace ( " $ " , p_input_vars [ 0 ] ) + " ; \n " ;
2019-02-22 18:38:58 +01:00
return code ;
}
void VisualShaderNodeScalarDerivativeFunc : : set_function ( Function p_func ) {
func = p_func ;
emit_changed ( ) ;
}
VisualShaderNodeScalarDerivativeFunc : : Function VisualShaderNodeScalarDerivativeFunc : : get_function ( ) const {
return func ;
}
Vector < StringName > VisualShaderNodeScalarDerivativeFunc : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " function " ) ;
return props ;
}
void VisualShaderNodeScalarDerivativeFunc : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_function " , " func " ) , & VisualShaderNodeScalarDerivativeFunc : : set_function ) ;
ClassDB : : bind_method ( D_METHOD ( " get_function " ) , & VisualShaderNodeScalarDerivativeFunc : : get_function ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " function " , PROPERTY_HINT_ENUM , " Sum,X,Y " ) , " set_function " , " get_function " ) ;
BIND_ENUM_CONSTANT ( FUNC_SUM ) ;
BIND_ENUM_CONSTANT ( FUNC_X ) ;
BIND_ENUM_CONSTANT ( FUNC_Y ) ;
}
VisualShaderNodeScalarDerivativeFunc : : VisualShaderNodeScalarDerivativeFunc ( ) {
func = FUNC_SUM ;
set_input_port_default_value ( 0 , 0.0 ) ;
}
////////////// Vector Derivative Function
String VisualShaderNodeVectorDerivativeFunc : : get_caption ( ) const {
return " VectorDerivativeFunc " ;
}
int VisualShaderNodeVectorDerivativeFunc : : get_input_port_count ( ) const {
return 1 ;
}
VisualShaderNodeVectorDerivativeFunc : : PortType VisualShaderNodeVectorDerivativeFunc : : get_input_port_type ( int p_port ) const {
return PORT_TYPE_VECTOR ;
}
String VisualShaderNodeVectorDerivativeFunc : : get_input_port_name ( int p_port ) const {
return " " ;
}
int VisualShaderNodeVectorDerivativeFunc : : get_output_port_count ( ) const {
return 1 ;
}
2019-09-18 18:04:40 +02:00
VisualShaderNodeVectorDerivativeFunc : : PortType VisualShaderNodeVectorDerivativeFunc : : get_output_port_type ( int p_port ) const {
2019-02-22 18:38:58 +01:00
return PORT_TYPE_VECTOR ;
}
String VisualShaderNodeVectorDerivativeFunc : : get_output_port_name ( int p_port ) const {
return " " ;
}
String VisualShaderNodeVectorDerivativeFunc : : 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 {
static const char * funcs [ FUNC_Y + 1 ] = {
" fwidth($) " ,
" dFdx($) " ,
" dFdy($) "
} ;
String code ;
2020-01-27 10:10:51 +01:00
code + = " \t " + p_output_vars [ 0 ] + " = " + String ( funcs [ func ] ) . replace ( " $ " , p_input_vars [ 0 ] ) + " ; \n " ;
2019-02-22 18:38:58 +01:00
return code ;
}
void VisualShaderNodeVectorDerivativeFunc : : set_function ( Function p_func ) {
func = p_func ;
emit_changed ( ) ;
}
VisualShaderNodeVectorDerivativeFunc : : Function VisualShaderNodeVectorDerivativeFunc : : get_function ( ) const {
return func ;
}
Vector < StringName > VisualShaderNodeVectorDerivativeFunc : : get_editable_properties ( ) const {
Vector < StringName > props ;
props . push_back ( " function " ) ;
return props ;
}
void VisualShaderNodeVectorDerivativeFunc : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_function " , " func " ) , & VisualShaderNodeVectorDerivativeFunc : : set_function ) ;
ClassDB : : bind_method ( D_METHOD ( " get_function " ) , & VisualShaderNodeVectorDerivativeFunc : : get_function ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " function " , PROPERTY_HINT_ENUM , " Sum,X,Y " ) , " set_function " , " get_function " ) ;
BIND_ENUM_CONSTANT ( FUNC_SUM ) ;
BIND_ENUM_CONSTANT ( FUNC_X ) ;
BIND_ENUM_CONSTANT ( FUNC_Y ) ;
}
VisualShaderNodeVectorDerivativeFunc : : VisualShaderNodeVectorDerivativeFunc ( ) {
func = FUNC_SUM ;
set_input_port_default_value ( 0 , Vector3 ( ) ) ;
}
////////////// Scalar Clamp
String VisualShaderNodeScalarClamp : : get_caption ( ) const {
return " ScalarClamp " ;
}
int VisualShaderNodeScalarClamp : : get_input_port_count ( ) const {
return 3 ;
}
VisualShaderNodeScalarClamp : : PortType VisualShaderNodeScalarClamp : : get_input_port_type ( int p_port ) const {
return PORT_TYPE_SCALAR ;
}
String VisualShaderNodeScalarClamp : : 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 " " ;
}
int VisualShaderNodeScalarClamp : : get_output_port_count ( ) const {
return 1 ;
}
VisualShaderNodeScalarClamp : : PortType VisualShaderNodeScalarClamp : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_SCALAR ;
}
String VisualShaderNodeScalarClamp : : get_output_port_name ( int p_port ) const {
return " " ;
}
String VisualShaderNodeScalarClamp : : 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-01-27 10:10:51 +01:00
return " \t " + 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
}
VisualShaderNodeScalarClamp : : VisualShaderNodeScalarClamp ( ) {
set_input_port_default_value ( 0 , 0.0 ) ;
set_input_port_default_value ( 1 , 0.0 ) ;
set_input_port_default_value ( 2 , 1.0 ) ;
}
////////////// Vector Clamp
String VisualShaderNodeVectorClamp : : get_caption ( ) const {
return " VectorClamp " ;
}
int VisualShaderNodeVectorClamp : : get_input_port_count ( ) const {
return 3 ;
}
VisualShaderNodeVectorClamp : : PortType VisualShaderNodeVectorClamp : : get_input_port_type ( int p_port ) const {
return PORT_TYPE_VECTOR ;
}
String VisualShaderNodeVectorClamp : : 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 " " ;
}
int VisualShaderNodeVectorClamp : : get_output_port_count ( ) const {
return 1 ;
}
VisualShaderNodeVectorClamp : : PortType VisualShaderNodeVectorClamp : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_VECTOR ;
}
String VisualShaderNodeVectorClamp : : get_output_port_name ( int p_port ) const {
return " " ;
}
String VisualShaderNodeVectorClamp : : 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-01-27 10:10:51 +01:00
return " \t " + 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
}
VisualShaderNodeVectorClamp : : VisualShaderNodeVectorClamp ( ) {
set_input_port_default_value ( 0 , Vector3 ( 0 , 0 , 0 ) ) ;
set_input_port_default_value ( 1 , Vector3 ( 0 , 0 , 0 ) ) ;
set_input_port_default_value ( 2 , Vector3 ( 1 , 1 , 1 ) ) ;
}
////////////// FaceForward
String VisualShaderNodeFaceForward : : get_caption ( ) const {
return " FaceForward " ;
}
int VisualShaderNodeFaceForward : : get_input_port_count ( ) const {
return 3 ;
}
VisualShaderNodeFaceForward : : PortType VisualShaderNodeFaceForward : : get_input_port_type ( int p_port ) const {
return PORT_TYPE_VECTOR ;
}
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 ;
}
VisualShaderNodeFaceForward : : PortType VisualShaderNodeFaceForward : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_VECTOR ;
}
String VisualShaderNodeFaceForward : : get_output_port_name ( int p_port ) const {
return " " ;
}
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 {
2020-01-27 10:10:51 +01:00
return " \t " + 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 {
2019-02-22 18:38:58 +01:00
return PORT_TYPE_VECTOR ;
}
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 {
2020-01-27 10:10:51 +01:00
return " \t " + 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 ) ) ;
}
////////////// Vector-Scalar Step
String VisualShaderNodeVectorScalarStep : : get_caption ( ) const {
return " VectorScalarStep " ;
}
int VisualShaderNodeVectorScalarStep : : get_input_port_count ( ) const {
return 2 ;
}
VisualShaderNodeVectorScalarStep : : PortType VisualShaderNodeVectorScalarStep : : get_input_port_type ( int p_port ) const {
if ( p_port = = 0 ) {
return PORT_TYPE_SCALAR ;
}
return PORT_TYPE_VECTOR ;
}
String VisualShaderNodeVectorScalarStep : : 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 " edge " ;
2020-05-14 16:41:43 +02:00
} else if ( p_port = = 1 ) {
2019-02-22 18:38:58 +01:00
return " x " ;
2020-05-14 16:41:43 +02:00
}
2019-02-22 18:38:58 +01:00
return " " ;
}
int VisualShaderNodeVectorScalarStep : : get_output_port_count ( ) const {
return 1 ;
}
2019-09-18 18:04:40 +02:00
VisualShaderNodeVectorScalarStep : : PortType VisualShaderNodeVectorScalarStep : : get_output_port_type ( int p_port ) const {
2019-02-22 18:38:58 +01:00
return PORT_TYPE_VECTOR ;
}
String VisualShaderNodeVectorScalarStep : : get_output_port_name ( int p_port ) const {
return " " ;
}
String VisualShaderNodeVectorScalarStep : : 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-01-27 10:10:51 +01:00
return " \t " + p_output_vars [ 0 ] + " = step( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
2019-02-22 18:38:58 +01:00
}
VisualShaderNodeVectorScalarStep : : VisualShaderNodeVectorScalarStep ( ) {
set_input_port_default_value ( 0 , 0.0 ) ;
set_input_port_default_value ( 1 , Vector3 ( 0.0 , 0.0 , 0.0 ) ) ;
}
////////////// Scalar SmoothStep
String VisualShaderNodeScalarSmoothStep : : get_caption ( ) const {
return " ScalarSmoothStep " ;
}
int VisualShaderNodeScalarSmoothStep : : get_input_port_count ( ) const {
return 3 ;
}
VisualShaderNodeScalarSmoothStep : : PortType VisualShaderNodeScalarSmoothStep : : get_input_port_type ( int p_port ) const {
return PORT_TYPE_SCALAR ;
}
String VisualShaderNodeScalarSmoothStep : : 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 " edge0 " ;
2020-05-14 16:41:43 +02:00
} else if ( p_port = = 1 ) {
2019-02-22 18:38:58 +01:00
return " edge1 " ;
2020-05-14 16:41:43 +02:00
} else if ( p_port = = 2 ) {
2019-02-22 18:38:58 +01:00
return " x " ;
2020-05-14 16:41:43 +02:00
}
2019-02-22 18:38:58 +01:00
return " " ;
}
int VisualShaderNodeScalarSmoothStep : : get_output_port_count ( ) const {
return 1 ;
}
VisualShaderNodeScalarSmoothStep : : PortType VisualShaderNodeScalarSmoothStep : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_SCALAR ;
}
String VisualShaderNodeScalarSmoothStep : : get_output_port_name ( int p_port ) const {
return " " ;
}
String VisualShaderNodeScalarSmoothStep : : 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-01-27 10:10:51 +01:00
return " \t " + 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
}
VisualShaderNodeScalarSmoothStep : : VisualShaderNodeScalarSmoothStep ( ) {
set_input_port_default_value ( 0 , 0.0 ) ;
set_input_port_default_value ( 1 , 0.0 ) ;
set_input_port_default_value ( 2 , 0.0 ) ;
}
////////////// Vector SmoothStep
String VisualShaderNodeVectorSmoothStep : : get_caption ( ) const {
return " VectorSmoothStep " ;
}
int VisualShaderNodeVectorSmoothStep : : get_input_port_count ( ) const {
return 3 ;
}
VisualShaderNodeVectorSmoothStep : : PortType VisualShaderNodeVectorSmoothStep : : get_input_port_type ( int p_port ) const {
return PORT_TYPE_VECTOR ;
}
String VisualShaderNodeVectorSmoothStep : : 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 " edge0 " ;
2020-05-14 16:41:43 +02:00
} else if ( p_port = = 1 ) {
2019-02-22 18:38:58 +01:00
return " edge1 " ;
2020-05-14 16:41:43 +02:00
} else if ( p_port = = 2 ) {
2019-02-22 18:38:58 +01:00
return " x " ;
2020-05-14 16:41:43 +02:00
}
2019-02-22 18:38:58 +01:00
return " " ;
}
int VisualShaderNodeVectorSmoothStep : : get_output_port_count ( ) const {
return 1 ;
}
2019-09-18 18:04:40 +02:00
VisualShaderNodeVectorSmoothStep : : PortType VisualShaderNodeVectorSmoothStep : : get_output_port_type ( int p_port ) const {
2019-02-22 18:38:58 +01:00
return PORT_TYPE_VECTOR ;
}
String VisualShaderNodeVectorSmoothStep : : get_output_port_name ( int p_port ) const {
return " " ;
}
String VisualShaderNodeVectorSmoothStep : : 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-01-27 10:10:51 +01:00
return " \t " + 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
}
VisualShaderNodeVectorSmoothStep : : VisualShaderNodeVectorSmoothStep ( ) {
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 ) ) ;
}
////////////// Vector-Scalar SmoothStep
String VisualShaderNodeVectorScalarSmoothStep : : get_caption ( ) const {
return " VectorScalarSmoothStep " ;
}
int VisualShaderNodeVectorScalarSmoothStep : : get_input_port_count ( ) const {
return 3 ;
}
VisualShaderNodeVectorScalarSmoothStep : : PortType VisualShaderNodeVectorScalarSmoothStep : : get_input_port_type ( int p_port ) const {
if ( p_port = = 0 ) {
return PORT_TYPE_SCALAR ;
} else if ( p_port = = 1 ) {
return PORT_TYPE_SCALAR ;
}
return PORT_TYPE_VECTOR ;
}
String VisualShaderNodeVectorScalarSmoothStep : : 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 " edge0 " ;
2020-05-14 16:41:43 +02:00
} else if ( p_port = = 1 ) {
2019-02-22 18:38:58 +01:00
return " edge1 " ;
2020-05-14 16:41:43 +02:00
} else if ( p_port = = 2 ) {
2019-02-22 18:38:58 +01:00
return " x " ;
2020-05-14 16:41:43 +02:00
}
2019-02-22 18:38:58 +01:00
return " " ;
}
int VisualShaderNodeVectorScalarSmoothStep : : get_output_port_count ( ) const {
return 1 ;
}
2019-09-18 18:04:40 +02:00
VisualShaderNodeVectorScalarSmoothStep : : PortType VisualShaderNodeVectorScalarSmoothStep : : get_output_port_type ( int p_port ) const {
2019-02-22 18:38:58 +01:00
return PORT_TYPE_VECTOR ;
}
String VisualShaderNodeVectorScalarSmoothStep : : get_output_port_name ( int p_port ) const {
return " " ;
}
String VisualShaderNodeVectorScalarSmoothStep : : 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-01-27 10:10:51 +01:00
return " \t " + 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
}
VisualShaderNodeVectorScalarSmoothStep : : VisualShaderNodeVectorScalarSmoothStep ( ) {
set_input_port_default_value ( 0 , 0.0 ) ;
set_input_port_default_value ( 1 , 0.0 ) ;
set_input_port_default_value ( 2 , Vector3 ( 0.0 , 0.0 , 0.0 ) ) ;
}
////////////// Distance
String VisualShaderNodeVectorDistance : : get_caption ( ) const {
return " Distance " ;
}
int VisualShaderNodeVectorDistance : : get_input_port_count ( ) const {
return 2 ;
}
VisualShaderNodeVectorDistance : : PortType VisualShaderNodeVectorDistance : : get_input_port_type ( int p_port ) const {
return PORT_TYPE_VECTOR ;
}
String VisualShaderNodeVectorDistance : : get_input_port_name ( int p_port ) const {
if ( p_port = = 0 ) {
return " p0 " ;
} else if ( p_port = = 1 ) {
return " p1 " ;
}
return " " ;
}
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 " " ;
}
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 {
2020-01-27 10:10:51 +01:00
return " \t " + p_output_vars [ 0 ] + " = distance( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
2019-02-22 18:38:58 +01:00
}
VisualShaderNodeVectorDistance : : VisualShaderNodeVectorDistance ( ) {
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 ) ) ;
}
////////////// Refract Vector
String VisualShaderNodeVectorRefract : : get_caption ( ) const {
return " Refract " ;
}
int VisualShaderNodeVectorRefract : : get_input_port_count ( ) const {
return 3 ;
}
VisualShaderNodeVectorRefract : : PortType VisualShaderNodeVectorRefract : : get_input_port_type ( int p_port ) const {
if ( p_port = = 2 ) {
return PORT_TYPE_SCALAR ;
}
return PORT_TYPE_VECTOR ;
}
String VisualShaderNodeVectorRefract : : get_input_port_name ( int p_port ) const {
if ( p_port = = 0 ) {
return " I " ;
} else if ( p_port = = 1 ) {
return " N " ;
} else if ( p_port = = 2 ) {
return " eta " ;
}
return " " ;
}
int VisualShaderNodeVectorRefract : : get_output_port_count ( ) const {
return 1 ;
}
VisualShaderNodeVectorRefract : : PortType VisualShaderNodeVectorRefract : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_VECTOR ;
}
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 {
2020-01-27 10:10:51 +01:00
return " \t " + 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
}
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 ) ;
}
2019-08-03 17:12:33 +02:00
////////////// Scalar Mix
2019-02-22 18:38:58 +01:00
String VisualShaderNodeScalarInterp : : get_caption ( ) const {
2019-08-03 17:12:33 +02:00
return " ScalarMix " ;
2019-02-22 18:38:58 +01:00
}
int VisualShaderNodeScalarInterp : : get_input_port_count ( ) const {
return 3 ;
}
2019-08-03 17:12:33 +02:00
2019-02-22 18:38:58 +01:00
VisualShaderNodeScalarInterp : : PortType VisualShaderNodeScalarInterp : : get_input_port_type ( int p_port ) const {
return PORT_TYPE_SCALAR ;
}
2019-08-03 17:12:33 +02:00
2019-02-22 18:38:58 +01:00
String VisualShaderNodeScalarInterp : : get_input_port_name ( int p_port ) const {
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
}
}
int VisualShaderNodeScalarInterp : : get_output_port_count ( ) const {
return 1 ;
}
2019-08-03 17:12:33 +02:00
2019-02-22 18:38:58 +01:00
VisualShaderNodeScalarInterp : : PortType VisualShaderNodeScalarInterp : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_SCALAR ;
}
2019-08-03 17:12:33 +02:00
2019-02-22 18:38:58 +01:00
String VisualShaderNodeScalarInterp : : get_output_port_name ( int p_port ) const {
return " mix " ;
}
String VisualShaderNodeScalarInterp : : 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-01-27 10:10:51 +01:00
return " \t " + 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
}
VisualShaderNodeScalarInterp : : VisualShaderNodeScalarInterp ( ) {
set_input_port_default_value ( 0 , 0.0 ) ;
2019-08-03 17:12:33 +02:00
set_input_port_default_value ( 1 , 1.0 ) ;
set_input_port_default_value ( 2 , 0.5 ) ;
2019-02-22 18:38:58 +01:00
}
2019-08-03 17:12:33 +02:00
////////////// Vector Mix
2019-02-22 18:38:58 +01:00
String VisualShaderNodeVectorInterp : : get_caption ( ) const {
2019-08-03 17:12:33 +02:00
return " VectorMix " ;
2019-02-22 18:38:58 +01:00
}
int VisualShaderNodeVectorInterp : : get_input_port_count ( ) const {
return 3 ;
}
2019-08-03 17:12:33 +02:00
2019-02-22 18:38:58 +01:00
VisualShaderNodeVectorInterp : : PortType VisualShaderNodeVectorInterp : : get_input_port_type ( int p_port ) const {
return PORT_TYPE_VECTOR ;
}
2019-08-03 17:12:33 +02:00
2019-02-22 18:38:58 +01:00
String VisualShaderNodeVectorInterp : : get_input_port_name ( int p_port ) const {
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
}
}
int VisualShaderNodeVectorInterp : : get_output_port_count ( ) const {
return 1 ;
}
2019-08-03 17:12:33 +02:00
2019-02-22 18:38:58 +01:00
VisualShaderNodeVectorInterp : : PortType VisualShaderNodeVectorInterp : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_VECTOR ;
}
2019-08-03 17:12:33 +02:00
2019-02-22 18:38:58 +01:00
String VisualShaderNodeVectorInterp : : get_output_port_name ( int p_port ) const {
return " mix " ;
}
String VisualShaderNodeVectorInterp : : 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-01-27 10:10:51 +01:00
return " \t " + 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
}
VisualShaderNodeVectorInterp : : VisualShaderNodeVectorInterp ( ) {
2019-08-03 17:12:33 +02:00
set_input_port_default_value ( 0 , Vector3 ( 0.0 , 0.0 , 0.0 ) ) ;
set_input_port_default_value ( 1 , Vector3 ( 1.0 , 1.0 , 1.0 ) ) ;
set_input_port_default_value ( 2 , Vector3 ( 0.5 , 0.5 , 0.5 ) ) ;
}
////////////// Vector Mix (by scalar)
String VisualShaderNodeVectorScalarMix : : get_caption ( ) const {
return " VectorScalarMix " ;
}
int VisualShaderNodeVectorScalarMix : : get_input_port_count ( ) const {
return 3 ;
}
VisualShaderNodeVectorScalarMix : : PortType VisualShaderNodeVectorScalarMix : : get_input_port_type ( int p_port ) const {
2020-05-14 16:41:43 +02:00
if ( p_port = = 2 ) {
2019-08-03 17:12:33 +02:00
return PORT_TYPE_SCALAR ;
2020-05-14 16:41:43 +02:00
}
2019-08-03 17:12:33 +02:00
return PORT_TYPE_VECTOR ;
}
String VisualShaderNodeVectorScalarMix : : get_input_port_name ( int p_port ) const {
if ( p_port = = 0 ) {
return " a " ;
} else if ( p_port = = 1 ) {
return " b " ;
} else {
return " weight " ;
}
}
int VisualShaderNodeVectorScalarMix : : get_output_port_count ( ) const {
return 1 ;
}
VisualShaderNodeVectorScalarMix : : PortType VisualShaderNodeVectorScalarMix : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_VECTOR ;
}
String VisualShaderNodeVectorScalarMix : : get_output_port_name ( int p_port ) const {
return " mix " ;
}
String VisualShaderNodeVectorScalarMix : : 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-01-27 10:10:51 +01:00
return " \t " + p_output_vars [ 0 ] + " = mix( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " , " + p_input_vars [ 2 ] + " ); \n " ;
2019-08-03 17:12:33 +02:00
}
VisualShaderNodeVectorScalarMix : : VisualShaderNodeVectorScalarMix ( ) {
set_input_port_default_value ( 0 , Vector3 ( 0.0 , 0.0 , 0.0 ) ) ;
set_input_port_default_value ( 1 , Vector3 ( 1.0 , 1.0 , 1.0 ) ) ;
set_input_port_default_value ( 2 , 0.5 ) ;
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 {
2018-07-14 23:15:42 +02:00
return 3 ;
}
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 {
2018-07-14 23:15:42 +02:00
if ( p_port = = 0 ) {
return " x " ;
} else if ( p_port = = 1 ) {
return " y " ;
} else {
return " z " ;
}
}
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
VisualShaderNodeVectorCompose : : PortType VisualShaderNodeVectorCompose : : get_output_port_type ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return PORT_TYPE_VECTOR ;
}
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 " ;
}
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 {
2020-01-27 10:10:51 +01:00
return " \t " + p_output_vars [ 0 ] + " = vec3( " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " , " + p_input_vars [ 2 ] + " ); \n " ;
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 {
2018-07-14 23:15:42 +02:00
return PORT_TYPE_VECTOR ;
}
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 {
2020-01-27 10:10:51 +01:00
return " \t " + 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
VisualShaderNodeVectorDecompose : : PortType VisualShaderNodeVectorDecompose : : get_input_port_type ( int p_port ) const {
2018-07-14 23:15:42 +02:00
return PORT_TYPE_VECTOR ;
}
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 {
2018-07-14 23:15:42 +02:00
return 3 ;
}
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 {
2018-07-14 23:15:42 +02:00
if ( p_port = = 0 ) {
return " x " ;
} else if ( p_port = = 1 ) {
return " y " ;
} else {
return " z " ;
}
}
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 ;
code + = " \t " + p_output_vars [ 0 ] + " = " + p_input_vars [ 0 ] + " .x; \n " ;
code + = " \t " + p_output_vars [ 1 ] + " = " + p_input_vars [ 0 ] + " .y; \n " ;
code + = " \t " + p_output_vars [ 2 ] + " = " + p_input_vars [ 0 ] + " .z; \n " ;
return code ;
}
2018-07-15 16:28:06 +02:00
VisualShaderNodeVectorDecompose : : VisualShaderNodeVectorDecompose ( ) {
2018-07-14 23:15:42 +02:00
set_input_port_default_value ( 0 , Vector3 ( ) ) ;
}
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 {
2018-07-14 23:15:42 +02:00
return PORT_TYPE_VECTOR ;
}
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 ;
code + = " \t " + p_output_vars [ 0 ] + " = " + p_input_vars [ 0 ] + " [0].xyz; \n " ;
code + = " \t " + p_output_vars [ 1 ] + " = " + p_input_vars [ 0 ] + " [1].xyz; \n " ;
code + = " \t " + p_output_vars [ 2 ] + " = " + p_input_vars [ 0 ] + " [2].xyz; \n " ;
code + = " \t " + p_output_vars [ 3 ] + " = " + p_input_vars [ 0 ] + " [3].xyz; \n " ;
return code ;
}
2018-07-15 16:28:06 +02:00
VisualShaderNodeTransformDecompose : : VisualShaderNodeTransformDecompose ( ) {
2018-07-14 23:15:42 +02:00
set_input_port_default_value ( 0 , Transform ( ) ) ;
}
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-02-06 13:11:03 +01:00
if ( hint = = HINT_RANGE ) {
2020-05-05 10:25:48 +02:00
return _get_qual_str ( ) + " uniform float " + get_uniform_name ( ) + " : hint_range( " + rtos ( hint_range_min ) + " , " + rtos ( hint_range_max ) + " ) ; \ n " ;
2020-02-06 13:11:03 +01:00
} else if ( hint = = HINT_RANGE_STEP ) {
2020-05-05 10:25:48 +02:00
return _get_qual_str ( ) + " uniform float " + get_uniform_name ( ) + " : hint_range( " + rtos ( hint_range_min ) + " , " + rtos ( hint_range_max ) + " , " + rtos ( hint_range_step ) + " ) ; \ n " ;
2020-02-06 13:11:03 +01:00
}
2020-05-05 10:25:48 +02:00
return _get_qual_str ( ) + " uniform float " + get_uniform_name ( ) + " ; \ n " ;
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 {
2018-07-14 23:15:42 +02:00
return " \t " + p_output_vars [ 0 ] + " = " + get_uniform_name ( ) + " ; \n " ;
}
2020-02-25 15:50:49 +01:00
void VisualShaderNodeFloatUniform : : set_hint ( Hint p_hint ) {
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 ) {
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 ) {
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 ) {
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-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
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-02-06 13:11:03 +01:00
BIND_ENUM_CONSTANT ( HINT_NONE ) ;
BIND_ENUM_CONSTANT ( HINT_RANGE ) ;
BIND_ENUM_CONSTANT ( HINT_RANGE_STEP ) ;
}
2020-05-05 10:25:48 +02:00
bool VisualShaderNodeFloatUniform : : is_qualifier_supported ( Qualifier p_qual ) const {
return true ; // all qualifiers are supported
}
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 " ) ;
}
return props ;
}
2020-02-25 15:50:49 +01:00
VisualShaderNodeFloatUniform : : VisualShaderNodeFloatUniform ( ) {
2020-02-06 13:11:03 +01:00
hint = HINT_NONE ;
hint_range_min = 0.0 ;
hint_range_max = 1.0 ;
hint_range_step = 0.1 ;
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 {
if ( hint = = HINT_RANGE ) {
2020-05-05 10:25:48 +02:00
return _get_qual_str ( ) + " uniform int " + get_uniform_name ( ) + " : hint_range( " + rtos ( hint_range_min ) + " , " + rtos ( hint_range_max ) + " ) ; \ n " ;
2020-02-25 15:50:49 +01:00
} else if ( hint = = HINT_RANGE_STEP ) {
2020-05-05 10:25:48 +02:00
return _get_qual_str ( ) + " uniform int " + get_uniform_name ( ) + " : hint_range( " + rtos ( hint_range_min ) + " , " + rtos ( hint_range_max ) + " , " + rtos ( hint_range_step ) + " ) ; \ n " ;
2020-02-25 15:50:49 +01:00
}
2020-05-05 10:25:48 +02:00
return _get_qual_str ( ) + " uniform int " + get_uniform_name ( ) + " ; \ n " ;
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 {
return " \t " + p_output_vars [ 0 ] + " = " + get_uniform_name ( ) + " ; \n " ;
}
void VisualShaderNodeIntUniform : : set_hint ( Hint p_hint ) {
hint = p_hint ;
emit_changed ( ) ;
}
VisualShaderNodeIntUniform : : Hint VisualShaderNodeIntUniform : : get_hint ( ) const {
return hint ;
}
void VisualShaderNodeIntUniform : : set_min ( int p_value ) {
hint_range_min = p_value ;
emit_changed ( ) ;
}
int VisualShaderNodeIntUniform : : get_min ( ) const {
return hint_range_min ;
}
void VisualShaderNodeIntUniform : : set_max ( int p_value ) {
hint_range_max = p_value ;
emit_changed ( ) ;
}
int VisualShaderNodeIntUniform : : get_max ( ) const {
return hint_range_max ;
}
void VisualShaderNodeIntUniform : : set_step ( int p_value ) {
hint_range_step = p_value ;
emit_changed ( ) ;
}
int VisualShaderNodeIntUniform : : get_step ( ) const {
return hint_range_step ;
}
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 ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " hint " , PROPERTY_HINT_ENUM , " None,Range,Range+Step " ) , " set_hint " , " get_hint " ) ;
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 " ) ;
BIND_ENUM_CONSTANT ( HINT_NONE ) ;
BIND_ENUM_CONSTANT ( HINT_RANGE ) ;
BIND_ENUM_CONSTANT ( HINT_RANGE_STEP ) ;
}
2020-05-05 10:25:48 +02:00
bool VisualShaderNodeIntUniform : : is_qualifier_supported ( Qualifier p_qual ) const {
return true ; // all qualifiers are supported
}
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 " ) ;
}
return props ;
}
VisualShaderNodeIntUniform : : VisualShaderNodeIntUniform ( ) {
hint = HINT_NONE ;
hint_range_min = 0 ;
hint_range_max = 100 ;
hint_range_step = 1 ;
}
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
}
String VisualShaderNodeBooleanUniform : : generate_global ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id ) const {
2020-05-05 10:25:48 +02:00
return _get_qual_str ( ) + " uniform bool " + get_uniform_name ( ) + " ; \ n " ;
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 {
return " \t " + p_output_vars [ 0 ] + " = " + get_uniform_name ( ) + " ; \n " ;
}
2020-05-05 10:25:48 +02:00
bool VisualShaderNodeBooleanUniform : : is_qualifier_supported ( Qualifier p_qual ) const {
return true ; // all qualifiers are supported
}
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 {
return PORT_TYPE_VECTOR ;
}
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 {
return 2 ;
}
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 {
return p_port = = 0 ? PORT_TYPE_VECTOR : PORT_TYPE_SCALAR ;
}
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 {
return p_port = = 0 ? " color " : " alpha " ; //no output port means the editor will be used as port
}
String VisualShaderNodeColorUniform : : generate_global ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id ) const {
2020-05-05 10:25:48 +02:00
return _get_qual_str ( ) + " uniform vec4 " + get_uniform_name ( ) + " : hint_color ; \ n " ;
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 {
2018-07-14 23:15:42 +02:00
String code = " \t " + p_output_vars [ 0 ] + " = " + get_uniform_name ( ) + " .rgb; \n " ;
code + = " \t " + p_output_vars [ 1 ] + " = " + get_uniform_name ( ) + " .a; \n " ;
return code ;
}
2020-05-05 10:25:48 +02:00
bool VisualShaderNodeColorUniform : : is_qualifier_supported ( Qualifier p_qual ) const {
return true ; // all qualifiers are supported
}
2018-07-14 23:15:42 +02:00
VisualShaderNodeColorUniform : : VisualShaderNodeColorUniform ( ) {
}
////////////// Vector Uniform
String VisualShaderNodeVec3Uniform : : get_caption ( ) const {
2018-07-15 16:28:06 +02:00
return " VectorUniform " ;
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 {
return PORT_TYPE_VECTOR ;
}
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 {
return PORT_TYPE_VECTOR ;
}
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
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-05-05 10:25:48 +02:00
return _get_qual_str ( ) + " uniform vec3 " + get_uniform_name ( ) + " ; \ n " ;
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 {
2018-07-14 23:15:42 +02:00
return " \t " + p_output_vars [ 0 ] + " = " + get_uniform_name ( ) + " ; \n " ;
}
2020-05-05 10:25:48 +02:00
bool VisualShaderNodeVec3Uniform : : is_qualifier_supported ( Qualifier p_qual ) const {
return true ; // all qualifiers are supported
}
2018-07-14 23:15:42 +02:00
VisualShaderNodeVec3Uniform : : VisualShaderNodeVec3Uniform ( ) {
}
////////////// 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 {
return PORT_TYPE_VECTOR ;
}
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
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-05-05 10:25:48 +02:00
return _get_qual_str ( ) + " uniform mat4 " + get_uniform_name ( ) + " ; \ n " ;
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 {
2018-07-14 23:15:42 +02:00
return " \t " + p_output_vars [ 0 ] + " = " + get_uniform_name ( ) + " ; \n " ;
}
2020-05-05 10:25:48 +02:00
bool VisualShaderNodeTransformUniform : : is_qualifier_supported ( Qualifier p_qual ) const {
return true ; // all qualifiers are supported
}
2018-07-14 23:15:42 +02:00
VisualShaderNodeTransformUniform : : VisualShaderNodeTransformUniform ( ) {
}
////////////// Texture Uniform
String VisualShaderNodeTextureUniform : : get_caption ( ) const {
2018-07-15 16:28:06 +02:00
return " TextureUniform " ;
2018-07-14 23:15:42 +02:00
}
int VisualShaderNodeTextureUniform : : get_input_port_count ( ) const {
return 2 ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
VisualShaderNodeTextureUniform : : PortType VisualShaderNodeTextureUniform : : get_input_port_type ( int p_port ) const {
return p_port = = 0 ? PORT_TYPE_VECTOR : PORT_TYPE_SCALAR ;
}
2019-09-18 18:04:40 +02:00
2018-07-14 23:15:42 +02:00
String VisualShaderNodeTextureUniform : : get_input_port_name ( int p_port ) const {
return p_port = = 0 ? " uv " : " lod " ;
}
int VisualShaderNodeTextureUniform : : get_output_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
VisualShaderNodeTextureUniform : : PortType VisualShaderNodeTextureUniform : : get_output_port_type ( int p_port ) const {
2019-10-01 10:51:50 +02:00
switch ( p_port ) {
case 0 :
return PORT_TYPE_VECTOR ;
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 VisualShaderNodeTextureUniform : : get_output_port_name ( int p_port ) const {
2019-10-01 10:51:50 +02:00
switch ( p_port ) {
case 0 :
return " rgb " ;
case 1 :
return " alpha " ;
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
}
String VisualShaderNodeTextureUniform : : 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 sampler2D " + get_uniform_name ( ) ;
2018-07-14 23:15:42 +02:00
switch ( texture_type ) {
case TYPE_DATA :
2020-05-14 16:41:43 +02:00
if ( color_default = = COLOR_DEFAULT_BLACK ) {
2018-07-14 23:15:42 +02:00
code + = " : hint_black; \n " ;
2020-05-14 16:41:43 +02:00
} else {
2018-07-14 23:15:42 +02:00
code + = " ; \n " ;
2020-05-14 16:41:43 +02:00
}
2018-07-14 23:15:42 +02:00
break ;
case TYPE_COLOR :
2020-05-14 16:41:43 +02:00
if ( color_default = = COLOR_DEFAULT_BLACK ) {
2018-07-14 23:15:42 +02:00
code + = " : hint_black_albedo; \n " ;
2020-05-14 16:41:43 +02:00
} else {
2018-07-14 23:15:42 +02:00
code + = " : hint_albedo; \n " ;
2020-05-14 16:41:43 +02:00
}
2018-07-14 23:15:42 +02:00
break ;
2020-05-10 13:00:47 +02:00
case TYPE_NORMALMAP :
code + = " : hint_normal; \n " ;
break ;
case TYPE_ANISO :
code + = " : hint_aniso; \n " ;
break ;
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 {
2018-07-14 23:15:42 +02:00
String id = get_uniform_name ( ) ;
String code = " \t { \n " ;
2019-10-03 09:40:26 +02:00
if ( p_input_vars [ 0 ] = = String ( ) ) { // Use UV by default.
2019-10-10 12:11:04 +02:00
if ( p_input_vars [ 1 ] = = String ( ) ) {
2020-01-27 10:10:51 +01:00
code + = " \t \t vec4 n_tex_read = texture( " + id + " , UV.xy); \n " ;
2019-10-10 12:11:04 +02:00
} else {
2020-01-27 10:10:51 +01:00
code + = " \t \t vec4 n_tex_read = textureLod( " + id + " , UV.xy, " + p_input_vars [ 1 ] + " ); \n " ;
2019-10-10 12:11:04 +02:00
}
2018-07-14 23:15:42 +02:00
} else if ( p_input_vars [ 1 ] = = String ( ) ) {
//no lod
2020-01-27 10:10:51 +01:00
code + = " \t \t vec4 n_tex_read = texture( " + id + " , " + p_input_vars [ 0 ] + " .xy); \n " ;
2018-07-14 23:15:42 +02:00
} else {
2020-01-27 10:10:51 +01:00
code + = " \t \t vec4 n_tex_read = textureLod( " + id + " , " + p_input_vars [ 0 ] + " .xy, " + p_input_vars [ 1 ] + " ); \n " ;
2018-07-14 23:15:42 +02:00
}
code + = " \t \t " + p_output_vars [ 0 ] + " = n_tex_read.rgb; \n " ;
code + = " \t \t " + p_output_vars [ 1 ] + " = n_tex_read.a; \n " ;
code + = " \t } \n " ;
return code ;
}
void VisualShaderNodeTextureUniform : : set_texture_type ( TextureType p_type ) {
texture_type = p_type ;
emit_changed ( ) ;
}
VisualShaderNodeTextureUniform : : TextureType VisualShaderNodeTextureUniform : : get_texture_type ( ) const {
return texture_type ;
}
void VisualShaderNodeTextureUniform : : set_color_default ( ColorDefault p_default ) {
color_default = p_default ;
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 ;
}
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 " ) ;
props . push_back ( " color_default " ) ;
return props ;
}
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 ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " texture_type " , PROPERTY_HINT_ENUM , " Data,Color,Normalmap,Aniso " ) , " set_texture_type " , " get_texture_type " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " color_default " , PROPERTY_HINT_ENUM , " White Default,Black Default " ) , " set_color_default " , " get_color_default " ) ;
BIND_ENUM_CONSTANT ( TYPE_DATA ) ;
BIND_ENUM_CONSTANT ( TYPE_COLOR ) ;
BIND_ENUM_CONSTANT ( TYPE_NORMALMAP ) ;
BIND_ENUM_CONSTANT ( TYPE_ANISO ) ;
BIND_ENUM_CONSTANT ( COLOR_DEFAULT_WHITE ) ;
BIND_ENUM_CONSTANT ( COLOR_DEFAULT_BLACK ) ;
}
2019-10-03 09:40:26 +02:00
String VisualShaderNodeTextureUniform : : get_input_port_default_hint ( int p_port ) const {
if ( p_port = = 0 ) {
return " UV.xy " ;
}
return " " ;
}
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 ;
}
return false ;
}
2018-07-14 23:15:42 +02:00
VisualShaderNodeTextureUniform : : VisualShaderNodeTextureUniform ( ) {
texture_type = TYPE_DATA ;
color_default = COLOR_DEFAULT_WHITE ;
2020-01-27 10:10:51 +01:00
simple_decl = false ;
2018-07-14 23:15:42 +02:00
}
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 ;
}
VisualShaderNodeTextureUniform : : PortType VisualShaderNodeTextureUniformTriplanar : : get_input_port_type ( int p_port ) const {
if ( p_port = = 0 ) {
return PORT_TYPE_VECTOR ;
} else if ( p_port = = 1 ) {
return PORT_TYPE_VECTOR ;
}
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 " " ;
}
String VisualShaderNodeTextureUniformTriplanar : : generate_global_per_node ( Shader : : Mode p_mode , VisualShader : : Type p_type , int p_id ) const {
String code ;
code + = " // TRIPLANAR FUNCTION GLOBAL CODE \n " ;
code + = " \t vec4 triplanar_texture(sampler2D p_sampler, vec3 p_weights, vec3 p_triplanar_pos) { \n " ;
code + = " \t \t vec4 samp = vec4(0.0); \n " ;
code + = " \t \t samp += texture(p_sampler, p_triplanar_pos.xy) * p_weights.z; \n " ;
code + = " \t \t samp += texture(p_sampler, p_triplanar_pos.xz) * p_weights.y; \n " ;
code + = " \t \t samp += texture(p_sampler, p_triplanar_pos.zy * vec2(-1.0, 1.0)) * p_weights.x; \n " ;
code + = " \t \t return samp; \n " ;
code + = " \t } \n " ;
code + = " \n " ;
code + = " \t uniform vec3 triplanar_scale = vec3(1.0, 1.0, 1.0); \n " ;
code + = " \t uniform vec3 triplanar_offset; \n " ;
code + = " \t uniform float triplanar_sharpness = 0.5; \n " ;
code + = " \n " ;
code + = " \t varying vec3 triplanar_power_normal; \n " ;
code + = " \t varying vec3 triplanar_pos; \n " ;
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 ) {
code + = " \t // TRIPLANAR FUNCTION VERTEX CODE \n " ;
code + = " \t \t triplanar_power_normal = pow(abs(NORMAL), vec3(triplanar_sharpness)); \n " ;
code + = " \t \t triplanar_power_normal /= dot(triplanar_power_normal, vec3(1.0)); \n " ;
code + = " \t \t triplanar_pos = VERTEX * triplanar_scale + triplanar_offset; \n " ;
code + = " \t \t triplanar_pos *= vec3(1.0, -1.0, 1.0); \n " ;
}
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 ( ) ;
String code = " \t { \n " ;
if ( p_input_vars [ 0 ] = = String ( ) & & p_input_vars [ 1 ] = = String ( ) ) {
code + = " \t \t vec4 n_tex_read = triplanar_texture( " + id + " , triplanar_power_normal, triplanar_pos ); \n " ;
} else if ( p_input_vars [ 0 ] ! = String ( ) & & p_input_vars [ 1 ] = = String ( ) ) {
code + = " \t \t vec4 n_tex_read = triplanar_texture( " + id + " , " + p_input_vars [ 0 ] + " , triplanar_pos ); \n " ;
} else if ( p_input_vars [ 0 ] = = String ( ) & & p_input_vars [ 1 ] ! = String ( ) ) {
code + = " \t \t vec4 n_tex_read = triplanar_texture( " + id + " , triplanar_power_normal, " + p_input_vars [ 1 ] + " ); \n " ;
} else {
code + = " \t \t vec4 n_tex_read = triplanar_texture( " + id + " , " + p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] + " ); \n " ;
}
code + = " \t \t " + p_output_vars [ 0 ] + " = n_tex_read.rgb; \n " ;
code + = " \t \t " + p_output_vars [ 1 ] + " = n_tex_read.a; \n " ;
code + = " \t } \n " ;
return code ;
}
2019-10-03 09:40:26 +02:00
String VisualShaderNodeTextureUniformTriplanar : : get_input_port_default_hint ( int p_port ) const {
if ( p_port = = 0 ) {
return " default " ;
} else if ( p_port = = 1 ) {
return " default " ;
}
return " " ;
}
2019-07-12 11:14:34 +02:00
VisualShaderNodeTextureUniformTriplanar : : VisualShaderNodeTextureUniformTriplanar ( ) {
}
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
int VisualShaderNodeCubemapUniform : : get_output_port_count ( ) const {
2019-10-09 10:29:23 +02:00
return 1 ;
}
2019-06-11 20:43:37 +02:00
VisualShaderNodeCubemapUniform : : PortType VisualShaderNodeCubemapUniform : : get_output_port_type ( int p_port ) const {
2019-10-09 10:29:23 +02:00
return PORT_TYPE_SAMPLER ;
}
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
int VisualShaderNodeCubemapUniform : : get_input_port_count ( ) const {
2019-10-09 10:29:23 +02:00
return 0 ;
2018-07-14 23:15:42 +02:00
}
2019-09-18 18:04:40 +02:00
2019-06-11 20:43:37 +02:00
VisualShaderNodeCubemapUniform : : PortType VisualShaderNodeCubemapUniform : : get_input_port_type ( int p_port ) const {
2019-10-09 10:29:23 +02:00
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 VisualShaderNodeCubemapUniform : : get_input_port_name ( int p_port ) const {
2019-10-09 10:29:23 +02:00
return " " ;
2018-07-14 23:15:42 +02:00
}
2019-06-11 20:43:37 +02:00
String VisualShaderNodeCubemapUniform : : get_input_port_default_hint ( int p_port ) const {
2019-10-09 10:29:23 +02:00
return " " ;
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 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 ( ) ;
2019-09-18 18:04:40 +02:00
2019-10-09 10:29:23 +02:00
switch ( texture_type ) {
case TYPE_DATA :
2020-05-14 16:41:43 +02:00
if ( color_default = = COLOR_DEFAULT_BLACK ) {
2019-10-09 10:29:23 +02:00
code + = " : hint_black; \n " ;
2020-05-14 16:41:43 +02:00
} else {
2019-10-09 10:29:23 +02:00
code + = " ; \n " ;
2020-05-14 16:41:43 +02:00
}
2019-10-09 10:29:23 +02:00
break ;
case TYPE_COLOR :
2020-05-14 16:41:43 +02:00
if ( color_default = = COLOR_DEFAULT_BLACK ) {
2019-10-09 10:29:23 +02:00
code + = " : hint_black_albedo; \n " ;
2020-05-14 16:41:43 +02:00
} else {
2019-10-09 10:29:23 +02:00
code + = " : hint_albedo; \n " ;
2020-05-14 16:41:43 +02:00
}
2019-10-09 10:29:23 +02:00
break ;
2020-05-10 13:00:47 +02:00
case TYPE_NORMALMAP :
code + = " : hint_normal; \n " ;
break ;
case TYPE_ANISO :
code + = " : hint_aniso; \n " ;
break ;
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 ;
}
return PORT_TYPE_VECTOR ;
}
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 {
return PORT_TYPE_VECTOR ;
}
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 ;
2020-02-01 15:41:49 +01:00
code + = " \t if(abs( " + p_input_vars [ 0 ] + " - " + p_input_vars [ 1 ] + " ) < " + p_input_vars [ 2 ] + " ) \n " ; // abs(a - b) < tolerance eg. a == b
2019-04-13 14:24:04 +02:00
code + = " \t { \n " ;
2020-02-01 15:41:49 +01:00
code + = " \t \t " + p_output_vars [ 0 ] + " = " + p_input_vars [ 3 ] + " ; \n " ;
2019-04-13 14:24:04 +02:00
code + = " \t } \n " ;
2020-02-01 15:41:49 +01:00
code + = " \t else if( " + p_input_vars [ 0 ] + " < " + p_input_vars [ 1 ] + " ) \n " ; // a < b
2019-04-13 14:24:04 +02:00
code + = " \t { \n " ;
2020-02-01 15:41:49 +01:00
code + = " \t \t " + p_output_vars [ 0 ] + " = " + p_input_vars [ 5 ] + " ; \n " ;
2019-04-13 14:24:04 +02:00
code + = " \t } \n " ;
code + = " \t else \n " ; // a > b (or a >= b if abs(a - b) < tolerance is false)
code + = " \t { \n " ;
2020-02-01 15:41:49 +01:00
code + = " \t \t " + p_output_vars [ 0 ] + " = " + p_input_vars [ 4 ] + " ; \n " ;
2019-04-13 14:24:04 +02:00
code + = " \t } \n " ;
return code ;
}
VisualShaderNodeIf : : VisualShaderNodeIf ( ) {
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 ) ) ;
2020-01-27 10:10:51 +01:00
simple_decl = false ;
2019-04-13 14:24:04 +02:00
}
////////////// Switch
String VisualShaderNodeSwitch : : get_caption ( ) const {
2019-09-03 13:46:31 +02:00
return " VectorSwitch " ;
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 ;
}
return PORT_TYPE_VECTOR ;
}
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 {
return PORT_TYPE_VECTOR ;
}
String VisualShaderNodeSwitch : : get_output_port_name ( int p_port ) const {
return " result " ;
}
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 ;
2019-09-05 08:07:13 +02:00
code + = " \t if( " + p_input_vars [ 0 ] + " ) \n " ;
2019-04-13 14:24:04 +02:00
code + = " \t { \n " ;
2020-02-01 15:41:49 +01:00
code + = " \t \t " + p_output_vars [ 0 ] + " = " + p_input_vars [ 1 ] + " ; \n " ;
2019-04-13 14:24:04 +02:00
code + = " \t } \n " ;
code + = " \t else \n " ;
code + = " \t { \n " ;
2020-02-01 15:41:49 +01:00
code + = " \t \t " + p_output_vars [ 0 ] + " = " + p_input_vars [ 2 ] + " ; \n " ;
2019-04-13 14:24:04 +02:00
code + = " \t } \n " ;
return code ;
}
VisualShaderNodeSwitch : : VisualShaderNodeSwitch ( ) {
set_input_port_default_value ( 0 , false ) ;
2019-09-03 13:46:31 +02:00
set_input_port_default_value ( 1 , Vector3 ( 1.0 , 1.0 , 1.0 ) ) ;
2019-04-13 14:24:04 +02:00
set_input_port_default_value ( 2 , Vector3 ( 0.0 , 0.0 , 0.0 ) ) ;
2020-01-27 10:10:51 +01:00
simple_decl = false ;
2019-04-13 14:24:04 +02:00
}
2019-05-19 12:07:00 +02:00
2019-09-03 13:46:31 +02:00
////////////// Switch(scalar)
String VisualShaderNodeScalarSwitch : : get_caption ( ) const {
return " ScalarSwitch " ;
}
VisualShaderNodeScalarSwitch : : PortType VisualShaderNodeScalarSwitch : : get_input_port_type ( int p_port ) const {
if ( p_port = = 0 ) {
return PORT_TYPE_BOOLEAN ;
}
return PORT_TYPE_SCALAR ;
}
VisualShaderNodeScalarSwitch : : PortType VisualShaderNodeScalarSwitch : : get_output_port_type ( int p_port ) const {
return PORT_TYPE_SCALAR ;
}
VisualShaderNodeScalarSwitch : : VisualShaderNodeScalarSwitch ( ) {
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 :
return PORT_TYPE_VECTOR ;
case 1 :
return PORT_TYPE_VECTOR ;
case 2 :
return PORT_TYPE_BOOLEAN ;
case 3 :
return PORT_TYPE_SCALAR ;
default :
return PORT_TYPE_VECTOR ;
}
}
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 " ;
}
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 ;
if ( p_input_vars [ 0 ] = = String ( ) ) {
normal = " NORMAL " ;
} else {
normal = p_input_vars [ 0 ] ;
}
if ( p_input_vars [ 1 ] = = String ( ) ) {
view = " VIEW " ;
} else {
view = p_input_vars [ 1 ] ;
}
2020-02-03 10:33:37 +01:00
return " \t " + 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 " ;
2019-11-22 16:28:59 +01:00
}
String VisualShaderNodeFresnel : : get_input_port_default_hint ( int p_port ) const {
if ( p_port = = 0 ) {
return " default " ;
} else if ( p_port = = 1 ) {
return " default " ;
}
return " " ;
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 {
static const char * funcs [ FUNC_IS_NAN + 1 ] = {
" isinf($) " ,
" isnan($) "
} ;
String code ;
2020-01-27 10:10:51 +01:00
code + = " \t " + p_output_vars [ 0 ] + " = " + String ( funcs [ func ] ) . replace ( " $ " , p_input_vars [ 0 ] ) + " ; \n " ;
2019-07-08 09:05:33 +02:00
return code ;
}
void VisualShaderNodeIs : : set_function ( Function p_func ) {
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 ) ;
}
VisualShaderNodeIs : : VisualShaderNodeIs ( ) {
func = FUNC_IS_INF ;
set_input_port_default_value ( 0 , 0.0 ) ;
}
////////////// Compare
String VisualShaderNodeCompare : : get_caption ( ) const {
return " Compare " ;
}
int VisualShaderNodeCompare : : get_input_port_count ( ) const {
if ( ctype = = CTYPE_SCALAR & & ( func = = FUNC_EQUAL | | func = = FUNC_NOT_EQUAL ) ) {
return 3 ;
}
return 2 ;
}
VisualShaderNodeCompare : : PortType VisualShaderNodeCompare : : get_input_port_type ( int p_port ) const {
2020-05-14 16:41:43 +02:00
if ( p_port = = 2 ) {
2019-07-08 09:05:33 +02:00
return PORT_TYPE_SCALAR ;
2020-05-14 16:41:43 +02:00
}
2019-07-08 09:05:33 +02:00
switch ( ctype ) {
case CTYPE_SCALAR :
return PORT_TYPE_SCALAR ;
2020-02-25 15:50:49 +01:00
case CTYPE_SCALAR_INT :
return PORT_TYPE_SCALAR_INT ;
2019-07-08 09:05:33 +02:00
case CTYPE_VECTOR :
return PORT_TYPE_VECTOR ;
case CTYPE_BOOLEAN :
return PORT_TYPE_BOOLEAN ;
case CTYPE_TRANSFORM :
return PORT_TYPE_TRANSFORM ;
}
return PORT_TYPE_VECTOR ;
}
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 {
if ( ctype = = CTYPE_BOOLEAN | | ctype = = CTYPE_TRANSFORM ) {
if ( func > FUNC_NOT_EQUAL ) {
2019-07-19 16:08:40 +02:00
return TTR ( " 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 {
static const char * ops [ FUNC_LESS_THAN_EQUAL + 1 ] = {
" == " ,
" != " ,
" > " ,
" >= " ,
" < " ,
" <= " ,
} ;
static const char * funcs [ FUNC_LESS_THAN_EQUAL + 1 ] = {
" equal($) " ,
" notEqual($) " ,
" greaterThan($) " ,
" greaterThanEqual($) " ,
" lessThan($) " ,
" lessThanEqual($) " ,
} ;
static const char * conds [ COND_ANY + 1 ] = {
" all($) " ,
" any($) " ,
} ;
String code ;
switch ( ctype ) {
case CTYPE_SCALAR :
if ( func = = FUNC_EQUAL ) {
2020-01-27 10:10:51 +01:00
code + = " \t " + 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 ) {
2020-01-27 10:10:51 +01:00
code + = " \t " + 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 {
2020-02-25 15:50:49 +01:00
code + = " \t " + p_output_vars [ 0 ] + " = " + ( p_input_vars [ 0 ] + " $ " + p_input_vars [ 1 ] ) . replace ( " $ " , ops [ func ] ) + " ; \n " ;
2019-07-08 09:05:33 +02:00
}
break ;
2020-02-25 15:50:49 +01:00
case CTYPE_SCALAR_INT :
code + = " \t " + p_output_vars [ 0 ] + " = " + ( p_input_vars [ 0 ] + " $ " + p_input_vars [ 1 ] ) . replace ( " $ " , ops [ func ] ) + " ; \n " ;
break ;
2019-07-08 09:05:33 +02:00
case CTYPE_VECTOR :
code + = " \t { \n " ;
2020-01-27 10:10:51 +01:00
code + = " \t \t bvec3 _bv = " + String ( funcs [ func ] ) . replace ( " $ " , p_input_vars [ 0 ] + " , " + p_input_vars [ 1 ] ) + " ; \n " ;
code + = " \t \t " + p_output_vars [ 0 ] + " = " + String ( conds [ condition ] ) . replace ( " $ " , " _bv " ) + " ; \n " ;
2019-07-08 09:05:33 +02:00
code + = " \t } \n " ;
break ;
case CTYPE_BOOLEAN :
2020-05-14 16:41:43 +02:00
if ( func > FUNC_NOT_EQUAL ) {
2020-01-27 10:10:51 +01:00
return " \t " + p_output_vars [ 0 ] + " = false; \n " ;
2020-05-14 16:41:43 +02:00
}
2020-01-27 10:10:51 +01:00
code + = " \t " + p_output_vars [ 0 ] + " = " + ( p_input_vars [ 0 ] + " $ " + p_input_vars [ 1 ] ) . replace ( " $ " , ops [ func ] ) + " ; \n " ;
2019-07-08 09:05:33 +02:00
break ;
case CTYPE_TRANSFORM :
2020-05-14 16:41:43 +02:00
if ( func > FUNC_NOT_EQUAL ) {
2020-01-27 10:10:51 +01:00
return " \t " + p_output_vars [ 0 ] + " = false; \n " ;
2020-05-14 16:41:43 +02:00
}
2020-01-27 10:10:51 +01:00
code + = " \t " + p_output_vars [ 0 ] + " = " + ( p_input_vars [ 0 ] + " $ " + p_input_vars [ 1 ] ) . replace ( " $ " , ops [ func ] ) + " ; \n " ;
2019-07-08 09:05:33 +02:00
break ;
default :
break ;
}
return code ;
}
2020-01-23 08:31:45 +01:00
void VisualShaderNodeCompare : : set_comparison_type ( ComparisonType p_type ) {
2019-07-08 09:05:33 +02:00
ctype = p_type ;
switch ( ctype ) {
case CTYPE_SCALAR :
set_input_port_default_value ( 0 , 0.0 ) ;
set_input_port_default_value ( 1 , 0.0 ) ;
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 :
set_input_port_default_value ( 0 , 0 ) ;
set_input_port_default_value ( 1 , 0 ) ;
simple_decl = true ;
break ;
2019-07-08 09:05:33 +02:00
case CTYPE_VECTOR :
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 ) ) ;
2020-01-27 10:10:51 +01:00
simple_decl = false ;
2019-07-08 09:05:33 +02:00
break ;
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 :
set_input_port_default_value ( 0 , Transform ( ) ) ;
set_input_port_default_value ( 1 , Transform ( ) ) ;
2020-01-27 10:10:51 +01:00
simple_decl = true ;
2019-07-08 09:05:33 +02:00
break ;
}
emit_changed ( ) ;
}
2020-01-23 08:31:45 +01:00
VisualShaderNodeCompare : : ComparisonType VisualShaderNodeCompare : : get_comparison_type ( ) const {
2019-07-08 09:05:33 +02:00
return ctype ;
}
void VisualShaderNodeCompare : : set_function ( Function p_func ) {
func = p_func ;
emit_changed ( ) ;
}
VisualShaderNodeCompare : : Function VisualShaderNodeCompare : : get_function ( ) const {
return func ;
}
void VisualShaderNodeCompare : : set_condition ( Condition p_cond ) {
condition = p_cond ;
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 " ) ;
2020-05-14 16:41:43 +02:00
if ( ctype = = CTYPE_VECTOR ) {
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 ) ;
2020-02-25 15:50:49 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " type " , PROPERTY_HINT_ENUM , " Float,Int,Vector,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 ) ;
2019-07-08 09:05:33 +02:00
BIND_ENUM_CONSTANT ( CTYPE_VECTOR ) ;
BIND_ENUM_CONSTANT ( CTYPE_BOOLEAN ) ;
BIND_ENUM_CONSTANT ( CTYPE_TRANSFORM ) ;
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 ) ;
BIND_ENUM_CONSTANT ( COND_ALL ) ;
BIND_ENUM_CONSTANT ( COND_ANY ) ;
}
VisualShaderNodeCompare : : VisualShaderNodeCompare ( ) {
ctype = CTYPE_SCALAR ;
func = FUNC_EQUAL ;
condition = COND_ALL ;
set_input_port_default_value ( 0 , 0.0 ) ;
set_input_port_default_value ( 1 , 0.0 ) ;
set_input_port_default_value ( 2 , CMP_EPSILON ) ;
}