summaryrefslogtreecommitdiff
path: root/servers/visual
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2018-02-20 11:26:26 +0100
committerGitHub <noreply@github.com>2018-02-20 11:26:26 +0100
commit05a8675f827a36136be635384f3a44ef0e47bc97 (patch)
treeecc51c6e47b4960f2c5c28421213d37b0068479c /servers/visual
parent1fbb83de2c4a6489d419bb7f771163f514de8f5b (diff)
parent311e69aa1e23bf9cc45adbadfb4db43734bd1788 (diff)
Merge pull request #15985 from Nallebeorn/uniforms-single-argument-constructors
Handle single-argument constructors in uniform default values
Diffstat (limited to 'servers/visual')
-rw-r--r--servers/visual/shader_language.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp
index d9f2c949e9..e67d83aaa1 100644
--- a/servers/visual/shader_language.cpp
+++ b/servers/visual/shader_language.cpp
@@ -3138,6 +3138,60 @@ ShaderLanguage::Node *ShaderLanguage::_reduce_expression(BlockNode *p_block, Sha
}
}
+ // Passed a single argument
+ if (op->arguments.size() <= 2) {
+ if (op->get_datatype() < TYPE_MAT2) {
+ // Scalar or vector
+ int dimensions = 0;
+ switch (op->get_datatype()) {
+ case TYPE_VEC2:
+ case TYPE_BVEC2:
+ case TYPE_UVEC2:
+ case TYPE_IVEC2: {
+ dimensions = 2;
+ } break;
+ case TYPE_VEC3:
+ case TYPE_BVEC3:
+ case TYPE_UVEC3:
+ case TYPE_IVEC3: {
+ dimensions = 3;
+ } break;
+ case TYPE_VEC4:
+ case TYPE_BVEC4:
+ case TYPE_UVEC4:
+ case TYPE_IVEC4: {
+ dimensions = 4;
+ } break;
+ }
+
+ if (dimensions) {
+ ConstantNode::Value val = values[0];
+ for (int i = 1; i < dimensions; i++) {
+
+ values.push_back(val);
+ }
+ }
+ } else if (op->get_datatype() <= TYPE_MAT4) {
+ // Matrix
+ int dimensions = 0;
+ switch (op->get_datatype()) {
+ case TYPE_MAT2: dimensions = 2; break;
+ case TYPE_MAT3: dimensions = 3; break;
+ case TYPE_MAT4: dimensions = 4; break;
+ }
+
+ // Fill the diagonal with the value, the rest with zeroes
+ ConstantNode::Value val = values[0];
+ for (int i = 1; i < dimensions * dimensions; i++) {
+ if (i % (dimensions + 1) == 0) {
+ values.push_back(val);
+ } else {
+ values.push_back(ConstantNode::Value());
+ }
+ }
+ }
+ }
+
ConstantNode *cn = alloc_node<ConstantNode>();
cn->datatype = op->get_datatype();
cn->values = values;