summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2014-06-11 10:41:03 -0300
committerJuan Linietsky <reduzio@gmail.com>2014-06-11 10:41:03 -0300
commit9b8696d3dd92e2ed6f310ad0f0bf3c2182c9c6ae (patch)
treeb2ed0515196bb774504b54aab0bf242992ac3d9f /drivers
parent6f0b4678e26c04abfc88c0226c803e78a108de98 (diff)
Light Baker!
-=-=-=-=-=-= -Support for lightmap baker, have fun figuring out how it works before tutorial is published.
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gles2/rasterizer_gles2.cpp49
-rw-r--r--drivers/gles2/shaders/material.glsl89
-rw-r--r--drivers/unix/ip_unix.cpp2
3 files changed, 137 insertions, 3 deletions
diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp
index 74a82e1a5c..91b82d1999 100644
--- a/drivers/gles2/rasterizer_gles2.cpp
+++ b/drivers/gles2/rasterizer_gles2.cpp
@@ -1042,8 +1042,8 @@ void RasterizerGLES2::texture_set_size_override(RID p_texture,int p_width, int p
ERR_FAIL_COND(!texture);
ERR_FAIL_COND(texture->render_target);
- ERR_FAIL_COND(p_width<=0 || p_width>4096);
- ERR_FAIL_COND(p_height<=0 || p_height>4096);
+ ERR_FAIL_COND(p_width<=0 || p_width>16384);
+ ERR_FAIL_COND(p_height<=0 || p_height>16384);
//real texture size is in alloc width and height
texture->width=p_width;
texture->height=p_height;
@@ -5471,6 +5471,7 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans
const ParamOverrideMap* prev_overrides=NULL; // make it diferent than NULL
const Skeleton *prev_skeleton =NULL;
uint8_t prev_sort_flags=0xFF;
+ const BakedLightData *prev_baked_light=NULL;
Geometry::Type prev_geometry_type=Geometry::GEOMETRY_INVALID;
@@ -5486,6 +5487,9 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans
material_shader.set_conditional(MaterialShaderGLES2::LIGHT_USE_PSSM,false);
material_shader.set_conditional(MaterialShaderGLES2::LIGHT_USE_PSSM4,false);
material_shader.set_conditional(MaterialShaderGLES2::SHADELESS,false);
+ material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_OCTREE,false);
+// material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_TEXTURE,false);
+
}
@@ -5503,8 +5507,10 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans
uint8_t sort_flags= e->sort_flags;
const Skeleton *skeleton = e->skeleton;
const Geometry *geometry_cmp = e->geometry_cmp;
+ const BakedLightData *baked_light = e->instance->baked_light;
bool rebind=false;
+ bool bind_baked_light_octree=false;
bool additive=false;
@@ -5622,6 +5628,32 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans
current_blend_mode=desired_blend_mode;
}
+ material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_OCTREE,false);
+// material_shader.set_conditional(MaterialShaderGLES2::USE_AMBIENT_TEXTURE,false);
+
+ if (!additive && baked_light) {
+
+ if (baked_light->mode==VS::BAKED_LIGHT_OCTREE && baked_light->octree_texture.is_valid() && e->instance->baked_light_octree_xform) {
+ material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_OCTREE,true);
+ bind_baked_light_octree=true;
+ if (prev_baked_light!=baked_light) {
+ Texture *tex=texture_owner.get(baked_light->octree_texture);
+ if (tex) {
+
+ glActiveTexture(GL_TEXTURE5);
+ glBindTexture(tex->target,tex->tex_id); //bind the texture
+ }
+
+ }
+ } else if (baked_light->mode==VS::BAKED_LIGHT_LIGHTMAPS) {
+
+ //material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_TEXTURE,true);
+ }
+ }
+
+ if (int(prev_baked_light!=NULL) ^ int(baked_light!=NULL)) {
+ rebind=true;
+ }
}
if (sort_flags!=prev_sort_flags) {
@@ -5672,6 +5704,18 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans
}
}
+ if (bind_baked_light_octree && (baked_light!=prev_baked_light || rebind)) {
+
+ material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_INVERSE_TRANSFORM, *e->instance->baked_light_octree_xform);
+ material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_LATTICE_SIZE, baked_light->octree_lattice_size);
+ 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_PIX_SIZE,baked_light->octree_tex_pixel_size);
+
+
+ }
+
_set_cull(e->mirror,p_reverse_cull);
@@ -5726,6 +5770,7 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans
prev_light=e->light;
prev_light_type=e->light_type;
prev_sort_flags=sort_flags;
+ prev_baked_light=baked_light;
// prev_geometry_type=geometry->type;
}
diff --git a/drivers/gles2/shaders/material.glsl b/drivers/gles2/shaders/material.glsl
index a919e3b1e2..7ed59ae9cd 100644
--- a/drivers/gles2/shaders/material.glsl
+++ b/drivers/gles2/shaders/material.glsl
@@ -93,6 +93,13 @@ varying vec3 tangent_interp;
varying vec3 binormal_interp;
#endif
+#ifdef ENABLE_AMBIENT_OCTREE
+
+uniform highp mat4 ambient_octree_inverse_transform;
+varying highp vec3 ambient_octree_coords;
+
+#endif
+
#ifdef USE_FOG
varying vec4 fog_interp;
@@ -173,12 +180,19 @@ void main() {
#ifdef USE_UNIFORM_INSTANCING
highp mat4 modelview = (camera_inverse_transform * (world_transform * instance_transform));
+#ifdef ENABLE_AMBIENT_OCTREE
+ highp mat4 ambient_octree_transform = (ambient_octree_inverse_transform * (world_transform * instance_transform));
+#endif
+
#else
#ifdef USE_ATTRIBUTE_INSTANCING
highp mat4 minst=mat4(instance_row0,instance_row1,instance_row2,instance_row3);
highp mat4 modelview = (camera_inverse_transform * (world_transform * minst));
+#ifdef ENABLE_AMBIENT_OCTREE
+ highp mat4 ambient_octree_transform = (ambient_octree_inverse_transform * (world_transform * minst));
+#endif
#else
@@ -201,9 +215,16 @@ void main() {
);*/
highp mat4 modelview = (camera_inverse_transform * (world_transform * minst));
+#ifdef ENABLE_AMBIENT_OCTREE
+ highp mat4 ambient_octree_transform = (ambient_octree_inverse_transform * (world_transform * minst));
+#endif
#else
highp mat4 modelview = (camera_inverse_transform * world_transform);
+#ifdef ENABLE_AMBIENT_OCTREE
+ highp mat4 ambient_octree_transform = (ambient_octree_inverse_transform * world_transform);
+#endif
+
#endif
#endif
@@ -233,6 +254,11 @@ void main() {
#endif
+#ifdef ENABLE_AMBIENT_OCTREE
+
+ ambient_octree_coords = (ambient_octree_transform * vertex_in).xyz;
+#endif
+
vertex_interp = (modelview * vertex_in).xyz;
normal_interp = normalize((modelview * vec4(normal_in,0.0)).xyz);
@@ -515,6 +541,16 @@ vec3 process_shade(in vec3 normal, in vec3 light_dir, in vec3 eye_vec, in vec3 d
uniform float const_light_mult;
uniform float time;
+#ifdef ENABLE_AMBIENT_OCTREE
+
+varying highp vec3 ambient_octree_coords;
+uniform highp float ambient_octree_lattice_size;
+uniform highp vec2 ambient_octree_pix_size;
+uniform highp float ambient_octree_lattice_divide;
+uniform highp sampler2D ambient_octree_tex;
+uniform int ambient_octree_steps;
+
+#endif
FRAGMENT_SHADER_GLOBALS
@@ -745,10 +781,57 @@ FRAGMENT_SHADER_CODE
}
#endif
+#ifdef ENABLE_AMBIENT_OCTREE
+
+ vec3 ambientmap_color = vec3(0.0,0.0,0.0);
+
+
+ {
+
+ //read position from initial lattice grid
+ highp vec3 lattice_pos = floor(ambient_octree_coords*ambient_octree_lattice_size);
+ highp vec2 octant_uv = highp vec2(lattice_pos.x+ambient_octree_lattice_size*lattice_pos.z,lattice_pos.y);
+ octant_uv=(octant_uv*highp vec2(2.0,4.0)+highp vec2(0.0,4.0));
+ highp float ld = 1.0/ambient_octree_lattice_size;
+
+
+ //go down the octree
+
+ for(int i=0;i<ambient_octree_steps;i++) {
+
+
+ highp vec3 sub=mod(ambient_octree_coords,ld);
+ ld*=0.5;
+ highp vec3 s = step(ld,sub);
+ octant_uv+=s.xy;
+ octant_uv.y+=s.z*2.0;
+ octant_uv=(octant_uv+0.5)*ambient_octree_pix_size;
+ highp vec4 new_uv = texture2D(ambient_octree_tex,octant_uv);
+ octant_uv=floor(highp vec2( dot(new_uv.xy,highp vec2(65280.0,255.0)), dot(new_uv.zw,highp vec2(65280.0,255.0)) )+0.5);//+ambient_octree_pix_size*0.5;
+
+ }
+
+ //sample color
+ octant_uv=(octant_uv+0.5)*ambient_octree_pix_size;
+ highp vec3 sub=(mod(ambient_octree_coords,ld)/ld);
+ octant_uv.xy+=sub.xy*ambient_octree_pix_size.xy;
+ vec3 col_up=texture2D(ambient_octree_tex,octant_uv).rgb;
+ octant_uv.y+=ambient_octree_pix_size.y*2.0;
+ vec3 col_down=texture2D(ambient_octree_tex,octant_uv).rgb;
+ ambientmap_color=mix(col_down,col_up,1.0-sub.z);
+
+ ambientmap_color*=diffuse.rgb;
+
+ }
+
+#endif
float shadow_attenuation = 1.0;
+
+
+
#ifdef LIGHT_USE_SHADOW
#ifdef LIGHT_TYPE_DIRECTIONAL
@@ -921,6 +1004,8 @@ FRAGMENT_SHADER_CODE
#endif
+
+
#ifdef USE_VERTEX_LIGHTING
vec3 ambient = light_ambient*diffuse.rgb;
@@ -933,11 +1018,13 @@ FRAGMENT_SHADER_CODE
diffuse.rgb=(diffuse.rgb * diffuse_interp.rgb + specular * specular_interp)*shadow_attenuation + ambient;
diffuse.rgb+=emission * const_light_mult;
-
#endif
+#ifdef ENABLE_AMBIENT_OCTREE
+ diffuse.rgb+=ambientmap_color;
+#endif
#ifdef USE_SHADOW_PASS
diff --git a/drivers/unix/ip_unix.cpp b/drivers/unix/ip_unix.cpp
index 18b19ca095..24b18a14f7 100644
--- a/drivers/unix/ip_unix.cpp
+++ b/drivers/unix/ip_unix.cpp
@@ -130,6 +130,8 @@ void IP_Unix::get_local_addresses(List<IP_Address> *r_addresses) const {
getifaddrs(&ifAddrStruct);
for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) {
+ if (!ifa->ifa_addr)
+ continue;
if (ifa ->ifa_addr->sa_family==AF_INET) { // check it is IP4
// is a valid IP4 Address