diff options
Diffstat (limited to 'drivers/gles2/rasterizer_gles2.cpp')
-rw-r--r-- | drivers/gles2/rasterizer_gles2.cpp | 301 |
1 files changed, 202 insertions, 99 deletions
diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index 307db4b762..dd690435ec 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -49,6 +49,12 @@ #define _GL_R16F_EXT 0x822D #define _GL_R32F_EXT 0x822E + +#define _GL_RED_EXT 0x1903 +#define _GL_RG_EXT 0x8227 +#define _GL_R8_EXT 0x8229 +#define _GL_RG8_EXT 0x822B + #define _DEPTH_COMPONENT24_OES 0x81A6 #ifdef GLEW_ENABLED @@ -1126,20 +1132,22 @@ VS::ShaderMode RasterizerGLES2::shader_get_mode(RID p_shader) const { } +void RasterizerGLES2::shader_set_code(RID p_shader, const String& p_vertex, const String& p_fragment,const String& p_light,int p_vertex_ofs,int p_fragment_ofs,int p_light_ofs) { -void RasterizerGLES2::shader_set_code(RID p_shader, const String& p_vertex, const String& p_fragment,int p_vertex_ofs,int p_fragment_ofs) { Shader *shader=shader_owner.get(p_shader); ERR_FAIL_COND(!shader); #ifdef DEBUG_ENABLED - if (shader->vertex_code==p_vertex && shader->fragment_code==p_fragment) + if (shader->vertex_code==p_vertex && shader->fragment_code==p_fragment && shader->light_code==p_light) return; #endif shader->fragment_code=p_fragment; shader->vertex_code=p_vertex; + shader->light_code=p_light; shader->fragment_line=p_fragment_ofs; shader->vertex_line=p_vertex_ofs; + shader->light_line=p_light_ofs; _shader_make_dirty(shader); } @@ -1160,6 +1168,14 @@ String RasterizerGLES2::shader_get_fragment_code(RID p_shader) const { } +String RasterizerGLES2::shader_get_light_code(RID p_shader) const { + + Shader *shader=shader_owner.get(p_shader); + ERR_FAIL_COND_V(!shader,String()); + return shader->light_code; + +} + void RasterizerGLES2::_shader_make_dirty(Shader* p_shader) { if (p_shader->dirty_list.in_list()) @@ -1328,38 +1344,22 @@ bool RasterizerGLES2::material_get_flag(RID p_material,VS::MaterialFlag p_flag) } -void RasterizerGLES2::material_set_hint(RID p_material, VS::MaterialHint p_hint,bool p_enabled) { +void RasterizerGLES2::material_set_depth_draw_mode(RID p_material, VS::MaterialDepthDrawMode p_mode) { Material *material = material_owner.get(p_material); ERR_FAIL_COND(!material); - ERR_FAIL_INDEX(p_hint,VS::MATERIAL_HINT_MAX); - material->hints[p_hint]=p_enabled; + material->depth_draw_mode=p_mode; } -bool RasterizerGLES2::material_get_hint(RID p_material,VS::MaterialHint p_hint) const { +VS::MaterialDepthDrawMode RasterizerGLES2::material_get_depth_draw_mode(RID p_material) const { Material *material = material_owner.get(p_material); - ERR_FAIL_COND_V(!material,false); - ERR_FAIL_INDEX_V(p_hint,VS::MATERIAL_HINT_MAX,false); - return material->hints[p_hint]; + ERR_FAIL_COND_V(!material,VS::MATERIAL_DEPTH_DRAW_ALWAYS); + return material->depth_draw_mode; } -void RasterizerGLES2::material_set_shade_model(RID p_material, VS::MaterialShadeModel p_model) { - - Material *material = material_owner.get(p_material); - ERR_FAIL_COND(!material); - material->shade_model=p_model; - -}; - -VS::MaterialShadeModel RasterizerGLES2::material_get_shade_model(RID p_material) const { - - Material *material = material_owner.get(p_material); - ERR_FAIL_COND_V(!material,VS::MATERIAL_SHADE_MODEL_LAMBERT); - return material->shade_model; -}; void RasterizerGLES2::material_set_blend_mode(RID p_material,VS::MaterialBlendMode p_mode) { @@ -3449,14 +3449,21 @@ RID RasterizerGLES2::viewport_data_create() { glGenFramebuffers(1, &vd->lum_fbo); glBindFramebuffer(GL_FRAMEBUFFER, vd->lum_fbo); + GLuint format_luminance = use_fp16_fb?_GL_RG_EXT:GL_RGBA; + GLuint format_luminance_type = use_fp16_fb?(full_float_fb_supported?GL_FLOAT:_GL_HALF_FLOAT_OES):GL_UNSIGNED_BYTE; + GLuint format_luminance_components = use_fp16_fb?_GL_RG_EXT:GL_RGBA; + glGenTextures(1, &vd->lum_color); glBindTexture(GL_TEXTURE_2D, vd->lum_color); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, - GL_RGBA, GL_UNSIGNED_BYTE, NULL); + //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, + // GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, format_luminance, 1, 1, 0, + format_luminance_components, format_luminance_type, NULL); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, vd->lum_color, 0); @@ -3928,10 +3935,12 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const { String vertex_code; String vertex_globals; - ShaderCompilerGLES2::Flags flags; + ShaderCompilerGLES2::Flags vertex_flags; + ShaderCompilerGLES2::Flags fragment_flags; + ShaderCompilerGLES2::Flags light_flags; if (p_shader->mode==VS::SHADER_MATERIAL) { - Error err = shader_precompiler.compile(p_shader->vertex_code,ShaderLanguage::SHADER_MATERIAL_VERTEX,vertex_code,vertex_globals,flags,&p_shader->uniforms); + Error err = shader_precompiler.compile(p_shader->vertex_code,ShaderLanguage::SHADER_MATERIAL_VERTEX,vertex_code,vertex_globals,vertex_flags,&p_shader->uniforms); if (err) { return; //invalid } @@ -3944,11 +3953,26 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const { String fragment_code; String fragment_globals; - Error err = shader_precompiler.compile(p_shader->fragment_code,(p_shader->mode==VS::SHADER_MATERIAL?ShaderLanguage::SHADER_MATERIAL_FRAGMENT:ShaderLanguage::SHADER_POST_PROCESS),fragment_code,fragment_globals,flags,&p_shader->uniforms); + Error err = shader_precompiler.compile(p_shader->fragment_code,(p_shader->mode==VS::SHADER_MATERIAL?ShaderLanguage::SHADER_MATERIAL_FRAGMENT:ShaderLanguage::SHADER_POST_PROCESS),fragment_code,fragment_globals,fragment_flags,&p_shader->uniforms); if (err) { return; //invalid } + + String light_code; + String light_globals; + + if (p_shader->mode==VS::SHADER_MATERIAL) { + + Error err = shader_precompiler.compile(p_shader->light_code,(ShaderLanguage::SHADER_MATERIAL_LIGHT),light_code,light_globals,light_flags,&p_shader->uniforms); + if (err) { + return; //invalid + } + } + + fragment_globals+=light_globals; //both fragment anyway + + //print_line("compiled fragment: "+fragment_code); // ("compiled fragment globals: "+fragment_globals); @@ -3969,40 +3993,43 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const { if (p_shader->mode==VS::SHADER_MATERIAL) { //print_line("setting code to id.. "+itos(p_shader->custom_code_id)); Vector<const char*> enablers; - if (flags.use_color_interp) + if (fragment_flags.use_color_interp) enablers.push_back("#define ENABLE_COLOR_INTERP\n"); - if (flags.use_uv_interp) + if (fragment_flags.use_uv_interp) enablers.push_back("#define ENABLE_UV_INTERP\n"); - if (flags.use_uv2_interp) + if (fragment_flags.use_uv2_interp) enablers.push_back("#define ENABLE_UV2_INTERP\n"); - if (flags.use_tangent_interp) + if (fragment_flags.use_tangent_interp) enablers.push_back("#define ENABLE_TANGENT_INTERP\n"); - if (flags.use_var1_interp) + if (fragment_flags.use_var1_interp) enablers.push_back("#define ENABLE_VAR1_INTERP\n"); - if (flags.use_var2_interp) + if (fragment_flags.use_var2_interp) enablers.push_back("#define ENABLE_VAR2_INTERP\n"); - if (flags.uses_texscreen) { + if (fragment_flags.uses_texscreen) { enablers.push_back("#define ENABLE_TEXSCREEN\n"); } - if (flags.uses_screen_uv) { + if (fragment_flags.uses_screen_uv) { enablers.push_back("#define ENABLE_SCREEN_UV\n"); } - if (flags.uses_discard) { + if (fragment_flags.uses_discard) { enablers.push_back("#define ENABLE_DISCARD\n"); } + if (light_flags.uses_light) { + enablers.push_back("#define USE_LIGHT_SHADER_CODE\n"); + } - material_shader.set_custom_shader_code(p_shader->custom_code_id,vertex_code, vertex_globals,fragment_code, fragment_globals,uniform_names,enablers); + material_shader.set_custom_shader_code(p_shader->custom_code_id,vertex_code, vertex_globals,fragment_code, light_code, fragment_globals,uniform_names,enablers); } else { //postprocess_shader.set_custom_shader_code(p_shader->custom_code_id,vertex_code, vertex_globals,fragment_code, fragment_globals,uniform_names); } p_shader->valid=true; - p_shader->has_alpha=flags.uses_alpha || flags.uses_texscreen; - p_shader->writes_vertex=flags.vertex_code_writes_vertex; - p_shader->uses_discard=flags.uses_discard; - p_shader->has_texscreen=flags.uses_texscreen; - p_shader->has_screen_uv=flags.uses_screen_uv; - p_shader->can_zpass=!flags.uses_discard && !flags.vertex_code_writes_vertex; + p_shader->has_alpha=fragment_flags.uses_alpha || fragment_flags.uses_texscreen; + p_shader->writes_vertex=vertex_flags.vertex_code_writes_vertex; + p_shader->uses_discard=fragment_flags.uses_discard; + p_shader->has_texscreen=fragment_flags.uses_texscreen; + p_shader->has_screen_uv=fragment_flags.uses_screen_uv; + p_shader->can_zpass=!fragment_flags.uses_discard && !vertex_flags.vertex_code_writes_vertex; p_shader->version++; } @@ -4056,7 +4083,6 @@ void RasterizerGLES2::_add_geometry( const Geometry* p_geometry, const InstanceD } - LightInstance *lights[RenderList::MAX_LIGHTS]; RenderList *render_list=NULL; @@ -4067,10 +4093,10 @@ void RasterizerGLES2::_add_geometry( const Geometry* p_geometry, const InstanceD if (shadow) { - if (has_blend_alpha || (has_base_alpha && !m->hints[VS::MATERIAL_HINT_OPAQUE_PRE_PASS])) + if (has_blend_alpha || (has_base_alpha && m->depth_draw_mode!=VS::MATERIAL_DEPTH_DRAW_OPAQUE_PRE_PASS_ALPHA)) return; //bye - if (m->shader_cache && !m->shader_cache->writes_vertex && !m->shader_cache->uses_discard && !m->hints[VS::MATERIAL_HINT_OPAQUE_PRE_PASS]) { + if (m->shader_cache && !m->shader_cache->writes_vertex && !m->shader_cache->uses_discard && m->depth_draw_mode!=VS::MATERIAL_DEPTH_DRAW_OPAQUE_PRE_PASS_ALPHA) { //shader does not use discard and does not write a vertex position, use generic material m = shadow_mat_ptr; if (m->last_pass!=frame) { @@ -4153,7 +4179,7 @@ void RasterizerGLES2::_add_geometry( const Geometry* p_geometry, const InstanceD e->light_type=0xFF; // no lights! e->light=0xFFFF; - if (!shadow && !has_blend_alpha && has_alpha && m->hints[VS::MATERIAL_HINT_OPAQUE_PRE_PASS]) { + if (!shadow && !has_blend_alpha && has_alpha && m->depth_draw_mode==VS::MATERIAL_DEPTH_DRAW_OPAQUE_PRE_PASS_ALPHA) { //if nothing exists, add this element as opaque too RenderList::Element *oe = opaque_render_list.add_element(); @@ -4170,26 +4196,36 @@ void RasterizerGLES2::_add_geometry( const Geometry* p_geometry, const InstanceD e->light_type=0x7F; //unshaded is zero } else { - //setup lights - uint16_t light_count=0; - uint16_t sort_key[4]; - uint8_t light_types[4]; + bool duplicate=false; - int dlc = MIN(directional_light_count,RenderList::MAX_LIGHTS);; - light_count=dlc; - for(int i=0;i<dlc;i++) { - sort_key[i]=directional_lights[i]->sort_key; - light_types[i]=VS::LIGHT_DIRECTIONAL; + for(int i=0;i<directional_light_count;i++) { + uint16_t sort_key = directional_lights[i]->sort_key; + uint8_t light_type = VS::LIGHT_DIRECTIONAL; if (directional_lights[i]->base->shadow_enabled) { - light_types[i]|=0x8; + light_type|=0x8; if (directional_lights[i]->base->directional_shadow_mode==VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS) - light_types[i]|=0x10; + light_type|=0x10; else if (directional_lights[i]->base->directional_shadow_mode==VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS) - light_types[i]|=0x30; + light_type|=0x30; + + } + + RenderList::Element *ec; + if (duplicate) { + ec = render_list->add_element(); + memcpy(ec,e,sizeof(RenderList::Element)); + } else { + + ec=e; + duplicate=true; } + ec->light_type=light_type; + ec->light=sort_key; + ec->additive_ptr=&e->additive; + } @@ -4200,37 +4236,34 @@ void RasterizerGLES2::_add_geometry( const Geometry* p_geometry, const InstanceD for(int i=0;i<ilc;i++) { - if (light_count>=RenderList::MAX_LIGHTS) - break; - LightInstance *li=light_instance_owner.get( liptr[i] ); if (!li || li->last_pass!=scene_pass) //lit by light not in visible scene continue; - light_types[light_count]=li->base->type; - if (li->base->shadow_enabled) - light_types[light_count]|=0x8; - sort_key[light_count++]=li->sort_key; - - - } - - for(int i=0;i<light_count;i++) { + uint8_t light_type=li->base->type|0x40; //penalty to ensure directionals always go first + if (li->base->shadow_enabled) { + light_type|=0x8; + } + uint16_t sort_key =li->sort_key; RenderList::Element *ec; - if (i>0) { + if (duplicate) { ec = render_list->add_element(); memcpy(ec,e,sizeof(RenderList::Element)); } else { + duplicate=true; ec=e; } - ec->light_type=light_types[i]; - ec->light=sort_key[i]; + ec->light_type=light_type; + ec->light=sort_key; ec->additive_ptr=&e->additive; + } + + } DEBUG_TEST_ERROR("Add Geometry"); @@ -4405,7 +4438,7 @@ bool RasterizerGLES2::_setup_material(const Geometry *p_geometry,const Material material_shader.set_conditional(MaterialShaderGLES2::USE_SHADOW_PCF_HQ,shadow_filter==SHADOW_FILTER_PCF13); material_shader.set_conditional(MaterialShaderGLES2::USE_SHADOW_ESM,shadow_filter==SHADOW_FILTER_ESM); - if (p_opaque_pass && p_material->hints[VS::MATERIAL_HINT_OPAQUE_PRE_PASS] && p_material->shader_cache && p_material->shader_cache->has_alpha) { + if (p_opaque_pass && p_material->depth_draw_mode==VS::MATERIAL_DEPTH_DRAW_OPAQUE_PRE_PASS_ALPHA && p_material->shader_cache && p_material->shader_cache->has_alpha) { material_shader.set_conditional(MaterialShaderGLES2::ENABLE_CLIP_ALPHA,true); } else { @@ -4417,7 +4450,8 @@ bool RasterizerGLES2::_setup_material(const Geometry *p_geometry,const Material if (!shadow) { bool depth_test=!p_material->flags[VS::MATERIAL_FLAG_ONTOP]; - bool depth_write=!p_material->hints[VS::MATERIAL_HINT_NO_DEPTH_DRAW] && (p_opaque_pass || !p_material->hints[VS::MATERIAL_HINT_NO_DEPTH_DRAW_FOR_ALPHA]); + bool depth_write=p_material->depth_draw_mode!=VS::MATERIAL_DEPTH_DRAW_NEVER && (p_opaque_pass || p_material->depth_draw_mode==VS::MATERIAL_DEPTH_DRAW_ALWAYS); + //bool depth_write=!p_material->hints[VS::MATERIAL_HINT_NO_DEPTH_DRAW] && (p_opaque_pass || !p_material->hints[VS::MATERIAL_HINT_NO_DEPTH_DRAW_FOR_ALPHA]); if (current_depth_mask!=depth_write) { current_depth_mask=depth_write; @@ -4565,7 +4599,7 @@ bool RasterizerGLES2::_setup_material(const Geometry *p_geometry,const Material material_shader.set_uniform(MaterialShaderGLES2::FOG_COLOR_END,Vector3(col_end.r,col_end.g,col_end.b)); } - material_shader.set_uniform(MaterialShaderGLES2::CONST_LIGHT_MULT,p_no_const_light?0.0:1.0); + //material_shader.set_uniform(MaterialShaderGLES2::TIME,Math::fmod(last_time,300.0)); //if uses TIME - draw_next_frame=true @@ -4588,7 +4622,6 @@ void RasterizerGLES2::_setup_light(uint16_t p_light) { VL_LIGHT_DIR, VL_LIGHT_ATTENUATION, VL_LIGHT_SPOT_ATTENUATION, - VL_LIGHT_AMBIENT, VL_LIGHT_DIFFUSE, VL_LIGHT_SPECULAR, VL_LIGHT_MAX @@ -4599,7 +4632,6 @@ void RasterizerGLES2::_setup_light(uint16_t p_light) { MaterialShaderGLES2::LIGHT_DIRECTION, MaterialShaderGLES2::LIGHT_ATTENUATION, MaterialShaderGLES2::LIGHT_SPOT_ATTENUATION, - MaterialShaderGLES2::LIGHT_AMBIENT, MaterialShaderGLES2::LIGHT_DIFFUSE, MaterialShaderGLES2::LIGHT_SPECULAR, }; @@ -4611,12 +4643,10 @@ void RasterizerGLES2::_setup_light(uint16_t p_light) { LightInstance *li=light_instances[p_light]; Light *l=li->base; - Color col_ambient=_convert_color(l->colors[VS::LIGHT_COLOR_AMBIENT]); Color col_diffuse=_convert_color(l->colors[VS::LIGHT_COLOR_DIFFUSE]); Color col_specular=_convert_color(l->colors[VS::LIGHT_COLOR_SPECULAR]); for(int j=0;j<3;j++) { - light_data[VL_LIGHT_AMBIENT][j]=col_ambient[j]; light_data[VL_LIGHT_DIFFUSE][j]=col_diffuse[j]; light_data[VL_LIGHT_SPECULAR][j]=col_specular[j]; } @@ -5524,6 +5554,7 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans bool stores_glow = !shadow && (current_env && current_env->fx_enabled[VS::ENV_FX_GLOW]) && !p_alpha_pass; + bool prev_blend=false; glDisable(GL_BLEND); for (int i=0;i<p_render_list->element_count;i++) { @@ -5596,6 +5627,7 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans additive=true; } + if (stores_glow) material_shader.set_conditional(MaterialShaderGLES2::USE_GLOW,!additive); @@ -5637,7 +5669,7 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans case VS::MATERIAL_BLEND_MODE_ADD: { glBlendEquation(GL_FUNC_ADD); - glBlendFunc(GL_SRC_ALPHA,GL_ONE); + glBlendFunc(p_alpha_pass?GL_SRC_ALPHA:GL_ONE,GL_ONE); } break; case VS::MATERIAL_BLEND_MODE_SUB: { @@ -5728,7 +5760,8 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans if (i==0 || light!=prev_light || rebind) { if (e->light!=0xFFFF) { - _setup_light(e->light&0x3); + _setup_light(e->light); + } } @@ -5739,6 +5772,7 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_LATTICE_DIVIDE, baked_light->octree_lattice_divide); material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_STEPS, baked_light->octree_steps); material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_TEX,5); + material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_MULTIPLIER,baked_light->texture_multiplier); material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_PIX_SIZE,baked_light->octree_tex_pixel_size); @@ -5754,6 +5788,17 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans //material_shader.set_uniform(MaterialShaderGLES2::SKELETON_MATRICES,6); material_shader.set_uniform(MaterialShaderGLES2::SKELTEX_PIXEL_SIZE,skeleton->pixel_size); } + if (!shadow) { + + if (!additive && current_env && current_env->fx_enabled[VS::ENV_FX_AMBIENT_LIGHT]) { + Color ambcolor = current_env->fx_param[VS::ENV_FX_PARAM_AMBIENT_LIGHT_COLOR]; + float ambnrg = current_env->fx_param[VS::ENV_FX_PARAM_AMBIENT_LIGHT_ENERGY]; + material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_LIGHT,Vector3(ambcolor.r*ambnrg,ambcolor.g*ambnrg,ambcolor.b*ambnrg)); + } else { + material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_LIGHT,Vector3()); + } + } + _rinfo.shader_change_count++; } @@ -5788,6 +5833,9 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans material_shader.set_uniform(MaterialShaderGLES2::WORLD_TRANSFORM, e->instance->transform); } + material_shader.set_uniform(MaterialShaderGLES2::NORMAL_MULT, e->mirror?-1.0:1.0); + material_shader.set_uniform(MaterialShaderGLES2::CONST_LIGHT_MULT,additive?0.0:1.0); + _render(e->geometry, material, skeleton,e->owner,e->instance->transform); DEBUG_TEST_ERROR("Rendering"); @@ -5901,6 +5949,8 @@ void RasterizerGLES2::_process_glow_bloom() { glBindTexture(GL_TEXTURE_2D, current_vd->lum_color ); glUniform1i(copy_shader.get_uniform_location(CopyShaderGLES2::HDR_SOURCE),2); copy_shader.set_uniform(CopyShaderGLES2::TONEMAP_EXPOSURE,float(current_env->fx_param[VS::ENV_FX_PARAM_HDR_EXPOSURE])); + copy_shader.set_uniform(CopyShaderGLES2::TONEMAP_WHITE,float(current_env->fx_param[VS::ENV_FX_PARAM_HDR_WHITE])); +// copy_shader.set_uniform(CopyShaderGLES2::TONEMAP_WHITE,1.0); copy_shader.set_uniform(CopyShaderGLES2::HDR_GLOW_TRESHOLD,float(current_env->fx_param[VS::ENV_FX_PARAM_HDR_GLOW_TRESHOLD])); copy_shader.set_uniform(CopyShaderGLES2::HDR_GLOW_SCALE,float(current_env->fx_param[VS::ENV_FX_PARAM_HDR_GLOW_SCALE])); @@ -5980,7 +6030,7 @@ void RasterizerGLES2::_process_hdr() { _copy_screen_quad(); copy_shader.set_conditional(CopyShaderGLES2::USE_HDR_COPY,false); - int passes = current_env->fx_param[VS::ENV_FX_PARAM_GLOW_BLUR_PASSES]; +// int passes = current_env->fx_param[VS::ENV_FX_PARAM_GLOW_BLUR_PASSES]; copy_shader.set_conditional(CopyShaderGLES2::USE_HDR_REDUCE,true); copy_shader.bind(); @@ -6048,6 +6098,9 @@ void RasterizerGLES2::_draw_tex_bg() { glDepthMask(GL_TRUE); glEnable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); + glDisable(GL_BLEND); + glColorMask(1,1,1,1); + RID texture; @@ -6083,6 +6136,7 @@ void RasterizerGLES2::_draw_tex_bg() { copy_shader.set_conditional(CopyShaderGLES2::USE_CUSTOM_ALPHA,true); + copy_shader.bind(); if (current_env->bg_mode==VS::ENV_BG_TEXTURE || current_env->bg_mode==VS::ENV_BG_TEXTURE_RGBE) { @@ -6301,6 +6355,7 @@ void RasterizerGLES2::end_scene() { _render_list_forward(&opaque_render_list,camera_transform,camera_transform_inverse,camera_projection,false,fragment_lighting); if (draw_tex_background) { + //most 3D vendors recommend drawing a texture bg or skybox here, //after opaque geometry has been drawn //so the zbuffer can get rid of most pixels @@ -6344,6 +6399,28 @@ void RasterizerGLES2::end_scene() { glDepthMask(false); if (current_env && current_env->fx_enabled[VS::ENV_FX_HDR]) { + + int hdr_tm = current_env->fx_param[VS::ENV_FX_PARAM_HDR_TONEMAPPER]; + switch(hdr_tm) { + case VS::ENV_FX_HDR_TONE_MAPPER_LINEAR: { + + + } break; + case VS::ENV_FX_HDR_TONE_MAPPER_LOG: { + copy_shader.set_conditional(CopyShaderGLES2::USE_LOG_TONEMAPPER,true); + + } break; + case VS::ENV_FX_HDR_TONE_MAPPER_REINHARDT: { + copy_shader.set_conditional(CopyShaderGLES2::USE_REINHARDT_TONEMAPPER,true); + } break; + case VS::ENV_FX_HDR_TONE_MAPPER_REINHARDT_AUTOWHITE: { + + copy_shader.set_conditional(CopyShaderGLES2::USE_REINHARDT_TONEMAPPER,true); + copy_shader.set_conditional(CopyShaderGLES2::USE_AUTOWHITE,true); + } break; + } + + _process_hdr(); } if (current_env && current_env->fx_enabled[VS::ENV_FX_GLOW]) { @@ -6393,6 +6470,7 @@ void RasterizerGLES2::end_scene() { glBindTexture(GL_TEXTURE_2D, current_vd->lum_color ); glUniform1i(copy_shader.get_uniform_location(CopyShaderGLES2::HDR_SOURCE),2); copy_shader.set_uniform(CopyShaderGLES2::TONEMAP_EXPOSURE,float(current_env->fx_param[VS::ENV_FX_PARAM_HDR_EXPOSURE])); + copy_shader.set_uniform(CopyShaderGLES2::TONEMAP_WHITE,float(current_env->fx_param[VS::ENV_FX_PARAM_HDR_WHITE])); } @@ -6423,6 +6501,9 @@ void RasterizerGLES2::end_scene() { copy_shader.set_conditional(CopyShaderGLES2::USE_FXAA,false); copy_shader.set_conditional(CopyShaderGLES2::USE_GLOW_SCREEN,false); copy_shader.set_conditional(CopyShaderGLES2::USE_GLOW_SOFTLIGHT,false); + copy_shader.set_conditional(CopyShaderGLES2::USE_REINHARDT_TONEMAPPER,false); + copy_shader.set_conditional(CopyShaderGLES2::USE_AUTOWHITE,false); + copy_shader.set_conditional(CopyShaderGLES2::USE_LOG_TONEMAPPER,false); material_shader.set_conditional(MaterialShaderGLES2::USE_8BIT_HDR,false); @@ -6437,6 +6518,7 @@ void RasterizerGLES2::end_scene() { if (GLOBAL_DEF("rasterizer/debug_shadow_maps",false)) { _debug_shadows(); } +// _debug_luminances(); } @@ -6806,7 +6888,7 @@ void RasterizerGLES2::_debug_draw_shadows_type(Vector<ShadowBuffer>& p_shadows,P void RasterizerGLES2::_debug_luminances() { - canvas_shader.set_conditional(CanvasShaderGLES2::DEBUG_ENCODED_32,true); + canvas_shader.set_conditional(CanvasShaderGLES2::DEBUG_ENCODED_32,!use_fp16_fb); canvas_begin(); glDisable(GL_BLEND); canvas_shader.bind(); @@ -6814,10 +6896,17 @@ void RasterizerGLES2::_debug_luminances() { Size2 debug_size(128,128); Size2 ofs; - for (int i=0;i<framebuffer.luminance.size();i++) { - _debug_draw_shadow(framebuffer.luminance[i].color, Rect2( ofs, debug_size )); - ofs.x+=debug_size.x; + for (int i=0;i<=framebuffer.luminance.size();i++) { + + if (i==framebuffer.luminance.size()) { + if (!current_vd) + break; + _debug_draw_shadow(current_vd->lum_color, Rect2( ofs, debug_size )); + } else { + _debug_draw_shadow(framebuffer.luminance[i].color, Rect2( ofs, debug_size )); + } + ofs.x+=debug_size.x/2; if ( (ofs.x+debug_size.x) > viewport.width ) { ofs.x=0; @@ -7873,6 +7962,7 @@ void RasterizerGLES2::_update_framebuffer() { glDeleteFramebuffers(1,&framebuffer.luminance[i].fbo); } + for(int i=0;i<3;i++) { glDeleteTextures(1,&framebuffer.blur[i].color); @@ -7924,12 +8014,20 @@ void RasterizerGLES2::_update_framebuffer() { #endif //color - GLuint format_rgba = use_fp16_fb?_GL_RGBA16F_EXT:GL_RGBA; +// GLuint format_rgba = use_fp16_fb?_GL_RGBA16F_EXT:GL_RGBA; + GLuint format_rgba = GL_RGBA; GLuint format_rgb = use_fp16_fb?_GL_RGB16F_EXT:GL_RGB; GLuint format_type = use_fp16_fb?_GL_HALF_FLOAT_OES:GL_UNSIGNED_BYTE; - GLuint format_luminance = use_fp16_fb?_GL_R32F_EXT:GL_RGBA; - GLuint format_luminance_type = use_fp16_fb?GL_FLOAT:GL_UNSIGNED_BYTE; - GLuint format_luminance_components = use_fp16_fb?GL_RED:GL_RGBA; + /*GLuint format_luminance = use_fp16_fb?GL_RGB16F:GL_RGBA; + GLuint format_luminance_type = use_fp16_fb?(use_fu_GL_HALF_FLOAT_OES):GL_UNSIGNED_BYTE; + GLuint format_luminance_components = use_fp16_fb?GL_RGB:GL_RGBA;*/ + + GLuint format_luminance = use_fp16_fb?_GL_RG_EXT:GL_RGBA; + GLuint format_luminance_type = use_fp16_fb?(full_float_fb_supported?GL_FLOAT:_GL_HALF_FLOAT_OES):GL_UNSIGNED_BYTE; + GLuint format_luminance_components = use_fp16_fb?_GL_RG_EXT:GL_RGBA; + + + glGenTextures(1, &framebuffer.color); glBindTexture(GL_TEXTURE_2D, framebuffer.color); @@ -8071,8 +8169,8 @@ void RasterizerGLES2::_update_framebuffer() { glGenTextures(1, &lb.color); glBindTexture(GL_TEXTURE_2D, lb.color); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexImage2D(GL_TEXTURE_2D, 0, format_luminance, lb.size, lb.size, 0, @@ -8084,10 +8182,12 @@ void RasterizerGLES2::_update_framebuffer() { GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); glBindFramebuffer(GL_FRAMEBUFFER, 0); + + base_size/=3; + DEBUG_TEST_ERROR("Shadow Buffer Init"); ERR_CONTINUE( status != GL_FRAMEBUFFER_COMPLETE ); - base_size/=3; framebuffer.luminance.push_back(lb); } @@ -8238,6 +8338,7 @@ void RasterizerGLES2::init() { // use_attribute_instancing=true; use_texture_instancing=false; use_attribute_instancing=true; + full_float_fb_supported=true; #ifdef OSX_ENABLED use_rgba_shadowmaps=true; use_fp16_fb=false; @@ -8290,9 +8391,11 @@ void RasterizerGLES2::init() { } if (use_fp16_fb) { - use_fp16_fb=extensions.has("GL_OES_texture_half_float") && extensions.has("GL_EXT_color_buffer_half_float"); + use_fp16_fb=extensions.has("GL_OES_texture_half_float") && extensions.has("GL_EXT_color_buffer_half_float") && extensions.has("GL_EXT_texture_rg"); } + full_float_fb_supported=extensions.has("GL_EXT_color_buffer_float"); + //etc_supported=false; use_hw_skeleton_xform=false; |