light_res.statements.append(Statement("type", Token("point")))
pos = obj.matrix_world@mathutils.Vector((0.0, 0.0, 0.0, 1.0))
light_res.statements.append(Statement("position", *obj.matrix_world.col[3][0:3]))
+ light_res.statements.append(Statement("attenuation", 1.0, 0.0, 1.0))
else:
raise Exception("Can't export light {} of unknown type {}".format(light.name, light.type))
vec4 light_pos = light_sources[index].position;
vec3 rel_pos = light_pos.xyz-world_pos*light_pos.w;
float d = length(rel_pos);
- return IncomingLight(rel_pos/d, light_sources[index].color);
+ float attenuation = 1.0/dot(vec3(1.0, d, d*d), light_sources[index].attenuation);
+ return IncomingLight(rel_pos/d, light_sources[index].color*attenuation);
}
virtual vec3 get_environment_sample(vec3 direction, float roughness)
vec4 position;
vec3 color;
int type;
+ vec3 attenuation;
};
struct ClipPlane
set_fog_color(Color(0.0f, 0.0f, 0.0f, 0.0f));
set_fog_density(0.0f);
- for(unsigned i=0; i<8; ++i)
+ for(unsigned i=0; i<7; ++i)
{
string base = format("light_sources[%d]", i);
shdata.uniform(base+".position", Vector4(0, 0, 1, 0));
shdata.uniform(base+".color", 0.0f, 0.0f, 0.0f);
shdata.uniform(base+".type", 0);
+ shdata.uniform(base+".attenuation", 1.0f, 0.0f, 0.0f);
}
}
shdata.uniform(base+".type", 2);
shdata.uniform(base+".position", position.x, position.y, position.z, 1.0f);
shdata.uniform(base+".color", color.r, color.g, color.b);
+ shdata.uniform3(base+".attenuation", attenuation);
}
private:
Vector3 position = { 0.0f, 0.0f, 0.0f };
- float attenuation[3] = { 1.0f, 0.0f, 0.1f };
+ float attenuation[3] = { 1.0f, 0.0f, 1.0f };
void update_matrix();