summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/SCsub1
-rw-r--r--core/helper/SCsub7
-rw-r--r--core/helper/value_evaluator.h46
-rw-r--r--core/io/multiplayer_api.cpp165
-rw-r--r--core/io/stream_peer.cpp15
-rw-r--r--core/io/stream_peer.h5
-rw-r--r--core/math/math_fieldwise.cpp (renamed from core/helper/math_fieldwise.cpp)0
-rw-r--r--core/math/math_fieldwise.h (renamed from core/helper/math_fieldwise.h)0
-rw-r--r--core/translation.cpp11
-rw-r--r--doc/classes/Array.xml2
-rw-r--r--doc/classes/Node.xml9
-rw-r--r--doc/classes/Physics2DDirectSpaceState.xml2
-rw-r--r--doc/classes/PhysicsDirectSpaceState.xml6
-rw-r--r--doc/classes/StreamPeer.xml19
-rw-r--r--drivers/gles2/rasterizer_scene_gles2.cpp1519
-rw-r--r--drivers/gles2/rasterizer_scene_gles2.h149
-rw-r--r--drivers/gles2/rasterizer_storage_gles2.cpp12
-rw-r--r--drivers/gles2/rasterizer_storage_gles2.h4
-rw-r--r--drivers/gles2/shader_compiler_gles2.cpp20
-rw-r--r--drivers/gles2/shader_gles2.cpp88
-rw-r--r--drivers/gles2/shader_gles2.h3
-rw-r--r--drivers/gles2/shaders/scene.glsl1068
-rw-r--r--drivers/gles3/rasterizer_scene_gles3.cpp36
-rw-r--r--drivers/gles3/shader_compiler_gles3.cpp18
-rw-r--r--drivers/gles3/shader_gles3.cpp5
-rw-r--r--drivers/gles3/shader_gles3.h1
-rw-r--r--drivers/gles3/shaders/scene.glsl27
-rw-r--r--drivers/unix/net_socket_posix.cpp77
-rw-r--r--editor/animation_track_editor.cpp4
-rw-r--r--editor/editor_file_dialog.cpp16
-rw-r--r--editor/editor_settings.cpp10
-rw-r--r--editor/editor_themes.cpp5
-rw-r--r--editor/filesystem_dock.cpp36
-rw-r--r--editor/find_in_files.cpp2
-rw-r--r--editor/icons/icon_text_file.svg57
-rw-r--r--editor/multi_node_edit.cpp2
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp66
-rw-r--r--editor/plugins/canvas_item_editor_plugin.h1
-rw-r--r--editor/plugins/physical_bone_plugin.cpp24
-rw-r--r--editor/plugins/physical_bone_plugin.h2
-rw-r--r--editor/plugins/script_editor_plugin.cpp4
-rw-r--r--editor/plugins/script_text_editor.cpp13
-rw-r--r--editor/property_editor.cpp57
-rw-r--r--editor/property_editor.h21
-rw-r--r--editor/script_create_dialog.cpp19
-rw-r--r--editor/script_create_dialog.h5
-rw-r--r--gles_builders.py6
-rw-r--r--modules/bullet/godot_collision_configuration.cpp56
-rw-r--r--modules/bullet/godot_collision_configuration.h13
-rw-r--r--modules/bullet/space_bullet.cpp15
-rw-r--r--modules/bullet/space_bullet.h2
-rw-r--r--modules/enet/networked_multiplayer_enet.cpp6
-rw-r--r--modules/webm/libvpx/SCsub2
-rw-r--r--modules/websocket/doc_classes/WebSocketClient.xml19
-rw-r--r--modules/websocket/doc_classes/WebSocketPeer.xml8
-rw-r--r--modules/websocket/doc_classes/WebSocketServer.xml23
-rw-r--r--modules/websocket/emws_client.cpp9
-rw-r--r--modules/websocket/emws_client.h2
-rw-r--r--modules/websocket/emws_peer.cpp8
-rw-r--r--modules/websocket/emws_peer.h2
-rw-r--r--modules/websocket/emws_server.cpp2
-rw-r--r--modules/websocket/emws_server.h2
-rw-r--r--modules/websocket/lws_client.cpp21
-rw-r--r--modules/websocket/lws_client.h2
-rw-r--r--modules/websocket/lws_peer.cpp42
-rw-r--r--modules/websocket/lws_peer.h8
-rw-r--r--modules/websocket/lws_server.cpp33
-rw-r--r--modules/websocket/lws_server.h2
-rw-r--r--modules/websocket/websocket_client.cpp14
-rw-r--r--modules/websocket/websocket_client.h5
-rw-r--r--modules/websocket/websocket_peer.cpp2
-rw-r--r--modules/websocket/websocket_peer.h2
-rw-r--r--modules/websocket/websocket_server.cpp14
-rw-r--r--modules/websocket/websocket_server.h5
-rw-r--r--platform/android/export/export.cpp1
-rw-r--r--platform/osx/crash_handler_osx.mm6
-rw-r--r--platform/server/detect.py2
-rw-r--r--platform/x11/crash_handler_x11.cpp6
-rw-r--r--platform/x11/detect.py6
-rw-r--r--scene/3d/visual_instance.cpp2
-rw-r--r--scene/gui/control.cpp2
-rw-r--r--scene/gui/file_dialog.cpp2
-rw-r--r--scene/gui/rich_text_label.cpp63
-rw-r--r--scene/gui/rich_text_label.h8
-rw-r--r--scene/gui/tree.cpp40
-rw-r--r--scene/gui/tree.h5
-rw-r--r--scene/main/node.cpp14
-rw-r--r--scene/main/node.h2
-rw-r--r--scene/main/scene_tree.cpp2
-rw-r--r--scene/resources/material.cpp4
-rw-r--r--servers/visual/shader_language.cpp18
-rw-r--r--servers/visual/shader_types.cpp4
-rw-r--r--servers/visual_server.cpp4
93 files changed, 2686 insertions, 1489 deletions
diff --git a/core/SCsub b/core/SCsub
index 6746cc871a..17b6e2c7ea 100644
--- a/core/SCsub
+++ b/core/SCsub
@@ -117,7 +117,6 @@ SConscript('os/SCsub')
SConscript('math/SCsub')
SConscript('io/SCsub')
SConscript('bind/SCsub')
-SConscript('helper/SCsub')
# Build it all as a library
diff --git a/core/helper/SCsub b/core/helper/SCsub
deleted file mode 100644
index 4efc902717..0000000000
--- a/core/helper/SCsub
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/usr/bin/env python
-
-Import('env')
-
-env.add_source_files(env.core_sources, "*.cpp")
-
-Export('env')
diff --git a/core/helper/value_evaluator.h b/core/helper/value_evaluator.h
deleted file mode 100644
index 39177a7820..0000000000
--- a/core/helper/value_evaluator.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*************************************************************************/
-/* value_evaluator.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
-/* */
-/* 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. */
-/*************************************************************************/
-
-#ifndef VALUE_EVALUATOR_H
-#define VALUE_EVALUATOR_H
-
-#include "core/object.h"
-
-class ValueEvaluator : public Object {
-
- GDCLASS(ValueEvaluator, Object);
-
-public:
- virtual double eval(const String &p_text) {
- return p_text.to_double();
- }
-};
-
-#endif // VALUE_EVALUATOR_H
diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp
index 5503b8d59c..17b77bc535 100644
--- a/core/io/multiplayer_api.cpp
+++ b/core/io/multiplayer_api.cpp
@@ -38,20 +38,23 @@ _FORCE_INLINE_ bool _should_call_local(MultiplayerAPI::RPCMode mode, bool is_mas
switch (mode) {
case MultiplayerAPI::RPC_MODE_DISABLED: {
- //do nothing
+ // Do nothing.
} break;
case MultiplayerAPI::RPC_MODE_REMOTE: {
- //do nothing also, no need to call local
+ // Do nothing also. Remote cannot produce a local call.
} break;
+ case MultiplayerAPI::RPC_MODE_MASTERSYNC: {
+ if (is_master)
+ r_skip_rpc = true; // I am the master, so skip remote call.
+ } // Do not break, fall over to other sync.
case MultiplayerAPI::RPC_MODE_REMOTESYNC:
- case MultiplayerAPI::RPC_MODE_MASTERSYNC:
case MultiplayerAPI::RPC_MODE_PUPPETSYNC: {
- //call it, sync always results in call
+ // Call it, sync always results in a local call.
return true;
} break;
case MultiplayerAPI::RPC_MODE_MASTER: {
if (is_master)
- r_skip_rpc = true; //no other master so..
+ r_skip_rpc = true; // I am the master, so skip remote call.
return is_master;
} break;
case MultiplayerAPI::RPC_MODE_PUPPET: {
@@ -91,7 +94,7 @@ void MultiplayerAPI::poll() {
network_peer->poll();
- if (!network_peer.is_valid()) //it's possible that polling might have resulted in a disconnection, so check here
+ if (!network_peer.is_valid()) // It's possible that polling might have resulted in a disconnection, so check here.
return;
while (network_peer->get_available_packet_count()) {
@@ -110,7 +113,7 @@ void MultiplayerAPI::poll() {
rpc_sender_id = 0;
if (!network_peer.is_valid()) {
- break; //it's also possible that a packet or RPC caused a disconnection, so also check here
+ break; // It's also possible that a packet or RPC caused a disconnection, so also check here.
}
}
}
@@ -157,7 +160,9 @@ Ref<NetworkedMultiplayerPeer> MultiplayerAPI::get_network_peer() const {
void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_packet_len) {
+ ERR_EXPLAIN("Multiplayer root node was not initialized. If you are using custom multiplayer, remember to set the root node via MultiplayerAPI.set_root_node before using it");
ERR_FAIL_COND(root_node == NULL);
+ ERR_EXPLAIN("Invalid packet received. Size too small.");
ERR_FAIL_COND(p_packet_len < 1);
uint8_t packet_type = p_packet[0];
@@ -177,13 +182,15 @@ void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_
case NETWORK_COMMAND_REMOTE_CALL:
case NETWORK_COMMAND_REMOTE_SET: {
+ ERR_EXPLAIN("Invalid packet received. Size too small.");
ERR_FAIL_COND(p_packet_len < 6);
Node *node = _process_get_node(p_from, p_packet, p_packet_len);
+ ERR_EXPLAIN("Invalid packet received. Requested node was not found.");
ERR_FAIL_COND(node == NULL);
- //detect cstring end
+ // Detect cstring end.
int len_end = 5;
for (; len_end < p_packet_len; len_end++) {
if (p_packet[len_end] == 0) {
@@ -191,6 +198,7 @@ void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_
}
}
+ ERR_EXPLAIN("Invalid packet received. Size too small.");
ERR_FAIL_COND(len_end >= p_packet_len);
StringName name = String::utf8((const char *)&p_packet[5]);
@@ -219,9 +227,11 @@ Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, int
Node *node = NULL;
if (target & 0x80000000) {
- //use full path (not cached yet)
+ // Use full path (not cached yet).
int ofs = target & 0x7FFFFFFF;
+
+ ERR_EXPLAIN("Invalid packet received. Size smaller than declared.");
ERR_FAIL_COND_V(ofs >= p_packet_len, NULL);
String paths;
@@ -234,17 +244,19 @@ Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, int
if (!node)
ERR_PRINTS("Failed to get path from RPC: " + String(np));
} else {
- //use cached path
+ // Use cached path.
int id = target;
Map<int, PathGetCache>::Element *E = path_get_cache.find(p_from);
+ ERR_EXPLAIN("Invalid packet received. Requests invalid peer cache.");
ERR_FAIL_COND_V(!E, NULL);
Map<int, PathGetCache::NodeInfo>::Element *F = E->get().nodes.find(id);
+ ERR_EXPLAIN("Invalid packet received. Unabled to find requested cached node.");
ERR_FAIL_COND_V(!F, NULL);
PathGetCache::NodeInfo *ni = &F->get();
- //do proper caching later
+ // Do proper caching later.
node = root_node->get_node(ni->path);
if (!node)
@@ -255,9 +267,10 @@ Node *MultiplayerAPI::_process_get_node(int p_from, const uint8_t *p_packet, int
void MultiplayerAPI::_process_rpc(Node *p_node, const StringName &p_name, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset) {
+ ERR_EXPLAIN("Invalid packet received. Size too small.");
ERR_FAIL_COND(p_offset >= p_packet_len);
- // Check that remote can call the RPC on this node
+ // Check that remote can call the RPC on this node.
RPCMode rpc_mode = RPC_MODE_DISABLED;
const Map<StringName, RPCMode>::Element *E = p_node->get_node_rpc_mode(p_name);
if (E) {
@@ -265,6 +278,8 @@ void MultiplayerAPI::_process_rpc(Node *p_node, const StringName &p_name, int p_
} else if (p_node->get_script_instance()) {
rpc_mode = p_node->get_script_instance()->get_rpc_mode(p_name);
}
+
+ ERR_EXPLAIN("RPC '" + String(p_name) + "' is not allowed from: " + itos(p_from) + ". Mode is " + itos((int)rpc_mode) + ", master is " + itos(p_node->get_network_master()) + ".");
ERR_FAIL_COND(!_can_call_mode(p_node, rpc_mode, p_from));
int argc = p_packet[p_offset];
@@ -277,11 +292,14 @@ void MultiplayerAPI::_process_rpc(Node *p_node, const StringName &p_name, int p_
for (int i = 0; i < argc; i++) {
+ ERR_EXPLAIN("Invalid packet received. Size too small.");
ERR_FAIL_COND(p_offset >= p_packet_len);
+
int vlen;
Error err = decode_variant(args.write[i], &p_packet[p_offset], p_packet_len - p_offset, &vlen);
+ ERR_EXPLAIN("Invalid packet received. Unable to decode RPC argument.");
ERR_FAIL_COND(err != OK);
- //args[i]=p_packet[3+i];
+
argp.write[i] = &args[i];
p_offset += vlen;
}
@@ -298,9 +316,10 @@ void MultiplayerAPI::_process_rpc(Node *p_node, const StringName &p_name, int p_
void MultiplayerAPI::_process_rset(Node *p_node, const StringName &p_name, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset) {
+ ERR_EXPLAIN("Invalid packet received. Size too small.");
ERR_FAIL_COND(p_offset >= p_packet_len);
- // Check that remote can call the RSET on this node
+ // Check that remote can call the RSET on this node.
RPCMode rset_mode = RPC_MODE_DISABLED;
const Map<StringName, RPCMode>::Element *E = p_node->get_node_rset_mode(p_name);
if (E) {
@@ -308,10 +327,15 @@ void MultiplayerAPI::_process_rset(Node *p_node, const StringName &p_name, int p
} else if (p_node->get_script_instance()) {
rset_mode = p_node->get_script_instance()->get_rset_mode(p_name);
}
+
+ ERR_EXPLAIN("RSET '" + String(p_name) + "' is not allowed from: " + itos(p_from) + ". Mode is " + itos((int)rset_mode) + ", master is " + itos(p_node->get_network_master()) + ".");
ERR_FAIL_COND(!_can_call_mode(p_node, rset_mode, p_from));
Variant value;
- decode_variant(value, &p_packet[p_offset], p_packet_len - p_offset);
+ Error err = decode_variant(value, &p_packet[p_offset], p_packet_len - p_offset);
+
+ ERR_EXPLAIN("Invalid packet received. Unable to decode RSET value.");
+ ERR_FAIL_COND(err != OK);
bool valid;
@@ -324,6 +348,7 @@ void MultiplayerAPI::_process_rset(Node *p_node, const StringName &p_name, int p
void MultiplayerAPI::_process_simplify_path(int p_from, const uint8_t *p_packet, int p_packet_len) {
+ ERR_EXPLAIN("Invalid packet received. Size too small.");
ERR_FAIL_COND(p_packet_len < 5);
int id = decode_uint32(&p_packet[1]);
@@ -342,9 +367,7 @@ void MultiplayerAPI::_process_simplify_path(int p_from, const uint8_t *p_packet,
path_get_cache[p_from].nodes[id] = ni;
- //send ack
-
- //encode path
+ // Encode path to send ack.
CharString pname = String(path).utf8();
int len = encode_cstring(pname.get_data(), NULL);
@@ -361,6 +384,7 @@ void MultiplayerAPI::_process_simplify_path(int p_from, const uint8_t *p_packet,
void MultiplayerAPI::_process_confirm_path(int p_from, const uint8_t *p_packet, int p_packet_len) {
+ ERR_EXPLAIN("Invalid packet received. Size too small.");
ERR_FAIL_COND(p_packet_len < 2);
String paths;
@@ -369,31 +393,33 @@ void MultiplayerAPI::_process_confirm_path(int p_from, const uint8_t *p_packet,
NodePath path = paths;
PathSentCache *psc = path_send_cache.getptr(path);
+ ERR_EXPLAIN("Invalid packet received. Tries to confirm a path which was not found in cache.");
ERR_FAIL_COND(!psc);
Map<int, bool>::Element *E = psc->confirmed_peers.find(p_from);
+ ERR_EXPLAIN("Invalid packet received. Source peer was not found in cache for the given path.");
ERR_FAIL_COND(!E);
E->get() = true;
}
bool MultiplayerAPI::_send_confirm_path(NodePath p_path, PathSentCache *psc, int p_target) {
bool has_all_peers = true;
- List<int> peers_to_add; //if one is missing, take note to add it
+ List<int> peers_to_add; // If one is missing, take note to add it.
for (Set<int>::Element *E = connected_peers.front(); E; E = E->next()) {
if (p_target < 0 && E->get() == -p_target)
- continue; //continue, excluded
+ continue; // Continue, excluded.
if (p_target > 0 && E->get() != p_target)
- continue; //continue, not for this peer
+ continue; // Continue, not for this peer.
Map<int, bool>::Element *F = psc->confirmed_peers.find(E->get());
if (!F || F->get() == false) {
- //path was not cached, or was cached but is unconfirmed
+ // Path was not cached, or was cached but is unconfirmed.
if (!F) {
- //not cached at all, take note
+ // Not cached at all, take note.
peers_to_add.push_back(E->get());
}
@@ -401,11 +427,11 @@ bool MultiplayerAPI::_send_confirm_path(NodePath p_path, PathSentCache *psc, int
}
}
- //those that need to be added, send a message for this
+ // Those that need to be added, send a message for this.
for (List<int>::Element *E = peers_to_add.front(); E; E = E->next()) {
- //encode function name
+ // Encode function name.
CharString pname = String(p_path).utf8();
int len = encode_cstring(pname.get_data(), NULL);
@@ -416,11 +442,11 @@ bool MultiplayerAPI::_send_confirm_path(NodePath p_path, PathSentCache *psc, int
encode_uint32(psc->id, &packet.write[1]);
encode_cstring(pname.get_data(), &packet.write[5]);
- network_peer->set_target_peer(E->get()); //to all of you
+ network_peer->set_target_peer(E->get()); // To all of you.
network_peer->set_transfer_mode(NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE);
network_peer->put_packet(packet.ptr(), packet.size());
- psc->confirmed_peers.insert(E->get(), false); //insert into confirmed, but as false since it was not confirmed
+ psc->confirmed_peers.insert(E->get(), false); // Insert into confirmed, but as false since it was not confirmed.
}
return has_all_peers;
@@ -459,35 +485,36 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p
}
NodePath from_path = (root_node->get_path()).rel_path_to(p_from->get_path());
+ ERR_EXPLAIN("Unable to send RPC. Relative path is empty. THIS IS LIKELY A BUG IN THE ENGINE!");
ERR_FAIL_COND(from_path.is_empty());
- //see if the path is cached
+ // See if the path is cached.
PathSentCache *psc = path_send_cache.getptr(from_path);
if (!psc) {
- //path is not cached, create
+ // Path is not cached, create.
path_send_cache[from_path] = PathSentCache();
psc = path_send_cache.getptr(from_path);
psc->id = last_send_cache_id++;
}
- //create base packet, lots of hardcode because it must be tight
+ // Create base packet, lots of hardcode because it must be tight.
int ofs = 0;
#define MAKE_ROOM(m_amount) \
if (packet_cache.size() < m_amount) packet_cache.resize(m_amount);
- //encode type
+ // Encode type.
MAKE_ROOM(1);
packet_cache.write[0] = p_set ? NETWORK_COMMAND_REMOTE_SET : NETWORK_COMMAND_REMOTE_CALL;
ofs += 1;
- //encode ID
+ // Encode ID.
MAKE_ROOM(ofs + 4);
encode_uint32(psc->id, &(packet_cache.write[ofs]));
ofs += 4;
- //encode function name
+ // Encode function name.
CharString name = String(p_name).utf8();
int len = encode_cstring(name.get_data(), NULL);
MAKE_ROOM(ofs + len);
@@ -495,20 +522,22 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p
ofs += len;
if (p_set) {
- //set argument
+ // Set argument.
Error err = encode_variant(*p_arg[0], NULL, len);
+ ERR_EXPLAIN("Unable to encode RSET value. THIS IS LIKELY A BUG IN THE ENGINE!");
ERR_FAIL_COND(err != OK);
MAKE_ROOM(ofs + len);
encode_variant(*p_arg[0], &(packet_cache.write[ofs]), len);
ofs += len;
} else {
- //call arguments
+ // Call arguments.
MAKE_ROOM(ofs + 1);
packet_cache.write[ofs] = p_argcount;
ofs += 1;
for (int i = 0; i < p_argcount; i++) {
Error err = encode_variant(*p_arg[i], NULL, len);
+ ERR_EXPLAIN("Unable to encode RPC argument. THIS IS LIKELY A BUG IN THE ENGINE!");
ERR_FAIL_COND(err != OK);
MAKE_ROOM(ofs + len);
encode_variant(*p_arg[i], &(packet_cache.write[ofs]), len);
@@ -516,21 +545,21 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p
}
}
- //see if all peers have cached path (is so, call can be fast)
+ // See if all peers have cached path (is so, call can be fast).
bool has_all_peers = _send_confirm_path(from_path, psc, p_to);
- //take chance and set transfer mode, since all send methods will use it
+ // Take chance and set transfer mode, since all send methods will use it.
network_peer->set_transfer_mode(p_unreliable ? NetworkedMultiplayerPeer::TRANSFER_MODE_UNRELIABLE : NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE);
if (has_all_peers) {
- //they all have verified paths, so send fast
- network_peer->set_target_peer(p_to); //to all of you
- network_peer->put_packet(packet_cache.ptr(), ofs); //a message with love
+ // They all have verified paths, so send fast.
+ network_peer->set_target_peer(p_to); // To all of you.
+ network_peer->put_packet(packet_cache.ptr(), ofs); // A message with love.
} else {
- //not all verified path, so send one by one
+ // Not all verified path, so send one by one.
- //apend path at the end, since we will need it for some packets
+ // Append path at the end, since we will need it for some packets.
CharString pname = String(from_path).utf8();
int path_len = encode_cstring(pname.get_data(), NULL);
MAKE_ROOM(ofs + path_len);
@@ -539,23 +568,23 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p
for (Set<int>::Element *E = connected_peers.front(); E; E = E->next()) {
if (p_to < 0 && E->get() == -p_to)
- continue; //continue, excluded
+ continue; // Continue, excluded.
if (p_to > 0 && E->get() != p_to)
- continue; //continue, not for this peer
+ continue; // Continue, not for this peer.
Map<int, bool>::Element *F = psc->confirmed_peers.find(E->get());
- ERR_CONTINUE(!F); //should never happen
+ ERR_CONTINUE(!F); // Should never happen.
- network_peer->set_target_peer(E->get()); //to this one specifically
+ network_peer->set_target_peer(E->get()); // To this one specifically.
if (F->get() == true) {
- //this one confirmed path, so use id
+ // This one confirmed path, so use id.
encode_uint32(psc->id, &(packet_cache.write[1]));
network_peer->put_packet(packet_cache.ptr(), ofs);
} else {
- //this one did not confirm path yet, so use entire path (sorry!)
- encode_uint32(0x80000000 | ofs, &(packet_cache.write[1])); //offset to path and flag
+ // This one did not confirm path yet, so use entire path (sorry!).
+ encode_uint32(0x80000000 | ofs, &(packet_cache.write[1])); // Offset to path and flag.
network_peer->put_packet(packet_cache.ptr(), ofs + path_len);
}
}
@@ -570,7 +599,7 @@ void MultiplayerAPI::_add_peer(int p_id) {
void MultiplayerAPI::_del_peer(int p_id) {
connected_peers.erase(p_id);
- path_get_cache.erase(p_id); //I no longer need your cache, sorry
+ path_get_cache.erase(p_id); // I no longer need your cache, sorry.
emit_signal("network_peer_disconnected", p_id);
}
@@ -591,8 +620,12 @@ void MultiplayerAPI::_server_disconnected() {
void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const StringName &p_method, const Variant **p_arg, int p_argcount) {
- ERR_FAIL_COND(!p_node->is_inside_tree());
+ ERR_EXPLAIN("Trying to call an RPC while no network peer is active.");
ERR_FAIL_COND(!network_peer.is_valid());
+ ERR_EXPLAIN("Trying to call an RPC on a node which is not inside SceneTree.");
+ ERR_FAIL_COND(!p_node->is_inside_tree());
+ ERR_EXPLAIN("Trying to call an RPC via a network peer which is not connected.");
+ ERR_FAIL_COND(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED);
int node_id = network_peer->get_unique_id();
bool skip_rpc = false;
@@ -601,7 +634,7 @@ void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const
bool is_master = p_node->is_network_master();
if (p_peer_id == 0 || p_peer_id == node_id || (p_peer_id < 0 && p_peer_id != -node_id)) {
- //check that send mode can use local call
+ // Check that send mode can use local call.
const Map<StringName, RPCMode>::Element *E = p_node->get_node_rpc_mode(p_method);
if (E) {
@@ -609,9 +642,9 @@ void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const
}
if (call_local_native) {
- // done below
+ // Done below.
} else if (p_node->get_script_instance()) {
- //attempt with script
+ // Attempt with script.
RPCMode rpc_mode = p_node->get_script_instance()->get_rpc_mode(p_method);
call_local_script = _should_call_local(rpc_mode, is_master, skip_rpc);
}
@@ -647,15 +680,19 @@ void MultiplayerAPI::rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const
void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const StringName &p_property, const Variant &p_value) {
- ERR_FAIL_COND(!p_node->is_inside_tree());
+ ERR_EXPLAIN("Trying to RSET while no network peer is active.");
ERR_FAIL_COND(!network_peer.is_valid());
+ ERR_EXPLAIN("Trying to RSET on a node which is not inside SceneTree.");
+ ERR_FAIL_COND(!p_node->is_inside_tree());
+ ERR_EXPLAIN("Trying to send an RSET via a network peer which is not connected.");
+ ERR_FAIL_COND(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED);
int node_id = network_peer->get_unique_id();
bool is_master = p_node->is_network_master();
bool skip_rset = false;
if (p_peer_id == 0 || p_peer_id == node_id || (p_peer_id < 0 && p_peer_id != -node_id)) {
- //check that send mode can use local call
+ // Check that send mode can use local call.
bool set_local = false;
@@ -675,7 +712,7 @@ void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const
return;
}
} else if (p_node->get_script_instance()) {
- //attempt with script
+ // Attempt with script.
RPCMode rpc_mode = p_node->get_script_instance()->get_rset_mode(p_property);
set_local = _should_call_local(rpc_mode, is_master, skip_rset);
@@ -703,8 +740,11 @@ void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const
Error MultiplayerAPI::send_bytes(PoolVector<uint8_t> p_data, int p_to, NetworkedMultiplayerPeer::TransferMode p_mode) {
+ ERR_EXPLAIN("Trying to send an empty raw packet.");
ERR_FAIL_COND_V(p_data.size() < 1, ERR_INVALID_DATA);
+ ERR_EXPLAIN("Trying to send a raw packet while no network peer is active.");
ERR_FAIL_COND_V(!network_peer.is_valid(), ERR_UNCONFIGURED);
+ ERR_EXPLAIN("Trying to send a raw packet via a network peer which is not connected.");
ERR_FAIL_COND_V(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED, ERR_UNCONFIGURED);
MAKE_ROOM(p_data.size() + 1);
@@ -720,6 +760,7 @@ Error MultiplayerAPI::send_bytes(PoolVector<uint8_t> p_data, int p_to, Networked
void MultiplayerAPI::_process_raw(int p_from, const uint8_t *p_packet, int p_packet_len) {
+ ERR_EXPLAIN("Invalid packet received. Size too small.");
ERR_FAIL_COND(p_packet_len < 2);
PoolVector<uint8_t> out;
@@ -734,30 +775,36 @@ void MultiplayerAPI::_process_raw(int p_from, const uint8_t *p_packet, int p_pac
int MultiplayerAPI::get_network_unique_id() const {
+ ERR_EXPLAIN("No network peer is assigned. Unable to get unique network ID.");
ERR_FAIL_COND_V(!network_peer.is_valid(), 0);
return network_peer->get_unique_id();
}
bool MultiplayerAPI::is_network_server() const {
+ // XXX Maybe fail silently? Maybe should actually return true to make development of both local and online multiplayer easier?
+ ERR_EXPLAIN("No network peer is assigned. I can't be a server.");
ERR_FAIL_COND_V(!network_peer.is_valid(), false);
return network_peer->is_server();
}
void MultiplayerAPI::set_refuse_new_network_connections(bool p_refuse) {
+ ERR_EXPLAIN("No network peer is assigned. Unable to set 'refuse_new_connections'.");
ERR_FAIL_COND(!network_peer.is_valid());
network_peer->set_refuse_new_connections(p_refuse);
}
bool MultiplayerAPI::is_refusing_new_network_connections() const {
+ ERR_EXPLAIN("No network peer is assigned. Unable to get 'refuse_new_connections'.");
ERR_FAIL_COND_V(!network_peer.is_valid(), false);
return network_peer->is_refusing_new_connections();
}
Vector<int> MultiplayerAPI::get_network_connected_peers() const {
+ ERR_EXPLAIN("No network peer is assigned. Assume no peers are connected.");
ERR_FAIL_COND_V(!network_peer.is_valid(), Vector<int>());
Vector<int> ret;
@@ -802,9 +849,9 @@ void MultiplayerAPI::_bind_methods() {
BIND_ENUM_CONSTANT(RPC_MODE_REMOTE);
BIND_ENUM_CONSTANT(RPC_MODE_MASTER);
BIND_ENUM_CONSTANT(RPC_MODE_PUPPET);
- BIND_ENUM_CONSTANT(RPC_MODE_SLAVE); // deprecated
+ BIND_ENUM_CONSTANT(RPC_MODE_SLAVE); // Deprecated.
BIND_ENUM_CONSTANT(RPC_MODE_REMOTESYNC);
- BIND_ENUM_CONSTANT(RPC_MODE_SYNC); // deprecated
+ BIND_ENUM_CONSTANT(RPC_MODE_SYNC); // Deprecated.
BIND_ENUM_CONSTANT(RPC_MODE_MASTERSYNC);
BIND_ENUM_CONSTANT(RPC_MODE_PUPPETSYNC);
}
diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp
index 156a842e35..3f608b720c 100644
--- a/core/io/stream_peer.cpp
+++ b/core/io/stream_peer.cpp
@@ -209,6 +209,12 @@ void StreamPeer::put_double(double p_val) {
}
put_data(buf, 8);
}
+void StreamPeer::put_string(const String &p_string) {
+
+ CharString cs = p_string.ascii();
+ put_u32(cs.length());
+ put_data((const uint8_t *)cs.get_data(), cs.length());
+}
void StreamPeer::put_utf8_string(const String &p_string) {
CharString cs = p_string.utf8();
@@ -325,6 +331,8 @@ double StreamPeer::get_double() {
}
String StreamPeer::get_string(int p_bytes) {
+ if (p_bytes < 0)
+ p_bytes = get_u32();
ERR_FAIL_COND_V(p_bytes < 0, String());
Vector<char> buf;
@@ -337,6 +345,8 @@ String StreamPeer::get_string(int p_bytes) {
}
String StreamPeer::get_utf8_string(int p_bytes) {
+ if (p_bytes < 0)
+ p_bytes = get_u32();
ERR_FAIL_COND_V(p_bytes < 0, String());
Vector<uint8_t> buf;
@@ -386,6 +396,7 @@ void StreamPeer::_bind_methods() {
ClassDB::bind_method(D_METHOD("put_u64", "value"), &StreamPeer::put_u64);
ClassDB::bind_method(D_METHOD("put_float", "value"), &StreamPeer::put_float);
ClassDB::bind_method(D_METHOD("put_double", "value"), &StreamPeer::put_double);
+ ClassDB::bind_method(D_METHOD("put_string", "value"), &StreamPeer::put_string);
ClassDB::bind_method(D_METHOD("put_utf8_string", "value"), &StreamPeer::put_utf8_string);
ClassDB::bind_method(D_METHOD("put_var", "value"), &StreamPeer::put_var);
@@ -399,8 +410,8 @@ void StreamPeer::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_u64"), &StreamPeer::get_u64);
ClassDB::bind_method(D_METHOD("get_float"), &StreamPeer::get_float);
ClassDB::bind_method(D_METHOD("get_double"), &StreamPeer::get_double);
- ClassDB::bind_method(D_METHOD("get_string", "bytes"), &StreamPeer::get_string);
- ClassDB::bind_method(D_METHOD("get_utf8_string", "bytes"), &StreamPeer::get_utf8_string);
+ ClassDB::bind_method(D_METHOD("get_string", "bytes"), &StreamPeer::get_string, DEFVAL(-1));
+ ClassDB::bind_method(D_METHOD("get_utf8_string", "bytes"), &StreamPeer::get_utf8_string, DEFVAL(-1));
ClassDB::bind_method(D_METHOD("get_var"), &StreamPeer::get_var);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "big_endian"), "set_big_endian", "is_big_endian_enabled");
diff --git a/core/io/stream_peer.h b/core/io/stream_peer.h
index 9d2e0340b0..f189960cbd 100644
--- a/core/io/stream_peer.h
+++ b/core/io/stream_peer.h
@@ -71,6 +71,7 @@ public:
void put_u64(uint64_t p_val);
void put_float(float p_val);
void put_double(double p_val);
+ void put_string(const String &p_string);
void put_utf8_string(const String &p_string);
void put_var(const Variant &p_variant);
@@ -84,8 +85,8 @@ public:
int64_t get_64();
float get_float();
double get_double();
- String get_string(int p_bytes);
- String get_utf8_string(int p_bytes);
+ String get_string(int p_bytes = -1);
+ String get_utf8_string(int p_bytes = -1);
Variant get_var();
StreamPeer() { big_endian = false; }
diff --git a/core/helper/math_fieldwise.cpp b/core/math/math_fieldwise.cpp
index 20b2341ab0..20b2341ab0 100644
--- a/core/helper/math_fieldwise.cpp
+++ b/core/math/math_fieldwise.cpp
diff --git a/core/helper/math_fieldwise.h b/core/math/math_fieldwise.h
index 0e7cc3ea4a..0e7cc3ea4a 100644
--- a/core/helper/math_fieldwise.h
+++ b/core/math/math_fieldwise.h
diff --git a/core/translation.cpp b/core/translation.cpp
index ce9b338ef6..25e67e9b96 100644
--- a/core/translation.cpp
+++ b/core/translation.cpp
@@ -938,11 +938,14 @@ void TranslationServer::set_locale(const String &p_locale) {
if (!is_locale_valid(univ_locale)) {
String trimmed_locale = get_trimmed_locale(univ_locale);
+ print_verbose(vformat("Unsupported locale '%s', falling back to '%s'.", p_locale, trimmed_locale));
- ERR_EXPLAIN("Invalid locale: " + trimmed_locale);
- ERR_FAIL_COND(!is_locale_valid(trimmed_locale));
-
- locale = trimmed_locale;
+ if (!is_locale_valid(trimmed_locale)) {
+ ERR_PRINTS(vformat("Unsupported locale '%s', falling back to 'en'.", trimmed_locale));
+ locale = "en";
+ } else {
+ locale = trimmed_locale;
+ }
} else {
locale = univ_locale;
}
diff --git a/doc/classes/Array.xml b/doc/classes/Array.xml
index 3bd621799a..b134650f8d 100644
--- a/doc/classes/Array.xml
+++ b/doc/classes/Array.xml
@@ -321,7 +321,7 @@
static func sort(a, b):
if a[0] &lt; b[0]:
return true
- return false
+ return false
var my_items = [[5, "Potato"], [9, "Rice"], [4, "Tomato"]]
my_items.sort_custom(MyCustomSorter, "sort")
diff --git a/doc/classes/Node.xml b/doc/classes/Node.xml
index d00652d40c..90e9436307 100644
--- a/doc/classes/Node.xml
+++ b/doc/classes/Node.xml
@@ -266,6 +266,15 @@
Returns the parent node of the current node, or an empty [code]Node[/code] if the node lacks a parent.
</description>
</method>
+ <method name="find_parent" qualifiers="const">
+ <return type="Node">
+ </return>
+ <argument index="0" name="mask" type="String">
+ </argument>
+ <description>
+ Finds the first parent of the current node whose name matches [code]mask[/code] as in [method String.match] (i.e. case sensitive, but '*' matches zero or more characters and '?' matches any single character except '.'). Note that it does not match against the full path, just against individual node names.
+ </description>
+ </method>
<method name="get_path" qualifiers="const">
<return type="NodePath">
</return>
diff --git a/doc/classes/Physics2DDirectSpaceState.xml b/doc/classes/Physics2DDirectSpaceState.xml
index 483c71b2c0..aa54d9a11a 100644
--- a/doc/classes/Physics2DDirectSpaceState.xml
+++ b/doc/classes/Physics2DDirectSpaceState.xml
@@ -117,7 +117,7 @@
[code]metadata[/code]: The intersecting shape's metadata. This metadata is different from [method Object.get_meta], and is set with [method Physics2DServer.shape_set_data].
[code]rid[/code]: The intersecting object's [RID].
[code]shape[/code]: The shape index of the colliding shape.
- The number of intersections can be limited with the second parameter, to reduce the processing time.
+ The number of intersections can be limited with the [code]max_results[/code] parameter, to reduce the processing time.
</description>
</method>
</methods>
diff --git a/doc/classes/PhysicsDirectSpaceState.xml b/doc/classes/PhysicsDirectSpaceState.xml
index 2f7cf5a8f3..1fd00fa21c 100644
--- a/doc/classes/PhysicsDirectSpaceState.xml
+++ b/doc/classes/PhysicsDirectSpaceState.xml
@@ -21,7 +21,7 @@
</argument>
<description>
Checks whether the shape can travel to a point. The method will return an array with two floats between 0 and 1, both representing a fraction of [code]motion[/code]. The first is how far the shape can move without triggering a collision, and the second is the point at which a collision will occur. If no collision is detected, the returned array will be [1, 1].
- If the shape can not move, the array will be empty.
+ If the shape can not move, the returned array will be [0, 0].
</description>
</method>
<method name="collide_shape">
@@ -41,7 +41,7 @@
<argument index="0" name="shape" type="PhysicsShapeQueryParameters">
</argument>
<description>
- Checks the intersections of a shape, given through a [PhysicsShapeQueryParameters] object, against the space. If it collides with more than a shape, the nearest one is selected. The returned object is a dictionary containing the following fields:
+ Checks the intersections of a shape, given through a [PhysicsShapeQueryParameters] object, against the space. If it collides with more than one shape, the nearest one is selected. The returned object is a dictionary containing the following fields:
[code]collider_id[/code]: The colliding object's ID.
[code]linear_velocity[/code]: The colliding object's velocity [Vector3]. If the object is an [Area], the result is [code](0, 0, 0)[/code].
[code]normal[/code]: The object's surface normal at the intersection point.
@@ -91,7 +91,7 @@
[code]collider_id[/code]: The colliding object's ID.
[code]rid[/code]: The intersecting object's [RID].
[code]shape[/code]: The shape index of the colliding shape.
- The number of intersections can be limited with the second parameter, to reduce the processing time.
+ The number of intersections can be limited with the [code]max_results[/code] parameter, to reduce the processing time.
</description>
</method>
</methods>
diff --git a/doc/classes/StreamPeer.xml b/doc/classes/StreamPeer.xml
index ebe29c7e24..74ac8a79c0 100644
--- a/doc/classes/StreamPeer.xml
+++ b/doc/classes/StreamPeer.xml
@@ -81,10 +81,10 @@
<method name="get_string">
<return type="String">
</return>
- <argument index="0" name="bytes" type="int">
+ <argument index="0" name="bytes" type="int" default="-1">
</argument>
<description>
- Get a string with byte-length "bytes" from the stream.
+ Get a string with byte-length [code]bytes[/code] from the stream. If [code]bytes[/code] is negative (default) the length will be read from the stream using the reverse process of [method put_string].
</description>
</method>
<method name="get_u16">
@@ -118,10 +118,10 @@
<method name="get_utf8_string">
<return type="String">
</return>
- <argument index="0" name="bytes" type="int">
+ <argument index="0" name="bytes" type="int" default="-1">
</argument>
<description>
- Get a utf8 string with byte-length "bytes" from the stream (this decodes the string sent as utf8).
+ Get a utf8 string with byte-length [code]bytes[/code] from the stream (this decodes the string sent as utf8). If [code]bytes[/code] is negative (default) the length will be read from the stream using the reverse process of [method put_utf8_string].
</description>
</method>
<method name="get_var">
@@ -203,6 +203,15 @@
Send a chunk of data through the connection, if all the data could not be sent at once, only part of it will. This function returns two values, an Error code and an integer, describing how much data was actually sent.
</description>
</method>
+ <method name="put_string">
+ <return type="void">
+ </return>
+ <argument index="0" name="value" type="String">
+ </argument>
+ <description>
+ Put a zero-terminated ascii string into the stream prepended by a 32 bits unsigned integer representing its size.
+ </description>
+ </method>
<method name="put_u16">
<return type="void">
</return>
@@ -245,7 +254,7 @@
<argument index="0" name="value" type="String">
</argument>
<description>
- Put a zero-terminated utf8 string into the stream.
+ Put a zero-terminated utf8 string into the stream prepended by a 32 bits unsigned integer representing its size.
</description>
</method>
<method name="put_var">
diff --git a/drivers/gles2/rasterizer_scene_gles2.cpp b/drivers/gles2/rasterizer_scene_gles2.cpp
index ca9f6dcbf8..56605a9fe5 100644
--- a/drivers/gles2/rasterizer_scene_gles2.cpp
+++ b/drivers/gles2/rasterizer_scene_gles2.cpp
@@ -110,8 +110,8 @@ void RasterizerSceneGLES2::shadow_atlas_set_size(RID p_atlas, int p_size) {
glBindTexture(GL_TEXTURE_2D, shadow_atlas->depth);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, shadow_atlas->size, shadow_atlas->size, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
@@ -604,6 +604,8 @@ RID RasterizerSceneGLES2::light_instance_create(RID p_light) {
light_instance->light = p_light;
light_instance->light_ptr = storage->light_owner.getornull(p_light);
+ light_instance->light_index = 0xFFFF;
+
ERR_FAIL_COND_V(!light_instance->light_ptr, RID());
light_instance->self = light_instance_owner.make_rid(light_instance);
@@ -709,9 +711,42 @@ void RasterizerSceneGLES2::_add_geometry_with_material(RasterizerStorageGLES2::G
bool has_blend_alpha = p_material->shader->spatial.blend_mode != RasterizerStorageGLES2::Shader::Spatial::BLEND_MODE_MIX;
bool has_alpha = has_base_alpha || has_blend_alpha;
- // TODO add this stuff
- // bool mirror = p_instance->mirror;
- // bool no_cull = false;
+ bool mirror = p_instance->mirror;
+ bool no_cull = false;
+
+ if (p_material->shader->spatial.cull_mode == RasterizerStorageGLES2::Shader::Spatial::CULL_MODE_DISABLED) {
+ no_cull = true;
+ mirror = false;
+ } else if (p_material->shader->spatial.cull_mode == RasterizerStorageGLES2::Shader::Spatial::CULL_MODE_FRONT) {
+ mirror = !mirror;
+ }
+
+ //if (p_material->shader->spatial.uses_sss) {
+ // state.used_sss = true;
+ //}
+
+ if (p_material->shader->spatial.uses_screen_texture) {
+ state.used_screen_texture = true;
+ }
+
+ if (p_depth_pass) {
+
+ if (has_blend_alpha || p_material->shader->spatial.uses_depth_texture || (has_base_alpha && p_material->shader->spatial.depth_draw_mode != RasterizerStorageGLES2::Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS))
+ return; //bye
+
+ if (!p_material->shader->spatial.uses_alpha_scissor && !p_material->shader->spatial.writes_modelview_or_projection && !p_material->shader->spatial.uses_vertex && !p_material->shader->spatial.uses_discard && p_material->shader->spatial.depth_draw_mode != RasterizerStorageGLES2::Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS) {
+ //shader does not use discard and does not write a vertex position, use generic material
+ if (p_instance->cast_shadows == VS::SHADOW_CASTING_SETTING_DOUBLE_SIDED) {
+ p_material = storage->material_owner.getptr(!p_shadow_pass && p_material->shader->spatial.uses_world_coordinates ? default_worldcoord_material_twosided : default_material_twosided);
+ no_cull = true;
+ mirror = false;
+ } else {
+ p_material = storage->material_owner.getptr(!p_shadow_pass && p_material->shader->spatial.uses_world_coordinates ? default_worldcoord_material : default_material);
+ }
+ }
+
+ has_alpha = false;
+ }
RenderList::Element *e = has_alpha ? render_list.add_alpha_element() : render_list.add_element();
@@ -724,46 +759,107 @@ void RasterizerSceneGLES2::_add_geometry_with_material(RasterizerStorageGLES2::G
e->instance = p_instance;
e->owner = p_owner;
e->sort_key = 0;
+ e->depth_key = 0;
+ e->use_accum = false;
+ e->light_index = RenderList::MAX_LIGHTS;
+ e->use_accum_ptr = &e->use_accum;
+
+ if (e->geometry->last_pass != render_pass) {
+ e->geometry->last_pass = render_pass;
+ e->geometry->index = current_geometry_index++;
+ }
- // TODO check render pass of geometry
-
- // TODO check directional light flag
+ e->geometry_index = e->geometry->index;
- if (p_depth_pass) {
- // if we are in the depth pass we can sort out a few things to improve performance
+ if (e->material->last_pass != render_pass) {
+ e->material->last_pass = render_pass;
+ e->material->index = current_material_index++;
- if (has_blend_alpha || p_material->shader->spatial.uses_depth_texture || (has_base_alpha && p_material->shader->spatial.depth_draw_mode != RasterizerStorageGLES2::Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS)) {
- return;
+ if (e->material->shader->last_pass != render_pass) {
+ e->material->shader->index = current_shader_index++;
}
+ }
- if (p_material->shader->spatial.uses_alpha_scissor && !p_material->shader->spatial.writes_modelview_or_projection && !p_material->shader->spatial.uses_vertex && !p_material->shader->spatial.uses_discard && p_material->shader->spatial.depth_draw_mode != RasterizerStorageGLES2::Shader::Spatial::DEPTH_DRAW_ALPHA_PREPASS) {
+ e->material_index = e->material->index;
- // shader doesn't use discard or writes a custom vertex position,
- // so we can use a stripped down shader instead
+ e->refprobe_0_index = 0xFF; //refprobe disabled by default
+ e->refprobe_1_index = 0xFF; //refprobe disabled by default
- // TODO twosided and worldcoord stuff
+ if (!p_depth_pass) {
- p_material = storage->material_owner.getptr(default_material_twosided);
- }
+ e->depth_layer = e->instance->depth_layer;
+ e->priority = p_material->render_priority;
- has_alpha = false;
- }
+ //if (e->instance->reflection_probe_instances.size() > 0 ) {
+ // RasterizerStorageGLES2::
+ //}
- e->sort_key |= uint64_t(e->geometry->index) << RenderList::SORT_KEY_GEOMETRY_INDEX_SHIFT;
- e->sort_key |= uint64_t(e->instance->base_type) << RenderList::SORT_KEY_GEOMETRY_TYPE_SHIFT;
+ //add directional lights
- if (p_material->shader->spatial.unshaded) {
- e->sort_key |= SORT_KEY_UNSHADED_FLAG;
- }
+ if (p_material->shader->spatial.unshaded) {
+ e->light_mode = LIGHTMODE_UNSHADED;
+ } else {
- if (!p_depth_pass) {
- e->sort_key |= uint64_t(e->material->index) << RenderList::SORT_KEY_MATERIAL_INDEX_SHIFT;
+ bool copy = false;
- e->sort_key |= uint64_t(p_material->render_priority + 128) << RenderList::SORT_KEY_PRIORITY_SHIFT;
- } else {
- // TODO
+ for (int i = 0; i < render_directional_lights; i++) {
+
+ if (copy) {
+ RenderList::Element *e2 = has_alpha ? render_list.add_alpha_element() : render_list.add_element();
+ if (!e2) {
+ break;
+ }
+ *e2 = *e; //this includes accum ptr :)
+ e = e2;
+ }
+
+ //directional sort key
+ e->light_type1 = 0;
+ e->light_type2 = 1;
+ e->light_index = i;
+
+ copy = true;
+ }
+
+ //add omni / spots
+
+ for (int i = 0; i < e->instance->light_instances.size(); i++) {
+
+ LightInstance *li = light_instance_owner.getornull(e->instance->light_instances[i]);
+
+ if (li->light_index >= render_light_instance_count) {
+ continue; // too many
+ }
+
+ if (copy) {
+ RenderList::Element *e2 = has_alpha ? render_list.add_alpha_element() : render_list.add_element();
+ if (!e2) {
+ break;
+ }
+ *e2 = *e; //this includes accum ptr :)
+ e = e2;
+ }
+
+ //directional sort key
+ e->light_type1 = 1;
+ e->light_type2 = li->light_ptr->type == VisualServer::LIGHT_OMNI ? 0 : 1;
+ e->light_index = li->light_index;
+
+ copy = true;
+ }
+
+ if (e->instance->lightmap.is_valid()) {
+ e->light_mode = LIGHTMODE_LIGHTMAP;
+ } else if (!e->instance->lightmap_capture_data.empty()) {
+ e->light_mode = LIGHTMODE_LIGHTMAP_CAPTURE;
+ } else {
+ e->light_mode = LIGHTMODE_NORMAL;
+ }
+ }
}
+ // do not add anything here, as lights are duplicated elements..
+
if (p_material->shader->spatial.uses_time) {
VisualServerRaster::redraw_request();
}
@@ -771,6 +867,13 @@ void RasterizerSceneGLES2::_add_geometry_with_material(RasterizerStorageGLES2::G
void RasterizerSceneGLES2::_fill_render_list(InstanceBase **p_cull_result, int p_cull_count, bool p_depth_pass, bool p_shadow_pass) {
+ render_pass++;
+ current_material_index = 0;
+ current_geometry_index = 0;
+ current_light_index = 0;
+ current_refprobe_index = 0;
+ current_shader_index = 0;
+
for (int i = 0; i < p_cull_count; i++) {
InstanceBase *instance = p_cull_result[i];
@@ -838,13 +941,13 @@ static const GLenum gl_primitive[] = {
GL_TRIANGLE_FAN
};
-void RasterizerSceneGLES2::_setup_material(RasterizerStorageGLES2::Material *p_material, bool p_reverse_cull, bool p_alpha_pass, Size2i p_skeleton_tex_size) {
+bool RasterizerSceneGLES2::_setup_material(RasterizerStorageGLES2::Material *p_material, bool p_reverse_cull, bool p_alpha_pass, Size2i p_skeleton_tex_size) {
// material parameters
state.scene_shader.set_custom_shader(p_material->shader->custom_code_id);
- state.scene_shader.bind();
+ bool shader_rebind = state.scene_shader.bind();
if (p_material->shader->spatial.no_depth_test) {
glDisable(GL_DEPTH_TEST);
@@ -923,193 +1026,169 @@ void RasterizerSceneGLES2::_setup_material(RasterizerStorageGLES2::Material *p_m
glBindTexture(t->target, t->tex_id);
}
state.scene_shader.use_material((void *)p_material);
+
+ return shader_rebind;
}
void RasterizerSceneGLES2::_setup_geometry(RenderList::Element *p_element, RasterizerStorageGLES2::Skeleton *p_skeleton) {
- state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON, p_skeleton != NULL);
- state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON_SOFTWARE, !storage->config.float_texture_supported);
- // state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON_SOFTWARE, true);
-
switch (p_element->instance->base_type) {
case VS::INSTANCE_MESH: {
RasterizerStorageGLES2::Surface *s = static_cast<RasterizerStorageGLES2::Surface *>(p_element->geometry);
- state.scene_shader.set_conditional(SceneShaderGLES2::USE_INSTANCING, false);
- state.scene_shader.set_conditional(SceneShaderGLES2::ENABLE_COLOR_INTERP, s->attribs[VS::ARRAY_COLOR].enabled);
- state.scene_shader.set_conditional(SceneShaderGLES2::ENABLE_UV_INTERP, s->attribs[VS::ARRAY_TEX_UV].enabled);
- state.scene_shader.set_conditional(SceneShaderGLES2::ENABLE_UV2_INTERP, s->attribs[VS::ARRAY_TEX_UV2].enabled);
-
- } break;
-
- case VS::INSTANCE_MULTIMESH: {
- RasterizerStorageGLES2::MultiMesh *multi_mesh = static_cast<RasterizerStorageGLES2::MultiMesh *>(p_element->owner);
- RasterizerStorageGLES2::Surface *s = static_cast<RasterizerStorageGLES2::Surface *>(p_element->geometry);
-
- state.scene_shader.set_conditional(SceneShaderGLES2::ENABLE_COLOR_INTERP, true);
- state.scene_shader.set_conditional(SceneShaderGLES2::USE_INSTANCING, true);
-
- state.scene_shader.set_conditional(SceneShaderGLES2::ENABLE_UV_INTERP, s->attribs[VS::ARRAY_TEX_UV].enabled);
- state.scene_shader.set_conditional(SceneShaderGLES2::ENABLE_UV2_INTERP, s->attribs[VS::ARRAY_TEX_UV2].enabled);
- } break;
-
- case VS::INSTANCE_IMMEDIATE: {
- state.scene_shader.set_conditional(SceneShaderGLES2::USE_INSTANCING, false);
- state.scene_shader.set_conditional(SceneShaderGLES2::ENABLE_COLOR_INTERP, true);
- state.scene_shader.set_conditional(SceneShaderGLES2::ENABLE_UV_INTERP, true);
- state.scene_shader.set_conditional(SceneShaderGLES2::ENABLE_UV2_INTERP, true);
- } break;
-
- default: {
-
- } break;
- }
-
- if (storage->config.float_texture_supported) {
- if (p_skeleton) {
- glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 1);
- glBindTexture(GL_TEXTURE_2D, p_skeleton->tex_id);
- }
-
- return;
- }
-
- if (p_skeleton) {
- ERR_FAIL_COND(p_skeleton->use_2d);
-
- PoolVector<float> &transform_buffer = storage->resources.skeleton_transform_cpu_buffer;
-
- switch (p_element->instance->base_type) {
- case VS::INSTANCE_MESH: {
- RasterizerStorageGLES2::Surface *s = static_cast<RasterizerStorageGLES2::Surface *>(p_element->geometry);
+ glBindBuffer(GL_ARRAY_BUFFER, s->vertex_id);
- if (!s->attribs[VS::ARRAY_BONES].enabled || !s->attribs[VS::ARRAY_WEIGHTS].enabled) {
- break; // the whole instance has a skeleton, but this surface is not affected by it.
- }
+ if (s->index_array_len > 0) {
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, s->index_id);
+ }
- // 3 * vec4 per vertex
- if (transform_buffer.size() < s->array_len * 12) {
- transform_buffer.resize(s->array_len * 12);
+ for (int i = 0; i < VS::ARRAY_MAX - 1; i++) {
+ if (s->attribs[i].enabled) {
+ glEnableVertexAttribArray(i);
+ glVertexAttribPointer(s->attribs[i].index, s->attribs[i].size, s->attribs[i].type, s->attribs[i].normalized, s->attribs[i].stride, (uint8_t *)0 + s->attribs[i].offset);
+ } else {
+ glDisableVertexAttribArray(i);
+ switch (i) {
+ case VS::ARRAY_NORMAL: {
+ glVertexAttrib4f(VS::ARRAY_COLOR, 0.0, 0.0, 1, 1);
+ } break;
+ case VS::ARRAY_COLOR: {
+ glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1);
+
+ } break;
+ default: {}
+ }
}
+ }
- const size_t bones_offset = s->attribs[VS::ARRAY_BONES].offset;
- const size_t bones_stride = s->attribs[VS::ARRAY_BONES].stride;
- const size_t bone_weight_offset = s->attribs[VS::ARRAY_WEIGHTS].offset;
- const size_t bone_weight_stride = s->attribs[VS::ARRAY_WEIGHTS].stride;
+ bool clear_skeleton_buffer = !storage->config.float_texture_supported;
- {
- PoolVector<float>::Write write = transform_buffer.write();
- float *buffer = write.ptr();
+ if (p_skeleton) {
- PoolVector<uint8_t>::Read vertex_array_read = s->data.read();
- const uint8_t *vertex_data = vertex_array_read.ptr();
+ if (storage->config.float_texture_supported) {
+ //use float texture workflow
+ glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 1);
+ glBindTexture(GL_TEXTURE_2D, p_skeleton->tex_id);
+ } else {
+ //use transform buffer workflow
+ ERR_FAIL_COND(p_skeleton->use_2d);
- for (int i = 0; i < s->array_len; i++) {
+ PoolVector<float> &transform_buffer = storage->resources.skeleton_transform_cpu_buffer;
- // do magic
+ if (!s->attribs[VS::ARRAY_BONES].enabled || !s->attribs[VS::ARRAY_WEIGHTS].enabled) {
+ break; // the whole instance has a skeleton, but this surface is not affected by it.
+ }
- size_t bones[4];
- float bone_weight[4];
+ // 3 * vec4 per vertex
+ if (transform_buffer.size() < s->array_len * 12) {
+ transform_buffer.resize(s->array_len * 12);
+ }
- if (s->attribs[VS::ARRAY_BONES].type == GL_UNSIGNED_BYTE) {
- // read as byte
- const uint8_t *bones_ptr = vertex_data + bones_offset + (i * bones_stride);
- bones[0] = bones_ptr[0];
- bones[1] = bones_ptr[1];
- bones[2] = bones_ptr[2];
- bones[3] = bones_ptr[3];
- } else {
- // read as short
- const uint16_t *bones_ptr = (const uint16_t *)(vertex_data + bones_offset + (i * bones_stride));
- bones[0] = bones_ptr[0];
- bones[1] = bones_ptr[1];
- bones[2] = bones_ptr[2];
- bones[3] = bones_ptr[3];
+ const size_t bones_offset = s->attribs[VS::ARRAY_BONES].offset;
+ const size_t bones_stride = s->attribs[VS::ARRAY_BONES].stride;
+ const size_t bone_weight_offset = s->attribs[VS::ARRAY_WEIGHTS].offset;
+ const size_t bone_weight_stride = s->attribs[VS::ARRAY_WEIGHTS].stride;
+
+ {
+ PoolVector<float>::Write write = transform_buffer.write();
+ float *buffer = write.ptr();
+
+ PoolVector<uint8_t>::Read vertex_array_read = s->data.read();
+ const uint8_t *vertex_data = vertex_array_read.ptr();
+
+ for (int i = 0; i < s->array_len; i++) {
+
+ // do magic
+
+ size_t bones[4];
+ float bone_weight[4];
+
+ if (s->attribs[VS::ARRAY_BONES].type == GL_UNSIGNED_BYTE) {
+ // read as byte
+ const uint8_t *bones_ptr = vertex_data + bones_offset + (i * bones_stride);
+ bones[0] = bones_ptr[0];
+ bones[1] = bones_ptr[1];
+ bones[2] = bones_ptr[2];
+ bones[3] = bones_ptr[3];
+ } else {
+ // read as short
+ const uint16_t *bones_ptr = (const uint16_t *)(vertex_data + bones_offset + (i * bones_stride));
+ bones[0] = bones_ptr[0];
+ bones[1] = bones_ptr[1];
+ bones[2] = bones_ptr[2];
+ bones[3] = bones_ptr[3];
+ }
+
+ if (s->attribs[VS::ARRAY_WEIGHTS].type == GL_FLOAT) {
+ // read as float
+ const float *weight_ptr = (const float *)(vertex_data + bone_weight_offset + (i * bone_weight_stride));
+ bone_weight[0] = weight_ptr[0];
+ bone_weight[1] = weight_ptr[1];
+ bone_weight[2] = weight_ptr[2];
+ bone_weight[3] = weight_ptr[3];
+ } else {
+ // read as half
+ const uint16_t *weight_ptr = (const uint16_t *)(vertex_data + bone_weight_offset + (i * bone_weight_stride));
+ bone_weight[0] = (weight_ptr[0] / (float)0xFFFF);
+ bone_weight[1] = (weight_ptr[1] / (float)0xFFFF);
+ bone_weight[2] = (weight_ptr[2] / (float)0xFFFF);
+ bone_weight[3] = (weight_ptr[3] / (float)0xFFFF);
+ }
+
+ size_t offset = i * 12;
+
+ Transform transform;
+
+ Transform bone_transforms[4] = {
+ storage->skeleton_bone_get_transform(p_element->instance->skeleton, bones[0]),
+ storage->skeleton_bone_get_transform(p_element->instance->skeleton, bones[1]),
+ storage->skeleton_bone_get_transform(p_element->instance->skeleton, bones[2]),
+ storage->skeleton_bone_get_transform(p_element->instance->skeleton, bones[3]),
+ };
+
+ transform.origin =
+ bone_weight[0] * bone_transforms[0].origin +
+ bone_weight[1] * bone_transforms[1].origin +
+ bone_weight[2] * bone_transforms[2].origin +
+ bone_weight[3] * bone_transforms[3].origin;
+
+ transform.basis =
+ bone_transforms[0].basis * bone_weight[0] +
+ bone_transforms[1].basis * bone_weight[1] +
+ bone_transforms[2].basis * bone_weight[2] +
+ bone_transforms[3].basis * bone_weight[3];
+
+ float row[3][4] = {
+ { transform.basis[0][0], transform.basis[0][1], transform.basis[0][2], transform.origin[0] },
+ { transform.basis[1][0], transform.basis[1][1], transform.basis[1][2], transform.origin[1] },
+ { transform.basis[2][0], transform.basis[2][1], transform.basis[2][2], transform.origin[2] },
+ };
+
+ size_t transform_buffer_offset = i * 12;
+
+ copymem(&buffer[transform_buffer_offset], row, sizeof(row));
}
-
- if (s->attribs[VS::ARRAY_WEIGHTS].type == GL_FLOAT) {
- // read as float
- const float *weight_ptr = (const float *)(vertex_data + bone_weight_offset + (i * bone_weight_stride));
- bone_weight[0] = weight_ptr[0];
- bone_weight[1] = weight_ptr[1];
- bone_weight[2] = weight_ptr[2];
- bone_weight[3] = weight_ptr[3];
- } else {
- // read as half
- const uint16_t *weight_ptr = (const uint16_t *)(vertex_data + bone_weight_offset + (i * bone_weight_stride));
- bone_weight[0] = (weight_ptr[0] / (float)0xFFFF);
- bone_weight[1] = (weight_ptr[1] / (float)0xFFFF);
- bone_weight[2] = (weight_ptr[2] / (float)0xFFFF);
- bone_weight[3] = (weight_ptr[3] / (float)0xFFFF);
- }
-
- size_t offset = i * 12;
-
- Transform transform;
-
- Transform bone_transforms[4] = {
- storage->skeleton_bone_get_transform(p_element->instance->skeleton, bones[0]),
- storage->skeleton_bone_get_transform(p_element->instance->skeleton, bones[1]),
- storage->skeleton_bone_get_transform(p_element->instance->skeleton, bones[2]),
- storage->skeleton_bone_get_transform(p_element->instance->skeleton, bones[3]),
- };
-
- transform.origin =
- bone_weight[0] * bone_transforms[0].origin +
- bone_weight[1] * bone_transforms[1].origin +
- bone_weight[2] * bone_transforms[2].origin +
- bone_weight[3] * bone_transforms[3].origin;
-
- transform.basis =
- bone_transforms[0].basis * bone_weight[0] +
- bone_transforms[1].basis * bone_weight[1] +
- bone_transforms[2].basis * bone_weight[2] +
- bone_transforms[3].basis * bone_weight[3];
-
- float row[3][4] = {
- { transform.basis[0][0], transform.basis[0][1], transform.basis[0][2], transform.origin[0] },
- { transform.basis[1][0], transform.basis[1][1], transform.basis[1][2], transform.origin[1] },
- { transform.basis[2][0], transform.basis[2][1], transform.basis[2][2], transform.origin[2] },
- };
-
- size_t transform_buffer_offset = i * 12;
-
- copymem(&buffer[transform_buffer_offset], row, sizeof(row));
}
- }
- storage->_update_skeleton_transform_buffer(transform_buffer, s->array_len * 12);
- } break;
+ storage->_update_skeleton_transform_buffer(transform_buffer, s->array_len * 12);
- default: {
+ //enable transform buffer and bind it
+ glBindBuffer(GL_ARRAY_BUFFER, storage->resources.skeleton_transform_buffer);
- } break;
- }
- }
-}
+ glEnableVertexAttribArray(VS::ARRAY_MAX + 0);
+ glEnableVertexAttribArray(VS::ARRAY_MAX + 1);
+ glEnableVertexAttribArray(VS::ARRAY_MAX + 2);
-void RasterizerSceneGLES2::_render_geometry(RenderList::Element *p_element) {
+ glVertexAttribPointer(VS::ARRAY_MAX + 0, 4, GL_FLOAT, GL_FALSE, sizeof(float) * 12, (const void *)(sizeof(float) * 4 * 0));
+ glVertexAttribPointer(VS::ARRAY_MAX + 1, 4, GL_FLOAT, GL_FALSE, sizeof(float) * 12, (const void *)(sizeof(float) * 4 * 1));
+ glVertexAttribPointer(VS::ARRAY_MAX + 2, 4, GL_FLOAT, GL_FALSE, sizeof(float) * 12, (const void *)(sizeof(float) * 4 * 2));
- switch (p_element->instance->base_type) {
-
- case VS::INSTANCE_MESH: {
-
- RasterizerStorageGLES2::Surface *s = static_cast<RasterizerStorageGLES2::Surface *>(p_element->geometry);
-
- // set up
-
- if (p_element->instance->skeleton.is_valid() && s->attribs[VS::ARRAY_BONES].enabled && s->attribs[VS::ARRAY_WEIGHTS].enabled) {
- glBindBuffer(GL_ARRAY_BUFFER, storage->resources.skeleton_transform_buffer);
-
- glEnableVertexAttribArray(VS::ARRAY_MAX + 0);
- glEnableVertexAttribArray(VS::ARRAY_MAX + 1);
- glEnableVertexAttribArray(VS::ARRAY_MAX + 2);
+ clear_skeleton_buffer = false;
+ }
+ }
- glVertexAttribPointer(VS::ARRAY_MAX + 0, 4, GL_FLOAT, GL_FALSE, sizeof(float) * 12, (const void *)(sizeof(float) * 4 * 0));
- glVertexAttribPointer(VS::ARRAY_MAX + 1, 4, GL_FLOAT, GL_FALSE, sizeof(float) * 12, (const void *)(sizeof(float) * 4 * 1));
- glVertexAttribPointer(VS::ARRAY_MAX + 2, 4, GL_FLOAT, GL_FALSE, sizeof(float) * 12, (const void *)(sizeof(float) * 4 * 2));
- } else {
+ if (clear_skeleton_buffer) {
// just to make sure
glDisableVertexAttribArray(VS::ARRAY_MAX + 0);
glDisableVertexAttribArray(VS::ARRAY_MAX + 1);
@@ -1120,6 +1199,12 @@ void RasterizerSceneGLES2::_render_geometry(RenderList::Element *p_element) {
glVertexAttrib4f(VS::ARRAY_MAX + 2, 0, 0, 1, 0);
}
+ } break;
+
+ case VS::INSTANCE_MULTIMESH: {
+ RasterizerStorageGLES2::MultiMesh *multi_mesh = static_cast<RasterizerStorageGLES2::MultiMesh *>(p_element->owner);
+ RasterizerStorageGLES2::Surface *s = static_cast<RasterizerStorageGLES2::Surface *>(p_element->geometry);
+
glBindBuffer(GL_ARRAY_BUFFER, s->vertex_id);
if (s->index_array_len > 0) {
@@ -1132,61 +1217,61 @@ void RasterizerSceneGLES2::_render_geometry(RenderList::Element *p_element) {
glVertexAttribPointer(s->attribs[i].index, s->attribs[i].size, s->attribs[i].type, s->attribs[i].normalized, s->attribs[i].stride, (uint8_t *)0 + s->attribs[i].offset);
} else {
glDisableVertexAttribArray(i);
+ switch (i) {
+ case VS::ARRAY_NORMAL: {
+ glVertexAttrib4f(VS::ARRAY_COLOR, 0.0, 0.0, 1, 1);
+ } break;
+ case VS::ARRAY_COLOR: {
+ glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1);
+
+ } break;
+ default: {}
+ }
}
}
- // drawing
+ if (!storage->config.float_texture_supported) {
+ // just to make sure, clear skeleton buffer too
+ glDisableVertexAttribArray(VS::ARRAY_MAX + 0);
+ glDisableVertexAttribArray(VS::ARRAY_MAX + 1);
+ glDisableVertexAttribArray(VS::ARRAY_MAX + 2);
- if (s->index_array_len > 0) {
- glDrawElements(gl_primitive[s->primitive], s->index_array_len, (s->array_len >= (1 << 16)) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0);
- } else {
- glDrawArrays(gl_primitive[s->primitive], 0, s->array_len);
+ glVertexAttrib4f(VS::ARRAY_MAX + 0, 1, 0, 0, 0);
+ glVertexAttrib4f(VS::ARRAY_MAX + 1, 0, 1, 0, 0);
+ glVertexAttrib4f(VS::ARRAY_MAX + 2, 0, 0, 1, 0);
}
- // tear down
-
- for (int i = 0; i < VS::ARRAY_MAX - 1; i++) {
- glDisableVertexAttribArray(i);
- }
+ } break;
- if (s->index_array_len > 0) {
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
- }
+ case VS::INSTANCE_IMMEDIATE: {
+ } break;
- if (p_element->instance->skeleton.is_valid() && s->attribs[VS::ARRAY_BONES].enabled && s->attribs[VS::ARRAY_WEIGHTS].enabled) {
- glBindBuffer(GL_ARRAY_BUFFER, storage->resources.skeleton_transform_buffer);
+ default: {
- glDisableVertexAttribArray(VS::ARRAY_MAX + 0);
- glDisableVertexAttribArray(VS::ARRAY_MAX + 1);
- glDisableVertexAttribArray(VS::ARRAY_MAX + 2);
- }
+ } break;
+ }
+}
- glBindBuffer(GL_ARRAY_BUFFER, 0);
+void RasterizerSceneGLES2::_render_geometry(RenderList::Element *p_element) {
- } break;
+ switch (p_element->instance->base_type) {
- case VS::INSTANCE_MULTIMESH: {
+ case VS::INSTANCE_MESH: {
- RasterizerStorageGLES2::MultiMesh *multi_mesh = static_cast<RasterizerStorageGLES2::MultiMesh *>(p_element->owner);
RasterizerStorageGLES2::Surface *s = static_cast<RasterizerStorageGLES2::Surface *>(p_element->geometry);
- int amount = MIN(multi_mesh->size, multi_mesh->visible_instances);
- if (amount == -1) {
- amount = multi_mesh->size;
+ // drawing
+
+ if (s->index_array_len > 0) {
+ glDrawElements(gl_primitive[s->primitive], s->index_array_len, (s->array_len >= (1 << 16)) ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0);
+ } else {
+ glDrawArrays(gl_primitive[s->primitive], 0, s->array_len);
}
if (p_element->instance->skeleton.is_valid() && s->attribs[VS::ARRAY_BONES].enabled && s->attribs[VS::ARRAY_WEIGHTS].enabled) {
+ //clean up after skeleton
glBindBuffer(GL_ARRAY_BUFFER, storage->resources.skeleton_transform_buffer);
- glEnableVertexAttribArray(VS::ARRAY_MAX + 0);
- glEnableVertexAttribArray(VS::ARRAY_MAX + 1);
- glEnableVertexAttribArray(VS::ARRAY_MAX + 2);
-
- glVertexAttribPointer(VS::ARRAY_MAX + 0, 4, GL_FLOAT, GL_FALSE, sizeof(float) * 12, (const void *)(sizeof(float) * 4 * 0));
- glVertexAttribPointer(VS::ARRAY_MAX + 1, 4, GL_FLOAT, GL_FALSE, sizeof(float) * 12, (const void *)(sizeof(float) * 4 * 1));
- glVertexAttribPointer(VS::ARRAY_MAX + 2, 4, GL_FLOAT, GL_FALSE, sizeof(float) * 12, (const void *)(sizeof(float) * 4 * 2));
- } else {
- // just to make sure
glDisableVertexAttribArray(VS::ARRAY_MAX + 0);
glDisableVertexAttribArray(VS::ARRAY_MAX + 1);
glDisableVertexAttribArray(VS::ARRAY_MAX + 2);
@@ -1196,36 +1281,19 @@ void RasterizerSceneGLES2::_render_geometry(RenderList::Element *p_element) {
glVertexAttrib4f(VS::ARRAY_MAX + 2, 0, 0, 1, 0);
}
- glBindBuffer(GL_ARRAY_BUFFER, s->vertex_id);
-
- if (s->index_array_len > 0) {
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, s->index_id);
- }
+ } break;
- for (int i = 0; i < VS::ARRAY_MAX - 1; i++) {
- if (s->attribs[i].enabled) {
- glEnableVertexAttribArray(i);
- glVertexAttribPointer(s->attribs[i].index, s->attribs[i].size, s->attribs[i].type, s->attribs[i].normalized, s->attribs[i].stride, (uint8_t *)0 + s->attribs[i].offset);
- } else {
- glDisableVertexAttribArray(i);
- }
- }
+ case VS::INSTANCE_MULTIMESH: {
- glDisableVertexAttribArray(12); // transform 0
- glDisableVertexAttribArray(13); // transform 1
- glDisableVertexAttribArray(14); // transform 2
- glDisableVertexAttribArray(15); // color
- glDisableVertexAttribArray(8); // custom data
+ RasterizerStorageGLES2::MultiMesh *multi_mesh = static_cast<RasterizerStorageGLES2::MultiMesh *>(p_element->owner);
+ RasterizerStorageGLES2::Surface *s = static_cast<RasterizerStorageGLES2::Surface *>(p_element->geometry);
- if (!s->attribs[VS::ARRAY_COLOR].enabled) {
- glDisableVertexAttribArray(VS::ARRAY_COLOR);
+ int amount = MIN(multi_mesh->size, multi_mesh->visible_instances);
- glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1);
+ if (amount == -1) {
+ amount = multi_mesh->size;
}
- glVertexAttrib4f(15, 1, 1, 1, 1);
- glVertexAttrib4f(8, 0, 0, 0, 0);
-
int stride = multi_mesh->color_floats + multi_mesh->custom_data_floats + multi_mesh->xform_floats;
int color_ofs = multi_mesh->xform_floats;
@@ -1260,22 +1328,27 @@ void RasterizerSceneGLES2::_render_geometry(RenderList::Element *p_element) {
{ transform.basis[2][0], transform.basis[2][1], transform.basis[2][2], transform.origin[2] },
};
- glVertexAttrib4fv(12, row[0]);
- glVertexAttrib4fv(13, row[1]);
- glVertexAttrib4fv(14, row[2]);
+ glVertexAttrib4fv(VS::ARRAY_MAX + 0, row[0]);
+ glVertexAttrib4fv(VS::ARRAY_MAX + 1, row[1]);
+ glVertexAttrib4fv(VS::ARRAY_MAX + 2, row[2]);
}
if (multi_mesh->color_floats) {
if (multi_mesh->color_format == VS::MULTIMESH_COLOR_8BIT) {
uint8_t *color_data = (uint8_t *)(buffer + color_ofs);
- glVertexAttrib4f(15, color_data[0] / 255.0, color_data[1] / 255.0, color_data[2] / 255.0, color_data[3] / 255.0);
+ glVertexAttrib4f(VS::ARRAY_MAX + 3, color_data[0] / 255.0, color_data[1] / 255.0, color_data[2] / 255.0, color_data[3] / 255.0);
} else {
- glVertexAttrib4fv(15, buffer + color_ofs);
+ glVertexAttrib4fv(VS::ARRAY_MAX + 3, buffer + color_ofs);
}
}
if (multi_mesh->custom_data_floats) {
- glVertexAttrib4fv(8, buffer + custom_data_ofs);
+ if (multi_mesh->custom_data_format == VS::MULTIMESH_CUSTOM_DATA_8BIT) {
+ uint8_t *custom_data = (uint8_t *)(buffer + custom_data_ofs);
+ glVertexAttrib4f(VS::ARRAY_MAX + 4, custom_data[0] / 255.0, custom_data[1] / 255.0, custom_data[2] / 255.0, custom_data[3] / 255.0);
+ } else {
+ glVertexAttrib4fv(VS::ARRAY_MAX + 4, buffer + custom_data_ofs);
+ }
}
if (s->index_array_len > 0) {
@@ -1285,25 +1358,6 @@ void RasterizerSceneGLES2::_render_geometry(RenderList::Element *p_element) {
}
}
- // tear down
-
- for (int i = 0; i < VS::ARRAY_MAX - 1; i++) {
- glDisableVertexAttribArray(i);
- }
-
- if (s->index_array_len > 0) {
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
- }
-
- if (p_element->instance->skeleton.is_valid() && s->attribs[VS::ARRAY_BONES].enabled && s->attribs[VS::ARRAY_WEIGHTS].enabled) {
- glBindBuffer(GL_ARRAY_BUFFER, storage->resources.skeleton_transform_buffer);
-
- glDisableVertexAttribArray(VS::ARRAY_MAX + 0);
- glDisableVertexAttribArray(VS::ARRAY_MAX + 1);
- glDisableVertexAttribArray(VS::ARRAY_MAX + 2);
- }
-
- glBindBuffer(GL_ARRAY_BUFFER, 0);
} break;
case VS::INSTANCE_IMMEDIATE: {
@@ -1420,505 +1474,549 @@ void RasterizerSceneGLES2::_render_geometry(RenderList::Element *p_element) {
}
}
-void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements, int p_element_count, const RID *p_directional_lights, int p_directional_light_count, const Transform &p_view_transform, const CameraMatrix &p_projection, RID p_shadow_atlas, Environment *p_env, GLuint p_base_env, float p_shadow_bias, float p_shadow_normal_bias, bool p_reverse_cull, bool p_alpha_pass, bool p_shadow, bool p_directional_add) {
-
- ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(p_shadow_atlas);
-
- Vector2 screen_pixel_size;
- screen_pixel_size.x = 1.0 / storage->frame.current_rt->width;
- screen_pixel_size.y = 1.0 / storage->frame.current_rt->height;
-
- bool use_radiance_map = false;
-
- VMap<RID, Vector<RenderList::Element *> > lit_objects;
-
- for (int i = 0; i < p_element_count; i++) {
- RenderList::Element *e = p_elements[i];
+void RasterizerSceneGLES2::_setup_light_type(LightInstance *p_light, ShadowAtlas *shadow_atlas) {
- RasterizerStorageGLES2::Material *material = e->material;
-
- RasterizerStorageGLES2::Skeleton *skeleton = storage->skeleton_owner.getornull(e->instance->skeleton);
-
- if (p_base_env) {
- glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 2);
- glBindTexture(GL_TEXTURE_CUBE_MAP, p_base_env);
- use_radiance_map = true;
- }
- state.scene_shader.set_conditional(SceneShaderGLES2::USE_RADIANCE_MAP, use_radiance_map);
-
- if (material->shader->spatial.unshaded) {
- state.scene_shader.set_conditional(SceneShaderGLES2::USE_RADIANCE_MAP, false);
- } else {
- state.scene_shader.set_conditional(SceneShaderGLES2::USE_RADIANCE_MAP, use_radiance_map);
- }
-
- // opaque pass
-
- state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_PASS, false);
-
- _setup_geometry(e, skeleton);
-
- _setup_material(material, p_reverse_cull, p_alpha_pass, Size2i(skeleton ? skeleton->size * 3 : 0, 0));
+ //turn off all by default
+ state.scene_shader.set_conditional(SceneShaderGLES2::USE_LIGHTING, false);
+ state.scene_shader.set_conditional(SceneShaderGLES2::USE_SHADOW, false);
+ state.scene_shader.set_conditional(SceneShaderGLES2::SHADOW_MODE_PCF_5, false);
+ state.scene_shader.set_conditional(SceneShaderGLES2::SHADOW_MODE_PCF_13, false);
+ state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_MODE_DIRECTIONAL, false);
+ state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_MODE_OMNI, false);
+ state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_MODE_SPOT, false);
+ state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_USE_PSSM2, false);
+ state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_USE_PSSM4, false);
+ state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_USE_PSSM_BLEND, false);
+ state.scene_shader.set_conditional(SceneShaderGLES2::USE_SHADOW, false);
- if (use_radiance_map) {
- state.scene_shader.set_uniform(SceneShaderGLES2::RADIANCE_INVERSE_XFORM, p_view_transform);
- }
+ if (!p_light) { //no light, return off
+ return;
+ }
- if (p_shadow) {
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_BIAS, p_shadow_bias);
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_NORMAL_BIAS, p_shadow_normal_bias);
- }
+ //turn on lighting
+ state.scene_shader.set_conditional(SceneShaderGLES2::USE_LIGHTING, true);
- if (p_env) {
- state.scene_shader.set_uniform(SceneShaderGLES2::BG_ENERGY, p_env->bg_energy);
- state.scene_shader.set_uniform(SceneShaderGLES2::AMBIENT_SKY_CONTRIBUTION, p_env->ambient_sky_contribution);
- state.scene_shader.set_uniform(SceneShaderGLES2::AMBIENT_COLOR, p_env->ambient_color);
- state.scene_shader.set_uniform(SceneShaderGLES2::AMBIENT_ENERGY, p_env->ambient_energy);
+ switch (p_light->light_ptr->type) {
+ case VS::LIGHT_DIRECTIONAL: {
- } else {
- state.scene_shader.set_uniform(SceneShaderGLES2::BG_ENERGY, 1.0);
- state.scene_shader.set_uniform(SceneShaderGLES2::AMBIENT_SKY_CONTRIBUTION, 1.0);
- state.scene_shader.set_uniform(SceneShaderGLES2::AMBIENT_COLOR, Color(1.0, 1.0, 1.0, 1.0));
- state.scene_shader.set_uniform(SceneShaderGLES2::AMBIENT_ENERGY, 1.0);
- }
+ state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_MODE_DIRECTIONAL, true);
+ switch (p_light->light_ptr->directional_shadow_mode) {
+ case VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL: {
+ //no need
+ } break;
+ case VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS: {
+ state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_USE_PSSM2, true);
- glEnable(GL_BLEND);
+ } break;
+ case VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS: {
+ state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_USE_PSSM4, true);
+ } break;
+ }
- if (p_alpha_pass || p_directional_add) {
- int desired_blend_mode;
- if (p_directional_add) {
- desired_blend_mode = RasterizerStorageGLES2::Shader::Spatial::BLEND_MODE_ADD;
- } else {
- desired_blend_mode = material->shader->spatial.blend_mode;
+ state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_USE_PSSM_BLEND, p_light->light_ptr->directional_blend_splits);
+ if (p_light->light_ptr->shadow) {
+ state.scene_shader.set_conditional(SceneShaderGLES2::USE_SHADOW, true);
+ glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 3);
+ glBindTexture(GL_TEXTURE_2D, directional_shadow.depth);
+ state.scene_shader.set_conditional(SceneShaderGLES2::SHADOW_MODE_PCF_5, shadow_filter_mode == SHADOW_FILTER_PCF5);
+ state.scene_shader.set_conditional(SceneShaderGLES2::SHADOW_MODE_PCF_13, shadow_filter_mode == SHADOW_FILTER_PCF13);
}
- switch (desired_blend_mode) {
+ } break;
+ case VS::LIGHT_OMNI: {
+
+ state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_MODE_OMNI, true);
+ if (shadow_atlas && p_light->light_ptr->shadow) {
+ state.scene_shader.set_conditional(SceneShaderGLES2::USE_SHADOW, true);
+ glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 3);
+ glBindTexture(GL_TEXTURE_2D, shadow_atlas->depth);
+ state.scene_shader.set_conditional(SceneShaderGLES2::SHADOW_MODE_PCF_5, shadow_filter_mode == SHADOW_FILTER_PCF5);
+ state.scene_shader.set_conditional(SceneShaderGLES2::SHADOW_MODE_PCF_13, shadow_filter_mode == SHADOW_FILTER_PCF13);
+ }
+ } break;
+ case VS::LIGHT_SPOT: {
+
+ state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_MODE_SPOT, true);
+ if (shadow_atlas && p_light->light_ptr->shadow) {
+ state.scene_shader.set_conditional(SceneShaderGLES2::USE_SHADOW, true);
+ glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 3);
+ glBindTexture(GL_TEXTURE_2D, shadow_atlas->depth);
+ state.scene_shader.set_conditional(SceneShaderGLES2::SHADOW_MODE_PCF_5, shadow_filter_mode == SHADOW_FILTER_PCF5);
+ state.scene_shader.set_conditional(SceneShaderGLES2::SHADOW_MODE_PCF_13, shadow_filter_mode == SHADOW_FILTER_PCF13);
+ }
+ } break;
+ }
+}
- case RasterizerStorageGLES2::Shader::Spatial::BLEND_MODE_MIX: {
- glBlendEquation(GL_FUNC_ADD);
- if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
- glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- } else {
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- }
+void RasterizerSceneGLES2::_setup_light(LightInstance *light, ShadowAtlas *shadow_atlas, const Transform &p_view_transform) {
- } break;
- case RasterizerStorageGLES2::Shader::Spatial::BLEND_MODE_ADD: {
+ RasterizerStorageGLES2::Light *light_ptr = light->light_ptr;
- glBlendEquation(GL_FUNC_ADD);
- glBlendFunc(p_alpha_pass ? GL_SRC_ALPHA : GL_ONE, GL_ONE);
+ //common parameters
+ float energy = light_ptr->param[VS::LIGHT_PARAM_ENERGY];
+ float specular = light_ptr->param[VS::LIGHT_PARAM_SPECULAR];
+ float sign = light_ptr->negative ? -1 : 1;
- } break;
- case RasterizerStorageGLES2::Shader::Spatial::BLEND_MODE_SUB: {
+ state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SPECULAR, specular);
+ Color color = light_ptr->color * sign * energy * Math_PI;
+ state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_COLOR, color);
- glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE);
- } break;
- case RasterizerStorageGLES2::Shader::Spatial::BLEND_MODE_MUL: {
- glBlendEquation(GL_FUNC_ADD);
- if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
- glBlendFuncSeparate(GL_DST_COLOR, GL_ZERO, GL_DST_ALPHA, GL_ZERO);
- } else {
- glBlendFuncSeparate(GL_DST_COLOR, GL_ZERO, GL_ZERO, GL_ONE);
- }
+ //specific parameters
- } break;
- }
- } else {
- // no blend mode given - assume mix
- glBlendEquation(GL_FUNC_ADD);
- if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
- glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- } else {
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- }
- }
+ switch (light_ptr->type) {
+ case VS::LIGHT_DIRECTIONAL: {
+ //not using inverse for performance, view should be normalized anyway
+ Vector3 direction = p_view_transform.basis.xform_inv(light->transform.basis.xform(Vector3(0, 0, -1))).normalized();
+ state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_DIRECTION, direction);
- state.scene_shader.set_uniform(SceneShaderGLES2::CAMERA_MATRIX, p_view_transform.inverse());
- state.scene_shader.set_uniform(SceneShaderGLES2::CAMERA_INVERSE_MATRIX, p_view_transform);
- state.scene_shader.set_uniform(SceneShaderGLES2::PROJECTION_MATRIX, p_projection);
- state.scene_shader.set_uniform(SceneShaderGLES2::PROJECTION_INVERSE_MATRIX, p_projection.inverse());
+ CameraMatrix matrices[4];
- state.scene_shader.set_uniform(SceneShaderGLES2::TIME, storage->frame.time[0]);
+ if (light_ptr->shadow && directional_shadow.depth) {
- state.scene_shader.set_uniform(SceneShaderGLES2::SCREEN_PIXEL_SIZE, screen_pixel_size);
- state.scene_shader.set_uniform(SceneShaderGLES2::NORMAL_MULT, 1.0); // TODO mirror?
- state.scene_shader.set_uniform(SceneShaderGLES2::WORLD_TRANSFORM, e->instance->transform);
+ int shadow_count = 0;
+ Color split_offsets;
- _render_geometry(e);
+ switch (light_ptr->directional_shadow_mode) {
+ case VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL: {
+ shadow_count = 1;
+ } break;
- if (material->shader->spatial.unshaded)
- continue;
+ case VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS: {
+ shadow_count = 2;
+ } break;
- if (p_shadow)
- continue;
+ case VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS: {
+ shadow_count = 4;
+ } break;
+ }
- for (int light = 0; light < e->instance->light_instances.size(); light++) {
+ for (int k = 0; k < shadow_count; k++) {
- RID light_instance = e->instance->light_instances[light];
+ uint32_t x = light->directional_rect.position.x;
+ uint32_t y = light->directional_rect.position.y;
+ uint32_t width = light->directional_rect.size.x;
+ uint32_t height = light->directional_rect.size.y;
- lit_objects[light_instance].push_back(e);
- }
- }
+ if (light_ptr->directional_shadow_mode == VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS) {
- if (p_shadow) {
- state.scene_shader.set_conditional(SceneShaderGLES2::USE_RADIANCE_MAP, false);
- state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_USE_PSSM4, false);
- state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_USE_PSSM2, false);
- state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_USE_PSSM_BLEND, false);
- return;
- }
+ width /= 2;
+ height /= 2;
- state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_PASS, true);
+ if (k == 0) {
- glEnable(GL_BLEND);
- glBlendEquation(GL_FUNC_ADD);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE);
+ } else if (k == 1) {
+ x += width;
+ } else if (k == 2) {
+ y += height;
+ } else if (k == 3) {
+ x += width;
+ y += height;
+ }
- for (int lo = 0; lo < lit_objects.size(); lo++) {
+ } else if (light_ptr->directional_shadow_mode == VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS) {
- RID key = lit_objects.getk(lo);
+ height /= 2;
- LightInstance *light = light_instance_owner.getornull(key);
- RasterizerStorageGLES2::Light *light_ptr = light->light_ptr;
+ if (k == 0) {
- const Vector<RenderList::Element *> &list = lit_objects.getv(lo);
+ } else {
+ y += height;
+ }
+ }
- for (int i = 0; i < list.size(); i++) {
+ split_offsets[k] = light->shadow_transform[k].split;
- RenderList::Element *e = list[i];
- RasterizerStorageGLES2::Material *material = e->material;
+ Transform modelview = (p_view_transform.inverse() * light->shadow_transform[k].transform).affine_inverse();
- RasterizerStorageGLES2::Skeleton *skeleton = storage->skeleton_owner.getornull(e->instance->skeleton);
+ CameraMatrix bias;
+ bias.set_light_bias();
+ CameraMatrix rectm;
+ Rect2 atlas_rect = Rect2(float(x) / directional_shadow.size, float(y) / directional_shadow.size, float(width) / directional_shadow.size, float(height) / directional_shadow.size);
+ rectm.set_light_atlas_rect(atlas_rect);
- {
- _setup_geometry(e, skeleton);
+ CameraMatrix shadow_mtx = rectm * bias * light->shadow_transform[k].camera * modelview;
+ matrices[k] = shadow_mtx;
- _setup_material(material, p_reverse_cull, p_alpha_pass, Size2i(skeleton ? skeleton->size * 3 : 0, 0));
- if (shadow_atlas != NULL) {
- glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 4);
- glBindTexture(GL_TEXTURE_2D, shadow_atlas->depth);
+ /*Color light_clamp;
+ light_clamp[0] = atlas_rect.position.x;
+ light_clamp[1] = atlas_rect.position.y;
+ light_clamp[2] = atlas_rect.size.x;
+ light_clamp[3] = atlas_rect.size.y;*/
}
- state.scene_shader.set_uniform(SceneShaderGLES2::CAMERA_MATRIX, p_view_transform.inverse());
- state.scene_shader.set_uniform(SceneShaderGLES2::CAMERA_INVERSE_MATRIX, p_view_transform);
- state.scene_shader.set_uniform(SceneShaderGLES2::PROJECTION_MATRIX, p_projection);
- state.scene_shader.set_uniform(SceneShaderGLES2::PROJECTION_INVERSE_MATRIX, p_projection.inverse());
+ // state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_CLAMP, light_clamp);
+ state.scene_shader.set_uniform(SceneShaderGLES2::SHADOW_PIXEL_SIZE, Size2(1.0 / directional_shadow.size, 1.0 / directional_shadow.size));
+ state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SPLIT_OFFSETS, split_offsets);
+ state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SHADOW_MATRIX, matrices[0]);
+ state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SHADOW_MATRIX2, matrices[1]);
+ state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SHADOW_MATRIX3, matrices[2]);
+ state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SHADOW_MATRIX4, matrices[3]);
+ }
+ } break;
+ case VS::LIGHT_OMNI: {
- state.scene_shader.set_uniform(SceneShaderGLES2::TIME, storage->frame.time[0]);
+ Vector3 position = p_view_transform.xform_inv(light->transform.origin);
- state.scene_shader.set_uniform(SceneShaderGLES2::SCREEN_PIXEL_SIZE, screen_pixel_size);
- state.scene_shader.set_uniform(SceneShaderGLES2::NORMAL_MULT, 1.0); // TODO mirror?
- state.scene_shader.set_uniform(SceneShaderGLES2::WORLD_TRANSFORM, e->instance->transform);
- }
+ state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_POSITION, position);
- switch (light_ptr->type) {
- case VS::LIGHT_OMNI: {
+ float range = light_ptr->param[VS::LIGHT_PARAM_RANGE];
+ state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_RANGE, range);
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_TYPE, (int)1);
+ Color attenuation = Color(0.0, 0.0, 0.0, 0.0);
+ attenuation.a = light_ptr->param[VS::LIGHT_PARAM_ATTENUATION];
+ state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_ATTENUATION, attenuation);
- Vector3 position = p_view_transform.inverse().xform(light->transform.origin);
+ if (light_ptr->shadow && shadow_atlas->shadow_owners.has(light->self)) {
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_POSITION, position);
+ uint32_t key = shadow_atlas->shadow_owners[light->self];
- float range = light_ptr->param[VS::LIGHT_PARAM_RANGE];
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_RANGE, range);
+ uint32_t quadrant = (key >> ShadowAtlas::QUADRANT_SHIFT) & 0x03;
+ uint32_t shadow = key & ShadowAtlas::SHADOW_INDEX_MASK;
- Color attenuation = Color(0.0, 0.0, 0.0, 0.0);
- attenuation.a = light_ptr->param[VS::LIGHT_PARAM_ATTENUATION];
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_ATTENUATION, attenuation);
+ ERR_BREAK(shadow >= (uint32_t)shadow_atlas->quadrants[quadrant].shadows.size());
- if (light_ptr->shadow && shadow_atlas->shadow_owners.has(light->self)) {
+ uint32_t atlas_size = shadow_atlas->size;
+ uint32_t quadrant_size = atlas_size >> 1;
- uint32_t key = shadow_atlas->shadow_owners[light->self];
+ uint32_t x = (quadrant & 1) * quadrant_size;
+ uint32_t y = (quadrant >> 1) * quadrant_size;
- uint32_t quadrant = (key >> ShadowAtlas::QUADRANT_SHIFT) & 0x03;
- uint32_t shadow = key & ShadowAtlas::SHADOW_INDEX_MASK;
+ uint32_t shadow_size = (quadrant_size / shadow_atlas->quadrants[quadrant].subdivision);
+ x += (shadow % shadow_atlas->quadrants[quadrant].subdivision) * shadow_size;
+ y += (shadow / shadow_atlas->quadrants[quadrant].subdivision) * shadow_size;
- ERR_CONTINUE(shadow >= (uint32_t)shadow_atlas->quadrants[quadrant].shadows.size());
+ uint32_t width = shadow_size;
+ uint32_t height = shadow_size;
- uint32_t atlas_size = shadow_atlas->size;
- uint32_t quadrant_size = atlas_size >> 1;
+ if (light->light_ptr->omni_shadow_detail == VS::LIGHT_OMNI_SHADOW_DETAIL_HORIZONTAL) {
+ height /= 2;
+ } else {
+ width /= 2;
+ }
- uint32_t x = (quadrant & 1) * quadrant_size;
- uint32_t y = (quadrant >> 1) * quadrant_size;
+ Transform proj = (p_view_transform.inverse() * light->transform).inverse();
- uint32_t shadow_size = (quadrant_size / shadow_atlas->quadrants[quadrant].subdivision);
- x += (shadow % shadow_atlas->quadrants[quadrant].subdivision) * shadow_size;
- y += (shadow / shadow_atlas->quadrants[quadrant].subdivision) * shadow_size;
+ Color light_clamp;
+ light_clamp[0] = float(x) / atlas_size;
+ light_clamp[1] = float(y) / atlas_size;
+ light_clamp[2] = float(width) / atlas_size;
+ light_clamp[3] = float(height) / atlas_size;
- uint32_t width = shadow_size;
- uint32_t height = shadow_size;
+ state.scene_shader.set_uniform(SceneShaderGLES2::SHADOW_PIXEL_SIZE, Size2(1.0 / shadow_atlas->size, 1.0 / shadow_atlas->size));
+ state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SHADOW_MATRIX, proj);
+ state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_CLAMP, light_clamp);
+ }
+ } break;
- if (light->light_ptr->omni_shadow_detail == VS::LIGHT_OMNI_SHADOW_DETAIL_HORIZONTAL) {
- height /= 2;
- } else {
- width /= 2;
- }
+ case VS::LIGHT_SPOT: {
- Transform proj = (p_view_transform.inverse() * light->transform).inverse();
+ Vector3 position = p_view_transform.xform_inv(light->transform.origin);
- Color light_clamp;
- light_clamp[0] = float(x) / atlas_size;
- light_clamp[1] = float(y) / atlas_size;
- light_clamp[2] = float(width) / atlas_size;
- light_clamp[3] = float(height) / atlas_size;
+ state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_POSITION, position);
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SHADOW_MATRIX, proj);
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_CLAMP, light_clamp);
+ Vector3 direction = p_view_transform.inverse().basis.xform(light->transform.basis.xform(Vector3(0, 0, -1))).normalized();
+ state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_DIRECTION, direction);
+ Color attenuation = Color(0.0, 0.0, 0.0, 0.0);
+ attenuation.a = light_ptr->param[VS::LIGHT_PARAM_ATTENUATION];
+ float range = light_ptr->param[VS::LIGHT_PARAM_RANGE];
+ float spot_attenuation = light_ptr->param[VS::LIGHT_PARAM_SPOT_ATTENUATION];
+ float angle = light_ptr->param[VS::LIGHT_PARAM_SPOT_ANGLE];
+ angle = Math::cos(Math::deg2rad(angle));
+ state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_ATTENUATION, attenuation);
+ state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SPOT_ATTENUATION, spot_attenuation);
+ state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SPOT_RANGE, spot_attenuation);
+ state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SPOT_ANGLE, angle);
+ state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_RANGE, range);
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_HAS_SHADOW, 1.0);
- } else {
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_HAS_SHADOW, 0.0);
- }
- } break;
+ if (light->light_ptr->shadow && shadow_atlas && shadow_atlas->shadow_owners.has(light->self)) {
+ uint32_t key = shadow_atlas->shadow_owners[light->self];
- case VS::LIGHT_SPOT: {
- Vector3 position = p_view_transform.inverse().xform(light->transform.origin);
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_TYPE, (int)2);
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_POSITION, position);
+ uint32_t quadrant = (key >> ShadowAtlas::QUADRANT_SHIFT) & 0x03;
+ uint32_t shadow = key & ShadowAtlas::SHADOW_INDEX_MASK;
- Vector3 direction = p_view_transform.inverse().basis.xform(light->transform.basis.xform(Vector3(0, 0, -1))).normalized();
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_DIRECTION, direction);
- Color attenuation = Color(0.0, 0.0, 0.0, 0.0);
- attenuation.a = light_ptr->param[VS::LIGHT_PARAM_ATTENUATION];
- float range = light_ptr->param[VS::LIGHT_PARAM_RANGE];
- float spot_attenuation = light_ptr->param[VS::LIGHT_PARAM_SPOT_ATTENUATION];
- float angle = light_ptr->param[VS::LIGHT_PARAM_SPOT_ANGLE];
- angle = Math::cos(Math::deg2rad(angle));
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_ATTENUATION, attenuation);
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SPOT_ATTENUATION, spot_attenuation);
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SPOT_RANGE, spot_attenuation);
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SPOT_ANGLE, angle);
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_RANGE, range);
+ ERR_BREAK(shadow >= (uint32_t)shadow_atlas->quadrants[quadrant].shadows.size());
- if (light->light_ptr->shadow && shadow_atlas && shadow_atlas->shadow_owners.has(light->self)) {
- uint32_t key = shadow_atlas->shadow_owners[light->self];
+ uint32_t atlas_size = shadow_atlas->size;
+ uint32_t quadrant_size = atlas_size >> 1;
- uint32_t quadrant = (key >> ShadowAtlas::QUADRANT_SHIFT) & 0x03;
- uint32_t shadow = key & ShadowAtlas::SHADOW_INDEX_MASK;
+ uint32_t x = (quadrant & 1) * quadrant_size;
+ uint32_t y = (quadrant >> 1) * quadrant_size;
- ERR_CONTINUE(shadow >= (uint32_t)shadow_atlas->quadrants[quadrant].shadows.size());
+ uint32_t shadow_size = (quadrant_size / shadow_atlas->quadrants[quadrant].subdivision);
+ x += (shadow % shadow_atlas->quadrants[quadrant].subdivision) * shadow_size;
+ y += (shadow / shadow_atlas->quadrants[quadrant].subdivision) * shadow_size;
- uint32_t atlas_size = shadow_atlas->size;
- uint32_t quadrant_size = atlas_size >> 1;
+ uint32_t width = shadow_size;
+ uint32_t height = shadow_size;
- uint32_t x = (quadrant & 1) * quadrant_size;
- uint32_t y = (quadrant >> 1) * quadrant_size;
+ Rect2 rect(float(x) / atlas_size, float(y) / atlas_size, float(width) / atlas_size, float(height) / atlas_size);
- uint32_t shadow_size = (quadrant_size / shadow_atlas->quadrants[quadrant].subdivision);
- x += (shadow % shadow_atlas->quadrants[quadrant].subdivision) * shadow_size;
- y += (shadow / shadow_atlas->quadrants[quadrant].subdivision) * shadow_size;
+ Color light_clamp;
+ light_clamp[0] = rect.position.x;
+ light_clamp[1] = rect.position.y;
+ light_clamp[2] = rect.size.x;
+ light_clamp[3] = rect.size.y;
- uint32_t width = shadow_size;
- uint32_t height = shadow_size;
+ Transform modelview = (p_view_transform.inverse() * light->transform).inverse();
- Rect2 rect(float(x) / atlas_size, float(y) / atlas_size, float(width) / atlas_size, float(height) / atlas_size);
+ CameraMatrix bias;
+ bias.set_light_bias();
- Color light_clamp;
- light_clamp[0] = rect.position.x;
- light_clamp[1] = rect.position.y;
- light_clamp[2] = rect.size.x;
- light_clamp[3] = rect.size.y;
+ CameraMatrix rectm;
+ rectm.set_light_atlas_rect(rect);
- Transform modelview = (p_view_transform.inverse() * light->transform).inverse();
+ CameraMatrix shadow_matrix = rectm * bias * light->shadow_transform[0].camera * modelview;
- CameraMatrix bias;
- bias.set_light_bias();
+ state.scene_shader.set_uniform(SceneShaderGLES2::SHADOW_PIXEL_SIZE, Size2(1.0 / shadow_atlas->size, 1.0 / shadow_atlas->size));
+ state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SHADOW_MATRIX, shadow_matrix);
+ state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_CLAMP, light_clamp);
+ }
- CameraMatrix rectm;
- rectm.set_light_atlas_rect(rect);
+ } break;
- CameraMatrix shadow_matrix = rectm * bias * light->shadow_transform[0].camera * modelview;
+ default: break;
+ }
+}
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_HAS_SHADOW, 1.0);
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SHADOW_MATRIX, shadow_matrix);
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_CLAMP, light_clamp);
+void RasterizerSceneGLES2::_render_render_list(RenderList::Element **p_elements, int p_element_count, const Transform &p_view_transform, const CameraMatrix &p_projection, RID p_shadow_atlas, Environment *p_env, GLuint p_base_env, float p_shadow_bias, float p_shadow_normal_bias, bool p_reverse_cull, bool p_alpha_pass, bool p_shadow) {
- } else {
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_HAS_SHADOW, 0.0);
- }
+ ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(p_shadow_atlas);
- } break;
+ Vector2 screen_pixel_size;
+ screen_pixel_size.x = 1.0 / storage->frame.current_rt->width;
+ screen_pixel_size.y = 1.0 / storage->frame.current_rt->height;
- default: break;
- }
+ bool use_radiance_map = false;
+ if (!p_shadow && p_base_env) {
+ glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 2);
+ glBindTexture(GL_TEXTURE_CUBE_MAP, p_base_env);
+ use_radiance_map = true;
+ state.scene_shader.set_conditional(SceneShaderGLES2::USE_RADIANCE_MAP, true); //since prev unshaded is false, this needs to be true if exists
+ }
- float energy = light->light_ptr->param[VS::LIGHT_PARAM_ENERGY];
- float specular = light->light_ptr->param[VS::LIGHT_PARAM_SPECULAR];
+ bool prev_unshaded = false;
+ bool prev_instancing = false;
+ state.scene_shader.set_conditional(SceneShaderGLES2::SHADELESS, false);
+ RasterizerStorageGLES2::Material *prev_material = NULL;
+ RasterizerStorageGLES2::Geometry *prev_geometry = NULL;
+ RasterizerStorageGLES2::Skeleton *prev_skeleton = NULL;
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_ENERGY, energy);
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_COLOR, light->light_ptr->color.to_linear());
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SPECULAR, specular);
+ Transform view_transform_inverse = p_view_transform.inverse();
+ CameraMatrix projection_inverse = p_projection.inverse();
- _render_geometry(e);
- }
- }
+ bool prev_base_pass = false;
+ LightInstance *prev_light = NULL;
+ bool prev_vertex_lit = false;
- for (int dl = 0; dl < p_directional_light_count; dl++) {
- RID light_rid = p_directional_lights[dl];
- LightInstance *light = light_instance_owner.getornull(light_rid);
- RasterizerStorageGLES2::Light *light_ptr = light->light_ptr;
+ int prev_blend_mode = -2; //will always catch the first go
- switch (light_ptr->directional_shadow_mode) {
- case VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL: {
- } break;
- case VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS: {
- state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_USE_PSSM2, true);
- state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_USE_PSSM_BLEND, light_ptr->directional_blend_splits);
- } break;
+ if (p_alpha_pass) {
+ glEnable(GL_BLEND);
+ } else {
+ glDisable(GL_BLEND);
+ }
- case VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS: {
- state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_USE_PSSM4, true);
- state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_USE_PSSM_BLEND, light_ptr->directional_blend_splits);
- } break;
- default:
- break;
- }
+ for (int i = 0; i < p_element_count; i++) {
+ RenderList::Element *e = p_elements[i];
- for (int i = 0; i < p_element_count; i++) {
+ RasterizerStorageGLES2::Material *material = e->material;
- RenderList::Element *e = p_elements[i];
- RasterizerStorageGLES2::Material *material = e->material;
- RasterizerStorageGLES2::Skeleton *skeleton = storage->skeleton_owner.getornull(e->instance->skeleton);
+ bool rebind = false;
+ bool accum_pass = *e->use_accum_ptr;
+ *e->use_accum_ptr = true; //set to accum for next time this is found
+ LightInstance *light = NULL;
- {
- _setup_material(material, p_reverse_cull, false, Size2i(skeleton ? skeleton->size * 3 : 0, 0));
+ if (!p_shadow) {
- if (directional_shadow.depth) {
- glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 4); // TODO move into base pass
- glBindTexture(GL_TEXTURE_2D, directional_shadow.depth);
+ bool unshaded = material->shader->spatial.unshaded;
+
+ if (unshaded != prev_unshaded) {
+ rebind = true;
+ if (unshaded) {
+ state.scene_shader.set_conditional(SceneShaderGLES2::SHADELESS, true);
+ state.scene_shader.set_conditional(SceneShaderGLES2::USE_RADIANCE_MAP, false);
+ state.scene_shader.set_conditional(SceneShaderGLES2::USE_LIGHTING, false);
+ } else {
+ state.scene_shader.set_conditional(SceneShaderGLES2::SHADELESS, false);
+ state.scene_shader.set_conditional(SceneShaderGLES2::USE_RADIANCE_MAP, use_radiance_map);
}
- state.scene_shader.set_uniform(SceneShaderGLES2::CAMERA_MATRIX, p_view_transform.inverse());
- state.scene_shader.set_uniform(SceneShaderGLES2::CAMERA_INVERSE_MATRIX, p_view_transform);
- state.scene_shader.set_uniform(SceneShaderGLES2::PROJECTION_MATRIX, p_projection);
- state.scene_shader.set_uniform(SceneShaderGLES2::PROJECTION_INVERSE_MATRIX, p_projection.inverse());
+ prev_unshaded = unshaded;
+ }
- state.scene_shader.set_uniform(SceneShaderGLES2::TIME, storage->frame.time[0]);
+ bool base_pass = !accum_pass && !unshaded; //conditions for a base pass
- state.scene_shader.set_uniform(SceneShaderGLES2::SCREEN_PIXEL_SIZE, screen_pixel_size);
- state.scene_shader.set_uniform(SceneShaderGLES2::NORMAL_MULT, 1.0); // TODO mirror?
- state.scene_shader.set_uniform(SceneShaderGLES2::WORLD_TRANSFORM, e->instance->transform);
+ if (base_pass != prev_base_pass) {
+ state.scene_shader.set_conditional(SceneShaderGLES2::BASE_PASS, base_pass);
+ rebind = true;
+ prev_base_pass = base_pass;
}
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_TYPE, (int)0);
- Vector3 direction = p_view_transform.inverse().basis.xform(light->transform.basis.xform(Vector3(0, 0, -1))).normalized();
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_DIRECTION, direction);
- float energy = light_ptr->param[VS::LIGHT_PARAM_ENERGY];
- float specular = light_ptr->param[VS::LIGHT_PARAM_SPECULAR];
+ if (!unshaded && e->light_index < RenderList::MAX_LIGHTS) {
+ light = render_light_instances[e->light_index];
+ }
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_ENERGY, energy);
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SPECULAR, specular);
+ if (light != prev_light) {
- float sign = light_ptr->negative ? -1 : 1;
+ _setup_light_type(light, shadow_atlas);
+ rebind = true;
+ }
- Color linear_col = light_ptr->color.to_linear();
- Color color;
- for (int c = 0; c < 3; c++)
- color[c] = linear_col[c] * sign * energy * Math_PI;
+ int blend_mode = p_alpha_pass ? material->shader->spatial.blend_mode : -1; // -1 no blend, no mix
- color[3] = 0;
+ if (accum_pass) { //accum pass force pass
+ blend_mode = RasterizerStorageGLES2::Shader::Spatial::BLEND_MODE_ADD;
+ }
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_COLOR, color);
+ if (prev_blend_mode != blend_mode) {
- CameraMatrix matrices[4];
+ if (prev_blend_mode == -1 && blend_mode != -1) {
+ //does blend
+ glEnable(GL_BLEND);
+ } else if (blend_mode == -1 && prev_blend_mode != -1) {
+ //do not blend
+ glDisable(GL_BLEND);
+ }
- if (light_ptr->shadow && directional_shadow.depth) {
+ switch (blend_mode) {
+ //-1 not handled because not blend is enabled anyway
+ case RasterizerStorageGLES2::Shader::Spatial::BLEND_MODE_MIX: {
+ glBlendEquation(GL_FUNC_ADD);
+ if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ } else {
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ }
- int shadow_count = 0;
- Color split_offsets;
+ } break;
+ case RasterizerStorageGLES2::Shader::Spatial::BLEND_MODE_ADD: {
+
+ glBlendEquation(GL_FUNC_ADD);
+ glBlendFunc(p_alpha_pass ? GL_SRC_ALPHA : GL_ONE, GL_ONE);
- switch (light_ptr->directional_shadow_mode) {
- case VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL: {
- shadow_count = 1;
} break;
+ case RasterizerStorageGLES2::Shader::Spatial::BLEND_MODE_SUB: {
- case VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS: {
- shadow_count = 2;
+ glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE);
} break;
+ case RasterizerStorageGLES2::Shader::Spatial::BLEND_MODE_MUL: {
+ glBlendEquation(GL_FUNC_ADD);
+ if (storage->frame.current_rt && storage->frame.current_rt->flags[RasterizerStorage::RENDER_TARGET_TRANSPARENT]) {
+ glBlendFuncSeparate(GL_DST_COLOR, GL_ZERO, GL_DST_ALPHA, GL_ZERO);
+ } else {
+ glBlendFuncSeparate(GL_DST_COLOR, GL_ZERO, GL_ZERO, GL_ONE);
+ }
- case VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS: {
- shadow_count = 4;
} break;
}
- for (int k = 0; k < shadow_count; k++) {
+ prev_blend_mode = blend_mode;
+ }
- uint32_t x = light->directional_rect.position.x;
- uint32_t y = light->directional_rect.position.y;
- uint32_t width = light->directional_rect.size.x;
- uint32_t height = light->directional_rect.size.y;
+ //condition to enable vertex lighting on this object
+ bool vertex_lit = light && (material->shader->spatial.uses_vertex_lighting || storage->config.force_vertex_shading) && !unshaded;
- if (light_ptr->directional_shadow_mode == VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS) {
+ if (vertex_lit != prev_vertex_lit) {
+ state.scene_shader.set_conditional(SceneShaderGLES2::USE_VERTEX_LIGHTING, vertex_lit);
+ prev_vertex_lit = vertex_lit;
+ }
+ }
- width /= 2;
- height /= 2;
+ bool instancing = e->instancing;
- if (k == 0) {
+ if (instancing != prev_instancing) {
- } else if (k == 1) {
- x += width;
- } else if (k == 2) {
- y += height;
- } else if (k == 3) {
- x += width;
- y += height;
- }
+ state.scene_shader.set_conditional(SceneShaderGLES2::USE_INSTANCING, instancing);
+ rebind = true;
+ }
- } else if (light_ptr->directional_shadow_mode == VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS) {
+ RasterizerStorageGLES2::Skeleton *skeleton = storage->skeleton_owner.getornull(e->instance->skeleton);
- height /= 2;
+ if (skeleton != prev_skeleton) {
- if (k == 0) {
+ if (skeleton) {
+ state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON, skeleton != NULL);
+ state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON_SOFTWARE, !storage->config.float_texture_supported);
+ } else {
+ state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON, false);
+ state.scene_shader.set_conditional(SceneShaderGLES2::USE_SKELETON_SOFTWARE, false);
+ }
- } else {
- y += height;
- }
- }
+ rebind = true;
+ }
- split_offsets[k] = light->shadow_transform[k].split;
+ if (e->geometry != prev_geometry || skeleton != prev_skeleton) {
+ _setup_geometry(e, skeleton);
+ }
- Transform modelview = (p_view_transform * light->shadow_transform[k].transform).inverse();
+ bool shader_rebind = false;
+ if (rebind || material != prev_material) {
+ shader_rebind = _setup_material(material, p_reverse_cull, p_alpha_pass, Size2i(skeleton ? skeleton->size * 3 : 0, 0));
+ }
- CameraMatrix bias;
- bias.set_light_bias();
- CameraMatrix rectm;
- Rect2 atlas_rect = Rect2(float(x) / directional_shadow.size, float(y) / directional_shadow.size, float(width) / directional_shadow.size, float(height) / directional_shadow.size);
- rectm.set_light_atlas_rect(atlas_rect);
+ if (i == 0 || shader_rebind) { //first time must rebindmakin
- CameraMatrix shadow_mtx = rectm * bias * light->shadow_transform[k].camera * modelview;
- matrices[k] = shadow_mtx.inverse();
+ if (p_shadow) {
+ state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_BIAS, p_shadow_bias);
+ state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_NORMAL_BIAS, p_shadow_normal_bias);
+ if (state.shadow_is_dual_parabolloid) {
+ state.scene_shader.set_uniform(SceneShaderGLES2::SHADOW_DUAL_PARABOLOID_RENDER_SIDE, state.dual_parbolloid_direction);
+ state.scene_shader.set_uniform(SceneShaderGLES2::SHADOW_DUAL_PARABOLOID_RENDER_ZFAR, state.dual_parbolloid_zfar);
+ }
+ } else {
+ if (use_radiance_map) {
+ state.scene_shader.set_uniform(SceneShaderGLES2::RADIANCE_INVERSE_XFORM, p_view_transform);
+ }
- Color light_clamp;
- light_clamp[0] = atlas_rect.position.x;
- light_clamp[1] = atlas_rect.position.y;
- light_clamp[2] = atlas_rect.size.x;
- light_clamp[3] = atlas_rect.size.y;
+ if (p_env) {
+ state.scene_shader.set_uniform(SceneShaderGLES2::BG_ENERGY, p_env->bg_energy);
+ state.scene_shader.set_uniform(SceneShaderGLES2::AMBIENT_SKY_CONTRIBUTION, p_env->ambient_sky_contribution);
+ state.scene_shader.set_uniform(SceneShaderGLES2::AMBIENT_COLOR, p_env->ambient_color);
+ state.scene_shader.set_uniform(SceneShaderGLES2::AMBIENT_ENERGY, p_env->ambient_energy);
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_HAS_SHADOW, 1.0);
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_CLAMP, light_clamp);
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SPLIT_OFFSETS, split_offsets);
+ } else {
+ state.scene_shader.set_uniform(SceneShaderGLES2::BG_ENERGY, 1.0);
+ state.scene_shader.set_uniform(SceneShaderGLES2::AMBIENT_SKY_CONTRIBUTION, 1.0);
+ state.scene_shader.set_uniform(SceneShaderGLES2::AMBIENT_COLOR, Color(1.0, 1.0, 1.0, 1.0));
+ state.scene_shader.set_uniform(SceneShaderGLES2::AMBIENT_ENERGY, 1.0);
}
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SHADOW_MATRIX1, matrices[0]);
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SHADOW_MATRIX2, matrices[1]);
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SHADOW_MATRIX3, matrices[2]);
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_SHADOW_MATRIX4, matrices[3]);
- } else {
- state.scene_shader.set_uniform(SceneShaderGLES2::LIGHT_HAS_SHADOW, 0.0);
+ if (light) {
+ _setup_light(light, shadow_atlas, p_view_transform);
+ }
}
- _render_geometry(e);
+ state.scene_shader.set_uniform(SceneShaderGLES2::CAMERA_MATRIX, view_transform_inverse);
+ state.scene_shader.set_uniform(SceneShaderGLES2::CAMERA_INVERSE_MATRIX, p_view_transform);
+ state.scene_shader.set_uniform(SceneShaderGLES2::PROJECTION_MATRIX, p_projection);
+ state.scene_shader.set_uniform(SceneShaderGLES2::PROJECTION_INVERSE_MATRIX, projection_inverse);
+
+ state.scene_shader.set_uniform(SceneShaderGLES2::TIME, storage->frame.time[0]);
+
+ state.scene_shader.set_uniform(SceneShaderGLES2::SCREEN_PIXEL_SIZE, screen_pixel_size);
+ state.scene_shader.set_uniform(SceneShaderGLES2::NORMAL_MULT, 1.0); // TODO mirror?
}
- }
- state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_PASS, false);
+ state.scene_shader.set_uniform(SceneShaderGLES2::WORLD_TRANSFORM, e->instance->transform);
+
+ _render_geometry(e);
+ prev_geometry = e->geometry;
+ prev_material = material;
+ prev_skeleton = skeleton;
+ prev_instancing = instancing;
+ prev_light = light;
+ }
+
+ _setup_light_type(NULL, NULL); //clear light stuff
+ state.scene_shader.set_conditional(SceneShaderGLES2::SHADELESS, false);
+ state.scene_shader.set_conditional(SceneShaderGLES2::BASE_PASS, false);
state.scene_shader.set_conditional(SceneShaderGLES2::USE_RADIANCE_MAP, false);
state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_USE_PSSM4, false);
state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_USE_PSSM2, false);
state.scene_shader.set_conditional(SceneShaderGLES2::LIGHT_USE_PSSM_BLEND, false);
+ state.scene_shader.set_conditional(SceneShaderGLES2::USE_VERTEX_LIGHTING, false);
}
void RasterizerSceneGLES2::_draw_sky(RasterizerStorageGLES2::Sky *p_sky, const CameraMatrix &p_projection, const Transform &p_transform, bool p_vflip, float p_custom_fov, float p_energy) {
@@ -2013,6 +2111,38 @@ void RasterizerSceneGLES2::_draw_sky(RasterizerStorageGLES2::Sky *p_sky, const C
void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID *p_light_cull_result, int p_light_cull_count, RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, RID p_environment, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass) {
+ //push back the directional lights
+
+ if (p_light_cull_count) {
+ //harcoded limit of 256 lights
+ render_light_instance_count = MIN(RenderList::MAX_LIGHTS, p_light_cull_count);
+ render_light_instances = (LightInstance **)alloca(sizeof(LightInstance *) * render_light_instance_count);
+ render_directional_lights = 0;
+
+ //doing this because directional lights are at the end, put them at the beginning
+ int index = 0;
+ for (int i = render_light_instance_count - 1; i >= 0; i--) {
+ RID light_rid = p_light_cull_result[i];
+
+ LightInstance *light = light_instance_owner.getornull(light_rid);
+
+ if (light->light_ptr->type == VS::LIGHT_DIRECTIONAL) {
+ render_directional_lights++;
+ //as goin in reverse, directional lights are always first anyway
+ }
+
+ light->light_index = index;
+ render_light_instances[index] = light;
+
+ index++;
+ }
+
+ } else {
+ render_light_instances = NULL;
+ render_directional_lights = 0;
+ render_light_instance_count = 0;
+ }
+
glEnable(GL_BLEND);
GLuint current_fb = storage->frame.current_rt->fbo;
@@ -2069,34 +2199,23 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const
}
}
- Vector<RID> directional_lights;
-
- for (int i = 0; i < p_light_cull_count; i++) {
- RID light_rid = p_light_cull_result[i];
-
- LightInstance *light = light_instance_owner.getornull(light_rid);
-
- if (light->light_ptr->type == VS::LIGHT_DIRECTIONAL) {
- directional_lights.push_back(light_rid);
- }
- }
-
// render opaque things first
render_list.sort_by_key(false);
- _render_render_list(render_list.elements, render_list.element_count, directional_lights.ptr(), directional_lights.size(), p_cam_transform, p_cam_projection, p_shadow_atlas, env, env_radiance_tex, 0.0, 0.0, false, false, false, false);
+ _render_render_list(render_list.elements, render_list.element_count, p_cam_transform, p_cam_projection, p_shadow_atlas, env, env_radiance_tex, 0.0, 0.0, false, false, false);
// alpha pass
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- render_list.sort_by_key(true);
- _render_render_list(&render_list.elements[render_list.max_elements - render_list.alpha_element_count], render_list.alpha_element_count, directional_lights.ptr(), directional_lights.size(), p_cam_transform, p_cam_projection, p_shadow_atlas, env, env_radiance_tex, 0.0, 0.0, false, true, false, false);
+ render_list.sort_by_depth(true);
+
+ _render_render_list(&render_list.elements[render_list.max_elements - render_list.alpha_element_count], render_list.alpha_element_count, p_cam_transform, p_cam_projection, p_shadow_atlas, env, env_radiance_tex, 0.0, 0.0, false, true, false);
glDepthMask(GL_FALSE);
glDisable(GL_DEPTH_TEST);
- // #define GLES2_SHADOW_ATLAS_DEBUG_VIEW
+ //#define GLES2_SHADOW_ATLAS_DEBUG_VIEW
#ifdef GLES2_SHADOW_ATLAS_DEBUG_VIEW
ShadowAtlas *shadow_atlas = shadow_atlas_owner.getornull(p_shadow_atlas);
@@ -2115,6 +2234,25 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const
storage->_copy_screen();
}
#endif
+
+ //#define GLES2_SHADOW_DIRECTIONAL_DEBUG_VIEW
+
+#ifdef GLES2_SHADOW_DIRECTIONAL_DEBUG_VIEW
+ if (true) {
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, directional_shadow.depth);
+
+ glViewport(0, 0, storage->frame.current_rt->width / 4, storage->frame.current_rt->height / 4);
+ storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_CUBEMAP, false);
+ storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_COPY_SECTION, false);
+ storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_CUSTOM_ALPHA, false);
+ storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_MULTIPLIER, false);
+ storage->shaders.copy.set_conditional(CopyShaderGLES2::USE_PANORAMA, false);
+ storage->shaders.copy.bind();
+
+ storage->_copy_screen();
+ }
+#endif
}
void RasterizerSceneGLES2::render_shadow(RID p_light, RID p_shadow_atlas, int p_pass, InstanceBase **p_cull_result, int p_cull_count) {
@@ -2134,8 +2272,9 @@ void RasterizerSceneGLES2::render_shadow(RID p_light, RID p_shadow_atlas, int p_
float zfar = 0;
bool flip_facing = false;
int custom_vp_size = 0;
-
GLuint fbo = 0;
+ state.shadow_is_dual_parabolloid = false;
+ state.dual_parbolloid_direction = 0.0;
int current_cubemap = -1;
float bias = 0;
@@ -2264,8 +2403,32 @@ void RasterizerSceneGLES2::render_shadow(RID p_light, RID p_shadow_atlas, int p_
zfar = light->param[VS::LIGHT_PARAM_RANGE];
current_cubemap = cubemap_index;
+ } else {
+ //dual parabolloid
+ state.shadow_is_dual_parabolloid = true;
+ light_projection = light_instance->shadow_transform[0].camera;
+ light_transform = light_instance->shadow_transform[0].transform;
+
+ if (light->omni_shadow_detail == VS::LIGHT_OMNI_SHADOW_DETAIL_HORIZONTAL) {
+
+ height /= 2;
+ y += p_pass * height;
+ } else {
+ width /= 2;
+ x += p_pass * width;
+ }
+
+ state.dual_parbolloid_direction = p_pass == 0 ? 1.0 : -1.0;
+ flip_facing = (p_pass == 1);
+ zfar = light->param[VS::LIGHT_PARAM_RANGE];
+ bias = light->param[VS::LIGHT_PARAM_SHADOW_BIAS];
+
+ state.dual_parbolloid_zfar = zfar;
+
+ state.scene_shader.set_conditional(SceneShaderGLES2::RENDER_DEPTH_DUAL_PARABOLOID, true);
}
- } else {
+
+ } else if (light->type == VS::LIGHT_SPOT) {
light_projection = light_instance->shadow_transform[0].camera;
light_transform = light_instance->shadow_transform[0].transform;
@@ -2304,11 +2467,16 @@ void RasterizerSceneGLES2::render_shadow(RID p_light, RID p_shadow_atlas, int p_
glClear(GL_DEPTH_BUFFER_BIT);
glDisable(GL_SCISSOR_TEST);
+ if (light->reverse_cull) {
+ flip_facing = !flip_facing;
+ }
+
state.scene_shader.set_conditional(SceneShaderGLES2::RENDER_DEPTH, true);
- _render_render_list(render_list.elements, render_list.element_count, NULL, 0, light_transform, light_projection, RID(), NULL, 0, bias, normal_bias, false, false, true, false);
+ _render_render_list(render_list.elements, render_list.element_count, light_transform, light_projection, RID(), NULL, 0, bias, normal_bias, flip_facing, false, true);
state.scene_shader.set_conditional(SceneShaderGLES2::RENDER_DEPTH, false);
+ state.scene_shader.set_conditional(SceneShaderGLES2::RENDER_DEPTH_DUAL_PARABOLOID, false);
// convert cubemap to dual paraboloid if needed
if (light->type == VS::LIGHT_OMNI && light->omni_shadow_mode == VS::LIGHT_OMNI_SHADOW_CUBE && p_pass == 5) {
@@ -2358,6 +2526,7 @@ void RasterizerSceneGLES2::render_shadow(RID p_light, RID p_shadow_atlas, int p_
}
glViewport(0, 0, storage->frame.current_rt->width, storage->frame.current_rt->height);
+ glColorMask(1, 1, 1, 1);
}
void RasterizerSceneGLES2::set_scene_pass(uint64_t p_pass) {
@@ -2377,6 +2546,8 @@ void RasterizerSceneGLES2::initialize() {
render_list.init();
+ render_pass = 1;
+
shadow_atlas_realloc_tolerance_msec = 500;
{
@@ -2394,6 +2565,27 @@ void RasterizerSceneGLES2::initialize() {
}
{
+ default_worldcoord_shader = storage->shader_create();
+ storage->shader_set_code(default_worldcoord_shader, "shader_type spatial; render_mode world_vertex_coords;\n");
+ default_worldcoord_material = storage->material_create();
+ storage->material_set_shader(default_worldcoord_material, default_worldcoord_shader);
+
+ default_worldcoord_shader_twosided = storage->shader_create();
+ default_worldcoord_material_twosided = storage->material_create();
+ storage->shader_set_code(default_worldcoord_shader_twosided, "shader_type spatial; render_mode cull_disabled,world_vertex_coords;\n");
+ storage->material_set_shader(default_worldcoord_material_twosided, default_worldcoord_shader_twosided);
+ }
+
+ {
+ //default material and shader
+
+ default_overdraw_shader = storage->shader_create();
+ storage->shader_set_code(default_overdraw_shader, "shader_type spatial;\nrender_mode blend_add,unshaded;\n void fragment() { ALBEDO=vec3(0.4,0.8,0.8); ALPHA=0.2; }");
+ default_overdraw_material = storage->material_create();
+ storage->material_set_shader(default_overdraw_material, default_overdraw_shader);
+ }
+
+ {
glGenBuffers(1, &state.sky_verts);
glBindBuffer(GL_ARRAY_BUFFER, state.sky_verts);
glBufferData(GL_ARRAY_BUFFER, sizeof(Vector3) * 8, NULL, GL_DYNAMIC_DRAW);
@@ -2463,8 +2655,8 @@ void RasterizerSceneGLES2::initialize() {
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, directional_shadow.size, directional_shadow.size, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
@@ -2475,9 +2667,16 @@ void RasterizerSceneGLES2::initialize() {
ERR_PRINT("Directional shadow framebuffer status invalid");
}
}
+
+ shadow_filter_mode = SHADOW_FILTER_NEAREST;
+
+ RenderList::Element e;
+ e.sort_key = 0;
+ e.light_type1 = 1;
}
void RasterizerSceneGLES2::iteration() {
+ shadow_filter_mode = ShadowFilterMode(int(GLOBAL_GET("rendering/quality/shadows/filter_mode")));
}
void RasterizerSceneGLES2::finalize() {
diff --git a/drivers/gles2/rasterizer_scene_gles2.h b/drivers/gles2/rasterizer_scene_gles2.h
index c5d28e55f4..27cbc35299 100644
--- a/drivers/gles2/rasterizer_scene_gles2.h
+++ b/drivers/gles2/rasterizer_scene_gles2.h
@@ -53,12 +53,34 @@
class RasterizerSceneGLES2 : public RasterizerScene {
public:
+ enum ShadowFilterMode {
+ SHADOW_FILTER_NEAREST,
+ SHADOW_FILTER_PCF5,
+ SHADOW_FILTER_PCF13,
+ };
+
+ ShadowFilterMode shadow_filter_mode;
+
RID default_material;
RID default_material_twosided;
RID default_shader;
RID default_shader_twosided;
+ RID default_worldcoord_material;
+ RID default_worldcoord_material_twosided;
+ RID default_worldcoord_shader;
+ RID default_worldcoord_shader_twosided;
+
+ RID default_overdraw_material;
+ RID default_overdraw_shader;
+
+ uint64_t render_pass;
uint64_t scene_pass;
+ uint32_t current_material_index;
+ uint32_t current_geometry_index;
+ uint32_t current_light_index;
+ uint32_t current_refprobe_index;
+ uint32_t current_shader_index;
RasterizerStorageGLES2 *storage;
struct State {
@@ -172,11 +194,16 @@ public:
bool cull_front;
bool cull_disabled;
bool used_sss;
- bool used_screen_texture;
bool using_contact_shadows;
VS::ViewportDebugDraw debug_draw;
*/
+
+ bool used_screen_texture;
+ bool shadow_is_dual_parabolloid;
+ float dual_parbolloid_direction;
+ float dual_parbolloid_zfar;
+
} state;
/* SHADOW ATLAS API */
@@ -373,6 +400,10 @@ public:
virtual void light_instance_set_shadow_transform(RID p_light_instance, const CameraMatrix &p_projection, const Transform &p_transform, float p_far, float p_split, int p_pass, float p_bias_scale = 1.0);
virtual void light_instance_mark_visible(RID p_light_instance);
+ LightInstance **render_light_instances;
+ int render_directional_lights;
+ int render_light_instance_count;
+
/* REFLECTION INSTANCE */
virtual RID gi_probe_instance_create();
@@ -382,40 +413,18 @@ public:
/* RENDER LIST */
+ enum LightMode {
+ LIGHTMODE_NORMAL,
+ LIGHTMODE_UNSHADED,
+ LIGHTMODE_LIGHTMAP,
+ LIGHTMODE_LIGHTMAP_CAPTURE,
+ };
+
struct RenderList {
+
enum {
- DEFAULT_MAX_ELEMENTS = 65536,
- SORT_FLAG_SKELETON = 1,
- SORT_FLAG_INSTANCING = 2,
- MAX_DIRECTIONAL_LIGHTS = 16,
- MAX_LIGHTS = 4096,
- MAX_REFLECTIONS = 1024,
-
- SORT_KEY_PRIORITY_SHIFT = 56,
- SORT_KEY_PRIORITY_MASK = 0xFF,
- //depth layer for opaque (56-52)
- SORT_KEY_OPAQUE_DEPTH_LAYER_SHIFT = 52,
- SORT_KEY_OPAQUE_DEPTH_LAYER_MASK = 0xF,
-//64 bits unsupported in MSVC
-#define SORT_KEY_UNSHADED_FLAG (uint64_t(1) << 49)
-#define SORT_KEY_NO_DIRECTIONAL_FLAG (uint64_t(1) << 48)
-#define SORT_KEY_LIGHTMAP_CAPTURE_FLAG (uint64_t(1) << 47)
-#define SORT_KEY_LIGHTMAP_FLAG (uint64_t(1) << 46)
-#define SORT_KEY_GI_PROBES_FLAG (uint64_t(1) << 45)
-#define SORT_KEY_VERTEX_LIT_FLAG (uint64_t(1) << 44)
- SORT_KEY_SHADING_SHIFT = 44,
- SORT_KEY_SHADING_MASK = 63,
- //44-28 material index
- SORT_KEY_MATERIAL_INDEX_SHIFT = 28,
- //28-8 geometry index
- SORT_KEY_GEOMETRY_INDEX_SHIFT = 8,
- //bits 5-7 geometry type
- SORT_KEY_GEOMETRY_TYPE_SHIFT = 5,
- //bits 0-5 for flags
- SORT_KEY_OPAQUE_PRE_PASS = 8,
- SORT_KEY_CULL_DISABLED_FLAG = 4,
- SORT_KEY_SKELETON_FLAG = 2,
- SORT_KEY_MIRROR_FLAG = 1
+ MAX_LIGHTS = 255,
+ DEFAULT_MAX_ELEMENTS = 65536
};
int max_elements;
@@ -427,7 +436,38 @@ public:
RasterizerStorageGLES2::Material *material;
RasterizerStorageGLES2::GeometryOwner *owner;
- uint64_t sort_key;
+ bool use_accum; //is this an add pass for multipass
+ bool *use_accum_ptr;
+
+ union {
+ //TODO: should be endian swapped on big endian
+ struct {
+ int32_t depth_layer : 16;
+ int32_t priority : 16;
+ };
+
+ uint32_t depth_key;
+ };
+
+ union {
+ struct {
+ //from least significant to most significant in sort, TODO: should be endian swapped on big endian
+
+ uint64_t geometry_index : 14;
+ uint64_t instancing : 1;
+ uint64_t skeleton : 1;
+ uint64_t shader_index : 10;
+ uint64_t material_index : 10;
+ uint64_t light_index : 8;
+ uint64_t light_type2 : 1; // if 1==0 : nolight/directional, else omni/spot
+ uint64_t refprobe_1_index : 8;
+ uint64_t refprobe_0_index : 8;
+ uint64_t light_type1 : 1; //no light, directional is 0, omni spot is 1
+ uint64_t light_mode : 2; // LightMode enum
+ };
+
+ uint64_t sort_key;
+ };
};
Element *base_elements;
@@ -445,7 +485,11 @@ public:
struct SortByKey {
_FORCE_INLINE_ bool operator()(const Element *A, const Element *B) const {
- return A->sort_key < B->sort_key;
+ if (A->depth_key == B->depth_key) {
+ return A->sort_key < B->sort_key;
+ } else {
+ return A->depth_key < B->depth_key;
+ }
}
};
@@ -476,29 +520,6 @@ public:
}
}
- struct SortByReverseDepthAndPriority {
-
- _FORCE_INLINE_ bool operator()(const Element *A, const Element *B) const {
- uint32_t layer_A = uint32_t(A->sort_key >> SORT_KEY_PRIORITY_SHIFT);
- uint32_t layer_B = uint32_t(B->sort_key >> SORT_KEY_PRIORITY_SHIFT);
- if (layer_A == layer_B) {
- return A->instance->depth > B->instance->depth;
- } else {
- return layer_A < layer_B;
- }
- }
- };
-
- void sort_by_reverse_depth_and_priority(bool p_alpha) { //used for alpha
-
- SortArray<Element *, SortByReverseDepthAndPriority> sorter;
- if (p_alpha) {
- sorter.sort(&elements[max_elements - alpha_element_count], alpha_element_count);
- } else {
- sorter.sort(elements, element_count);
- }
- }
-
// element adding and stuff
_FORCE_INLINE_ Element *add_element() {
@@ -549,7 +570,6 @@ public:
void _fill_render_list(InstanceBase **p_cull_result, int p_cull_count, bool p_depth_pass, bool p_shadow_pass);
void _render_render_list(RenderList::Element **p_elements, int p_element_count,
- const RID *p_directional_lights, int p_directional_light_count,
const Transform &p_view_transform,
const CameraMatrix &p_projection,
RID p_shadow_atlas,
@@ -559,14 +579,15 @@ public:
float p_shadow_normal_bias,
bool p_reverse_cull,
bool p_alpha_pass,
- bool p_shadow,
- bool p_directional_add);
+ bool p_shadow);
void _draw_sky(RasterizerStorageGLES2::Sky *p_sky, const CameraMatrix &p_projection, const Transform &p_transform, bool p_vflip, float p_custom_fov, float p_energy);
- void _setup_material(RasterizerStorageGLES2::Material *p_material, bool p_reverse_cull, bool p_alpha_pass, Size2i p_skeleton_tex_size = Size2i(0, 0));
- void _setup_geometry(RenderList::Element *p_element, RasterizerStorageGLES2::Skeleton *p_skeleton);
- void _render_geometry(RenderList::Element *p_element);
+ _FORCE_INLINE_ bool _setup_material(RasterizerStorageGLES2::Material *p_material, bool p_reverse_cull, bool p_alpha_pass, Size2i p_skeleton_tex_size = Size2i(0, 0));
+ _FORCE_INLINE_ void _setup_geometry(RenderList::Element *p_element, RasterizerStorageGLES2::Skeleton *p_skeleton);
+ _FORCE_INLINE_ void _setup_light_type(LightInstance *p_light, ShadowAtlas *shadow_atlas);
+ _FORCE_INLINE_ void _setup_light(LightInstance *p_light, ShadowAtlas *shadow_atlas, const Transform &p_view_transform);
+ _FORCE_INLINE_ void _render_geometry(RenderList::Element *p_element);
virtual void render_scene(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID *p_light_cull_result, int p_light_cull_count, RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, RID p_environment, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass);
virtual void render_shadow(RID p_light, RID p_shadow_atlas, int p_pass, InstanceBase **p_cull_result, int p_cull_count);
diff --git a/drivers/gles2/rasterizer_storage_gles2.cpp b/drivers/gles2/rasterizer_storage_gles2.cpp
index d945132dc2..adf07c2e4f 100644
--- a/drivers/gles2/rasterizer_storage_gles2.cpp
+++ b/drivers/gles2/rasterizer_storage_gles2.cpp
@@ -52,6 +52,8 @@ GLuint RasterizerStorageGLES2::system_fbo = 0;
#define _GL_HALF_FLOAT_OES 0x8D61
#endif
+#define _EXT_TEXTURE_CUBE_MAP_SEAMLESS 0x884F
+
void RasterizerStorageGLES2::bind_quad_array() const {
glBindBuffer(GL_ARRAY_BUFFER, resources.quadie);
glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, 0);
@@ -4225,6 +4227,16 @@ void RasterizerStorageGLES2::initialize() {
glBindTexture(GL_TEXTURE_2D, 0);
}
+
+#ifdef GLES_OVER_GL
+ //this needs to be enabled manually in OpenGL 2.1
+
+ glEnable(_EXT_TEXTURE_CUBE_MAP_SEAMLESS);
+ glEnable(GL_POINT_SPRITE);
+ glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
+#endif
+
+ config.force_vertex_shading = GLOBAL_GET("rendering/quality/shading/force_vertex_shading");
}
void RasterizerStorageGLES2::finalize() {
diff --git a/drivers/gles2/rasterizer_storage_gles2.h b/drivers/gles2/rasterizer_storage_gles2.h
index d9bf6b3ccb..e6708914ec 100644
--- a/drivers/gles2/rasterizer_storage_gles2.h
+++ b/drivers/gles2/rasterizer_storage_gles2.h
@@ -406,6 +406,9 @@ public:
String path;
+ uint32_t index;
+ uint64_t last_pass;
+
struct CanvasItem {
enum BlendMode {
@@ -491,6 +494,7 @@ public:
valid = false;
custom_code_id = 0;
version = 1;
+ last_pass = 0;
}
};
diff --git a/drivers/gles2/shader_compiler_gles2.cpp b/drivers/gles2/shader_compiler_gles2.cpp
index 83b61dc288..bedcfbb798 100644
--- a/drivers/gles2/shader_compiler_gles2.cpp
+++ b/drivers/gles2/shader_compiler_gles2.cpp
@@ -31,6 +31,7 @@
#include "shader_compiler_gles2.h"
#include "core/os/os.h"
+#include "core/project_settings.h"
#include "core/string_buffer.h"
#include "core/string_builder.h"
@@ -830,6 +831,7 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() {
actions[VS::SHADER_SPATIAL].renames["POINT_SIZE"] = "gl_PointSize";
// gl_InstanceID is not available in OpenGL ES 2.0
actions[VS::SHADER_SPATIAL].renames["INSTANCE_ID"] = "0";
+ actions[VS::SHADER_SPATIAL].renames["OUTPUT_IS_SRGB"] = "SHADER_IS_SRGB";
//builtins
@@ -900,16 +902,30 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() {
actions[VS::SHADER_SPATIAL].render_mode_defines["skip_vertex_transform"] = "#define SKIP_TRANSFORM_USED\n";
actions[VS::SHADER_SPATIAL].render_mode_defines["world_vertex_coords"] = "#define VERTEX_WORLD_COORDS_USED\n";
- actions[VS::SHADER_SPATIAL].render_mode_defines["diffuse_burley"] = "#define DIFFUSE_BURLEY\n";
+ bool force_lambert = GLOBAL_GET("rendering/quality/shading/force_lambert_over_burley");
+
+ if (!force_lambert) {
+ actions[VS::SHADER_SPATIAL].render_mode_defines["diffuse_burley"] = "#define DIFFUSE_BURLEY\n";
+ }
+
actions[VS::SHADER_SPATIAL].render_mode_defines["diffuse_oren_nayar"] = "#define DIFFUSE_OREN_NAYAR\n";
actions[VS::SHADER_SPATIAL].render_mode_defines["diffuse_lambert_wrap"] = "#define DIFFUSE_LAMBERT_WRAP\n";
actions[VS::SHADER_SPATIAL].render_mode_defines["diffuse_toon"] = "#define DIFFUSE_TOON\n";
- actions[VS::SHADER_SPATIAL].render_mode_defines["specular_schlick_ggx"] = "#define SPECULAR_SCHLICK_GGX\n";
+ bool force_blinn = GLOBAL_GET("rendering/quality/shading/force_blinn_over_ggx");
+
+ if (!force_blinn) {
+ actions[VS::SHADER_SPATIAL].render_mode_defines["specular_schlick_ggx"] = "#define SPECULAR_SCHLICK_GGX\n";
+ } else {
+ actions[VS::SHADER_SPATIAL].render_mode_defines["specular_schlick_ggx"] = "#define SPECULAR_BLINN\n";
+ }
+
actions[VS::SHADER_SPATIAL].render_mode_defines["specular_blinn"] = "#define SPECULAR_BLINN\n";
actions[VS::SHADER_SPATIAL].render_mode_defines["specular_phong"] = "#define SPECULAR_PHONG\n";
actions[VS::SHADER_SPATIAL].render_mode_defines["specular_toon"] = "#define SPECULAR_TOON\n";
actions[VS::SHADER_SPATIAL].render_mode_defines["specular_disabled"] = "#define SPECULAR_DISABLED\n";
+ actions[VS::SHADER_SPATIAL].render_mode_defines["shadows_disabled"] = "#define SHADOWS_DISABLED\n";
+ actions[VS::SHADER_SPATIAL].render_mode_defines["ambient_light_disabled"] = "#define AMBIENT_LIGHT_DISABLED\n";
/* PARTICLES SHADER */
diff --git a/drivers/gles2/shader_gles2.cpp b/drivers/gles2/shader_gles2.cpp
index 445428acc5..650e8f7c42 100644
--- a/drivers/gles2/shader_gles2.cpp
+++ b/drivers/gles2/shader_gles2.cpp
@@ -57,7 +57,7 @@
ShaderGLES2 *ShaderGLES2::active = NULL;
-// #define DEBUG_SHADER
+//#define DEBUG_SHADER
#ifdef DEBUG_SHADER
@@ -132,6 +132,11 @@ bool ShaderGLES2::bind() {
ERR_FAIL_COND_V(!version, false);
+ if (!version->ok) { //broken, unable to bind (do not throw error, you saw it before already when it failed compilation).
+ glUseProgram(0);
+ return false;
+ }
+
glUseProgram(version->id);
// find out uniform names and locations
@@ -171,72 +176,24 @@ void ShaderGLES2::unbind() {
active = NULL;
}
-static String _fix_error_code_line(const String &p_error, int p_code_start, int p_offset) {
-
- int last_find_pos = -1;
- // NVIDIA
- String error = p_error;
- while ((last_find_pos = p_error.find("(", last_find_pos + 1)) != -1) {
-
- int end_pos = last_find_pos + 1;
-
- while (true) {
-
- if (p_error[end_pos] >= '0' && p_error[end_pos] <= '9') {
-
- end_pos++;
- continue;
- } else if (p_error[end_pos] == ')') {
- break;
- } else {
-
- end_pos = -1;
- break;
- }
- }
+static void _display_error_with_code(const String &p_error, const Vector<const char *> &p_code) {
- if (end_pos == -1)
- continue;
+ int line = 1;
+ String total_code;
- String numstr = error.substr(last_find_pos + 1, (end_pos - last_find_pos) - 1);
- String begin = error.substr(0, last_find_pos + 1);
- String end = error.substr(end_pos, error.length());
- int num = numstr.to_int() + p_code_start - p_offset;
- error = begin + itos(num) + end;
+ for (int i = 0; i < p_code.size(); i++) {
+ total_code += String(p_code[i]);
}
- // ATI
- last_find_pos = -1;
- while ((last_find_pos = p_error.find("ERROR: ", last_find_pos + 1)) != -1) {
-
- last_find_pos += 6;
- int end_pos = last_find_pos + 1;
+ Vector<String> lines = String(total_code).split("\n");
- while (true) {
-
- if (p_error[end_pos] >= '0' && p_error[end_pos] <= '9') {
-
- end_pos++;
- continue;
- } else if (p_error[end_pos] == ':') {
- break;
- } else {
+ for (int j = 0; j < lines.size(); j++) {
- end_pos = -1;
- break;
- }
- }
- continue;
- if (end_pos == -1)
- continue;
-
- String numstr = error.substr(last_find_pos + 1, (end_pos - last_find_pos) - 1);
- String begin = error.substr(0, last_find_pos + 1);
- String end = error.substr(end_pos, error.length());
- int num = numstr.to_int() + p_code_start - p_offset;
- error = begin + itos(num) + end;
+ print_line(itos(line) + ": " + lines[j]);
+ line++;
}
- return error;
+
+ ERR_PRINTS(p_error);
}
ShaderGLES2::Version *ShaderGLES2::get_current_version() {
@@ -316,7 +273,7 @@ ShaderGLES2::Version *ShaderGLES2::get_current_version() {
if (cc) {
for (int i = 0; i < cc->custom_defines.size(); i++) {
strings.push_back(cc->custom_defines.write[i]);
- DEBUG_PRINT("CD #" + itos(i) + ": " + String(cc->custom_defines[i]));
+ DEBUG_PRINT("CD #" + itos(i) + ": " + String(cc->custom_defines[i].get_data()));
}
}
@@ -375,9 +332,8 @@ ShaderGLES2::Version *ShaderGLES2::get_current_version() {
String err_string = get_shader_name() + ": Vertex shader compilation failed:\n";
err_string += ilogmem;
- err_string = _fix_error_code_line(err_string, vertex_code_start, define_line_ofs);
- ERR_PRINTS(err_string);
+ _display_error_with_code(err_string, strings);
Memory::free_static(ilogmem);
glDeleteShader(v.vert_id);
@@ -451,9 +407,8 @@ ShaderGLES2::Version *ShaderGLES2::get_current_version() {
String err_string = get_shader_name() + ": Fragment shader compilation failed:\n";
err_string += ilogmem;
- err_string = _fix_error_code_line(err_string, fragment_code_start, define_line_ofs);
- ERR_PRINTS(err_string);
+ _display_error_with_code(err_string, strings);
Memory::free_static(ilogmem);
glDeleteShader(v.frag_id);
@@ -503,9 +458,8 @@ ShaderGLES2::Version *ShaderGLES2::get_current_version() {
String err_string = get_shader_name() + ": Program linking failed:\n";
err_string += ilogmem;
- err_string = _fix_error_code_line(err_string, fragment_code_start, define_line_ofs);
- ERR_PRINTS(err_string);
+ _display_error_with_code(err_string, strings);
Memory::free_static(ilogmem);
glDeleteShader(v.frag_id);
diff --git a/drivers/gles2/shader_gles2.h b/drivers/gles2/shader_gles2.h
index 8e274b4f57..78e1962f80 100644
--- a/drivers/gles2/shader_gles2.h
+++ b/drivers/gles2/shader_gles2.h
@@ -468,7 +468,8 @@ public:
// like forward declared nested classes.
void use_material(void *p_material);
- uint32_t get_version() const { return new_conditional_version.version; }
+ _FORCE_INLINE_ uint32_t get_version() const { return new_conditional_version.version; }
+ _FORCE_INLINE_ bool is_version_valid() const { return version && version->ok; }
void set_uniform_camera(int p_idx, const CameraMatrix &p_mat) {
diff --git a/drivers/gles2/shaders/scene.glsl b/drivers/gles2/shaders/scene.glsl
index 906c089170..da4c3a84f1 100644
--- a/drivers/gles2/shaders/scene.glsl
+++ b/drivers/gles2/shaders/scene.glsl
@@ -5,12 +5,16 @@
#define mediump
#define highp
#else
-precision mediump float;
-precision mediump int;
+precision highp float;
+precision highp int;
#endif
#include "stdlib.glsl"
+#define SHADER_IS_SRGB true
+
+#define M_PI 3.14159265359
+
//
// attributes
//
@@ -39,9 +43,9 @@ attribute vec2 uv2_attrib; // attrib:5
#ifdef USE_SKELETON_SOFTWARE
-attribute highp vec4 bone_transform_row_0; // attrib:9
-attribute highp vec4 bone_transform_row_1; // attrib:10
-attribute highp vec4 bone_transform_row_2; // attrib:11
+attribute highp vec4 bone_transform_row_0; // attrib:8
+attribute highp vec4 bone_transform_row_1; // attrib:9
+attribute highp vec4 bone_transform_row_2; // attrib:10
#else
@@ -57,12 +61,12 @@ uniform ivec2 skeleton_texture_size;
#ifdef USE_INSTANCING
-attribute highp vec4 instance_xform_row_0; // attrib:12
-attribute highp vec4 instance_xform_row_1; // attrib:13
-attribute highp vec4 instance_xform_row_2; // attrib:14
+attribute highp vec4 instance_xform_row_0; // attrib:8
+attribute highp vec4 instance_xform_row_1; // attrib:9
+attribute highp vec4 instance_xform_row_2; // attrib:10
-attribute highp vec4 instance_color; // attrib:15
-attribute highp vec4 instance_custom_data; // attrib:8
+attribute highp vec4 instance_color; // attrib:11
+attribute highp vec4 instance_custom_data; // attrib:12
#endif
@@ -116,6 +120,148 @@ VERTEX_SHADER_GLOBALS
/* clang-format on */
+#ifdef RENDER_DEPTH_DUAL_PARABOLOID
+
+varying highp float dp_clip;
+uniform highp float shadow_dual_paraboloid_render_zfar;
+uniform highp float shadow_dual_paraboloid_render_side;
+
+#endif
+
+#if defined(USE_SHADOW) && defined(USE_LIGHTING)
+
+#ifdef LIGHT_MODE_DIRECTIONAL
+uniform highp sampler2D light_directional_shadow; // texunit:-3
+uniform highp vec4 light_split_offsets;
+#endif
+
+uniform highp mat4 light_shadow_matrix;
+varying highp vec4 shadow_coord;
+
+#if defined(LIGHT_USE_PSSM2) || defined(LIGHT_USE_PSSM4)
+uniform highp mat4 light_shadow_matrix2;
+varying highp vec4 shadow_coord2;
+#endif
+
+#if defined(LIGHT_USE_PSSM4)
+
+uniform highp mat4 light_shadow_matrix3;
+uniform highp mat4 light_shadow_matrix4;
+varying highp vec4 shadow_coord3;
+varying highp vec4 shadow_coord4;
+
+#endif
+
+#endif
+
+#if defined(USE_VERTEX_LIGHTING) && defined(USE_LIGHTING)
+
+varying highp vec3 diffuse_interp;
+varying highp vec3 specular_interp;
+
+// general for all lights
+uniform vec4 light_color;
+uniform float light_specular;
+
+// directional
+uniform vec3 light_direction;
+
+// omni
+uniform vec3 light_position;
+
+uniform float light_range;
+uniform vec4 light_attenuation;
+
+// spot
+uniform float light_spot_attenuation;
+uniform float light_spot_range;
+uniform float light_spot_angle;
+
+void light_compute(
+ vec3 N,
+ vec3 L,
+ vec3 V,
+ vec3 light_color,
+ vec3 attenuation,
+ float roughness) {
+
+//this makes lights behave closer to linear, but then addition of lights looks bad
+//better left disabled
+
+//#define SRGB_APPROX(m_var) m_var = pow(m_var,0.4545454545);
+/*
+#define SRGB_APPROX(m_var) {\
+ float S1 = sqrt(m_var);\
+ float S2 = sqrt(S1);\
+ float S3 = sqrt(S2);\
+ m_var = 0.662002687 * S1 + 0.684122060 * S2 - 0.323583601 * S3 - 0.0225411470 * m_var;\
+ }
+*/
+#define SRGB_APPROX(m_var)
+
+ float NdotL = dot(N, L);
+ float cNdotL = max(NdotL, 0.0); // clamped NdotL
+ float NdotV = dot(N, V);
+ float cNdotV = max(NdotV, 0.0);
+
+#if defined(DIFFUSE_OREN_NAYAR)
+ vec3 diffuse_brdf_NL;
+#else
+ float diffuse_brdf_NL; // BRDF times N.L for calculating diffuse radiance
+#endif
+
+#if defined(DIFFUSE_LAMBERT_WRAP)
+ // energy conserving lambert wrap shader
+ diffuse_brdf_NL = max(0.0, (NdotL + roughness) / ((1.0 + roughness) * (1.0 + roughness)));
+
+#elif defined(DIFFUSE_OREN_NAYAR)
+
+ {
+ // see http://mimosa-pudica.net/improved-oren-nayar.html
+ float LdotV = dot(L, V);
+
+ float s = LdotV - NdotL * NdotV;
+ float t = mix(1.0, max(NdotL, NdotV), step(0.0, s));
+
+ float sigma2 = roughness * roughness; // TODO: this needs checking
+ vec3 A = 1.0 + sigma2 * (-0.5 / (sigma2 + 0.33) + 0.17 * diffuse_color / (sigma2 + 0.13));
+ float B = 0.45 * sigma2 / (sigma2 + 0.09);
+
+ diffuse_brdf_NL = cNdotL * (A + vec3(B) * s / t) * (1.0 / M_PI);
+ }
+#else
+ // lambert by default for everything else
+ diffuse_brdf_NL = cNdotL * (1.0 / M_PI);
+#endif
+
+ SRGB_APPROX(diffuse_brdf_NL)
+
+ diffuse_interp += light_color * diffuse_brdf_NL * attenuation;
+
+ if (roughness > 0.0) {
+
+ // D
+ float specular_brdf_NL = 0.0;
+
+#if !defined(SPECULAR_DISABLED)
+ //normalized blinn always unless disabled
+ vec3 H = normalize(V + L);
+ float cNdotH = max(dot(N, H), 0.0);
+ float cVdotH = max(dot(V, H), 0.0);
+ float cLdotH = max(dot(L, H), 0.0);
+ float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25;
+ float blinn = pow(cNdotH, shininess);
+ blinn *= (shininess + 8.0) / (8.0 * 3.141592654);
+ specular_brdf_NL = (blinn) / max(4.0 * cNdotV * cNdotL, 0.75);
+#endif
+
+ SRGB_APPROX(specular_brdf_NL)
+ specular_interp += specular_brdf_NL * light_color * attenuation;
+ }
+}
+
+#endif
+
void main() {
highp vec4 vertex = vertex_attrib;
@@ -209,6 +355,7 @@ void main() {
#endif
mat4 modelview = camera_matrix * world_matrix;
+ float roughness = 1.0;
#define world_transform world_matrix
@@ -252,13 +399,105 @@ VERTEX_SHADER_CODE
#ifdef RENDER_DEPTH
+#ifdef RENDER_DEPTH_DUAL_PARABOLOID
+
+ vertex_interp.z *= shadow_dual_paraboloid_render_side;
+ normal_interp.z *= shadow_dual_paraboloid_render_side;
+
+ dp_clip = vertex_interp.z; //this attempts to avoid noise caused by objects sent to the other parabolloid side due to bias
+
+ //for dual paraboloid shadow mapping, this is the fastest but least correct way, as it curves straight edges
+
+ highp vec3 vtx = vertex_interp + normalize(vertex_interp) * light_bias;
+ highp float distance = length(vtx);
+ vtx = normalize(vtx);
+ vtx.xy /= 1.0 - vtx.z;
+ vtx.z = (distance / shadow_dual_paraboloid_render_zfar);
+ vtx.z = vtx.z * 2.0 - 1.0;
+
+ vertex_interp = vtx;
+
+#else
float z_ofs = light_bias;
z_ofs += (1.0 - abs(normal_interp.z)) * light_normal_bias;
vertex_interp.z -= z_ofs;
+#endif //dual parabolloid
+
+#endif //depth
+
+//vertex lighting
+#if defined(USE_VERTEX_LIGHTING) && defined(USE_LIGHTING)
+ //vertex shaded version of lighting (more limited)
+ vec3 L;
+ vec3 light_att;
+
+#ifdef LIGHT_MODE_OMNI
+ vec3 light_vec = light_position - vertex_interp;
+ float light_length = length(light_vec);
+
+ float normalized_distance = light_length / light_range;
+
+ float omni_attenuation = pow(1.0 - normalized_distance, light_attenuation.w);
+
+ vec3 attenuation = vec3(omni_attenuation);
+ light_att = vec3(omni_attenuation);
+
+ L = normalize(light_vec);
+
+#endif
+
+#ifdef LIGHT_MODE_SPOT
+
+ vec3 light_rel_vec = light_position - vertex_interp;
+ float light_length = length(light_rel_vec);
+ float normalized_distance = light_length / light_range;
+
+ float spot_attenuation = pow(1.0 - normalized_distance, light_attenuation.w);
+ vec3 spot_dir = light_direction;
+
+ float spot_cutoff = light_spot_angle;
+
+ float scos = max(dot(-normalize(light_rel_vec), spot_dir), spot_cutoff);
+ float spot_rim = max(0.0001, (1.0 - scos) / (1.0 - spot_cutoff));
+
+ spot_attenuation *= 1.0 - pow(spot_rim, light_spot_attenuation);
+
+ light_att = vec3(spot_attenuation);
+ L = normalize(light_rel_vec);
#endif
+#ifdef LIGHT_MODE_DIRECTIONAL
+ vec3 light_vec = -light_direction;
+ light_att = vec3(1.0); //no base attenuation
+ L = normalize(light_vec);
+#endif
+
+ diffuse_interp = vec3(0.0);
+ specular_interp = vec3(0.0);
+ light_compute(normal_interp, L, -normalize(vertex_interp), light_color.rgb, light_att, roughness);
+
+#endif
+
+//shadows (for both vertex and fragment)
+#if defined(USE_SHADOW) && defined(USE_LIGHTING)
+
+ vec4 vi4 = vec4(vertex_interp, 1.0);
+ shadow_coord = light_shadow_matrix * vi4;
+
+#if defined(LIGHT_USE_PSSM2) || defined(LIGHT_USE_PSSM4)
+ shadow_coord2 = light_shadow_matrix2 * vi4;
+#endif
+
+#if defined(LIGHT_USE_PSSM4)
+ shadow_coord3 = light_shadow_matrix3 * vi4;
+ shadow_coord3 = light_shadow_matrix3 * vi4;
+
+#endif
+
+#endif //use shadow and use lighting
+
gl_Position = projection_matrix * vec4(vertex_interp, 1.0);
}
@@ -276,12 +515,13 @@ VERTEX_SHADER_CODE
#define highp
#else
precision mediump float;
-precision mediump int;
+precision highp int;
#endif
#include "stdlib.glsl"
#define M_PI 3.14159265359
+#define SHADER_IS_SRGB true
//
// uniforms
@@ -301,10 +541,11 @@ uniform highp float time;
uniform vec2 screen_pixel_size;
#endif
-uniform highp sampler2D depth_buffer; //texunit:-5
+// I think supporting this in GLES2 is difficult
+// uniform highp sampler2D depth_buffer;
#if defined(SCREEN_TEXTURE_USED)
-uniform highp sampler2D screen_texture; //texunit:-6
+uniform highp sampler2D screen_texture; //texunit:-4
#endif
#ifdef USE_RADIANCE_MAP
@@ -323,49 +564,68 @@ uniform float ambient_sky_contribution;
uniform vec4 ambient_color;
uniform float ambient_energy;
-#ifdef LIGHT_PASS
+#ifdef USE_LIGHTING
-#define LIGHT_TYPE_DIRECTIONAL 0
-#define LIGHT_TYPE_OMNI 1
-#define LIGHT_TYPE_SPOT 2
+#ifdef USE_VERTEX_LIGHTING
-// general for all lights
-uniform int light_type;
+//get from vertex
+varying highp vec3 diffuse_interp;
+varying highp vec3 specular_interp;
-uniform float light_energy;
+#else
+//done in fragment
+// general for all lights
uniform vec4 light_color;
uniform float light_specular;
// directional
uniform vec3 light_direction;
-
// omni
uniform vec3 light_position;
-uniform float light_range;
uniform vec4 light_attenuation;
// spot
uniform float light_spot_attenuation;
uniform float light_spot_range;
uniform float light_spot_angle;
+#endif
-// shadows
-uniform highp sampler2D light_shadow_atlas; //texunit:-4
-uniform float light_has_shadow;
+//this is needed outside above if because dual paraboloid wants it
+uniform float light_range;
+
+#ifdef USE_SHADOW
+
+uniform highp vec2 shadow_pixel_size;
+
+#if defined(LIGHT_MODE_OMNI) || defined(LIGHT_MODE_SPOT)
+uniform highp sampler2D light_shadow_atlas; //texunit:-3
+#endif
+
+#ifdef LIGHT_MODE_DIRECTIONAL
+uniform highp sampler2D light_directional_shadow; // texunit:-3
+uniform highp vec4 light_split_offsets;
+#endif
+
+varying highp vec4 shadow_coord;
+
+#if defined(LIGHT_USE_PSSM2) || defined(LIGHT_USE_PSSM4)
+varying highp vec4 shadow_coord2;
+#endif
+
+#if defined(LIGHT_USE_PSSM4)
+
+varying highp vec4 shadow_coord3;
+varying highp vec4 shadow_coord4;
+
+#endif
-uniform mat4 light_shadow_matrix;
uniform vec4 light_clamp;
-// directional shadow
+#endif // light shadow
-uniform highp sampler2D light_directional_shadow; // texunit:-4
-uniform vec4 light_split_offsets;
+// directional shadow
-uniform mat4 light_shadow_matrix1;
-uniform mat4 light_shadow_matrix2;
-uniform mat4 light_shadow_matrix3;
-uniform mat4 light_shadow_matrix4;
#endif
//
@@ -406,7 +666,79 @@ FRAGMENT_SHADER_GLOBALS
/* clang-format on */
-#ifdef LIGHT_PASS
+#ifdef RENDER_DEPTH_DUAL_PARABOLOID
+
+varying highp float dp_clip;
+
+#endif
+
+#ifdef USE_LIGHTING
+
+// This returns the G_GGX function divided by 2 cos_theta_m, where in practice cos_theta_m is either N.L or N.V.
+// We're dividing this factor off because the overall term we'll end up looks like
+// (see, for example, the first unnumbered equation in B. Burley, "Physically Based Shading at Disney", SIGGRAPH 2012):
+//
+// F(L.V) D(N.H) G(N.L) G(N.V) / (4 N.L N.V)
+//
+// We're basically regouping this as
+//
+// F(L.V) D(N.H) [G(N.L)/(2 N.L)] [G(N.V) / (2 N.V)]
+//
+// and thus, this function implements the [G(N.m)/(2 N.m)] part with m = L or V.
+//
+// The contents of the D and G (G1) functions (GGX) are taken from
+// E. Heitz, "Understanding the Masking-Shadowing Function in Microfacet-Based BRDFs", J. Comp. Graph. Tech. 3 (2) (2014).
+// Eqns 71-72 and 85-86 (see also Eqns 43 and 80).
+
+float G_GGX_2cos(float cos_theta_m, float alpha) {
+ // Schlick's approximation
+ // C. Schlick, "An Inexpensive BRDF Model for Physically-based Rendering", Computer Graphics Forum. 13 (3): 233 (1994)
+ // Eq. (19), although see Heitz (2014) the about the problems with his derivation.
+ // It nevertheless approximates GGX well with k = alpha/2.
+ float k = 0.5 * alpha;
+ return 0.5 / (cos_theta_m * (1.0 - k) + k);
+
+ // float cos2 = cos_theta_m * cos_theta_m;
+ // float sin2 = (1.0 - cos2);
+ // return 1.0 / (cos_theta_m + sqrt(cos2 + alpha * alpha * sin2));
+}
+
+float D_GGX(float cos_theta_m, float alpha) {
+ float alpha2 = alpha * alpha;
+ float d = 1.0 + (alpha2 - 1.0) * cos_theta_m * cos_theta_m;
+ return alpha2 / (M_PI * d * d);
+}
+
+float G_GGX_anisotropic_2cos(float cos_theta_m, float alpha_x, float alpha_y, float cos_phi, float sin_phi) {
+ float cos2 = cos_theta_m * cos_theta_m;
+ float sin2 = (1.0 - cos2);
+ float s_x = alpha_x * cos_phi;
+ float s_y = alpha_y * sin_phi;
+ return 1.0 / max(cos_theta_m + sqrt(cos2 + (s_x * s_x + s_y * s_y) * sin2), 0.001);
+}
+
+float D_GGX_anisotropic(float cos_theta_m, float alpha_x, float alpha_y, float cos_phi, float sin_phi) {
+ float cos2 = cos_theta_m * cos_theta_m;
+ float sin2 = (1.0 - cos2);
+ float r_x = cos_phi / alpha_x;
+ float r_y = sin_phi / alpha_y;
+ float d = cos2 + sin2 * (r_x * r_x + r_y * r_y);
+ return 1.0 / max(M_PI * alpha_x * alpha_y * d * d, 0.001);
+}
+
+float SchlickFresnel(float u) {
+ float m = 1.0 - u;
+ float m2 = m * m;
+ return m2 * m2 * m; // pow(m,5)
+}
+
+float GTR1(float NdotH, float a) {
+ if (a >= 1.0) return 1.0 / M_PI;
+ float a2 = a * a;
+ float t = 1.0 + (a2 - 1.0) * NdotH * NdotH;
+ return (a2 - 1.0) / (M_PI * log(a2) * t);
+}
+
void light_compute(
vec3 N,
vec3 L,
@@ -428,52 +760,267 @@ void light_compute(
inout vec3 diffuse_light,
inout vec3 specular_light) {
+//this makes lights behave closer to linear, but then addition of lights looks bad
+//better left disabled
+
+//#define SRGB_APPROX(m_var) m_var = pow(m_var,0.4545454545);
+/*
+#define SRGB_APPROX(m_var) {\
+ float S1 = sqrt(m_var);\
+ float S2 = sqrt(S1);\
+ float S3 = sqrt(S2);\
+ m_var = 0.662002687 * S1 + 0.684122060 * S2 - 0.323583601 * S3 - 0.0225411470 * m_var;\
+ }
+*/
+#define SRGB_APPROX(m_var)
+
+#if defined(USE_LIGHT_SHADER_CODE)
+ // light is written by the light shader
+
+ vec3 normal = N;
+ vec3 albedo = diffuse_color;
+ vec3 light = L;
+ vec3 view = V;
+
+ /* clang-format off */
+
+LIGHT_SHADER_CODE
+
+ /* clang-format on */
+
+#else
float NdotL = dot(N, L);
- float cNdotL = max(NdotL, 0.0);
+ float cNdotL = max(NdotL, 0.0); // clamped NdotL
float NdotV = dot(N, V);
float cNdotV = max(NdotV, 0.0);
- {
- // calculate diffuse reflection
-
- // TODO hardcode Oren Nayar for now
- float diffuse_brdf_NL;
+ if (metallic < 1.0) {
+#if defined(DIFFUSE_OREN_NAYAR)
+ vec3 diffuse_brdf_NL;
+#else
+ float diffuse_brdf_NL; // BRDF times N.L for calculating diffuse radiance
+#endif
+#if defined(DIFFUSE_LAMBERT_WRAP)
+ // energy conserving lambert wrap shader
diffuse_brdf_NL = max(0.0, (NdotL + roughness) / ((1.0 + roughness) * (1.0 + roughness)));
- // diffuse_brdf_NL = cNdotL * (1.0 / M_PI);
+
+#elif defined(DIFFUSE_OREN_NAYAR)
+
+ {
+ // see http://mimosa-pudica.net/improved-oren-nayar.html
+ float LdotV = dot(L, V);
+
+ float s = LdotV - NdotL * NdotV;
+ float t = mix(1.0, max(NdotL, NdotV), step(0.0, s));
+
+ float sigma2 = roughness * roughness; // TODO: this needs checking
+ vec3 A = 1.0 + sigma2 * (-0.5 / (sigma2 + 0.33) + 0.17 * diffuse_color / (sigma2 + 0.13));
+ float B = 0.45 * sigma2 / (sigma2 + 0.09);
+
+ diffuse_brdf_NL = cNdotL * (A + vec3(B) * s / t) * (1.0 / M_PI);
+ }
+
+#elif defined(DIFFUSE_TOON)
+
+ diffuse_brdf_NL = smoothstep(-roughness, max(roughness, 0.01), NdotL);
+
+#elif defined(DIFFUSE_BURLEY)
+
+ {
+
+ vec3 H = normalize(V + L);
+ float cLdotH = max(0.0, dot(L, H));
+
+ float FD90 = 0.5 + 2.0 * cLdotH * cLdotH * roughness;
+ float FdV = 1.0 + (FD90 - 1.0) * SchlickFresnel(cNdotV);
+ float FdL = 1.0 + (FD90 - 1.0) * SchlickFresnel(cNdotL);
+ diffuse_brdf_NL = (1.0 / M_PI) * FdV * FdL * cNdotL;
+ /*
+ float energyBias = mix(roughness, 0.0, 0.5);
+ float energyFactor = mix(roughness, 1.0, 1.0 / 1.51);
+ float fd90 = energyBias + 2.0 * VoH * VoH * roughness;
+ float f0 = 1.0;
+ float lightScatter = f0 + (fd90 - f0) * pow(1.0 - cNdotL, 5.0);
+ float viewScatter = f0 + (fd90 - f0) * pow(1.0 - cNdotV, 5.0);
+
+ diffuse_brdf_NL = lightScatter * viewScatter * energyFactor;
+ */
+ }
+#else
+ // lambert
+ diffuse_brdf_NL = cNdotL * (1.0 / M_PI);
+#endif
+
+ SRGB_APPROX(diffuse_brdf_NL)
diffuse_light += light_color * diffuse_color * diffuse_brdf_NL * attenuation;
+
+#if defined(TRANSMISSION_USED)
+ diffuse_light += light_color * diffuse_color * (vec3(1.0 / M_PI) - diffuse_brdf_NL) * transmission * attenuation;
+#endif
+
+#if defined(LIGHT_USE_RIM)
+ float rim_light = pow(max(0.0, 1.0 - cNdotV), max(0.0, (1.0 - roughness) * 16.0));
+ diffuse_light += rim_light * rim * mix(vec3(1.0), diffuse_color, rim_tint) * light_color;
+#endif
}
- {
- // calculate specular reflection
+ if (roughness > 0.0) {
+
+ // D
+
+ float specular_brdf_NL;
+
+#if defined(SPECULAR_BLINN)
+
+ //normalized blinn
+ vec3 H = normalize(V + L);
+ float cNdotH = max(dot(N, H), 0.0);
+ float cVdotH = max(dot(V, H), 0.0);
+ float cLdotH = max(dot(L, H), 0.0);
+ float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25;
+ float blinn = pow(cNdotH, shininess);
+ blinn *= (shininess + 8.0) / (8.0 * 3.141592654);
+ specular_brdf_NL = (blinn) / max(4.0 * cNdotV * cNdotL, 0.75);
+
+#elif defined(SPECULAR_PHONG)
vec3 R = normalize(-reflect(L, N));
- float cRdotV = max(dot(R, V), 0.0);
- float blob_intensity = pow(cRdotV, (1.0 - roughness) * 256.0);
- specular_light += light_color * attenuation * blob_intensity * specular_blob_intensity;
+ float cRdotV = max(0.0, dot(R, V));
+ float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25;
+ float phong = pow(cRdotV, shininess);
+ phong *= (shininess + 8.0) / (8.0 * 3.141592654);
+ specular_brdf_NL = (phong) / max(4.0 * cNdotV * cNdotL, 0.75);
+
+#elif defined(SPECULAR_TOON)
+
+ vec3 R = normalize(-reflect(L, N));
+ float RdotV = dot(R, V);
+ float mid = 1.0 - roughness;
+ mid *= mid;
+ specular_brdf_NL = smoothstep(mid - roughness * 0.5, mid + roughness * 0.5, RdotV) * mid;
+
+#elif defined(SPECULAR_DISABLED)
+ // none..
+ specular_brdf_NL = 0.0;
+#elif defined(SPECULAR_SCHLICK_GGX)
+ // shlick+ggx as default
+
+ vec3 H = normalize(V + L);
+
+ float cNdotH = max(dot(N, H), 0.0);
+ float cLdotH = max(dot(L, H), 0.0);
+
+#if defined(LIGHT_USE_ANISOTROPY)
+
+ float aspect = sqrt(1.0 - anisotropy * 0.9);
+ float rx = roughness / aspect;
+ float ry = roughness * aspect;
+ float ax = rx * rx;
+ float ay = ry * ry;
+ float XdotH = dot(T, H);
+ float YdotH = dot(B, H);
+ float D = D_GGX_anisotropic(cNdotH, ax, ay, XdotH, YdotH);
+ float G = G_GGX_anisotropic_2cos(cNdotL, ax, ay, XdotH, YdotH) * G_GGX_anisotropic_2cos(cNdotV, ax, ay, XdotH, YdotH);
+
+#else
+ float alpha = roughness * roughness;
+ float D = D_GGX(cNdotH, alpha);
+ float G = G_GGX_2cos(cNdotL, alpha) * G_GGX_2cos(cNdotV, alpha);
+#endif
+ // F
+ //float F0 = 1.0;
+ //float cLdotH5 = SchlickFresnel(cLdotH);
+ //float F = mix(cLdotH5, 1.0, F0);
+
+ specular_brdf_NL = cNdotL * D /* F */ * G;
+
+#endif
+
+ SRGB_APPROX(specular_brdf_NL)
+ specular_light += specular_brdf_NL * light_color * specular_blob_intensity * attenuation;
+
+#if defined(LIGHT_USE_CLEARCOAT)
+ if (clearcoat_gloss > 0.0) {
+#if !defined(SPECULAR_SCHLICK_GGX) && !defined(SPECULAR_BLINN)
+ vec3 H = normalize(V + L);
+#endif
+#if !defined(SPECULAR_SCHLICK_GGX)
+ float cNdotH = max(dot(N, H), 0.0);
+ float cLdotH = max(dot(L, H), 0.0);
+ float cLdotH5 = SchlickFresnel(cLdotH);
+#endif
+ float Dr = GTR1(cNdotH, mix(.1, .001, clearcoat_gloss));
+ float Fr = mix(.04, 1.0, cLdotH5);
+ float Gr = G_GGX_2cos(cNdotL, .25) * G_GGX_2cos(cNdotV, .25);
+
+ float specular_brdf_NL = 0.25 * clearcoat * Gr * Fr * Dr * cNdotL;
+
+ specular_light += specular_brdf_NL * light_color * specular_blob_intensity * attenuation;
+ }
+#endif
}
+
+#endif //defined(USE_LIGHT_SHADER_CODE)
}
+#endif
// shadows
+#ifdef USE_SHADOW
+
+#define SAMPLE_SHADOW_TEXEL(p_shadow, p_pos, p_depth) step(p_depth, texture2D(p_shadow, p_pos).r)
+
float sample_shadow(
highp sampler2D shadow,
- vec2 shadow_pixel_size,
- vec2 pos,
- float depth,
- vec4 clamp_rect) {
- // vec4 depth_value = texture2D(shadow, pos);
-
- // return depth_value.z;
- return texture2DProj(shadow, vec4(pos, depth, 1.0)).r;
- // return (depth_value.x + depth_value.y + depth_value.z + depth_value.w) / 4.0;
+ highp vec2 pos,
+ highp float depth) {
+
+#ifdef SHADOW_MODE_PCF_13
+
+ float avg = SAMPLE_SHADOW_TEXEL(shadow, pos, depth);
+ avg += SAMPLE_SHADOW_TEXEL(shadow, pos + vec2(shadow_pixel_size.x, 0.0), depth);
+ avg += SAMPLE_SHADOW_TEXEL(shadow, pos + vec2(-shadow_pixel_size.x, 0.0), depth);
+ avg += SAMPLE_SHADOW_TEXEL(shadow, pos + vec2(0.0, shadow_pixel_size.y), depth);
+ avg += SAMPLE_SHADOW_TEXEL(shadow, pos + vec2(0.0, -shadow_pixel_size.y), depth);
+ avg += SAMPLE_SHADOW_TEXEL(shadow, pos + vec2(shadow_pixel_size.x, shadow_pixel_size.y), depth);
+ avg += SAMPLE_SHADOW_TEXEL(shadow, pos + vec2(-shadow_pixel_size.x, shadow_pixel_size.y), depth);
+ avg += SAMPLE_SHADOW_TEXEL(shadow, pos + vec2(shadow_pixel_size.x, -shadow_pixel_size.y), depth);
+ avg += SAMPLE_SHADOW_TEXEL(shadow, pos + vec2(-shadow_pixel_size.x, -shadow_pixel_size.y), depth);
+ avg += SAMPLE_SHADOW_TEXEL(shadow, pos + vec2(shadow_pixel_size.x * 2.0, 0.0), depth);
+ avg += SAMPLE_SHADOW_TEXEL(shadow, pos + vec2(-shadow_pixel_size.x * 2.0, 0.0), depth);
+ avg += SAMPLE_SHADOW_TEXEL(shadow, pos + vec2(0.0, shadow_pixel_size.y * 2.0), depth);
+ avg += SAMPLE_SHADOW_TEXEL(shadow, pos + vec2(0.0, -shadow_pixel_size.y * 2.0), depth);
+ return avg * (1.0 / 13.0);
+#endif
+
+#ifdef SHADOW_MODE_PCF_5
+
+ float avg = SAMPLE_SHADOW_TEXEL(shadow, pos, depth);
+ avg += SAMPLE_SHADOW_TEXEL(shadow, pos + vec2(shadow_pixel_size.x, 0.0), depth);
+ avg += SAMPLE_SHADOW_TEXEL(shadow, pos + vec2(-shadow_pixel_size.x, 0.0), depth);
+ avg += SAMPLE_SHADOW_TEXEL(shadow, pos + vec2(0.0, shadow_pixel_size.y), depth);
+ avg += SAMPLE_SHADOW_TEXEL(shadow, pos + vec2(0.0, -shadow_pixel_size.y), depth);
+ return avg * (1.0 / 5.0);
+
+#endif
+
+#if !defined(SHADOW_MODE_PCF_5) || !defined(SHADOW_MODE_PCF_13)
+
+ return SAMPLE_SHADOW_TEXEL(shadow, pos, depth);
+#endif
}
#endif
void main() {
+#ifdef RENDER_DEPTH_DUAL_PARABOLOID
+
+ if (dp_clip > 0.0)
+ discard;
+#endif
highp vec3 vertex = vertex_interp;
vec3 albedo = vec3(1.0);
vec3 transmission = vec3(0.0);
@@ -540,11 +1087,8 @@ FRAGMENT_SHADER_CODE
vec3 specular_light = vec3(0.0, 0.0, 0.0);
vec3 diffuse_light = vec3(0.0, 0.0, 0.0);
-
vec3 ambient_light = vec3(0.0, 0.0, 0.0);
- vec3 env_reflection_light = vec3(0.0, 0.0, 0.0);
-
vec3 eye_position = -normalize(vertex_interp);
#ifdef ALPHA_SCISSOR_USED
@@ -553,287 +1097,288 @@ FRAGMENT_SHADER_CODE
}
#endif
+#ifdef BASE_PASS
+ //none
+#ifdef USE_RADIANCE_MAP
+
+ vec3 ref_vec = reflect(-eye_position, N);
+ ref_vec = normalize((radiance_inverse_xform * vec4(ref_vec, 0.0)).xyz);
+
+ ref_vec.z *= -1.0;
+
+ specular_light = textureCubeLod(radiance_map, ref_vec, roughness * RADIANCE_MAX_LOD).xyz * bg_energy;
+
+ {
+ vec3 ambient_dir = normalize((radiance_inverse_xform * vec4(normal, 0.0)).xyz);
+ vec3 env_ambient = textureCubeLod(radiance_map, ambient_dir, RADIANCE_MAX_LOD).xyz * bg_energy;
+
+ ambient_light = mix(ambient_color.rgb, env_ambient, ambient_sky_contribution);
+ }
+
+#else
+
+ ambient_light = ambient_color.rgb;
+
+#endif
+
+ ambient_light *= ambient_energy;
+
+#endif //BASE PASS
+
//
// Lighting
//
-#ifdef LIGHT_PASS
-
- if (light_type == LIGHT_TYPE_OMNI) {
- vec3 light_vec = light_position - vertex;
- float light_length = length(light_vec);
+#ifdef USE_LIGHTING
- float normalized_distance = light_length / light_range;
+#ifndef USE_VERTEX_LIGHTING
+ vec3 L;
+#endif
+ vec3 light_att = vec3(1.0);
- float omni_attenuation = pow(1.0 - normalized_distance, light_attenuation.w);
+#ifdef LIGHT_MODE_OMNI
- vec3 attenuation = vec3(omni_attenuation);
+#ifndef USE_VERTEX_LIGHTING
+ vec3 light_vec = light_position - vertex;
+ float light_length = length(light_vec);
- if (light_has_shadow > 0.5) {
- highp vec3 splane = (light_shadow_matrix * vec4(vertex, 1.0)).xyz;
- float shadow_len = length(splane);
+ float normalized_distance = light_length / light_range;
- splane = normalize(splane);
+ float omni_attenuation = pow(1.0 - normalized_distance, light_attenuation.w);
- vec4 clamp_rect = light_clamp;
+ light_att = vec3(omni_attenuation);
+ L = normalize(light_vec);
- if (splane.z >= 0.0) {
- splane.z += 1.0;
+#endif
- clamp_rect.y += clamp_rect.w;
- } else {
- splane.z = 1.0 - splane.z;
- }
+#ifdef USE_SHADOW
+ {
+ highp vec3 splane = shadow_coord.xyz;
+ float shadow_len = length(splane);
- splane.xy /= splane.z;
- splane.xy = splane.xy * 0.5 + 0.5;
- splane.z = shadow_len / light_range;
+ splane = normalize(splane);
- splane.xy = clamp_rect.xy + splane.xy * clamp_rect.zw;
+ vec4 clamp_rect = light_clamp;
- float shadow = sample_shadow(light_shadow_atlas, vec2(0.0), splane.xy, splane.z, clamp_rect);
+ if (splane.z >= 0.0) {
+ splane.z += 1.0;
- if (shadow > splane.z) {
- } else {
- attenuation = vec3(0.0);
- }
+ clamp_rect.y += clamp_rect.w;
+ } else {
+ splane.z = 1.0 - splane.z;
}
- light_compute(
- normal,
- normalize(light_vec),
- eye_position,
- binormal,
- tangent,
- light_color.xyz * light_energy,
- attenuation,
- albedo,
- transmission,
- specular * light_specular,
- roughness,
- metallic,
- rim,
- rim_tint,
- clearcoat,
- clearcoat_gloss,
- anisotropy,
- diffuse_light,
- specular_light);
-
- } else if (light_type == LIGHT_TYPE_DIRECTIONAL) {
-
- vec3 light_vec = -light_direction;
- vec3 attenuation = vec3(1.0, 1.0, 1.0);
-
- float depth_z = -vertex.z;
-
- if (light_has_shadow > 0.5) {
+ splane.xy /= splane.z;
+ splane.xy = splane.xy * 0.5 + 0.5;
+ splane.z = shadow_len / light_range;
+
+ splane.xy = clamp_rect.xy + splane.xy * clamp_rect.zw;
+
+ float shadow = sample_shadow(light_shadow_atlas, splane.xy, splane.z);
+
+ light_att *= shadow;
+ }
+#endif
+
+#endif //type omni
+#ifdef LIGHT_MODE_DIRECTIONAL
+
+#ifndef USE_VERTEX_LIGHTING
+ vec3 light_vec = -light_direction;
+ L = normalize(light_vec);
+#endif
+ float depth_z = -vertex.z;
+
+#ifdef USE_SHADOW
+ {
#ifdef LIGHT_USE_PSSM4
- if (depth_z < light_split_offsets.w) {
+ if (depth_z < light_split_offsets.w) {
#elif defined(LIGHT_USE_PSSM2)
- if (depth_z < light_split_offsets.y) {
+ if (depth_z < light_split_offsets.y) {
#else
- if (depth_z < light_split_offsets.x) {
-#endif
+ if (depth_z < light_split_offsets.x) {
+#endif //pssm2
- vec3 pssm_coord;
- float pssm_fade = 0.0;
+ vec3 pssm_coord;
+ float pssm_fade = 0.0;
#ifdef LIGHT_USE_PSSM_BLEND
- float pssm_blend;
- vec3 pssm_coord2;
- bool use_blend = true;
+ float pssm_blend;
+ vec3 pssm_coord2;
+ bool use_blend = true;
#endif
#ifdef LIGHT_USE_PSSM4
- if (depth_z < light_split_offsets.y) {
- if (depth_z < light_split_offsets.x) {
- highp vec4 splane = (light_shadow_matrix1 * vec4(vertex, 1.0));
- pssm_coord = splane.xyz / splane.w;
+ if (depth_z < light_split_offsets.y) {
+ if (depth_z < light_split_offsets.x) {
+ highp vec4 splane = shadow_coord;
+ pssm_coord = splane.xyz / splane.w;
#ifdef LIGHT_USE_PSSM_BLEND
- splane = (light_shadow_matrix2 * vec4(vertex, 1.0));
- pssm_coord2 = splane.xyz / splane.w;
+ splane = shadow_coord2;
+ pssm_coord2 = splane.xyz / splane.w;
- pssm_blend = smoothstep(0.0, light_split_offsets.x, depth_z);
+ pssm_blend = smoothstep(0.0, light_split_offsets.x, depth_z);
#endif
- } else {
- highp vec4 splane = (light_shadow_matrix2 * vec4(vertex, 1.0));
- pssm_coord = splane.xyz / splane.w;
+ } else {
+ highp vec4 splane = shadow_coord2;
+ pssm_coord = splane.xyz / splane.w;
#ifdef LIGHT_USE_PSSM_BLEND
- splane = (light_shadow_matrix3 * vec4(vertex, 1.0));
- pssm_coord2 = splane.xyz / splane.w;
+ splane = shadow_coord3;
+ pssm_coord2 = splane.xyz / splane.w;
- pssm_blend = smoothstep(light_split_offsets.x, light_split_offsets.y, depth_z);
+ pssm_blend = smoothstep(light_split_offsets.x, light_split_offsets.y, depth_z);
#endif
- }
- } else {
- if (depth_z < light_split_offsets.z) {
+ }
+ } else {
+ if (depth_z < light_split_offsets.z) {
- highp vec4 splane = (light_shadow_matrix3 * vec4(vertex, 1.0));
- pssm_coord = splane.xyz / splane.w;
+ highp vec4 splane = shadow_coord3;
+ pssm_coord = splane.xyz / splane.w;
#if defined(LIGHT_USE_PSSM_BLEND)
- splane = (light_shadow_matrix4 * vec4(vertex, 1.0));
- pssm_coord2 = splane.xyz / splane.w;
- pssm_blend = smoothstep(light_split_offsets.y, light_split_offsets.z, depth_z);
+ splane = shadow_coord4;
+ pssm_coord2 = splane.xyz / splane.w;
+ pssm_blend = smoothstep(light_split_offsets.y, light_split_offsets.z, depth_z);
#endif
- } else {
+ } else {
- highp vec4 splane = (light_shadow_matrix4 * vec4(vertex, 1.0));
- pssm_coord = splane.xyz / splane.w;
- pssm_fade = smoothstep(light_split_offsets.z, light_split_offsets.w, depth_z);
+ highp vec4 splane = shadow_coord4;
+ pssm_coord = splane.xyz / splane.w;
+ pssm_fade = smoothstep(light_split_offsets.z, light_split_offsets.w, depth_z);
#if defined(LIGHT_USE_PSSM_BLEND)
- use_blend = false;
+ use_blend = false;
#endif
- }
}
+ }
#endif // LIGHT_USE_PSSM4
#ifdef LIGHT_USE_PSSM2
- if (depth_z < light_split_offsets.x) {
+ if (depth_z < light_split_offsets.x) {
- highp vec4 splane = (light_shadow_matrix1 * vec4(vertex, 1.0));
- pssm_coord = splane.xyz / splane.w;
+ highp vec4 splane = shadow_coord;
+ pssm_coord = splane.xyz / splane.w;
#ifdef LIGHT_USE_PSSM_BLEND
- splane = (light_shadow_matrix2 * vec4(vertex, 1.0));
- pssm_coord2 = splane.xyz / splane.w;
- pssm_blend = smoothstep(0.0, light_split_offsets.x, depth_z);
+ splane = shadow_coord2;
+ pssm_coord2 = splane.xyz / splane.w;
+ pssm_blend = smoothstep(0.0, light_split_offsets.x, depth_z);
#endif
- } else {
- highp vec4 splane = (light_shadow_matrix2 * vec4(vertex, 1.0));
- pssm_coord = splane.xyz / splane.w;
- pssm_fade = smoothstep(light_split_offsets.x, light_split_offsets.y, depth_z);
+ } else {
+ highp vec4 splane = shadow_coord2;
+ pssm_coord = splane.xyz / splane.w;
+ pssm_fade = smoothstep(light_split_offsets.x, light_split_offsets.y, depth_z);
#ifdef LIGHT_USE_PSSM_BLEND
- use_blend = false;
+ use_blend = false;
#endif
- }
+ }
#endif // LIGHT_USE_PSSM2
#if !defined(LIGHT_USE_PSSM4) && !defined(LIGHT_USE_PSSM2)
- {
- highp vec4 splane = (light_shadow_matrix1 * vec4(vertex, 1.0));
- pssm_coord = splane.xyz / splane.w;
- }
+ {
+ highp vec4 splane = shadow_coord;
+ pssm_coord = splane.xyz / splane.w;
+ }
#endif
- float shadow = sample_shadow(light_shadow_atlas, vec2(0.0), pssm_coord.xy, pssm_coord.z, light_clamp);
+ float shadow = sample_shadow(light_directional_shadow, pssm_coord.xy, pssm_coord.z);
#ifdef LIGHT_USE_PSSM_BLEND
- if (use_blend) {
- shadow = mix(shadow, sample_shadow(light_shadow_atlas, vec2(0.0), pssm_coord2.xy, pssm_coord2.z, light_clamp), pssm_blend);
- }
+ if (use_blend) {
+ shadow = mix(shadow, sample_shadow(light_directional_shadow, pssm_coord2.xy, pssm_coord2.z), pssm_blend);
+ }
#endif
- attenuation *= shadow;
- }
+ light_att *= shadow;
}
+ }
+#endif //use shadow
- light_compute(normal,
- normalize(light_vec),
- eye_position,
- binormal,
- tangent,
- light_color.xyz * light_energy,
- attenuation,
- albedo,
- transmission,
- specular * light_specular,
- roughness,
- metallic,
- rim,
- rim_tint,
- clearcoat,
- clearcoat_gloss,
- anisotropy,
- diffuse_light,
- specular_light);
- } else if (light_type == LIGHT_TYPE_SPOT) {
-
- vec3 light_att = vec3(1.0);
-
- if (light_has_shadow > 0.5) {
- highp vec4 splane = (light_shadow_matrix * vec4(vertex, 1.0));
- splane.xyz /= splane.w;
-
- float shadow = sample_shadow(light_shadow_atlas, vec2(0.0), splane.xy, splane.z, light_clamp);
-
- if (shadow > splane.z) {
- } else {
- light_att = vec3(0.0);
- }
- }
+#endif
- vec3 light_rel_vec = light_position - vertex;
- float light_length = length(light_rel_vec);
- float normalized_distance = light_length / light_range;
-
- float spot_attenuation = pow(1.0 - normalized_distance, light_attenuation.w);
- vec3 spot_dir = light_direction;
-
- float spot_cutoff = light_spot_angle;
-
- float scos = max(dot(-normalize(light_rel_vec), spot_dir), spot_cutoff);
- float spot_rim = max(0.0001, (1.0 - scos) / (1.0 - spot_cutoff));
-
- spot_attenuation *= 1.0 - pow(spot_rim, light_spot_attenuation);
-
- light_att *= vec3(spot_attenuation);
-
- light_compute(
- normal,
- normalize(light_rel_vec),
- eye_position,
- binormal,
- tangent,
- light_color.xyz * light_energy,
- light_att,
- albedo,
- transmission,
- specular * light_specular,
- roughness,
- metallic,
- rim,
- rim_tint,
- clearcoat,
- clearcoat_gloss,
- anisotropy,
- diffuse_light,
- specular_light);
- }
+#ifdef LIGHT_MODE_SPOT
- gl_FragColor = vec4(ambient_light + diffuse_light + specular_light, alpha);
-#else
+ light_att = vec3(1.0);
-#ifdef RENDER_DEPTH
+#ifndef USE_VERTEX_LIGHTING
-#else
+ vec3 light_rel_vec = light_position - vertex;
+ float light_length = length(light_rel_vec);
+ float normalized_distance = light_length / light_range;
-#ifdef USE_RADIANCE_MAP
+ float spot_attenuation = pow(1.0 - normalized_distance, light_attenuation.w);
+ vec3 spot_dir = light_direction;
- vec3 ref_vec = reflect(-eye_position, N);
- ref_vec = normalize((radiance_inverse_xform * vec4(ref_vec, 0.0)).xyz);
+ float spot_cutoff = light_spot_angle;
- ref_vec.z *= -1.0;
+ float scos = max(dot(-normalize(light_rel_vec), spot_dir), spot_cutoff);
+ float spot_rim = max(0.0001, (1.0 - scos) / (1.0 - spot_cutoff));
+
+ spot_attenuation *= 1.0 - pow(spot_rim, light_spot_attenuation);
- env_reflection_light = textureCubeLod(radiance_map, ref_vec, roughness * RADIANCE_MAX_LOD).xyz * bg_energy;
+ light_att = vec3(spot_attenuation);
+
+ L = normalize(light_rel_vec);
+
+#endif
+#ifdef USE_SHADOW
{
- vec3 ambient_dir = normalize((radiance_inverse_xform * vec4(normal, 0.0)).xyz);
- vec3 env_ambient = textureCubeLod(radiance_map, ambient_dir, RADIANCE_MAX_LOD).xyz * bg_energy;
+ highp vec4 splane = shadow_coord;
+ splane.xyz /= splane.w;
- ambient_light = mix(ambient_color.rgb, env_ambient, ambient_sky_contribution);
+ float shadow = sample_shadow(light_shadow_atlas, splane.xy, splane.z);
+ light_att *= shadow;
}
+#endif
- ambient_light *= ambient_energy;
+#endif
+
+#ifdef USE_VERTEX_LIGHTING
+ //vertex lighting
+
+ specular_light += specular_interp * specular * light_att;
+ diffuse_light += diffuse_interp * albedo * light_att;
+
+#else
+ //fragment lighting
+ light_compute(
+ normal,
+ L,
+ eye_position,
+ binormal,
+ tangent,
+ light_color.xyz,
+ light_att,
+ albedo,
+ transmission,
+ specular * light_specular,
+ roughness,
+ metallic,
+ rim,
+ rim_tint,
+ clearcoat,
+ clearcoat_gloss,
+ anisotropy,
+ diffuse_light,
+ specular_light);
+
+#endif //vertex lighting
+
+#endif //USE_LIGHTING
+ //compute and merge
+
+#ifndef RENDER_DEPTH
+
+#ifdef SHADELESS
- specular_light += env_reflection_light;
+ gl_FragColor = vec4(albedo, alpha);
+#else
ambient_light *= albedo;
@@ -865,10 +1410,7 @@ FRAGMENT_SHADER_CODE
gl_FragColor = vec4(ambient_light + diffuse_light + specular_light, alpha);
// gl_FragColor = vec4(normal, 1.0);
-#else
- gl_FragColor = vec4(albedo, alpha);
-#endif
-#endif // RENDER_DEPTH
+#endif //unshaded
-#endif // lighting
+#endif // not RENDER_DEPTH
}
diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp
index 1e43651d54..086829f9ba 100644
--- a/drivers/gles3/rasterizer_scene_gles3.cpp
+++ b/drivers/gles3/rasterizer_scene_gles3.cpp
@@ -1557,8 +1557,11 @@ void RasterizerSceneGLES3::_render_geometry(RenderList::Element *e) {
RasterizerStorageGLES3::MultiMesh *multi_mesh = static_cast<RasterizerStorageGLES3::MultiMesh *>(e->owner);
RasterizerStorageGLES3::Surface *s = static_cast<RasterizerStorageGLES3::Surface *>(e->geometry);
- int amount = MAX(multi_mesh->size, multi_mesh->visible_instances);
+ int amount = MIN(multi_mesh->size, multi_mesh->visible_instances);
+ if (amount == -1) {
+ amount = multi_mesh->size;
+ }
#ifdef DEBUG_ENABLED
if (state.debug_draw == VS::VIEWPORT_DEBUG_DRAW_WIREFRAME && s->array_wireframe_id) {
@@ -2364,14 +2367,15 @@ void RasterizerSceneGLES3::_add_geometry_with_material(RasterizerStorageGLES3::G
e->sort_key |= uint64_t(e->geometry->index) << RenderList::SORT_KEY_GEOMETRY_INDEX_SHIFT;
e->sort_key |= uint64_t(e->instance->base_type) << RenderList::SORT_KEY_GEOMETRY_TYPE_SHIFT;
- if (!p_depth_pass) {
+ if (e->material->last_pass != render_pass) {
+ e->material->last_pass = render_pass;
+ e->material->index = current_material_index++;
+ }
- if (e->material->last_pass != render_pass) {
- e->material->last_pass = render_pass;
- e->material->index = current_material_index++;
- }
+ e->sort_key |= uint64_t(e->material->index) << RenderList::SORT_KEY_MATERIAL_INDEX_SHIFT;
+ e->sort_key |= uint64_t(e->instance->depth_layer) << RenderList::SORT_KEY_OPAQUE_DEPTH_LAYER_SHIFT;
- e->sort_key |= uint64_t(e->material->index) << RenderList::SORT_KEY_MATERIAL_INDEX_SHIFT;
+ if (!p_depth_pass) {
if (e->instance->gi_probe_instances.size()) {
e->sort_key |= SORT_KEY_GI_PROBES_FLAG;
@@ -2386,9 +2390,6 @@ void RasterizerSceneGLES3::_add_geometry_with_material(RasterizerStorageGLES3::G
}
e->sort_key |= uint64_t(p_material->render_priority + 128) << RenderList::SORT_KEY_PRIORITY_SHIFT;
- } else {
- e->sort_key |= uint64_t(e->instance->depth_layer) << RenderList::SORT_KEY_OPAQUE_DEPTH_LAYER_SHIFT;
- e->sort_key |= uint64_t(e->material->index) << RenderList::SORT_KEY_MATERIAL_INDEX_SHIFT;
}
/*
@@ -2738,7 +2739,7 @@ void RasterizerSceneGLES3::_setup_directional_light(int p_index, const Transform
ubo_data.shadow_split_offsets[j] = li->shadow_transform[j].split;
- Transform modelview = (p_camera_inverse_transform * li->shadow_transform[j].transform).inverse();
+ Transform modelview = (p_camera_inverse_transform * li->shadow_transform[j].transform).affine_inverse();
CameraMatrix bias;
bias.set_light_bias();
@@ -3131,7 +3132,6 @@ void RasterizerSceneGLES3::_fill_render_list(InstanceBase **p_cull_result, int p
current_material_index = 0;
state.used_sss = false;
state.used_screen_texture = false;
-
//fill list
for (int i = 0; i < p_cull_count; i++) {
@@ -5147,13 +5147,13 @@ void RasterizerSceneGLES3::initialize() {
void RasterizerSceneGLES3::iteration() {
- shadow_filter_mode = ShadowFilterMode(int(ProjectSettings::get_singleton()->get("rendering/quality/shadows/filter_mode")));
- subsurface_scatter_follow_surface = ProjectSettings::get_singleton()->get("rendering/quality/subsurface_scattering/follow_surface");
- subsurface_scatter_weight_samples = ProjectSettings::get_singleton()->get("rendering/quality/subsurface_scattering/weight_samples");
- subsurface_scatter_quality = SubSurfaceScatterQuality(int(ProjectSettings::get_singleton()->get("rendering/quality/subsurface_scattering/quality")));
- subsurface_scatter_size = ProjectSettings::get_singleton()->get("rendering/quality/subsurface_scattering/scale");
+ shadow_filter_mode = ShadowFilterMode(int(GLOBAL_GET("rendering/quality/shadows/filter_mode")));
+ subsurface_scatter_follow_surface = GLOBAL_GET("rendering/quality/subsurface_scattering/follow_surface");
+ subsurface_scatter_weight_samples = GLOBAL_GET("rendering/quality/subsurface_scattering/weight_samples");
+ subsurface_scatter_quality = SubSurfaceScatterQuality(int(GLOBAL_GET("rendering/quality/subsurface_scattering/quality")));
+ subsurface_scatter_size = GLOBAL_GET("rendering/quality/subsurface_scattering/scale");
- state.scene_shader.set_conditional(SceneShaderGLES3::VCT_QUALITY_HIGH, ProjectSettings::get_singleton()->get("rendering/quality/voxel_cone_tracing/high_quality"));
+ state.scene_shader.set_conditional(SceneShaderGLES3::VCT_QUALITY_HIGH, GLOBAL_GET("rendering/quality/voxel_cone_tracing/high_quality"));
}
void RasterizerSceneGLES3::finalize() {
diff --git a/drivers/gles3/shader_compiler_gles3.cpp b/drivers/gles3/shader_compiler_gles3.cpp
index 11c84e7db8..350107de69 100644
--- a/drivers/gles3/shader_compiler_gles3.cpp
+++ b/drivers/gles3/shader_compiler_gles3.cpp
@@ -31,6 +31,7 @@
#include "shader_compiler_gles3.h"
#include "core/os/os.h"
+#include "core/project_settings.h"
#define SL ShaderLanguage
@@ -860,6 +861,7 @@ ShaderCompilerGLES3::ShaderCompilerGLES3() {
actions[VS::SHADER_SPATIAL].renames["SCREEN_TEXTURE"] = "screen_texture";
actions[VS::SHADER_SPATIAL].renames["DEPTH_TEXTURE"] = "depth_buffer";
actions[VS::SHADER_SPATIAL].renames["ALPHA_SCISSOR"] = "alpha_scissor";
+ actions[VS::SHADER_SPATIAL].renames["OUTPUT_IS_SRGB"] = "SHADER_IS_SRGB";
//for light
actions[VS::SHADER_SPATIAL].renames["VIEW"] = "view";
@@ -901,12 +903,24 @@ ShaderCompilerGLES3::ShaderCompilerGLES3() {
actions[VS::SHADER_SPATIAL].render_mode_defines["cull_front"] = "#define DO_SIDE_CHECK\n";
actions[VS::SHADER_SPATIAL].render_mode_defines["cull_disabled"] = "#define DO_SIDE_CHECK\n";
- actions[VS::SHADER_SPATIAL].render_mode_defines["diffuse_burley"] = "#define DIFFUSE_BURLEY\n";
+ bool force_lambert = GLOBAL_GET("rendering/quality/shading/force_lambert_over_burley");
+
+ if (!force_lambert) {
+ actions[VS::SHADER_SPATIAL].render_mode_defines["diffuse_burley"] = "#define DIFFUSE_BURLEY\n";
+ }
+
actions[VS::SHADER_SPATIAL].render_mode_defines["diffuse_oren_nayar"] = "#define DIFFUSE_OREN_NAYAR\n";
actions[VS::SHADER_SPATIAL].render_mode_defines["diffuse_lambert_wrap"] = "#define DIFFUSE_LAMBERT_WRAP\n";
actions[VS::SHADER_SPATIAL].render_mode_defines["diffuse_toon"] = "#define DIFFUSE_TOON\n";
- actions[VS::SHADER_SPATIAL].render_mode_defines["specular_schlick_ggx"] = "#define SPECULAR_SCHLICK_GGX\n";
+ bool force_blinn = GLOBAL_GET("rendering/quality/shading/force_blinn_over_ggx");
+
+ if (!force_blinn) {
+ actions[VS::SHADER_SPATIAL].render_mode_defines["specular_schlick_ggx"] = "#define SPECULAR_SCHLICK_GGX\n";
+ } else {
+ actions[VS::SHADER_SPATIAL].render_mode_defines["specular_schlick_ggx"] = "#define SPECULAR_BLINN\n";
+ }
+
actions[VS::SHADER_SPATIAL].render_mode_defines["specular_blinn"] = "#define SPECULAR_BLINN\n";
actions[VS::SHADER_SPATIAL].render_mode_defines["specular_phong"] = "#define SPECULAR_PHONG\n";
actions[VS::SHADER_SPATIAL].render_mode_defines["specular_toon"] = "#define SPECULAR_TOON\n";
diff --git a/drivers/gles3/shader_gles3.cpp b/drivers/gles3/shader_gles3.cpp
index 2a3b8a9b91..799179e8d4 100644
--- a/drivers/gles3/shader_gles3.cpp
+++ b/drivers/gles3/shader_gles3.cpp
@@ -122,6 +122,11 @@ bool ShaderGLES3::bind() {
ERR_FAIL_COND_V(!version, false);
+ if (!version->ok) { //broken, unable to bind (do not throw error, you saw it before already when it failed compilation).
+ glUseProgram(0);
+ return false;
+ }
+
glUseProgram(version->id);
DEBUG_TEST_ERROR("Use Program");
diff --git a/drivers/gles3/shader_gles3.h b/drivers/gles3/shader_gles3.h
index ca74317218..9db4942163 100644
--- a/drivers/gles3/shader_gles3.h
+++ b/drivers/gles3/shader_gles3.h
@@ -336,6 +336,7 @@ public:
}
uint32_t get_version() const { return new_conditional_version.version; }
+ _FORCE_INLINE_ bool is_version_valid() const { return version && version->ok; }
void set_uniform_camera(int p_idx, const CameraMatrix &p_mat) {
diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl
index 12cbe02d0c..7da20dfa00 100644
--- a/drivers/gles3/shaders/scene.glsl
+++ b/drivers/gles3/shaders/scene.glsl
@@ -3,6 +3,8 @@
#define M_PI 3.14159265359
+#define SHADER_IS_SRGB false
+
/*
from VisualServer:
@@ -514,6 +516,7 @@ VERTEX_SHADER_CODE
/* clang-format off */
[fragment]
+
/* texture unit usage, N is max_texture_unity-N
1-skeleton
@@ -533,6 +536,7 @@ uniform highp mat4 world_transform;
/* clang-format on */
#define M_PI 3.14159265359
+#define SHADER_IS_SRGB false
/* Varyings */
@@ -1020,16 +1024,27 @@ LIGHT_SHADER_CODE
#if defined(SPECULAR_BLINN)
+ //normalized blinn
vec3 H = normalize(V + L);
float cNdotH = max(dot(N, H), 0.0);
- float intensity = pow(cNdotH, (1.0 - roughness) * 256.0);
+ float cVdotH = max(dot(V, H), 0.0);
+ float cLdotH = max(dot(L, H), 0.0);
+ float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25;
+ float blinn = pow(cNdotH, shininess);
+ blinn *= (shininess + 8.0) / (8.0 * 3.141592654);
+ float intensity = (blinn) / max(4.0 * cNdotV * cNdotL, 0.75);
+
specular_light += light_color * intensity * specular_blob_intensity * attenuation;
#elif defined(SPECULAR_PHONG)
vec3 R = normalize(-reflect(L, N));
float cRdotV = max(0.0, dot(R, V));
- float intensity = pow(cRdotV, (1.0 - roughness) * 256.0);
+ float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25;
+ float phong = pow(cRdotV, shininess);
+ phong *= (shininess + 8.0) / (8.0 * 3.141592654);
+ float intensity = (phong) / max(4.0 * cNdotV * cNdotL, 0.75);
+
specular_light += light_color * intensity * specular_blob_intensity * attenuation;
#elif defined(SPECULAR_TOON)
@@ -1070,11 +1085,11 @@ LIGHT_SHADER_CODE
float G = G_GGX_2cos(cNdotL, alpha) * G_GGX_2cos(cNdotV, alpha);
#endif
// F
- float F0 = 1.0; // FIXME
- float cLdotH5 = SchlickFresnel(cLdotH);
- float F = mix(cLdotH5, 1.0, F0);
+ //float F0 = 1.0;
+ //float cLdotH5 = SchlickFresnel(cLdotH);
+ //float F = mix(cLdotH5, 1.0, F0);
- float specular_brdf_NL = cNdotL * D * F * G;
+ float specular_brdf_NL = cNdotL * D /* F */ * G;
specular_light += specular_brdf_NL * light_color * specular_blob_intensity * attenuation;
#endif
diff --git a/drivers/unix/net_socket_posix.cpp b/drivers/unix/net_socket_posix.cpp
index 9dcc6038ab..6e0bf97711 100644
--- a/drivers/unix/net_socket_posix.cpp
+++ b/drivers/unix/net_socket_posix.cpp
@@ -68,25 +68,29 @@
#define SOCK_BUF(x) x
#define SOCK_CBUF(x) x
#define SOCK_IOCTL ioctl
-#define SOCK_POLL ::poll
#define SOCK_CLOSE ::close
/* Windows */
#elif defined(WINDOWS_ENABLED)
#include <winsock2.h>
#include <ws2tcpip.h>
+
+#include <mswsock.h>
// Some custom defines to minimize ifdefs
#define SOCK_EMPTY INVALID_SOCKET
#define SOCK_BUF(x) (char *)(x)
#define SOCK_CBUF(x) (const char *)(x)
#define SOCK_IOCTL ioctlsocket
-#define SOCK_POLL WSAPoll
#define SOCK_CLOSE closesocket
// Windows doesn't have this flag
#ifndef MSG_NOSIGNAL
#define MSG_NOSIGNAL 0
#endif
+// Workaround missing flag in MinGW
+#if defined(__MINGW32__) && !defined(SIO_UDP_NETRESET)
+#define SIO_UDP_NETRESET _WSAIOW(IOC_VENDOR, 15)
+#endif
#endif
@@ -260,6 +264,21 @@ Error NetSocketPosix::open(Type p_sock_type, IP::Type &ip_type) {
}
_is_stream = p_sock_type == TYPE_TCP;
+
+#if defined(WINDOWS_ENABLED)
+ if (!_is_stream) {
+ // Disable windows feature/bug reporting WSAECONNRESET/WSAENETRESET when
+ // recv/recvfrom and an ICMP reply was received from a previous send/sendto.
+ unsigned long disable = 0;
+ if (ioctlsocket(_sock, SIO_UDP_CONNRESET, &disable) == SOCKET_ERROR) {
+ print_verbose("Unable to turn off UDP WSAECONNRESET behaviour on Windows");
+ }
+ if (ioctlsocket(_sock, SIO_UDP_NETRESET, &disable) == SOCKET_ERROR) {
+ // This feature seems not to be supported on wine.
+ print_verbose("Unable to turn off UDP WSAENETRESET behaviour on Windows");
+ }
+ }
+#endif
return OK;
}
@@ -331,10 +350,58 @@ Error NetSocketPosix::connect_to_host(IP_Address p_host, uint16_t p_port) {
return OK;
}
-Error NetSocketPosix::poll(PollType p_type, int timeout) const {
+Error NetSocketPosix::poll(PollType p_type, int p_timeout) const {
ERR_FAIL_COND_V(!is_open(), ERR_UNCONFIGURED);
+#if defined(WINDOWS_ENABLED)
+ bool ready = false;
+ fd_set rd, wr, ex;
+ fd_set *rdp = NULL;
+ fd_set *wrp = NULL;
+ FD_ZERO(&rd);
+ FD_ZERO(&wr);
+ FD_ZERO(&ex);
+ FD_SET(_sock, &ex);
+ struct timeval timeout = { p_timeout, 0 };
+ // For blocking operation, pass NULL timeout pointer to select.
+ struct timeval *tp = NULL;
+ if (p_timeout >= 0) {
+ // If timeout is non-negative, we want to specify the timeout instead.
+ tp = &timeout;
+ }
+
+ switch (p_type) {
+ case POLL_TYPE_IN:
+ FD_SET(_sock, &rd);
+ rdp = &rd;
+ break;
+ case POLL_TYPE_OUT:
+ FD_SET(_sock, &wr);
+ wrp = &wr;
+ break;
+ case POLL_TYPE_IN_OUT:
+ FD_SET(_sock, &rd);
+ FD_SET(_sock, &wr);
+ rdp = &rd;
+ wrp = &wr;
+ }
+ int ret = select(1, rdp, wrp, &ex, tp);
+
+ ERR_FAIL_COND_V(ret == SOCKET_ERROR, FAILED);
+
+ if (ret == 0)
+ return ERR_BUSY;
+
+ ERR_FAIL_COND_V(FD_ISSET(_sock, &ex), FAILED);
+
+ if (rdp && FD_ISSET(_sock, rdp))
+ ready = true;
+ if (wrp && FD_ISSET(_sock, wrp))
+ ready = true;
+
+ return ready ? OK : ERR_BUSY;
+#else
struct pollfd pfd;
pfd.fd = _sock;
pfd.events = POLLIN;
@@ -351,14 +418,16 @@ Error NetSocketPosix::poll(PollType p_type, int timeout) const {
pfd.events = POLLOUT || POLLIN;
}
- int ret = SOCK_POLL(&pfd, 1, timeout);
+ int ret = ::poll(&pfd, 1, p_timeout);
ERR_FAIL_COND_V(ret < 0, FAILED);
+ ERR_FAIL_COND_V(pfd.revents & POLLERR, FAILED);
if (ret == 0)
return ERR_BUSY;
return OK;
+#endif
}
Error NetSocketPosix::recv(uint8_t *p_buffer, int p_len, int &r_read) {
diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp
index ac28fb9b99..6c68648bc0 100644
--- a/editor/animation_track_editor.cpp
+++ b/editor/animation_track_editor.cpp
@@ -4923,8 +4923,8 @@ AnimationTrackEditor::AnimationTrackEditor() {
//this shortcut will be checked from the track itself. so no need to enable it here (will conflict with scenetree dock)
edit->get_popup()->add_separator();
- edit->get_popup()->add_shortcut(ED_SHORTCUT("animation_editor/goto_next_step", TTR("Goto Next Step"), KEY_MASK_CMD | KEY_RIGHT), EDIT_GOTO_NEXT_STEP);
- edit->get_popup()->add_shortcut(ED_SHORTCUT("animation_editor/goto_prev_step", TTR("Goto Prev Step"), KEY_MASK_CMD | KEY_LEFT), EDIT_GOTO_PREV_STEP);
+ edit->get_popup()->add_shortcut(ED_SHORTCUT("animation_editor/goto_next_step", TTR("Go to Next Step"), KEY_MASK_CMD | KEY_RIGHT), EDIT_GOTO_NEXT_STEP);
+ edit->get_popup()->add_shortcut(ED_SHORTCUT("animation_editor/goto_prev_step", TTR("Go to Previous Step"), KEY_MASK_CMD | KEY_LEFT), EDIT_GOTO_PREV_STEP);
edit->get_popup()->add_separator();
edit->get_popup()->add_item(TTR("Optimize Animation"), EDIT_OPTIMIZE_ANIMATION);
edit->get_popup()->add_item(TTR("Clean-Up Animation"), EDIT_CLEAN_UP_ANIMATION);
diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp
index f11a30bb86..08fd8a1319 100644
--- a/editor/editor_file_dialog.cpp
+++ b/editor/editor_file_dialog.cpp
@@ -198,8 +198,18 @@ void EditorFileDialog::update_dir() {
dir->set_text(dir_access->get_current_dir());
- // Disable "Open" button only when we in selecting file(s) mode or open dir mode.
+ // Disable "Open" button only when selecting file(s) mode.
get_ok()->set_disabled(_is_open_should_be_disabled());
+ switch (mode) {
+
+ case MODE_OPEN_FILE:
+ case MODE_OPEN_FILES:
+ get_ok()->set_text(TTR("Open"));
+ break;
+ case MODE_OPEN_DIR:
+ get_ok()->set_text(TTR("Select Current Folder"));
+ break;
+ }
}
void EditorFileDialog::_dir_entered(String p_dir) {
@@ -453,6 +463,8 @@ void EditorFileDialog::_item_selected(int p_item) {
file->set_text(d["name"]);
_request_single_thumbnail(get_current_dir().plus_file(get_current_file()));
+ } else if (mode == MODE_OPEN_DIR) {
+ get_ok()->set_text(TTR("Select This Folder"));
}
get_ok()->set_disabled(_is_open_should_be_disabled());
@@ -637,7 +649,7 @@ bool EditorFileDialog::_is_open_should_be_disabled() {
Vector<int> items = item_list->get_selected_items();
if (items.size() == 0)
- return true;
+ return mode != MODE_OPEN_DIR; // In "Open folder" mode, having nothing selected picks the current folder.
for (int i = 0; i < items.size(); i++) {
diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp
index 3f49edf88d..2dec21fffb 100644
--- a/editor/editor_settings.cpp
+++ b/editor/editor_settings.cpp
@@ -485,6 +485,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
_initial_set("editors/2d/bone_outline_color", Color(0.35, 0.35, 0.35));
_initial_set("editors/2d/bone_outline_size", 2);
_initial_set("editors/2d/keep_margins_when_changing_anchors", false);
+ _initial_set("editors/2d/viewport_border_color", Color(0.4, 0.4, 1.0, 0.4));
_initial_set("editors/2d/warped_mouse_panning", true);
_initial_set("editors/2d/simple_spacebar_panning", false);
_initial_set("editors/2d/scroll_to_pan", false);
@@ -1216,18 +1217,25 @@ bool EditorSettings::is_dark_theme() {
void EditorSettings::list_text_editor_themes() {
String themes = "Adaptive,Default,Custom";
+
DirAccess *d = DirAccess::open(get_text_editor_themes_dir());
if (d) {
+ List<String> custom_themes;
d->list_dir_begin();
String file = d->get_next();
while (file != String()) {
if (file.get_extension() == "tet" && file.get_basename().to_lower() != "default" && file.get_basename().to_lower() != "adaptive" && file.get_basename().to_lower() != "custom") {
- themes += "," + file.get_basename();
+ custom_themes.push_back(file.get_basename());
}
file = d->get_next();
}
d->list_dir_end();
memdelete(d);
+
+ custom_themes.sort();
+ for (List<String>::Element *E = custom_themes.front(); E; E = E->next()) {
+ themes += "," + E->get();
+ }
}
add_property_hint(PropertyInfo(Variant::STRING, "text_editor/theme/color_theme", PROPERTY_HINT_ENUM, themes));
}
diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp
index 7ed7b920d9..6dfd5ef573 100644
--- a/editor/editor_themes.cpp
+++ b/editor/editor_themes.cpp
@@ -945,6 +945,11 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
// TooltipPanel
Ref<StyleBoxFlat> style_tooltip = style_popup->duplicate();
+ float v = MAX(border_size * EDSCALE, 1.0);
+ style_tooltip->set_default_margin(MARGIN_LEFT, v);
+ style_tooltip->set_default_margin(MARGIN_TOP, v);
+ style_tooltip->set_default_margin(MARGIN_RIGHT, v);
+ style_tooltip->set_default_margin(MARGIN_BOTTOM, v);
style_tooltip->set_bg_color(Color(mono_color.r, mono_color.g, mono_color.b, 0.9));
style_tooltip->set_border_width_all(border_width);
style_tooltip->set_border_color_all(mono_color);
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp
index 46f89439c0..607ced4573 100644
--- a/editor/filesystem_dock.cpp
+++ b/editor/filesystem_dock.cpp
@@ -395,6 +395,9 @@ void FileSystemDock::_notification(int p_what) {
}
void FileSystemDock::_tree_multi_selected(Object *p_item, int p_column, bool p_selected) {
+ // Update the import dock
+ import_dock_needs_update = true;
+ call_deferred("_update_import_dock");
// Return if we don't select something new
if (!p_selected)
@@ -1535,7 +1538,7 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> p_selected)
if (!fpath.ends_with("/")) {
fpath = fpath.get_base_dir();
}
- make_script_dialog_text->config("Node", fpath + "new_script.gd");
+ make_script_dialog_text->config("Node", fpath + "new_script.gd", false);
make_script_dialog_text->popup_centered(Size2(300, 300) * EDSCALE);
} break;
@@ -2122,15 +2125,33 @@ void FileSystemDock::_update_import_dock() {
if (!import_dock_needs_update)
return;
- //check import
+ // List selected
+ Vector<String> selected;
+ if (display_mode_setting == DISPLAY_MODE_SETTING_TREE_ONLY) {
+ // Use the tree
+ selected = _tree_get_selected();
+
+ } else {
+ // Use the file list
+ for (int i = 0; i < files->get_item_count(); i++) {
+ if (!files->is_selected(i))
+ continue;
+
+ selected.push_back(files->get_item_metadata(i));
+ }
+ }
+
+ // Check import
Vector<String> imports;
String import_type;
+ for (int i = 0; i < selected.size(); i++) {
+ String fpath = selected[i];
- for (int i = 0; i < files->get_item_count(); i++) {
- if (!files->is_selected(i))
- continue;
+ if (fpath.ends_with("/")) {
+ imports.clear();
+ break;
+ }
- String fpath = files->get_item_metadata(i);
if (!FileAccess::exists(fpath + ".import")) {
imports.clear();
break;
@@ -2317,7 +2338,7 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) {
tree->set_drag_forwarding(this);
tree->set_allow_rmb_select(true);
tree->set_select_mode(Tree::SELECT_MULTI);
- tree->set_custom_minimum_size(Size2(0, 200 * EDSCALE));
+ tree->set_custom_minimum_size(Size2(0, 15 * EDSCALE));
split_box->add_child(tree);
tree->connect("item_edited", this, "_favorite_toggled");
@@ -2356,6 +2377,7 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) {
files->connect("gui_input", this, "_file_list_gui_input");
files->connect("multi_selected", this, "_file_multi_selected");
files->connect("rmb_clicked", this, "_file_list_rmb_pressed");
+ files->set_custom_minimum_size(Size2(0, 15 * EDSCALE));
files->set_allow_rmb_select(true);
file_list_vb->add_child(files);
diff --git a/editor/find_in_files.cpp b/editor/find_in_files.cpp
index 11d0b67bd6..2fdf1c82c0 100644
--- a/editor/find_in_files.cpp
+++ b/editor/find_in_files.cpp
@@ -302,7 +302,7 @@ FindInFilesDialog::FindInFilesDialog() {
set_custom_minimum_size(Size2(400, 190));
set_resizable(true);
- set_title(TTR("Find in files"));
+ set_title(TTR("Find in Files"));
VBoxContainer *vbc = memnew(VBoxContainer);
vbc->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 8 * EDSCALE);
diff --git a/editor/icons/icon_text_file.svg b/editor/icons/icon_text_file.svg
new file mode 100644
index 0000000000..342a407b79
--- /dev/null
+++ b/editor/icons/icon_text_file.svg
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="16"
+ height="16"
+ version="1.1"
+ viewBox="0 0 16 16"
+ id="svg8"
+ sodipodi:docname="icon_text_file.svg"
+ inkscape:version="0.92.2 2405546, 2018-03-11"
+ enable-background="new">
+ <metadata
+ id="metadata14">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <defs
+ id="defs12" />
+ <sodipodi:namedview
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1"
+ objecttolerance="10"
+ gridtolerance="10"
+ guidetolerance="10"
+ inkscape:pageopacity="0"
+ inkscape:pageshadow="2"
+ inkscape:window-width="2560"
+ inkscape:window-height="1440"
+ id="namedview10"
+ showgrid="false"
+ inkscape:zoom="64"
+ inkscape:cx="-0.11275433"
+ inkscape:cy="5.0633688"
+ inkscape:window-x="1920"
+ inkscape:window-y="0"
+ inkscape:window-maximized="0"
+ inkscape:current-layer="svg8"
+ inkscape:snap-grids="true" />
+ <path
+ style="display:inline;fill:#e0e0e0"
+ d="m 13.370548,12.198712 c 0.359546,-0.0075 0.719092,-0.015 1.078638,-0.0225 -0.004,-0.738576 -0.008,-1.477152 -0.01198,-2.215728 -1.429703,0.011985 -2.859406,0.02397 -4.289109,0.035955 0.004,0.759672 0.008,1.519344 0.01198,2.279016 0.40349,-0.01135 0.806981,-0.02271 1.210471,-0.03406 0,1.251681 0,2.503363 0,3.755044 0.666667,0 1.333333,0 2,0 M 6.1005477,12.247152 c 0.332722,0.21587 0.665444,0.431741 0.998166,0.647611 -0.3328629,0.218648 -0.6657258,0.437297 -0.9985887,0.655945 -1e-7,0.818044 -2e-7,1.636088 -3e-7,2.454132 0.5662705,-0.533749 1.1325409,-1.067498 1.6988114,-1.601247 0.6353035,0.532396 1.2706071,1.064791 1.9059106,1.597187 -9.5e-4,-0.757409 -0.0019,-1.514817 -0.00285,-2.272226 -0.2987204,-0.278501 -0.5974407,-0.557002 -0.8961611,-0.835503 0.2983766,-0.205775 0.5967531,-0.41155 0.8951297,-0.617325 0.00283,-0.73844 0.00565,-1.476881 0.00848,-2.215321 -0.63732,0.474447 -1.27464,0.948893 -1.91196,1.42334 C 7.2318406,10.979446 6.6661958,10.475146 6.1005511,9.9708468 M 4.6399123,12.202271 c 0.3595459,-0.0075 0.7190917,-0.015 1.0786376,-0.0225 -0.00399,-0.738576 -0.00799,-1.477152 -0.011985,-2.2157276 -1.4297028,0.011985 -2.8594057,0.02397 -4.2891085,0.035955 0.00399,0.7596716 0.00799,1.5193436 0.011985,2.2790156 0.4034903,-0.01135 0.8069806,-0.02271 1.2104709,-0.03406 0,1.251681 0,2.503363 0,3.755044 0.6666667,0 1.3333333,0 2,0 M 7,1 C 6.81185,1.7526 6.6237,2.5052 6.43555,3.2578 6.0521572,3.3957205 5.6943609,3.6619566 5.3589944,3.3047548 4.8252629,2.9844032 4.2915315,2.6640516 3.7578,2.3437 3.2864333,2.8150667 2.8150667,3.2864333 2.3437,3.7578 2.7421333,4.4225 3.1405667,5.0872 3.539,5.7519 3.3683054,6.121632 3.3058712,6.5625877 2.8157946,6.5467719 2.2105097,6.6978312 1.6052249,6.8488906 0.99994,6.99995 c 0,0.6666667 0,1.3333333 0,2 1.7571667,0 3.5143333,0 5.2715,0 C 5.5845118,7.9199003 6.2580962,6.3373839 7.5001288,6.0629153 8.7083679,5.7047153 10.045643,6.7406952 9.99996,7.99995 c 0.104409,0.4657408 -0.6052318,1.1778026 0.181951,1 1.606006,0 3.212013,0 4.818019,0 0,-0.6666667 0,-1.3333333 0,-2 C 14.24733,6.8118 13.49473,6.62365 12.74213,6.4355 12.603459,6.0528244 12.33852,5.6958457 12.695012,5.3607965 13.015418,4.8264643 13.335824,4.2921322 13.65623,3.7578 13.184863,3.2864333 12.713497,2.8150667 12.24213,2.3437 11.57743,2.7421333 10.91273,3.1405667 10.24803,3.539 9.8782981,3.3683053 9.4373423,3.3058712 9.4531581,2.8157946 9.3020988,2.2105097 9.1510394,1.6052249 8.99998,0.99994 8.3333478,0.99998002 7.6664935,0.99985998 7,1 Z"
+ id="path4781-7"
+ inkscape:connector-curvature="0" />
+</svg>
diff --git a/editor/multi_node_edit.cpp b/editor/multi_node_edit.cpp
index 173be01586..be4e752d55 100644
--- a/editor/multi_node_edit.cpp
+++ b/editor/multi_node_edit.cpp
@@ -30,7 +30,7 @@
#include "multi_node_edit.h"
-#include "core/helper/math_fieldwise.h"
+#include "core/math/math_fieldwise.h"
#include "editor_node.h"
bool MultiNodeEdit::_set(const StringName &p_name, const Variant &p_value) {
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index 2ea17fda1c..7d971de0e3 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -1654,6 +1654,8 @@ bool CanvasItemEditor::_gui_input_scale(const Ref<InputEvent> &p_event) {
Transform2D unscaled_transform = (xform * canvas_item->get_transform().affine_inverse() * Transform2D(canvas_item->_edit_get_rotation(), canvas_item->_edit_get_position())).orthonormalized();
Transform2D simple_xform = viewport->get_transform() * unscaled_transform;
+ drag_type = DRAG_SCALE_BOTH;
+
Size2 scale_factor = Size2(SCALE_HANDLE_DISTANCE, SCALE_HANDLE_DISTANCE);
Rect2 x_handle_rect = Rect2(scale_factor.x * EDSCALE, -5 * EDSCALE, 10 * EDSCALE, 10 * EDSCALE);
if (x_handle_rect.has_point(simple_xform.affine_inverse().xform(b->get_position()))) {
@@ -1663,18 +1665,17 @@ bool CanvasItemEditor::_gui_input_scale(const Ref<InputEvent> &p_event) {
if (y_handle_rect.has_point(simple_xform.affine_inverse().xform(b->get_position()))) {
drag_type = DRAG_SCALE_Y;
}
- if (drag_type == DRAG_SCALE_X || drag_type == DRAG_SCALE_Y) {
- drag_from = transform.affine_inverse().xform(b->get_position());
- drag_selection = List<CanvasItem *>();
- drag_selection.push_back(canvas_item);
- _save_canvas_item_state(drag_selection);
- return true;
- }
+
+ drag_from = transform.affine_inverse().xform(b->get_position());
+ drag_selection = List<CanvasItem *>();
+ drag_selection.push_back(canvas_item);
+ _save_canvas_item_state(drag_selection);
+ return true;
}
}
}
- if (drag_type == DRAG_SCALE_X || drag_type == DRAG_SCALE_Y) {
+ if (drag_type == DRAG_SCALE_BOTH || drag_type == DRAG_SCALE_X || drag_type == DRAG_SCALE_Y) {
// Resize the node
if (m.is_valid()) {
_restore_canvas_item_state(drag_selection);
@@ -1682,24 +1683,49 @@ bool CanvasItemEditor::_gui_input_scale(const Ref<InputEvent> &p_event) {
drag_to = transform.affine_inverse().xform(m->get_position());
+ Transform2D parent_xform = canvas_item->get_global_transform_with_canvas() * canvas_item->get_transform().affine_inverse();
+ Transform2D unscaled_transform = (transform * parent_xform * Transform2D(canvas_item->_edit_get_rotation(), canvas_item->_edit_get_position())).orthonormalized();
+ Transform2D simple_xform = (viewport->get_transform() * unscaled_transform).affine_inverse() * transform;
+
bool uniform = m->get_shift();
- Point2 offset = drag_to - drag_from;
+
+ Point2 drag_from_local = simple_xform.xform(drag_from);
+ Point2 drag_to_local = simple_xform.xform(drag_to);
+ Point2 offset = drag_to_local - drag_from_local;
+
Size2 scale = canvas_item->call("get_scale");
float ratio = scale.y / scale.x;
- if (drag_type == DRAG_SCALE_X) {
- scale.x += offset.x / SCALE_HANDLE_DISTANCE;
+ if (drag_type == DRAG_SCALE_BOTH) {
+ Size2 scale_factor = drag_to_local / drag_from_local;
if (uniform) {
- scale.y = scale.x * ratio;
+ if (ABS(offset.x) > ABS(offset.y)) {
+ scale.x *= scale_factor.x;
+ scale.y = scale.x * ratio;
+ } else {
+ scale.y *= scale_factor.y;
+ scale.x = scale.y / ratio;
+ }
+ } else {
+ scale *= scale_factor;
}
- canvas_item->call("set_scale", scale);
-
- } else if (drag_type == DRAG_SCALE_Y) {
- scale.y -= offset.y / SCALE_HANDLE_DISTANCE;
- if (uniform) {
- scale.x = scale.y / ratio;
+ } else {
+ Size2 scale_factor = Vector2(offset.x, -offset.y) / SCALE_HANDLE_DISTANCE;
+ Size2 parent_scale = parent_xform.get_scale();
+ scale_factor *= Vector2(1.0 / parent_scale.x, 1.0 / parent_scale.y);
+ if (drag_type == DRAG_SCALE_X) {
+ scale.x += scale_factor.x;
+ if (uniform) {
+ scale.y = scale.x * ratio;
+ }
+ } else if (drag_type == DRAG_SCALE_Y) {
+ scale.y += scale_factor.y;
+ if (uniform) {
+ scale.x = scale.y / ratio;
+ }
}
- canvas_item->call("set_scale", scale);
}
+ canvas_item->call("set_scale", scale);
+ return true;
}
// Confirm resize
@@ -2815,7 +2841,7 @@ void CanvasItemEditor::_draw_axis() {
RID ci = viewport->get_canvas_item();
- Color area_axis_color(0.4, 0.4, 1.0, 0.4);
+ Color area_axis_color = EditorSettings::get_singleton()->get("editors/2d/viewport_border_color");
Size2 screen_size = Size2(ProjectSettings::get_singleton()->get("display/window/size/width"), ProjectSettings::get_singleton()->get("display/window/size/height"));
diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h
index 2d539d6727..c788a63d56 100644
--- a/editor/plugins/canvas_item_editor_plugin.h
+++ b/editor/plugins/canvas_item_editor_plugin.h
@@ -195,6 +195,7 @@ private:
DRAG_MOVE,
DRAG_SCALE_X,
DRAG_SCALE_Y,
+ DRAG_SCALE_BOTH,
DRAG_ROTATE,
DRAG_PIVOT,
DRAG_V_GUIDE,
diff --git a/editor/plugins/physical_bone_plugin.cpp b/editor/plugins/physical_bone_plugin.cpp
index 1c3c000808..6341d7f2ef 100644
--- a/editor/plugins/physical_bone_plugin.cpp
+++ b/editor/plugins/physical_bone_plugin.cpp
@@ -69,15 +69,7 @@ PhysicalBoneEditor::PhysicalBoneEditor(EditorNode *p_editor) :
hide();
}
-PhysicalBoneEditor::~PhysicalBoneEditor() {
- // TODO the spatial_editor_hb should be removed from SpatialEditor, but in this moment it's not possible
- for (int i = spatial_editor_hb->get_child_count() - 1; 0 <= i; --i) {
- Node *n = spatial_editor_hb->get_child(i);
- spatial_editor_hb->remove_child(n);
- memdelete(n);
- }
- memdelete(spatial_editor_hb);
-}
+PhysicalBoneEditor::~PhysicalBoneEditor() {}
void PhysicalBoneEditor::set_selected(PhysicalBone *p_pb) {
@@ -98,19 +90,17 @@ void PhysicalBoneEditor::show() {
PhysicalBonePlugin::PhysicalBonePlugin(EditorNode *p_editor) :
editor(p_editor),
- selected(NULL) {
-
- physical_bone_editor = memnew(PhysicalBoneEditor(editor));
-}
+ selected(NULL),
+ physical_bone_editor(editor) {}
void PhysicalBonePlugin::make_visible(bool p_visible) {
if (p_visible) {
- physical_bone_editor->show();
+ physical_bone_editor.show();
} else {
- physical_bone_editor->hide();
- physical_bone_editor->set_selected(NULL);
+ physical_bone_editor.hide();
+ physical_bone_editor.set_selected(NULL);
selected = NULL;
}
}
@@ -119,5 +109,5 @@ void PhysicalBonePlugin::edit(Object *p_node) {
selected = static_cast<PhysicalBone *>(p_node); // Trust it
ERR_FAIL_COND(!selected);
- physical_bone_editor->set_selected(selected);
+ physical_bone_editor.set_selected(selected);
}
diff --git a/editor/plugins/physical_bone_plugin.h b/editor/plugins/physical_bone_plugin.h
index e03d342709..e1f8c9ec47 100644
--- a/editor/plugins/physical_bone_plugin.h
+++ b/editor/plugins/physical_bone_plugin.h
@@ -64,7 +64,7 @@ class PhysicalBonePlugin : public EditorPlugin {
EditorNode *editor;
PhysicalBone *selected;
- PhysicalBoneEditor *physical_bone_editor;
+ PhysicalBoneEditor physical_bone_editor;
public:
virtual String get_name() const { return "PhysicalBone"; }
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp
index c8e7bfb74b..5e000ca6ef 100644
--- a/editor/plugins/script_editor_plugin.cpp
+++ b/editor/plugins/script_editor_plugin.cpp
@@ -3013,7 +3013,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/show_in_file_system", TTR("Show In File System")), SHOW_IN_FILE_SYSTEM);
file_menu->get_popup()->add_separator();
- file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/history_previous", TTR("History Prev"), KEY_MASK_ALT | KEY_LEFT), WINDOW_PREV);
+ file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/history_previous", TTR("History Previous"), KEY_MASK_ALT | KEY_LEFT), WINDOW_PREV);
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/history_next", TTR("History Next"), KEY_MASK_ALT | KEY_RIGHT), WINDOW_NEXT);
file_menu->get_popup()->add_separator();
@@ -3060,7 +3060,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
debug_menu->get_popup()->add_separator();
//debug_menu->get_popup()->add_check_item("Show Debugger",DEBUG_SHOW);
debug_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("debugger/keep_debugger_open", TTR("Keep Debugger Open")), DEBUG_SHOW_KEEP_OPEN);
- debug_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("debugger/debug_with_exteral_editor", TTR("Debug with external editor")), DEBUG_WITH_EXTERNAL_EDITOR);
+ debug_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("debugger/debug_with_external_editor", TTR("Debug with External Editor")), DEBUG_WITH_EXTERNAL_EDITOR);
debug_menu->get_popup()->connect("id_pressed", this, "_menu_option");
debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_NEXT), true);
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index d4ddaf274f..46a6b85131 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -941,6 +941,7 @@ void ScriptTextEditor::_edit_option(int p_op) {
case SEARCH_LOCATE_FUNCTION: {
quick_open->popup(get_functions());
+ quick_open->set_title(TTR("Go to Function"));
} break;
case SEARCH_GOTO_LINE: {
@@ -1567,8 +1568,8 @@ void ScriptTextEditor::register_editor() {
ED_SHORTCUT("script_text_editor/toggle_breakpoint", TTR("Toggle Breakpoint"), KEY_F9);
#endif
ED_SHORTCUT("script_text_editor/remove_all_breakpoints", TTR("Remove All Breakpoints"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F9);
- ED_SHORTCUT("script_text_editor/goto_next_breakpoint", TTR("Goto Next Breakpoint"), KEY_MASK_CMD | KEY_PERIOD);
- ED_SHORTCUT("script_text_editor/goto_previous_breakpoint", TTR("Goto Previous Breakpoint"), KEY_MASK_CMD | KEY_COMMA);
+ ED_SHORTCUT("script_text_editor/goto_next_breakpoint", TTR("Go to Next Breakpoint"), KEY_MASK_CMD | KEY_PERIOD);
+ ED_SHORTCUT("script_text_editor/goto_previous_breakpoint", TTR("Go to Previous Breakpoint"), KEY_MASK_CMD | KEY_COMMA);
ED_SHORTCUT("script_text_editor/find", TTR("Find..."), KEY_MASK_CMD | KEY_F);
#ifdef OSX_ENABLED
@@ -1581,14 +1582,14 @@ void ScriptTextEditor::register_editor() {
ED_SHORTCUT("script_text_editor/replace", TTR("Replace..."), KEY_MASK_CMD | KEY_R);
#endif
- ED_SHORTCUT("script_text_editor/find_in_files", TTR("Find in files..."), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F);
+ ED_SHORTCUT("script_text_editor/find_in_files", TTR("Find in Files..."), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F);
#ifdef OSX_ENABLED
- ED_SHORTCUT("script_text_editor/goto_function", TTR("Goto Function..."), KEY_MASK_CTRL | KEY_MASK_CMD | KEY_J);
+ ED_SHORTCUT("script_text_editor/goto_function", TTR("Go to Function..."), KEY_MASK_CTRL | KEY_MASK_CMD | KEY_J);
#else
- ED_SHORTCUT("script_text_editor/goto_function", TTR("Goto Function..."), KEY_MASK_ALT | KEY_MASK_CMD | KEY_F);
+ ED_SHORTCUT("script_text_editor/goto_function", TTR("Go to Function..."), KEY_MASK_ALT | KEY_MASK_CMD | KEY_F);
#endif
- ED_SHORTCUT("script_text_editor/goto_line", TTR("Goto Line..."), KEY_MASK_CMD | KEY_L);
+ ED_SHORTCUT("script_text_editor/goto_line", TTR("Go to Line..."), KEY_MASK_CMD | KEY_L);
#ifdef OSX_ENABLED
ED_SHORTCUT("script_text_editor/contextual_help", TTR("Contextual Help"), KEY_MASK_ALT | KEY_MASK_SHIFT | KEY_SPACE);
diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp
index 508db2e03f..c611327a31 100644
--- a/editor/property_editor.cpp
+++ b/editor/property_editor.cpp
@@ -1991,60 +1991,3 @@ CustomPropertyEditor::CustomPropertyEditor() {
create_dialog = NULL;
property_select = NULL;
}
-
-/////////////////////////////
-
-double PropertyValueEvaluator::eval(const String &p_text) {
-
- // If range value contains a comma replace it with dot (issue #6028)
- const String &p_new_text = p_text.replace(",", ".");
-
- if (!obj || !script_language)
- return _default_eval(p_new_text);
-
- Ref<Script> script = Ref<Script>(script_language->create_script());
- script->set_source_code(_build_script(p_new_text));
- Error err = script->reload();
- if (err) {
- ERR_PRINTS("PropertyValueEvaluator: Error loading script for expression: " + p_new_text);
- return _default_eval(p_new_text);
- }
-
- Object dummy;
- ScriptInstance *script_instance = script->instance_create(&dummy);
- if (!script_instance)
- return _default_eval(p_new_text);
-
- Variant::CallError call_err;
- Variant arg = obj;
- const Variant *args[] = { &arg };
- double result = script_instance->call("eval", args, 1, call_err);
- if (call_err.error == Variant::CallError::CALL_OK) {
- return result;
- }
- ERR_PRINTS("PropertyValueEvaluator: Eval failed, error code: " + itos(call_err.error));
-
- return _default_eval(p_new_text);
-}
-
-void PropertyValueEvaluator::edit(Object *p_obj) {
- obj = p_obj;
-}
-
-String PropertyValueEvaluator::_build_script(const String &p_text) {
- String script_text = "tool\nextends Object\nfunc eval(s):\n\tself = s\n\treturn " + p_text.strip_edges() + "\n";
- return script_text;
-}
-
-PropertyValueEvaluator::PropertyValueEvaluator() {
- script_language = NULL;
-
- for (int i = 0; i < ScriptServer::get_language_count(); i++) {
- if (ScriptServer::get_language(i)->get_name() == "GDScript") {
- script_language = ScriptServer::get_language(i);
- }
- }
-}
-
-PropertyValueEvaluator::~PropertyValueEvaluator() {
-}
diff --git a/editor/property_editor.h b/editor/property_editor.h
index ee3a56d857..c74103df3d 100644
--- a/editor/property_editor.h
+++ b/editor/property_editor.h
@@ -171,30 +171,9 @@ public:
void set_read_only(bool p_read_only) { read_only = p_read_only; }
- void set_value_evaluator(PropertyValueEvaluator *p_evaluator) { evaluator = p_evaluator; }
-
bool edit(Object *p_owner, const String &p_name, Variant::Type p_type, const Variant &p_variant, int p_hint, String p_hint_text);
CustomPropertyEditor();
};
-class PropertyValueEvaluator : public ValueEvaluator {
- GDCLASS(PropertyValueEvaluator, ValueEvaluator);
-
- Object *obj;
- ScriptLanguage *script_language;
- String _build_script(const String &p_text);
-
- _FORCE_INLINE_ double _default_eval(const String &p_text) {
- return p_text.to_double();
- }
-
-public:
- void edit(Object *p_obj);
- double eval(const String &p_text);
-
- PropertyValueEvaluator();
- ~PropertyValueEvaluator();
-};
-
#endif
diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp
index d8de775d36..df704706af 100644
--- a/editor/script_create_dialog.cpp
+++ b/editor/script_create_dialog.cpp
@@ -50,7 +50,11 @@ void ScriptCreateDialog::_notification(int p_what) {
}
}
-void ScriptCreateDialog::config(const String &p_base_name, const String &p_base_path) {
+bool ScriptCreateDialog::_can_be_built_in() {
+ return (supports_built_in && built_in_enabled);
+}
+
+void ScriptCreateDialog::config(const String &p_base_name, const String &p_base_path, bool p_built_in_enabled) {
class_name->set_text("");
class_name->deselect();
@@ -66,6 +70,8 @@ void ScriptCreateDialog::config(const String &p_base_name, const String &p_base_
}
file_path->deselect();
+ built_in_enabled = p_built_in_enabled;
+
_lang_changed(current_language);
_class_name_changed("");
_path_changed(file_path->get_text());
@@ -544,7 +550,7 @@ void ScriptCreateDialog::_update_dialog() {
}
}
- if (!supports_built_in)
+ if (!_can_be_built_in())
internal->set_pressed(false);
/* Is Script created or loaded from existing file */
@@ -553,14 +559,14 @@ void ScriptCreateDialog::_update_dialog() {
get_ok()->set_text(TTR("Create"));
parent_name->set_editable(true);
parent_browse_button->set_disabled(false);
- internal->set_disabled(!supports_built_in);
+ internal->set_disabled(!_can_be_built_in());
_msg_path_valid(true, TTR("Built-in script (into scene file)"));
} else if (is_new_script_created) {
// New Script Created
get_ok()->set_text(TTR("Create"));
parent_name->set_editable(true);
parent_browse_button->set_disabled(false);
- internal->set_disabled(!supports_built_in);
+ internal->set_disabled(!_can_be_built_in());
if (is_path_valid) {
_msg_path_valid(true, TTR("Create new script file"));
}
@@ -569,7 +575,7 @@ void ScriptCreateDialog::_update_dialog() {
get_ok()->set_text(TTR("Load"));
parent_name->set_editable(false);
parent_browse_button->set_disabled(true);
- internal->set_disabled(!supports_built_in);
+ internal->set_disabled(!_can_be_built_in());
if (is_path_valid) {
_msg_path_valid(true, TTR("Load existing script file"));
}
@@ -588,7 +594,7 @@ void ScriptCreateDialog::_bind_methods() {
ClassDB::bind_method("_path_entered", &ScriptCreateDialog::_path_entered);
ClassDB::bind_method("_template_changed", &ScriptCreateDialog::_template_changed);
- ClassDB::bind_method(D_METHOD("config", "inherits", "path"), &ScriptCreateDialog::config);
+ ClassDB::bind_method(D_METHOD("config", "inherits", "path", "built_in_enabled"), &ScriptCreateDialog::config, DEFVAL(true));
ADD_SIGNAL(MethodInfo("script_created", PropertyInfo(Variant::OBJECT, "script", PROPERTY_HINT_RESOURCE_TYPE, "Script")));
}
@@ -793,6 +799,7 @@ ScriptCreateDialog::ScriptCreateDialog() {
has_named_classes = false;
supports_built_in = false;
can_inherit_from_file = false;
+ built_in_enabled = true;
is_built_in = false;
is_new_script_created = true;
diff --git a/editor/script_create_dialog.h b/editor/script_create_dialog.h
index 1ad4a1b7a1..e0bf336b56 100644
--- a/editor/script_create_dialog.h
+++ b/editor/script_create_dialog.h
@@ -69,11 +69,13 @@ class ScriptCreateDialog : public ConfirmationDialog {
bool is_parent_name_valid;
bool is_class_name_valid;
bool is_built_in;
+ bool built_in_enabled;
int current_language;
bool re_check_path;
String script_template;
Vector<String> template_list;
+ bool _can_be_built_in();
void _path_changed(const String &p_path = String());
void _path_entered(const String &p_path = String());
void _lang_changed(int l = 0);
@@ -96,8 +98,7 @@ protected:
static void _bind_methods();
public:
- void config(const String &p_base_name, const String &p_base_path);
-
+ void config(const String &p_base_name, const String &p_base_path, bool p_built_in_enabled = true);
ScriptCreateDialog();
};
diff --git a/gles_builders.py b/gles_builders.py
index b5a2b24aa3..8ed9f39393 100644
--- a/gles_builders.py
+++ b/gles_builders.py
@@ -232,7 +232,11 @@ def build_legacygl_header(filename, include, class_suffix, output_attribs, gles2
fd.write("\t_FORCE_INLINE_ int get_uniform(Uniforms p_uniform) const { return _get_uniform(p_uniform); }\n\n")
if header_data.conditionals:
fd.write("\t_FORCE_INLINE_ void set_conditional(Conditionals p_conditional,bool p_enable) { _set_conditional(p_conditional,p_enable); }\n\n")
- fd.write("\t#define _FU if (get_uniform(p_uniform)<0) return; ERR_FAIL_COND( get_active()!=this );\n\n ")
+ fd.write("\t#ifdef DEBUG_ENABLED\n ")
+ fd.write("\t#define _FU if (get_uniform(p_uniform)<0) return; if (!is_version_valid()) return; ERR_FAIL_COND( get_active()!=this ); \n\n ")
+ fd.write("\t#else\n ")
+ fd.write("\t#define _FU if (get_uniform(p_uniform)<0) return; \n\n ")
+ fd.write("\t#endif\n")
fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, float p_value) { _FU glUniform1f(get_uniform(p_uniform),p_value); }\n\n")
fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, double p_value) { _FU glUniform1f(get_uniform(p_uniform),p_value); }\n\n")
fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, uint8_t p_value) { _FU glUniform1i(get_uniform(p_uniform),p_value); }\n\n")
diff --git a/modules/bullet/godot_collision_configuration.cpp b/modules/bullet/godot_collision_configuration.cpp
index f4bb9acbd7..919c3152d7 100644
--- a/modules/bullet/godot_collision_configuration.cpp
+++ b/modules/bullet/godot_collision_configuration.cpp
@@ -94,3 +94,59 @@ btCollisionAlgorithmCreateFunc *GodotCollisionConfiguration::getClosestPointsAlg
return btDefaultCollisionConfiguration::getClosestPointsAlgorithmCreateFunc(proxyType0, proxyType1);
}
}
+
+GodotSoftCollisionConfiguration::GodotSoftCollisionConfiguration(const btDiscreteDynamicsWorld *world, const btDefaultCollisionConstructionInfo &constructionInfo) :
+ btSoftBodyRigidBodyCollisionConfiguration(constructionInfo) {
+
+ void *mem = NULL;
+
+ mem = btAlignedAlloc(sizeof(GodotRayWorldAlgorithm::CreateFunc), 16);
+ m_rayWorldCF = new (mem) GodotRayWorldAlgorithm::CreateFunc(world);
+
+ mem = btAlignedAlloc(sizeof(GodotRayWorldAlgorithm::SwappedCreateFunc), 16);
+ m_swappedRayWorldCF = new (mem) GodotRayWorldAlgorithm::SwappedCreateFunc(world);
+}
+
+GodotSoftCollisionConfiguration::~GodotSoftCollisionConfiguration() {
+ m_rayWorldCF->~btCollisionAlgorithmCreateFunc();
+ btAlignedFree(m_rayWorldCF);
+
+ m_swappedRayWorldCF->~btCollisionAlgorithmCreateFunc();
+ btAlignedFree(m_swappedRayWorldCF);
+}
+
+btCollisionAlgorithmCreateFunc *GodotSoftCollisionConfiguration::getCollisionAlgorithmCreateFunc(int proxyType0, int proxyType1) {
+
+ if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType0 && CUSTOM_CONVEX_SHAPE_TYPE == proxyType1) {
+
+ // This collision is not supported
+ return m_emptyCreateFunc;
+ } else if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType0) {
+
+ return m_rayWorldCF;
+ } else if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType1) {
+
+ return m_swappedRayWorldCF;
+ } else {
+
+ return btSoftBodyRigidBodyCollisionConfiguration::getCollisionAlgorithmCreateFunc(proxyType0, proxyType1);
+ }
+}
+
+btCollisionAlgorithmCreateFunc *GodotSoftCollisionConfiguration::getClosestPointsAlgorithmCreateFunc(int proxyType0, int proxyType1) {
+
+ if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType0 && CUSTOM_CONVEX_SHAPE_TYPE == proxyType1) {
+
+ // This collision is not supported
+ return m_emptyCreateFunc;
+ } else if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType0) {
+
+ return m_rayWorldCF;
+ } else if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType1) {
+
+ return m_swappedRayWorldCF;
+ } else {
+
+ return btSoftBodyRigidBodyCollisionConfiguration::getClosestPointsAlgorithmCreateFunc(proxyType0, proxyType1);
+ }
+}
diff --git a/modules/bullet/godot_collision_configuration.h b/modules/bullet/godot_collision_configuration.h
index 9b30ad0c62..11012c5f6d 100644
--- a/modules/bullet/godot_collision_configuration.h
+++ b/modules/bullet/godot_collision_configuration.h
@@ -32,6 +32,7 @@
#define GODOT_COLLISION_CONFIGURATION_H
#include <BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h>
+#include <BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.h>
/**
@author AndreaCatania
@@ -50,4 +51,16 @@ public:
virtual btCollisionAlgorithmCreateFunc *getCollisionAlgorithmCreateFunc(int proxyType0, int proxyType1);
virtual btCollisionAlgorithmCreateFunc *getClosestPointsAlgorithmCreateFunc(int proxyType0, int proxyType1);
};
+
+class GodotSoftCollisionConfiguration : public btSoftBodyRigidBodyCollisionConfiguration {
+ btCollisionAlgorithmCreateFunc *m_rayWorldCF;
+ btCollisionAlgorithmCreateFunc *m_swappedRayWorldCF;
+
+public:
+ GodotSoftCollisionConfiguration(const btDiscreteDynamicsWorld *world, const btDefaultCollisionConstructionInfo &constructionInfo = btDefaultCollisionConstructionInfo());
+ virtual ~GodotSoftCollisionConfiguration();
+
+ virtual btCollisionAlgorithmCreateFunc *getCollisionAlgorithmCreateFunc(int proxyType0, int proxyType1);
+ virtual btCollisionAlgorithmCreateFunc *getClosestPointsAlgorithmCreateFunc(int proxyType0, int proxyType1);
+};
#endif
diff --git a/modules/bullet/space_bullet.cpp b/modules/bullet/space_bullet.cpp
index 404cb8e37b..329e12cfff 100644
--- a/modules/bullet/space_bullet.cpp
+++ b/modules/bullet/space_bullet.cpp
@@ -150,14 +150,14 @@ int BulletPhysicsDirectSpaceState::intersect_shape(const RID &p_shape, const Tra
return btQuery.m_count;
}
-bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, float p_margin, float &p_closest_safe, float &p_closest_unsafe, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas, ShapeRestInfo *r_info) {
+bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, float p_margin, float &r_closest_safe, float &r_closest_unsafe, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas, ShapeRestInfo *r_info) {
ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->get(p_shape);
btCollisionShape *btShape = shape->create_bt_shape(p_xform.basis.get_scale(), p_margin);
if (!btShape->isConvex()) {
bulletdelete(btShape);
ERR_PRINTS("The shape is not a convex shape, then is not supported: shape type: " + itos(shape->get_type()));
- return 0;
+ return false;
}
btConvexShape *bt_convex_shape = static_cast<btConvexShape *>(btShape);
@@ -177,10 +177,13 @@ bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transf
space->dynamicsWorld->convexSweepTest(bt_convex_shape, bt_xform_from, bt_xform_to, btResult, 0.002);
+ r_closest_unsafe = 1.0;
+ r_closest_safe = 1.0;
+
if (btResult.hasHit()) {
const btScalar l = bt_motion.length();
- p_closest_unsafe = btResult.m_closestHitFraction;
- p_closest_safe = MAX(p_closest_unsafe - (1 - ((l - 0.01) / l)), 0);
+ r_closest_unsafe = btResult.m_closestHitFraction;
+ r_closest_safe = MAX(r_closest_unsafe - (1 - ((l - 0.01) / l)), 0);
if (r_info) {
if (btCollisionObject::CO_RIGID_BODY == btResult.m_hitCollisionObject->getInternalType()) {
B_TO_G(static_cast<const btRigidBody *>(btResult.m_hitCollisionObject)->getVelocityInLocalPoint(btResult.m_hitPointWorld), r_info->linear_velocity);
@@ -195,7 +198,7 @@ bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transf
}
bulletdelete(bt_convex_shape);
- return btResult.hasHit();
+ return true; // Mean success
}
/// Returns the list of contacts pairs in this order: Local contact, other body contact
@@ -577,7 +580,7 @@ void SpaceBullet::create_empty_world(bool p_create_soft_world) {
}
if (p_create_soft_world) {
- collisionConfiguration = bulletnew(btSoftBodyRigidBodyCollisionConfiguration);
+ collisionConfiguration = bulletnew(GodotSoftCollisionConfiguration(static_cast<btDiscreteDynamicsWorld *>(world_mem)));
} else {
collisionConfiguration = bulletnew(GodotCollisionConfiguration(static_cast<btDiscreteDynamicsWorld *>(world_mem)));
}
diff --git a/modules/bullet/space_bullet.h b/modules/bullet/space_bullet.h
index 0649e1f7e3..67ab5c610d 100644
--- a/modules/bullet/space_bullet.h
+++ b/modules/bullet/space_bullet.h
@@ -78,7 +78,7 @@ public:
virtual int intersect_point(const Vector3 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false);
virtual bool intersect_ray(const Vector3 &p_from, const Vector3 &p_to, RayResult &r_result, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, bool p_pick_ray = false);
virtual int intersect_shape(const RID &p_shape, const Transform &p_xform, float p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false);
- virtual bool cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, float p_margin, float &p_closest_safe, float &p_closest_unsafe, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, ShapeRestInfo *r_info = NULL);
+ virtual bool cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, float p_margin, float &r_closest_safe, float &r_closest_unsafe, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, ShapeRestInfo *r_info = NULL);
/// Returns the list of contacts pairs in this order: Local contact, other body contact
virtual bool collide_shape(RID p_shape, const Transform &p_shape_xform, float p_margin, Vector3 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false);
virtual bool rest_info(RID p_shape, const Transform &p_shape_xform, float p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false);
diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/networked_multiplayer_enet.cpp
index 0a1061f92e..7b5fd854ff 100644
--- a/modules/enet/networked_multiplayer_enet.cpp
+++ b/modules/enet/networked_multiplayer_enet.cpp
@@ -207,13 +207,13 @@ void NetworkedMultiplayerENet::poll() {
_pop_current_packet();
ENetEvent event;
- /* Wait up to 1000 milliseconds for an event. */
+ /* Keep servicing until there are no available events left in queue. */
while (true) {
if (!host || !active) // Might have been disconnected while emitting a notification
return;
- int ret = enet_host_service(host, &event, 1);
+ int ret = enet_host_service(host, &event, 0);
if (ret < 0) {
// Error, do something?
@@ -293,7 +293,7 @@ void NetworkedMultiplayerENet::poll() {
encode_uint32(*id, &packet->data[4]);
enet_peer_send(E->get(), SYSCH_CONFIG, packet);
}
- } else if (!server) {
+ } else {
emit_signal("server_disconnected");
close_connection();
return;
diff --git a/modules/webm/libvpx/SCsub b/modules/webm/libvpx/SCsub
index 2daf8c282f..711000bd9f 100644
--- a/modules/webm/libvpx/SCsub
+++ b/modules/webm/libvpx/SCsub
@@ -349,7 +349,7 @@ if webm_multithread:
env_libvpx.add_source_files(env.modules_sources, libvpx_sources_mt)
if webm_cpu_x86:
- is_clang_or_gcc = ('gcc' in env["CC"]) or ('clang' in env["CC"]) or ("OSXCROSS_ROOT" in os.environ)
+ is_clang_or_gcc = ('gcc' in os.path.basename(env["CC"])) or ('clang' in os.path.basename(env["CC"])) or ("OSXCROSS_ROOT" in os.environ)
env_libvpx_mmx = env_libvpx.Clone()
if cpu_bits == '32' and is_clang_or_gcc:
diff --git a/modules/websocket/doc_classes/WebSocketClient.xml b/modules/websocket/doc_classes/WebSocketClient.xml
index 9241492623..b3ea535495 100644
--- a/modules/websocket/doc_classes/WebSocketClient.xml
+++ b/modules/websocket/doc_classes/WebSocketClient.xml
@@ -31,8 +31,12 @@
<method name="disconnect_from_host">
<return type="void">
</return>
+ <argument index="0" name="code" type="int" default="1000">
+ </argument>
+ <argument index="1" name="reason" type="String" default="&quot;&quot;">
+ </argument>
<description>
- Disconnect from the server if currently connected.
+ Disconnect this client from the connected host. See [method WebSocketPeer.close] for more info.
</description>
</method>
</methods>
@@ -43,8 +47,10 @@
</members>
<signals>
<signal name="connection_closed">
+ <argument index="0" name="was_clean_close" type="bool">
+ </argument>
<description>
- Emitted when the connection to the server is closed.
+ Emitted when the connection to the server is closed. [code]was_clean_close[/code] will be [code]true[/code] if the connection was shutdown cleanly.
</description>
</signal>
<signal name="connection_error">
@@ -64,6 +70,15 @@
Emitted when a WebSocket message is received. Note: This signal is NOT emitted when used as high level multiplayer peer.
</description>
</signal>
+ <signal name="server_close_request">
+ <argument index="0" name="code" type="int">
+ </argument>
+ <argument index="1" name="reason" type="String">
+ </argument>
+ <description>
+ Emitted when the server requests a clean close. You should keep polling until you get a [signal connection_closed] signal to achieve the clean close. See [method WebSocketPeer.close] for more details.
+ </description>
+ </signal>
</signals>
<constants>
</constants>
diff --git a/modules/websocket/doc_classes/WebSocketPeer.xml b/modules/websocket/doc_classes/WebSocketPeer.xml
index 85a08e0c0b..cc59706916 100644
--- a/modules/websocket/doc_classes/WebSocketPeer.xml
+++ b/modules/websocket/doc_classes/WebSocketPeer.xml
@@ -15,8 +15,14 @@
<method name="close">
<return type="void">
</return>
+ <argument index="0" name="code" type="int" default="1000">
+ </argument>
+ <argument index="1" name="reason" type="String" default="&quot;&quot;">
+ </argument>
<description>
- Close this WebSocket connection, actively disconnecting the peer.
+ Close this WebSocket connection. [code]code[/code] is the status code for the closure (see RFC6455 section 7.4 for a list of valid status codes). [reason] is the human readable reason for closing the connection (can be any UTF8 string, must be less than 123 bytes).
+ Note: To achieve a clean close, you will need to keep polling until either [signal WebSocketClient.connection_closed] or [signal WebSocketServer.client_disconnected] is received.
+ Note: HTML5 export might not support all status codes. Please refer to browsers-specific documentation for more details.
</description>
</method>
<method name="get_connected_host" qualifiers="const">
diff --git a/modules/websocket/doc_classes/WebSocketServer.xml b/modules/websocket/doc_classes/WebSocketServer.xml
index a1061e446b..ba66fdd89b 100644
--- a/modules/websocket/doc_classes/WebSocketServer.xml
+++ b/modules/websocket/doc_classes/WebSocketServer.xml
@@ -18,8 +18,12 @@
</return>
<argument index="0" name="id" type="int">
</argument>
+ <argument index="1" name="code" type="int" default="1000">
+ </argument>
+ <argument index="2" name="reason" type="String" default="&quot;&quot;">
+ </argument>
<description>
- Disconnects the given peer.
+ Disconnects the peer identified by [code]id[/code] from the server. See [method WebSocketPeer.close] for more info.
</description>
</method>
<method name="get_peer_address" qualifiers="const">
@@ -68,7 +72,7 @@
<description>
Start listening on the given port.
You can specify the desired subprotocols via the "protocols" array. If the list empty (default), "binary" will be used.
- You can use this server as a network peer for [MultiplayerAPI] by passing true as "gd_mp_api". Note: [signal data_received] will not be fired and clients other than Godot will not work in this case.
+ You can use this server as a network peer for [MultiplayerAPI] by passing [code]true[/code] as [code]gd_mp_api[/code]. Note: [signal data_received] will not be fired and clients other than Godot will not work in this case.
</description>
</method>
<method name="stop">
@@ -80,6 +84,17 @@
</method>
</methods>
<signals>
+ <signal name="client_close_request">
+ <argument index="0" name="id" type="int">
+ </argument>
+ <argument index="1" name="code" type="int">
+ </argument>
+ <argument index="2" name="reason" type="String">
+ </argument>
+ <description>
+ Emitted when a client requests a clean close. You should keep polling until you get a [signal client_disconnected] signal with the same [code]id[/code] to achieve the clean close. See [method WebSocketPeer.close] for more details.
+ </description>
+ </signal>
<signal name="client_connected">
<argument index="0" name="id" type="int">
</argument>
@@ -92,8 +107,10 @@
<signal name="client_disconnected">
<argument index="0" name="id" type="int">
</argument>
+ <argument index="1" name="was_clean_close" type="bool">
+ </argument>
<description>
- Emitted when a client disconnects.
+ Emitted when a client disconnects. [code]was_clean_close[/code] will be [code]true[/code] if the connection was shutdown cleanly.
</description>
</signal>
<signal name="data_received">
diff --git a/modules/websocket/emws_client.cpp b/modules/websocket/emws_client.cpp
index 836b564de8..8255ed7116 100644
--- a/modules/websocket/emws_client.cpp
+++ b/modules/websocket/emws_client.cpp
@@ -55,8 +55,9 @@ EMSCRIPTEN_KEEPALIVE void _esws_on_error(void *obj) {
EMSCRIPTEN_KEEPALIVE void _esws_on_close(void *obj, int code, char *reason, int was_clean) {
EMWSClient *client = static_cast<EMWSClient *>(obj);
+ client->_on_close_request(code, String(reason));
client->_is_connecting = false;
- client->_on_disconnect();
+ client->_on_disconnect(was_clean != 0);
}
}
@@ -145,7 +146,7 @@ Error EMWSClient::connect_to_host(String p_host, String p_path, uint16_t p_port,
if (!Module.IDHandler.has($0))
return; // Godot Object is gone!
var was_clean = 0;
- if (event.was_clean)
+ if (event.wasClean)
was_clean = 1;
ccall("_esws_on_close",
"void",
@@ -182,9 +183,9 @@ NetworkedMultiplayerPeer::ConnectionStatus EMWSClient::get_connection_status() c
return CONNECTION_DISCONNECTED;
};
-void EMWSClient::disconnect_from_host() {
+void EMWSClient::disconnect_from_host(int p_code, String p_reason) {
- _peer->close();
+ _peer->close(p_code, p_reason);
};
IP_Address EMWSClient::get_connected_host() const {
diff --git a/modules/websocket/emws_client.h b/modules/websocket/emws_client.h
index 6c2fa23b53..b20633baff 100644
--- a/modules/websocket/emws_client.h
+++ b/modules/websocket/emws_client.h
@@ -48,7 +48,7 @@ public:
Error connect_to_host(String p_host, String p_path, uint16_t p_port, bool p_ssl, PoolVector<String> p_protocol = PoolVector<String>());
Ref<WebSocketPeer> get_peer(int p_peer_id) const;
- void disconnect_from_host();
+ void disconnect_from_host(int p_code = 1000, String p_reason = "");
IP_Address get_connected_host() const;
uint16_t get_connected_port() const;
virtual ConnectionStatus get_connection_status() const;
diff --git a/modules/websocket/emws_peer.cpp b/modules/websocket/emws_peer.cpp
index e0b987b4d7..68f41165eb 100644
--- a/modules/websocket/emws_peer.cpp
+++ b/modules/websocket/emws_peer.cpp
@@ -130,15 +130,17 @@ bool EMWSPeer::is_connected_to_host() const {
return peer_sock != -1;
};
-void EMWSPeer::close() {
+void EMWSPeer::close(int p_code, String p_reason) {
if (peer_sock != -1) {
/* clang-format off */
EM_ASM({
var sock = Module.IDHandler.get($0);
- sock.close();
+ var code = $1;
+ var reason = UTF8ToString($2);
+ sock.close(code, reason);
Module.IDHandler.remove($0);
- }, peer_sock);
+ }, peer_sock, p_code, p_reason.utf8().get_data());
/* clang-format on */
}
peer_sock = -1;
diff --git a/modules/websocket/emws_peer.h b/modules/websocket/emws_peer.h
index e06f725265..a4b2c8f50b 100644
--- a/modules/websocket/emws_peer.h
+++ b/modules/websocket/emws_peer.h
@@ -63,7 +63,7 @@ public:
virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size);
virtual int get_max_packet_size() const { return PACKET_BUFFER_SIZE; };
- virtual void close();
+ virtual void close(int p_code = 1000, String p_reason = "");
virtual bool is_connected_to_host() const;
virtual IP_Address get_connected_host() const;
virtual uint16_t get_connected_port() const;
diff --git a/modules/websocket/emws_server.cpp b/modules/websocket/emws_server.cpp
index 3eb93e4152..ad4a758c0f 100644
--- a/modules/websocket/emws_server.cpp
+++ b/modules/websocket/emws_server.cpp
@@ -68,7 +68,7 @@ int EMWSServer::get_peer_port(int p_peer_id) const {
return 0;
}
-void EMWSServer::disconnect_peer(int p_peer_id) {
+void EMWSServer::disconnect_peer(int p_peer_id, int p_code, String p_reason) {
}
EMWSServer::EMWSServer() {
diff --git a/modules/websocket/emws_server.h b/modules/websocket/emws_server.h
index 9ec4ce72c8..74b689a29b 100644
--- a/modules/websocket/emws_server.h
+++ b/modules/websocket/emws_server.h
@@ -48,7 +48,7 @@ public:
Ref<WebSocketPeer> get_peer(int p_id) const;
IP_Address get_peer_address(int p_peer_id) const;
int get_peer_port(int p_peer_id) const;
- void disconnect_peer(int p_peer_id);
+ void disconnect_peer(int p_peer_id, int p_code = 1000, String p_reason = "");
virtual void poll();
virtual PoolVector<String> get_protocols() const;
diff --git a/modules/websocket/lws_client.cpp b/modules/websocket/lws_client.cpp
index 09f6422058..cd814760e6 100644
--- a/modules/websocket/lws_client.cpp
+++ b/modules/websocket/lws_client.cpp
@@ -129,6 +129,7 @@ int LWSClient::_handle_cb(struct lws *wsi, enum lws_callback_reasons reason, voi
peer->set_wsi(wsi);
peer_data->peer_id = 0;
peer_data->force_close = false;
+ peer_data->clean_close = false;
_on_connect(lws_get_protocol(wsi)->name);
break;
@@ -137,10 +138,18 @@ int LWSClient::_handle_cb(struct lws *wsi, enum lws_callback_reasons reason, voi
destroy_context();
return -1; // We should close the connection (would probably happen anyway)
+ case LWS_CALLBACK_WS_PEER_INITIATED_CLOSE: {
+ int code;
+ String reason = peer->get_close_reason(in, len, code);
+ peer_data->clean_close = true;
+ _on_close_request(code, reason);
+ return 0;
+ }
+
case LWS_CALLBACK_CLIENT_CLOSED:
peer->close();
destroy_context();
- _on_disconnect();
+ _on_disconnect(peer_data->clean_close);
return 0; // We can end here
case LWS_CALLBACK_CLIENT_RECEIVE:
@@ -150,8 +159,10 @@ int LWSClient::_handle_cb(struct lws *wsi, enum lws_callback_reasons reason, voi
break;
case LWS_CALLBACK_CLIENT_WRITEABLE:
- if (peer_data->force_close)
+ if (peer_data->force_close) {
+ peer->send_close_status(wsi);
return -1;
+ }
peer->write_wsi();
break;
@@ -179,13 +190,12 @@ NetworkedMultiplayerPeer::ConnectionStatus LWSClient::get_connection_status() co
return CONNECTION_CONNECTING;
}
-void LWSClient::disconnect_from_host() {
+void LWSClient::disconnect_from_host(int p_code, String p_reason) {
if (context == NULL)
return;
- _peer->close();
- destroy_context();
+ _peer->close(p_code, p_reason);
};
IP_Address LWSClient::get_connected_host() const {
@@ -208,6 +218,7 @@ LWSClient::~LWSClient() {
invalidate_lws_ref(); // We do not want any more callback
disconnect_from_host();
+ destroy_context();
_peer = Ref<LWSPeer>();
};
diff --git a/modules/websocket/lws_client.h b/modules/websocket/lws_client.h
index 8850683cb5..1bbc19f352 100644
--- a/modules/websocket/lws_client.h
+++ b/modules/websocket/lws_client.h
@@ -46,7 +46,7 @@ class LWSClient : public WebSocketClient {
public:
Error connect_to_host(String p_host, String p_path, uint16_t p_port, bool p_ssl, PoolVector<String> p_protocol = PoolVector<String>());
Ref<WebSocketPeer> get_peer(int p_peer_id) const;
- void disconnect_from_host();
+ void disconnect_from_host(int p_code = 1000, String p_reason = "");
IP_Address get_connected_host() const;
uint16_t get_connected_port() const;
virtual ConnectionStatus get_connection_status() const;
diff --git a/modules/websocket/lws_peer.cpp b/modules/websocket/lws_peer.cpp
index 0989357258..245b28b608 100644
--- a/modules/websocket/lws_peer.cpp
+++ b/modules/websocket/lws_peer.cpp
@@ -178,11 +178,49 @@ bool LWSPeer::is_connected_to_host() const {
return wsi != NULL;
};
-void LWSPeer::close() {
+String LWSPeer::get_close_reason(void *in, size_t len, int &r_code) {
+ String s;
+ r_code = 0;
+ if (len < 2) // From docs this should not happen
+ return s;
+
+ const uint8_t *b = (const uint8_t *)in;
+ r_code = b[0] << 8 | b[1];
+
+ if (len > 2) {
+ const char *utf8 = (const char *)&b[2];
+ s.parse_utf8(utf8, len - 2);
+ }
+ return s;
+}
+
+void LWSPeer::send_close_status(struct lws *p_wsi) {
+ if (close_code == -1)
+ return;
+
+ int len = close_reason.size();
+ ERR_FAIL_COND(len > 123); // Maximum allowed reason size in bytes
+
+ lws_close_status code = (lws_close_status)close_code;
+ unsigned char *reason = len > 0 ? (unsigned char *)close_reason.utf8().ptrw() : NULL;
+
+ lws_close_reason(p_wsi, code, reason, len);
+
+ close_code = -1;
+ close_reason = "";
+}
+
+void LWSPeer::close(int p_code, String p_reason) {
if (wsi != NULL) {
+ close_code = p_code;
+ close_reason = p_reason;
PeerData *data = ((PeerData *)lws_wsi_user(wsi));
data->force_close = true;
- lws_callback_on_writable(wsi); // notify that we want to disconnect
+ data->clean_close = true;
+ lws_callback_on_writable(wsi); // Notify that we want to disconnect
+ } else {
+ close_code = -1;
+ close_reason = "";
}
wsi = NULL;
rbw.resize(0);
diff --git a/modules/websocket/lws_peer.h b/modules/websocket/lws_peer.h
index d7d46e3076..571445db01 100644
--- a/modules/websocket/lws_peer.h
+++ b/modules/websocket/lws_peer.h
@@ -53,10 +53,14 @@ private:
WriteMode write_mode;
bool _was_string;
+ int close_code;
+ String close_reason;
+
public:
struct PeerData {
uint32_t peer_id;
bool force_close;
+ bool clean_close;
};
RingBuffer<uint8_t> rbw;
@@ -71,7 +75,7 @@ public:
virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size);
virtual int get_max_packet_size() const { return PACKET_BUFFER_SIZE; };
- virtual void close();
+ virtual void close(int p_code = 1000, String p_reason = "");
virtual bool is_connected_to_host() const;
virtual IP_Address get_connected_host() const;
virtual uint16_t get_connected_port() const;
@@ -83,6 +87,8 @@ public:
void set_wsi(struct lws *wsi);
Error read_wsi(void *in, size_t len);
Error write_wsi();
+ void send_close_status(struct lws *wsi);
+ String get_close_reason(void *in, size_t len, int &r_code);
LWSPeer();
~LWSPeer();
diff --git a/modules/websocket/lws_server.cpp b/modules/websocket/lws_server.cpp
index 4a614f6933..58fa043346 100644
--- a/modules/websocket/lws_server.cpp
+++ b/modules/websocket/lws_server.cpp
@@ -90,20 +90,36 @@ int LWSServer::_handle_cb(struct lws *wsi, enum lws_callback_reasons reason, voi
peer_data->peer_id = id;
peer_data->force_close = false;
-
+ peer_data->clean_close = false;
_on_connect(id, lws_get_protocol(wsi)->name);
break;
}
+ case LWS_CALLBACK_WS_PEER_INITIATED_CLOSE: {
+ if (peer_data == NULL)
+ return 0;
+
+ int32_t id = peer_data->peer_id;
+ if (_peer_map.has(id)) {
+ int code;
+ Ref<LWSPeer> peer = _peer_map[id];
+ String reason = peer->get_close_reason(in, len, code);
+ peer_data->clean_close = true;
+ _on_close_request(id, code, reason);
+ }
+ return 0;
+ }
+
case LWS_CALLBACK_CLOSED: {
if (peer_data == NULL)
return 0;
int32_t id = peer_data->peer_id;
+ bool clean = peer_data->clean_close;
if (_peer_map.has(id)) {
_peer_map[id]->close();
_peer_map.erase(id);
}
- _on_disconnect(id);
+ _on_disconnect(id, clean);
return 0; // we can end here
}
@@ -118,10 +134,15 @@ int LWSServer::_handle_cb(struct lws *wsi, enum lws_callback_reasons reason, voi
}
case LWS_CALLBACK_SERVER_WRITEABLE: {
- if (peer_data->force_close)
+ int id = peer_data->peer_id;
+ if (peer_data->force_close) {
+ if (_peer_map.has(id)) {
+ Ref<LWSPeer> peer = _peer_map[id];
+ peer->send_close_status(wsi);
+ }
return -1;
+ }
- int id = peer_data->peer_id;
if (_peer_map.has(id))
static_cast<Ref<LWSPeer> >(_peer_map[id])->write_wsi();
break;
@@ -164,10 +185,10 @@ int LWSServer::get_peer_port(int p_peer_id) const {
return _peer_map[p_peer_id]->get_connected_port();
}
-void LWSServer::disconnect_peer(int p_peer_id) {
+void LWSServer::disconnect_peer(int p_peer_id, int p_code, String p_reason) {
ERR_FAIL_COND(!has_peer(p_peer_id));
- get_peer(p_peer_id)->close();
+ get_peer(p_peer_id)->close(p_code, p_reason);
}
LWSServer::LWSServer() {
diff --git a/modules/websocket/lws_server.h b/modules/websocket/lws_server.h
index 9e3fb9b775..346773ebc4 100644
--- a/modules/websocket/lws_server.h
+++ b/modules/websocket/lws_server.h
@@ -54,7 +54,7 @@ public:
Ref<WebSocketPeer> get_peer(int p_id) const;
IP_Address get_peer_address(int p_peer_id) const;
int get_peer_port(int p_peer_id) const;
- void disconnect_peer(int p_peer_id);
+ void disconnect_peer(int p_peer_id, int p_code = 1000, String p_reason = "");
virtual void poll() { _lws_poll(); }
LWSServer();
diff --git a/modules/websocket/websocket_client.cpp b/modules/websocket/websocket_client.cpp
index 7701163085..f9b94dc519 100644
--- a/modules/websocket/websocket_client.cpp
+++ b/modules/websocket/websocket_client.cpp
@@ -107,12 +107,17 @@ void WebSocketClient::_on_connect(String p_protocol) {
}
}
-void WebSocketClient::_on_disconnect() {
+void WebSocketClient::_on_close_request(int p_code, String p_reason) {
+
+ emit_signal("server_close_request", p_code, p_reason);
+}
+
+void WebSocketClient::_on_disconnect(bool p_was_clean) {
if (_is_multiplayer) {
emit_signal("connection_failed");
} else {
- emit_signal("connection_closed");
+ emit_signal("connection_closed", p_was_clean);
}
}
@@ -127,7 +132,7 @@ void WebSocketClient::_on_error() {
void WebSocketClient::_bind_methods() {
ClassDB::bind_method(D_METHOD("connect_to_url", "url", "protocols", "gd_mp_api"), &WebSocketClient::connect_to_url, DEFVAL(PoolVector<String>()), DEFVAL(false));
- ClassDB::bind_method(D_METHOD("disconnect_from_host"), &WebSocketClient::disconnect_from_host);
+ ClassDB::bind_method(D_METHOD("disconnect_from_host", "code", "reason"), &WebSocketClient::disconnect_from_host, DEFVAL(1000), DEFVAL(""));
ClassDB::bind_method(D_METHOD("set_verify_ssl_enabled", "enabled"), &WebSocketClient::set_verify_ssl_enabled);
ClassDB::bind_method(D_METHOD("is_verify_ssl_enabled"), &WebSocketClient::is_verify_ssl_enabled);
@@ -135,6 +140,7 @@ void WebSocketClient::_bind_methods() {
ADD_SIGNAL(MethodInfo("data_received"));
ADD_SIGNAL(MethodInfo("connection_established", PropertyInfo(Variant::STRING, "protocol")));
- ADD_SIGNAL(MethodInfo("connection_closed"));
+ ADD_SIGNAL(MethodInfo("server_close_request", PropertyInfo(Variant::INT, "code"), PropertyInfo(Variant::STRING, "reason")));
+ ADD_SIGNAL(MethodInfo("connection_closed", PropertyInfo(Variant::BOOL, "was_clean_close")));
ADD_SIGNAL(MethodInfo("connection_error"));
}
diff --git a/modules/websocket/websocket_client.h b/modules/websocket/websocket_client.h
index 6165f37d40..948f128e9f 100644
--- a/modules/websocket/websocket_client.h
+++ b/modules/websocket/websocket_client.h
@@ -53,7 +53,7 @@ public:
virtual void poll() = 0;
virtual Error connect_to_host(String p_host, String p_path, uint16_t p_port, bool p_ssl, PoolVector<String> p_protocol = PoolVector<String>()) = 0;
- virtual void disconnect_from_host() = 0;
+ virtual void disconnect_from_host(int p_code = 1000, String p_reason = "") = 0;
virtual IP_Address get_connected_host() const = 0;
virtual uint16_t get_connected_port() const = 0;
@@ -62,7 +62,8 @@ public:
void _on_peer_packet();
void _on_connect(String p_protocol);
- void _on_disconnect();
+ void _on_close_request(int p_code, String p_reason);
+ void _on_disconnect(bool p_was_clean);
void _on_error();
WebSocketClient();
diff --git a/modules/websocket/websocket_peer.cpp b/modules/websocket/websocket_peer.cpp
index 61f783e377..3ecb32ce19 100644
--- a/modules/websocket/websocket_peer.cpp
+++ b/modules/websocket/websocket_peer.cpp
@@ -42,7 +42,7 @@ void WebSocketPeer::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_write_mode", "mode"), &WebSocketPeer::set_write_mode);
ClassDB::bind_method(D_METHOD("is_connected_to_host"), &WebSocketPeer::is_connected_to_host);
ClassDB::bind_method(D_METHOD("was_string_packet"), &WebSocketPeer::was_string_packet);
- ClassDB::bind_method(D_METHOD("close"), &WebSocketPeer::close);
+ ClassDB::bind_method(D_METHOD("close", "code", "reason"), &WebSocketPeer::close, DEFVAL(1000), DEFVAL(""));
ClassDB::bind_method(D_METHOD("get_connected_host"), &WebSocketPeer::get_connected_host);
ClassDB::bind_method(D_METHOD("get_connected_port"), &WebSocketPeer::get_connected_port);
diff --git a/modules/websocket/websocket_peer.h b/modules/websocket/websocket_peer.h
index ad451e9cc7..5918fda3c2 100644
--- a/modules/websocket/websocket_peer.h
+++ b/modules/websocket/websocket_peer.h
@@ -58,7 +58,7 @@ public:
virtual WriteMode get_write_mode() const = 0;
virtual void set_write_mode(WriteMode p_mode) = 0;
- virtual void close() = 0;
+ virtual void close(int p_code = 1000, String p_reason = "") = 0;
virtual bool is_connected_to_host() const = 0;
virtual IP_Address get_connected_host() const = 0;
diff --git a/modules/websocket/websocket_server.cpp b/modules/websocket/websocket_server.cpp
index 53dd7b51b7..c631ed70d5 100644
--- a/modules/websocket/websocket_server.cpp
+++ b/modules/websocket/websocket_server.cpp
@@ -46,9 +46,10 @@ void WebSocketServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("has_peer", "id"), &WebSocketServer::has_peer);
ClassDB::bind_method(D_METHOD("get_peer_address", "id"), &WebSocketServer::get_peer_address);
ClassDB::bind_method(D_METHOD("get_peer_port", "id"), &WebSocketServer::get_peer_port);
- ClassDB::bind_method(D_METHOD("disconnect_peer", "id"), &WebSocketServer::disconnect_peer);
+ ClassDB::bind_method(D_METHOD("disconnect_peer", "id", "code", "reason"), &WebSocketServer::disconnect_peer, DEFVAL(1000), DEFVAL(""));
- ADD_SIGNAL(MethodInfo("client_disconnected", PropertyInfo(Variant::INT, "id")));
+ ADD_SIGNAL(MethodInfo("client_close_request", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::INT, "code"), PropertyInfo(Variant::STRING, "reason")));
+ ADD_SIGNAL(MethodInfo("client_disconnected", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::BOOL, "was_clean_close")));
ADD_SIGNAL(MethodInfo("client_connected", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::STRING, "protocol")));
ADD_SIGNAL(MethodInfo("data_received", PropertyInfo(Variant::INT, "id")));
}
@@ -85,13 +86,18 @@ void WebSocketServer::_on_connect(int32_t p_peer_id, String p_protocol) {
}
}
-void WebSocketServer::_on_disconnect(int32_t p_peer_id) {
+void WebSocketServer::_on_disconnect(int32_t p_peer_id, bool p_was_clean) {
if (_is_multiplayer) {
// Send delete to clients
_send_del(p_peer_id);
emit_signal("peer_disconnected", p_peer_id);
} else {
- emit_signal("client_disconnected", p_peer_id);
+ emit_signal("client_disconnected", p_peer_id, p_was_clean);
}
}
+
+void WebSocketServer::_on_close_request(int32_t p_peer_id, int p_code, String p_reason) {
+
+ emit_signal("client_close_request", p_peer_id, p_code, p_reason);
+}
diff --git a/modules/websocket/websocket_server.h b/modules/websocket/websocket_server.h
index 64935f8a58..156f25897c 100644
--- a/modules/websocket/websocket_server.h
+++ b/modules/websocket/websocket_server.h
@@ -54,11 +54,12 @@ public:
virtual IP_Address get_peer_address(int p_peer_id) const = 0;
virtual int get_peer_port(int p_peer_id) const = 0;
- virtual void disconnect_peer(int p_peer_id) = 0;
+ virtual void disconnect_peer(int p_peer_id, int p_code = 1000, String p_reason = "") = 0;
void _on_peer_packet(int32_t p_peer_id);
void _on_connect(int32_t p_peer_id, String p_protocol);
- void _on_disconnect(int32_t p_peer_id);
+ void _on_disconnect(int32_t p_peer_id, bool p_was_clean);
+ void _on_close_request(int32_t p_peer_id, int p_code, String p_reason);
WebSocketServer();
~WebSocketServer();
diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp
index fa9474bfe8..6ec7d27464 100644
--- a/platform/android/export/export.cpp
+++ b/platform/android/export/export.cpp
@@ -344,6 +344,7 @@ class EditorExportAndroid : public EditorExportPlatform {
}
d.name = vendor + " " + device;
+ if (device == String()) continue;
}
ndevices.push_back(d);
diff --git a/platform/osx/crash_handler_osx.mm b/platform/osx/crash_handler_osx.mm
index 9ad3437f0f..490155bb24 100644
--- a/platform/osx/crash_handler_osx.mm
+++ b/platform/osx/crash_handler_osx.mm
@@ -68,8 +68,9 @@ static uint64_t load_address() {
}
static void handle_crash(int sig) {
- if (OS::get_singleton() == NULL)
- return;
+ if (OS::get_singleton() == NULL) {
+ abort();
+ }
void *bt_buffer[256];
size_t size = backtrace(bt_buffer, 256);
@@ -151,6 +152,7 @@ CrashHandler::CrashHandler() {
}
CrashHandler::~CrashHandler() {
+ disable();
}
void CrashHandler::disable() {
diff --git a/platform/server/detect.py b/platform/server/detect.py
index 266b0c5cc9..e921bf4a5f 100644
--- a/platform/server/detect.py
+++ b/platform/server/detect.py
@@ -56,7 +56,7 @@ def configure(env):
## Compiler configuration
if env['use_llvm']:
- if ('clang++' not in env['CXX']):
+ if ('clang++' not in os.path.basename(env['CXX'])):
env["CC"] = "clang"
env["CXX"] = "clang++"
env["LINK"] = "clang++"
diff --git a/platform/x11/crash_handler_x11.cpp b/platform/x11/crash_handler_x11.cpp
index ab9275e49f..79c3d9aece 100644
--- a/platform/x11/crash_handler_x11.cpp
+++ b/platform/x11/crash_handler_x11.cpp
@@ -45,8 +45,9 @@
#include <stdlib.h>
static void handle_crash(int sig) {
- if (OS::get_singleton() == NULL)
- return;
+ if (OS::get_singleton() == NULL) {
+ abort();
+ }
void *bt_buffer[256];
size_t size = backtrace(bt_buffer, 256);
@@ -119,6 +120,7 @@ CrashHandler::CrashHandler() {
}
CrashHandler::~CrashHandler() {
+ disable();
}
void CrashHandler::disable() {
diff --git a/platform/x11/detect.py b/platform/x11/detect.py
index 6a7a426804..905546e724 100644
--- a/platform/x11/detect.py
+++ b/platform/x11/detect.py
@@ -86,7 +86,7 @@ def configure(env):
env.Prepend(CCFLAGS=['-O3', '-ffast-math'])
else: #optimize for size
env.Prepend(CCFLAGS=['-Os'])
-
+
if (env["debug_symbols"] == "yes"):
env.Prepend(CCFLAGS=['-g1'])
if (env["debug_symbols"] == "full"):
@@ -115,12 +115,12 @@ def configure(env):
## Compiler configuration
- if 'CXX' in env and 'clang' in env['CXX']:
+ if 'CXX' in env and 'clang' in os.path.basename(env['CXX']):
# Convenience check to enforce the use_llvm overrides when CXX is clang(++)
env['use_llvm'] = True
if env['use_llvm']:
- if ('clang++' not in env['CXX']):
+ if ('clang++' not in os.path.basename(env['CXX'])):
env["CC"] = "clang"
env["CXX"] = "clang++"
env["LINK"] = "clang++"
diff --git a/scene/3d/visual_instance.cpp b/scene/3d/visual_instance.cpp
index 767518dc83..6dc821c3f5 100644
--- a/scene/3d/visual_instance.cpp
+++ b/scene/3d/visual_instance.cpp
@@ -294,7 +294,7 @@ void GeometryInstance::_bind_methods() {
ADD_GROUP("Geometry", "");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material_override", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial,SpatialMaterial"), "set_material_override", "get_material_override");
ADD_PROPERTY(PropertyInfo(Variant::INT, "cast_shadow", PROPERTY_HINT_ENUM, "Off,On,Double-Sided,Shadows Only"), "set_cast_shadows_setting", "get_cast_shadows_setting");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "extra_cull_margin", PROPERTY_HINT_RANGE, "0,16384,0"), "set_extra_cull_margin", "get_extra_cull_margin");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "extra_cull_margin", PROPERTY_HINT_RANGE, "0,16384,0.01"), "set_extra_cull_margin", "get_extra_cull_margin");
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "use_in_baked_light"), "set_flag", "get_flag", FLAG_USE_BAKED_LIGHT);
ADD_GROUP("LOD", "lod_");
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index 12349e0983..dc18895298 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -1993,7 +1993,7 @@ Control *Control::find_prev_valid_focus() const {
if (!from) {
- ERR_EXPLAIN("Prev focus node is not a control: " + n->get_name());
+ ERR_EXPLAIN("Previous focus node is not a control: " + n->get_name());
ERR_FAIL_V(NULL);
}
} else {
diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp
index 5f162a3652..283d66d8de 100644
--- a/scene/gui/file_dialog.cpp
+++ b/scene/gui/file_dialog.cpp
@@ -349,7 +349,7 @@ void FileDialog::_tree_selected() {
file->set_text(d["name"]);
} else if (mode == MODE_OPEN_DIR) {
- get_ok()->set_text(RTR("Select this Folder"));
+ get_ok()->set_text(RTR("Select This Folder"));
}
get_ok()->set_disabled(_is_open_should_be_disabled());
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index fa5019a6f7..1069470ed3 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -320,14 +320,17 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
Color color;
Color font_color_shadow;
bool underline = false;
+ bool strikethrough = false;
if (p_mode == PROCESS_DRAW) {
color = _find_color(text, p_base_color);
font_color_shadow = _find_color(text, p_font_color_shadow);
- underline = _find_underline(text);
- if (_find_meta(text, &meta) && underline_meta) {
+ if (_find_underline(text) || (_find_meta(text, &meta) && underline_meta)) {
underline = true;
+ } else if (_find_strikethrough(text)) {
+
+ strikethrough = true;
}
} else if (p_mode == PROCESS_CACHE) {
@@ -469,6 +472,15 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
underline_width *= EDSCALE;
#endif
VS::get_singleton()->canvas_item_add_line(ci, p_ofs + Point2(align_ofs + wofs, uy), p_ofs + Point2(align_ofs + wofs + w, uy), uc, underline_width);
+ } else if (strikethrough) {
+ Color uc = color;
+ uc.a *= 0.5;
+ int uy = y + lh / 2 - line_descent + 2;
+ float strikethrough_width = 1.0;
+#ifdef TOOLS_ENABLED
+ strikethrough_width *= EDSCALE;
+#endif
+ VS::get_singleton()->canvas_item_add_line(ci, p_ofs + Point2(align_ofs + wofs, uy), p_ofs + Point2(align_ofs + wofs + w, uy), uc, strikethrough_width);
}
}
@@ -1227,6 +1239,23 @@ bool RichTextLabel::_find_underline(Item *p_item) {
return false;
}
+bool RichTextLabel::_find_strikethrough(Item *p_item) {
+
+ Item *item = p_item;
+
+ while (item) {
+
+ if (item->type == ITEM_STRIKETHROUGH) {
+
+ return true;
+ }
+
+ item = item->parent;
+ }
+
+ return false;
+}
+
bool RichTextLabel::_find_meta(Item *p_item, Variant *r_meta) {
Item *item = p_item;
@@ -1458,6 +1487,7 @@ void RichTextLabel::push_font(const Ref<Font> &p_font) {
item->font = p_font;
_add_item(item, true);
}
+
void RichTextLabel::push_color(const Color &p_color) {
ERR_FAIL_COND(current->type == ITEM_TABLE);
@@ -1466,6 +1496,7 @@ void RichTextLabel::push_color(const Color &p_color) {
item->color = p_color;
_add_item(item, true);
}
+
void RichTextLabel::push_underline() {
ERR_FAIL_COND(current->type == ITEM_TABLE);
@@ -1474,6 +1505,14 @@ void RichTextLabel::push_underline() {
_add_item(item, true);
}
+void RichTextLabel::push_strikethrough() {
+
+ ERR_FAIL_COND(current->type == ITEM_TABLE);
+ ItemStrikethrough *item = memnew(ItemStrikethrough);
+
+ _add_item(item, true);
+}
+
void RichTextLabel::push_align(Align p_align) {
ERR_FAIL_COND(current->type == ITEM_TABLE);
@@ -1683,7 +1722,7 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
}
if (brk_pos == p_bbcode.length())
- break; //nothing else o add
+ break; //nothing else to add
int brk_end = p_bbcode.find("]", brk_pos + 1);
@@ -1749,7 +1788,7 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
int columns = tag.substr(6, tag.length()).to_int();
if (columns < 1)
columns = 1;
- //use monospace font
+
push_table(columns);
pos = brk_end + 1;
tag_stack.push_front("table");
@@ -1763,7 +1802,7 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
int ratio = tag.substr(5, tag.length()).to_int();
if (ratio < 1)
ratio = 1;
- //use monospace font
+
set_table_column_expand(get_current_table_column(), true, ratio);
push_cell();
pos = brk_end + 1;
@@ -1776,43 +1815,37 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
tag_stack.push_front(tag);
} else if (tag == "s") {
- //use strikethrough (not supported underline instead)
- push_underline();
+ //use strikethrough
+ push_strikethrough();
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "center") {
- //use underline
push_align(ALIGN_CENTER);
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "fill") {
- //use underline
push_align(ALIGN_FILL);
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "right") {
- //use underline
push_align(ALIGN_RIGHT);
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "ul") {
- //use underline
push_list(LIST_DOTS);
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "ol") {
- //use underline
push_list(LIST_NUMBERS);
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "indent") {
- //use underline
indent_level++;
push_indent(indent_level);
pos = brk_end + 1;
@@ -1820,7 +1853,6 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
} else if (tag == "url") {
- //use strikethrough (not supported underline instead)
int end = p_bbcode.find("[", brk_end);
if (end == -1)
end = p_bbcode.length();
@@ -1838,7 +1870,6 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
tag_stack.push_front("url");
} else if (tag == "img") {
- //use strikethrough (not supported underline instead)
int end = p_bbcode.find("[", brk_end);
if (end == -1)
end = p_bbcode.length();
@@ -2145,6 +2176,7 @@ void RichTextLabel::_bind_methods() {
ClassDB::bind_method(D_METHOD("push_list", "type"), &RichTextLabel::push_list);
ClassDB::bind_method(D_METHOD("push_meta", "data"), &RichTextLabel::push_meta);
ClassDB::bind_method(D_METHOD("push_underline"), &RichTextLabel::push_underline);
+ ClassDB::bind_method(D_METHOD("push_strikethrough"), &RichTextLabel::push_strikethrough);
ClassDB::bind_method(D_METHOD("push_table", "columns"), &RichTextLabel::push_table);
ClassDB::bind_method(D_METHOD("set_table_column_expand", "column", "expand", "ratio"), &RichTextLabel::set_table_column_expand);
ClassDB::bind_method(D_METHOD("push_cell"), &RichTextLabel::push_cell);
@@ -2233,6 +2265,7 @@ void RichTextLabel::_bind_methods() {
BIND_ENUM_CONSTANT(ITEM_FONT);
BIND_ENUM_CONSTANT(ITEM_COLOR);
BIND_ENUM_CONSTANT(ITEM_UNDERLINE);
+ BIND_ENUM_CONSTANT(ITEM_STRIKETHROUGH);
BIND_ENUM_CONSTANT(ITEM_ALIGN);
BIND_ENUM_CONSTANT(ITEM_INDENT);
BIND_ENUM_CONSTANT(ITEM_LIST);
diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h
index 06e9b8efe3..c2e5712b9d 100644
--- a/scene/gui/rich_text_label.h
+++ b/scene/gui/rich_text_label.h
@@ -62,6 +62,7 @@ public:
ITEM_FONT,
ITEM_COLOR,
ITEM_UNDERLINE,
+ ITEM_STRIKETHROUGH,
ITEM_ALIGN,
ITEM_INDENT,
ITEM_LIST,
@@ -164,6 +165,11 @@ private:
ItemUnderline() { type = ITEM_UNDERLINE; }
};
+ struct ItemStrikethrough : public Item {
+
+ ItemStrikethrough() { type = ITEM_STRIKETHROUGH; }
+ };
+
struct ItemMeta : public Item {
Variant meta;
@@ -277,6 +283,7 @@ private:
Align _find_align(Item *p_item);
Color _find_color(Item *p_item, const Color &p_default_color);
bool _find_underline(Item *p_item);
+ bool _find_strikethrough(Item *p_item);
bool _find_meta(Item *p_item, Variant *r_meta);
void _update_scroll();
@@ -307,6 +314,7 @@ public:
void push_font(const Ref<Font> &p_font);
void push_color(const Color &p_color);
void push_underline();
+ void push_strikethrough();
void push_align(Align p_align);
void push_indent(int p_level);
void push_list(ListType p_list);
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 24b9083964..23e4c26695 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -159,7 +159,7 @@ void TreeItem::set_text(int p_column, String p_text) {
ERR_FAIL_INDEX(p_column, cells.size());
cells.write[p_column].text = p_text;
- if (cells[p_column].mode == TreeItem::CELL_MODE_RANGE || cells[p_column].mode == TreeItem::CELL_MODE_RANGE_EXPRESSION) {
+ if (cells[p_column].mode == TreeItem::CELL_MODE_RANGE) {
Vector<String> strings = p_text.split(",");
cells.write[p_column].min = INT_MAX;
@@ -791,7 +791,6 @@ void TreeItem::_bind_methods() {
BIND_ENUM_CONSTANT(CELL_MODE_STRING);
BIND_ENUM_CONSTANT(CELL_MODE_CHECK);
BIND_ENUM_CONSTANT(CELL_MODE_RANGE);
- BIND_ENUM_CONSTANT(CELL_MODE_RANGE_EXPRESSION);
BIND_ENUM_CONSTANT(CELL_MODE_ICON);
BIND_ENUM_CONSTANT(CELL_MODE_CUSTOM);
@@ -1245,9 +1244,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
//font->draw( ci, text_pos, p_item->cells[i].text, col,item_rect.size.x-check_w );
} break;
- case TreeItem::CELL_MODE_RANGE:
- case TreeItem::CELL_MODE_RANGE_EXPRESSION: {
-
+ case TreeItem::CELL_MODE_RANGE: {
if (p_item->cells[i].text != "") {
if (!p_item->cells[i].editable)
@@ -1821,9 +1818,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
//p_item->edited_signal.call(col);
} break;
- case TreeItem::CELL_MODE_RANGE:
- case TreeItem::CELL_MODE_RANGE_EXPRESSION: {
-
+ case TreeItem::CELL_MODE_RANGE: {
if (c.text != "") {
//if (x >= (get_column_width(col)-item_h/2)) {
@@ -2010,21 +2005,6 @@ void Tree::text_editor_enter(String p_text) {
//popup_edited_item->edited_signal.call( popup_edited_item_col );
} break;
- case TreeItem::CELL_MODE_RANGE_EXPRESSION: {
-
- if (evaluator)
- c.val = evaluator->eval(p_text);
- else
- c.val = p_text.to_double();
-
- if (c.step > 0)
- c.val = Math::stepify(c.val, c.step);
- if (c.val < c.min)
- c.val = c.min;
- else if (c.val > c.max)
- c.val = c.max;
-
- } break;
default: { ERR_FAIL(); }
}
@@ -2453,7 +2433,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
update();
}
- if (pressing_for_editor && popup_edited_item && (popup_edited_item->get_cell_mode(popup_edited_item_col) == TreeItem::CELL_MODE_RANGE || popup_edited_item->get_cell_mode(popup_edited_item_col) == TreeItem::CELL_MODE_RANGE_EXPRESSION)) {
+ if (pressing_for_editor && popup_edited_item && (popup_edited_item->get_cell_mode(popup_edited_item_col) == TreeItem::CELL_MODE_RANGE)) {
//range drag
if (!range_drag_enabled) {
@@ -2697,7 +2677,7 @@ bool Tree::edit_selected() {
item_edited(col, s);
return true;
- } else if ((c.mode == TreeItem::CELL_MODE_RANGE || c.mode == TreeItem::CELL_MODE_RANGE_EXPRESSION) && c.text != "") {
+ } else if (c.mode == TreeItem::CELL_MODE_RANGE && c.text != "") {
popup_menu->clear();
for (int i = 0; i < c.text.get_slice_count(","); i++) {
@@ -2713,7 +2693,7 @@ bool Tree::edit_selected() {
popup_edited_item_col = col;
return true;
- } else if (c.mode == TreeItem::CELL_MODE_STRING || c.mode == TreeItem::CELL_MODE_RANGE || c.mode == TreeItem::CELL_MODE_RANGE_EXPRESSION) {
+ } else if (c.mode == TreeItem::CELL_MODE_STRING || c.mode == TreeItem::CELL_MODE_RANGE) {
Vector2 ofs(0, (text_editor->get_size().height - rect.size.height) / 2);
Point2i textedpos = get_global_position() + rect.position - ofs;
@@ -2723,7 +2703,7 @@ bool Tree::edit_selected() {
text_editor->set_text(c.mode == TreeItem::CELL_MODE_STRING ? c.text : String::num(c.val, Math::step_decimals(c.step)));
text_editor->select_all();
- if (c.mode == TreeItem::CELL_MODE_RANGE || c.mode == TreeItem::CELL_MODE_RANGE_EXPRESSION) {
+ if (c.mode == TreeItem::CELL_MODE_RANGE) {
value_editor->set_position(textedpos + Point2i(0, text_editor->get_size().height));
value_editor->set_size(Size2(rect.size.width, 1));
@@ -3713,10 +3693,6 @@ bool Tree::is_folding_hidden() const {
return hide_folding;
}
-void Tree::set_value_evaluator(ValueEvaluator *p_evaluator) {
- evaluator = p_evaluator;
-}
-
void Tree::set_drop_mode_flags(int p_flags) {
if (drop_mode_flags == p_flags)
return;
@@ -3934,8 +3910,6 @@ Tree::Tree() {
hide_folding = false;
- evaluator = NULL;
-
drop_mode_flags = 0;
drop_mode_over = NULL;
drop_mode_section = 0;
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index 205cdbfb7e..551600109e 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -31,7 +31,6 @@
#ifndef TREE_H
#define TREE_H
-#include "core/helper/value_evaluator.h"
#include "scene/gui/control.h"
#include "scene/gui/line_edit.h"
#include "scene/gui/popup_menu.h"
@@ -504,8 +503,6 @@ private:
bool hide_folding;
- ValueEvaluator *evaluator;
-
int _count_selected_items(TreeItem *p_from) const;
void _go_left();
void _go_right();
@@ -601,8 +598,6 @@ public:
void set_allow_reselect(bool p_allow);
bool get_allow_reselect() const;
- void set_value_evaluator(ValueEvaluator *p_evaluator);
-
Tree();
~Tree();
};
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index 06bc12d774..d3282c6ada 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -1348,6 +1348,19 @@ Node *Node::get_parent() const {
return data.parent;
}
+Node *Node::find_parent(const String &p_mask) const {
+
+ Node *p = data.parent;
+ while (p) {
+
+ if (p->data.name.operator String().match(p_mask))
+ return p;
+ p = p->data.parent;
+ }
+
+ return NULL;
+}
+
bool Node::is_a_parent_of(const Node *p_node) const {
ERR_FAIL_NULL_V(p_node, false);
@@ -2629,6 +2642,7 @@ void Node::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_node", "path"), &Node::get_node);
ClassDB::bind_method(D_METHOD("get_parent"), &Node::get_parent);
ClassDB::bind_method(D_METHOD("find_node", "mask", "recursive", "owned"), &Node::find_node, DEFVAL(true), DEFVAL(true));
+ ClassDB::bind_method(D_METHOD("find_parent", "mask"), &Node::find_parent);
ClassDB::bind_method(D_METHOD("has_node_and_resource", "path"), &Node::has_node_and_resource);
ClassDB::bind_method(D_METHOD("get_node_and_resource", "path"), &Node::_get_node_and_resource);
diff --git a/scene/main/node.h b/scene/main/node.h
index 8d6c558e93..a7baebc9c2 100644
--- a/scene/main/node.h
+++ b/scene/main/node.h
@@ -257,6 +257,8 @@ public:
Node *get_node_and_resource(const NodePath &p_path, RES &r_res, Vector<StringName> &r_leftover_subpath, bool p_last_is_property = true) const;
Node *get_parent() const;
+ Node *find_parent(const String &p_mask) const;
+
_FORCE_INLINE_ SceneTree *get_tree() const {
ERR_FAIL_COND_V(!data.tree, NULL);
return data.tree;
diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp
index 16be6dad7d..aebc96aad7 100644
--- a/scene/main/scene_tree.cpp
+++ b/scene/main/scene_tree.cpp
@@ -1602,7 +1602,7 @@ void SceneTree::_live_edit_duplicate_node_func(const NodePath &p_at, const Strin
continue;
Node *n2 = n->get_node(p_at);
- Node *dup = n2->duplicate(true);
+ Node *dup = n2->duplicate(Node::DUPLICATE_SIGNALS | Node::DUPLICATE_GROUPS | Node::DUPLICATE_SCRIPTS);
if (!dup)
continue;
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp
index 2cf802a2da..cc8685b952 100644
--- a/scene/resources/material.cpp
+++ b/scene/resources/material.cpp
@@ -562,7 +562,9 @@ void SpatialMaterial::_update_shader() {
if (flags[FLAG_SRGB_VERTEX_COLOR]) {
- code += "\tCOLOR.rgb = mix( pow((COLOR.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)), vec3(2.4)), COLOR.rgb* (1.0 / 12.92), lessThan(COLOR.rgb,vec3(0.04045)) );\n";
+ code += "\tif (!OUTPUT_IS_SRGB) {\n";
+ code += "\t\tCOLOR.rgb = mix( pow((COLOR.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)), vec3(2.4)), COLOR.rgb* (1.0 / 12.92), lessThan(COLOR.rgb,vec3(0.04045)) );\n";
+ code += "\t}\n";
}
if (flags[FLAG_USE_POINT_SIZE]) {
diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp
index 4718eb14a5..417617fa5b 100644
--- a/servers/visual/shader_language.cpp
+++ b/servers/visual/shader_language.cpp
@@ -1622,33 +1622,51 @@ const ShaderLanguage::BuiltinFuncDef ShaderLanguage::builtin_func_defs[] = {
{ "min", TYPE_FLOAT, { TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } },
{ "min", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
+ { "min", TYPE_VEC2, { TYPE_VEC2, TYPE_FLOAT, TYPE_VOID } },
{ "min", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } },
+ { "min", TYPE_VEC3, { TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } },
{ "min", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } },
+ { "min", TYPE_VEC4, { TYPE_VEC4, TYPE_FLOAT, TYPE_VOID } },
{ "min", TYPE_INT, { TYPE_INT, TYPE_INT, TYPE_VOID } },
{ "min", TYPE_IVEC2, { TYPE_IVEC2, TYPE_IVEC2, TYPE_VOID } },
+ { "min", TYPE_IVEC2, { TYPE_IVEC2, TYPE_INT, TYPE_VOID } },
{ "min", TYPE_IVEC3, { TYPE_IVEC3, TYPE_IVEC3, TYPE_VOID } },
+ { "min", TYPE_IVEC3, { TYPE_IVEC3, TYPE_INT, TYPE_VOID } },
{ "min", TYPE_IVEC4, { TYPE_IVEC4, TYPE_IVEC4, TYPE_VOID } },
+ { "min", TYPE_IVEC4, { TYPE_IVEC4, TYPE_INT, TYPE_VOID } },
{ "min", TYPE_UINT, { TYPE_UINT, TYPE_UINT, TYPE_VOID } },
{ "min", TYPE_UVEC2, { TYPE_UVEC2, TYPE_UVEC2, TYPE_VOID } },
+ { "min", TYPE_UVEC2, { TYPE_UVEC2, TYPE_UINT, TYPE_VOID } },
{ "min", TYPE_UVEC3, { TYPE_UVEC3, TYPE_UVEC3, TYPE_VOID } },
+ { "min", TYPE_UVEC3, { TYPE_UVEC3, TYPE_UINT, TYPE_VOID } },
{ "min", TYPE_UVEC4, { TYPE_UVEC4, TYPE_UVEC4, TYPE_VOID } },
+ { "min", TYPE_UVEC4, { TYPE_UVEC4, TYPE_UINT, TYPE_VOID } },
{ "max", TYPE_FLOAT, { TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } },
{ "max", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
+ { "max", TYPE_VEC2, { TYPE_VEC2, TYPE_FLOAT, TYPE_VOID } },
{ "max", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } },
+ { "max", TYPE_VEC3, { TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } },
{ "max", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } },
+ { "max", TYPE_VEC4, { TYPE_VEC4, TYPE_FLOAT, TYPE_VOID } },
{ "max", TYPE_INT, { TYPE_INT, TYPE_INT, TYPE_VOID } },
{ "max", TYPE_IVEC2, { TYPE_IVEC2, TYPE_IVEC2, TYPE_VOID } },
+ { "max", TYPE_IVEC2, { TYPE_IVEC2, TYPE_INT, TYPE_VOID } },
{ "max", TYPE_IVEC3, { TYPE_IVEC3, TYPE_IVEC3, TYPE_VOID } },
+ { "max", TYPE_IVEC3, { TYPE_IVEC3, TYPE_INT, TYPE_VOID } },
{ "max", TYPE_IVEC4, { TYPE_IVEC4, TYPE_IVEC4, TYPE_VOID } },
+ { "max", TYPE_IVEC4, { TYPE_IVEC4, TYPE_INT, TYPE_VOID } },
{ "max", TYPE_UINT, { TYPE_UINT, TYPE_UINT, TYPE_VOID } },
{ "max", TYPE_UVEC2, { TYPE_UVEC2, TYPE_UVEC2, TYPE_VOID } },
+ { "max", TYPE_UVEC2, { TYPE_UVEC2, TYPE_UINT, TYPE_VOID } },
{ "max", TYPE_UVEC3, { TYPE_UVEC3, TYPE_UVEC3, TYPE_VOID } },
+ { "max", TYPE_UVEC3, { TYPE_UVEC3, TYPE_UINT, TYPE_VOID } },
{ "max", TYPE_UVEC4, { TYPE_UVEC4, TYPE_UVEC4, TYPE_VOID } },
+ { "max", TYPE_UVEC4, { TYPE_UVEC4, TYPE_UINT, TYPE_VOID } },
{ "clamp", TYPE_FLOAT, { TYPE_FLOAT, TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } },
{ "clamp", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
diff --git a/servers/visual/shader_types.cpp b/servers/visual/shader_types.cpp
index caa454b98e..57e8d86468 100644
--- a/servers/visual/shader_types.cpp
+++ b/servers/visual/shader_types.cpp
@@ -78,6 +78,7 @@ ShaderTypes::ShaderTypes() {
shader_modes[VS::SHADER_SPATIAL].functions["vertex"].built_ins["INV_PROJECTION_MATRIX"] = ShaderLanguage::TYPE_MAT4;
shader_modes[VS::SHADER_SPATIAL].functions["vertex"].built_ins["TIME"] = constt(ShaderLanguage::TYPE_FLOAT);
shader_modes[VS::SHADER_SPATIAL].functions["vertex"].built_ins["VIEWPORT_SIZE"] = constt(ShaderLanguage::TYPE_VEC2);
+ shader_modes[VS::SHADER_SPATIAL].functions["vertex"].built_ins["OUTPUT_IS_SRGB"] = constt(ShaderLanguage::TYPE_BOOL);
shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["VERTEX"] = constt(ShaderLanguage::TYPE_VEC3);
shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["FRAGCOORD"] = constt(ShaderLanguage::TYPE_VEC4);
@@ -112,6 +113,8 @@ ShaderTypes::ShaderTypes() {
shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["POINT_COORD"] = constt(ShaderLanguage::TYPE_VEC2);
shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["ALPHA_SCISSOR"] = ShaderLanguage::TYPE_FLOAT;
+ shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["OUTPUT_IS_SRGB"] = constt(ShaderLanguage::TYPE_BOOL);
+
shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["WORLD_MATRIX"] = constt(ShaderLanguage::TYPE_MAT4);
shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["INV_CAMERA_MATRIX"] = constt(ShaderLanguage::TYPE_MAT4);
shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["PROJECTION_MATRIX"] = constt(ShaderLanguage::TYPE_MAT4);
@@ -138,6 +141,7 @@ ShaderTypes::ShaderTypes() {
shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["ROUGHNESS"] = constt(ShaderLanguage::TYPE_FLOAT);
shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["DIFFUSE_LIGHT"] = ShaderLanguage::TYPE_VEC3;
shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["SPECULAR_LIGHT"] = ShaderLanguage::TYPE_VEC3;
+ shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["OUTPUT_IS_SRGB"] = constt(ShaderLanguage::TYPE_BOOL);
shader_modes[VS::SHADER_SPATIAL].functions["light"].can_discard = true;
diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp
index 7240266133..18a239b019 100644
--- a/servers/visual_server.cpp
+++ b/servers/visual_server.cpp
@@ -2393,6 +2393,10 @@ VisualServer::VisualServer() {
GLOBAL_DEF("rendering/quality/shading/force_vertex_shading", false);
GLOBAL_DEF("rendering/quality/shading/force_vertex_shading.mobile", true);
+ GLOBAL_DEF("rendering/quality/shading/force_lambert_over_burley", false);
+ GLOBAL_DEF("rendering/quality/shading/force_lambert_over_burley.mobile", true);
+ GLOBAL_DEF("rendering/quality/shading/force_blinn_over_ggx", false);
+ GLOBAL_DEF("rendering/quality/shading/force_blinn_over_ggx.mobile", true);
GLOBAL_DEF("rendering/quality/depth_prepass/enable", true);
GLOBAL_DEF("rendering/quality/depth_prepass/disable_for_vendors", "PowerVR,Mali,Adreno");