Mir3 shadows

Far

tsniffer
Staff member
Developer
May 19, 2003
20,172
30
2,767
540
Hey

I very new at this coding malark, everything seems to be going ok but i have absolutely no idea how to generate the shadows for the players.

Coding in C#, could someone give me the gist of what i should be looking at doing?

Thanks,
 

Coly

LOMCN Developer
Developer
Mar 31, 2005
1,399
33
195
Germany
you use DirectX 3D ? means D3DXSprits ???? If not write the way you bilt the Textures
 

Far

tsniffer
Staff member
Developer
May 19, 2003
20,172
30
2,767
540
yeah im using DirectX 3D.
 

Coly

LOMCN Developer
Developer
Mar 31, 2005
1,399
33
195
Germany
^^ then have fun.... You can it do in a very bad way : made a Render Target Texture, add your Char, dark it and then Rotate it etc.
I have play with this way for a long time and I dislike it... If you made it only for OS up to Vista you can use the old way thats Wemade self use over Direct2D.

!!! the new Direct2D is only working on OS up to Vista and not supportet at XP or Win2k ect.
If I have a bit more time I show your the old way...
 

Far

tsniffer
Staff member
Developer
May 19, 2003
20,172
30
2,767
540
does wemade still use direct2D? as the euro client runs fine in windows 7 without any compatibility issues.

yeah i thought it would probably be something such as dark the image then skew it.

if you have time would appreciate some insight in to the direct2D way :)
 

Coly

LOMCN Developer
Developer
Mar 31, 2005
1,399
33
195
Germany
Direct2D is new system and Wemade use DirectDraw.
Direct2D is a bit like GDI+ but you can use it in C# and VB.net very easy.

Sample :
http://msdn.microsoft.com/en-us/library/dd940321(v=vs.85).aspx

over Direct2D:
http://msdn.microsoft.com/en-us/library/dd370990(v=vs.85).aspx

that what you need to "Skew"
http://msdn.microsoft.com/en-us/library/dd799457(v=VS.85).aspx

Code:
void DemoApp::DrawAndSkewARectangle()
{
    m_pRenderTarget->SetTransform(D2D1::Matrix3x2F::Identity());
    // Create a rectangle.
    D2D1_RECT_F rectangle = D2D1::Rect(126.0f, 301.5f, 186.0f, 361.5f);

    // Draw the outline of the rectangle.
    m_pRenderTarget->DrawRectangle(
        rectangle,
        m_pOriginalShapeBrush,
        1.0f,
        m_pStrokeStyleDash
        );

[B]    // Apply the skew transform to the render target.
    m_pRenderTarget->SetTransform(
        D2D1::Matrix3x2F::Skew(
            45.0f,
            0.0f,
            D2D1::Point2F(126.0f, 301.5f))
        );
[/B]
    // Paint the interior of the rectangle.
    m_pRenderTarget->FillRectangle(rectangle, m_pFillBrush);

    // Draw the outline of the rectangle.
    m_pRenderTarget->DrawRectangle(rectangle, m_pTransformedShapeBrush);

    m_pRenderTarget->SetTransform(D2D1::Matrix3x2F::Identity());

    static const WCHAR szText[] = L"Skew";
    m_pRenderTarget->DrawText(
        szText,
        ARRAYSIZE(szText) - 1,
        m_pTextFormat,
        D2D1::RectF(126.0f, 391.5f, 186.0f, 411.5f),
        m_pTextBrush
        );
}


---------- Post added 15-07-2011 at 10:19 AM ---------- Previous post was 14-07-2011 at 03:57 PM ----------

I have another Idea but I don't have test it atm :

load your texture and change the Color Palette, chang only Color to #010101 or so...
after this skew it and use DrawPrimitive functions to blit it.
 

Coly

LOMCN Developer
Developer
Mar 31, 2005
1,399
33
195
Germany
Yes/no you need for your Shadow only Upper Left and Upper Rigth Coords moving...


OK :
Code:
.... ------------....
... *            *...
..*            *..
.------------.

Not OK :
Code:
            \
     *      \
*             \
\
  \         *
    \ *
 
  • Like
Reactions: Andreas

Far

tsniffer
Staff member
Developer
May 19, 2003
20,172
30
2,767
540
still not got anywhere with this, no idea how to implement skewing in to directx 3d.

also, does the client generate a few of the mob shadows? I've got most of the mobs shadows, but the hen only had 8 images afters its been harvested, the wils don't have any other images for it, yet in official the hen clearly has a shadow.

any suggestions?
 

wbrian

Dedicated Member
Dedicated Member
Aug 31, 2007
193
2
64
I dont know much DirectX but in OpenGL i would do this like that:
take texture and duplicate it, change all nontransparent pixels to black (or 50% alpha black) and skew it.

Atm i dont know how to skew image using pixels:P Maybe this can help http://www.codeproject.com/KB/graphics/Aaform.aspx http://www.antigrain.com/ .

Or u can easy make skew in Direct2D (if u can) and export it to wil if u miss some shadows:D

##### OffTopic #####

Making shadows must be easy, but its faster than read it from wils?

##### EOot #####
 

Far

tsniffer
Staff member
Developer
May 19, 2003
20,172
30
2,767
540
i think just with the amount of different armour texture, its an extra 30-40mb to load, and displaying a black image twice would be much more memory efficient. though saying this, i'm not sure why mobs don't then generate all their own shadows?

i've got the duplicating and turning it to black sorted, i just have no idea how to skew.
 

Coly

LOMCN Developer
Developer
Mar 31, 2005
1,399
33
195
Germany
Cut Alpha out with DirectX:

Code:
  FDevice9.SetRenderState(D3DRS_ALPHABLENDENABLE, iFALSE);
  FDevice9.SetRenderState(D3DRS_ALPHAFUNC       , D3DCMP_NOTEQUAL);
  FDevice9.SetRenderState(D3DRS_ALPHAREF        , 127);
  FDevice9.SetRenderState(D3DRS_ALPHATESTENABLE , iTRUE);

with Render States it is better to read things over State Blocks!!
 

Jamie

LOMCN Developer
Developer
Mar 29, 2003
4,797
299
370
United Kingdom
Code:
        public Bitmap MakeShadow(Stream Stream)
        {
            if (Image == null)
                LoadImage(Stream);
            if (Image == null) return null;

            switch (Header.ShadowType)
            {
                case 48:
                    return null; //Not Implemented
                case 49:
                    Bitmap Temp = new Bitmap(Header.Width + Header.Height / 2, Header.Height);

                    int DestY, DestX;
                    for (int Y = 0; Y < Image.Height; Y++)
                    {
                        if (Y % 2 == 1) continue;
                        DestY = Y / 2 + Temp.Height /2 -3;
                        for (int X = 0; X < Image.Width; X++)
                        {
                            if (Image.GetPixel(X, Y) == Color.FromArgb(255, 0, 255)) continue;
                            DestX = X + (Temp.Height - Y) / 2;
                            Temp.SetPixel(DestX, DestY, Color.Black);
                        }

                    }
                    return Temp;
                default :
                    return null; //Not Implemented
            }

        }

Rough but working example of how I created the shadows.
 

Far

tsniffer
Staff member
Developer
May 19, 2003
20,172
30
2,767
540
im afraid this seems all a little too complex for me at the moment, i've looked up streams and no idea how to they work really. Lost as to how i add this in to your current files. Thanks for sharing though, ill get it figured eventually.
 

Jamie

LOMCN Developer
Developer
Mar 29, 2003
4,797
299
370
United Kingdom
The stream isn't the important veriable here.

Stream was only used to load the image if the image hasn't been loaded.

Skew Code
Code:
case 49:
                    Bitmap Temp = new Bitmap(Image.Width + Image.Height / 2, Image.Height);

                    int DestY, DestX;
                    for (int Y = 0; Y < Image.Height; Y++)
                    {
                        if (Y % 2 == 1) continue;
                        DestY = Y / 2 + Temp.Height /2 -3;
                        for (int X = 0; X < Image.Width; X++)
                        {
                            if (Image.GetPixel(X, Y) == Color.FromArgb(255, 0, 255)) continue;
                            DestX = X + (Temp.Height - Y) / 2;
                            Temp.SetPixel(DestX, DestY, Color.Black);
                        }

                    }
                    return Temp;