[Source] Multi-Sample Anti-Aliasing in Flyff

Page 1 of 2 12 LastLast
Results 1 to 25 of 47
  1. #1
    Elite Member Jcdacez is offline
    Member +Rank
    Mar 2010 Join Date
    EnglandLocation
    185Posts

    [Source] Multi-Sample Anti-Aliasing in Flyff

    Well i got shown this on another site but it wasnt working correctly
    (if your card couldnt support AA the client would jus crash)

    UPDATE (01/02/2012) : The Code Below has been Improved, Thanks to nabby59 and ShadowDragon42 for the research/coding help with this!

    SO i decided to release a code i did which so far, seems to be working fine.

    For those who dont know, Anti-aliasing, in a nutshell takes all those "Jagged" looking edges on models, and smooths them out some, giving a cleaner look ingame, obviously the higher the multiplied sampler, the better the quality.

    What the code itself does, is checks to see if your graphics card is compatible with the anti aliasing and checks what multisample level you can use on your graphics hardware for Flyff, and sets it to that.

    To add this....


    in d3dapp.cpp find:

    Code:
    #ifdef __XUZHU
     #if 0
        // Create the device
        hr = m_pD3D->CreateDevice( m_pD3D->GetAdapterCount()-1, D3DDEVTYPE_REF,
    		m_hWndFocus, behaviorFlags, &m_d3dpp,
    		&m_pd3dDevice );
    under the SECOND #else after this replace:

    Code:
    	hr = m_pD3D->CreateDevice( m_d3dSettings.AdapterOrdinal(), pDeviceInfo->DevType,
    		m_hWndFocus, behaviorFlags, &m_d3dpp,
    		&m_pd3dDevice );

    with this:

    Code:
    	DWORD MSQuality = 0;
    	D3DMULTISAMPLE_TYPE MSType = D3DMULTISAMPLE_NONE;
    	if( SUCCEEDED( m_pD3D->CheckDeviceMultiSampleType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_A8R8G8B8, TRUE, D3DMULTISAMPLE_8_SAMPLES, &MSQuality) ))
    		MSType = D3DMULTISAMPLE_8_SAMPLES;
    	else if( SUCCEEDED( m_pD3D->CheckDeviceMultiSampleType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_A8R8G8B8, TRUE, D3DMULTISAMPLE_4_SAMPLES, &MSQuality) ))
    		MSType = D3DMULTISAMPLE_4_SAMPLES;
    	else if( SUCCEEDED( m_pD3D->CheckDeviceMultiSampleType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_A8R8G8B8, TRUE, D3DMULTISAMPLE_2_SAMPLES, &MSQuality) ))
    		MSType = D3DMULTISAMPLE_2_SAMPLES;
    	int MSQ = MSQuality - 1;
    
    	// --------------------------------------------------------------
    	// ... Below Will Display a message box on Start-Up with the AntiAliasing 
    	// ... Multisample level Your Graphics card can handle .
    	// ---------------------------------------------------------------
    	//	char msaaText[128];
    	//	sprintf( msaaText, "Multi Sample Type = x%d", MSType );
    	//	MessageBox( NULL, msaaText, "MSAA AMOUNT", MB_OK );
    	// -------------------------------------------------------------------
    
    	m_d3dpp.SwapEffect      = D3DSWAPEFFECT_DISCARD;
    	m_d3dpp.MultiSampleType = MSType;
    	m_d3dpp.MultiSampleQuality = MSQ;
    	m_d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    	m_d3dpp.EnableAutoDepthStencil = TRUE;
    	m_d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
    	m_d3dpp.Flags = 0;
    	m_d3dpp.FullScreen_RefreshRateInHz      = D3DPRESENT_RATE_DEFAULT;
    	m_d3dpp.PresentationInterval                  = D3DPRESENT_INTERVAL_DEFAULT;
    
    	hr = m_pD3D->CreateDevice( m_d3dSettings.AdapterOrdinal(), pDeviceInfo->DevType,
    		m_hWndFocus, behaviorFlags, &m_d3dpp,
    		&m_pd3dDevice );
    
    
    	m_pd3dDevice->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE);
    	m_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); 
    	m_pd3dDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL); 
    	m_pd3dDevice->SetRenderState(D3DRS_ALPHAREF, (DWORD)8); 
    	m_pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);

    I hope this helps.
    Last edited by Jcdacez; 01-02-12 at 05:08 AM.


  2. #2
    Moderator DriftCity is offline
    ModeratorRank
    Oct 2009 Join Date
    /NapTown/Location
    619Posts

    Re: [Source] Multi-Sample Anti-Aliasing in Flyff

    Wow, Amazing that this tiny codes can create anti aliasing.

  3. #3
    0xC0FFEE spikensbror is offline
    Grand MasterRank
    Dec 2006 Join Date
    SwedenLocation
    1,855Posts

    Re: [Source] Multi-Sample Anti-Aliasing in Flyff

    This is probably the most hacky and stupid implementation ever.
    Just implement it natively where it loads the settings instead of blindly overwriting all determined settings.

    This could have been accomplished with 1 changed line and 1 added line.

  4. #4
    Elite Member Jcdacez is offline
    Member +Rank
    Mar 2010 Join Date
    EnglandLocation
    185Posts

    Re: [Source] Multi-Sample Anti-Aliasing in Flyff

    Quote Originally Posted by spikensbror View Post
    This is probably the most hacky and stupid implementation ever.
    Just implement it natively where it loads the settings instead of blindly overwriting all determined settings.

    This could have been accomplished with 1 changed line and 1 added line.
    I didn't make the code on the anti-alias itself so I'm not even going to regard your comment on the implementation strategy on a personal level

    Fact of the matter is, as far as i can see, what others can see, it works, it adds multiple sampling levels, it detects if u can handle such a level of multisampling or not.

    Yeah its not the BEST method, but do u see another method on this page, better yet, if you have a 1 line change, where is the link to the release?....

    Exactly...There wasn't an MSAA code on this site, this one does the job, so i posted it...

    I'm not swinging my E-Dick to the public im jus posting something people want on their server, I'm NOT a fantastic coder myself, I'm a learner like most, i can do Basics and i DIDN'T know this and MAYBE this will branch an understanding in this level of code to SOME extent that more advanced things in terms of Anti-aliasing, HDR, or anything of that nature, processing/post-processing to others too.

    Complain that the community sucks cos no one releases, yet be over critical of a basic release that helps =\...Logic much.

  5. #5
    Moderator DriftCity is offline
    ModeratorRank
    Oct 2009 Join Date
    /NapTown/Location
    619Posts

    Re: [Source] Multi-Sample Anti-Aliasing in Flyff

    I know who made it, The most epic flyff developer in history! Not gonna name him XD

  6. #6
    Elite Member Jcdacez is offline
    Member +Rank
    Mar 2010 Join Date
    EnglandLocation
    185Posts

    Re: [Source] Multi-Sample Anti-Aliasing in Flyff

    Quote Originally Posted by driftcity View Post
    I know who made it, The most epic flyff developer in history! Not gonna name him XD
    yeah but saying the most epic flyff developer is like saying The Worlds Fastest Slug :P i jk

  7. #7
    0xC0FFEE spikensbror is offline
    Grand MasterRank
    Dec 2006 Join Date
    SwedenLocation
    1,855Posts

    Re: [Source] Multi-Sample Anti-Aliasing in Flyff

    Quote Originally Posted by Jcdacez View Post
    Complain that the community sucks cos no one releases, yet be over critical of a basic release that helps =\...Logic much.
    I gave up on the community a long time ago bro.

  8. #8
    Elite Member CatDMG is offline
    Member +Rank
    May 2005 Join Date
    UALocation
    202Posts

    Re: [Source] Multi-Sample Anti-Aliasing in Flyff

    what's the point of bullying here then?
    This guys released something that can find its use.

  9. #9
    0xC0FFEE spikensbror is offline
    Grand MasterRank
    Dec 2006 Join Date
    SwedenLocation
    1,855Posts

    Re: [Source] Multi-Sample Anti-Aliasing in Flyff

    Giving input on the release.
    As I said, this overwrites a ton of settings which is predetermined by the d3dApp.

  10. #10
    Grand Master kolelolx is offline
    Grand MasterRank
    Oct 2010 Join Date
    577Posts

    Re: [Source] Multi-Sample Anti-Aliasing in Flyff

    True, no matter how simple or whatever you want to say, it makes the game look a lot nicer and I haven't seen you make anything better.
    Haters gonna hate, Josh.
    Posted via Mobile Device

  11. #11
    Sorcerer Supreme Max98 is offline
    Member +Rank
    Nov 2011 Join Date
    285Posts

    Re: [Source] Multi-Sample Anti-Aliasing in Flyff

    don't you think it make the game more lagy?

  12. #12
    Grand Master Shinija is offline
    Grand MasterRank
    Oct 2007 Join Date
    UKLocation
    684Posts

    Re: [Source] Multi-Sample Anti-Aliasing in Flyff

    Quote Originally Posted by kolelolx View Post
    True, no matter how simple or whatever you want to say, it makes the game look a lot nicer and I haven't seen you make anything better.
    Haters gonna hate, Josh.
    Posted via Mobile Device
    His merely remarking that there are better ways to do this and this is not the most efficient way, retard.

  13. #13
    Flyff Developer ShadowDragon is offline
    Grand MasterRank
    Apr 2009 Join Date
    1,915Posts

    Re: [Source] Multi-Sample Anti-Aliasing in Flyff

    Quote Originally Posted by Max98 View Post
    don't you think it make the game more lagy?
    it's only more laggy if you're computer isn't good enough to handle it

  14. #14
    Sorcerer Supreme Langstra is offline
    Member +Rank
    Feb 2011 Join Date
    Among heroesLocation
    479Posts

    Re: [Source] Multi-Sample Anti-Aliasing in Flyff

    Well in that case I do not think that this is a good implementation. There should be an option to enable or disable AA. Even though most computers nowadays should be able to handle it a lot of players run other things next to flyff and rather have settings a little it lower so it runs more smooth.
    I am not implying that there should be a spoon fed tutorial on how to do this, just merely saying that this is not the best implementation and how I think it should be done.

  15. #15
    Flyff Developer ShadowDragon is offline
    Grand MasterRank
    Apr 2009 Join Date
    1,915Posts

    Re: [Source] Multi-Sample Anti-Aliasing in Flyff

    Quote Originally Posted by Langstra View Post
    Well in that case I do not think that this is a good implementation. There should be an option to enable or disable AA. Even though most computers nowadays should be able to handle it a lot of players run other things next to flyff and rather have settings a little it lower so it runs more smooth.
    I am not implying that there should be a spoon fed tutorial on how to do this, just merely saying that this is not the best implementation and how I think it should be done.
    When I learned enough about DirectX, I was planning to do exactly that, adding the new options into the patcher. I just sorta got bored of reading DirectX books lol so I haven't gotten around to finishing that.

    To do it correctly, you should check if their device is capable of the setting (antialiasing, anisotropic filtering, etc.), then either enable or disable the option for it. If they select it, it's just as simple as spiken said to implement: 1 changed line and 1 added line. (I already know about the functions, I just never got through the first part I said xD)

  16. #16
    Grand Master kolelolx is offline
    Grand MasterRank
    Oct 2010 Join Date
    577Posts

    Re: [Source] Multi-Sample Anti-Aliasing in Flyff

    This is only the bit for the actual anti aliasing, its not hard to figure out how to stop the lag.
    Posted via Mobile Device

  17. #17
    Elite Member Jcdacez is offline
    Member +Rank
    Mar 2010 Join Date
    EnglandLocation
    185Posts

    Re: [Source] Multi-Sample Anti-Aliasing in Flyff

    Quote Originally Posted by Langstra View Post
    Well in that case I do not think that this is a good implementation. There should be an option to enable or disable AA. Even though most computers nowadays should be able to handle it a lot of players run other things next to flyff and rather have settings a little it lower so it runs more smooth.
    I am not implying that there should be a spoon fed tutorial on how to do this, just merely saying that this is not the best implementation and how I think it should be done.
    Guys please read the code, the code CHECKS if your computer can handle the Anti aliasing, and if it can it sees then how much Multisampling u can have...

    So it will ALWAYS go to an anti alias level your graphics card can support, yes a neuz.ini saved option via patcher r ingame optinos would be a better choice, but for time's sake and lack or knowledge sake, i wanted to get the working code released before everyone used the original and crashes happened everywhere xD.

    Maybe there are more "fail safes" you can add to this code like an "if(SUCCESS...." and "if(FAILED [then revert to no AA]"
    altho i believe the code does that already in a a way as it will set to 0 multi sampling if you cant handle anything over..

    so in a nutshell, yeah it shaved like 5 FPS off my game (maybe not even that) but its totally adaptable to your graphics card so u wont have an issue where someone can't play if their card doesnt support it, it'll jus go back to regular.

  18. #18
    Flyff Developer ShadowDragon is offline
    Grand MasterRank
    Apr 2009 Join Date
    1,915Posts

    Re: [Source] Multi-Sample Anti-Aliasing in Flyff

    Ok, I read the coding. What it's doing it now, is setting it to the max antialiasing your card can handle, no matter what. In my opinion, 4x AA or 8x AA is the most you'll need. Any higher, and you hardly notice a difference, unless you're pressing your face to the monitor to examine each pixel.

  19. #19
    Elite Member Jcdacez is offline
    Member +Rank
    Mar 2010 Join Date
    EnglandLocation
    185Posts

    Re: [Source] Multi-Sample Anti-Aliasing in Flyff

    Quote Originally Posted by ShadowDragon42 View Post
    Ok, I read the coding. What it's doing it now, is setting it to the max antialiasing your card can handle, no matter what. In my opinion, 4x AA or 8x AA is the most you'll need. Any higher, and you hardly notice a difference, unless you're pressing your face to the monitor to examine each pixel.
    You have a valid point.
    So i very quickly scrambled this togethor, agian im sure there are WAY better methods to do this, but below SHOULD (havent tested it) detect the value your card can take, then it sets it to a sensible value based on what you can support, altho frankly i do not see the point as im not sure many people will get more than x8 anyway.

    My computer is pretty good to say the least, and for some reason on flyff it only gets x2

    Code:
    	DWORD MSQuality = 0;
    	m_pD3D->CheckDeviceMultiSampleType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_A8R8G8B8, TRUE, D3DMULTISAMPLE_NONMASKABLE, &MSQuality);
    	int MSQ = MSQuality - 1;
    
    if (MSQ >= 8) // if your card can handle x8 or more.
    {
    	m_d3dpp.SwapEffect      = D3DSWAPEFFECT_DISCARD;
    	m_d3dpp.MultiSampleType = D3DMULTISAMPLE_NONMASKABLE;
    	m_d3dpp.MultiSampleQuality = 8; 
    	m_d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    	m_d3dpp.EnableAutoDepthStencil = TRUE;
    	m_d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
    	m_d3dpp.Flags = 0;
    	m_d3dpp.FullScreen_RefreshRateInHz      = D3DPRESENT_RATE_DEFAULT;
    	m_d3dpp.PresentationInterval                  = D3DPRESENT_INTERVAL_DEFAULT;
    
    	hr = m_pD3D->CreateDevice( m_d3dSettings.AdapterOrdinal(), pDeviceInfo->DevType,
    		m_hWndFocus, behaviorFlags, &m_d3dpp,
    		&m_pd3dDevice );
    
    
    	m_pd3dDevice->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE);
    	m_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); 
    	m_pd3dDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL); 
    	m_pd3dDevice->SetRenderState(D3DRS_ALPHAREF, (DWORD)8); 
    	m_pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
    }
    else if (MSQ >= 4 && MSQ < 8) // if your card can handle x4-x6
    {
    	m_d3dpp.SwapEffect      = D3DSWAPEFFECT_DISCARD;
    	m_d3dpp.MultiSampleType = D3DMULTISAMPLE_NONMASKABLE;
    	m_d3dpp.MultiSampleQuality = 4;
    	m_d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    	m_d3dpp.EnableAutoDepthStencil = TRUE;
    	m_d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
    	m_d3dpp.Flags = 0;
    	m_d3dpp.FullScreen_RefreshRateInHz      = D3DPRESENT_RATE_DEFAULT;
    	m_d3dpp.PresentationInterval                  = D3DPRESENT_INTERVAL_DEFAULT;
    
    	hr = m_pD3D->CreateDevice( m_d3dSettings.AdapterOrdinal(), pDeviceInfo->DevType,
    		m_hWndFocus, behaviorFlags, &m_d3dpp,
    		&m_pd3dDevice );
    
    
    	m_pd3dDevice->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE);
    	m_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); 
    	m_pd3dDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL); 
    	m_pd3dDevice->SetRenderState(D3DRS_ALPHAREF, (DWORD)8); 
    	m_pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
    
    }
    
    //If your card cannot handle any of the above remove AA.
    else{
    	hr = m_pD3D->CreateDevice( m_d3dSettings.AdapterOrdinal(), pDeviceInfo->DevType,
    		m_hWndFocus, behaviorFlags, &m_d3dpp,
    		&m_pd3dDevice );
    
    }
    Last edited by Jcdacez; 29-01-12 at 06:27 AM.

  20. #20
    Newbie wewsir is offline
    MemberRank
    Jan 2012 Join Date
    3Posts

    Re: [Source] Multi-Sample Anti-Aliasing in Flyff

    Quote Originally Posted by Jcdacez View Post
    Code:
    	m_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
    why you sett this?????
    bad idea

  21. #21
    Elite Member Jcdacez is offline
    Member +Rank
    Mar 2010 Join Date
    EnglandLocation
    185Posts

    Re: [Source] Multi-Sample Anti-Aliasing in Flyff

    Quote Originally Posted by wewsir View Post
    why you sett this?????
    bad idea
    xD funny little dude, you lost your thread and u come to troll me now??

    xD if you have a valid input then you'd say why this is a bad idea and add some explanation,

    You better not start stalking my threads jus to thumbs me down, screb xD

  22. #22
    Newbie wewsir is offline
    MemberRank
    Jan 2012 Join Date
    3Posts

    Re: [Source] Multi-Sample Anti-Aliasing in Flyff

    Quote Originally Posted by Jcdacez View Post
    xD if you have a valid input then you'd say why this is a bad idea and add some explanation,
    is bad idea cuz u cull both side ??
    render twice many, is stupid!

  23. #23
    Flyff Developer ShadowDragon is offline
    Grand MasterRank
    Apr 2009 Join Date
    1,915Posts

    Re: [Source] Multi-Sample Anti-Aliasing in Flyff

    I actually hadn't noticed that before, so I'll explain it, cause wewsir is actually correct. Setting the Culling mode to none, forces it to render both sides of everything, even if you can't see it. For example, rendering the bottom side of the floor that isn't visible.

  24. #24
    Elite Member Jcdacez is offline
    Member +Rank
    Mar 2010 Join Date
    EnglandLocation
    185Posts

    Re: [Source] Multi-Sample Anti-Aliasing in Flyff

    Quote Originally Posted by ShadowDragon42 View Post
    I actually hadn't noticed that before, so I'll explain it, cause wewsir is actually correct. Setting the Culling mode to none, forces it to render both sides of everything, even if you can't see it. For example, rendering the bottom side of the floor that isn't visible.
    ok that makes more sense, but to be fair i did not add that part of the code as i stated in the beginning :P.

    Yeah Culling basically unloads shit off the camera view right? great thanks shadowdragon, i'll edit my posts :P

  25. #25
    Flyff Developer ShadowDragon is offline
    Grand MasterRank
    Apr 2009 Join Date
    1,915Posts

    Re: [Source] Multi-Sample Anti-Aliasing in Flyff

    Quote Originally Posted by Jcdacez View Post
    ok that makes more sense, but to be fair i did not add that part of the code as i stated in the beginning :P.

    Yeah Culling basically unloads shit off the camera view right? great thanks shadowdragon, i'll edit my posts :P
    Yeah, I figured you didn't add it, cause it's a common sense thing that would only be done in certain situations.



Page 1 of 2 12 LastLast

Advertisement