I have to build a texture of a cube that models the emission of light by the object. Any tips? I really don't know where to start.
Presumably you are using a lighting system already, let's say Lambert shading for simplicity..
So we have a texture which is going to be illuminated by some light source. The following psuedo/shader code will do lambert shading as normal..
diffuseIllum = lightColour * dot(normal, lightDir); outputColour = textureColour.rgb * diffuseIllum;
But we want certain parts of our texture to emit colours instead of being illuminated by only our light source.
One method would be to use an extra channel in the input texture, say the Alpha channel, to control which pixels are emissive
diffuseIllum = lightColour * dot(normal, lightDir); outputColor = mix(textureColour.rgb * diffuseIllum, textureColour.rgb, texture.a);
Unfortunately this won't work so well if you want say a dark red glow because the output pixel will either be the emissive colour (dark red) or the lit texture colour, which could be much brighter. In effect our emissive areas could end up darker than the surrounding illuminated areas.
We could add the emissive colour to the illuminated texture but that limits how much control over final colour we have.
outputColour = textureColour.rgb * diffuseIllum + textureColour.rgb * textureColour.a;
A more correct method would involve using 2 textures, one for diffuse illumination and another for purely emissive. These would be added together in the pixel shader.
outputColour = textureColour.rgb * diffuseIllum + emissiveTextureColour.rgb;
A self-illuminating texture is rather easy. You can use the fragmentshader to increase the color value of those pixels.
If you want a "halo"-like effect it gets more complicated. As Charlie said, you'd have to render in multiple passes. Render your texture only in a first pass, blur it and adjust color / brightness and put that information on top of your main render pass.
If you even want your texture to illuminate surrounding objects it gets even more complicated. You could go for a texture projection for static purposes. Or you could average the texture information into one color and place an omni light in front of the emitting cube face. There are better solutions though, I am sure.