diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-12-21 14:20:35 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2016-12-21 14:22:17 -0300 |
commit | 37f558cd7b2308f6442f74c5265f12425d9887c8 (patch) | |
tree | 88901b350f7674013f7aecf8fddf3f1c3dbd7399 /drivers/gles3 | |
parent | 72b844c34999d8615450798ed1f27ef24a72d8ce (diff) |
Some BRDF fixes
Diffstat (limited to 'drivers/gles3')
-rw-r--r-- | drivers/gles3/rasterizer_gles3.cpp | 19 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_scene_gles3.cpp | 21 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_scene_gles3.h | 1 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_storage_gles3.cpp | 13 | ||||
-rw-r--r-- | drivers/gles3/rasterizer_storage_gles3.h | 6 | ||||
-rw-r--r-- | drivers/gles3/shaders/scene.glsl | 44 |
6 files changed, 87 insertions, 17 deletions
diff --git a/drivers/gles3/rasterizer_gles3.cpp b/drivers/gles3/rasterizer_gles3.cpp index 110436b9d5..cb42790e67 100644 --- a/drivers/gles3/rasterizer_gles3.cpp +++ b/drivers/gles3/rasterizer_gles3.cpp @@ -130,9 +130,9 @@ void RasterizerGLES3::initialize() { ERR_PRINT("Error initializing GLAD"); } - glEnable(_EXT_DEBUG_OUTPUT_SYNCHRONOUS_ARB); +// glEnable(_EXT_DEBUG_OUTPUT_SYNCHRONOUS_ARB); // glDebugMessageCallbackARB(_gl_debug_print, NULL); - glEnable(_EXT_DEBUG_OUTPUT); +// glEnable(_EXT_DEBUG_OUTPUT); #endif @@ -169,6 +169,14 @@ void RasterizerGLES3::begin_frame(){ storage->update_dirty_skeletons(); storage->update_dirty_shaders(); storage->update_dirty_materials(); + + storage->info.render_object_count=0; + storage->info.render_material_switch_count=0; + storage->info.render_surface_switch_count=0; + storage->info.render_shader_rebind_count=0; + storage->info.render_vertices_count=0; + + scene->iteration(); @@ -277,6 +285,13 @@ void RasterizerGLES3::end_frame(){ canvas->draw_generic_textured_rect(Rect2(0,0,15,15),Rect2(0,0,1,1)); #endif OS::get_singleton()->swap_buffers(); + +/* print_line("objects: "+itos(storage->info.render_object_count)); + print_line("material chages: "+itos(storage->info.render_material_switch_count)); + print_line("surface changes: "+itos(storage->info.render_surface_switch_count)); + print_line("shader changes: "+itos(storage->info.render_shader_rebind_count)); + print_line("vertices: "+itos(storage->info.render_vertices_count)); +*/ } void RasterizerGLES3::finalize(){ diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index 65591de56e..675b6f228d 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -1331,10 +1331,14 @@ void RasterizerSceneGLES3::_render_geometry(RenderList::Element *e) { glDrawElements(gl_primitive[s->primitive],s->index_array_len, (s->array_len>=(1<<16))?GL_UNSIGNED_INT:GL_UNSIGNED_SHORT,0); + storage->info.render_vertices_count+=s->index_array_len; + } else { glDrawArrays(gl_primitive[s->primitive],0,s->array_len); + storage->info.render_vertices_count+=s->array_len; + } } break; @@ -1349,10 +1353,14 @@ void RasterizerSceneGLES3::_render_geometry(RenderList::Element *e) { glDrawElementsInstanced(gl_primitive[s->primitive],s->index_array_len, (s->array_len>=(1<<16))?GL_UNSIGNED_INT:GL_UNSIGNED_SHORT,0,amount); + storage->info.render_vertices_count+=s->index_array_len * amount; + } else { glDrawArraysInstanced(gl_primitive[s->primitive],0,s->array_len,amount); + storage->info.render_vertices_count+=s->array_len * amount; + } } break; @@ -1379,6 +1387,8 @@ void RasterizerSceneGLES3::_render_geometry(RenderList::Element *e) { int vertices = c.vertices.size(); uint32_t buf_ofs=0; + storage->info.render_vertices_count+=vertices; + if (c.texture.is_valid() && storage->texture_owner.owns(c.texture)) { const RasterizerStorageGLES3::Texture *t = storage->texture_owner.get(c.texture); @@ -1704,6 +1714,8 @@ void RasterizerSceneGLES3::_render_list(RenderList::Element **p_elements,int p_e bool first=true; + storage->info.render_object_count+=p_element_count; + for (int i=0;i<p_element_count;i++) { RenderList::Element *e = p_elements[i]; @@ -1864,8 +1876,13 @@ void RasterizerSceneGLES3::_render_list(RenderList::Element **p_elements,int p_e if (material!=prev_material || rebind) { + storage->info.render_material_switch_count++; + rebind = _setup_material(material,p_alpha_pass); -// _rinfo.mat_change_count++; + + if (rebind) { + storage->info.render_shader_rebind_count++; + } } if (!(e->sort_key&RenderList::SORT_KEY_UNSHADED_FLAG) && !p_directional_add && !p_shadow) { @@ -1877,6 +1894,8 @@ void RasterizerSceneGLES3::_render_list(RenderList::Element **p_elements,int p_e if (prev_base_type != e->instance->base_type || prev_geometry!=e->geometry) { _setup_geometry(e); + storage->info.render_surface_switch_count++; + } _set_cull(e->sort_key&RenderList::SORT_KEY_MIRROR_FLAG,p_reverse_cull); diff --git a/drivers/gles3/rasterizer_scene_gles3.h b/drivers/gles3/rasterizer_scene_gles3.h index ef1b7b8d38..ce869da131 100644 --- a/drivers/gles3/rasterizer_scene_gles3.h +++ b/drivers/gles3/rasterizer_scene_gles3.h @@ -148,6 +148,7 @@ public: } state; + /* SHADOW ATLAS API */ struct ShadowAtlas : public RID_Data { diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index eca916854a..9edc37fe3b 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -826,15 +826,20 @@ Image RasterizerStorageGLES3::texture_get_data(RID p_texture,VS::CubeMapSide p_c DVector<uint8_t> data; - int data_size = Image::get_image_data_size(texture->width,texture->height,texture->format,texture->mipmaps>1?-1:0); + int data_size = Image::get_image_data_size(texture->alloc_width,texture->alloc_height,texture->format,texture->mipmaps>1?-1:0); - data.resize(data_size); + data.resize(data_size*2); //add some memory at the end, just in case for buggy drivers DVector<uint8_t>::Write wb = data.write(); glActiveTexture(GL_TEXTURE0); glBindTexture(texture->target,texture->tex_id); + glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); + + print_line("GET FORMAT: "+Image::get_format_name(texture->format)+" mipmaps: "+itos(texture->mipmaps)); + + for(int i=0;i<texture->mipmaps;i++) { int ofs=0; @@ -848,7 +853,9 @@ Image RasterizerStorageGLES3::texture_get_data(RID p_texture,VS::CubeMapSide p_c glGetCompressedTexImage(texture->target,i,&wb[ofs]); } else { + glPixelStorei(GL_PACK_ALIGNMENT, 1); + glGetTexImage(texture->target,i,texture->gl_format_cache,texture->gl_type_cache,&wb[ofs]); } } @@ -856,6 +863,8 @@ Image RasterizerStorageGLES3::texture_get_data(RID p_texture,VS::CubeMapSide p_c wb=DVector<uint8_t>::Write(); + data.resize(data_size); + Image img(texture->alloc_width,texture->alloc_height,texture->mipmaps>1?true:false,texture->format,data); return img; diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h index b81c3df78a..5d07d0be87 100644 --- a/drivers/gles3/rasterizer_storage_gles3.h +++ b/drivers/gles3/rasterizer_storage_gles3.h @@ -91,6 +91,12 @@ public: uint64_t texture_mem; + uint32_t render_object_count; + uint32_t render_material_switch_count; + uint32_t render_surface_switch_count; + uint32_t render_shader_rebind_count; + uint32_t render_vertices_count; + } info; diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index bf561a7e46..c9de56be4f 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -569,7 +569,7 @@ void light_compute(vec3 N, vec3 L,vec3 V,vec3 B, vec3 T,vec3 light_color,vec3 di float speci = dotNL * D * F * vis; - specular += speci * light_color * specular_color * specular_blob_intensity; + specular += speci * light_color /* specular_color*/ * specular_blob_intensity; #if defined(LIGHT_USE_CLEARCOAT) float Dr = GTR1(dotNH, mix(.1,.001,clearcoat_gloss)); @@ -780,7 +780,8 @@ void reflection_process(int idx, vec3 vertex, vec3 normal,vec3 binormal, vec3 ta splane.xy = clamp(splane.xy,clamp_rect.xy,clamp_rect.xy+clamp_rect.zw); highp vec4 reflection; - reflection.rgb = textureLod(reflection_atlas,splane.xy,roughness*5.0).rgb * ( brdf.x + brdf.y); + reflection.rgb = textureLod(reflection_atlas,splane.xy,roughness*5.0).rgb * brdf.x + brdf.y; + if (reflections[idx].params.z < 0.5) { reflection.rgb = mix(skybox,reflection.rgb,blend); } @@ -893,6 +894,7 @@ void gi_probe_compute(sampler3D probe, mat4 probe_xform, vec3 bounds,vec3 cell_s blend=1.0; //radiance +#ifdef VCT_QUALITY_HIGH #define MAX_CONE_DIRS 6 vec3 cone_dirs[MAX_CONE_DIRS] = vec3[] ( @@ -905,13 +907,28 @@ void gi_probe_compute(sampler3D probe, mat4 probe_xform, vec3 bounds,vec3 cell_s ); float cone_weights[MAX_CONE_DIRS] = float[](0.25, 0.15, 0.15, 0.15, 0.15, 0.15); + float cone_angle_tan = 0.577; +#else + +#define MAX_CONE_DIRS 4 + + vec3 cone_dirs[MAX_CONE_DIRS] = vec3[] ( + vec3(0.707107, 0, 0.707107), + vec3(0, 0.707107, 0.707107), + vec3(-0.707107, 0, 0.707107), + vec3(0, -0.707107, 0.707107) + ); + + float cone_weights[MAX_CONE_DIRS] = float[](0.25, 0.25, 0.25, 0.25); + float cone_angle_tan = 0.98269; +#endif float max_distance = length(bounds); vec3 light=vec3(0.0); for(int i=0;i<MAX_CONE_DIRS;i++) { vec3 dir = normalize( (probe_xform * vec4(pos + normal_mtx * cone_dirs[i],1.0)).xyz - probe_pos); - light+=cone_weights[i] * voxel_cone_trace(probe,cell_size,probe_pos,dir,0.577,max_distance); + light+=cone_weights[i] * voxel_cone_trace(probe,cell_size,probe_pos,dir,cone_angle_tan,max_distance); } @@ -928,6 +945,7 @@ void gi_probe_compute(sampler3D probe, mat4 probe_xform, vec3 bounds,vec3 cell_s void gi_probes_compute(vec3 pos, vec3 normal, float roughness, vec3 specular, inout vec3 out_specular, inout vec3 out_ambient) { + roughness = roughness * roughness; vec3 ref_vec = normalize(reflect(normalize(pos),normal)); @@ -1073,7 +1091,7 @@ FRAGMENT_SHADER_CODE #endif #ifdef ENABLE_CLIP_ALPHA - if (diffuse.a<0.99) { + if (albedo.a<0.99) { //used for doublepass and shadowmapping discard; } @@ -1082,8 +1100,6 @@ FRAGMENT_SHADER_CODE /////////////////////// LIGHTING ////////////////////////////// //apply energy conservation - vec3 diffuse=mix(albedo,vec3(0.0),specular); - specular = max(vec3(0.04),specular); vec3 specular_light = vec3(0.0,0.0,0.0); vec3 ambient_light; @@ -1093,6 +1109,7 @@ FRAGMENT_SHADER_CODE #ifndef RENDER_SHADOW float ndotv = clamp(dot(normal,eye_vec),0.0,1.0); + vec2 brdf = texture(brdf_texture, vec2(roughness, ndotv)).xy; #endif @@ -1125,7 +1142,7 @@ FRAGMENT_SHADER_CODE norm.xy/=norm.z; norm.xy=norm.xy * vec2(0.5,0.25) + vec2(0.5,0.25+y_ofs); - specular_light = textureLod(radiance_map, norm.xy, lod).xyz * ( brdf.x + brdf.y); + specular_light = textureLod(radiance_map, norm.xy, lod).xyz * brdf.x + brdf.y; } //no longer a cubemap @@ -1219,7 +1236,6 @@ FRAGMENT_SHADER_CODE } else { highp vec4 splane=(shadow_matrix4 * vec4(vertex,1.0)); pssm_coord=splane.xyz/splane.w; - diffuse_light*=vec3(1.0,0.4,1.0); #if defined(LIGHT_USE_PSSM_BLEND) use_blend=false; @@ -1281,7 +1297,7 @@ FRAGMENT_SHADER_CODE #endif //LIGHT_DIRECTIONAL_SHADOW - light_compute(normal,-light_direction_attenuation.xyz,eye_vec,binormal,tangent,light_color_energy.rgb*light_attenuation,diffuse,specular,light_params.z,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light); + light_compute(normal,-light_direction_attenuation.xyz,eye_vec,binormal,tangent,light_color_energy.rgb*light_attenuation,albedo,specular,light_params.z,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light); #endif //#USE_LIGHT_DIRECTIONAL @@ -1310,11 +1326,11 @@ FRAGMENT_SHADER_CODE } for(int i=0;i<omni_light_count;i++) { - light_process_omni(omni_light_indices[i],vertex,eye_vec,normal,binormal,tangent,diffuse,specular,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light); + light_process_omni(omni_light_indices[i],vertex,eye_vec,normal,binormal,tangent,albedo,specular,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light); } for(int i=0;i<spot_light_count;i++) { - light_process_spot(spot_light_indices[i],vertex,eye_vec,normal,binormal,tangent,diffuse,specular,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light); + light_process_spot(spot_light_indices[i],vertex,eye_vec,normal,binormal,tangent,albedo,specular,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light); } @@ -1338,13 +1354,17 @@ LIGHT_SHADER_CODE #else specular_light*=reflection_multiplier; - specular_light*=specular; ambient_light*=albedo; //ambient must be multiplied by albedo at the end #if defined(ENABLE_AO) ambient_light*=ao; #endif + //energy conservation + diffuse_light=mix(diffuse_light,vec3(0.0),specular); + ambient_light=mix(ambient_light,vec3(0.0),specular); + specular_light *= max(vec3(0.04),specular); + #ifdef USE_MULTIPLE_RENDER_TARGETS #if defined(ENABLE_AO) |