I am trying to make 2d lights based on box2d raycastion.
It worked good.
But when light sources is mixed with each other it not look good.
Any ideas will help me.
Maybe i need another blend function?
For lights i use meshes.
Render
render.set_depth_mask(false)
-- set render target so all drawing is done to it
render.set_render_target(self.targets.light_map.target, { transient = { render.BUFFER_DEPTH_BIT, render.BUFFER_STENCIL_BIT } })
render.clear({ [render.BUFFER_COLOR_BIT] = vmath.vector4(0, 0, 0, 0), [render.BUFFER_DEPTH_BIT] = 1, [render.BUFFER_STENCIL_BIT] = 0 })
render.set_viewport(0, 0,
self.targets.light_map.w, self.targets.light_map.h)
render.set_view(CAMERAS.current:get_view())
render.set_projection(CAMERAS.current:get_proj())
render.set_blend_func(render.BLEND_SRC_ALPHA, render.BLEND_ONE)
render.draw(self.predicates.light)
light.vp
data.x is ray distance from 1 at start and 0 at ray end.
// Positions can be world or local space, since world and normal
// matrices are identity for world vertex space materials.
// If world vertex space is selected, you can remove the
// normal matrix multiplication for optimal performance.
attribute highp vec4 position;
attribute mediump vec3 normal;
attribute mediump vec2 texcoord0;
attribute mediump vec4 color0;
attribute mediump vec4 data; //(x is ray fraction);
uniform mediump mat4 mtx_worldview;
uniform mediump mat4 mtx_view;
uniform mediump mat4 mtx_proj;
uniform mediump mat4 mtx_normal;
uniform mediump vec4 light;
varying highp vec4 var_position;
varying mediump vec3 var_normal;
varying mediump vec2 var_texcoord0;
varying mediump vec4 var_color0;
varying mediump vec4 var_light;
void main()
{
vec4 p = mtx_worldview * vec4(position.xyz, 1.0);
var_position = p;
var_texcoord0 = texcoord0;
var_color0 = color0 * data.x;
gl_Position = mtx_proj * p;
}
light.fp
varying highp vec4 var_position;
varying mediump vec3 var_normal;
varying mediump vec2 var_texcoord0;
varying highp vec4 var_color0;
varying mediump vec4 var_light;
uniform lowp sampler2D tex0;
uniform lowp vec4 tint;
uniform lowp vec4 ambient;
void main()
{
// Pre-multiply alpha since all runtime textures already are
// vec4 tint_pm = vec4(tint.xyz * tint.w, tint.w);
// Pre-multiply alpha since all runtime textures already are
vec4 color0 = vec4(var_color0.rgb,var_color0.a);
// vec4 color = texture2D(tex0, var_texcoord0.xy)*tint_pm*color0;
//vec4 color = color0;
//gamma correction
vec4 color = sqrt(color0);
gl_FragColor =color;
}