Jump to content

  • Log In with Google      Sign In   
  • Create Account


greenpig83

Member Since 28 Jul 2012
Offline Last Active Aug 15 2014 08:16 AM

Topics I've Started

Manage user avatar...

07 March 2014 - 01:17 AM

Hi, I have a common problem like this!

 

In my game each user have an avatar. It's a small image about 128x128 size.  (I use D3DSprite  to draw the avatar on screen)

I have hundred of them for user to select, or they can upload their own. I think most system have this like forum...

There are alot of them that load them all at start of game is not nice! So I want to load them only when that avatar appear on screen. And keep about 100 avatar at a time! When a avatar is loaded it will have a loading image instead! The avatar will be free if it is not used ...

 

If we use each texture for an avatar, it's simple. I'm not tested yet, but i think display many texture at a time will slow down the performance (if we in a lobby screen or ranking screen, there will be ~ 20-50 players on screen). I prefer to load all the small image into 1 big one, that will speed up a lot! Because D3DSprite draw well with less texture!

 

But as we know, when we change a texture, we need to lock it, and i'm not sure we can still draw it while it's locking. Furthermore, I read at

 

http://social.msdn.microsoft.com/Forums/en-US/07e44457-75c2-432e-9a8c-d6e550003eba/background-texture-loading?forum=gametechnologiesdirectx101

 

they adviced not to use thread for loading texture. So that will be problem. I dont want the game to stop just to load all the user avatar. What will you do in this situation ?

THanks


Binary to Integer (Read hex binary file)

19 February 2014 - 12:09 PM

I'm trying to read an unknown type file (a save game file, I change the value and then see the file in Hex editor) !

And i want to read the integer values. I know where it is ! but the hex value is quite strange! I use Decimal here for easy understanding!

 

(byte-byte -> integer )
           //128,63 -> 1           128 =  10000000   63=00111111
            //0, 64 -> 2(10)            00000000-0100000064=    01000000
            //64-64 -> 3(11)            01000000-01000000
            //128-64 -> 4(100)          10000000-01000000
            //160-64 -> 5(101)      160=10100000-01000000
            //192-64 -> 6(110)      192=11000000-01000000
            //224-64 -> 7(111)          11100000-01000000
            //0-65 -> 8 (1000)          00000000-01000001
            //16-65 -> 9(1001)          00010000-01000001   
            //32-65 ->10(1010)          00100000-01000001
            //48-65 ->11(1011)          00110000-01000001   
            //64-65 ->12(1100)          01000000-01000001
            //80-65 ->13(1101)          01010000-01000001
            //96-65 ->14(1110)          01100000-01000001   
            //112-65 ->15(1111)         01110000-01000001
            //128-65 ->16(10000)        10000000-01000001
 
            //136-65 ->17(10001)        10001000-01000001   
            //144-65 ->18(10010)        10010000-01000001
            //152-65 ->19(10011)        10011000-01000001
 
            //160-65 ->20(10100)        10100000-01000001   
            //168-65 ->21(10101)        10101000-01000001
            //176-65 ->22(10110)        10110000-01000001
 
            //32-66 ->40(101000)        00100000-01000010
 
            //48,64,80
 
            //160-66 ->80(1010000)      10100000-01000010   
            //162-66 ->81(1010001)      10100010-01000010
            //164-66 ->82(1010010)      10100100-01000010
 
 
(bigger values, int,int,int -> byte-byte )
//80,81,82  -> 160-66,162-66,164-66
            //180,181,182 -> : 52-67,53-67,54-67
            //20,21,22 -> 160 ,168 , 176 -65
            //30,40,50 ->  240-65,248-65, 0-66  (3 integer -> 3 (2bytes))
 
//128-191 -> -1             10000000-10111111
            //0-192 -> -2               00000000-11000000
            //64-192 -> -3              01000000-11000000
 
The values is like above. It use 4 byte (but only 2 byte have values) . It seems that the left-most bit of 2nd byte are for Signed!
There is some rule , but i find it hard to figure out !
Thanks !
 

Need algorith to rotate isometric image sprite !

18 February 2014 - 04:54 AM

Hi I'm working with an isometric project. That require me, each unit animation need 8 direction (5 for flipping : E flip to W, NE flip to WE, SE flip to SW!). 

I've found many resource on net that are isometric, but not all 8 direction, some 6 direction (hexa tile game), some only 4...! 

So I think that because its isometric view, we can base on 1 direction and rotate to its closest direction (about 30 degree rotate)!  Of course it will not look nice (because we reverse engine it), but better than unit move to West, but his heads and legs heading NW. 

 

Here is an example of the dragon from MM8! 

This frame it's heading SE (south-East). 

m492Fa1_zps75c1b023.png

 

And this one is what I want to achive, heading E (East)

m492Fa2_zps59c1ab3a.png

 

Normally we lack the East,West direction because in isometric world! But just 1 is enough, because East can be flipped into West! North cant flipped to South...

Thanks! I think I can write my own this but it will take time and need time to make it look nice, so if there are already a solution I dont want to reinvent the wheel!


Generate random map of fixed size chunk

16 December 2013 - 03:32 PM

Hi i'm working on a rts map, based on tile. And when generate the random map, I want to divide things into chunk of fixed size. Example I want to have about 10 chunks of forest of size 100 (100 tiles /chunk, no need exactly just about, so we can control it)... Or dessert, water... The chunk should have random and natural shape!
 
Of couse we all think about perlin noise, cause it give us the most random and natural shape. However after research about the perlin and its application. It's not easy to control the size of each island, you change some noise parameter (octave,persist,frequence..) : http://libnoise.sourceforge.net/tutorials/tutorial4.html
 
It does change the result map, but it's not easy to control the size. Do you know other algorith that address my problem, or should I try to change the result of the perlin algorith to create my chunk ?

[Dx9] How to use Fragment Shader (XBR filter)

12 December 2013 - 09:30 PM

Hi, I'm new to Shader and HLSL. I'm working with sprite and Zooming with Linear (SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);) 

get very bad result, it's blurry and darken! After search a while I found out that XBR 2x filter is so good for sprite zooming (Although it work only well with 2x). I think we can use it to zoom to 2x then scale back to where we want (because zoom out work very well). Search awhile and I found some code but it's not in vertex shader -> pixel shader format that I used to work it. So I have trouble to load it in my code and test !

The code is like this :

 

const static float coef           = 2.0;
const static half3 yuv_weighted  = half3(14.352, 28.176, 5.472);
 
 
float4 df(float4 A, float4 B)
{
  return float4(abs(A.x-B.x), abs(A.y-B.y), abs(A.z-B.z), abs(A.w-B.w));
}
 
 
float4 weighted_distance(float4 a, float4 b, float4 c, float4 d, float4 e, float4 f, float4 g, float4 h)
{
  return (df(a,b) + df(a,c) + df(d,e) + df(d,f) + 4.0*df(g,h));
}
 
 
struct input
{
  half2 video_size;
  float2 texture_size;
  half2 output_size;
  float frame_count;
  float frame_direction;
  float frame_rotation;
};
 
 
struct out_vertex {
  half4 position : POSITION;
  float2 texCoord : TEXCOORD0;
  half4 t1 : TEXCOORD1;
};
 
/*    VERTEX_SHADER    */
out_vertex main_vertex
(
  half4 position  : POSITION,
  float2 texCoord : TEXCOORD0,
 
     uniform half4x4 modelViewProj,
  uniform input IN
)
{
        out_vertex OUT = (out_vertex)0;
 
  OUT.position = mul(modelViewProj, position);
 
  half2 ps = float2(1.0/IN.texture_size.x, 1.0/IN.texture_size.y);
  half dx = ps.x;
  half dy = ps.y;
 
  OUT.texCoord = texCoord;
  OUT.t1.xy = half2( dx,  0); // F
  OUT.t1.zw = half2(  0, dy); // H
 
  return OUT;
}
 
 
/*    FRAGMENT SHADER    */
half4 main_fragment(in out_vertex VAR, uniform sampler2D decal : TEXUNIT0, uniform input IN) : COLOR
{
  bool4 edr, edr_left, edr_up, px; // px = pixel, edr = edge detection rule
  bool4 ir_lv1, ir_lv2_left, ir_lv2_up;
  bool4 nc; // new_color
  bool4 fx, fx_left, fx_up; // inequations of straight lines.
 
  float2 fp = frac(VAR.texCoord*IN.texture_size);
 
  float2 dx = VAR.t1.xy;
  float2 dy = VAR.t1.zw;
 
  half3 A = tex2D(decal, VAR.texCoord -dx -dy).xyz;
  half3 B = tex2D(decal, VAR.texCoord     -dy).xyz;
  half3 C = tex2D(decal, VAR.texCoord +dx -dy).xyz;
  half3 D = tex2D(decal, VAR.texCoord -dx    ).xyz;
  half3 E = tex2D(decal, VAR.texCoord        ).xyz;
  half3 F = tex2D(decal, VAR.texCoord +dx    ).xyz;
  half3 G = tex2D(decal, VAR.texCoord -dx +dy).xyz;
  half3 H = tex2D(decal, VAR.texCoord     +dy).xyz;
  half3 I = tex2D(decal, VAR.texCoord +dx +dy).xyz;
 
  half3  A1 = tex2D(decal, VAR.texCoord     -dx -2.0*dy).xyz;
  half3  C1 = tex2D(decal, VAR.texCoord     +dx -2.0*dy).xyz;
  half3  A0 = tex2D(decal, VAR.texCoord -2.0*dx     -dy).xyz;
  half3  G0 = tex2D(decal, VAR.texCoord -2.0*dx     +dy).xyz;
  half3  C4 = tex2D(decal, VAR.texCoord +2.0*dx     -dy).xyz;
  half3  I4 = tex2D(decal, VAR.texCoord +2.0*dx     +dy).xyz;
  half3  G5 = tex2D(decal, VAR.texCoord     -dx +2.0*dy).xyz;
  half3  I5 = tex2D(decal, VAR.texCoord     +dx +2.0*dy).xyz;
  half3  B1 = tex2D(decal, VAR.texCoord         -2.0*dy).xyz;
  half3  D0 = tex2D(decal, VAR.texCoord -2.0*dx        ).xyz;
  half3  H5 = tex2D(decal, VAR.texCoord         +2.0*dy).xyz;
  half3  F4 = tex2D(decal, VAR.texCoord +2.0*dx        ).xyz;
 
float4 b = mul( half4x3(B, D, H, F), yuv_weighted );
float4 c = mul( half4x3(C, A, G, I), yuv_weighted );
float4 e = mul( half4x3(E, E, E, E), yuv_weighted );
float4 d = b.yzwx;
float4 f = b.wxyz;
float4 g = c.zwxy;
float4 h = b.zwxy;
float4 i = c.wxyz;
 
float4 i4 = mul( half4x3(I4, C1, A0, G5), yuv_weighted );
float4 i5 = mul( half4x3(I5, C4, A1, G0), yuv_weighted );
float4 h5 = mul( half4x3(H5, F4, B1, D0), yuv_weighted );
float4 f4 = h5.yzwx;
 
  float4 Ao = float4( 1.0, -1.0, -1.0, 1.0 );
  float4 Bo = float4( 1.0,  1.0, -1.0,-1.0 );
  float4 Co = float4( 1.5,  0.5, -0.5, 0.5 );
  float4 Ax = float4( 1.0, -1.0, -1.0, 1.0 );
  float4 Bx = float4( 0.5,  2.0, -0.5,-2.0 );
  float4 Cx = float4( 1.0,  1.0, -0.5, 0.0 );
  float4 Ay = float4( 1.0, -1.0, -1.0, 1.0 );
  float4 By = float4( 2.0,  0.5, -2.0,-0.5 );
  float4 Cy = float4( 2.0,  0.0, -1.0, 0.5 );
 
  // These inequations define the line below which interpolation occurs.
  fx.x      = (Ao.x*fp.y+Bo.x*fp.x > Co.x); 
  fx_left.x = (Ax.x*fp.y+Bx.x*fp.x > Cx.x);
  fx_up.x   = (Ay.x*fp.y+By.x*fp.x > Cy.x);
 
  fx.y      = (Ao.y*fp.y+Bo.y*fp.x > Co.y); 
  fx_left.y = (Ax.y*fp.y+Bx.y*fp.x > Cx.y);
  fx_up.y   = (Ay.y*fp.y+By.y*fp.x > Cy.y);
 
  fx.z      = (Ao.z*fp.y+Bo.z*fp.x > Co.z); 
  fx_left.z = (Ax.z*fp.y+Bx.z*fp.x > Cx.z);
  fx_up.z   = (Ay.z*fp.y+By.z*fp.x > Cy.z);
 
  fx.w      = (Ao.w*fp.y+Bo.w*fp.x > Co.w); 
  fx_left.w = (Ax.w*fp.y+Bx.w*fp.x > Cx.w);
  fx_up.w   = (Ay.w*fp.y+By.w*fp.x > Cy.w);
 
  ir_lv1.x      = ((e.x!=f.x) && (e.x!=h.x));
  ir_lv2_left.x = ((e.x!=g.x) && (d.x!=g.x));
  ir_lv2_up.x   = ((e.x!=c.x) && (b.x!=c.x));
 
  ir_lv1.y      = ((e.y!=f.y) && (e.y!=h.y));
  ir_lv2_left.y = ((e.y!=g.y) && (d.y!=g.y));
  ir_lv2_up.y   = ((e.y!=c.y) && (b.y!=c.y));
 
  ir_lv1.z      = ((e.z!=f.z) && (e.z!=h.z));
  ir_lv2_left.z = ((e.z!=g.z) && (d.z!=g.z));
  ir_lv2_up.z   = ((e.z!=c.z) && (b.z!=c.z));
 
  ir_lv1.w      = ((e.w!=f.w) && (e.w!=h.w));
  ir_lv2_left.w = ((e.w!=g.w) && (d.w!=g.w));
  ir_lv2_up.w   = ((e.w!=c.w) && (b.w!=c.w));
 
  float4 w1 = weighted_distance( e, c, g, i, h5, f4, h, f);
  float4 w2 = weighted_distance( h, d, i5, f, i4, b, e, i);
 
  float4 t1 = (coef*df(f,g));
  float4 t2 = df(h,c);
  float4 t3 = df(f,g);
  float4 t4 = (coef*df(h,c));
 
  edr      = bool4((w1.x<w2.x) && ir_lv1.x, (w1.y<w2.y) && ir_lv1.y, (w1.z<w2.z) && ir_lv1.z, (w1.w<w2.w) && ir_lv1.w);
  edr_left = bool4((t1.x<=t2.x) && ir_lv2_left.x, (t1.y<=t2.y) && ir_lv2_left.y, (t1.z<=t2.z) && ir_lv2_left.z, (t1.w<=t2.w) && ir_lv2_left.w);
  edr_up   = bool4((t4.x<=t3.x) && ir_lv2_up.x, (t4.y<=t3.y) && ir_lv2_up.y, (t4.z<=t3.z) && ir_lv2_up.z, (t4.w<=t3.w) && ir_lv2_up.w);
 
  nc.x = ( edr.x && (fx.x || edr_left.x && fx_left.x || edr_up.x && fx_up.x) );
  nc.y = ( edr.y && (fx.y || edr_left.y && fx_left.y || edr_up.y && fx_up.y) );
  nc.z = ( edr.z && (fx.z || edr_left.z && fx_left.z || edr_up.z && fx_up.z) );
  nc.w = ( edr.w && (fx.w || edr_left.w && fx_left.w || edr_up.w && fx_up.w) );
 
  t1 = df(e,f);
  t2 = df(e,h);
 
  px = bool4(t1.x<=t2.x, t1.y<=t2.y, t1.z<=t2.z, t1.w<=t2.w);
 
  half3 res = nc.x ? px.x ? F : H : nc.y ? px.y ? B : F : nc.z ? px.z ? D : B : nc.w ? px.w ? H : D : E;
 
  return half4(res.x, res.y, res.z, 1.0);
}
 
Thanks!

PARTNERS