Commit graph

210 commits

Author SHA1 Message Date
Yuri Roubinsky
6b7f8558d9 Removed switch operator from GLES2 shader back-end 2019-11-02 12:43:32 +03:00
Yuri Roubinsky
1b003f3d64 Prevents shader crash on GLES2 if unsupported built-in has been used 2019-10-31 09:21:44 +03:00
Yuri Roubinsky
76eb486413 Added check if field name in the shader is equal to builtin 2019-10-29 15:37:19 +03:00
Yuri Roubinsky
ef6161532d Fix shader crash if non-boolean expression inserted into "if" 2019-10-28 08:35:33 +03:00
Hugo Locurcio
701581d1d3
Improve error messages related to shader_type
The list of allowed shader types is now displayed if any
`shader_type`-related error is emitted.

This makes it easier to remember which shader types are allowed
when creating a new shader.
2019-10-26 17:43:14 +02:00
Yuri Roubinsky
ada4bcbe30 Fix invalid autocompletion pasting of shader param name 2019-10-08 18:33:22 +03:00
Yuri Roubinsky
76324bec8d Prevent shader crash if name of variable overrides function name 2019-10-06 20:35:41 +03:00
Yuri Roubinsky
d9087e1b44 Prevent shader crash if function call been used on constant 2019-10-06 18:20:05 +03:00
Yuri Roubinsky
5a5a062d61 Fix few redefinition name errors for variable/param/function in shaders 2019-10-06 17:27:28 +03:00
Yuri Roubinsky
1472fca951 Removed unnecessary shader error log messages 2019-10-02 12:37:22 +03:00
Chaosus
1333ea2a2d Implement shader array support for varyings 2019-09-14 18:23:25 +03:00
Yuri Roubinski
38601dd3e9 Fix shader crash when users miss the return statement 2019-08-28 11:32:33 +03:00
Yuri Roubinski
4dda253ee0 Implements switch to shaders 2019-08-23 14:43:09 +03:00
Yuri Roubinski
a525e3c5ce Implemented do/while loops for shaders 2019-08-13 18:39:55 +03:00
Yuri Roubinski
24417f1975 Force user to initialize local shader constants 2019-08-13 12:31:25 +03:00
Cameron Reikes
9f7a166c35 Show that identifier found in function names 2019-08-09 21:15:33 -07:00
Yuri Roubinski
b24b3497d6 Implemented local shader constants 2019-08-05 10:35:53 +03:00
qarmin
aab8da25ad Fix some code found by Coverity Scan and PVS Studio 2019-07-23 09:14:31 +02:00
Chaosus
cfcc9ee9c1 Allows to use non-constants in the local shader array initializer 2019-07-16 08:04:49 +03:00
Chaosus
9379cbc774 Added local array initializer 2019-07-16 07:13:37 +03:00
Chaosus
c37379456f Implemented local shader arrays 2019-07-15 15:57:39 +03:00
Chaosus
e7f5640632 Added missed "textureProjLod" shader built-in overload for 3D textures 2019-07-15 09:59:11 +03:00
hbina085
26c0609656 Make the default return value on crash explicit
Noticed that the error condition will return a NULL instead of something more explicit like "false".
Should make the code more readable at a glance.
2019-07-11 23:06:58 -04:00
Chaosus
a2b2da2454 Removed invalid mix shader overloads 2019-07-11 17:16:26 +03:00
Chaosus
4083d0c784 Fix "not" shader function return type 2019-07-09 15:55:00 +03:00
geequlim
253cd73f1d Fix code completion for shader editor 2019-07-06 12:03:17 +08:00
Chaosus
c2d4abf62e Added constant support to shaders
Co-authored-by: DavidSichma <sichmada@gmail.com>
2019-06-01 13:41:07 +03:00
Rémi Verschelde
193837a8f5
Merge pull request #28829 from vreon/swizzle-up
Allow constructing larger data types by swizzling
2019-05-24 17:02:26 +02:00
Rémi Verschelde
e0574e1d98 Fix typos with codespell
Using codespell 1.15.0.

Method:
```
$ cat > ../godot-word-whitelist.txt << EOF
ang
curvelinear
doubleclick
leapyear
lod
merchantibility
nd
numer
ois
ony
que
seeked
synching
te
uint
unselect
webp
EOF

$ codespell -w -q 3 -I ../godot-word-whitelist.txt --skip="./thirdparty,*.po"
$ git diff // undo unwanted changes
```
2019-05-19 13:10:35 +02:00
Jesse Dubay
1b9d26765f Allow constructing larger data types by swizzling
GLSL allows the construction of larger data types by swizzling smaller
ones, but Godot shading language treated this as an error:

  vec2 test2 = vec2(0.0, 1.0);
  vec3 test3 = test2.xxx; // error: Invalid member for vec2 expression

This commit updates the expression parser for the 2 and 3-component data
types accordingly.

Fixes #10496
2019-05-11 11:01:09 -07:00
Rémi Verschelde
c8994b56f9 Style: Apply new changes from clang-format 8.0
It seems to stay compatible with formatting done by clang-format 6.0 and 7.0,
so contributors can keep using those versions for now (they will not undo those
changes).
2019-04-09 17:09:48 +02:00
Juan Linietsky
ffb9f342a5 Ensure implicit conversions for scalar constants work in shaders, closes #26239 2019-02-26 23:21:37 -03:00
Juan Linietsky
fd68bb2596 -Treat scalar conversions when calling functions as error, closes #24261
-Make shader editor display errors if exist when just opening it
-Make ShaderMaterial not lose parameters if opened in error.
2019-02-23 17:55:09 -03:00
marxin
8d51618949 Add -Wshadow=local to warnings and fix reported issues.
Fixes #25316.
2019-02-20 19:44:12 +01:00
Hein-Pieter van Braam
d308eb091a Fix many asan and ubsan reported issues
This allows most demos to run without any ubsan or asan errors. There
are still some things in thirdpart/ and some things in AudioServer that
needs a look but this fixes a lot of issues. This should help debug less
obvious issues, hopefully.

This fixes #25217 and fixes #25218
2019-01-30 06:43:56 +01:00
Rémi Verschelde
b16c309f82 Update copyright statements to 2019
Happy new year to the wonderful Godot community!
2019-01-01 12:58:10 +01:00
Bastiaan Olij
c1a53d8b06 Always treat exponent as float 2018-12-30 13:10:58 +01:00
Kanabenki
33a7fae127 Allow *= operator between vec and mat types in shaders 2018-11-24 18:57:29 +01:00
Juan Linietsky
631cf676c3 Removed noperspective (not in GLSL ES 3.0), do not write smooth if not specified. Fixes #20435 2018-11-21 23:07:09 -03:00
JFonS
fb92c7b0fa Use hint_color when getting shader default params 2018-11-16 12:20:23 +01:00
Juan Linietsky
d2e642b2dc Proper validation of out arguments in built-in shader functions, closes #16244 2018-11-14 18:56:19 -03:00
Juan Linietsky
baa8678d2a Do not allow samplers where they dont belong (variables/return types), fixes #15133 2018-11-12 08:36:26 -03:00
Simon Wenner
9fcf9ee813 fixed uninitialized variables and false positives found by CppCheck 2018-10-25 20:38:17 +02:00
Dualtagh Murray
b902a2f2a7 Fixing warnings generated by MSVC
Fixes #22684.
2018-10-19 11:45:24 +02:00
Rémi Verschelde
7b081a7fc8 Fix warnings about unhandled enum value in switch [-Wswitch]
Fixes GCC 5 warnings of the form:

core/io/http_client.cpp:288:9: warning: enumeration value 'STATUS_SSL_HANDSHAKE_ERROR' not handled in switch [-Wswitch]
core/io/marshalls.cpp:806:9: warning: enumeration value 'AABB' not handled in switch [-Wswitch]

Those can be trivial cases where adding a default fallback is the solution,
or more complex issues/hidden bugs where missed values are actually meant
to be handled.
2018-09-27 18:34:30 +02:00
Rémi Verschelde
d95bbb8922 Fix warnings about set but unused variables [-Wunused-but-set-variable]
Fixes the following GCC 5 warnings:
```
drivers/gles2/rasterizer_canvas_gles2.cpp:814:8: warning: variable 'rt_size' set but not used [-Wunused-but-set-variable]
drivers/gles2/rasterizer_scene_gles2.cpp:2270:11: warning: variable 'vp_height' set but not used [-Wunused-but-set-variable]
drivers/gles2/rasterizer_scene_gles2.cpp:2673:22: warning: variable 'e' set but not used [-Wunused-but-set-variable]
drivers/gles2/rasterizer_scene_gles2.cpp:715:7: warning: variable 'no_cull' set but not used [-Wunused-but-set-variable]
drivers/gles2/shader_gles2.cpp:693:14: warning: variable 'cc' set but not used [-Wunused-but-set-variable]
drivers/gles3/rasterizer_canvas_gles3.cpp:1226:8: warning: variable 'rt_size' set but not used [-Wunused-but-set-variable]
drivers/gles3/rasterizer_scene_gles3.cpp:3039:10: warning: variable 'contrib' set but not used [-Wunused-but-set-variable]
drivers/gles3/rasterizer_scene_gles3.cpp:4504:32: warning: variable 'vp_height' set but not used [-Wunused-but-set-variable]
editor/editor_inspector.cpp:272:9: warning: variable 'guide_color' set but not used [-Wunused-but-set-variable]
editor/editor_themes.cpp:1067:14: warning: variable 'alpha3' set but not used [-Wunused-but-set-variable]
editor/editor_themes.cpp:263:8: warning: variable 'script_bg_color' set but not used [-Wunused-but-set-variable]
editor/plugins/collision_shape_2d_editor_plugin.cpp:326:11: warning: variable 'cpoint' set but not used [-Wunused-but-set-variable]
editor/plugins/mesh_editor_plugin.cpp:72:9: warning: variable 'size' set but not used [-Wunused-but-set-variable]
editor/plugins/shader_editor_plugin.cpp:471:12: warning: variable 'mpos' set but not used [-Wunused-but-set-variable]
editor/plugins/shader_editor_plugin.cpp:89:8: warning: variable 'basetype_color' set but not used [-Wunused-but-set-variable]
editor/plugins/shader_editor_plugin.cpp:90:8: warning: variable 'type_color' set but not used [-Wunused-but-set-variable]
editor/plugins/shader_editor_plugin.cpp:92:8: warning: variable 'string_color' set but not used [-Wunused-but-set-variable]
modules/visual_script/visual_script_editor.cpp:2521:7: warning: variable 'seq_connect' set but not used [-Wunused-but-set-variable]
platform/android/export/export.cpp:580:12: warning: variable 'styles_count' set but not used [-Wunused-but-set-variable]
platform/android/export/export.cpp:584:12: warning: variable 'styles_offset' set but not used [-Wunused-but-set-variable]
platform/osx/export/export.cpp:464:9: warning: variable 'zerr' set but not used [-Wunused-but-set-variable]
scene/2d/tile_map.cpp:260:10: warning: variable 'tcenter' set but not used [-Wunused-but-set-variable]
scene/3d/light.cpp:166:7: warning: variable 'editor_ok' set but not used [-Wunused-but-set-variable]
scene/3d/navigation.cpp:566:11: warning: variable 'closest_navmesh' set but not used [-Wunused-but-set-variable]
scene/gui/rich_text_label.cpp:869:8: warning: variable 'size' set but not used [-Wunused-but-set-variable]
scene/main/viewport.cpp:705:14: warning: variable 'xform' set but not used [-Wunused-but-set-variable]
scene/main/viewport.cpp:706:8: warning: variable 'ss' set but not used [-Wunused-but-set-variable]
scene/main/viewport.cpp:726:14: warning: variable 'xform' set but not used [-Wunused-but-set-variable]
scene/main/viewport.cpp:727:8: warning: variable 'ss' set but not used [-Wunused-but-set-variable]
scene/resources/material.cpp:430:7: warning: variable 'using_world' set but not used [-Wunused-but-set-variable]
servers/visual/shader_language.cpp:2026:7: warning: variable 'all_const' set but not used [-Wunused-but-set-variable]
servers/visual/visual_server_scene.cpp:1383:28: warning: variable 'z_max_cam' set but not used [-Wunused-but-set-variable]
```

Also fixes two [-Wunused-value] warnings:
```
scene/gui/text_edit.cpp:4405:20: warning: statement has no effect [-Wunused-value]
servers/visual/visual_server_scene.cpp:905:48: warning: value computed is not used [-Wunused-value]
```

Some of those are bugs and need further work, they are identified with
`// FIXME` comments.
2018-09-27 16:25:24 +02:00
Chaosus
16e5ef6894 Added missed min/max shader overloads 2018-09-21 20:10:03 +03:00
Ibrahn Sahir
bff864818f Fixed an access after free in ShaderLanguage::_reduce_expression.
Passing an element reference of a vector to a push_back call to
that same vector can cause an access after free. This is because push_back
will resize the vector, reallocating if necessary, leaving the reference
referring to the freed memory.
Removed an instance of this usage here.
2018-09-19 14:28:19 +01:00
JFonS
3cedec5f75 Set uniform default values in inspector 2018-09-13 23:05:33 +02:00
Rémi Verschelde
277b24dfb7 Make core/ includes absolute, remove subfolders from include path
This allows more consistency in the manner we include core headers,
where previously there would be a mix of absolute, relative and
include path-dependent includes.
2018-09-12 09:52:22 +02:00
JFonS
f495cede0b Fix handling of shader constants that caused crash, closes #15166 2018-08-31 19:24:48 +02:00
Rémi Verschelde
52466d57e9 Make some debug prints verbose-only, remove others 2018-08-24 14:59:01 +02:00
Chaosus
9634d74d31 Allow matrixes in varyings 2018-08-19 15:36:58 +03:00
Juan Linietsky
0fc1c4eda8
Merge pull request #20149 from Overblob/shader_float_typing
Shader language - Add optional float typings
2018-08-10 18:21:28 -03:00
Thomas Herzog
b4d3f541e7 add 3D textures 2018-07-30 12:20:27 +02:00
Juan Linietsky
d2aaf460fb Manually fix, merge and close #15168 2018-07-29 12:18:37 -03:00
Hein-Pieter van Braam
0e29f7974b Reduce unnecessary COW on Vector by make writing explicit
This commit makes operator[] on Vector const and adds a write proxy to it.  From
now on writes to Vectors need to happen through the .write proxy. So for
instance:

Vector<int> vec;
vec.push_back(10);
std::cout << vec[0] << std::endl;
vec.write[0] = 20;

Failing to use the .write proxy will cause a compilation error.

In addition COWable datatypes can now embed a CowData pointer to their data.
This means that String, CharString, and VMap no longer use or derive from
Vector.

_ALWAYS_INLINE_ and _FORCE_INLINE_ are now equivalent for debug and non-debug
builds. This is a lot faster for Vector in the editor and while running tests.
The reason why this difference used to exist is because force-inlined methods
used to give a bad debugging experience. After extensive testing with modern
compilers this is no longer the case.
2018-07-26 00:54:16 +02:00
Todd Ross
9423f23ffb allow comments and whitespace before shader_type declaration 2018-07-26 00:17:57 +02:00
Chaosus
ca0a6c3fca Added conversions between matrixes in shaders 2018-07-25 18:14:52 +03:00
Rémi Verschelde
1d84c4f870
Merge pull request #20158 from Overblob/Fixed_shader_parsing_error_log
Fixed shader parsing error log
2018-07-17 14:16:56 +02:00
Overblob
e6ad5e23b4 * Small hex/float/integer parsing refactoring
* Potential bug fix on hex (cannot be used atm)
* Added optional typing for floats, eg:
"1f" -> "1.0"
"1.f" -> "1.0"
"1.99f" -> "1.99"
"1." -> "1.0"
2018-07-15 14:58:23 +02:00
Juan Linietsky
f6ce73f724 Visual Shaders are back. 2018-07-14 18:16:18 -03:00
Overblob
7a74d310aa Fixed error due to bad cursor handling when parsing shader code
Fixed completion error log thrown on "no auto-completion found" for typings with no completion.
2018-07-14 19:59:11 +02:00
Oliver Rausch
2368b31e1e Fix return type of isnan and isinf in the shader language 2018-06-01 01:34:32 +02:00
nemerle
f2ba9a1f65 Fix bad operator check in ShaderLanguage::_validate_assign 2018-05-16 21:28:12 +02:00
Juan Linietsky
0db4c576f1
Merge pull request #18533 from JFonS/fix_shader_compile
Fix vector reduction in shader language
2018-05-07 14:30:44 -03:00
JFonS
5b50685b38 Fix vector reduction in shader language 2018-05-07 19:25:31 +02:00
Rémi Verschelde
4cce6f3417
Merge pull request #18321 from Crazy-P/Fixes-logically-dead-code
Fixes logically dead code (Coverity)
2018-05-01 08:35:10 +02:00
Hugo Locurcio
1c419531a0 Change ".." punctuation for "..." in editor strings (#16507) 2018-04-22 19:36:01 +02:00
Crazy-P
e6deba8d19 Fixes logically dead code (Coverity)
Fixes reported logically dead codes by Coverity

* image.cpp: Doesn't really need any modification. But to remove the bug
report then we have to move the MAX call away from the for loop
statement.

* rasterizer_gles3.cpp: Removes unnecessary elif condition since it is
checked earlier in the function

* collada.cpp: If stamement never reached due to macro ERR_CONTINUE does
the same.

* navigation_mesh.cpp: Variables should always be null - however, also
checked for the very same condition in their function call. Leaving this
for review (whether the function call is necessary or not)

* path_editor_plugin.cpp: If cancel is true, then it should restore the
edited value to the original provided.
http://docs.godotengine.org/en/3.0/classes/class_editorspatialgizmo.html#class-editorspatialgizmo-commit-handle

* spatial_editor_gizmos.cpp: the very condition of i >= 3 is
predetermined in the if case right before it. Thus case 1 is always '1'
and case 2 is always '-1'

* grid_map_editor.cpp: Same as above in spatial_editor_gizmos.cpp

* voxel_light_baker.cpp: Same as above in spatial_editor_gizmos.cpp

* visual_server.cpp: Same as above in spatial_editor_gizmos.cpp

* visual_script_expression.cpp: char '-' is already true in the switch
case mechanism. Thus it can never reach to default case.

* particles.cpp: Case 'PARAM_MAX' is unreachable due to index checking
right before the switch execution.

* shader_language.cpp: Invalid index is handled in switch default case.
`type < TYPE_FLOAT && type > TYPE_VEC4` -> `(type < TYPE_FLOAT || type > TYPE_VEC4`)
Fixes the "always false problem" in TODO comment.
2018-04-21 22:35:23 +08:00
Poommetee Ketson
59b816679e
Fix typos in shader_language.cpp 2018-04-17 19:21:00 +07:00
Chaosus
d974fa1780 Removed redundant abs shader builtin 2018-03-28 12:50:55 +03:00
JFonS
479f531635 Hinted shader uniforms can have a default value 2018-03-15 15:23:40 +01:00
Chaosus
97bef8d908 Fix invalid mix function overload 2018-03-10 12:56:43 +03:00
Saracen
b095e21d91 Make the shader token names consistent. 2018-03-07 23:56:47 +00:00
Chaosus
c6b6af7bb5 Fix floatBitsToUint function 2018-03-03 16:22:36 +03:00
Juan Linietsky
4c56edfb83
Revert "Handle single-argument constructors in uniform default values" 2018-02-20 07:28:22 -03:00
Rémi Verschelde
05a8675f82
Merge pull request #15985 from Nallebeorn/uniforms-single-argument-constructors
Handle single-argument constructors in uniform default values
2018-02-20 11:26:26 +01:00
Chaosus
8f04a13c98 Added missing shader functions 2018-02-18 18:08:18 +03:00
Benjamin
311e69aa1e Handle single-argument constructors in shaders.
Expand these (fill vectors, fill matrix diagonals) in _reduce_expression() so they're handled properly even as uniform default values (where they previously caused a crash).
2018-01-22 22:32:35 +01:00
Rémi Verschelde
e4213e66b2 Add missing copyright headers and fix formatting
Using `misc/scripts/fix_headers.py` on all Godot files.
Some missing header guards were added, and the header inclusion order
was fixed in the Bullet module.
2018-01-05 01:22:23 +01:00
binbitten
f141bafba3 Fix premature declaration of shader variables created with assignment 2018-01-03 07:23:04 +01:00
Rémi Verschelde
b50a9114b1 Update copyright statements to 2018
Happy new year to the wonderful Godot community!
2018-01-01 14:40:47 +01:00
binbitten
9b2283382e Fixed wrong highlighted line when erroring and using single-line comments, fixes #15167 2017-12-29 19:32:21 +01:00
Rémi Verschelde
8f25a2dc11 Cleanup some #if 0'd code 2017-12-17 15:40:24 +01:00
Enzo Nocera
8e2a1ffd6e Shader Language: Add in-for declared variables within for-block scope. 2017-12-17 01:43:59 +01:00
Juan Linietsky
e946fb8cb0 Made built-in identifiers properly constant in shaders. Fixes #14449, closes #14629 2017-12-15 18:24:30 -03:00
Scayze
b0fb6b1380 Added interpolation modifiers to shaderlang 2017-11-27 16:47:46 +01:00
RaXaR
b932d8c37a Added overloads of vector parameters for shader Trig functions.
Ammend: Removed whitespace from blank lines.
Ammend2: Removed extra spaces in an attempt to make Clang happy. :)
2017-11-27 01:18:45 +02:00
Juan Linietsky
bc2e8d99e5 Made Vector::ptrw explicit for writing, compiler was sometimes using the wrong function,
leading to unnecesary copy on writes and reduced performance.
2017-11-25 00:09:40 -03:00
Ferenc Arn
0ca9181ee8 Rename two-parameter arc-tangent function to atan in shader language, as it is in GLSL.
Fixes #13214.
2017-11-23 21:19:11 -05:00
Pedro J. Estébanez
7764640f22 Fix crash in shader parsing
...that would happen if incorrect syntax was found just after an opening square bracket.

Fixes #12046.
2017-10-16 21:55:42 +02:00
Juan Linietsky
4f39ce32b9 Fixes to light shaders, should work now.. 2017-09-27 21:45:47 -03:00
Daniel Doran
d0c42da961 Discarding now works in shaders
"discard" has been added to the list of recognised keywords.

A flag specifing when discarding is allowed is now set correctly.
2017-09-24 01:37:53 -06:00
Ferenc Arn
a6c3147c0a Add inversesqrt to shader language. 2017-09-21 21:02:08 -04:00
Hein-Pieter van Braam
b2a38854fd Fix unused variable warnings
The forth in my quest to make Godot 3.x compile with -Werror on GCC7
2017-09-08 15:03:53 +02:00
Juan Linietsky
7eb8760477 Added support for for, break and continue. Closes #10560, closes #10661 2017-09-05 15:25:34 -03:00
Poommetee Ketson
459f526119 Fix typos 'a' and 'an' 2017-09-02 21:19:06 +07:00
Hein-Pieter van Braam
9c63ab99f0 Fix use of unitialized variables
The second in my quest to make Godot 3.x compile with -Werror on GCC7
2017-09-02 01:59:26 +02:00
Poommetee Ketson
69ccae3d99 Fix typo 'begining' to 'beginning' 2017-09-01 22:54:57 +07:00