Monday, December 31, 2018

xna - How is this glowing with colors radiating outward 2D effect accomplished?


I'm currently totally at a loss as to how this effect is done: http://www.youtube.com/watch?v=zp8MHUNp7Cg


The glowing on the ship and the changing color. I want to do this effect in XNA 4.0 any hints and tips?




Answer



It looks like simple vertex colouring where the colour index is function of the distance to the centre of the ship, plus time.


This can be implemented using a texture storing a palette. It could also be done proceduraly if the desired colour gradients are simple enough.


If using a palette, the vertex shader would be something like this:


uniform float4 in_ShipCenter; /* Centre of the ship */
uniform float in_Time; /* Elapsed time */
/* ... */

void main(float4 in_Position : POSITION,
uniform sampler1D in_Palette,

/* ... */
out float4 out_Color : COLOR)
{
/* ... */
float distance = length((in_Position - in_ShipCenter).xyz);
float time = in_Time;

/* Simple distance/time combination */
vec2 colorIndex = vec2(distance + time, 0.5);


/* Other possible effects:
* vec2 colorIndex = vec2(A * distance + B * time, 0.5);
* vec2 colorIndex = vec2(distance, time);
* vec2 colorIndex = vec2(distance + A * time, time + B * distance); */

/* Query the colour in the two-dimensional texture palette. */
out_Color = tex2D(in_Palette, colorIndex);
}

Edit: account for the fact that XNA doesn't support 1D palettes. If you still want to access the pixels of a 2D palette as if it was a 1D palette, see this question.



No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...