diff options
Diffstat (limited to 'servers')
29 files changed, 720 insertions, 673 deletions
diff --git a/servers/audio/audio_mixer_sw.cpp b/servers/audio/audio_mixer_sw.cpp index d1f36cb7b6..64369182b1 100644 --- a/servers/audio/audio_mixer_sw.cpp +++ b/servers/audio/audio_mixer_sw.cpp @@ -339,7 +339,7 @@ void AudioMixerSW::mix_channel(Channel& c) { c.mix.old_chorus_vol[i]=c.mix.chorus_vol[i]; } - c.first_mix=false; + c.first_mix=false; } @@ -734,7 +734,7 @@ int AudioMixerSW::_get_channel(ChannelID p_channel) const { if (channels[idx].check!=check) { return -1; } - if (!channels[idx].active) { + if (!channels[idx].active) { return -1; } @@ -918,7 +918,7 @@ void AudioMixerSW::channel_set_filter(ChannelID p_channel, FilterType p_type, fl if (type_changed) { //type changed reset filter - c.filter.old_coefs=c.filter.coefs; + c.filter.old_coefs=c.filter.coefs; c.mix.filter_l.ha[0]=0; c.mix.filter_l.ha[1]=0; c.mix.filter_l.hb[0]=0; diff --git a/servers/audio/audio_mixer_sw.h b/servers/audio/audio_mixer_sw.h index f5bd4cc5ba..950ed19af6 100644 --- a/servers/audio/audio_mixer_sw.h +++ b/servers/audio/audio_mixer_sw.h @@ -197,7 +197,7 @@ private: void mix_channel(Channel& p_channel); int mix_chunk_left; - void mix_chunk(); + void mix_chunk(); float channel_nrg; int channel_id_count; diff --git a/servers/audio/audio_server_sw.h b/servers/audio/audio_server_sw.h index bc6191729c..8d3d992e2b 100644 --- a/servers/audio/audio_server_sw.h +++ b/servers/audio/audio_server_sw.h @@ -68,7 +68,7 @@ class AudioServerSW : public AudioServer { SelfList<Voice>::List active_list; struct Stream { - bool active; + bool active; List<Stream*>::Element *E; AudioStream *audio_stream; EventStream *event_stream; diff --git a/servers/physics/gjk_epa.cpp b/servers/physics/gjk_epa.cpp index 229c6d3fb4..f76f8c646a 100644 --- a/servers/physics/gjk_epa.cpp +++ b/servers/physics/gjk_epa.cpp @@ -15,7 +15,7 @@ // Config -/* GJK */ +/* GJK */ #define GJK_MAX_ITERATIONS 128 #define GJK_ACCURARY ((real_t)0.0001) #define GJK_MIN_DISTANCE ((real_t)0.0001) @@ -24,7 +24,7 @@ #define GJK_SIMPLEX3_EPS ((real_t)0.0) #define GJK_SIMPLEX4_EPS ((real_t)0.0) -/* EPA */ +/* EPA */ #define EPA_MAX_VERTICES 64 #define EPA_MAX_FACES (EPA_MAX_VERTICES*2) #define EPA_MAX_ITERATIONS 255 @@ -38,12 +38,12 @@ namespace GjkEpa2 { struct sResults { enum eStatus { - Separated, /* Shapes doesnt penetrate */ - Penetrating, /* Shapes are penetrating */ - GJK_Failed, /* GJK phase fail, no big issue, shapes are probably just 'touching' */ - EPA_Failed /* EPA phase fail, bigger problem, need to save parameters, and debug */ + Separated, /* Shapes doesnt penetrate */ + Penetrating, /* Shapes are penetrating */ + GJK_Failed, /* GJK phase fail, no big issue, shapes are probably just 'touching' */ + EPA_Failed /* EPA phase fail, bigger problem, need to save parameters, and debug */ } status; - + Vector3 witnesses[2]; Vector3 normal; real_t distance; @@ -65,15 +65,15 @@ struct MinkowskiDiff { _FORCE_INLINE_ Vector3 Support0 ( const Vector3& d ) const { return transform_A.xform( m_shapes[0]->get_support( transform_A.basis.xform_inv(d).normalized() ) ); } - + _FORCE_INLINE_ Vector3 Support1 ( const Vector3& d ) const { return transform_B.xform( m_shapes[1]->get_support( transform_B.basis.xform_inv(d).normalized() ) ); } - + _FORCE_INLINE_ Vector3 Support ( const Vector3& d ) const { return ( Support0 ( d )-Support1 ( -d ) ); } - + _FORCE_INLINE_ Vector3 Support ( const Vector3& d,U index ) const { if ( index ) @@ -89,7 +89,7 @@ typedef MinkowskiDiff tShape; // GJK struct GJK { - /* Types */ + /* Types */ struct sSV { Vector3 d,w; @@ -104,7 +104,7 @@ struct GJK Valid, Inside, Failed };}; - /* Fields */ + /* Fields */ tShape m_shape; Vector3 m_ray; real_t m_distance; @@ -115,7 +115,7 @@ struct GJK U m_current; sSimplex* m_simplex; eStatus::_ m_status; - /* Methods */ + /* Methods */ GJK() { Initialize(); @@ -135,7 +135,7 @@ struct GJK real_t alpha=0; Vector3 lastw[4]; U clastw=0; - /* Initialize solver */ + /* Initialize solver */ m_free[0] = &m_store[0]; m_free[1] = &m_store[1]; m_free[2] = &m_store[2]; @@ -145,31 +145,31 @@ struct GJK m_status = eStatus::Valid; m_shape = shapearg; m_distance = 0; - /* Initialize simplex */ + /* Initialize simplex */ m_simplices[0].rank = 0; m_ray = guess; const real_t sqrl= m_ray.length_squared(); appendvertice(m_simplices[0],sqrl>0?-m_ray:Vector3(1,0,0)); m_simplices[0].p[0] = 1; - m_ray = m_simplices[0].c[0]->w; + m_ray = m_simplices[0].c[0]->w; sqdist = sqrl; lastw[0] = lastw[1] = lastw[2] = lastw[3] = m_ray; - /* Loop */ + /* Loop */ do { const U next=1-m_current; sSimplex& cs=m_simplices[m_current]; sSimplex& ns=m_simplices[next]; - /* Check zero */ + /* Check zero */ const real_t rl=m_ray.length(); if(rl<GJK_MIN_DISTANCE) - {/* Touching or inside */ + {/* Touching or inside */ m_status=eStatus::Inside; break; } - /* Append new vertice in -'v' direction */ + /* Append new vertice in -'v' direction */ appendvertice(cs,-m_ray); const Vector3& w=cs.c[cs.rank-1]->w; bool found=false; @@ -179,23 +179,23 @@ struct GJK { found=true;break; } } if(found) - {/* Return old simplex */ + {/* Return old simplex */ removevertice(m_simplices[m_current]); break; } else - {/* Update lastw */ + {/* Update lastw */ lastw[clastw=(clastw+1)&3]=w; } - /* Check for termination */ + /* Check for termination */ const real_t omega=vec3_dot(m_ray,w)/rl; alpha=MAX(omega,alpha); if(((rl-alpha)-(GJK_ACCURARY*rl))<=0) - {/* Return old simplex */ + {/* Return old simplex */ removevertice(m_simplices[m_current]); break; - } - /* Reduce simplex */ + } + /* Reduce simplex */ real_t weights[4]; U mask=0; switch(cs.rank) @@ -214,7 +214,7 @@ struct GJK weights,mask);break; } if(sqdist>=0) - {/* Valid */ + {/* Valid */ ns.rank = 0; m_ray = Vector3(0,0,0); m_current = next; @@ -234,7 +234,7 @@ struct GJK if(mask==15) m_status=eStatus::Inside; } else - {/* Return old simplex */ + {/* Return old simplex */ removevertice(m_simplices[m_current]); break; } @@ -246,7 +246,7 @@ struct GJK case eStatus::Valid: m_distance=m_ray.length();break; case eStatus::Inside: m_distance=0;break; default: {} - } + } return(m_status); } bool EncloseOrigin() @@ -314,7 +314,7 @@ struct GJK } return(false); } - /* Internals */ + /* Internals */ void getsupport(const Vector3& d,sSV& sv) const { sv.d = d/d.length(); @@ -378,13 +378,13 @@ struct GJK m = static_cast<U>(((subm&1)?1<<i:0)+((subm&2)?1<<j:0)); w[i] = subw[0]; w[j] = subw[1]; - w[imd3[j]] = 0; + w[imd3[j]] = 0; } } } if(mindist<0) { - const real_t d=vec3_dot(a,n); + const real_t d=vec3_dot(a,n); const real_t s=Math::sqrt(l); const Vector3 p=n*(d/l); mindist = p.length_squared(); @@ -451,7 +451,7 @@ struct GJK // EPA struct EPA { - /* Types */ + /* Types */ typedef GJK::sSV sSV; struct sFace { @@ -482,13 +482,13 @@ struct GJK Touching, Degenerated, NonConvex, - InvalidHull, + InvalidHull, OutOfFaces, OutOfVertices, AccuraryReached, FallBack, Failed };}; - /* Fields */ + /* Fields */ eStatus::_ m_status; GJK::sSimplex m_result; Vector3 m_normal; @@ -498,10 +498,10 @@ struct GJK U m_nextsv; sList m_hull; sList m_stock; - /* Methods */ + /* Methods */ EPA() { - Initialize(); + Initialize(); } @@ -544,7 +544,7 @@ struct GJK if((simplex.rank>1)&&gjk.EncloseOrigin()) { - /* Clean up */ + /* Clean up */ while(m_hull.root) { sFace* f = m_hull.root; @@ -553,7 +553,7 @@ struct GJK } m_status = eStatus::Valid; m_nextsv = 0; - /* Orient simplex */ + /* Orient simplex */ if(gjk.det( simplex.c[0]->w-simplex.c[3]->w, simplex.c[1]->w-simplex.c[3]->w, simplex.c[2]->w-simplex.c[3]->w)<0) @@ -561,7 +561,7 @@ struct GJK SWAP(simplex.c[0],simplex.c[1]); SWAP(simplex.p[0],simplex.p[1]); } - /* Build initial hull */ + /* Build initial hull */ sFace* tetra[]={newface(simplex.c[0],simplex.c[1],simplex.c[2],true), newface(simplex.c[1],simplex.c[0],simplex.c[3],true), newface(simplex.c[2],simplex.c[1],simplex.c[3],true), @@ -582,10 +582,10 @@ struct GJK for(;iterations<EPA_MAX_ITERATIONS;++iterations) { if(m_nextsv<EPA_MAX_VERTICES) - { + { sHorizon horizon; sSV* w=&m_sv_store[m_nextsv++]; - bool valid=true; + bool valid=true; best->pass = (U1)(++pass); gjk.getsupport(best->n,*w); const real_t wdist=vec3_dot(best->n,w->w)-best->d; @@ -628,7 +628,7 @@ struct GJK return(m_status); } } - /* Fallback */ + /* Fallback */ m_status = eStatus::FallBack; m_normal = -guess; const real_t nl=m_normal.length(); @@ -639,7 +639,7 @@ struct GJK m_depth = 0; m_result.rank=1; m_result.c[0]=simplex.c[0]; - m_result.p[0]=1; + m_result.p[0]=1; return(m_status); } sFace* newface(sSV* a,sSV* b,sSV* c,bool forced) @@ -739,16 +739,16 @@ struct GJK tShape& shape, bool withmargins) { - /* Results */ + /* Results */ results.witnesses[0] = results.witnesses[1] = Vector3(0,0,0); results.status = sResults::Separated; - /* Shape */ + /* Shape */ shape.m_shapes[0] = shape0; shape.m_shapes[1] = shape1; shape.transform_A = wtrs0; shape.transform_B = wtrs1; - + } @@ -808,7 +808,7 @@ bool Penetration( const ShapeSW* shape0, { tShape shape; Initialize(shape0,wtrs0,shape1,wtrs1,results,shape,false); - GJK gjk; + GJK gjk; GJK::eStatus::_ gjk_status=gjk.Evaluate(shape,-guess); switch(gjk_status) { @@ -841,7 +841,7 @@ bool Penetration( const ShapeSW* shape0, } -/* Symbols cleanup */ +/* Symbols cleanup */ #undef GJK_MAX_ITERATIONS #undef GJK_ACCURARY @@ -885,7 +885,7 @@ bool gjk_epa_calculate_distance(const ShapeSW *p_shape_A, const Transform& p_tra bool gjk_epa_calculate_penetration(const ShapeSW *p_shape_A, const Transform& p_transform_A, const ShapeSW *p_shape_B, const Transform& p_transform_B, CollisionSolverSW::CallbackResult p_result_callback,void *p_userdata, bool p_swap ) { GjkEpa2::sResults res; - + if (GjkEpa2::Penetration(p_shape_A,p_transform_A,p_shape_B,p_transform_B,p_transform_B.origin-p_transform_A.origin,res)) { if (p_result_callback) { if (p_swap) @@ -894,8 +894,8 @@ bool gjk_epa_calculate_penetration(const ShapeSW *p_shape_A, const Transform& p_ p_result_callback(res.witnesses[0],res.witnesses[1],p_userdata); } return true; - } - + } + return false; } diff --git a/servers/physics/space_sw.cpp b/servers/physics/space_sw.cpp index 08f280a976..4cf7729b09 100644 --- a/servers/physics/space_sw.cpp +++ b/servers/physics/space_sw.cpp @@ -318,7 +318,7 @@ bool PhysicsDirectSpaceStateSW::cast_motion(const RID& p_shape, const Transform& } p_closest_safe=best_safe; - p_closest_unsafe=best_unsafe; + p_closest_unsafe=best_unsafe; return true; } diff --git a/servers/physics_2d/body_2d_sw.cpp b/servers/physics_2d/body_2d_sw.cpp index f1f94f3485..ab1c7ef66f 100644 --- a/servers/physics_2d/body_2d_sw.cpp +++ b/servers/physics_2d/body_2d_sw.cpp @@ -260,7 +260,7 @@ void Body2DSW::set_state(Physics2DServer::BodyState p_state, const Variant& p_va if (mode==Physics2DServer::BODY_MODE_KINEMATIC) { - new_transform=p_variant; + new_transform=p_variant; //wakeup_neighbours(); set_active(true); if (first_time_kinematic) { @@ -396,7 +396,7 @@ void Body2DSW::_compute_area_gravity_and_dampenings(const Area2DSW *p_area) { } area_linear_damp += p_area->get_linear_damp(); - area_angular_damp += p_area->get_angular_damp(); + area_angular_damp += p_area->get_angular_damp(); } void Body2DSW::integrate_forces(real_t p_step) { @@ -518,7 +518,7 @@ void Body2DSW::integrate_forces(real_t p_step) { // damp_area=NULL; // clear the area, so it is set in the next frame def_area=NULL; // clear the area, so it is set in the next frame - contact_count=0; + contact_count=0; } @@ -597,7 +597,7 @@ void Body2DSW::call_queries() { set_force_integration_callback(0,StringName()); } else { - Variant::CallError ce; + Variant::CallError ce; if (fi_callback->callback_udata.get_type()) { obj->call(fi_callback->method,vp,2,ce); diff --git a/servers/physics_2d/body_pair_2d_sw.cpp b/servers/physics_2d/body_pair_2d_sw.cpp index db7869c6a6..35f19605df 100644 --- a/servers/physics_2d/body_pair_2d_sw.cpp +++ b/servers/physics_2d/body_pair_2d_sw.cpp @@ -77,7 +77,7 @@ void BodyPair2DSW::_contact_added_callback(const Vector2& p_point_A,const Vector contact.acc_normal_impulse=c.acc_normal_impulse; contact.acc_tangent_impulse=c.acc_tangent_impulse; contact.acc_bias_impulse=c.acc_bias_impulse; - new_index=i; + new_index=i; break; } } @@ -259,10 +259,10 @@ bool BodyPair2DSW::setup(float p_step) { if (A->get_continuous_collision_detection_mode()==Physics2DServer::CCD_MODE_CAST_SHAPE) { motion_A=A->get_motion(); - } + } if (B->get_continuous_collision_detection_mode()==Physics2DServer::CCD_MODE_CAST_SHAPE) { motion_B=B->get_motion(); - } + } //faster to set than to check.. //bool prev_collided=collided; diff --git a/servers/physics_2d/collision_solver_2d_sw.cpp b/servers/physics_2d/collision_solver_2d_sw.cpp index d9bf235c86..fcc3f8067a 100644 --- a/servers/physics_2d/collision_solver_2d_sw.cpp +++ b/servers/physics_2d/collision_solver_2d_sw.cpp @@ -226,7 +226,7 @@ bool CollisionSolver2DSW::solve_concave(const Shape2DSW *p_shape_A,const Matrix3 concave_B->cull(local_aabb,concave_callback,&cinfo); -// print_line("Rect2 TESTS: "+itos(cinfo.aabb_tests)); +// print_line("Rect2 TESTS: "+itos(cinfo.aabb_tests)); return cinfo.collided; } diff --git a/servers/physics_2d/physics_2d_server_sw.h b/servers/physics_2d/physics_2d_server_sw.h index 28acf4e2d1..cd4dfc1a8b 100644 --- a/servers/physics_2d/physics_2d_server_sw.h +++ b/servers/physics_2d/physics_2d_server_sw.h @@ -258,7 +258,7 @@ public: virtual void set_active(bool p_active); virtual void init(); virtual void step(float p_step); - virtual void sync(); + virtual void sync(); virtual void flush_queries(); virtual void end_sync(); virtual void finish(); diff --git a/servers/physics_2d/shape_2d_sw.cpp b/servers/physics_2d/shape_2d_sw.cpp index 3054ba8d59..8b583dd3c6 100644 --- a/servers/physics_2d/shape_2d_sw.cpp +++ b/servers/physics_2d/shape_2d_sw.cpp @@ -746,7 +746,7 @@ Variant ConvexPolygonShape2DSW::get_data() const { dvr.resize(point_count); - for(int i=0;i<point_count;i++) { + for(int i=0;i<point_count;i++) { dvr.set(i,points[i].pos); } @@ -968,19 +968,25 @@ void ConcavePolygonShape2DSW::set_data(const Variant& p_data) { ERR_FAIL_COND(p_data.get_type()!=Variant::VECTOR2_ARRAY && p_data.get_type()!=Variant::REAL_ARRAY); - segments.clear();; - points.clear();; - bvh.clear();; - bvh_depth=1; - Rect2 aabb; if (p_data.get_type()==Variant::VECTOR2_ARRAY) { DVector<Vector2> p2arr = p_data; int len = p2arr.size(); - DVector<Vector2>::Read arr = p2arr.read(); + ERR_FAIL_COND(len%2); + + segments.clear(); + points.clear(); + bvh.clear(); + bvh_depth=1; + if (len==0) { + configure(aabb); + return; + } + + DVector<Vector2>::Read arr = p2arr.read(); Map<Point2,int> pointmap; for(int i=0;i<len;i+=2) { @@ -988,8 +994,6 @@ void ConcavePolygonShape2DSW::set_data(const Variant& p_data) { Point2 p1 =arr[i]; Point2 p2 =arr[i+1]; int idx_p1,idx_p2; - if (p1==p2) - continue; //don't want it if (pointmap.has(p1)) { idx_p1=pointmap[p1]; diff --git a/servers/physics_2d/space_2d_sw.cpp b/servers/physics_2d/space_2d_sw.cpp index eaf9427ad8..027e218bfc 100644 --- a/servers/physics_2d/space_2d_sw.cpp +++ b/servers/physics_2d/space_2d_sw.cpp @@ -337,7 +337,7 @@ bool Physics2DDirectSpaceStateSW::cast_motion(const RID& p_shape, const Matrix32 Vector2 sep=mnormal; //important optimization for this to work fast enough bool collided = CollisionSolver2DSW::solve(shape,p_xform,p_motion*(hi+space->contact_max_allowed_penetration),col_obj->get_shape(shape_idx),col_obj_xform,Vector2(),Physics2DServerSW::_shape_col_cbk,&cbk,&sep,p_margin); - if (!collided || cbk.amount==0) { + if (!collided || cbk.amount==0) { continue; } @@ -1256,7 +1256,7 @@ void Space2DSW::set_param(Physics2DServer::SpaceParameter p_param, real_t p_valu case Physics2DServer::SPACE_PARAM_BODY_MAX_ALLOWED_PENETRATION: contact_max_allowed_penetration=p_value; break; case Physics2DServer::SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_TRESHOLD: body_linear_velocity_sleep_treshold=p_value; break; case Physics2DServer::SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_TRESHOLD: body_angular_velocity_sleep_treshold=p_value; break; - case Physics2DServer::SPACE_PARAM_BODY_TIME_TO_SLEEP: body_time_to_sleep=p_value; break; + case Physics2DServer::SPACE_PARAM_BODY_TIME_TO_SLEEP: body_time_to_sleep=p_value; break; case Physics2DServer::SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS: constraint_bias=p_value; break; } } diff --git a/servers/physics_2d/step_2d_sw.cpp b/servers/physics_2d/step_2d_sw.cpp index 94e1d26329..4f9d06ee96 100644 --- a/servers/physics_2d/step_2d_sw.cpp +++ b/servers/physics_2d/step_2d_sw.cpp @@ -35,7 +35,7 @@ void Step2DSW::_populate_island(Body2DSW* p_body,Body2DSW** p_island,Constraint2 p_body->set_island_next(*p_island); *p_island=p_body; - for(Map<Constraint2DSW*,int>::Element *E=p_body->get_constraint_map().front();E;E=E->next()) { + for(Map<Constraint2DSW*,int>::Element *E=p_body->get_constraint_map().front();E;E=E->next()) { Constraint2DSW *c=(Constraint2DSW*)E->key(); if (c->get_island_step()==_step) diff --git a/servers/physics_2d_server.h b/servers/physics_2d_server.h index 7a4365bea3..25875f16d3 100644 --- a/servers/physics_2d_server.h +++ b/servers/physics_2d_server.h @@ -533,7 +533,7 @@ public: virtual void damped_string_joint_set_param(RID p_joint, DampedStringParam p_param, real_t p_value)=0; virtual real_t damped_string_joint_get_param(RID p_joint, DampedStringParam p_param) const=0; - virtual JointType joint_get_type(RID p_joint) const=0; + virtual JointType joint_get_type(RID p_joint) const=0; /* QUERY API */ diff --git a/servers/physics_server.h b/servers/physics_server.h index 8e302bf363..9b00825d92 100644 --- a/servers/physics_server.h +++ b/servers/physics_server.h @@ -421,7 +421,7 @@ public: BODY_STATE_LINEAR_VELOCITY, BODY_STATE_ANGULAR_VELOCITY, BODY_STATE_SLEEPING, - BODY_STATE_CAN_SLEEP + BODY_STATE_CAN_SLEEP }; virtual void body_set_state(RID p_body, BodyState p_state, const Variant& p_variant)=0; @@ -648,7 +648,7 @@ public: virtual void damped_string_joint_set_param(RID p_joint, DampedStringParam p_param, real_t p_value)=0; virtual real_t damped_string_joint_get_param(RID p_joint, DampedStringParam p_param) const=0; - virtual JointType joint_get_type(RID p_joint) const=0; + virtual JointType joint_get_type(RID p_joint) const=0; #endif /* QUERY API */ diff --git a/servers/spatial_sound/spatial_sound_server_sw.cpp b/servers/spatial_sound/spatial_sound_server_sw.cpp index 1ce56a5cdd..d87d05dc4d 100644 --- a/servers/spatial_sound/spatial_sound_server_sw.cpp +++ b/servers/spatial_sound/spatial_sound_server_sw.cpp @@ -323,7 +323,7 @@ RID SpatialSoundServerSW::source_create(RID p_space) { void SpatialSoundServerSW::source_set_polyphony(RID p_source,int p_voice_count) { - + ERR_FAIL_COND(p_voice_count<=0); // more than 32 is too much, change this if you really need more if (p_voice_count>32) { @@ -378,8 +378,8 @@ float SpatialSoundServerSW::source_get_param(RID p_source, SourceParam p_param) Source *source = source_owner.get(p_source); ERR_FAIL_COND_V(!source,0); return source->params[p_param]; - - + + } void SpatialSoundServerSW::source_set_audio_stream(RID p_source, AudioServer::AudioStream *p_stream) { @@ -542,7 +542,7 @@ void SpatialSoundServerSW::free(RID p_id) { if (space_owner.owns(p_id)) { - Space *space = space_owner.get(p_id); + Space *space = space_owner.get(p_id); free(space->default_room); while(space->listeners.size()) { diff --git a/servers/spatial_sound/spatial_sound_server_sw.h b/servers/spatial_sound/spatial_sound_server_sw.h index 8a4dabdc3e..a8ae7beb59 100644 --- a/servers/spatial_sound/spatial_sound_server_sw.h +++ b/servers/spatial_sound/spatial_sound_server_sw.h @@ -154,7 +154,7 @@ class SpatialSoundServerSW : public SpatialSoundServer { }; mutable RID_Owner<Listener> listener_owner; - + struct ActiveVoice { Source *source; diff --git a/servers/visual/particle_system_sw.cpp b/servers/visual/particle_system_sw.cpp index 00c06b9e3c..07cc6d8a2a 100644 --- a/servers/visual/particle_system_sw.cpp +++ b/servers/visual/particle_system_sw.cpp @@ -34,11 +34,11 @@ ParticleSystemSW::ParticleSystemSW() { amount=8; emitting=true; - + for (int i=0;i<VS::PARTICLE_VAR_MAX;i++) { particle_randomness[i]=0.0; } - + particle_vars[VS::PARTICLE_LIFETIME]=2.0;// particle_vars[VS::PARTICLE_SPREAD]=0.2;// particle_vars[VS::PARTICLE_GRAVITY]=9.8;// @@ -89,7 +89,7 @@ _FORCE_INLINE_ static float _rand_from_seed(uint32_t *seed) { if (s < 0) s += 2147483647; (*seed) = s; - + float v=((float)((*seed) & 0xFFFFF))/(float)0xFFFFF; v=v*2.0-1.0; return v; @@ -144,10 +144,10 @@ void ParticleSystemProcessSW::process(const ParticleSystemSW *p_system,const Tra } float next_time = particle_system_time+p_time; - + if (next_time > lifetime) next_time=Math::fmod(next_time,lifetime); - + ParticleData *pdata=&particle_data[0]; Vector3 attractor_positions[VS::MAX_PARTICLE_ATTRACTORS]; @@ -159,13 +159,13 @@ void ParticleSystemProcessSW::process(const ParticleSystemSW *p_system,const Tra for(int i=0;i<particle_count;i++) { - + ParticleData &p=pdata[i]; - + float restart_time = (i * lifetime / p_system->amount); - + bool restart=false; - + if ( next_time < particle_system_time ) { if (restart_time > particle_system_time || restart_time < next_time ) @@ -191,11 +191,11 @@ void ParticleSystemProcessSW::process(const ParticleSystemSW *p_system,const Tra else p.pos = p_transform.xform( r[_irand_from_seed(&rand_seed)%emission_point_count] ); } - - + + float angle1 = _rand_from_seed(&rand_seed)*p_system->particle_vars[VS::PARTICLE_SPREAD]*Math_PI; float angle2 = _rand_from_seed(&rand_seed)*20.0*Math_PI; // make it more random like - + Vector3 rot_xz=Vector3( Math::sin(angle1), 0.0, Math::cos(angle1) ); Vector3 rot = Vector3( Math::cos(angle2)*rot_xz.x,Math::sin(angle2)*rot_xz.x, rot_xz.z); @@ -204,22 +204,22 @@ void ParticleSystemProcessSW::process(const ParticleSystemSW *p_system,const Tra p.vel=p_transform.basis.xform( p.vel ); p.vel+=p_system->emission_base_velocity; - - p.rot=p_system->particle_vars[VS::PARTICLE_INITIAL_ANGLE]+p_system->particle_randomness[VS::PARTICLE_INITIAL_ANGLE]*_rand_from_seed(&rand_seed); + + p.rot=p_system->particle_vars[VS::PARTICLE_INITIAL_ANGLE]+p_system->particle_randomness[VS::PARTICLE_INITIAL_ANGLE]*_rand_from_seed(&rand_seed); p.active=true; for(int r=0;r<PARTICLE_RANDOM_NUMBERS;r++) p.random[r]=_rand_from_seed(&rand_seed); } else { - + p.pos=Vector3(); p.rot=0; p.vel=Vector3(); p.active=false; } - + } else { - + if (!p.active) continue; diff --git a/servers/visual/particle_system_sw.h b/servers/visual/particle_system_sw.h index 9a176ba0d4..4edcecaaa9 100644 --- a/servers/visual/particle_system_sw.h +++ b/servers/visual/particle_system_sw.h @@ -37,13 +37,13 @@ struct ParticleSystemSW { enum { - + MAX_PARTICLES=1024 }; float particle_vars[VS::PARTICLE_VAR_MAX]; float particle_randomness[VS::PARTICLE_VAR_MAX]; - + Vector3 emission_half_extents; DVector<Vector3> emission_points; Vector3 gravity_normal; @@ -54,14 +54,14 @@ struct ParticleSystemSW { AABB visibility_aabb; bool sort; bool local_coordinates; - + struct ColorPhase { - + float pos; Color color; ColorPhase() { pos=1.0; color=Color(0.0,0.0,1.0,1.0); } }; - + int color_phase_count; ColorPhase color_phases[VS::MAX_PARTICLE_COLOR_PHASES]; @@ -71,12 +71,12 @@ struct ParticleSystemSW { Vector3 pos; float force; }; - + int attractor_count; Attractor attractors[VS::MAX_PARTICLE_ATTRACTORS]; - ParticleSystemSW(); + ParticleSystemSW(); ~ParticleSystemSW(); }; @@ -89,7 +89,7 @@ struct ParticleSystemProcessSW { }; struct ParticleData { - + Vector3 pos; Vector3 vel; float rot; @@ -102,7 +102,7 @@ struct ParticleSystemProcessSW { bool valid; float particle_system_time; - uint32_t rand_seed; + uint32_t rand_seed; Vector<ParticleData> particle_data; void process(const ParticleSystemSW *p_system,const Transform& p_transform,float p_time); diff --git a/servers/visual/rasterizer.cpp b/servers/visual/rasterizer.cpp index 26eca478fd..32f5b80e55 100644 --- a/servers/visual/rasterizer.cpp +++ b/servers/visual/rasterizer.cpp @@ -370,7 +370,7 @@ RID Rasterizer::fixed_material_create() { material_set_param(mat,_fixed_material_param_names[i],fm.param[i]); //must be there } fixed_material_dirty_list.add(&fm.dirty_list); - //print_line("FMC: "+itos(mat.get_id())); + //print_line("FMC: "+itos(mat.get_id())); return mat; } diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h index b84e83cb0c..276758ea95 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer.h @@ -178,7 +178,7 @@ public: /* TEXTURE API */ virtual RID texture_create()=0; - RID texture_create_from_image(const Image& p_image,uint32_t p_flags=VS::TEXTURE_FLAGS_DEFAULT); // helper + RID texture_create_from_image(const Image& p_image,uint32_t p_flags=VS::TEXTURE_FLAGS_DEFAULT); // helper virtual void texture_allocate(RID p_texture,int p_width, int p_height,Image::Format p_format,uint32_t p_flags=VS::TEXTURE_FLAGS_DEFAULT)=0; virtual void texture_set_data(RID p_texture,const Image& p_image,VS::CubeMapSide p_cube_side=VS::CUBEMAP_LEFT)=0; virtual Image texture_get_data(RID p_texture,VS::CubeMapSide p_cube_side=VS::CUBEMAP_LEFT) const=0; @@ -263,10 +263,10 @@ public: virtual void fixed_material_set_point_size(RID p_material,float p_size); virtual float fixed_material_get_point_size(RID p_material) const; - /* MESH API */ - + /* MESH API */ + virtual RID mesh_create()=0; - + virtual void mesh_add_surface(RID p_mesh,VS::PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes=Array(),bool p_alpha_sort=false)=0; virtual Array mesh_get_surface_arrays(RID p_mesh,int p_surface) const=0; @@ -287,10 +287,10 @@ public: virtual int mesh_surface_get_array_index_len(RID p_mesh, int p_surface) const=0; virtual uint32_t mesh_surface_get_format(RID p_mesh, int p_surface) const=0; virtual VS::PrimitiveType mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const=0; - + virtual void mesh_remove_surface(RID p_mesh,int p_index)=0; virtual int mesh_get_surface_count(RID p_mesh) const=0; - + virtual AABB mesh_get_aabb(RID p_mesh,RID p_skeleton=RID()) const=0; virtual void mesh_set_custom_aabb(RID p_mesh,const AABB& p_aabb)=0; @@ -338,23 +338,23 @@ public: virtual void immediate_set_material(RID p_immediate,RID p_material)=0; virtual RID immediate_get_material(RID p_immediate) const=0; - + /* PARTICLES API */ - + virtual RID particles_create()=0; - + virtual void particles_set_amount(RID p_particles, int p_amount)=0; virtual int particles_get_amount(RID p_particles) const=0; - + virtual void particles_set_emitting(RID p_particles, bool p_emitting)=0; virtual bool particles_is_emitting(RID p_particles) const=0; - + virtual void particles_set_visibility_aabb(RID p_particles, const AABB& p_visibility)=0; virtual AABB particles_get_visibility_aabb(RID p_particles) const=0; - + virtual void particles_set_emission_half_extents(RID p_particles, const Vector3& p_half_extents)=0; virtual Vector3 particles_get_emission_half_extents(RID p_particles) const=0; - + virtual void particles_set_emission_base_velocity(RID p_particles, const Vector3& p_base_velocity)=0; virtual Vector3 particles_get_emission_base_velocity(RID p_particles) const=0; @@ -363,22 +363,22 @@ public: virtual void particles_set_gravity_normal(RID p_particles, const Vector3& p_normal)=0; virtual Vector3 particles_get_gravity_normal(RID p_particles) const=0; - + virtual void particles_set_variable(RID p_particles, VS::ParticleVariable p_variable,float p_value)=0; virtual float particles_get_variable(RID p_particles, VS::ParticleVariable p_variable) const=0; - + virtual void particles_set_randomness(RID p_particles, VS::ParticleVariable p_variable,float p_randomness)=0; virtual float particles_get_randomness(RID p_particles, VS::ParticleVariable p_variable) const=0; - + virtual void particles_set_color_phase_pos(RID p_particles, int p_phase, float p_pos)=0; virtual float particles_get_color_phase_pos(RID p_particles, int p_phase) const=0; - + virtual void particles_set_color_phases(RID p_particles, int p_phases)=0; virtual int particles_get_color_phases(RID p_particles) const=0; virtual void particles_set_color_phase_color(RID p_particles, int p_phase, const Color& p_color)=0; virtual Color particles_get_color_phase_color(RID p_particles, int p_phase) const=0; - + virtual void particles_set_attractors(RID p_particles, int p_attractors)=0; virtual int particles_get_attractors(RID p_particles) const=0; @@ -390,7 +390,7 @@ public: virtual void particles_set_material(RID p_particles, RID p_material,bool p_owned=false)=0; virtual RID particles_get_material(RID p_particles) const=0; - + virtual AABB particles_get_aabb(RID p_particles) const=0; virtual void particles_set_height_from_velocity(RID p_particles, bool p_enable)=0; @@ -400,31 +400,31 @@ public: virtual bool particles_is_using_local_coordinates(RID p_particles) const=0; /* SKELETON API */ - + virtual RID skeleton_create()=0; virtual void skeleton_resize(RID p_skeleton,int p_bones)=0; virtual int skeleton_get_bone_count(RID p_skeleton) const=0; virtual void skeleton_bone_set_transform(RID p_skeleton,int p_bone, const Transform& p_transform)=0; virtual Transform skeleton_bone_get_transform(RID p_skeleton,int p_bone)=0; - + /* LIGHT API */ - + virtual RID light_create(VS::LightType p_type)=0; virtual VS::LightType light_get_type(RID p_light) const=0; virtual void light_set_color(RID p_light,VS::LightColor p_type, const Color& p_color)=0; - virtual Color light_get_color(RID p_light,VS::LightColor p_type) const=0; - + virtual Color light_get_color(RID p_light,VS::LightColor p_type) const=0; + virtual void light_set_shadow(RID p_light,bool p_enabled)=0; - virtual bool light_has_shadow(RID p_light) const=0; - + virtual bool light_has_shadow(RID p_light) const=0; + virtual void light_set_volumetric(RID p_light,bool p_enabled)=0; - virtual bool light_is_volumetric(RID p_light) const=0; - + virtual bool light_is_volumetric(RID p_light) const=0; + virtual void light_set_projector(RID p_light,RID p_texture)=0; virtual RID light_get_projector(RID p_light) const=0; - + virtual void light_set_var(RID p_light, VS::LightParam p_var, float p_value)=0; virtual float light_get_var(RID p_light, VS::LightParam p_var) const=0; @@ -440,10 +440,10 @@ public: virtual float light_directional_get_shadow_param(RID p_light,VS::LightDirectionalShadowParam p_param) const=0; virtual AABB light_get_aabb(RID p_poly) const=0; - + virtual RID light_instance_create(RID p_light)=0; - virtual void light_instance_set_transform(RID p_light_instance,const Transform& p_transform)=0; - + virtual void light_instance_set_transform(RID p_light_instance,const Transform& p_transform)=0; + enum ShadowType { SHADOW_NONE, @@ -454,7 +454,7 @@ public: SHADOW_PSSM, //parallel split shadow map SHADOW_PSM //perspective shadow map }; - + enum ShadowPass { PASS_DUAL_PARABOLOID_FRONT=0, PASS_DUAL_PARABOLOID_BACK=1, @@ -463,7 +463,7 @@ public: PASS_CUBE_TOP=2, PASS_CUBE_BOTTOM=3, PASS_CUBE_LEFT=4, - PASS_CUBE_RIGHT=5, + PASS_CUBE_RIGHT=5, }; virtual ShadowType light_instance_get_shadow_type(RID p_light_instance,bool p_far=false) const=0; @@ -479,13 +479,13 @@ public: virtual bool shadow_allocate_far(RID p_light)=0; //true on successful alloc /* PARTICLES INSTANCE */ - + virtual RID particles_instance_create(RID p_particles)=0; virtual void particles_instance_set_transform(RID p_particles_instance,const Transform& p_transform)=0; - + /* RENDER API */ /* all calls (inside begin/end shadow) are always warranted to be in the following order: */ - + /* VIEWPORT API */ virtual RID viewport_data_create()=0; @@ -496,19 +496,19 @@ public: virtual bool render_target_renedered_in_frame(RID p_render_target)=0; virtual void begin_frame()=0; - + virtual void set_viewport(const VS::ViewportRect& p_viewport)=0; virtual void set_render_target(RID p_render_target,bool p_transparent_bg=false,bool p_vflip=false)=0; virtual void clear_viewport(const Color& p_color)=0; virtual void capture_viewport(Image* r_capture)=0; - + virtual void begin_scene(RID p_viewport_data,RID p_env,VS::ScenarioDebugMode p_debug)=0; virtual void begin_shadow_map( RID p_light_instance, int p_shadow_pass )=0; virtual void set_camera(const Transform& p_world,const CameraMatrix& p_projection,bool p_ortho_hint)=0; - + virtual void add_light( RID p_light_instance )=0; ///< all "add_light" calls happen before add_geometry calls - + typedef Map<StringName,Variant> ParamOverrideMap; struct BakedLightData { @@ -539,6 +539,7 @@ public: Vector<RID> light_instances; Vector<float> morph_values; BakedLightData *baked_light; + VS::ShadowCastingSetting cast_shadows; Transform *baked_light_octree_xform; int baked_lightmap_id; bool mirror :8; @@ -556,10 +557,10 @@ public: virtual void end_scene()=0; virtual void end_shadow_map()=0; - + virtual void end_frame()=0; virtual void flush_frame(); //not necesary in most cases - + /* CANVAS API */ enum CanvasRectFlags { @@ -613,7 +614,7 @@ public: CanvasLight *mask_next_ptr; CanvasLight() { - enabled=true; + enabled=true; color=Color(1,1,1); shadow_color=Color(0,0,0,0); height=0; @@ -978,7 +979,7 @@ public: virtual void canvas_light_shadow_buffer_update(RID p_buffer, const Matrix32& p_light_xform, int p_light_mask,float p_near, float p_far, CanvasLightOccluderInstance* p_occluders, CameraMatrix *p_xform_cache)=0; /* ENVIRONMENT */ - + virtual RID environment_create()=0; @@ -998,9 +999,9 @@ public: virtual RID sampled_light_dp_create(int p_width,int p_height)=0; virtual void sampled_light_dp_update(RID p_sampled_light,const Color *p_data,float p_multiplier)=0; - + /*MISC*/ - + virtual bool is_texture(const RID& p_rid) const=0; virtual bool is_material(const RID& p_rid) const=0; virtual bool is_mesh(const RID& p_rid) const=0; diff --git a/servers/visual/shader_graph.cpp b/servers/visual/shader_graph.cpp index 07bbf9f7b4..7fe949bec3 100644 --- a/servers/visual/shader_graph.cpp +++ b/servers/visual/shader_graph.cpp @@ -34,78 +34,78 @@ struct _ConnectionKey { int node; - int slot; - + int slot; + _FORCE_INLINE_ _ConnectionKey(int p_node=0,int p_slot=0) { node=p_node; slot=p_slot; } - + _FORCE_INLINE_ bool operator<(const _ConnectionKey& p_other) const { - + if (node<p_other.node) return true; else if (node>p_other.node) - return false; + return false; else return slot<p_other.slot; } }; Error ShaderGraph::generate(ShaderCodeGenerator * p_generator) const { - + Map<int,Node>::Element *E = node_map.front(); - int i=0; + int i=0; while(E) { - + E->get().order=i++; E->get().out_valid=false; E->get().in_valid=false; E=E->next(); - } + } int worst_case=connections.size() * connections.size(); // worst bubble case int iterations=0; int swaps; - - do { + + do { swaps=0; const List<Connection>::Element *E=connections.front(); while(E) { const Connection &c = E->get(); - + const Node *src = &node_map[c.src_id]; const Node *dst = &node_map[c.dst_id]; - + if (src->order > dst->order) { - + SWAP(src->order, dst->order); swaps++; } - + E=E->next(); } - - + + iterations++; - + } while (iterations<=worst_case && swaps>0); - + ERR_FAIL_COND_V( swaps != 0 , ERR_CYCLIC_LINK ); - + //node array Vector<const Node*> nodes; nodes.resize(node_map.size()); - + E = node_map.front(); while(E) { - + ERR_FAIL_INDEX_V( E->get().order, nodes.size(), ERR_BUG); nodes[E->get().order]=&E->get(); E=E->next(); } - + //connection set - + Map<_ConnectionKey,int> in_connection_map; Map<_ConnectionKey,List<int> > out_connection_map; Map<_ConnectionKey,int> in_node_map; @@ -115,7 +115,7 @@ Error ShaderGraph::generate(ShaderCodeGenerator * p_generator) const { i=0; while(CE) { const Connection &c = CE->get(); - + _ConnectionKey in_k; in_k.node=node_map[c.dst_id].order; in_k.slot=c.dst_slot; @@ -131,11 +131,11 @@ Error ShaderGraph::generate(ShaderCodeGenerator * p_generator) const { if(!out_node_map.has(out_k)) out_node_map[out_k]=List<int>(); out_node_map[out_k].push_back(node_map[c.dst_id].order); - + i++; CE=CE->next(); } - + // validate nodes if they are connected to an output for(int i=nodes.size()-1;i>=0;i--) { @@ -231,9 +231,9 @@ Error ShaderGraph::generate(ShaderCodeGenerator * p_generator) const { } // write code - + p_generator->begin(); - + for(int i=0;i<nodes.size();i++) { @@ -244,35 +244,35 @@ Error ShaderGraph::generate(ShaderCodeGenerator * p_generator) const { in_indices.resize(VS::shader_get_input_count(nodes[i]->type)); Vector<int> out_indices; Vector<int> out_slot_indices; - + for(int j=0;j<in_indices.size();j++) { - + _ConnectionKey key(nodes[i]->order,j); if (in_connection_map.has(key)) in_indices[j]=in_connection_map[key]; else - in_indices[j]=-1; + in_indices[j]=-1; } - + for(int j=0;j<VS::shader_get_output_count(nodes[i]->type);j++) { - + _ConnectionKey key(nodes[i]->order,j); if (out_connection_map.has(key)) { for(List<int>::Element *CE=out_connection_map[key].front();CE;CE=CE->next()) { - + out_indices.push_back(CE->get()); out_slot_indices.push_back(j); } } } - + Error err = p_generator->add_node(nodes[i]->type,i,nodes[i]->id,nodes[i]->param,in_indices,out_indices,out_slot_indices); ERR_FAIL_COND_V( err, err ); } - + p_generator->end(); - - + + return OK; } @@ -282,7 +282,7 @@ void ShaderGraph::node_add(VS::ShaderNodeType p_type,int p_id) { ERR_FAIL_COND( node_map.has(p_id ) ); ERR_FAIL_INDEX( p_type, VS::NODE_TYPE_MAX ); Node node; - + node.type=p_type; node.id=p_id; node.x=0; @@ -312,14 +312,14 @@ int ShaderGraph::node_get_pos_y(int p_id) const { void ShaderGraph::node_remove(int p_id) { ERR_FAIL_COND(!node_map.has(p_id)); - + //erase connections associated with node List<Connection>::Element *N,*E=connections.front(); while(E) { N=E->next(); const Connection &c = E->get(); if (c.src_id==p_id || c.dst_id==p_id) { - + connections.erase(E); } E=N; @@ -337,17 +337,17 @@ void ShaderGraph::node_change_type(int p_id, VS::ShaderNodeType p_type) { } void ShaderGraph::node_set_param(int p_id, const Variant& p_value) { - + ERR_FAIL_COND(!node_map.has(p_id)); - node_map[p_id].param=p_value; + node_map[p_id].param=p_value; } void ShaderGraph::get_node_list(List<int> *p_node_list) const { Map<int,Node>::Element *E = node_map.front(); - + while(E) { - + p_node_list->push_back(E->key()); E=E->next(); } @@ -363,7 +363,7 @@ VS::ShaderNodeType ShaderGraph::node_get_type(int p_id) const { Variant ShaderGraph::node_get_param(int p_id) const { ERR_FAIL_COND_V(!node_map.has(p_id),Variant()); - return node_map[p_id].param; + return node_map[p_id].param; } @@ -383,16 +383,16 @@ Error ShaderGraph::connect(int p_src_id,int p_src_slot, int p_dst_id,int p_dst_s while(E) { const Connection &c = E->get(); ERR_FAIL_COND_V(c.dst_slot==p_dst_slot && c.dst_id == p_dst_id, ERR_ALREADY_EXISTS); - + E=E->next(); } - + Connection c; c.src_slot=p_src_slot; c.src_id=p_src_id; c.dst_slot=p_dst_slot; c.dst_id=p_dst_id; - + connections.push_back(c); return OK; @@ -419,12 +419,12 @@ void ShaderGraph::disconnect(int p_src_id,int p_src_slot, int p_dst_id,int p_dst N=E->next(); const Connection &c = E->get(); if (c.src_slot==p_src_slot && c.src_id==p_src_id && c.dst_slot==p_dst_slot && c.dst_id == p_dst_id) { - + connections.erase(E); } E=N; } - + } diff --git a/servers/visual/shader_graph.h b/servers/visual/shader_graph.h index 07e4bb3540..41df0f60f1 100644 --- a/servers/visual/shader_graph.h +++ b/servers/visual/shader_graph.h @@ -43,7 +43,7 @@ public: virtual void begin()=0; virtual Error add_node(VS::ShaderNodeType p_type,int p_node_pos,int p_id,const Variant& p_param,const Vector<int>& p_in_connections,const Vector<int>& p_out_connections,const Vector<int>& p_out_connection_outputs)=0; virtual void end()=0; - + virtual ~ShaderCodeGenerator() {} }; @@ -61,7 +61,7 @@ public: private: struct Node { - + int16_t x,y; VS::ShaderNodeType type; Variant param; @@ -74,7 +74,7 @@ private: Map<int,Node> node_map; List<Connection> connections; - + public: Error generate(ShaderCodeGenerator * p_generator) const; @@ -87,7 +87,7 @@ public: void node_set_pos(int p_id, int p_x,int p_y); int node_get_pos_x(int p_id) const; int node_get_pos_y(int p_id) const; - + void get_node_list(List<int> *p_node_list) const; void get_sorted_node_list(List<int> *p_node_list) const; VS::ShaderNodeType node_get_type(int p_id) const; @@ -95,14 +95,14 @@ public: Error connect(int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot); bool is_connected(int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot) const; - void disconnect(int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot); + void disconnect(int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot); void clear(); List<Connection> get_connection_list() const; - ShaderGraph(); + ShaderGraph(); ~ShaderGraph(); }; diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index d0e8bfccd6..0b2a282c04 100644 --- a/servers/visual/shader_language.cpp +++ b/servers/visual/shader_language.cpp @@ -607,7 +607,7 @@ bool ShaderLanguage::test_existing_identifier(Node *p_node,const StringName p_id return true; } else if (node->type==Node::TYPE_PROGRAM) { - ProgramNode *program = (ProgramNode*)node; + ProgramNode *program = (ProgramNode*)node; for(int i=0;i<program->functions.size();i++) { if (program->functions[i].name==p_identifier) { @@ -1138,7 +1138,7 @@ const ShaderLanguage::BuiltinsDef ShaderLanguage::ci_vertex_builtins_defs[]={ //builtins { "WORLD_MATRIX", TYPE_MAT4}, { "PROJECTION_MATRIX", TYPE_MAT4}, - { "EXTRA_MATRIX", TYPE_MAT4}, + { "EXTRA_MATRIX", TYPE_MAT4}, { "TIME", TYPE_FLOAT}, { NULL, TYPE_VOID}, }; diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp index 3675194325..2ce0c9a360 100644 --- a/servers/visual/visual_server_raster.cpp +++ b/servers/visual/visual_server_raster.cpp @@ -45,7 +45,7 @@ BalloonAllocator<> *VisualServerRaster::OctreeAllocator::allocator=NULL; RID VisualServerRaster::texture_create() { - + return rasterizer->texture_create(); } @@ -340,7 +340,7 @@ VisualServerRaster::FixedMaterialLightShader VisualServerRaster::fixed_material_ -/* MESH API */ +/* MESH API */ RID VisualServerRaster::mesh_create() { @@ -625,14 +625,14 @@ RID VisualServerRaster::particles_create() { void VisualServerRaster::particles_set_amount(RID p_particles, int p_amount) { VS_CHANGED; - rasterizer->particles_set_amount(p_particles,p_amount); + rasterizer->particles_set_amount(p_particles,p_amount); } int VisualServerRaster::particles_get_amount(RID p_particles) const { return rasterizer->particles_get_amount(p_particles); } - + void VisualServerRaster::particles_set_emitting(RID p_particles, bool p_emitting) { VS_CHANGED; rasterizer->particles_set_emitting(p_particles,p_emitting); @@ -641,7 +641,7 @@ bool VisualServerRaster::particles_is_emitting(RID p_particles) const { return rasterizer->particles_is_emitting(p_particles); } - + void VisualServerRaster::particles_set_visibility_aabb(RID p_particles, const AABB& p_visibility) { VS_CHANGED; rasterizer->particles_set_visibility_aabb(p_particles, p_visibility); @@ -650,7 +650,7 @@ AABB VisualServerRaster::particles_get_visibility_aabb(RID p_particles) const { return rasterizer->particles_get_visibility_aabb(p_particles); } - + void VisualServerRaster::particles_set_emission_half_extents(RID p_particles, const Vector3& p_half_extents) { VS_CHANGED; rasterizer->particles_set_emission_half_extents(p_particles,p_half_extents); @@ -688,7 +688,7 @@ Vector3 VisualServerRaster::particles_get_gravity_normal(RID p_particles) const return rasterizer->particles_get_gravity_normal(p_particles); } - + void VisualServerRaster::particles_set_variable(RID p_particles, ParticleVariable p_variable,float p_value) { VS_CHANGED; rasterizer->particles_set_variable(p_particles,p_variable,p_value); @@ -770,7 +770,7 @@ RID VisualServerRaster::particles_get_material(RID p_particles) const { return rasterizer->particles_get_material(p_particles); } - + void VisualServerRaster::particles_set_height_from_velocity(RID p_particles, bool p_enable) { @@ -812,33 +812,33 @@ void VisualServerRaster::light_set_color(RID p_light,LightColor p_type, const Co } Color VisualServerRaster::light_get_color(RID p_light,LightColor p_type) const { - + return rasterizer->light_get_color(p_light,p_type); - + } void VisualServerRaster::light_set_shadow(RID p_light,bool p_enabled) { VS_CHANGED; - rasterizer->light_set_shadow(p_light,p_enabled); + rasterizer->light_set_shadow(p_light,p_enabled); } bool VisualServerRaster::light_has_shadow(RID p_light) const { return rasterizer->light_has_shadow(p_light); -} +} void VisualServerRaster::light_set_volumetric(RID p_light,bool p_enabled) { VS_CHANGED; - rasterizer->light_set_volumetric(p_light,p_enabled); + rasterizer->light_set_volumetric(p_light,p_enabled); } bool VisualServerRaster::light_is_volumetric(RID p_light) const { return rasterizer->light_is_volumetric(p_light); -} +} void VisualServerRaster::light_set_projector(RID p_light,RID p_texture) { VS_CHANGED; @@ -854,13 +854,13 @@ void VisualServerRaster::light_set_param(RID p_light, LightParam p_var, float p_ VS_CHANGED; rasterizer->light_set_var(p_light,p_var,p_value); _dependency_queue_update(p_light,true); - + } float VisualServerRaster::light_get_param(RID p_light, LightParam p_var) const { - - return rasterizer->light_get_var(p_light,p_var); + + return rasterizer->light_get_var(p_light,p_var); } void VisualServerRaster::light_set_operator(RID p_light,LightOp p_op) { @@ -940,7 +940,7 @@ Transform VisualServerRaster::skeleton_bone_get_transform(RID p_skeleton,int p_b return rasterizer->skeleton_bone_get_transform(p_skeleton,p_bone); } - + /* VISIBILITY API */ @@ -970,7 +970,7 @@ BSP_Tree VisualServerRaster::room_get_bounds(RID p_room) const { return room->bounds; } - + /* PORTAL API */ RID VisualServerRaster::portal_create() { @@ -1422,7 +1422,7 @@ void VisualServerRaster::camera_set_perspective(RID p_camera,float p_fovy_degree camera->fov=p_fovy_degrees; camera->znear=p_z_near; camera->zfar=p_z_far; - + } void VisualServerRaster::camera_set_orthogonal(RID p_camera,float p_size, float p_z_near, float p_z_far) { @@ -1440,7 +1440,7 @@ void VisualServerRaster::camera_set_transform(RID p_camera,const Transform& p_tr Camera *camera = camera_owner.get( p_camera ); ERR_FAIL_COND(!camera); camera->transform=p_transform.orthonormalized(); - + } @@ -1502,7 +1502,7 @@ RID VisualServerRaster::viewport_create() { Viewport *viewport = memnew( Viewport ); RID rid = viewport_owner.make_rid( viewport ); ERR_FAIL_COND_V( !rid.is_valid(), rid ); - + viewport->self=rid; viewport->hide_scenario=false; viewport->hide_canvas=false; @@ -1670,7 +1670,7 @@ void VisualServerRaster::viewport_set_rect(RID p_viewport,const ViewportRect& p_ viewport = viewport_owner.get( p_viewport ); ERR_FAIL_COND(!viewport); - + viewport->rect=p_rect; if (viewport->render_target.is_valid()) { rasterizer->render_target_set_size(viewport->render_target,viewport->rect.width,viewport->rect.height); @@ -1684,7 +1684,7 @@ VisualServer::ViewportRect VisualServerRaster::viewport_get_rect(RID p_viewport) viewport = viewport_owner.get( p_viewport ); ERR_FAIL_COND_V(!viewport, ViewportRect()); - + return viewport->rect; } @@ -1736,11 +1736,11 @@ void VisualServerRaster::viewport_attach_camera(RID p_viewport,RID p_camera) { - + if (p_camera.is_valid()) { ERR_FAIL_COND(!camera_owner.owns(p_camera)); - // a camera + // a camera viewport->camera=p_camera; } else { viewport->camera=RID(); @@ -1773,7 +1773,7 @@ RID VisualServerRaster::viewport_get_attached_camera(RID p_viewport) const { viewport = viewport_owner.get( p_viewport ); ERR_FAIL_COND_V(!viewport, RID()); - + return viewport->camera; } @@ -1862,7 +1862,7 @@ void VisualServerRaster::viewport_remove_canvas(RID p_viewport,RID p_canvas) { viewport = viewport_owner.get( p_viewport ); ERR_FAIL_COND(!viewport); - Canvas *canvas = canvas_owner.get( p_canvas ); + Canvas *canvas = canvas_owner.get( p_canvas ); ERR_FAIL_COND(!canvas); @@ -1894,7 +1894,7 @@ void VisualServerRaster::viewport_set_canvas_layer(RID p_viewport,RID p_canvas,i } E->get().layer=p_layer; - + } void VisualServerRaster::viewport_set_transparent_background(RID p_viewport,bool p_enabled) { @@ -1916,13 +1916,13 @@ bool VisualServerRaster::viewport_has_transparent_background(RID p_viewport) con RID VisualServerRaster::viewport_get_scenario(RID p_viewport) const { - + const Viewport *viewport=NULL; viewport = viewport_owner.get( p_viewport ); ERR_FAIL_COND_V(!viewport, RID()); - - return viewport->scenario; + + return viewport->scenario; } @@ -1976,38 +1976,38 @@ Variant VisualServerRaster::environment_fx_get_param(RID p_env,EnvironmentFxPara void VisualServerRaster::_dependency_queue_update(RID p_rid,bool p_update_aabb) { Map< RID, Set<RID> >::Element * E = instance_dependency_map.find( p_rid ); - + if (!E) return; - - + + Set<RID>::Element *I = E->get().front(); - + while(I) { - + Instance *ins = instance_owner.get( I->get() ); _instance_queue_update( ins , p_update_aabb ); - + I = I->next(); } - + } void VisualServerRaster::_instance_queue_update(Instance *p_instance,bool p_update_aabb) { if (p_update_aabb) p_instance->update_aabb=true; - + if (p_instance->update) return; p_instance->update_next=instance_update_list; instance_update_list=p_instance; p_instance->update=true; - + } RID VisualServerRaster::scenario_create() { - + Scenario *scenario = memnew( Scenario ); ERR_FAIL_COND_V(!scenario,RID()); RID scenario_rid = scenario_owner.make_rid( scenario ); @@ -2449,10 +2449,10 @@ void VisualServerRaster::instance_set_transform(RID p_instance, const Transform& VS_CHANGED; Instance *instance = instance_owner.get( p_instance ); ERR_FAIL_COND( !instance ); - + if (p_transform==instance->data.transform) // must improve somehow return; - + instance->data.transform=p_transform; if (instance->base_type==INSTANCE_LIGHT) instance->data.transform.orthonormalize(); @@ -2464,7 +2464,7 @@ Transform VisualServerRaster::instance_get_transform(RID p_instance) const { Instance *instance = instance_owner.get( p_instance ); ERR_FAIL_COND_V( !instance, Transform() ); - + return instance->data.transform; } @@ -2574,7 +2574,7 @@ void VisualServerRaster::instance_set_room( RID p_instance, RID p_room ) { ERR_EXPLAIN("Cycle in room assignment"); ERR_FAIL_COND( parent == room ); parent=parent->room; - } + } } if ( (1<<instance->base_type) & INSTANCE_GEOMETRY_MASK ) { @@ -2634,45 +2634,45 @@ real_t VisualServerRaster::instance_get_extra_visibility_margin( RID p_instance Vector<RID> VisualServerRaster::instances_cull_aabb(const AABB& p_aabb, RID p_scenario) const { - + Vector<RID> instances; Scenario *scenario=scenario_owner.get(p_scenario); - ERR_FAIL_COND_V(!scenario,instances); - + ERR_FAIL_COND_V(!scenario,instances); + const_cast<VisualServerRaster*>(this)->_update_instances(); // check dirty instances before culling - + int culled=0; Instance *cull[1024]; culled=scenario->octree.cull_AABB(p_aabb,cull,1024); - + for (int i=0;i<culled;i++) { - + Instance *instance=cull[i]; ERR_CONTINUE(!instance); instances.push_back(instance->self); } - + return instances; } Vector<RID> VisualServerRaster::instances_cull_ray(const Vector3& p_from, const Vector3& p_to, RID p_scenario) const{ Vector<RID> instances; Scenario *scenario=scenario_owner.get(p_scenario); - ERR_FAIL_COND_V(!scenario,instances); + ERR_FAIL_COND_V(!scenario,instances); const_cast<VisualServerRaster*>(this)->_update_instances(); // check dirty instances before culling - + int culled=0; - Instance *cull[1024]; + Instance *cull[1024]; culled=scenario->octree.cull_segment(p_from,p_to*10000,cull,1024); for (int i=0;i<culled;i++) { - + Instance *instance=cull[i]; ERR_CONTINUE(!instance); instances.push_back(instance->self); } - + return instances; } @@ -2680,22 +2680,22 @@ Vector<RID> VisualServerRaster::instances_cull_convex(const Vector<Plane>& p_con Vector<RID> instances; Scenario *scenario=scenario_owner.get(p_scenario); - ERR_FAIL_COND_V(!scenario,instances); + ERR_FAIL_COND_V(!scenario,instances); const_cast<VisualServerRaster*>(this)->_update_instances(); // check dirty instances before culling - + int culled=0; - Instance *cull[1024]; - + Instance *cull[1024]; + culled=scenario->octree.cull_convex(p_convex,cull,1024); - + for (int i=0;i<culled;i++) { - + Instance *instance=cull[i]; - ERR_CONTINUE(!instance); + ERR_CONTINUE(!instance); instances.push_back(instance->self); } - + return instances; } @@ -2724,7 +2724,12 @@ void VisualServerRaster::instance_geometry_set_flag(RID p_instance,InstanceFlags } break; case INSTANCE_FLAG_CAST_SHADOW: { - instance->cast_shadows=p_enabled; + if (p_enabled == true) { + instance->data.cast_shadows = SHADOW_CASTING_SETTING_ON; + } + else { + instance->data.cast_shadows = SHADOW_CASTING_SETTING_OFF; + } } break; case INSTANCE_FLAG_RECEIVE_SHADOWS: { @@ -2771,7 +2776,12 @@ bool VisualServerRaster::instance_geometry_get_flag(RID p_instance,InstanceFlags } break; case INSTANCE_FLAG_CAST_SHADOW: { - return instance->cast_shadows; + if(instance->data.cast_shadows == SHADOW_CASTING_SETTING_OFF) { + return false; + } + else { + return true; + } } break; case INSTANCE_FLAG_RECEIVE_SHADOWS: { @@ -2795,6 +2805,22 @@ bool VisualServerRaster::instance_geometry_get_flag(RID p_instance,InstanceFlags return false; } +void VisualServerRaster::instance_geometry_set_cast_shadows_setting(RID p_instance, VS::ShadowCastingSetting p_shadow_casting_setting) { + + Instance *instance = instance_owner.get( p_instance ); + ERR_FAIL_COND( !instance ); + + instance->data.cast_shadows = p_shadow_casting_setting; +} + +VS::ShadowCastingSetting VisualServerRaster::instance_geometry_get_cast_shadows_setting(RID p_instance) const{ + + const Instance *instance = instance_owner.get( p_instance ); + ERR_FAIL_COND_V( !instance, SHADOW_CASTING_SETTING_OFF ); + + return instance->data.cast_shadows; +} + void VisualServerRaster::instance_geometry_set_material_override(RID p_instance, RID p_material) { @@ -2950,9 +2976,9 @@ void VisualServerRaster::_update_instance(Instance *p_instance) { p_instance->version++; if (p_instance->base_type == INSTANCE_LIGHT) { - + rasterizer->light_instance_set_transform( p_instance->light_info->instance, p_instance->data.transform ); - + } if (p_instance->aabb.has_no_surface()) @@ -2960,10 +2986,10 @@ void VisualServerRaster::_update_instance(Instance *p_instance) { if (p_instance->base_type == INSTANCE_PARTICLES) { - + rasterizer->particles_instance_set_transform( p_instance->particles_info->instance, p_instance->data.transform ); } - + if ((1<<p_instance->base_type)&INSTANCE_GEOMETRY_MASK) { @@ -3015,7 +3041,7 @@ void VisualServerRaster::_update_instance(Instance *p_instance) { else portal_aabb.expand_to(point); } - + portal_aabb.grow_by(p_instance->portal_info->portal->connect_range); new_aabb = portal_aabb; @@ -3091,7 +3117,7 @@ void VisualServerRaster::_update_instance(Instance *p_instance) { } if (p_instance->base_type==INSTANCE_PORTAL) { - + _portal_attempt_connect(p_instance); } @@ -3112,18 +3138,18 @@ void VisualServerRaster::_update_instance(Instance *p_instance) { void VisualServerRaster::_update_instance_aabb(Instance *p_instance) { AABB new_aabb; - + ERR_FAIL_COND(p_instance->base_type!=INSTANCE_NONE && !p_instance->base_rid.is_valid()); - + switch(p_instance->base_type) { case VisualServer::INSTANCE_NONE: { // do nothing } break; case VisualServer::INSTANCE_MESH: { - + new_aabb = rasterizer->mesh_get_aabb(p_instance->base_rid,p_instance->data.skeleton); - + } break; case VisualServer::INSTANCE_MULTIMESH: { @@ -3137,41 +3163,41 @@ void VisualServerRaster::_update_instance_aabb(Instance *p_instance) { } break; case VisualServer::INSTANCE_PARTICLES: { - + new_aabb = rasterizer->particles_get_aabb(p_instance->base_rid); - + } break; case VisualServer::INSTANCE_LIGHT: { - + new_aabb = rasterizer->light_get_aabb(p_instance->base_rid); - + } break; case VisualServer::INSTANCE_ROOM: { - + Room *room = room_owner.get( p_instance->base_rid ); ERR_FAIL_COND(!room); new_aabb=room->bounds.get_aabb(); - + } break; case VisualServer::INSTANCE_PORTAL: { - + Portal *portal = portal_owner.get( p_instance->base_rid ); - ERR_FAIL_COND(!portal); + ERR_FAIL_COND(!portal); for (int i=0;i<portal->shape.size();i++) { - + Vector3 point( portal->shape[i].x, portal->shape[i].y, 0 ); if (i==0) { - + new_aabb.pos=point; new_aabb.size.z=0.01; // make it not flat for octree } else { - + new_aabb.expand_to(point); } } - } break; + } break; case VisualServer::INSTANCE_BAKED_LIGHT: { BakedLight *baked_light = baked_light_owner.get( p_instance->base_rid ); @@ -3194,24 +3220,24 @@ void VisualServerRaster::_update_instance_aabb(Instance *p_instance) { if (p_instance->extra_margin) new_aabb.grow_by(p_instance->extra_margin); - + p_instance->aabb=new_aabb; - + } void VisualServerRaster::_update_instances() { while(instance_update_list) { - + Instance *instance=instance_update_list; instance_update_list=instance_update_list->update_next; - + if (instance->update_aabb) _update_instance_aabb(instance); - + _update_instance(instance); - + instance->update=false; instance->update_aabb=false; instance->update_next=0; @@ -3251,7 +3277,7 @@ RID VisualServerRaster::canvas_create() { Canvas * canvas = memnew( Canvas ); ERR_FAIL_COND_V(!canvas,RID()); RID rid = canvas_owner.make_rid( canvas ); - + return rid; } @@ -3291,10 +3317,10 @@ void VisualServerRaster::canvas_set_modulate(RID p_canvas,const Color& p_color) RID VisualServerRaster::canvas_item_create() { - + CanvasItem *canvas_item = memnew( CanvasItem ); ERR_FAIL_COND_V(!canvas_item,RID()); - + return canvas_item_owner.make_rid( canvas_item ); } @@ -3422,7 +3448,7 @@ void VisualServerRaster::canvas_item_set_rect(RID p_item, const Rect2& p_rect) { VS_CHANGED; CanvasItem *canvas_item = canvas_item_owner.get( p_item ); ERR_FAIL_COND(!canvas_item); - + canvas_item->rect=p_rect; }*/ @@ -3430,7 +3456,7 @@ void VisualServerRaster::canvas_item_set_clip(RID p_item, bool p_clip) { VS_CHANGED; CanvasItem *canvas_item = canvas_item_owner.get( p_item ); ERR_FAIL_COND(!canvas_item); - + canvas_item->clip=p_clip; } @@ -3517,7 +3543,7 @@ void VisualServerRaster::canvas_item_add_line(RID p_item, const Point2& p_from, VS_CHANGED; CanvasItem *canvas_item = canvas_item_owner.get( p_item ); ERR_FAIL_COND(!canvas_item); - + CanvasItem::CommandLine * line = memnew( CanvasItem::CommandLine ); ERR_FAIL_COND(!line); line->color=p_color; @@ -3526,15 +3552,15 @@ void VisualServerRaster::canvas_item_add_line(RID p_item, const Point2& p_from, line->width=p_width; canvas_item->rect_dirty=true; - - canvas_item->commands.push_back(line); + + canvas_item->commands.push_back(line); } void VisualServerRaster::canvas_item_add_rect(RID p_item, const Rect2& p_rect, const Color& p_color) { VS_CHANGED; CanvasItem *canvas_item = canvas_item_owner.get( p_item ); ERR_FAIL_COND(!canvas_item); - + CanvasItem::CommandRect * rect = memnew( CanvasItem::CommandRect ); ERR_FAIL_COND(!rect); rect->modulate=p_color; @@ -3564,7 +3590,7 @@ void VisualServerRaster::canvas_item_add_texture_rect(RID p_item, const Rect2& p VS_CHANGED; CanvasItem *canvas_item = canvas_item_owner.get( p_item ); ERR_FAIL_COND(!canvas_item); - + CanvasItem::CommandRect * rect = memnew( CanvasItem::CommandRect ); ERR_FAIL_COND(!rect); rect->modulate=p_modulate; @@ -3596,7 +3622,7 @@ void VisualServerRaster::canvas_item_add_texture_rect_region(RID p_item, const R VS_CHANGED; CanvasItem *canvas_item = canvas_item_owner.get( p_item ); ERR_FAIL_COND(!canvas_item); - + CanvasItem::CommandRect * rect = memnew( CanvasItem::CommandRect ); ERR_FAIL_COND(!rect); rect->modulate=p_modulate; @@ -3622,8 +3648,8 @@ void VisualServerRaster::canvas_item_add_texture_rect_region(RID p_item, const R canvas_item->rect_dirty=true; - canvas_item->commands.push_back(rect); - + canvas_item->commands.push_back(rect); + } void VisualServerRaster::canvas_item_add_style_box(RID p_item, const Rect2& p_rect, RID p_texture,const Vector2& p_topleft, const Vector2& p_bottomright, bool p_draw_center,const Color& p_modulate) { @@ -3631,7 +3657,7 @@ void VisualServerRaster::canvas_item_add_style_box(RID p_item, const Rect2& p_re VS_CHANGED; CanvasItem *canvas_item = canvas_item_owner.get( p_item ); ERR_FAIL_COND(!canvas_item); - + CanvasItem::CommandStyle * style = memnew( CanvasItem::CommandStyle ); ERR_FAIL_COND(!style); style->texture=p_texture; @@ -3644,13 +3670,13 @@ void VisualServerRaster::canvas_item_add_style_box(RID p_item, const Rect2& p_re style->margin[MARGIN_BOTTOM]=p_bottomright.y; canvas_item->rect_dirty=true; - canvas_item->commands.push_back(style); + canvas_item->commands.push_back(style); } void VisualServerRaster::canvas_item_add_primitive(RID p_item,const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, RID p_texture,float p_width) { VS_CHANGED; CanvasItem *canvas_item = canvas_item_owner.get( p_item ); ERR_FAIL_COND(!canvas_item); - + CanvasItem::CommandPrimitive * prim = memnew( CanvasItem::CommandPrimitive ); ERR_FAIL_COND(!prim); prim->texture=p_texture; @@ -3660,7 +3686,7 @@ void VisualServerRaster::canvas_item_add_primitive(RID p_item,const Vector<Point prim->width=p_width; canvas_item->rect_dirty=true; - canvas_item->commands.push_back(prim); + canvas_item->commands.push_back(prim); } void VisualServerRaster::canvas_item_add_polygon(RID p_item, const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, RID p_texture) { @@ -3881,10 +3907,10 @@ void VisualServerRaster::canvas_item_clear(RID p_item) { VS_CHANGED; CanvasItem *canvas_item = canvas_item_owner.get( p_item ); ERR_FAIL_COND(!canvas_item); - - + + canvas_item->clear(); - + } void VisualServerRaster::canvas_item_raise(RID p_item) { @@ -4372,7 +4398,7 @@ void VisualServerRaster::black_bars_set_images(RID p_left, RID p_top, RID p_righ void VisualServerRaster::_free_attached_instances(RID p_rid,bool p_free_scenario) { Map< RID, Set<RID> >::Element * E = instance_dependency_map.find( p_rid ); - + if (E) { // has instances while( E->get().size() ) { @@ -4381,10 +4407,10 @@ void VisualServerRaster::_free_attached_instances(RID p_rid,bool p_free_scenario instance_set_scenario( E->get().front()->get(), RID() ); else instance_set_base( E->get().front()->get(), RID() ); - + } } - + instance_dependency_map.erase(p_rid); } @@ -4426,7 +4452,7 @@ void VisualServerRaster::free( RID p_rid ) { VS_CHANGED; if (rasterizer->is_texture(p_rid) || rasterizer->is_material(p_rid) || rasterizer->is_shader(p_rid) || rasterizer->is_environment(p_rid)) { - + rasterizer->free(p_rid); } else if (rasterizer->is_skeleton(p_rid)) { @@ -4444,14 +4470,14 @@ void VisualServerRaster::free( RID p_rid ) { rasterizer->free(p_rid); } else if (rasterizer->is_mesh(p_rid) || rasterizer->is_multimesh(p_rid) || rasterizer->is_light(p_rid) || rasterizer->is_particles(p_rid) || rasterizer->is_immediate(p_rid)) { //delete the resource - + _free_attached_instances(p_rid); rasterizer->free(p_rid); } else if (room_owner.owns(p_rid)) { _free_attached_instances(p_rid); - Room *room = room_owner.get(p_rid); - ERR_FAIL_COND(!room); + Room *room = room_owner.get(p_rid); + ERR_FAIL_COND(!room); room_owner.free(p_rid); memdelete(room); @@ -4489,16 +4515,16 @@ void VisualServerRaster::free( RID p_rid ) { } else if (camera_owner.owns(p_rid)) { // delete te camera - + Camera *camera = camera_owner.get(p_rid); ERR_FAIL_COND(!camera); - + camera_owner.free( p_rid ); memdelete(camera); - + } else if (viewport_owner.owns(p_rid)) { // delete the viewport - + Viewport *viewport = viewport_owner.get( p_rid ); ERR_FAIL_COND(!viewport); @@ -4523,15 +4549,15 @@ void VisualServerRaster::free( RID p_rid ) { viewport->canvas_map.erase(viewport->canvas_map.front()); } - - viewport_owner.free(p_rid); + + viewport_owner.free(p_rid); memdelete(viewport); - + } else if (instance_owner.owns(p_rid)) { // delete the instance - + _update_instances(); // be sure - + Instance *instance = instance_owner.get(p_rid); ERR_FAIL_COND(!instance); @@ -4546,9 +4572,9 @@ void VisualServerRaster::free( RID p_rid ) { instance_owner.free(p_rid); memdelete(instance); - + } else if (canvas_owner.owns(p_rid)) { - + Canvas *canvas = canvas_owner.get(p_rid); ERR_FAIL_COND(!canvas); @@ -4580,11 +4606,11 @@ void VisualServerRaster::free( RID p_rid ) { } canvas_owner.free( p_rid ); - + memdelete( canvas ); - + } else if (canvas_item_owner.owns(p_rid)) { - + CanvasItem *canvas_item = canvas_item_owner.get(p_rid); ERR_FAIL_COND(!canvas_item); @@ -4612,7 +4638,7 @@ void VisualServerRaster::free( RID p_rid ) { } canvas_item_owner.free( p_rid ); - + memdelete( canvas_item ); } else if (canvas_item_material_owner.owns(p_rid)) { @@ -4684,22 +4710,22 @@ void VisualServerRaster::free( RID p_rid ) { memdelete(occluder_poly); } else if (scenario_owner.owns(p_rid)) { - + Scenario *scenario=scenario_owner.get(p_rid); ERR_FAIL_COND(!scenario); - + _update_instances(); // be sure _free_attached_instances(p_rid,true); - + //rasterizer->free( scenario->environment ); scenario_owner.free(p_rid); memdelete(scenario); - + } else { - + ERR_FAIL(); } - + } @@ -4721,7 +4747,7 @@ void VisualServerRaster::_instance_draw(Instance *p_instance) { switch(p_instance->base_type) { - + case INSTANCE_MESH: { const float *morphs = NULL; if (!p_instance->data.morph_values.empty()) { @@ -4729,7 +4755,7 @@ void VisualServerRaster::_instance_draw(Instance *p_instance) { } rasterizer->add_mesh(p_instance->base_rid, &p_instance->data); - } break; + } break; case INSTANCE_MULTIMESH: { rasterizer->add_multimesh(p_instance->base_rid, &p_instance->data); } break; @@ -4839,17 +4865,17 @@ Vector<Plane> VisualServerRaster::_camera_generate_orthogonal_planes(Instance *p void VisualServerRaster::_light_instance_update_pssm_shadow(Instance *p_light,Scenario *p_scenario,Camera *p_camera,const CullRange& p_cull_range) { int splits = rasterizer->light_instance_get_shadow_passes( p_light->light_info->instance ); - + float split_weight=rasterizer->light_directional_get_shadow_param(p_light->base_rid,LIGHT_DIRECTIONAL_SHADOW_PARAM_PSSM_SPLIT_WEIGHT); float distances[5]; float texsize=rasterizer->light_instance_get_shadow_size( p_light->light_info->instance ); - + // float cull_min=p_cull_range.min; //float cull_max=p_cull_range.max; - + bool overlap = rasterizer->light_instance_get_pssm_shadow_overlap(p_light->light_info->instance); float cull_min=p_camera->znear; @@ -4857,7 +4883,7 @@ void VisualServerRaster::_light_instance_update_pssm_shadow(Instance *p_light,Sc float max_dist = rasterizer->light_directional_get_shadow_param(p_light->base_rid,VS::LIGHT_DIRECTIONAL_SHADOW_PARAM_MAX_DISTANCE); if (max_dist>0.0) cull_max=MIN(cull_max,max_dist); - + for(int i = 0; i < splits; i++) { float idm = i / (float)splits; float lg = cull_min * Math::pow(cull_max/cull_min, idm); @@ -4868,16 +4894,16 @@ void VisualServerRaster::_light_instance_update_pssm_shadow(Instance *p_light,Sc distances[0]=cull_min; distances[splits]=cull_max; - + for (int i=0;i<splits;i++) { - + // setup a camera matrix for that range! CameraMatrix camera_matrix; - + switch(p_camera->type) { - + case Camera::ORTHOGONAL: { - + camera_matrix.set_orthogonal( p_camera->size, viewport_rect.width / (float)viewport_rect.height, @@ -4888,7 +4914,7 @@ void VisualServerRaster::_light_instance_update_pssm_shadow(Instance *p_light,Sc ); } break; case Camera::PERSPECTIVE: { - + camera_matrix.set_perspective( p_camera->fov, @@ -4898,18 +4924,18 @@ void VisualServerRaster::_light_instance_update_pssm_shadow(Instance *p_light,Sc p_camera->vaspect ); - - } break; - } - + + } break; + } + //obtain the frustum endpoints - + Vector3 endpoints[8]; // frustum plane endpoints bool res = camera_matrix.get_endpoints(p_camera->transform,endpoints); ERR_CONTINUE(!res); - + // obtain the light frustm ranges (given endpoints) - + Vector3 x_vec=p_light->data.transform.basis.get_axis( Vector3::AXIS_X ).normalized(); Vector3 y_vec=p_light->data.transform.basis.get_axis( Vector3::AXIS_Y ).normalized(); Vector3 z_vec=p_light->data.transform.basis.get_axis( Vector3::AXIS_Z ).normalized(); @@ -4926,27 +4952,27 @@ void VisualServerRaster::_light_instance_update_pssm_shadow(Instance *p_light,Sc //used for culling for(int j=0;j<8;j++) { - + float d_x=x_vec.dot(endpoints[j]); float d_y=y_vec.dot(endpoints[j]); float d_z=z_vec.dot(endpoints[j]); - + if (j==0 || d_x<x_min) x_min=d_x; if (j==0 || d_x>x_max) x_max=d_x; - + if (j==0 || d_y<y_min) y_min=d_y; if (j==0 || d_y>y_max) y_max=d_y; - + if (j==0 || d_z<z_min) z_min=d_z; if (j==0 || d_z>z_max) z_max=d_z; - - + + } @@ -4998,10 +5024,10 @@ void VisualServerRaster::_light_instance_update_pssm_shadow(Instance *p_light,Sc } //now that we now all ranges, we can proceed to make the light frustum planes, for culling octree - + Vector<Plane> light_frustum_planes; light_frustum_planes.resize(6); - + //right/left light_frustum_planes[0]=Plane( x_vec, x_max ); light_frustum_planes[1]=Plane( -x_vec, -x_min ); @@ -5009,17 +5035,17 @@ void VisualServerRaster::_light_instance_update_pssm_shadow(Instance *p_light,Sc light_frustum_planes[2]=Plane( y_vec, y_max ); light_frustum_planes[3]=Plane( -y_vec, -y_min ); //near/far - light_frustum_planes[4]=Plane( z_vec, z_max+1e6 ); - light_frustum_planes[5]=Plane( -z_vec, -z_min ); // z_min is ok, since casters further than far-light plane are not needed - + light_frustum_planes[4]=Plane( z_vec, z_max+1e6 ); + light_frustum_planes[5]=Plane( -z_vec, -z_min ); // z_min is ok, since casters further than far-light plane are not needed + int caster_cull_count = p_scenario->octree.cull_convex(light_frustum_planes,instance_shadow_cull_result,MAX_INSTANCE_CULL,INSTANCE_GEOMETRY_MASK); - + // a pre pass will need to be needed to determine the actual z-near to be used for(int j=0;j<caster_cull_count;j++) { - + float min,max; Instance *ins=instance_shadow_cull_result[j]; - if (!ins->visible || !ins->cast_shadows) + if (!ins->visible || ins->data.cast_shadows == VS::SHADOW_CASTING_SETTING_OFF) continue; ins->transformed_aabb.project_range_in_plane(Plane(z_vec,0),min,max); @@ -5041,23 +5067,23 @@ void VisualServerRaster::_light_instance_update_pssm_shadow(Instance *p_light,Sc rasterizer->light_instance_set_shadow_transform(p_light->light_info->instance, i, ortho_camera, ortho_transform,distances[i],distances[i+1] ); } - + rasterizer->begin_shadow_map( p_light->light_info->instance, i ); - + for (int j=0;j<caster_cull_count;j++) { - + Instance *instance = instance_shadow_cull_result[j]; - if (!instance->visible || !instance->cast_shadows) + if (!instance->visible || instance->data.cast_shadows==VS::SHADOW_CASTING_SETTING_OFF) continue; _instance_draw(instance); } - + rasterizer->end_shadow_map(); - - + + } - - + + } @@ -5130,7 +5156,7 @@ void VisualServerRaster::_light_instance_update_lispsm_shadow(Instance *p_light, for(int i=0;i<caster_count;i++) { Instance *ins = instance_shadow_cull_result[i]; - if (!ins->visible || !ins->cast_shadows) + if (!ins->visible || ins->data.cast_shadows == VS::SHADOW_CASTING_SETTING_OFF) continue; for(int j=0;j<8;j++) { @@ -5281,7 +5307,7 @@ void VisualServerRaster::_light_instance_update_lispsm_shadow(Instance *p_light, Instance *instance = instance_shadow_cull_result[i]; - if (!instance->visible || !instance->cast_shadows) + if (!instance->visible || instance->data.cast_shadows == VS::SHADOW_CASTING_SETTING_OFF) continue; _instance_draw(instance); } @@ -5378,7 +5404,7 @@ void VisualServerRaster::_light_instance_update_lispsm_shadow(Instance *p_light, for(int i=0;i<caster_count;i++) { Instance *ins=instance_shadow_cull_result[i]; - if (!ins->visible || !ins->cast_shadows) + if (!ins->visible || ins->cast_shadows==VS::SHADOW_CASTING_SETTING_OFF) continue; //@TODO optimize using support mapping @@ -5468,7 +5494,7 @@ void VisualServerRaster::_light_instance_update_lispsm_shadow(Instance *p_light, Instance *instance = instance_shadow_cull_result[i]; - if (!instance->visible || !instance->cast_shadows) + if (!instance->visible || instance->cast_shadows==VS::SHADOW_CASTING_SETTING_OFF) continue; _instance_draw(instance); } @@ -5493,7 +5519,7 @@ void VisualServerRaster::_light_instance_update_shadow(Instance *p_light,Scenari Rasterizer::ShadowType shadow_type = rasterizer->light_instance_get_shadow_type(p_light->light_info->instance); switch(shadow_type) { - + case Rasterizer::SHADOW_SIMPLE: { /* SPOT SHADOW */ @@ -5516,7 +5542,7 @@ void VisualServerRaster::_light_instance_update_shadow(Instance *p_light,Scenari for (int i=0;i<cull_count;i++) { Instance *instance = instance_shadow_cull_result[i]; - if (!instance->visible || !instance->cast_shadows) + if (!instance->visible || instance->data.cast_shadows == VS::SHADOW_CASTING_SETTING_OFF) continue; _instance_draw(instance); } @@ -5557,7 +5583,7 @@ void VisualServerRaster::_light_instance_update_shadow(Instance *p_light,Scenari for (int j=0;j<cull_count;j++) { Instance *instance = instance_shadow_cull_result[j]; - if (!instance->visible || !instance->cast_shadows) + if (!instance->visible || instance->data.cast_shadows == VS::SHADOW_CASTING_SETTING_OFF) continue; _instance_draw(instance); @@ -5641,7 +5667,10 @@ void VisualServerRaster::_instance_validate_autorooms(Instance *p_geometry) { int pass = room->room_info->room->bounds.get_points_inside(dst_points,point_count); - float ratio = (float)pass / point_count; + float ratio = pass; + if( point_count != 0 ) { + ratio /= (float)point_count; + } if (ratio>0.5) // should make some constant p_geometry->valid_auto_rooms.insert(room); @@ -6021,7 +6050,7 @@ void VisualServerRaster::_cull_room(Camera *p_camera, Instance *p_room,Instance } - + } void VisualServerRaster::_process_sampled_light(const Transform& p_camera,Instance *p_sampled_light,bool p_linear_colorspace) { @@ -6353,7 +6382,7 @@ void VisualServerRaster::_render_camera(Viewport *p_viewport,Camera *p_camera, S switch(p_camera->type) { case Camera::ORTHOGONAL: { - + camera_matrix.set_orthogonal( p_camera->size, viewport_rect.width / (float)viewport_rect.height, @@ -6375,19 +6404,19 @@ void VisualServerRaster::_render_camera(Viewport *p_viewport,Camera *p_camera, S ); ortho=false; - - } break; + + } break; } rasterizer->set_camera(p_camera->transform, camera_matrix,ortho); - + Vector<Plane> planes = camera_matrix.get_projection_planes(p_camera->transform); CullRange cull_range; // cull range is used for PSSM, and having an idea of the rendering depth cull_range.nearp=Plane(p_camera->transform.origin,-p_camera->transform.basis.get_axis(2).normalized()); cull_range.z_near=camera_matrix.get_z_near(); - cull_range.z_far=camera_matrix.get_z_far(); + cull_range.z_far=camera_matrix.get_z_far(); cull_range.min=cull_range.z_far; cull_range.max=cull_range.z_near; @@ -6403,10 +6432,10 @@ void VisualServerRaster::_render_camera(Viewport *p_viewport,Camera *p_camera, S */ /* STEP 3 - PROCESS PORTALS, VALIDATE ROOMS */ - + // compute portals - + exterior_visited=false; exterior_portal_cull_count=0; @@ -6487,11 +6516,11 @@ void VisualServerRaster::_render_camera(Viewport *p_viewport,Camera *p_camera, S } /* STEP 4 - REMOVE FURTHER CULLED OBJECTS, ADD LIGHTS */ - + for(int i=0;i<cull_count;i++) { - + Instance *ins = instance_cull_result[i]; - + bool keep=false; @@ -6511,7 +6540,7 @@ void VisualServerRaster::_render_camera(Viewport *p_viewport,Camera *p_camera, S } } - } else if ((1<<ins->base_type)&INSTANCE_GEOMETRY_MASK && ins->visible) { + } else if ((1<<ins->base_type)&INSTANCE_GEOMETRY_MASK && ins->visible && ins->data.cast_shadows!=VS::SHADOW_CASTING_SETTING_SHADOWS_ONLY) { bool discarded=false; @@ -6577,7 +6606,7 @@ void VisualServerRaster::_render_camera(Viewport *p_viewport,Camera *p_camera, S } } } - + } if (!keep) { @@ -6591,12 +6620,12 @@ void VisualServerRaster::_render_camera(Viewport *p_viewport,Camera *p_camera, S ins->last_render_pass=render_pass; } } - + if (cull_range.max > cull_range.z_far ) cull_range.max=cull_range.z_far; if (cull_range.min < cull_range.z_near ) cull_range.min=cull_range.z_near; - + /* STEP 5 - PROCESS LIGHTS */ rasterizer->shadow_clear_near(); //clear near shadows, will be recreated @@ -6623,7 +6652,7 @@ void VisualServerRaster::_render_camera(Viewport *p_viewport,Camera *p_camera, S //discard lights not affecting anything (useful for deferred rendering, shadowmaps, etc) for (int i=0;i<light_cull_count;i++) { - + Instance *ins = light_cull_result[i]; if (light_discard_enabled) { @@ -6652,7 +6681,7 @@ void VisualServerRaster::_render_camera(Viewport *p_viewport,Camera *p_camera, S } } - + } { //this should eventually change to @@ -6665,12 +6694,12 @@ void VisualServerRaster::_render_camera(Viewport *p_viewport,Camera *p_camera, S if (!rasterizer->light_has_shadow(ins->base_rid) || !shadows_enabled) continue; - + /* for far shadows? if (ins->version == ins->light_info->last_version && rasterizer->light_instance_has_far_shadow(ins->light_info->instance)) continue; // didn't change */ - + _light_instance_update_shadow(ins,p_scenario,p_camera,cull_range); ins->light_info->last_version=ins->version; } @@ -6700,17 +6729,17 @@ void VisualServerRaster::_render_camera(Viewport *p_viewport,Camera *p_camera, S } /* STEP 7 - PROCESS GEOMETRY AND DRAW SCENE*/ - + rasterizer->begin_scene(p_viewport->viewport_data,environment,p_scenario->debug); - rasterizer->set_viewport(viewport_rect); - + rasterizer->set_viewport(viewport_rect); + // add lights { List<RID>::Element *E=p_scenario->directional_lights.front(); - + for(;E;E=E->next()) { Instance *light = E->get().is_valid()?instance_owner.get(E->get()):NULL; @@ -6732,11 +6761,11 @@ void VisualServerRaster::_render_camera(Viewport *p_viewport,Camera *p_camera, S // add geometry for(int i=0;i<cull_count;i++) { - + Instance *ins = instance_cull_result[i]; ERR_CONTINUE(!((1<<ins->base_type)&INSTANCE_GEOMETRY_MASK)); - + _instance_draw(ins); } @@ -6797,7 +6826,7 @@ void VisualServerRaster::_render_canvas_item(CanvasItem *p_canvas_item,const Mat if (global_rect.intersects(p_clip_rect) && ci->viewport.is_valid() && viewport_owner.owns(ci->viewport)) { - Viewport *vp = viewport_owner.get(ci->viewport); + Viewport *vp = viewport_owner.get(ci->viewport); Point2i from = xform.get_origin() + Point2(viewport_rect.x,viewport_rect.y); Point2i size = rect.size; @@ -7338,7 +7367,7 @@ void VisualServerRaster::_draw_viewports() { rasterizer->set_viewport(viewport_rect); } - rasterizer->canvas_begin(); + rasterizer->canvas_begin(); rasterizer->canvas_disable_blending(); rasterizer->canvas_begin_rect(Matrix32()); rasterizer->canvas_draw_rect(E->get()->rt_to_screen_rect,0,Rect2(Point2(),E->get()->rt_to_screen_rect.size),E->get()->render_target_texture,Color(1,1,1)); @@ -7466,7 +7495,7 @@ void VisualServerRaster::draw() { rasterizer->begin_frame(); _draw_viewports(); _draw_cursors_and_margins(); - rasterizer->end_frame(); + rasterizer->end_frame(); draw_extra_frame=rasterizer->needs_to_draw_next_frame(); } @@ -7548,13 +7577,13 @@ void VisualServerRaster::set_boot_image(const Image& p_image, const Color& p_col void VisualServerRaster::init() { rasterizer->init(); - + shadows_enabled=GLOBAL_DEF("render/shadows_enabled",true); //default_scenario = scenario_create(); //default_viewport = viewport_create(); for(int i=0;i<4;i++) black_margin[i]=0; - + Image img; img.create(default_mouse_cursor_xpm); //img.convert(Image::FORMAT_RGB); @@ -7571,7 +7600,7 @@ void VisualServerRaster::_clean_up_owner(RID_OwnerBase *p_owner,String p_type) { List<RID> rids; p_owner->get_owned_list(&rids); - + int lost=0; for(List<RID>::Element *I=rids.front();I;I=I->next()) { if (OS::get_singleton()->is_stdout_verbose()) { @@ -7596,19 +7625,19 @@ void VisualServerRaster::finish() { _clean_up_owner( &room_owner,"Room" ); _clean_up_owner( &portal_owner,"Portal" ); - + _clean_up_owner( &camera_owner,"Camera" ); _clean_up_owner( &viewport_owner,"Viewport" ); - + _clean_up_owner( &scenario_owner,"Scenario" ); _clean_up_owner( &instance_owner,"Instance" ); - + _clean_up_owner( &canvas_owner,"Canvas" ); _clean_up_owner( &canvas_item_owner,"CanvasItem" ); rasterizer->finish(); octree_allocator.clear(); - + if (instance_dependency_map.size()) { print_line("Base resources missing amount: "+itos(instance_dependency_map.size())); } @@ -7620,9 +7649,9 @@ RID VisualServerRaster::get_test_cube() { if (test_cube.is_valid()) return test_cube; - + test_cube=_make_test_cube(); - return test_cube; + return test_cube; } @@ -7644,5 +7673,3 @@ VisualServerRaster::VisualServerRaster(Rasterizer *p_rasterizer) { VisualServerRaster::~VisualServerRaster() { } - - diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index 459dc60e81..77d5780c5f 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -44,7 +44,7 @@ class VisualServerRaster : public VisualServer { enum { - + MAX_INSTANCE_CULL=8192, MAX_INSTANCE_LIGHTS=4, LIGHT_CACHE_DIRTY=-1, @@ -58,13 +58,13 @@ class VisualServerRaster : public VisualServer { }; struct Room { - + bool occlude_exterior; BSP_Tree bounds; Room() { occlude_exterior=true; } }; - - + + BalloonAllocator<> octree_allocator; struct OctreeAllocator { @@ -116,10 +116,10 @@ class VisualServerRaster : public VisualServer { void _update_baked_light_sampler_dp_cache(BakedLightSampler * blsamp); struct Camera { - + enum Type { PERSPECTIVE, - ORTHOGONAL + ORTHOGONAL }; Type type; float fov; @@ -128,18 +128,18 @@ class VisualServerRaster : public VisualServer { uint32_t visible_layers; bool vaspect; RID env; - + Transform transform; - + Camera() { - + visible_layers=0xFFFFFFFF; fov=60; type=PERSPECTIVE; znear=0.1; zfar=100; size=1.0; vaspect=false; - + } }; @@ -147,29 +147,28 @@ class VisualServerRaster : public VisualServer { struct Instance; typedef Set<Instance*,Comparator<Instance*>,OctreeAllocator> InstanceSet; struct Scenario; - + struct Instance { - + enum { - + MAX_LIGHTS=4 }; - + RID self; - OctreeElementID octree_id; + OctreeElementID octree_id; Scenario *scenario; bool update; bool update_aabb; - Instance *update_next; + Instance *update_next; InstanceType base_type; RID base_rid; - + AABB aabb; AABB transformed_aabb; uint32_t object_ID; bool visible; - bool cast_shadows; bool receive_shadows; bool visible_in_all_rooms; uint32_t layer_mask; @@ -181,7 +180,7 @@ class VisualServerRaster : public VisualServer { Rasterizer::InstanceData data; - + Set<Instance*> auto_rooms; Set<Instance*> valid_auto_rooms; Instance *room; @@ -193,9 +192,9 @@ class VisualServerRaster : public VisualServer { uint64_t last_render_pass; uint64_t last_frame_pass; - + uint64_t version; // changes to this, and changes to base increase version - + InstanceSet lights; bool light_cache_dirty; @@ -206,7 +205,7 @@ class VisualServerRaster : public VisualServer { Transform affine_inverse; Room *room; List<Instance*> owned_geometry_instances; - List<Instance*> owned_portal_instances; + List<Instance*> owned_portal_instances; List<Instance*> owned_room_instances; List<Instance*> owned_light_instances; //not used, but just for the sake of it Set<Instance*> disconnected_child_portals; @@ -231,8 +230,8 @@ class VisualServerRaster : public VisualServer { }; struct LightInfo { - - RID instance; + + RID instance; int light_set_index; uint64_t last_version; uint64_t last_add_pass; @@ -241,10 +240,10 @@ class VisualServerRaster : public VisualServer { bool enabled; float dtc; //distance to camera, used for sorting - + LightInfo() { - - D=NULL; + + D=NULL; light_set_index=-1; last_add_pass=0; enabled=true; @@ -274,10 +273,10 @@ class VisualServerRaster : public VisualServer { resolution=0; } }; - + struct ParticlesInfo { - - RID instance; + + RID instance; }; @@ -289,7 +288,7 @@ class VisualServerRaster : public VisualServer { BakedLightSamplerInfo * baked_light_sampler_info; - Instance() { + Instance() { octree_id=0; update_next=0; object_ID=0; @@ -300,7 +299,7 @@ class VisualServerRaster : public VisualServer { update_next=NULL; update=false; visible=true; - cast_shadows=true; + data.cast_shadows=SHADOW_CASTING_SETTING_ON; receive_shadows=true; data.depth_scale=false; data.billboard=false; @@ -329,9 +328,9 @@ class VisualServerRaster : public VisualServer { light_cache_dirty=true; } - + ~Instance() { - + if (light_info) memdelete(light_info); if (particles_info) @@ -344,26 +343,26 @@ class VisualServerRaster : public VisualServer { memdelete(baked_light_info); }; }; - + struct _InstanceLightsort { bool operator()(const Instance* p_A, const Instance* p_B) const { return p_A->light_info->dtc < p_B->light_info->dtc; } }; struct Scenario { - + ScenarioDebugMode debug; RID self; // well wtf, balloon allocator is slower? typedef ::Octree<Instance,true> Octree; - + Octree octree; - + List<RID> directional_lights; RID environment; RID fallback_environment; - + Instance *dirty_instances; Scenario() { dirty_instances=NULL; debug=SCENARIO_DEBUG_DISABLED; } @@ -459,7 +458,7 @@ class VisualServerRaster : public VisualServer { } Canvas() { modulate=Color(1,1,1,1); } - + }; @@ -525,14 +524,14 @@ class VisualServerRaster : public VisualServer { Map<RID,int> screen_viewports; struct CullRange { - + Plane nearp; float min,max; float z_near,z_far; - + void add_aabb(const AABB& p_aabb) { - - + + } }; @@ -560,12 +559,12 @@ class VisualServerRaster : public VisualServer { Instance *instance_cull_result[MAX_INSTANCE_CULL]; Instance *instance_shadow_cull_result[MAX_INSTANCE_CULL]; //used for generating shadowmaps - Instance *light_cull_result[MAX_LIGHTS_CULLED]; + Instance *light_cull_result[MAX_LIGHTS_CULLED]; int light_cull_count; Instance *exterior_portal_cull_result[MAX_EXTERIOR_PORTALS]; int exterior_portal_cull_count; - bool exterior_visited; + bool exterior_visited; Instance *light_sampler_cull_result[MAX_LIGHT_SAMPLERS]; int light_samplers_culled; @@ -592,7 +591,7 @@ class VisualServerRaster : public VisualServer { void _update_instance(Instance *p_instance); void _free_attached_instances(RID p_rid,bool p_free_scenario=false); void _clean_up_owner(RID_OwnerBase *p_owner,String p_type); - + Instance *instance_update_list; //RID default_scenario; @@ -600,7 +599,7 @@ class VisualServerRaster : public VisualServer { RID test_cube; - + mutable RID_Owner<Room> room_owner; mutable RID_Owner<Portal> portal_owner; @@ -609,20 +608,20 @@ class VisualServerRaster : public VisualServer { mutable RID_Owner<Camera> camera_owner; mutable RID_Owner<Viewport> viewport_owner; - + mutable RID_Owner<Scenario> scenario_owner; mutable RID_Owner<Instance> instance_owner; - + mutable RID_Owner<Canvas> canvas_owner; mutable RID_Owner<CanvasItem> canvas_item_owner; Map< RID, Set<RID> > instance_dependency_map; Map< RID, Set<Instance*> > skeleton_dependency_map; - + ViewportRect viewport_rect; _FORCE_INLINE_ void _instance_draw(Instance *p_instance); - + bool _test_portal_cull(Camera *p_camera, Instance *p_portal_from, Instance *p_portal_to); void _cull_portal(Camera *p_camera, Instance *p_portal,Instance *p_from_portal); void _cull_room(Camera *p_camera, Instance *p_room,Instance *p_from_portal=NULL); @@ -641,9 +640,9 @@ class VisualServerRaster : public VisualServer { void _light_instance_update_lispsm_shadow(Instance *p_light,Scenario *p_scenario,Camera *p_camera,const CullRange& p_cull_range); void _light_instance_update_pssm_shadow(Instance *p_light,Scenario *p_scenario,Camera *p_camera,const CullRange& p_cull_range); - + void _light_instance_update_shadow(Instance *p_light,Scenario *p_scenario,Camera *p_camera,const CullRange& p_cull_range); - + uint64_t render_pass; int changes; bool draw_extra_frame; @@ -652,8 +651,8 @@ class VisualServerRaster : public VisualServer { void _draw_viewport(Viewport *p_viewport,int p_ofs_x, int p_ofs_y,int p_parent_w,int p_parent_h); void _draw_viewports(); void _draw_cursors_and_margins(); - - + + Rasterizer *rasterizer; public: @@ -677,7 +676,7 @@ public: /* SHADER API */ - + virtual RID shader_create(ShaderMode p_mode=SHADER_MATERIAL); virtual void shader_set_mode(RID p_shader,ShaderMode p_mode); @@ -765,7 +764,7 @@ public: virtual int mesh_surface_get_array_index_len(RID p_mesh, int p_surface) const; virtual uint32_t mesh_surface_get_format(RID p_mesh, int p_surface) const; virtual PrimitiveType mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const; - + virtual void mesh_remove_surface(RID p_mesh,int p_index); virtual int mesh_get_surface_count(RID p_mesh) const; @@ -808,23 +807,23 @@ public: virtual void immediate_set_material(RID p_immediate,RID p_material); virtual RID immediate_get_material(RID p_immediate) const; - + /* PARTICLES API */ - + virtual RID particles_create(); - + virtual void particles_set_amount(RID p_particles, int p_amount); virtual int particles_get_amount(RID p_particles) const; - + virtual void particles_set_emitting(RID p_particles, bool p_emitting); virtual bool particles_is_emitting(RID p_particles) const; - + virtual void particles_set_visibility_aabb(RID p_particles, const AABB& p_visibility); virtual AABB particles_get_visibility_aabb(RID p_particles) const; - + virtual void particles_set_emission_half_extents(RID p_particles, const Vector3& p_half_extents); virtual Vector3 particles_get_emission_half_extents(RID p_particles) const; - + virtual void particles_set_emission_base_velocity(RID p_particles, const Vector3& p_base_velocity); virtual Vector3 particles_get_emission_base_velocity(RID p_particles) const; @@ -833,16 +832,16 @@ public: virtual void particles_set_gravity_normal(RID p_particles, const Vector3& p_normal); virtual Vector3 particles_get_gravity_normal(RID p_particles) const; - + virtual void particles_set_variable(RID p_particles, ParticleVariable p_variable,float p_value); virtual float particles_get_variable(RID p_particles, ParticleVariable p_variable) const; - + virtual void particles_set_randomness(RID p_particles, ParticleVariable p_variable,float p_randomness); virtual float particles_get_randomness(RID p_particles, ParticleVariable p_variable) const; - + virtual void particles_set_color_phase_pos(RID p_particles, int p_phase, float p_pos); virtual float particles_get_color_phase_pos(RID p_particles, int p_phase) const; - + virtual void particles_set_color_phases(RID p_particles, int p_phases); virtual int particles_get_color_phases(RID p_particles) const; @@ -860,32 +859,32 @@ public: virtual void particles_set_material(RID p_particles, RID p_material,bool p_owned=false); virtual RID particles_get_material(RID p_particles) const; - + virtual void particles_set_height_from_velocity(RID p_particles, bool p_enable); virtual bool particles_has_height_from_velocity(RID p_particles) const; virtual void particles_set_use_local_coordinates(RID p_particles, bool p_enable); virtual bool particles_is_using_local_coordinates(RID p_particles) const; - + /* Light API */ - + virtual RID light_create(LightType p_type); virtual LightType light_get_type(RID p_light) const; virtual void light_set_color(RID p_light,LightColor p_type, const Color& p_color); - virtual Color light_get_color(RID p_light,LightColor p_type) const; - + virtual Color light_get_color(RID p_light,LightColor p_type) const; + virtual void light_set_shadow(RID p_light,bool p_enabled); - virtual bool light_has_shadow(RID p_light) const; - + virtual bool light_has_shadow(RID p_light) const; + virtual void light_set_volumetric(RID p_light,bool p_enabled); - virtual bool light_is_volumetric(RID p_light) const; - + virtual bool light_is_volumetric(RID p_light) const; + virtual void light_set_projector(RID p_light,RID p_texture); virtual RID light_get_projector(RID p_light) const; - + virtual void light_set_param(RID p_light, LightParam p_var, float p_value); virtual float light_get_param(RID p_light, LightParam p_var) const; @@ -902,7 +901,7 @@ public: /* SKELETON API */ - + virtual RID skeleton_create(); virtual void skeleton_resize(RID p_skeleton,int p_bones); virtual int skeleton_get_bone_count(RID p_skeleton) const; @@ -914,9 +913,9 @@ public: virtual RID room_create(); virtual void room_set_bounds(RID p_room, const BSP_Tree& p_bounds); virtual BSP_Tree room_get_bounds(RID p_room) const; - + /* PORTAL API */ - + virtual RID portal_create(); virtual void portal_set_shape(RID p_portal, const Vector<Point2>& p_shape); virtual Vector<Point2> portal_get_shape(RID p_portal) const; @@ -962,12 +961,12 @@ public: virtual int baked_light_sampler_get_resolution(RID p_baked_light_sampler) const; /* CAMERA API */ - + virtual RID camera_create(); virtual void camera_set_perspective(RID p_camera,float p_fovy_degrees, float p_z_near, float p_z_far); virtual void camera_set_orthogonal(RID p_camera,float p_size, float p_z_near, float p_z_far); - virtual void camera_set_transform(RID p_camera,const Transform& p_transform); - + virtual void camera_set_transform(RID p_camera,const Transform& p_transform); + virtual void camera_set_visible_layers(RID p_camera,uint32_t p_layers); virtual uint32_t camera_get_visible_layers(RID p_camera) const; @@ -1001,7 +1000,7 @@ public: virtual void viewport_set_rect(RID p_viewport,const ViewportRect& p_rect); virtual ViewportRect viewport_get_rect(RID p_viewport) const; - + virtual void viewport_set_hide_scenario(RID p_viewport,bool p_hide); virtual void viewport_set_hide_canvas(RID p_viewport,bool p_hide); virtual void viewport_set_disable_environment(RID p_viewport,bool p_disable); @@ -1012,8 +1011,8 @@ public: virtual RID viewport_get_scenario(RID p_viewport) const; virtual void viewport_attach_canvas(RID p_viewport,RID p_canvas); virtual void viewport_remove_canvas(RID p_viewport,RID p_canvas); - virtual void viewport_set_canvas_transform(RID p_viewport,RID p_canvas,const Matrix32& p_offset); - virtual Matrix32 viewport_get_canvas_transform(RID p_viewport,RID p_canvas) const; + virtual void viewport_set_canvas_transform(RID p_viewport,RID p_canvas,const Matrix32& p_offset); + virtual Matrix32 viewport_get_canvas_transform(RID p_viewport,RID p_canvas) const; virtual void viewport_set_global_canvas_transform(RID p_viewport,const Matrix32& p_transform); virtual Matrix32 viewport_get_global_canvas_transform(RID p_viewport) const; virtual void viewport_set_canvas_layer(RID p_viewport,RID p_canvas,int p_layer); @@ -1038,10 +1037,10 @@ public: virtual void environment_fx_set_param(RID p_env,EnvironmentFxParam p_effect,const Variant& p_param); virtual Variant environment_fx_get_param(RID p_env,EnvironmentFxParam p_effect) const; - + /* SCENARIO API */ - - virtual RID scenario_create(); + + virtual RID scenario_create(); virtual void scenario_set_debug(RID p_scenario,ScenarioDebugMode p_debug_mode); virtual void scenario_set_environment(RID p_scenario, RID p_environment); @@ -1049,9 +1048,9 @@ public: virtual void scenario_set_fallback_environment(RID p_scenario, RID p_environment); - + /* INSTANCING API */ - + virtual RID instance_create(); virtual void instance_set_base(RID p_instance, RID p_base); @@ -1093,6 +1092,9 @@ public: virtual void instance_geometry_set_flag(RID p_instance,InstanceFlags p_flags,bool p_enabled); virtual bool instance_geometry_get_flag(RID p_instance,InstanceFlags p_flags) const; + virtual void instance_geometry_set_cast_shadows_setting(RID p_instance, VS::ShadowCastingSetting p_shadow_casting_setting); + virtual VS::ShadowCastingSetting instance_geometry_get_cast_shadows_setting(RID p_instance) const; + virtual void instance_geometry_set_material_override(RID p_instance, RID p_material); virtual RID instance_geometry_get_material_override(RID p_instance) const; @@ -1113,7 +1115,7 @@ public: virtual bool instance_light_is_enabled(RID p_instance) const; /* CANVAS (2D) */ - + virtual RID canvas_create(); virtual void canvas_set_item_mirroring(RID p_canvas,RID p_item,const Point2& p_mirroring); virtual Point2 canvas_get_item_mirroring(RID p_canvas,RID p_item) const; @@ -1215,7 +1217,7 @@ public: virtual RID canvas_item_material_create(); virtual void canvas_item_material_set_shader(RID p_material, RID p_shader); virtual void canvas_item_material_set_shader_param(RID p_material, const StringName& p_param, const Variant& p_value); - virtual Variant canvas_item_material_get_shader_param(RID p_material, const StringName& p_param) const; + virtual Variant canvas_item_material_get_shader_param(RID p_material, const StringName& p_param) const; virtual void canvas_item_material_set_shading_mode(RID p_material, CanvasItemShadingMode p_mode); @@ -1232,7 +1234,7 @@ public: virtual void black_bars_set_images(RID p_left, RID p_top, RID p_right, RID p_bottom); /* FREE */ - + virtual void free( RID p_rid ); /* CUSTOM SHADE MODEL */ @@ -1249,7 +1251,7 @@ public: virtual void draw(); virtual void sync(); - virtual void init(); + virtual void init(); virtual void finish(); virtual bool has_changed() const; @@ -1264,7 +1266,7 @@ public: virtual void set_boot_image(const Image& p_image, const Color& p_color, bool p_scale); virtual void set_default_clear_color(const Color& p_color); - VisualServerRaster(Rasterizer *p_rasterizer); + VisualServerRaster(Rasterizer *p_rasterizer); ~VisualServerRaster(); }; diff --git a/servers/visual/visual_server_wrap_mt.cpp b/servers/visual/visual_server_wrap_mt.cpp index 478a31806c..5ea4145342 100644 --- a/servers/visual/visual_server_wrap_mt.cpp +++ b/servers/visual/visual_server_wrap_mt.cpp @@ -35,20 +35,20 @@ void VisualServerWrapMT::thread_exit() { } void VisualServerWrapMT::thread_draw() { - - + + draw_mutex->lock(); - + draw_pending--; bool draw=(draw_pending==0);// only draw when no more flushes are pending - + draw_mutex->unlock(); - + if (draw) { - + visual_server->draw(); - } - + } + } void VisualServerWrapMT::thread_flush() { @@ -67,10 +67,10 @@ void VisualServerWrapMT::thread_flush() { void VisualServerWrapMT::_thread_callback(void *_instance) { VisualServerWrapMT *vsmt = reinterpret_cast<VisualServerWrapMT*>(_instance); - + vsmt->thread_loop(); -} +} void VisualServerWrapMT::thread_loop() { @@ -79,18 +79,18 @@ void VisualServerWrapMT::thread_loop() { OS::get_singleton()->make_rendering_thread(); visual_server->init(); - + exit=false; draw_thread_up=true; while(!exit) { // flush commands one by one, until exit is requested command_queue.wait_and_flush_one(); } - + command_queue.flush_all(); // flush all - + visual_server->finish(); - + } @@ -117,7 +117,7 @@ void VisualServerWrapMT::sync() { } void VisualServerWrapMT::draw() { - + if (create_thread) { @@ -155,7 +155,7 @@ void VisualServerWrapMT::init() { visual_server->init(); } - + } void VisualServerWrapMT::finish() { @@ -164,7 +164,7 @@ void VisualServerWrapMT::finish() { if (thread) { command_queue.push( this, &VisualServerWrapMT::thread_exit); - Thread::wait_to_finish( thread ); + Thread::wait_to_finish( thread ); memdelete(thread); diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h index fb502d8a6e..52e38c8438 100644 --- a/servers/visual/visual_server_wrap_mt.h +++ b/servers/visual/visual_server_wrap_mt.h @@ -41,9 +41,9 @@ class VisualServerWrapMT : public VisualServer { // the real visual server mutable VisualServer *visual_server; - + mutable CommandQueueMT command_queue; - + static void _thread_callback(void *_instance); void thread_loop(); @@ -52,7 +52,7 @@ class VisualServerWrapMT : public VisualServer { Thread *thread; volatile bool draw_thread_up; bool create_thread; - + Mutex *draw_mutex; int draw_pending; void thread_draw(); @@ -433,7 +433,7 @@ public: FUNC2(viewport_set_render_target_vflip,RID,bool); FUNC1RC(bool,viewport_get_render_target_vflip,RID); FUNC2(viewport_set_render_target_to_screen_rect,RID,const Rect2&); - + FUNC2(viewport_set_render_target_clear_on_new_frame,RID,bool); FUNC1RC(bool,viewport_get_render_target_clear_on_new_frame,RID); FUNC1(viewport_render_target_clear,RID); @@ -534,6 +534,9 @@ public: FUNC3(instance_geometry_set_flag,RID,InstanceFlags ,bool ); FUNC2RC(bool,instance_geometry_get_flag,RID,InstanceFlags ); + FUNC2(instance_geometry_set_cast_shadows_setting, RID, ShadowCastingSetting); + FUNC1RC(ShadowCastingSetting, instance_geometry_get_cast_shadows_setting, RID); + FUNC2(instance_geometry_set_material_override,RID, RID ); FUNC1RC(RID,instance_geometry_get_material_override,RID); @@ -660,7 +663,7 @@ public: FUNC0R(RID,canvas_item_material_create); FUNC2(canvas_item_material_set_shader,RID,RID); FUNC3(canvas_item_material_set_shader_param,RID,const StringName&,const Variant&); - FUNC2RC(Variant,canvas_item_material_get_shader_param,RID,const StringName&); + FUNC2RC(Variant,canvas_item_material_get_shader_param,RID,const StringName&); FUNC2(canvas_item_material_set_shading_mode,RID,CanvasItemShadingMode); /* CURSOR */ diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp index fd2913cc7e..17d5b16b9f 100644 --- a/servers/visual_server.cpp +++ b/servers/visual_server.cpp @@ -73,11 +73,11 @@ DVector<String> VisualServer::_shader_get_param_list(RID p_shader) const { VisualServer *VisualServer::create() { ERR_FAIL_COND_V(singleton,NULL); - + if (create_func) return create_func(); - - return NULL; + + return NULL; } RID VisualServer::texture_create_from_image(const Image& p_image,uint32_t p_flags) { @@ -87,7 +87,7 @@ RID VisualServer::texture_create_from_image(const Image& p_image,uint32_t p_flag ERR_FAIL_COND_V(!texture.is_valid(),texture); texture_set_data(texture, p_image ); - + return texture; } @@ -152,9 +152,9 @@ RID VisualServer::_make_test_cube() { DVector<Vector3> vertices; DVector<Vector3> normals; - DVector<float> tangents; + DVector<float> tangents; DVector<Vector3> uvs; - + int vtx_idx=0; #define ADD_VTX(m_idx);\ vertices.push_back( face_points[m_idx] );\ @@ -168,20 +168,20 @@ RID VisualServer::_make_test_cube() { for (int i=0;i<6;i++) { - + Vector3 face_points[4]; Vector3 normal_points[4]; float uv_points[8]={0,0,0,1,1,1,1,0}; - + for (int j=0;j<4;j++) { - + float v[3]; v[0]=1.0; v[1]=1-2*((j>>1)&1); v[2]=v[1]*(1-2*(j&1)); - + for (int k=0;k<3;k++) { - + if (i<3) face_points[j][(i+k)%3]=v[k]*(i>=3?-1:1); else @@ -218,7 +218,7 @@ RID VisualServer::_make_test_cube() { d[VisualServer::ARRAY_INDEX]=indices; mesh_add_surface( test_cube, PRIMITIVE_TRIANGLES,d ); - + test_material = fixed_material_create(); @@ -231,51 +231,51 @@ RID VisualServer::_make_test_cube() { fixed_material_set_param( test_material, FIXED_MATERIAL_PARAM_SPECULAR, Color(1,1,1) ); mesh_surface_set_material(test_cube, 0, test_material ); - + return test_cube; } RID VisualServer::make_sphere_mesh(int p_lats,int p_lons,float p_radius) { - + DVector<Vector3> vertices; DVector<Vector3> normals; - + for(int i = 1; i <= p_lats; i++) { double lat0 = Math_PI * (-0.5 + (double) (i - 1) / p_lats); double z0 = Math::sin(lat0); double zr0 = Math::cos(lat0); - + double lat1 = Math_PI * (-0.5 + (double) i / p_lats); double z1 = Math::sin(lat1); double zr1 = Math::cos(lat1); - + for(int j = p_lons; j >= 1; j--) { - + double lng0 = 2 * Math_PI * (double) (j - 1) / p_lons; double x0 = Math::cos(lng0); double y0 = Math::sin(lng0); - + double lng1 = 2 * Math_PI * (double) (j) / p_lons; - double x1 = Math::cos(lng1); + double x1 = Math::cos(lng1); double y1 = Math::sin(lng1); - - + + Vector3 v[4]={ Vector3(x1 * zr0, z0, y1 *zr0), Vector3(x1 * zr1, z1, y1 *zr1), Vector3(x0 * zr1, z1, y0 *zr1), Vector3(x0 * zr0, z0, y0 *zr0) }; - + #define ADD_POINT(m_idx)\ normals.push_back(v[m_idx]); \ vertices.push_back(v[m_idx]*p_radius);\ - + ADD_POINT(0); ADD_POINT(1); ADD_POINT(2); - + ADD_POINT(2); ADD_POINT(3); ADD_POINT(0); @@ -313,7 +313,7 @@ RID VisualServer::material_2d_get(bool p_shaded, bool p_transparent, bool p_cut_ material_2d[version]=fixed_material_create(); fixed_material_set_flag(material_2d[version],FIXED_MATERIAL_FLAG_USE_ALPHA,p_transparent); - fixed_material_set_flag(material_2d[version],FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY,true); + fixed_material_set_flag(material_2d[version],FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY,true); fixed_material_set_flag(material_2d[version],FIXED_MATERIAL_FLAG_DISCARD_ALPHA,p_cut_alpha); material_set_flag(material_2d[version],MATERIAL_FLAG_UNSHADED,!p_shaded); material_set_flag(material_2d[version],MATERIAL_FLAG_DOUBLE_SIDED,true); @@ -736,23 +736,23 @@ void VisualServer::mesh_add_surface_from_mesh_data( RID p_mesh, const Geometry:: #if 1 DVector<Vector3> vertices; DVector<Vector3> normals; - + for (int i=0;i<p_mesh_data.faces.size();i++) { - + const Geometry::MeshData::Face& f = p_mesh_data.faces[i]; - + for (int j=2;j<f.indices.size();j++) { - + #define _ADD_VERTEX(m_idx)\ vertices.push_back( p_mesh_data.vertices[ f.indices[m_idx] ] );\ normals.push_back( f.plane.normal ); - + _ADD_VERTEX( 0 ); _ADD_VERTEX( j-1 ); _ADD_VERTEX( j ); - } + } } - + int s = mesh_get_surface_count(p_mesh); Array d; d.resize(VS::ARRAY_MAX); @@ -783,7 +783,7 @@ void VisualServer::mesh_add_surface_from_mesh_data( RID p_mesh, const Geometry:: #endif - + } void VisualServer::mesh_add_surface_from_planes( RID p_mesh, const DVector<Plane>& p_planes) { diff --git a/servers/visual_server.h b/servers/visual_server.h index 4841720f41..3a5b3d8d37 100644 --- a/servers/visual_server.h +++ b/servers/visual_server.h @@ -53,18 +53,18 @@ class VisualServer : public Object { void _viewport_set_rect(RID p_viewport,const Rect2& p_rect); Rect2 _viewport_get_rect(RID p_viewport) const; void _canvas_item_add_style_box(RID p_item, const Rect2& p_rect, RID p_texture,const Vector<float>& p_margins, const Color& p_modulate=Color(1,1,1)); -protected: +protected: RID _make_test_cube(); void _free_internal_rids(); RID test_texture; RID white_texture; RID test_material; RID material_2d[16]; - + static VisualServer* (*create_func)(); - static void _bind_methods(); + static void _bind_methods(); public: - + static VisualServer *get_singleton(); static VisualServer *create(); @@ -80,9 +80,9 @@ public: virtual MipMapPolicy get_mipmap_policy() const; - + enum { - + NO_INDEX_ARRAY=-1, CUSTOM_ARRAY_SIZE=8, ARRAY_WEIGHTS_SIZE=4, @@ -95,7 +95,7 @@ public: MAX_CURSORS = 8, }; - + /* TEXTURE API */ enum TextureFlags { @@ -108,21 +108,21 @@ public: TEXTURE_FLAG_CUBEMAP=2048, TEXTURE_FLAG_VIDEO_SURFACE=4096, TEXTURE_FLAGS_DEFAULT=TEXTURE_FLAG_REPEAT|TEXTURE_FLAG_MIPMAPS|TEXTURE_FLAG_FILTER - }; - + }; + enum CubeMapSide { - + CUBEMAP_LEFT, CUBEMAP_RIGHT, CUBEMAP_BOTTOM, CUBEMAP_TOP, - CUBEMAP_FRONT, + CUBEMAP_FRONT, CUBEMAP_BACK }; virtual RID texture_create()=0; - RID texture_create_from_image(const Image& p_image,uint32_t p_flags=TEXTURE_FLAGS_DEFAULT); // helper + RID texture_create_from_image(const Image& p_image,uint32_t p_flags=TEXTURE_FLAGS_DEFAULT); // helper virtual void texture_allocate(RID p_texture,int p_width, int p_height,Image::Format p_format,uint32_t p_flags=TEXTURE_FLAGS_DEFAULT)=0; virtual void texture_set_data(RID p_texture,const Image& p_image,CubeMapSide p_cube_side=CUBEMAP_LEFT)=0; virtual Image texture_get_data(RID p_texture,CubeMapSide p_cube_side=CUBEMAP_LEFT) const=0; @@ -237,7 +237,7 @@ public: FIXED_MATERIAL_PARAM_SPECULAR_EXP, FIXED_MATERIAL_PARAM_GLOW, FIXED_MATERIAL_PARAM_NORMAL, - FIXED_MATERIAL_PARAM_SHADE_PARAM, + FIXED_MATERIAL_PARAM_SHADE_PARAM, FIXED_MATERIAL_PARAM_MAX }; @@ -299,15 +299,15 @@ public: ARRAY_VERTEX=0, ARRAY_NORMAL=1, ARRAY_TANGENT=2, - ARRAY_COLOR=3, - ARRAY_TEX_UV=4, + ARRAY_COLOR=3, + ARRAY_TEX_UV=4, ARRAY_TEX_UV2=5, ARRAY_BONES=6, - ARRAY_WEIGHTS=7, + ARRAY_WEIGHTS=7, ARRAY_INDEX=8, ARRAY_MAX=9 - }; - + }; + enum ArrayFormat { /* ARRAY FORMAT FLAGS */ ARRAY_FORMAT_VERTEX=1<<ARRAY_VERTEX, // mandatory @@ -319,8 +319,8 @@ public: ARRAY_FORMAT_BONES=1<<ARRAY_BONES, ARRAY_FORMAT_WEIGHTS=1<<ARRAY_WEIGHTS, ARRAY_FORMAT_INDEX=1<<ARRAY_INDEX, - }; - + }; + enum PrimitiveType { PRIMITIVE_POINTS=0, PRIMITIVE_LINES=1, @@ -330,10 +330,10 @@ public: PRIMITIVE_TRIANGLE_STRIP=5, PRIMITIVE_TRIANGLE_FAN=6, PRIMITIVE_MAX=7, - }; + }; virtual RID mesh_create()=0; - + virtual void mesh_add_surface(RID p_mesh,PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes=Array(),bool p_alpha_sort=false)=0; virtual Array mesh_get_surface_arrays(RID p_mesh,int p_surface) const=0; virtual Array mesh_get_surface_morph_arrays(RID p_mesh,int p_surface) const=0; @@ -358,7 +358,7 @@ public: virtual int mesh_surface_get_array_index_len(RID p_mesh, int p_surface) const=0; virtual uint32_t mesh_surface_get_format(RID p_mesh, int p_surface) const=0; virtual PrimitiveType mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const=0; - + virtual void mesh_remove_surface(RID p_mesh,int p_index)=0; virtual int mesh_get_surface_count(RID p_mesh) const=0; @@ -405,9 +405,9 @@ public: /* PARTICLES API */ - + virtual RID particles_create()=0; - + enum ParticleVariable { PARTICLE_LIFETIME, PARTICLE_SPREAD, @@ -425,16 +425,16 @@ public: PARTICLE_HEIGHT_SPEED_SCALE, PARTICLE_VAR_MAX }; - + virtual void particles_set_amount(RID p_particles, int p_amount)=0; virtual int particles_get_amount(RID p_particles) const=0; - + virtual void particles_set_emitting(RID p_particles, bool p_emitting)=0; virtual bool particles_is_emitting(RID p_particles) const=0; - + virtual void particles_set_visibility_aabb(RID p_particles, const AABB& p_visibility)=0; virtual AABB particles_get_visibility_aabb(RID p_particles) const=0; - + virtual void particles_set_emission_half_extents(RID p_particles, const Vector3& p_half_extents)=0; virtual Vector3 particles_get_emission_half_extents(RID p_particles) const=0; @@ -443,13 +443,13 @@ public: virtual void particles_set_emission_points(RID p_particles, const DVector<Vector3>& p_points)=0; virtual DVector<Vector3> particles_get_emission_points(RID p_particles) const=0; - + virtual void particles_set_gravity_normal(RID p_particles, const Vector3& p_normal)=0; virtual Vector3 particles_get_gravity_normal(RID p_particles) const=0; - + virtual void particles_set_variable(RID p_particles, ParticleVariable p_variable,float p_value)=0; virtual float particles_get_variable(RID p_particles, ParticleVariable p_variable) const=0; - + virtual void particles_set_randomness(RID p_particles, ParticleVariable p_variable,float p_randomness)=0; virtual float particles_get_randomness(RID p_particles, ParticleVariable p_variable) const=0; @@ -458,7 +458,7 @@ public: virtual void particles_set_color_phase_pos(RID p_particles, int p_phase, float p_pos)=0; virtual float particles_get_color_phase_pos(RID p_particles, int p_phase) const=0; - + virtual void particles_set_color_phase_color(RID p_particles, int p_phase, const Color& p_color)=0; virtual Color particles_get_color_phase_color(RID p_particles, int p_phase) const=0; @@ -473,7 +473,7 @@ public: virtual void particles_set_material(RID p_particles, RID p_material,bool p_owned=false)=0; virtual RID particles_get_material(RID p_particles) const=0; - + virtual void particles_set_height_from_velocity(RID p_particles, bool p_enable)=0; virtual bool particles_has_height_from_velocity(RID p_particles) const=0; @@ -481,20 +481,20 @@ public: virtual bool particles_is_using_local_coordinates(RID p_particles) const=0; /* Light API */ - + enum LightType { LIGHT_DIRECTIONAL, LIGHT_OMNI, LIGHT_SPOT }; - enum LightColor { + enum LightColor { LIGHT_COLOR_DIFFUSE, LIGHT_COLOR_SPECULAR }; - + enum LightParam { - + LIGHT_PARAM_SPOT_ATTENUATION, LIGHT_PARAM_SPOT_ANGLE, LIGHT_PARAM_RADIUS, @@ -512,20 +512,20 @@ public: virtual LightType light_get_type(RID p_light) const=0; virtual void light_set_color(RID p_light,LightColor p_type, const Color& p_color)=0; - virtual Color light_get_color(RID p_light,LightColor p_type) const=0; + virtual Color light_get_color(RID p_light,LightColor p_type) const=0; virtual void light_set_shadow(RID p_light,bool p_enabled)=0; - virtual bool light_has_shadow(RID p_light) const=0; - + virtual bool light_has_shadow(RID p_light) const=0; + virtual void light_set_volumetric(RID p_light,bool p_enabled)=0; - virtual bool light_is_volumetric(RID p_light) const=0; - + virtual bool light_is_volumetric(RID p_light) const=0; + virtual void light_set_projector(RID p_light,RID p_texture)=0; virtual RID light_get_projector(RID p_light) const=0; - + virtual void light_set_param(RID p_light, LightParam p_var, float p_value)=0; virtual float light_get_param(RID p_light, LightParam p_var) const=0; - + enum LightOp { LIGHT_OPERATOR_ADD, @@ -567,26 +567,26 @@ public: virtual float light_directional_get_shadow_param(RID p_light,LightDirectionalShadowParam p_param) const=0; //@TODO fallof model and all that stuff - + /* SKELETON API */ - + virtual RID skeleton_create()=0; virtual void skeleton_resize(RID p_skeleton,int p_bones)=0; virtual int skeleton_get_bone_count(RID p_skeleton) const=0; virtual void skeleton_bone_set_transform(RID p_skeleton,int p_bone, const Transform& p_transform)=0; virtual Transform skeleton_bone_get_transform(RID p_skeleton,int p_bone)=0; - + /* ROOM API */ virtual RID room_create()=0; virtual void room_set_bounds(RID p_room, const BSP_Tree& p_bounds)=0; virtual BSP_Tree room_get_bounds(RID p_room) const=0; - + /* PORTAL API */ // portals are only (x/y) points, forming a convex shape, which its clockwise // order points outside. (z is 0); - + virtual RID portal_create()=0; virtual void portal_set_shape(RID p_portal, const Vector<Point2>& p_shape)=0; virtual Vector<Point2> portal_get_shape(RID p_portal) const=0; @@ -645,11 +645,11 @@ public: virtual int baked_light_sampler_get_resolution(RID p_baked_light_sampler) const=0; /* CAMERA API */ - + virtual RID camera_create()=0; virtual void camera_set_perspective(RID p_camera,float p_fovy_degrees, float p_z_near, float p_z_far)=0; virtual void camera_set_orthogonal(RID p_camera,float p_size, float p_z_near, float p_z_far)=0; - virtual void camera_set_transform(RID p_camera,const Transform& p_transform)=0; + virtual void camera_set_transform(RID p_camera,const Transform& p_transform)=0; virtual void camera_set_visible_layers(RID p_camera,uint32_t p_layers)=0; virtual uint32_t camera_get_visible_layers(RID p_camera) const=0; @@ -711,14 +711,14 @@ public: struct ViewportRect { - + int x,y,width,height; ViewportRect() { x=y=width=height=0; } }; - + virtual void viewport_set_rect(RID p_viewport,const ViewportRect& p_rect)=0; virtual ViewportRect viewport_get_rect(RID p_viewport) const=0; - + virtual void viewport_set_hide_scenario(RID p_viewport,bool p_hide)=0; virtual void viewport_set_hide_canvas(RID p_viewport,bool p_hide)=0; virtual void viewport_set_disable_environment(RID p_viewport,bool p_disable)=0; @@ -845,7 +845,7 @@ public: - virtual RID scenario_create()=0; + virtual RID scenario_create()=0; enum ScenarioDebugMode { SCENARIO_DEBUG_DISABLED, @@ -863,9 +863,9 @@ public: /* INSTANCING API */ - + enum InstanceType { - + INSTANCE_NONE, INSTANCE_MESH, INSTANCE_MULTIMESH, @@ -879,7 +879,7 @@ public: INSTANCE_GEOMETRY_MASK=(1<<INSTANCE_MESH)|(1<<INSTANCE_MULTIMESH)|(1<<INSTANCE_IMMEDIATE)|(1<<INSTANCE_PARTICLES) }; - + virtual RID instance_create2(RID p_base, RID p_scenario); @@ -900,17 +900,17 @@ public: virtual void instance_set_transform(RID p_instance, const Transform& p_transform)=0; virtual Transform instance_get_transform(RID p_instance) const=0; - + virtual void instance_attach_object_instance_ID(RID p_instance,uint32_t p_ID)=0; virtual uint32_t instance_get_object_instance_ID(RID p_instance) const=0; virtual void instance_set_morph_target_weight(RID p_instance,int p_shape, float p_weight)=0; virtual float instance_get_morph_target_weight(RID p_instance,int p_shape) const=0; - + virtual void instance_attach_skeleton(RID p_instance,RID p_skeleton)=0; virtual RID instance_get_skeleton(RID p_instance) const=0; - + virtual void instance_set_exterior( RID p_instance, bool p_enabled )=0; virtual bool instance_is_exterior( RID p_instance) const=0; @@ -937,9 +937,19 @@ public: INSTANCE_FLAG_MAX }; + enum ShadowCastingSetting { + SHADOW_CASTING_SETTING_OFF, + SHADOW_CASTING_SETTING_ON, + SHADOW_CASTING_SETTING_DOUBLE_SIDED, + SHADOW_CASTING_SETTING_SHADOWS_ONLY, + }; + virtual void instance_geometry_set_flag(RID p_instance,InstanceFlags p_flags,bool p_enabled)=0; virtual bool instance_geometry_get_flag(RID p_instance,InstanceFlags p_flags) const=0; + virtual void instance_geometry_set_cast_shadows_setting(RID p_instance, ShadowCastingSetting p_shadow_casting_setting) = 0; + virtual ShadowCastingSetting instance_geometry_get_cast_shadows_setting(RID p_instance) const = 0; + virtual void instance_geometry_set_material_override(RID p_instance, RID p_material)=0; virtual RID instance_geometry_get_material_override(RID p_instance) const=0; @@ -1142,10 +1152,10 @@ public: RID material_2d_get(bool p_shaded, bool p_transparent, bool p_cut_alpha,bool p_opaque_prepass); - + /* TESTING */ - + virtual RID get_test_cube()=0; virtual RID get_test_texture(); @@ -1167,7 +1177,7 @@ public: virtual bool has_feature(Features p_feature) const=0; - VisualServer(); + VisualServer(); virtual ~VisualServer(); }; |