Shaders in HGE development thread
  • DaiShivaDaiShiva August 2009
    I decided to try out implementing shader support in hge, I believe it fits with the rest of the interface.

    The patch file assumes a DX9 version of HGE.

    http://www.daishiva.com/other/hge_shader.patch

    How to use a patch file:
    patch -p0 -i hge_shader.patch

    I would assume there is a windows program to do it as well.

    There are three functions that I added to the hge interface:
    1
    2
    3
    HSHADER		CALL	Shader_Create(const char *filename)
    void CALL Shader_Free(HSHADER shader)
    void CALL Gfx_SetShader(HSHADER shader)


    The patch file also modifies tutorial5 to illustrate how to create and use shaders (three are provided, use keys 1-4 to swap between them)

    Hmm, I do believe I left out the Shader_Free call at program shutdown, doh.
  • I do have to ask though - how is someone who can't figure out how to add shader support to HGE (which DaiShiva has shown isn't exactly rocket science) going to figure out how to write and use shaders?
  • JasonPJasonP July 2009
    ProfEclipse,

    That is truly an Unknown quantity sir, full of Unknown variables running in a Unknown system.

    (see what I did there!)

    Seriously though, there are crap loads of HLSL tutorials out there that are pretty informative. Though I can see your point, adding Shader support is like uh, just basically circumventing the fixed function shader that DX9 falls back upon (a cake walk). (Not to dismiss your fine work DaiShiva :D)
  • ProfEclipseProfEclipse August 2009
    Exactly. The two months (based on posts) spent waiting for someone else to add shader support could have been spent adding - and already using - shader support themselves.

    That's the beauty of having the source. You don't have to wait around for someone to do something if you want it sooner.

    If you know how to use shaders from C++, then you should be able to figure out how to add shader support to HGE.

    @Unknown - I don't mean to harp on you. I'm just saying that if you really want a feature added to HGE, you have the source. Try adding it yourself. If you run into trouble, you can always post here and get plenty of help. If you wait on someone else to do it, you might be waiting a very long time.
  • UnknownUnknown August 2009
    Hi everyone,

    wow, so many answers.
    I downloaded the patch, but its just a text file for me ?
    And this line "patch -p0 -i hge_shader.patch ", i think thats for linux or ?

    greetz
    unknown
  • DaiShivaDaiShiva August 2009
    a patch file is a text file

    it contains:
    the file being operated on
    the line number(s) where the changes are made
    whether or not lines are added (+) or deleted (-)

    I use the cygwin 'patch' command. I have not looked for an alternative.

    If you dont want to find a patch utility, you could always make the changes by hand.
  • barneybarney August 2009
    Hey there!
    Akkernight and DaiShiva, i cannot thank you enough for the directx9 and shaders support! It's great, good job!

    But since I'm a bit new to shaders i need some help. I've understood the basics of it but here's my problem.

    I change a lot of my sprites' colors during the game with spr->SetColor function. But when I activate a shader, then the shaders gets the textures color as white. I thought if i could pass an another float4 color for recoloring the main color, it would all be fine, but i couldn't find a solution.

    I just need to pass that float4 data to the HLSL file from c++, is it possible, or are there other solutions as well?
    Thank you!
  • DaiShivaDaiShiva August 2009
    Here is what I'm currently trying out for setting shader values:

    in Shader_Create, make a LPD3DXCONSTANTTABLE, save it in a std::map

    create a new function for the HGE interface:
    1
    2
    3
    4
    5
    6
    7
    8
    void CALL HGE_Impl::Shader_SetValue(HSHADER shader, const char *varName, float value)
    {
    if (shader) {
    LPD3DXCONSTANTTABLE table = shaderConstants[shader];
    D3DXHANDLE handle = table->GetConstantByName(NULL, varName);
    table->SetFloat(pD3DDevice, handle, value);
    }
    }


    What I dont understand is that setting the constant table of one shader, seems to carry over into the other shaders that use the same variable name.
  • barneybarney August 2009
    Instead of storing maps, I think this solution might work better and just edit one shader, gonna try that in a moment:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    void CALL HGE_Impl::Shader_SetValue(HSHADER shader, const char *varName, float value)
    {
    if (CurShader) {
    LPD3DXCONSTANTTABLE table;
    D3DXGetShaderConstantTable(&shader, &table);
    D3DXHANDLE handle = table->GetConstantByName(NULL, varName);
    table->SetFloat(pD3DDevice, handle, value);
    }
    }


    This second line should get only one shaders constant table.
    Thanks again, by the way :)
  • barneybarney August 2009
    Couldn't make it work :( It compiles all fine but it doesn't change the float :(
    Can you show your hlsl file and your Shader_SetValue parameters please DaiShiva?
  • DaiShivaDaiShiva August 2009
    Yeah im no directx expert (is why I use hge) and all the google searches I have assume some kind of working knowledge of it. Not having to store maps to the constant table would be good!


    I'm using the shader files contained in the patch and modifying tutorial5. for testing I'm adding a float parameter to the main function and multiplying it with the returned color value.
  • barneybarney August 2009
    I'm no direct-x expert neither, actually began using it yesterday and got that info with google and msdn:)
    Tried that as well, but doesn't work :(
    Here is my hlsl file
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    sampler2D g_samSrcColor; 
    float4 ps_main(float2 Tex : TEXCOORD0 , float g) : COLOR0
    {
     
    float4 Color;
    Color = tex2D( g_samSrcColor, Tex.xy);
    Color.r =Color.r * g;
    Color.g =Color.g * g;
    Color.b =Color.b * g;
    Color.a =Color.a * g;
    Color += tex2D( g_samSrcColor, Tex.xy+0.001);
    Color += tex2D( g_samSrcColor, Tex.xy+0.002);
    Color += tex2D( g_samSrcColor, Tex.xy+0.003);
    Color += tex2D( g_samSrcColor, Tex.xy+0.004);
    Color += tex2D( g_samSrcColor, Tex.xy+0.005);
    Color += tex2D( g_samSrcColor, Tex.xy+0.006);
    Color += tex2D( g_samSrcColor, Tex.xy+0.007);
    Color += tex2D( g_samSrcColor, Tex.xy+0.008);
    Color += tex2D( g_samSrcColor, Tex.xy+0.009);
    Color += tex2D( g_samSrcColor, Tex.xy+0.010);
    Color = Color / 10;
     
    return Color;
    }

    And my Shader_SetValue func:
    1
    2
    hge->Shader_SetValue(shader1, "g", 3.0f); // Just at the beginning
    // If I put it in RenderFunc game crashes

    What is wrong with this code? Thanks!
  • DaiShivaDaiShiva August 2009


    And my Shader_SetValue func:

    1
    2
    hge->Shader_SetValue(shader1, "g", 3.0f); // Just at the beginning
    // If I put it in RenderFunc game crashes

    What is wrong with this code? Thanks!


    From what I read, variables in the constant table start with a $, so I believe it should be:
    1
    hge->Shader_SetValue(shader1, "$g", 3.0f);
  • DaiShivaDaiShiva August 2009
    Also your line:
    1
    if (CurShader) {


    should be:
    1
    if (shader) {


    (Yes, that is my fault in the original post)
  • DaiShivaDaiShiva August 2009
    This is what ive had to do in order to not store the table
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    void CALL HGE_Impl::Shader_SetValue(HSHADER shader, const char *varName, float value)
    {
    if (shader) {
    LPDIRECT3DPIXELSHADER9 shad = (LPDIRECT3DPIXELSHADER9) shader;
    unsigned char *function;
    unsigned int size;
    LPD3DXCONSTANTTABLE table;
     
    shad->GetFunction(NULL,&size);
    function = new unsigned char[size];
     
    shad->GetFunction(function,&size);
    D3DXGetShaderConstantTable((DWORD*)function,&table);
     
    D3DXHANDLE handle = table->GetConstantByName(NULL, varName);
    table->SetFloat(pD3DDevice, handle, value);
     
    delete [] function;
    }
    }
  • barneybarney August 2009
    Yay, it's working, thanks a lot DaiShiva!! :)
  • WafflesWaffles July 2010
    I'm trying to use pixel shader 3.0. I seem to just get a white screen, but if i tell the shader to display a certain color by manually returning it, it seems to work. Is there some change i would be missing in 3_0? As far as i can tell, its just not passing the Texture Coordinates over, as i can't change the screen by those values.

    My Code in HGE
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    HRESULT result = D3DXCompileShader( file,   //filepath
    size, //length
    NULL, //macro's
    NULL, //includes
    "ps_main", //main function
    "ps_3_0", //shader profile
    D3DXSHADER_ENABLE_BACKWARDS_COMPATIBILITY, //flags
    &code, //compiled operations
    &errors, //errors
    NULL); //constants


    And my Shader
    1
    2
    3
    4
    5
    6
    7
    8
    sampler2D g_samSrcColor; 
     
    float4 ps_main(float2 Tex : TEXCOORD0 ) : COLOR0
    {
    float4 Color = tex2D( g_samSrcColor, Tex.xy);
     
    return Color;
    }
  • A white texture is usually an indication that either the texture didn't load successfully or that the texture isn't set in the shader.
  • WafflesWaffles July 2010
    Well the strange thing is that it isn't always white, its a greenish brownish white, which is just like my texture which it should be loading. And if i render something at the top corner, the entire screen will become that color. Is there a different way to handle texture coordinates with 3.0? Because i'm definitely not getting those.
  • Texture coordinates work the same in all PS versions. There's something else going on there.
  • glbreakerglbreaker July 2010
    I`ll tried to write simple gaussian blur, but picture remains the same (example shaders works fine, my simple box blur also works). Where i`m stupid?
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    sampler2D g_samSrcColor;
     
    float PixelKernel[13] =
    {
    -6,
    -5,
    -4,
    -3,
    -2,
    -1,
    0,
    1,
    2,
    3,
    4,
    5,
    6,
    };
     
    static const float BlurWeights[13] =
    {
    0.002216,
    ...
    bla-bla
    };
     
    float4 ps_main( float2 Tex : TEXCOORD0 ) : COLOR0
    {
    float4 color = 0;
     
    for (int i = 0; i < 13; ++i)
    color += tex2D(g_samSrcColor, Tex + PixelKernel[i]) * BlurWeights[i];
     
    return color;
    }

    :roll:
  • GKoshGKosh September 2010
    Done everything as described: clean HGE 1.8.1 + DaiShiva DX9 patch + shaders patch.

    In tutorial5 got error "Unhandled exception at 0x00000000 in hge_tut05.exe: 0xC0000005: Access violation reading location 0x00000000."
    1
    2
    3
    4
    5
    6
    7
    8
    9
    // Create a distortion mesh
    dis=new hgeDistortionMesh(nCols, nRows);
    dis->SetTexture(tex);
    dis->SetTextureRect(0,0,512,512);
    dis->SetBlendMode(BLEND_COLORADD | BLEND_ALPHABLEND | BLEND_ZWRITE);
    dis->Clear(0xFF000000);
     
    // Load a font
    fnt=new hgeFont("font1.fnt");


    Error comes when "dis->SetTextureRect(0,0,512,512);"
    If I just comment this, same error comes from line "fnt=new hgeFont("font1.fnt");"
  • ProfEclipseProfEclipse September 2010
    That's a null pointer problem. Most likely hgeCreate failed, so there is no valid hge pointer object available.
  • GKoshGKosh September 2010
    Thank you, I got solution :)
  • fantomassfantomass December 2010
    could anyone send to me already patched version? =)
    apparently, my hands are grow from a wrong place :/

    image
  • fantomassfantomass December 2010
    oh, i did it! by hands! x)
  • fantomassfantomass December 2010
    does anyone have problems with render targets?

    image

    standard tutorial04 :/

    Log:


    HGE Started..

    HGE version: 1.80
    Date: 18.12.2010, 04:46:46

    Application: HGE Tutorial 04 - Using render targets
    OS: Windows 5.1.2600
    Memory: 2096236K total, 819344K free

    D3D Driver: ati2dvag.dll
    Description: ATI Radeon HD 3600 Series
    Version: 6.14.10.7008
    Mode: 800 x 600 x X8R8G8B8

    Sound Device: SoundMAX HD Audio
    Sample rate: 44100

    Init done.

    Gfx_BeginScene: Can't set render target
    Gfx_BeginScene: Can't set render target
    ...
    Gfx_BeginScene: Can't set render target

  • ProfEclipseProfEclipse December 2010
    Render target handling changed slightly in DX9. Apparently your updates to DX9 aren't complete.
  • fantomassfantomass December 2010

    Render target handling changed slightly in DX9. Apparently your updates to DX9 aren't complete.



    i just used HGE + hge_dx9.patch (Akkernight) + hge_shader.patch (DaiShiva). i double check the code - all seems to be in order :)

    im not so good at directx. how to fix this targets? :/
  • fantomassfantomass December 2010
    finaly! games can sleep peacefully now! =)

    image

    Patched HGE DX9 with Shaders and no bugs! =)

    next step - extend amount of blending modes! :)
  • DaiShivaDaiShiva December 2010
    Do you have a patch file containing your changes?
  • I'd be more interested in seeing some of the code behind the effect created by that screenshot. I'm assuming its using shaders etc to create the effects in the background.
  • fantomassfantomass December 2010

    Do you have a patch file containing your changes?


    i dont know how to make and use them correctly. i patched code by hands and eyes :)

    i think i just did something wrong when i tried to fix all those warnings in the first time. this build has those two patches + ProfEclipse FPS fix. and i'm not implement blending mods and etc yet

    I'd be more interested in seeing some of the code behind the effect created by that screenshot. I'm assuming its using shaders etc to create the effects in the background.


    no, it's just photoshop. but i think it wouldn't be too difficult. background + middleground + foreground = funny parallax effect. with no shaders =)

    but yeah - is there any way to use several samplers and other external data? for example to make tone mapping, curves correction, dynamic effects which depend from time, etc? =)
  • fantomassfantomass December 2010
    and how many performance impact have using of render targets? :/
  • kijanek6kijanek6 December 2010
    fantomass said:

    I can't run any tutorial (precompiled and compiled on my own), my own project also crashes. It is unable to load any texture. I have WinXP SP3 and GeForce 8600M.
  • fantomassfantomass December 2010


    I can't run any tutorial (precompiled and compiled on my own), my own project also crashes. It is unable to load any texture. I have WinXP SP3 and GeForce 8600M.

    is your dx up to date? try it :/

    also i have had similar problems, because i put original hge.dll in windows/system32 folder and forgot to update it to dx9 version :/
  • kijanek6kijanek6 December 2010
    I downloaded that DLL and it didn't help. :(
  • fantomassfantomass December 2010
    need more info =)
    dll missing, unhandled exeption, acces violation, log, screenshots, etc? )

    did you try to rebuild hge? :/
  • kijanek6kijanek6 December 2010
    I rebuilded HGE, replaced DLL, LIB and headers.
    No errors. Just Texture_Loads returns NULL (0) everytime. Even in precompiled tutorials (I replaced there hge.dll with my compiled one). When I compiled my game with that version (where I don't check whether textures are loaded properly) one sprite was completely brown, another completely white. I'll post screens in a moment, actually I'm thinking about that lighting problem. ;)

    And this version works perfectly fine. But it doesn't contain shaders.
  • fantomassfantomass December 2010
    bum.. :/

    i think it's time to call a rescue team =)
  • I'm adding shaders to that as we speak. I was trying to determine the way the OGL does similar shaders but its taking a bit longer than expected... would you like what I have in its current state?
  • kijanek6kijanek6 December 2010
    [quote="Jonathan.Deceptive"]would you like what I have in its current state?
    Yes, and actually I use this version in my game. I'd love to see various additional functions, which original HGE lacks (for example Gfx_GetClippingArea would be nice). And plugin system you have mentioned in another topic would be totally great.
  • fantomassfantomass December 2010

    I'm adding shaders to that as we speak. I was trying to determine the way the OGL does similar shaders but its taking a bit longer than expected... would you like what I have in its current state?


    as i know DX use hlsl and OGL - glsl o,O

    it's would be difficult to make shaders universal support :/
  • fantomass said:

    as i know DX use hlsl and OGL - glsl o,O



    And there we have it... having support for both types would be ok, it would just mean the shader files would have to be specific for DX or OGL.
  • fantomassfantomass December 2010
    well, it's no harm in trying - keep it up! =)
  • SilvanSilvan April 2011
    Hello folk!

    Maybe I missed it... is there a version of HGE with DX9 support, shader,
    point sprites, lua.. ??

    Silvan
  • kvakvskvakvs September 2011
    Manually applied the Daishiva's patch to my Git repo source tree.

    Now if you select DirectX9 in main CMakeLists.txt config, it will build with shaders support, and also will build tutorial05_shaders to demonstrate how shaders work (press 1,2,3,4 to see effects applied).

    See in this topic http://relishgames.com/forum/viewtopic.php?t=6235
  • ka7713ka7713 November 2012
    hge_impl.h
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
            struct Shader_t
    {
    LPDIRECT3DPIXELSHADER9 Shader;
    LPD3DXCONSTANTTABLE ShaderConstants;
    std::string FileName;
     
    Shader_t()
    {
    Shader = 0;
    ShaderConstants = 0;
    }
     
    ~Shader_t()
    {
    if(Shader)
    Shader->Release();
    }
    };
     
    HSHADER CurShader;
    std::map<HSHADER, std::shared_ptr<Shader_t>> fShaders;
    std::vector<int> fShaderPass;


    graphics.cpp
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    void HGE_Impl::_GfxDone()
    {
    .....
    fShaders.clear();
    .....
    }
     
    std::shared_ptr<char> CALL HGE_Impl::Resource_Text(const char *filename, DWORD *size)
    {
    DWORD _size = 0;
    char *_ptr = static_cast<char*>(Resource_Load(filename, &_size));
     
    if(size)
    {
    *size = _size;
    }
     
    //add NULL.
    if(_ptr)
    {
    _ptr = static_cast<char*>(realloc(_ptr, _size+1));
    _ptr[_size] = 0;
     
    return std::shared_ptr<char>( _ptr, [](char *__ptr){free(__ptr);});
    }
     
    return std::shared_ptr<char>();
    }
     
    HSHADER CALL HGE_Impl::Shader_Create(const char *__filename)
    {
    HSHADER _r = 0;
    auto _it = fShaders.begin();
    for(; _it != fShaders.end(); ++_it)
    {
    if(_it->second->FileName == __filename)
    break;
    }
     
    if(_it == fShaders.end())
    {
    DWORD _size = 0;
    auto _txt = Resource_Text(__filename, &_size); //shader_ptr
     
    if(_size > 0)
    {
    DWORD _shaderFlags = 0;
    LPD3DXBUFFER _errorMsgs;
    LPD3DXBUFFER _code = NULL;
    auto _shader = std::shared_ptr<Shader_t>(new Shader_t());
     
    #ifdef _DEBUG
    _shaderFlags |= D3DXSHADER_SKIPOPTIMIZATION|D3DXSHADER_DEBUG;
    #endif
     
    HRESULT result = D3DXCompileShader(
    _txt.get(), //LPCSTR pSrcData,
    _size, //UINT SrcDataLen,
    NULL, //CONST D3DXMACRO* pDefines,
    NULL, //LPD3DXINCLUDE pInclude,
    "ps_main", //LPCSTR pFunctionName,
    "ps_2_0", //LPCSTR pProfile,
    _shaderFlags, //DWORD Flags,
    &_code, //LPD3DXBUFFER* ppShader,
    &_errorMsgs, //LPD3DXBUFFER* ppErrorMsgs,
    &_shader->ShaderConstants //LPD3DXCONSTANTTABLE* ppConstantTable
    );
     
    if(FAILED(result))
    {
    CHAR* _Info = reinterpret_cast<CHAR*>(_errorMsgs->GetBufferPointer());
    _PostError("Can't create shader\n");
    _PostError(_Info);
    return NULL;
    }
     
    pD3DDevice->CreatePixelShader((DWORD*)_code->GetBufferPointer(), &_shader->Shader);
    _code->Release();
     
    _r = (HSHADER)_shader->Shader;
    _shader->FileName = __filename;
    fShaders[_r] = _shader;
    }
    }
    else
    {
    _r = (HSHADER)_it->second->Shader;
    }
     
    return _r;
    }
     
    void CALL HGE_Impl::Gfx_SetShader(HSHADER __shader)
    {
    if (CurShader != __shader)
    {
    _render_batch();
     
    //reset pass
    for(auto _it=fShaderPass.begin(); _it!=fShaderPass.end(); ++_it)
    {
    if(*_it != 0)
    pD3DDevice->SetTexture(*_it, 0);
    }
    fShaderPass.clear();
     
    CurShader = __shader;
    pD3DDevice->SetPixelShader((LPDIRECT3DPIXELSHADER9)__shader);
    }
    }
     
    void CALL HGE_Impl::Shader_Free(HSHADER __shader)
    {
    fShaders.erase(__shader);
    }
     
    void CALL HGE_Impl::Shader_SetValue(HSHADER __shader, const char *__varName, float __val)
    {
    if(__shader)
    {
    auto _it = fShaders.find(__shader);
    if(_it != fShaders.end())
    {
    D3DXHANDLE handle = _it->second->ShaderConstants->GetConstantByName(NULL, __varName);
    if(handle)
    _it->second->ShaderConstants->SetFloat(pD3DDevice, handle, __val);
    }
    }
    }
     
    void CALL HGE_Impl::Shader_TexturePass(int __pass, HTEXTURE __text)
    {
    pD3DDevice->SetTexture(__pass, (LPDIRECT3DTEXTURE9)__text);
    fShaderPass.push_back(__pass);
    }



    shader_mask.hlsl
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    sampler2D BaseTexture;
    sampler2D MaskTexture;
     
    float MaskLocationX;
    float MaskLocationY;
    float MaskWidth;
    float MaskHeight;
    float BaseTextureLocationX;
    float BaseTextureLocationY;
    float BaseTextureWidth;
    float BaseTextureHeight;
     
    //1~2
    float4 ps_main(float2 texCoord : TEXCOORD0) : COLOR0
    {
    float maskPixelX = texCoord.x * BaseTextureWidth + BaseTextureLocationX;
    float maskPixelY = texCoord.y * BaseTextureHeight + BaseTextureLocationY;
    float maskPixelX_rpos = (texCoord.x-1) * BaseTextureWidth + BaseTextureLocationX;
    float maskPixelY_rpos = (texCoord.y-1) * BaseTextureHeight + BaseTextureLocationY;
    float _a;
     
    float2 maskCoord = float2((maskPixelX - MaskLocationX) / MaskWidth, (maskPixelY - MaskLocationY) / MaskHeight);
    float4 bitMask = tex2D(MaskTexture, maskCoord);
    float4 tex = tex2D(BaseTexture, texCoord);
     
    if(maskPixelY_rpos >= MaskLocationY
    && maskPixelX_rpos >= MaskLocationX
    && maskPixelX_rpos <= MaskWidth + MaskLocationX
    && maskPixelY_rpos <= MaskHeight + MaskLocationY
    )
    {
    _a = bitMask.a;
    }
    else
    {
    _a = 0;
    }
     
    return tex * _a;
    }


    sample
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    float _mask_width = fHGE->Texture_GetWidth(fSpMask.GetTexture(),false);
    float _mask_height = fHGE->Texture_GetHeight(fSpMask.GetTexture(),false);
    float _base_width = fHGE->Texture_GetWidth(fSpBase.GetTexture(), true);
    float _base_height = fHGE->Texture_GetHeight(fSpBase.GetTexture(),true);
     
    fHGE->Gfx_SetShader(fShMask);
    fHGE->Shader_SetValue(fShMask, "MaskWidth", _mask_width);
    fHGE->Shader_SetValue(fShMask, "MaskHeight", _mask_height);
    fHGE->Shader_SetValue(fShMask, "BaseTextureLocationX", 0.f);
    fHGE->Shader_SetValue(fShMask, "BaseTextureLocationY", 0.f);
    fHGE->Shader_SetValue(fShMask, "BaseTextureWidth", _base_width);
    fHGE->Shader_SetValue(fShMask, "BaseTextureHeight", _base_height);
    fHGE->Shader_SetValue(fShMask, "MaskLocationX", 0);
    fHGE->Shader_SetValue(fShMask, "MaskLocationY", 0);
    fHGE->Shader_TexturePass(1, fSpMask.GetTexture());
     
    fSpBase.Render(0,0);
     
    fHGE->Gfx_SetShader(0);
  • SantalLicanSantalLican November 2012
    Please, more information.
    What is this? Be more detailed?
    Ask, feedback, or anything else?
  • fantomassfantomass January 3
    code is little bit clumsy and i don't like that you use stl, but i know what it does and it is pretty cool =D

    i was going to write it by myself for a long time, but i'm too lazy. i'll try to rid of stl and use your code instead :)

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership

In this Discussion

Tagged

Who's Online (0)