Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PI, TAU and E constants to the shader language (3.x) #52315

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions drivers/gles2/shader_compiler_gles2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,9 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() {
actions[VS::SHADER_CANVAS_ITEM].renames["PROJECTION_MATRIX"] = "projection_matrix";
actions[VS::SHADER_CANVAS_ITEM].renames["EXTRA_MATRIX"] = "extra_matrix_instance";
actions[VS::SHADER_CANVAS_ITEM].renames["TIME"] = "time";
actions[VS::SHADER_CANVAS_ITEM].renames["PI"] = _MKSTR(Math_PI);
actions[VS::SHADER_CANVAS_ITEM].renames["TAU"] = _MKSTR(Math_TAU);
actions[VS::SHADER_CANVAS_ITEM].renames["E"] = _MKSTR(Math_E);
actions[VS::SHADER_CANVAS_ITEM].renames["AT_LIGHT_PASS"] = "at_light_pass";
actions[VS::SHADER_CANVAS_ITEM].renames["INSTANCE_CUSTOM"] = "instance_custom";

Expand Down Expand Up @@ -1117,6 +1120,9 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() {
//builtins

actions[VS::SHADER_SPATIAL].renames["TIME"] = "time";
actions[VS::SHADER_SPATIAL].renames["PI"] = _MKSTR(Math_PI);
actions[VS::SHADER_SPATIAL].renames["TAU"] = _MKSTR(Math_TAU);
actions[VS::SHADER_SPATIAL].renames["E"] = _MKSTR(Math_E);
actions[VS::SHADER_SPATIAL].renames["VIEWPORT_SIZE"] = "viewport_size";

actions[VS::SHADER_SPATIAL].renames["FRAGCOORD"] = "gl_FragCoord";
Expand Down
13 changes: 13 additions & 0 deletions drivers/gles3/shader_compiler_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,10 @@ ShaderCompilerGLES3::ShaderCompilerGLES3() {
actions[VS::SHADER_CANVAS_ITEM].renames["PROJECTION_MATRIX"] = "projection_matrix";
actions[VS::SHADER_CANVAS_ITEM].renames["EXTRA_MATRIX"] = "extra_matrix";
actions[VS::SHADER_CANVAS_ITEM].renames["TIME"] = "time";
actions[VS::SHADER_CANVAS_ITEM].renames["PI"] = _MKSTR(Math_PI);
actions[VS::SHADER_CANVAS_ITEM].renames["TAU"] = _MKSTR(Math_TAU);
actions[VS::SHADER_CANVAS_ITEM].renames["E"] = _MKSTR(Math_E);

actions[VS::SHADER_CANVAS_ITEM].renames["AT_LIGHT_PASS"] = "at_light_pass";
actions[VS::SHADER_CANVAS_ITEM].renames["INSTANCE_CUSTOM"] = "instance_custom";

Expand Down Expand Up @@ -1175,6 +1179,10 @@ ShaderCompilerGLES3::ShaderCompilerGLES3() {
//builtins

actions[VS::SHADER_SPATIAL].renames["TIME"] = "time";
actions[VS::SHADER_SPATIAL].renames["PI"] = _MKSTR(Math_PI);
actions[VS::SHADER_SPATIAL].renames["TAU"] = _MKSTR(Math_TAU);
actions[VS::SHADER_SPATIAL].renames["E"] = _MKSTR(Math_E);

actions[VS::SHADER_SPATIAL].renames["VIEWPORT_SIZE"] = "viewport_size";

actions[VS::SHADER_SPATIAL].renames["FRAGCOORD"] = "gl_FragCoord";
Expand Down Expand Up @@ -1282,7 +1290,12 @@ ShaderCompilerGLES3::ShaderCompilerGLES3() {
actions[VS::SHADER_PARTICLES].renames["RESTART"] = "restart";
actions[VS::SHADER_PARTICLES].renames["CUSTOM"] = "out_custom";
actions[VS::SHADER_PARTICLES].renames["TRANSFORM"] = "xform";

actions[VS::SHADER_PARTICLES].renames["TIME"] = "time";
actions[VS::SHADER_PARTICLES].renames["PI"] = _MKSTR(Math_PI);
actions[VS::SHADER_PARTICLES].renames["TAU"] = _MKSTR(Math_TAU);
actions[VS::SHADER_PARTICLES].renames["E"] = _MKSTR(Math_E);

actions[VS::SHADER_PARTICLES].renames["LIFETIME"] = "lifetime";
actions[VS::SHADER_PARTICLES].renames["DELTA"] = "local_delta";
actions[VS::SHADER_PARTICLES].renames["NUMBER"] = "particle_number";
Expand Down
3 changes: 1 addition & 2 deletions scene/resources/particles_material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,7 @@ void ParticlesMaterial::_update_shader() {
code += " float scale_rand = rand_from_seed(alt_seed);\n";
code += " float hue_rot_rand = rand_from_seed(alt_seed);\n";
code += " float anim_offset_rand = rand_from_seed(alt_seed);\n";
code += " float pi = 3.14159;\n";
code += " float degree_to_rad = pi / 180.0;\n";
code += " float degree_to_rad = PI / 180.0;\n";
code += "\n";

if (emission_shape == EMISSION_SHAPE_POINTS || emission_shape == EMISSION_SHAPE_DIRECTED_POINTS) {
Expand Down
10 changes: 10 additions & 0 deletions servers/visual/shader_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ ShaderTypes::ShaderTypes() {
/*************** SPATIAL ***********************/

shader_modes[VS::SHADER_SPATIAL].functions["global"].built_ins["TIME"] = constt(ShaderLanguage::TYPE_FLOAT);
shader_modes[VS::SHADER_SPATIAL].functions["global"].built_ins["PI"] = constt(ShaderLanguage::TYPE_FLOAT);
shader_modes[VS::SHADER_SPATIAL].functions["global"].built_ins["TAU"] = constt(ShaderLanguage::TYPE_FLOAT);
shader_modes[VS::SHADER_SPATIAL].functions["global"].built_ins["E"] = constt(ShaderLanguage::TYPE_FLOAT);

shader_modes[VS::SHADER_SPATIAL].functions["vertex"].built_ins["VERTEX"] = ShaderLanguage::TYPE_VEC3;
shader_modes[VS::SHADER_SPATIAL].functions["vertex"].built_ins["NORMAL"] = ShaderLanguage::TYPE_VEC3;
Expand Down Expand Up @@ -200,6 +203,9 @@ ShaderTypes::ShaderTypes() {
/************ CANVAS ITEM **************************/

shader_modes[VS::SHADER_CANVAS_ITEM].functions["global"].built_ins["TIME"] = constt(ShaderLanguage::TYPE_FLOAT);
shader_modes[VS::SHADER_CANVAS_ITEM].functions["global"].built_ins["PI"] = constt(ShaderLanguage::TYPE_FLOAT);
shader_modes[VS::SHADER_CANVAS_ITEM].functions["global"].built_ins["TAU"] = constt(ShaderLanguage::TYPE_FLOAT);
shader_modes[VS::SHADER_CANVAS_ITEM].functions["global"].built_ins["E"] = constt(ShaderLanguage::TYPE_FLOAT);

shader_modes[VS::SHADER_CANVAS_ITEM].functions["vertex"].built_ins["VERTEX"] = ShaderLanguage::TYPE_VEC2;
shader_modes[VS::SHADER_CANVAS_ITEM].functions["vertex"].built_ins["UV"] = ShaderLanguage::TYPE_VEC2;
Expand Down Expand Up @@ -265,6 +271,10 @@ ShaderTypes::ShaderTypes() {
/************ PARTICLES **************************/

shader_modes[VS::SHADER_PARTICLES].functions["global"].built_ins["TIME"] = constt(ShaderLanguage::TYPE_FLOAT);
shader_modes[VS::SHADER_PARTICLES].functions["global"].built_ins["PI"] = constt(ShaderLanguage::TYPE_FLOAT);
shader_modes[VS::SHADER_PARTICLES].functions["global"].built_ins["TAU"] = constt(ShaderLanguage::TYPE_FLOAT);
shader_modes[VS::SHADER_PARTICLES].functions["global"].built_ins["E"] = constt(ShaderLanguage::TYPE_FLOAT);

shader_modes[VS::SHADER_PARTICLES].functions["vertex"].built_ins["COLOR"] = ShaderLanguage::TYPE_VEC4;
shader_modes[VS::SHADER_PARTICLES].functions["vertex"].built_ins["VELOCITY"] = ShaderLanguage::TYPE_VEC3;
shader_modes[VS::SHADER_PARTICLES].functions["vertex"].built_ins["MASS"] = ShaderLanguage::TYPE_FLOAT;
Expand Down