Sprites with multiple skins

Posted By: Kartoffel

Sprites with multiple skins - 09/01/14 13:09

Hey,

I'd like to know if it's possible to create sprites with multiple skins (I need this for normalmapping).
I just tried using ent_setskin but had no success.
Posted By: sivan

Re: Sprites with multiple skins - 09/02/14 07:09

I think no, sprites have some limitations I discussed with Jcl a while ago (I don't remember exactly, but it was related to my lightmapper, i.e. getting skin pixel data by c_tracing, and finally I needed to create temporary models out of sprites, and then remove them... the manual does not describe it exactly).
maybe you can use a skin looking like of an animated sprite to read normal map from it. (by the way I do not use sprites any more.)
Posted By: Emre

Re: Sprites with multiple skins - 09/02/14 08:16

how about shader solution?
Code:
//from rendermonkey
float4 lightness = float4( 0.30, 0.59, 0.11, 0.00 );
float4 tex2DN_ATI(uniform sampler2D BaseMap,float2 texCoord,float res) : COLOR
{	


	float off = 1.0 / res;
	float4 s00 = tex2D(BaseMap, texCoord + float2(-off, -off));
	float4 s01 = tex2D(BaseMap, texCoord + float2( 0,   -off));
	float4 s02 = tex2D(BaseMap, texCoord + float2( off, -off));
	float4 s10 = tex2D(BaseMap, texCoord + float2(-off,  0));
	float4 s12 = tex2D(BaseMap, texCoord + float2( off,  0));
	float4 s20 = tex2D(BaseMap, texCoord + float2(-off,  off));
	float4 s21 = tex2D(BaseMap, texCoord + float2( 0,    off));
	float4 s22 = tex2D(BaseMap, texCoord + float2( off,  off));
	float4 sobelX = s00 + 2 * s10 + s20 - s02 - 2 * s12 - s22;
	float4 sobelY = s00 + 2 * s01 + s02 - s20 - 2 * s21 - s22;
	float sx = dot(sobelX, lightness);
	float sy = dot(sobelY, lightness);
	float3 normal = normalize(float3(sx, sy, 1));
	return float4(normal * 0.5 + 0.5, 1);
	
}

...
float4 normal=2*(tex2DN_ATI(sampler,coord,512)-0.5);
...



result is not very good but maybe you'd like to use anyway.
Posted By: Kartoffel

Re: Sprites with multiple skins - 09/02/14 10:02

not sure what it does? I guess you're generating a normalmap from the color data?

I think I'm going with a workaround then, making the texture twice as wide (left colormap, right normalmap), applying 'scale_x = 0.5;' and using some little helperfunctions to sample the texture properly.
(actually that's pretty much sivan's soluition :D)

But thank you for your suggestions.

Edit: the function would be something like this:
Code:
const static float num_skins_total = 2.0;
const static float4 border_color = { 0.0, 0.0, 0.0, 0.0 };

float4 tex2D_multitex(sampler2D smp, float2 tex, float skin_num)
{
   // address modes:
   tex %= 1.0; // address wrap
   
   //tex = saturate(tex); // address clamp
   
   //if(saturate(tex.x) != tex.x || saturate(tex.y) != tex.y) // address border
   //   return border_color;
   
   return tex2D(smp, (tex + skin_num) / num_skins_total);
}

Posted By: Emre

Re: Sprites with multiple skins - 09/02/14 11:00

Originally Posted By: Kartoffel
not sure what it does? I guess you're generating a normalmap from the color data?

Yes, exactly. laugh


as far as i remember, i took that code from RenderMonkey
Posted By: Kartoffel

Re: Sprites with multiple skins - 09/02/14 11:05

okay, nice. BUT, I really don't like generated normalmaps smirk
Especially because I'm working on low-res graphics and the normalmaps have to be really accurate.
Posted By: Emre

Re: Sprites with multiple skins - 09/02/14 11:17

fair enough. i don't like it either. as i said result is not very good. tongue
Posted By: Kartoffel

Re: Sprites with multiple skins - 09/02/14 11:20

yeah grin
but thanks though, always nice to see how ppl offer their help here... really appreciate that.
© 2024 lite-C Forums