summaryrefslogtreecommitdiff
path: root/servers/visual
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2014-05-29 10:56:39 -0300
committerJuan Linietsky <reduzio@gmail.com>2014-05-29 10:56:39 -0300
commit6f0b4678e26c04abfc88c0226c803e78a108de98 (patch)
tree51b99b2ece75e5782c0b14c97bb6913c48e7f363 /servers/visual
parentd9adf2627a70ab37408aca9ae4140c6280dfe6df (diff)
More 3D Improvements
-=-=-=-=-=-=-=-=-=-= -Sprite3D and AnimatedSprite3D support. -Opaque pre-pass works, is compatible with shadows -Improved shadow map rendering (can differentiate between plain opaque and opaque with shaders/discard/etc) -Added option to use alpha discard in FixedMaterial -Improved Glow FX, many more options (three modes, Additive, Screen and SoftLight), strength and scale -Ability for Background (image or cubemap) to send to glow buffer -Dumb Deploy of clients now actually works in Android -Many Many rendering fixes, 3D is much more usable now.
Diffstat (limited to 'servers/visual')
-rw-r--r--servers/visual/rasterizer.cpp6
-rw-r--r--servers/visual/rasterizer.h22
-rw-r--r--servers/visual/rasterizer_dummy.cpp80
-rw-r--r--servers/visual/rasterizer_dummy.h29
-rw-r--r--servers/visual/shader_language.cpp2
-rw-r--r--servers/visual/visual_server_raster.cpp77
-rw-r--r--servers/visual/visual_server_raster.h15
-rw-r--r--servers/visual/visual_server_wrap_mt.h16
8 files changed, 246 insertions, 1 deletions
diff --git a/servers/visual/rasterizer.cpp b/servers/visual/rasterizer.cpp
index 2de49d3d81..e21848eac2 100644
--- a/servers/visual/rasterizer.cpp
+++ b/servers/visual/rasterizer.cpp
@@ -157,6 +157,9 @@ RID Rasterizer::_create_shader(const FixedMaterialShaderKey& p_key) {
if (p_key.use_alpha) {
code+="DIFFUSE_ALPHA=diffuse;\n";
+ if (p_key.discard_alpha) {
+ code+="DISCARD=diffuse.a<0.5;\n";
+ }
} else {
code+="DIFFUSE=diffuse.rgb;\n";
}
@@ -262,6 +265,7 @@ void Rasterizer::_free_shader(const FixedMaterialShaderKey& p_key) {
void Rasterizer::fixed_material_set_flag(RID p_material, VS::FixedMaterialFlags p_flag, bool p_enabled) {
+
Map<RID,FixedMaterial*>::Element *E = fixed_materials.find(p_material);
ERR_FAIL_COND(!E);
FixedMaterial &fm=*E->get();
@@ -271,6 +275,7 @@ void Rasterizer::fixed_material_set_flag(RID p_material, VS::FixedMaterialFlags
case VS::FIXED_MATERIAL_FLAG_USE_ALPHA: fm.use_alpha=p_enabled; break;
case VS::FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY: fm.use_color_array=p_enabled; break;
case VS::FIXED_MATERIAL_FLAG_USE_POINT_SIZE: fm.use_pointsize=p_enabled; break;
+ case VS::FIXED_MATERIAL_FLAG_DISCARD_ALPHA: fm.discard_alpha=p_enabled; break;
}
if (!fm.dirty_list.in_list())
@@ -288,6 +293,7 @@ bool Rasterizer::fixed_material_get_flag(RID p_material, VS::FixedMaterialFlags
case VS::FIXED_MATERIAL_FLAG_USE_ALPHA: return fm.use_alpha;; break;
case VS::FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY: return fm.use_color_array;; break;
case VS::FIXED_MATERIAL_FLAG_USE_POINT_SIZE: return fm.use_pointsize;; break;
+ case VS::FIXED_MATERIAL_FLAG_DISCARD_ALPHA: return fm.discard_alpha;; break;
}
diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h
index 783231d2e5..a3cdff9859 100644
--- a/servers/visual/rasterizer.h
+++ b/servers/visual/rasterizer.h
@@ -55,6 +55,7 @@ protected:
bool use_alpha:1;
bool use_color_array:1;
bool use_pointsize:1;
+ bool discard_alpha:1;
bool valid:1;
};
@@ -80,6 +81,7 @@ protected:
RID self;
bool use_alpha;
bool use_color_array;
+ bool discard_alpha;
bool use_pointsize;
float point_size;
Transform uv_xform;
@@ -100,6 +102,7 @@ protected:
k.use_alpha=use_alpha;
k.use_color_array=use_color_array;
k.use_pointsize=use_pointsize;
+ k.discard_alpha=discard_alpha;
k.detail_blend=detail_blend;
k.valid=true;
for(int i=0;i<VS::FIXED_MATERIAL_PARAM_MAX;i++) {
@@ -119,6 +122,7 @@ protected:
use_alpha=false;
use_color_array=false;
use_pointsize=false;
+ discard_alpha=false;
point_size=1.0;
detail_blend=VS::MATERIAL_BLEND_MODE_MIX;
for(int i=0;i<VS::FIXED_MATERIAL_PARAM_MAX;i++) {
@@ -298,6 +302,22 @@ public:
virtual void multimesh_set_visible_instances(RID p_multimesh,int p_visible)=0;
virtual int multimesh_get_visible_instances(RID p_multimesh) const=0;
+ /* IMMEDIATE API */
+
+ virtual RID immediate_create()=0;
+ virtual void immediate_begin(RID p_immediate,VS::PrimitiveType p_rimitive,RID p_texture=RID())=0;
+ virtual void immediate_vertex(RID p_immediate,const Vector3& p_vertex)=0;
+ virtual void immediate_normal(RID p_immediate,const Vector3& p_normal)=0;
+ virtual void immediate_tangent(RID p_immediate,const Plane& p_tangent)=0;
+ virtual void immediate_color(RID p_immediate,const Color& p_color)=0;
+ virtual void immediate_uv(RID p_immediate,const Vector2& tex_uv)=0;
+ virtual void immediate_uv2(RID p_immediate,const Vector2& tex_uv)=0;
+ virtual void immediate_end(RID p_immediate)=0;
+ virtual void immediate_clear(RID p_immediate)=0;
+ virtual AABB immediate_get_aabb(RID p_immediate) const=0;
+ virtual void immediate_set_material(RID p_immediate,RID p_material)=0;
+ virtual RID immediate_get_material(RID p_immediate) const=0;
+
/* PARTICLES API */
@@ -487,6 +507,7 @@ public:
virtual void add_mesh( const RID& p_mesh, const InstanceData *p_data)=0;
virtual void add_multimesh( const RID& p_multimesh, const InstanceData *p_data)=0;
+ virtual void add_immediate( const RID& p_immediate, const InstanceData *p_data)=0;
virtual void add_particles( const RID& p_particle_instance, const InstanceData *p_data)=0;
@@ -544,6 +565,7 @@ public:
virtual bool is_material(const RID& p_rid) const=0;
virtual bool is_mesh(const RID& p_rid) const=0;
virtual bool is_multimesh(const RID& p_rid) const=0;
+ virtual bool is_immediate(const RID& p_rid) const=0;
virtual bool is_particles(const RID &p_beam) const=0;
virtual bool is_light(const RID& p_rid) const=0;
diff --git a/servers/visual/rasterizer_dummy.cpp b/servers/visual/rasterizer_dummy.cpp
index 39c02c2037..1d55693bfb 100644
--- a/servers/visual/rasterizer_dummy.cpp
+++ b/servers/visual/rasterizer_dummy.cpp
@@ -709,6 +709,74 @@ int RasterizerDummy::multimesh_get_visible_instances(RID p_multimesh) const {
}
+/* IMMEDIATE API */
+
+
+RID RasterizerDummy::immediate_create() {
+
+ Immediate *im = memnew( Immediate );
+ return immediate_owner.make_rid(im);
+
+}
+
+void RasterizerDummy::immediate_begin(RID p_immediate,VS::PrimitiveType p_rimitive,RID p_texture){
+
+
+}
+void RasterizerDummy::immediate_vertex(RID p_immediate,const Vector3& p_vertex){
+
+
+}
+void RasterizerDummy::immediate_normal(RID p_immediate,const Vector3& p_normal){
+
+
+}
+void RasterizerDummy::immediate_tangent(RID p_immediate,const Plane& p_tangent){
+
+
+}
+void RasterizerDummy::immediate_color(RID p_immediate,const Color& p_color){
+
+
+}
+void RasterizerDummy::immediate_uv(RID p_immediate,const Vector2& tex_uv){
+
+
+}
+void RasterizerDummy::immediate_uv2(RID p_immediate,const Vector2& tex_uv){
+
+
+}
+
+void RasterizerDummy::immediate_end(RID p_immediate){
+
+
+}
+void RasterizerDummy::immediate_clear(RID p_immediate) {
+
+
+}
+
+AABB RasterizerDummy::immediate_get_aabb(RID p_immediate) const {
+
+ return AABB(Vector3(-1,-1,-1),Vector3(2,2,2));
+}
+
+void RasterizerDummy::immediate_set_material(RID p_immediate,RID p_material) {
+
+ Immediate *im = immediate_owner.get(p_immediate);
+ ERR_FAIL_COND(!im);
+ im->material=p_material;
+
+}
+
+RID RasterizerDummy::immediate_get_material(RID p_immediate) const {
+
+ const Immediate *im = immediate_owner.get(p_immediate);
+ ERR_FAIL_COND_V(!im,RID());
+ return im->material;
+
+}
/* PARTICLES API */
@@ -1627,6 +1695,12 @@ bool RasterizerDummy::is_mesh(const RID& p_rid) const {
return mesh_owner.owns(p_rid);
}
+
+bool RasterizerDummy::is_immediate(const RID& p_rid) const {
+
+ return immediate_owner.owns(p_rid);
+}
+
bool RasterizerDummy::is_multimesh(const RID& p_rid) const {
return multimesh_owner.owns(p_rid);
@@ -1703,6 +1777,12 @@ void RasterizerDummy::free(const RID& p_rid) {
multimesh_owner.free(p_rid);
memdelete(multimesh);
+ } else if (immediate_owner.owns(p_rid)) {
+
+ Immediate *immediate = immediate_owner.get(p_rid);
+ immediate_owner.free(p_rid);
+ memdelete(immediate);
+
} else if (particles_owner.owns(p_rid)) {
Particles *particles = particles_owner.get(p_rid);
diff --git a/servers/visual/rasterizer_dummy.h b/servers/visual/rasterizer_dummy.h
index 880e19c9b0..b683a25bdc 100644
--- a/servers/visual/rasterizer_dummy.h
+++ b/servers/visual/rasterizer_dummy.h
@@ -231,8 +231,18 @@ class RasterizerDummy : public Rasterizer {
};
+
mutable RID_Owner<MultiMesh> multimesh_owner;
+ struct Immediate {
+
+
+ RID material;
+ int empty;
+ };
+
+ mutable RID_Owner<Immediate> immediate_owner;
+
struct Particles : public Geometry {
ParticleSystemSW data; // software particle system
@@ -490,6 +500,23 @@ public:
virtual void multimesh_set_visible_instances(RID p_multimesh,int p_visible);
virtual int multimesh_get_visible_instances(RID p_multimesh) const;
+ /* IMMEDIATE API */
+
+ virtual RID immediate_create();
+ virtual void immediate_begin(RID p_immediate,VS::PrimitiveType p_rimitive,RID p_texture=RID());
+ virtual void immediate_vertex(RID p_immediate,const Vector3& p_vertex);
+ virtual void immediate_normal(RID p_immediate,const Vector3& p_normal);
+ virtual void immediate_tangent(RID p_immediate,const Plane& p_tangent);
+ virtual void immediate_color(RID p_immediate,const Color& p_color);
+ virtual void immediate_uv(RID p_immediate,const Vector2& tex_uv);
+ virtual void immediate_uv2(RID p_immediate,const Vector2& tex_uv);
+ virtual void immediate_end(RID p_immediate);
+ virtual void immediate_clear(RID p_immediate);
+ virtual void immediate_set_material(RID p_immediate,RID p_material);
+ virtual RID immediate_get_material(RID p_immediate) const;
+
+ virtual AABB immediate_get_aabb(RID p_mesh) const;
+
/* PARTICLES API */
virtual RID particles_create();
@@ -647,6 +674,7 @@ public:
virtual void add_mesh( const RID& p_mesh, const InstanceData *p_data);
virtual void add_multimesh( const RID& p_multimesh, const InstanceData *p_data);
+ virtual void add_immediate( const RID& p_immediate, const InstanceData *p_data) {}
virtual void add_particles( const RID& p_particle_instance, const InstanceData *p_data);
virtual void end_scene();
@@ -692,6 +720,7 @@ public:
virtual bool is_texture(const RID& p_rid) const;
virtual bool is_material(const RID& p_rid) const;
virtual bool is_mesh(const RID& p_rid) const;
+ virtual bool is_immediate(const RID& p_rid) const;
virtual bool is_multimesh(const RID& p_rid) const;
virtual bool is_particles(const RID &p_beam) const;
diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp
index 3061c2ddff..cdc1f678e7 100644
--- a/servers/visual/shader_language.cpp
+++ b/servers/visual/shader_language.cpp
@@ -1034,7 +1034,7 @@ const ShaderLanguage::BuiltinsDef ShaderLanguage::fragment_builtins_defs[]={
{ "SPEC_EXP", TYPE_FLOAT},
{ "GLOW", TYPE_FLOAT},
{ "SHADE_PARAM", TYPE_FLOAT},
- { "DISCARD", TYPE_FLOAT},
+ { "DISCARD", TYPE_BOOL},
{ "SCREEN_UV", TYPE_VEC2},
{ "POINT_COORD", TYPE_VEC2},
{ "INV_CAMERA_MATRIX", TYPE_MAT4},
diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp
index 6b74b34ba1..bffc1c43fe 100644
--- a/servers/visual/visual_server_raster.cpp
+++ b/servers/visual/visual_server_raster.cpp
@@ -519,6 +519,72 @@ int VisualServerRaster::multimesh_get_visible_instances(RID p_multimesh) const {
}
+/* IMMEDIATE API */
+
+
+RID VisualServerRaster::immediate_create() {
+
+ return rasterizer->immediate_create();
+}
+
+void VisualServerRaster::immediate_begin(RID p_immediate,PrimitiveType p_primitive,RID p_texture){
+
+ rasterizer->immediate_begin(p_immediate,p_primitive,p_texture);
+}
+void VisualServerRaster::immediate_vertex(RID p_immediate,const Vector3& p_vertex){
+
+ rasterizer->immediate_vertex(p_immediate,p_vertex);
+
+}
+void VisualServerRaster::immediate_normal(RID p_immediate,const Vector3& p_normal){
+
+ rasterizer->immediate_normal(p_immediate,p_normal);
+
+}
+void VisualServerRaster::immediate_tangent(RID p_immediate,const Plane& p_tangent){
+
+ rasterizer->immediate_tangent(p_immediate,p_tangent);
+
+}
+void VisualServerRaster::immediate_color(RID p_immediate,const Color& p_color){
+
+ rasterizer->immediate_color(p_immediate,p_color);
+
+}
+void VisualServerRaster::immediate_uv(RID p_immediate,const Vector2& p_uv){
+
+ rasterizer->immediate_uv(p_immediate,p_uv);
+
+}
+void VisualServerRaster::immediate_uv2(RID p_immediate,const Vector2& p_uv2){
+
+ rasterizer->immediate_uv2(p_immediate,p_uv2);
+
+}
+void VisualServerRaster::immediate_end(RID p_immediate){
+
+ VS_CHANGED;
+ _dependency_queue_update(p_immediate,true);
+ rasterizer->immediate_end(p_immediate);
+
+}
+void VisualServerRaster::immediate_clear(RID p_immediate){
+
+ VS_CHANGED;
+ _dependency_queue_update(p_immediate,true);
+ rasterizer->immediate_clear(p_immediate);
+
+}
+
+void VisualServerRaster::immediate_set_material(RID p_immediate,RID p_material) {
+
+ rasterizer->immediate_set_material(p_immediate,p_material);
+}
+
+RID VisualServerRaster::immediate_get_material(RID p_immediate) const {
+
+ return rasterizer->immediate_get_material(p_immediate);
+}
/* PARTICLES API */
@@ -1705,6 +1771,8 @@ void VisualServerRaster::instance_set_base(RID p_instance, RID p_base) {
instance->data.morph_values.resize( rasterizer->mesh_get_morph_target_count(p_base));
} else if (rasterizer->is_multimesh(p_base)) {
instance->base_type=INSTANCE_MULTIMESH;
+ } else if (rasterizer->is_immediate(p_base)) {
+ instance->base_type=INSTANCE_IMMEDIATE;
} else if (rasterizer->is_particles(p_base)) {
instance->base_type=INSTANCE_PARTICLES;
instance->particles_info=memnew( Instance::ParticlesInfo );
@@ -2468,6 +2536,12 @@ void VisualServerRaster::_update_instance_aabb(Instance *p_instance) {
new_aabb = rasterizer->multimesh_get_aabb(p_instance->base_rid);
} break;
+ case VisualServer::INSTANCE_IMMEDIATE: {
+
+ new_aabb = rasterizer->immediate_get_aabb(p_instance->base_rid);
+
+
+ } break;
case VisualServer::INSTANCE_PARTICLES: {
new_aabb = rasterizer->particles_get_aabb(p_instance->base_rid);
@@ -3498,6 +3572,9 @@ void VisualServerRaster::_instance_draw(Instance *p_instance) {
case INSTANCE_MULTIMESH: {
rasterizer->add_multimesh(p_instance->base_rid, &p_instance->data);
} break;
+ case INSTANCE_IMMEDIATE: {
+ rasterizer->add_immediate(p_instance->base_rid, &p_instance->data);
+ } break;
case INSTANCE_PARTICLES: {
rasterizer->add_particles(p_instance->particles_info->instance, &p_instance->data);
} break;
diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h
index c281e0b9e6..f6ef4ba6d5 100644
--- a/servers/visual/visual_server_raster.h
+++ b/servers/visual/visual_server_raster.h
@@ -766,6 +766,21 @@ public:
virtual void multimesh_set_visible_instances(RID p_multimesh,int p_visible);
virtual int multimesh_get_visible_instances(RID p_multimesh) const;
+ /* IMMEDIATE API */
+
+ virtual RID immediate_create();
+ virtual void immediate_begin(RID p_immediate,PrimitiveType p_rimitive,RID p_texture=RID());
+ virtual void immediate_vertex(RID p_immediate,const Vector3& p_vertex);
+ virtual void immediate_normal(RID p_immediate,const Vector3& p_normal);
+ virtual void immediate_tangent(RID p_immediate,const Plane& p_tangent);
+ virtual void immediate_color(RID p_immediate,const Color& p_color);
+ virtual void immediate_uv(RID p_immediate, const Vector2& p_uv);
+ virtual void immediate_uv2(RID p_immediate,const Vector2& tex_uv);
+ virtual void immediate_end(RID p_immediate);
+ virtual void immediate_clear(RID p_immediate);
+ virtual void immediate_set_material(RID p_immediate,RID p_material);
+ virtual RID immediate_get_material(RID p_immediate) const;
+
/* PARTICLES API */
diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h
index 87e13cb202..cfc4bd8605 100644
--- a/servers/visual/visual_server_wrap_mt.h
+++ b/servers/visual/visual_server_wrap_mt.h
@@ -741,6 +741,22 @@ public:
FUNC2(multimesh_set_visible_instances,RID,int);
FUNC1RC(int,multimesh_get_visible_instances,RID);
+ /* IMMEDIATE API */
+
+
+ FUNC0R(RID,immediate_create);
+ FUNC3(immediate_begin,RID,PrimitiveType,RID);
+ FUNC2(immediate_vertex,RID,const Vector3&);
+ FUNC2(immediate_normal,RID,const Vector3&);
+ FUNC2(immediate_tangent,RID,const Plane&);
+ FUNC2(immediate_color,RID,const Color&);
+ FUNC2(immediate_uv,RID,const Vector2&);
+ FUNC2(immediate_uv2,RID,const Vector2&);
+ FUNC1(immediate_end,RID);
+ FUNC1(immediate_clear,RID);
+ FUNC2(immediate_set_material,RID,RID);
+ FUNC1RC(RID,immediate_get_material,RID);
+
/* PARTICLES API */