diff options
Diffstat (limited to 'drivers/gles3/rasterizer_scene_gles3.h')
-rw-r--r-- | drivers/gles3/rasterizer_scene_gles3.h | 138 |
1 files changed, 121 insertions, 17 deletions
diff --git a/drivers/gles3/rasterizer_scene_gles3.h b/drivers/gles3/rasterizer_scene_gles3.h index 53088deb0d..4b1b77f13c 100644 --- a/drivers/gles3/rasterizer_scene_gles3.h +++ b/drivers/gles3/rasterizer_scene_gles3.h @@ -32,12 +32,28 @@ public: float camera_inverse_matrix[16]; float camera_matrix[16]; float time[4]; - float ambient_light[4]; + float ambient_light_color[4]; + float bg_color[4]; + float ambient_energy; + float bg_energy; } ubo_data; GLuint scene_ubo; + struct EnvironmentRadianceUBO { + + float transform[16]; + float box_min[4]; //unused for now + float box_max[4]; + float ambient_contribution; + + } env_radiance_data; + + GLuint env_radiance_ubo; + + GLuint brdf_texture; + GLuint skybox_verts; GLuint skybox_array; @@ -54,16 +70,15 @@ public: RID skybox_color; RID skybox_radiance; - RID skybox_irradiance; float skybox_scale; Color bg_color; - float energy; + float bg_energy; float skybox_ambient; Color ambient_color; - float ambient_anergy; - float ambient_skybox_energy; + float ambient_energy; + float ambient_skybox_contribution; int canvas_max_layer; @@ -71,10 +86,10 @@ public: Environment() { bg_mode=VS::ENV_BG_CLEAR_COLOR; skybox_scale=1.0; - energy=1.0; + bg_energy=1.0; skybox_ambient=0; - ambient_anergy=1.0; - ambient_skybox_energy=0.0; + ambient_energy=1.0; + ambient_skybox_contribution=0.0; canvas_max_layer=0; } }; @@ -84,12 +99,12 @@ public: virtual RID environment_create(); virtual void environment_set_background(RID p_env,VS::EnvironmentBG p_bg); - virtual void environment_set_skybox(RID p_env,RID p_skybox,int p_radiance_size,int p_irradiance_size); + virtual void environment_set_skybox(RID p_env,RID p_skybox,int p_radiance_size); virtual void environment_set_skybox_scale(RID p_env,float p_scale); virtual void environment_set_bg_color(RID p_env,const Color& p_color); virtual void environment_set_bg_energy(RID p_env,float p_energy); virtual void environment_set_canvas_max_layer(RID p_env,int p_max_layer); - virtual void environment_set_ambient_light(RID p_env,const Color& p_color,float p_energy=1.0,float p_skybox_energy=0.0); + virtual void environment_set_ambient_light(RID p_env,const Color& p_color,float p_energy=1.0,float p_skybox_contribution=0.0); virtual void environment_set_glow(RID p_env,bool p_enable,int p_radius,float p_intensity,float p_strength,float p_bloom_treshold,VS::EnvironmentGlowBlendMode p_blend_mode); virtual void environment_set_fog(RID p_env,bool p_enable,float p_begin,float p_end,RID p_gradient_texture); @@ -100,19 +115,81 @@ public: virtual void environment_set_saturation(RID p_env,bool p_enable,float p_saturation); virtual void environment_set_color_correction(RID p_env,bool p_enable,RID p_ramp); + + /* LIGHT INSTANCE */ + + struct LightInstance : public RID_Data { + + struct SplitInfo { + + CameraMatrix camera; + Transform transform; + float near; + float far; + }; + + struct LightDataUBO { + + float light_pos_inv_radius[4]; + float light_direction_attenuation[4]; + float light_color_energy[4]; + float light_params[4]; //cone attenuation, specular, shadow darkening, + float shadow_split_offsets[4]; + float shadow_matrix1[16]; + float shadow_matrix2[16]; + float shadow_matrix3[16]; + float shadow_matrix4[16]; + + } light_ubo_data; + + + SplitInfo split_info[4]; + + RID light; + RasterizerStorageGLES3::Light *light_ptr; + + CameraMatrix shadow_matrix[4]; + + Transform transform; + + Vector3 light_vector; + Vector3 spot_vector; + float linear_att; + + GLuint light_ubo; + + uint64_t shadow_pass; + uint64_t last_pass; + uint16_t light_index; + + Vector2 dp; + + CameraMatrix shadow_projection[4]; + + + LightInstance() { } + + }; + + mutable RID_Owner<LightInstance> light_instance_owner; + + virtual RID light_instance_create(RID p_light); + virtual void light_instance_set_transform(RID p_light_instance,const Transform& p_transform); + /* RENDER LIST */ struct RenderList { enum { DEFAULT_MAX_ELEMENTS=65536, - MAX_LIGHTS=4, SORT_FLAG_SKELETON=1, SORT_FLAG_INSTANCING=2, - + MAX_DIRECTIONAL_LIGHTS=16, + MAX_LIGHTS=4096, SORT_KEY_DEPTH_LAYER_SHIFT=58, SORT_KEY_LIGHT_TYPE_SHIFT=54, //type is most important SORT_KEY_LIGHT_INDEX_SHIFT=38, //type is most important + SORT_KEY_LIGHT_INDEX_UNSHADED=uint64_t(0xF) << SORT_KEY_LIGHT_TYPE_SHIFT, //type is most important SORT_KEY_MATERIAL_INDEX_SHIFT=22, SORT_KEY_GEOMETRY_INDEX_SHIFT=6, SORT_KEY_GEOMETRY_TYPE_SHIFT=2, @@ -161,7 +238,24 @@ public: SortArray<Element*,SortByKey> sorter; if (p_alpha) { - sorter.sort(&elements[max_elements-alpha_element_count-1],alpha_element_count); + sorter.sort(&elements[max_elements-alpha_element_count],alpha_element_count); + } else { + sorter.sort(elements,element_count); + } + } + + struct SortByDepth { + + _FORCE_INLINE_ bool operator()(const Element* A, const Element* B ) const { + return A->instance->depth > B->instance->depth; + } + }; + + void sort_by_depth(bool p_alpha) { + + SortArray<Element*,SortByDepth> sorter; + if (p_alpha) { + sorter.sort(&elements[max_elements-alpha_element_count],alpha_element_count); } else { sorter.sort(elements,element_count); } @@ -197,6 +291,7 @@ public: } + RenderList() { max_elements=DEFAULT_MAX_ELEMENTS; @@ -210,26 +305,35 @@ public: + LightInstance *directional_light_instances[RenderList::MAX_DIRECTIONAL_LIGHTS]; + int directional_light_instance_count; + + LightInstance *light_instances[RenderList::MAX_LIGHTS]; + int light_instance_count; + RenderList render_list; _FORCE_INLINE_ bool _setup_material(RasterizerStorageGLES3::Material* p_material,bool p_alpha_pass); _FORCE_INLINE_ void _setup_geometry(RenderList::Element *e); _FORCE_INLINE_ void _render_geometry(RenderList::Element *e); + _FORCE_INLINE_ void _setup_light(LightInstance *p_light); + void _render_list(RenderList::Element **p_elements, int p_element_count, const Transform& p_view_transform, const CameraMatrix& p_projection, RasterizerStorageGLES3::Texture *p_base_env, bool p_reverse_cull, bool p_alpha_pass); - void _render_list(RenderList::Element **p_elements, int p_element_count, const Transform& p_view_transform, const CameraMatrix& p_projection, bool p_reverse_cull, bool p_alpha_pass); - - virtual RID light_instance_create(RID p_light); - virtual void light_instance_set_transform(RID p_light_instance,const Transform& p_transform); _FORCE_INLINE_ void _add_geometry( RasterizerStorageGLES3::Geometry* p_geometry, InstanceBase *p_instance, RasterizerStorageGLES3::GeometryOwner *p_owner,int p_material); void _draw_skybox(RID p_skybox, CameraMatrix& p_projection, const Transform& p_transform, bool p_vflip, float p_scale); + void _setup_environment(Environment *env,CameraMatrix& p_cam_projection, const Transform& p_cam_transform); + void _setup_lights(RID *p_light_cull_result, int p_light_cull_count, const Transform &p_camera_inverse_transform); + virtual void render_scene(const Transform& p_cam_transform,CameraMatrix& p_cam_projection,bool p_cam_ortogonal,InstanceBase** p_cull_result,int p_cull_count,RID* p_light_cull_result,int p_light_cull_count,RID* p_directional_lights,int p_directional_light_count,RID p_environment); virtual bool free(RID p_rid); + void _generate_brdf(); + void initialize(); void finalize(); RasterizerSceneGLES3(); |