HoD is a first person point-and-click adventure set in a steampunk environment. You will have to unravel the mystery of the airship, you will find yourself in, where nothing is what it seems.

Report RSS Dynamic light in a dark world

Purpose built lighting effects done cheap. Light shining through an open door using a simple shader.

Posted by on - Basic Animation

As I am targeting low end PCs and mobile devices, using real-time lighting and shadow casting is not an option in my game.

One purpose build lighting effect is the door light. When the door opens or closes, the light from the room on the opposite side will illuminate the floor on the other side. The light cone will change during the transition.

door light animation

To achieve this effect, I’m using a light cone shaped mesh. During the transition the outer vertices move in- and out-wards, masked by a second UV set.

mesh

// float property to control the transition
Properties {
	_doorOpen ("Door open", Range (0, 1)) = 0
}

// vertext shader
VertOut vertShader(VertIn input) {
	VertOut output;
	// offset to move the vertices on X, multiplied with the mask-uv
	// using uv.y to pin the mesh to the left corner of the opening
	float open = (input.texcoord1.x*_doorOpen) + (_doorOpen*0.5*(1.0-input.texcoord1.y));
	// adding it to the vertex positon
	output.position = mul(UNITY_MATRIX_MVP,float4(input.vertex.x + open,input.vertex.y,input.vertex.z,input.vertex.w));
	return output;
}

The output color of the shader is a simple white gradient with a falloff.

To increase the brightness and intensity of the floor, I’m using a special blend mode.

In Unity:

SubShader {
		// blending
		Blend DstColor One	
}

In GLSL:

(GL_DST_COLOR,GL_ONE)

What it does: Source-Color * Destination-Color + Destination-Color * 1

It will multiply the light color with the floor color and adds it to the floor color already in the frame buffer.

Simple as that. It's a nice effect without any extraordinary performance impact.
I'm using this for other objects as well, like laser beams hitting a surface.

Thanks for reading.


Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: