Added constants PI, TAU and E to the shader language
This commit is contained in:
parent
d0aaf4a1fd
commit
16567321ba
8 changed files with 33 additions and 4 deletions
|
@ -91,7 +91,6 @@ void ColorPicker::init_shaders() {
|
|||
wheel_shader.instance();
|
||||
wheel_shader->set_code(
|
||||
"shader_type canvas_item;"
|
||||
"const float TAU = 6.28318530718;"
|
||||
"void fragment() {"
|
||||
" float x = UV.x - 0.5;"
|
||||
" float y = UV.y - 0.5;"
|
||||
|
@ -111,7 +110,6 @@ void ColorPicker::init_shaders() {
|
|||
circle_shader.instance();
|
||||
circle_shader->set_code(
|
||||
"shader_type canvas_item;"
|
||||
"const float TAU = 6.28318530718;"
|
||||
"uniform float v = 1.0;"
|
||||
"void fragment() {"
|
||||
" float x = UV.x - 0.5;"
|
||||
|
|
|
@ -193,7 +193,6 @@ ProceduralSkyMaterial::ProceduralSkyMaterial() {
|
|||
code += "uniform float ground_energy = 1.0;\n\n";
|
||||
code += "uniform float sun_angle_max = 1.74;\n";
|
||||
code += "uniform float sun_curve : hint_range(0, 1) = 0.05;\n\n";
|
||||
code += "const float PI = 3.1415926535897932384626433833;\n\n";
|
||||
code += "void sky() {\n";
|
||||
code += "\tfloat v_angle = acos(clamp(EYEDIR.y, -1.0, 1.0));\n";
|
||||
code += "\tfloat c = (1.0 - v_angle / (PI * 0.5));\n";
|
||||
|
@ -499,7 +498,6 @@ PhysicalSkyMaterial::PhysicalSkyMaterial() {
|
|||
|
||||
code += "uniform sampler2D night_sky : hint_black;";
|
||||
|
||||
code += "const float PI = 3.141592653589793238462643383279502884197169;\n";
|
||||
code += "const vec3 UP = vec3( 0.0, 1.0, 0.0 );\n\n";
|
||||
|
||||
code += "// Sun constants\n";
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
#include "scene_shader_forward_clustered.h"
|
||||
#include "core/config/project_settings.h"
|
||||
#include "core/math/math_defs.h"
|
||||
#include "render_forward_clustered.h"
|
||||
|
||||
using namespace RendererSceneRenderImplementation;
|
||||
|
@ -608,6 +609,9 @@ void SceneShaderForwardClustered::init(RendererStorageRD *p_storage, const Strin
|
|||
//builtins
|
||||
|
||||
actions.renames["TIME"] = "scene_data.time";
|
||||
actions.renames["PI"] = _MKSTR(Math_PI);
|
||||
actions.renames["TAU"] = _MKSTR(Math_TAU);
|
||||
actions.renames["E"] = _MKSTR(Math_E);
|
||||
actions.renames["VIEWPORT_SIZE"] = "scene_data.viewport_size";
|
||||
|
||||
actions.renames["FRAGCOORD"] = "gl_FragCoord";
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
#include "scene_shader_forward_mobile.h"
|
||||
#include "core/config/project_settings.h"
|
||||
#include "core/math/math_defs.h"
|
||||
#include "render_forward_mobile.h"
|
||||
|
||||
using namespace RendererSceneRenderImplementation;
|
||||
|
@ -625,6 +626,9 @@ void SceneShaderForwardMobile::init(RendererStorageRD *p_storage, const String p
|
|||
//builtins
|
||||
|
||||
actions.renames["TIME"] = "scene_data.time";
|
||||
actions.renames["PI"] = _MKSTR(Math_PI);
|
||||
actions.renames["TAU"] = _MKSTR(Math_TAU);
|
||||
actions.renames["E"] = _MKSTR(Math_E);
|
||||
actions.renames["VIEWPORT_SIZE"] = "scene_data.viewport_size";
|
||||
|
||||
actions.renames["FRAGCOORD"] = "gl_FragCoord";
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "renderer_canvas_render_rd.h"
|
||||
#include "core/config/project_settings.h"
|
||||
#include "core/math/geometry_2d.h"
|
||||
#include "core/math/math_defs.h"
|
||||
#include "core/math/math_funcs.h"
|
||||
#include "renderer_compositor_rd.h"
|
||||
|
||||
|
@ -2367,6 +2368,9 @@ RendererCanvasRenderRD::RendererCanvasRenderRD(RendererStorageRD *p_storage) {
|
|||
actions.renames["CANVAS_MATRIX"] = "canvas_data.canvas_transform";
|
||||
actions.renames["SCREEN_MATRIX"] = "canvas_data.screen_transform";
|
||||
actions.renames["TIME"] = "canvas_data.time";
|
||||
actions.renames["PI"] = _MKSTR(Math_PI);
|
||||
actions.renames["TAU"] = _MKSTR(Math_TAU);
|
||||
actions.renames["E"] = _MKSTR(Math_E);
|
||||
actions.renames["AT_LIGHT_PASS"] = "false";
|
||||
actions.renames["INSTANCE_CUSTOM"] = "instance_custom";
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
#include "renderer_scene_sky_rd.h"
|
||||
#include "core/config/project_settings.h"
|
||||
#include "core/math/math_defs.h"
|
||||
#include "renderer_scene_render_rd.h"
|
||||
#include "servers/rendering/rendering_server_default.h"
|
||||
|
||||
|
@ -710,6 +711,9 @@ void RendererSceneSkyRD::init(RendererStorageRD *p_storage) {
|
|||
actions.renames["SKY_COORDS"] = "panorama_coords";
|
||||
actions.renames["SCREEN_UV"] = "uv";
|
||||
actions.renames["TIME"] = "params.time";
|
||||
actions.renames["PI"] = _MKSTR(Math_PI);
|
||||
actions.renames["TAU"] = _MKSTR(Math_TAU);
|
||||
actions.renames["E"] = _MKSTR(Math_E);
|
||||
actions.renames["HALF_RES_COLOR"] = "half_res_color";
|
||||
actions.renames["QUARTER_RES_COLOR"] = "quarter_res_color";
|
||||
actions.renames["RADIANCE"] = "radiance";
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "core/config/engine.h"
|
||||
#include "core/config/project_settings.h"
|
||||
#include "core/io/resource_loader.h"
|
||||
#include "core/math/math_defs.h"
|
||||
#include "renderer_compositor_rd.h"
|
||||
#include "servers/rendering/shader_language.h"
|
||||
|
||||
|
@ -9144,6 +9145,9 @@ RendererStorageRD::RendererStorageRD() {
|
|||
actions.renames["CUSTOM"] = "PARTICLE.custom";
|
||||
actions.renames["TRANSFORM"] = "PARTICLE.xform";
|
||||
actions.renames["TIME"] = "FRAME.time";
|
||||
actions.renames["PI"] = _MKSTR(Math_PI);
|
||||
actions.renames["TAU"] = _MKSTR(Math_TAU);
|
||||
actions.renames["E"] = _MKSTR(Math_E);
|
||||
actions.renames["LIFETIME"] = "params.lifetime";
|
||||
actions.renames["DELTA"] = "local_delta";
|
||||
actions.renames["NUMBER"] = "particle_number";
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
/*************************************************************************/
|
||||
|
||||
#include "shader_types.h"
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
const Map<StringName, ShaderLanguage::FunctionInfo> &ShaderTypes::get_functions(RS::ShaderMode p_mode) {
|
||||
return shader_modes[p_mode].functions;
|
||||
|
@ -54,6 +55,9 @@ ShaderTypes::ShaderTypes() {
|
|||
/*************** SPATIAL ***********************/
|
||||
|
||||
shader_modes[RS::SHADER_SPATIAL].functions["global"].built_ins["TIME"] = constt(ShaderLanguage::TYPE_FLOAT);
|
||||
shader_modes[RS::SHADER_SPATIAL].functions["global"].built_ins["PI"] = constt(ShaderLanguage::TYPE_FLOAT);
|
||||
shader_modes[RS::SHADER_SPATIAL].functions["global"].built_ins["TAU"] = constt(ShaderLanguage::TYPE_FLOAT);
|
||||
shader_modes[RS::SHADER_SPATIAL].functions["global"].built_ins["E"] = constt(ShaderLanguage::TYPE_FLOAT);
|
||||
|
||||
shader_modes[RS::SHADER_SPATIAL].functions["vertex"].built_ins["VERTEX"] = ShaderLanguage::TYPE_VEC3;
|
||||
shader_modes[RS::SHADER_SPATIAL].functions["vertex"].built_ins["NORMAL"] = ShaderLanguage::TYPE_VEC3;
|
||||
|
@ -227,6 +231,9 @@ ShaderTypes::ShaderTypes() {
|
|||
/************ CANVAS ITEM **************************/
|
||||
|
||||
shader_modes[RS::SHADER_CANVAS_ITEM].functions["global"].built_ins["TIME"] = constt(ShaderLanguage::TYPE_FLOAT);
|
||||
shader_modes[RS::SHADER_CANVAS_ITEM].functions["global"].built_ins["PI"] = constt(ShaderLanguage::TYPE_FLOAT);
|
||||
shader_modes[RS::SHADER_CANVAS_ITEM].functions["global"].built_ins["TAU"] = constt(ShaderLanguage::TYPE_FLOAT);
|
||||
shader_modes[RS::SHADER_CANVAS_ITEM].functions["global"].built_ins["E"] = constt(ShaderLanguage::TYPE_FLOAT);
|
||||
|
||||
shader_modes[RS::SHADER_CANVAS_ITEM].functions["vertex"].built_ins["VERTEX"] = ShaderLanguage::TYPE_VEC2;
|
||||
shader_modes[RS::SHADER_CANVAS_ITEM].functions["vertex"].built_ins["UV"] = ShaderLanguage::TYPE_VEC2;
|
||||
|
@ -317,6 +324,9 @@ ShaderTypes::ShaderTypes() {
|
|||
/************ PARTICLES **************************/
|
||||
|
||||
shader_modes[RS::SHADER_PARTICLES].functions["global"].built_ins["TIME"] = constt(ShaderLanguage::TYPE_FLOAT);
|
||||
shader_modes[RS::SHADER_PARTICLES].functions["global"].built_ins["PI"] = constt(ShaderLanguage::TYPE_FLOAT);
|
||||
shader_modes[RS::SHADER_PARTICLES].functions["global"].built_ins["TAU"] = constt(ShaderLanguage::TYPE_FLOAT);
|
||||
shader_modes[RS::SHADER_PARTICLES].functions["global"].built_ins["E"] = constt(ShaderLanguage::TYPE_FLOAT);
|
||||
|
||||
shader_modes[RS::SHADER_PARTICLES].functions["start"].built_ins["COLOR"] = ShaderLanguage::TYPE_VEC4;
|
||||
shader_modes[RS::SHADER_PARTICLES].functions["start"].built_ins["VELOCITY"] = ShaderLanguage::TYPE_VEC3;
|
||||
|
@ -381,6 +391,9 @@ ShaderTypes::ShaderTypes() {
|
|||
/************ SKY **************************/
|
||||
|
||||
shader_modes[RS::SHADER_SKY].functions["global"].built_ins["TIME"] = constt(ShaderLanguage::TYPE_FLOAT);
|
||||
shader_modes[RS::SHADER_SKY].functions["global"].built_ins["PI"] = constt(ShaderLanguage::TYPE_FLOAT);
|
||||
shader_modes[RS::SHADER_SKY].functions["global"].built_ins["TAU"] = constt(ShaderLanguage::TYPE_FLOAT);
|
||||
shader_modes[RS::SHADER_SKY].functions["global"].built_ins["E"] = constt(ShaderLanguage::TYPE_FLOAT);
|
||||
shader_modes[RS::SHADER_SKY].functions["global"].built_ins["POSITION"] = constt(ShaderLanguage::TYPE_VEC3);
|
||||
shader_modes[RS::SHADER_SKY].functions["global"].built_ins["RADIANCE"] = constt(ShaderLanguage::TYPE_SAMPLERCUBE);
|
||||
shader_modes[RS::SHADER_SKY].functions["global"].built_ins["AT_HALF_RES_PASS"] = constt(ShaderLanguage::TYPE_BOOL);
|
||||
|
|
Loading…
Reference in a new issue