diff --git a/core/image.cpp b/core/image.cpp index 0b63d9c5244..fe5c067b05d 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -404,7 +404,7 @@ void Image::convert( Format p_new_format ){ case FORMAT_RGBA8|(FORMAT_LA8<<8): _convert<3,true,1,true,false,true>( width, height,rptr, wptr ); break; case FORMAT_RGBA8|(FORMAT_R8<<8): _convert<3,true,1,false,false,false>( width, height,rptr, wptr ); break; case FORMAT_RGBA8|(FORMAT_RG8<<8): _convert<3,true,2,false,false,false>( width, height,rptr, wptr ); break; - case FORMAT_RGBA8|(FORMAT_RGB8<<8): _convert<3,true,3,true,false,false>( width, height,rptr, wptr ); break; + case FORMAT_RGBA8|(FORMAT_RGB8<<8): _convert<3,true,3,false,false,false>( width, height,rptr, wptr ); break; } diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index 7fdd08a8347..1b080a1216d 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -3687,9 +3687,47 @@ void RasterizerSceneGLES3::render_scene(const Transform& p_cam_transform,const C state.ubo_data.subsurface_scatter_width=subsurface_scatter_size; + state.ubo_data.shadow_z_offset=0; + state.ubo_data.shadow_slope_scale=0; + state.ubo_data.shadow_dual_paraboloid_render_side=0; + state.ubo_data.shadow_dual_paraboloid_render_zfar=0; _setup_environment(env,p_cam_projection,p_cam_transform); + bool fb_cleared=false; + + glDepthFunc(GL_LEQUAL); + + + if (storage->frame.current_rt && true) { + //pre z pass + glDisable(GL_BLEND); + glDepthMask(GL_TRUE); + glEnable(GL_DEPTH_TEST); + glDisable(GL_SCISSOR_TEST); + glBindFramebuffer(GL_FRAMEBUFFER,storage->frame.current_rt->fbo); + glViewport(0,0,storage->frame.current_rt->width,storage->frame.current_rt->height); + + glColorMask(0,0,0,0); + + glClearDepth(1.0); + glClear(GL_DEPTH_BUFFER_BIT); + + + render_list.clear(); + _fill_render_list(p_cull_result,p_cull_count,true); + render_list.sort_by_depth(false); + state.scene_shader.set_conditional(SceneShaderGLES3::RENDER_DEPTH,true); + _render_list(render_list.elements,render_list.element_count,p_cam_transform,p_cam_projection,0,false,false,true,false,false); + state.scene_shader.set_conditional(SceneShaderGLES3::RENDER_DEPTH,false); + + glColorMask(1,1,1,1); + + fb_cleared=true; + render_pass++; + } + + _setup_lights(p_light_cull_result,p_light_cull_count,p_cam_transform.affine_inverse(),p_cam_projection,p_shadow_atlas); _setup_reflections(p_reflection_probe_cull_result,p_reflection_probe_cull_count,p_cam_transform.affine_inverse(),p_cam_projection,p_reflection_atlas,env); @@ -3778,9 +3816,10 @@ void RasterizerSceneGLES3::render_scene(const Transform& p_cam_transform,const C } } - - glClearDepth(1.0); - glClear(GL_DEPTH_BUFFER_BIT); + if (!fb_cleared) { + glClearDepth(1.0); + glClear(GL_DEPTH_BUFFER_BIT); + } Color clear_color(0,0,0,0); @@ -4287,7 +4326,7 @@ void RasterizerSceneGLES3::render_shadow(RID p_light,RID p_shadow_atlas,int p_pa zfar=light->param[VS::LIGHT_PARAM_RANGE]; bias=light->param[VS::LIGHT_PARAM_SHADOW_BIAS]; - state.scene_shader.set_conditional(SceneShaderGLES3::RENDER_SHADOW_DUAL_PARABOLOID,true); + state.scene_shader.set_conditional(SceneShaderGLES3::RENDER_DEPTH_DUAL_PARABOLOID,true); } } else if (light->type==VS::LIGHT_SPOT) { @@ -4341,12 +4380,12 @@ void RasterizerSceneGLES3::render_shadow(RID p_light,RID p_shadow_atlas,int p_pa _setup_environment(NULL,light_projection,light_transform); - state.scene_shader.set_conditional(SceneShaderGLES3::RENDER_SHADOW,true); + state.scene_shader.set_conditional(SceneShaderGLES3::RENDER_DEPTH,true); _render_list(render_list.elements,render_list.element_count,light_transform,light_projection,0,!flip_facing,false,true,false,false); - state.scene_shader.set_conditional(SceneShaderGLES3::RENDER_SHADOW,false); - state.scene_shader.set_conditional(SceneShaderGLES3::RENDER_SHADOW_DUAL_PARABOLOID,false); + state.scene_shader.set_conditional(SceneShaderGLES3::RENDER_DEPTH,false); + state.scene_shader.set_conditional(SceneShaderGLES3::RENDER_DEPTH_DUAL_PARABOLOID,false); if (light->type==VS::LIGHT_OMNI && light->omni_shadow_mode==VS::LIGHT_OMNI_SHADOW_CUBE && p_pass==5) { diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index 3fc05135423..2875c1f7885 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -4743,6 +4743,7 @@ RID RasterizerStorageGLES3::gi_probe_create() { gip->dynamic_range=1.0; gip->energy=1.0; gip->interior=false; + gip->compress=false; gip->version=1; gip->cell_size=1.0; @@ -4864,6 +4865,24 @@ bool RasterizerStorageGLES3::gi_probe_is_interior(RID p_probe) const{ } + +void RasterizerStorageGLES3::gi_probe_set_compress(RID p_probe,bool p_enable) { + + GIProbe *gip = gi_probe_owner.getornull(p_probe); + ERR_FAIL_COND(!gip); + + gip->compress=p_enable; + +} + +bool RasterizerStorageGLES3::gi_probe_is_compressed(RID p_probe) const{ + + const GIProbe *gip = gi_probe_owner.getornull(p_probe); + ERR_FAIL_COND_V(!gip,false); + + return gip->compress; + +} float RasterizerStorageGLES3::gi_probe_get_energy(RID p_probe) const{ const GIProbe *gip = gi_probe_owner.getornull(p_probe); diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h index b0f98001597..690a169ca26 100644 --- a/drivers/gles3/rasterizer_storage_gles3.h +++ b/drivers/gles3/rasterizer_storage_gles3.h @@ -899,6 +899,7 @@ public: int dynamic_range; float energy; bool interior; + bool compress; uint32_t version; @@ -932,6 +933,9 @@ public: virtual void gi_probe_set_interior(RID p_probe,bool p_enable); virtual bool gi_probe_is_interior(RID p_probe) const; + virtual void gi_probe_set_compress(RID p_probe,bool p_enable); + virtual bool gi_probe_is_compressed(RID p_probe) const; + virtual uint32_t gi_probe_get_version(RID p_probe); struct GIProbeData : public RID_Data { diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index 90c501ea32e..c18a356a546 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -146,7 +146,7 @@ MATERIAL_UNIFORMS #endif -#ifdef RENDER_SHADOW_DUAL_PARABOLOID +#ifdef RENDER_DEPTH_DUAL_PARABOLOID out highp float dp_clip; @@ -253,10 +253,10 @@ VERTEX_SHADER_CODE binormal_interp = binormal; #endif -#ifdef RENDER_SHADOW +#ifdef RENDER_DEPTH -#ifdef RENDER_SHADOW_DUAL_PARABOLOID +#ifdef RENDER_DEPTH_DUAL_PARABOLOID vertex_interp.z*= shadow_dual_paraboloid_render_side; normal_interp.z*= shadow_dual_paraboloid_render_side; @@ -282,12 +282,12 @@ VERTEX_SHADER_CODE z_ofs += (1.0-abs(normal_interp.z))*shadow_z_slope_scale; vertex_interp.z-=z_ofs; -#endif //RENDER_SHADOW_DUAL_PARABOLOID +#endif //RENDER_DEPTH_DUAL_PARABOLOID -#endif //RENDER_SHADOW +#endif //RENDER_DEPTH -#if !defined(SKIP_TRANSFORM_USED) && !defined(RENDER_SHADOW_DUAL_PARABOLOID) +#if !defined(SKIP_TRANSFORM_USED) && !defined(RENDER_DEPTH_DUAL_PARABOLOID) gl_Position = projection_matrix * vec4(vertex_interp,1.0); #else gl_Position = vertex; @@ -622,7 +622,7 @@ float sample_shadow(highp sampler2DShadow shadow, vec2 shadow_pixel_size, vec2 p } -#ifdef RENDER_SHADOW_DUAL_PARABOLOID +#ifdef RENDER_DEPTH_DUAL_PARABOLOID in highp float dp_clip; @@ -861,20 +861,20 @@ vec3 voxel_cone_trace(sampler3D probe, vec3 cell_size, vec3 pos, vec3 ambient, b float dist = dot(direction,mix(vec3(-1.0),vec3(1.0),greaterThan(direction,vec3(0.0))))*2.0; float alpha=0.0; - vec4 color = vec4(0.0); + vec3 color = vec3(0.0); while(dist < max_distance && alpha < 0.95) { float diameter = max(1.0, 2.0 * tan_half_angle * dist); vec4 scolor = textureLod(probe, (pos + dist * direction) * cell_size, log2(diameter) ); float a = (1.0 - alpha); - color.rgb += a * scolor.rgb; + color += scolor.rgb * a; alpha += a * scolor.a; dist += diameter * 0.5; } //color.rgb = mix(color.rgb,mix(ambient,color.rgb,alpha),blend_ambient); - return color.rgb; + return color; } void gi_probe_compute(sampler3D probe, mat4 probe_xform, vec3 bounds,vec3 cell_size,vec3 pos, vec3 ambient, vec3 environment, bool blend_ambient,float multiplier, mat3 normal_mtx,vec3 ref_vec, float roughness, out vec4 out_spec, out vec4 out_diff) { @@ -1004,7 +1004,7 @@ void gi_probes_compute(vec3 pos, vec3 normal, float roughness, vec3 specular, in void main() { -#ifdef RENDER_SHADOW_DUAL_PARABOLOID +#ifdef RENDER_DEPTH_DUAL_PARABOLOID if (dp_clip>0.0) discard; @@ -1128,7 +1128,7 @@ FRAGMENT_SHADER_CODE vec3 eye_vec = -normalize( vertex_interp ); -#ifndef RENDER_SHADOW +#ifndef RENDER_DEPTH float ndotv = clamp(dot(normal,eye_vec),0.0,1.0); vec2 brdf = texture(brdf_texture, vec2(roughness, ndotv)).xy; @@ -1370,7 +1370,7 @@ LIGHT_SHADER_CODE } #endif -#ifdef RENDER_SHADOW +#ifdef RENDER_DEPTH //nothing happens, so a tree-ssa optimizer will result in no fragment shader :) #else @@ -1424,7 +1424,7 @@ LIGHT_SHADER_CODE -#endif //RENDER_SHADOW +#endif //RENDER_DEPTH } diff --git a/scene/3d/gi_probe.cpp b/scene/3d/gi_probe.cpp index de2d9c1b986..f8d8213b82a 100644 --- a/scene/3d/gi_probe.cpp +++ b/scene/3d/gi_probe.cpp @@ -75,6 +75,19 @@ bool GIProbeData::is_interior() const{ return VS::get_singleton()->gi_probe_is_interior(probe); } + +bool GIProbeData::is_compressed() const{ + + return VS::get_singleton()->gi_probe_is_compressed(probe); +} + + +void GIProbeData::set_compress(bool p_enable) { + + VS::get_singleton()->gi_probe_set_compress(probe,p_enable); + +} + int GIProbeData::get_dynamic_range() const{ @@ -111,6 +124,9 @@ void GIProbeData::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_interior","interior"),&GIProbeData::set_interior); ObjectTypeDB::bind_method(_MD("is_interior"),&GIProbeData::is_interior); + ObjectTypeDB::bind_method(_MD("set_compress","compress"),&GIProbeData::set_compress); + ObjectTypeDB::bind_method(_MD("is_compressed"),&GIProbeData::is_compressed); + ADD_PROPERTY(PropertyInfo(Variant::_AABB,"bounds",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_bounds"),_SCS("get_bounds")); ADD_PROPERTY(PropertyInfo(Variant::REAL,"cell_size",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_cell_size"),_SCS("get_cell_size")); ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM,"to_cell_xform",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_to_cell_xform"),_SCS("get_to_cell_xform")); @@ -119,6 +135,7 @@ void GIProbeData::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT,"dynamic_range",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_dynamic_range"),_SCS("get_dynamic_range")); ADD_PROPERTY(PropertyInfo(Variant::REAL,"energy",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_energy"),_SCS("get_energy")); ADD_PROPERTY(PropertyInfo(Variant::BOOL,"interior",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_interior"),_SCS("is_interior")); + ADD_PROPERTY(PropertyInfo(Variant::BOOL,"compress",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_compress"),_SCS("is_compressed")); } @@ -211,6 +228,19 @@ bool GIProbe::is_interior() const { } +void GIProbe::set_compress(bool p_enable) { + + compress=p_enable; + if (probe_data.is_valid()) { + probe_data->set_compress(p_enable); + } +} + +bool GIProbe::is_compressed() const { + + return compress; +} + #include "math.h" @@ -1145,6 +1175,7 @@ void GIProbe::bake(Node *p_from_node, bool p_create_visual_debug){ probe_data->set_dynamic_range(dynamic_range); probe_data->set_energy(energy); probe_data->set_interior(interior); + probe_data->set_compress(compress); probe_data->set_to_cell_xform(baker.to_cell_space); set_probe_data(probe_data); @@ -1327,6 +1358,9 @@ void GIProbe::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_interior","enable"),&GIProbe::set_interior); ObjectTypeDB::bind_method(_MD("is_interior"),&GIProbe::is_interior); + ObjectTypeDB::bind_method(_MD("set_compress","enable"),&GIProbe::set_compress); + ObjectTypeDB::bind_method(_MD("is_compressed"),&GIProbe::is_compressed); + ObjectTypeDB::bind_method(_MD("bake","from_node","create_visual_debug"),&GIProbe::bake,DEFVAL(Variant()),DEFVAL(false)); ObjectTypeDB::bind_method(_MD("debug_bake"),&GIProbe::_debug_bake); ObjectTypeDB::set_method_flags(get_type_static(),_SCS("debug_bake"),METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR); @@ -1336,6 +1370,7 @@ void GIProbe::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::INT,"dynamic_range",PROPERTY_HINT_RANGE,"1,16,1"),_SCS("set_dynamic_range"),_SCS("get_dynamic_range")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"energy",PROPERTY_HINT_RANGE,"0,16,0.01"),_SCS("set_energy"),_SCS("get_energy")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"interior"),_SCS("set_interior"),_SCS("is_interior")); + ADD_PROPERTY( PropertyInfo(Variant::BOOL,"compress"),_SCS("set_compress"),_SCS("is_compressed")); ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"data",PROPERTY_HINT_RESOURCE_TYPE,"GIProbeData"),_SCS("set_probe_data"),_SCS("get_probe_data")); @@ -1355,6 +1390,7 @@ GIProbe::GIProbe() { color_scan_cell_width=4; bake_texture_size=128; interior=false; + compress=false; gi_probe = VS::get_singleton()->gi_probe_create(); diff --git a/scene/3d/gi_probe.h b/scene/3d/gi_probe.h index ca882856cf2..59747761b8e 100644 --- a/scene/3d/gi_probe.h +++ b/scene/3d/gi_probe.h @@ -38,6 +38,9 @@ public: void set_interior(bool p_enable); bool is_interior() const; + void set_compress(bool p_enable); + bool is_compressed() const; + virtual RID get_rid() const; GIProbeData(); @@ -130,6 +133,7 @@ private: int dynamic_range; float energy; bool interior; + bool compress; int color_scan_cell_width; int bake_texture_size; @@ -169,6 +173,8 @@ public: void set_interior(bool p_enable); bool is_interior() const; + void set_compress(bool p_enable); + bool is_compressed() const; void bake(Node *p_from_node=NULL,bool p_create_visual_debug=false); diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h index eda67f2ed4b..7452985522d 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer.h @@ -430,6 +430,9 @@ public: virtual void gi_probe_set_interior(RID p_probe,bool p_enable)=0; virtual bool gi_probe_is_interior(RID p_probe) const=0; + virtual void gi_probe_set_compress(RID p_probe,bool p_enable)=0; + virtual bool gi_probe_is_compressed(RID p_probe) const=0; + virtual uint32_t gi_probe_get_version(RID p_probe)=0; enum GIProbeCompression { @@ -442,6 +445,7 @@ public: virtual RID gi_probe_dynamic_data_create(int p_width,int p_height,int p_depth,GIProbeCompression p_compression)=0; virtual void gi_probe_dynamic_data_update(RID p_gi_probe_data,int p_depth_slice,int p_slice_count,int p_mipmap,const void* p_data)=0; + /* PARTICLES */ virtual RID particles_create()=0; diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index 5088dedb536..e67c140b2d5 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -827,6 +827,9 @@ public: BIND2(gi_probe_set_interior,RID,bool) BIND1RC(bool,gi_probe_is_interior,RID) + BIND2(gi_probe_set_compress,RID,bool) + BIND1RC(bool,gi_probe_is_compressed,RID) + BIND2(gi_probe_set_dynamic_data,RID,const DVector& ) BIND1RC( DVector,gi_probe_get_dynamic_data,RID) diff --git a/servers/visual/visual_server_scene.cpp b/servers/visual/visual_server_scene.cpp index deb391c77ef..6b170d3797c 100644 --- a/servers/visual/visual_server_scene.cpp +++ b/servers/visual/visual_server_scene.cpp @@ -2407,7 +2407,9 @@ void VisualServerScene::_setup_gi_probe(Instance *p_instance) { _gi_probe_fill_local_data(0,0,0,0,0,cells,header,ldw.ptr(),probe->dynamic.level_cell_lists.ptr()); - probe->dynamic.compression = VSG::storage->gi_probe_get_dynamic_data_get_preferred_compression(); + bool compress = VSG::storage->gi_probe_is_compressed(p_instance->base); + + probe->dynamic.compression = compress ? VSG::storage->gi_probe_get_dynamic_data_get_preferred_compression() : RasterizerStorage::GI_PROBE_UNCOMPRESSED; probe->dynamic.probe_data=VSG::storage->gi_probe_dynamic_data_create(header->width,header->height,header->depth,probe->dynamic.compression); @@ -3112,10 +3114,10 @@ void VisualServerScene::_bake_gi_probe(Instance *p_gi_probe) { color_1 |= CLAMP(int(to.y*63),0,63)<<5; color_1 |= CLAMP(int(to.z*31),0,31); - //if (color_1 > color_0) { + if (color_1 > color_0) { SWAP(color_1,color_0); SWAP(from,to); - //} + } if (distance>0) { diff --git a/servers/visual_server.h b/servers/visual_server.h index 33a40834896..f4848ff34e5 100644 --- a/servers/visual_server.h +++ b/servers/visual_server.h @@ -472,6 +472,9 @@ public: virtual void gi_probe_set_interior(RID p_probe,bool p_enable)=0; virtual bool gi_probe_is_interior(RID p_probe) const=0; + virtual void gi_probe_set_compress(RID p_probe,bool p_enable)=0; + virtual bool gi_probe_is_compressed(RID p_probe) const=0; + /* PARTICLES API */ virtual RID particles_create()=0;