vertex shader textures

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: vertex shader textures

Post by Nadro »

Please, look at setActiveTexture method in CD3D9Driver.cpp (line 730 in trunk).
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: vertex shader textures

Post by Granyte »

alright after all that search it would seem it's impossible to use vertex texture without using the DX effect framework
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: vertex shader textures

Post by Granyte »

I think i got vertex texture to work in dx9

I changed the setactivetexture function in CD3D9Driver.cpp at line 752
to this

Code: Select all

bool CD3D9Driver::setActiveTexture(u32 stage, const video::ITexture* texture)
{
    if (CurrentTexture[stage] == texture)
        return true;
 
    if (texture && texture->getDriverType() != EDT_DIRECT3D9)
    {
        os::Printer::log("Fatal Error: Tried to set a texture not owned by this driver.", ELL_ERROR);
        return false;
    }
 
    CurrentTexture[stage] = texture;
 
    if (!texture)
    {
        pID3DDevice->SetTexture(stage, 0);
        pID3DDevice->SetTextureStageState( stage, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE );
    }
    else
    {
        pID3DDevice->SetTexture(stage, ((const CD3D9Texture*)texture)->getDX9Texture());
        if (stage == 0)
        {
            //os::Printer::log("VertexTexture Attempt", ELL_ERROR);
            pID3DDevice->SetTexture(D3DVERTEXTEXTURESAMPLER0,((const CD3D9Texture*)texture)->getDX9Texture()); 
            pID3DDevice->SetTextureStageState( D3DVERTEXTEXTURESAMPLER0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
        }
    }
    return true;
}
now there are 4 texture register in vertexshader but this only send the texture to the first register i could be easily adapted or an other advantage we have in dx9 is that we could send diferent texture to vertex shader then we send to pixel shader but that would require more texture slot in the material
Last edited by Granyte on Fri Sep 28, 2012 12:49 am, edited 1 time in total.
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: vertex shader textures

Post by Granyte »

I updated the patch a little to make the integration with irrlicht mor logical.

But should i make the patch send the for texture to the vertex shader sampler befor submiting a patch?
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: vertex shader textures

Post by Granyte »

I'm now completly sure i got vertex texture to work for dx9.

I Recieved no feedback on how i should build the patch to get it reviewed.

Should i make it send the 4 first texture to the vertex shader? or should it be some other way because in dx9 there iss only 4 vertex texture layer? Should it always send the texture to the vertex shader and the pixel shader or should we sometimes skip the ovr head?
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: vertex shader textures

Post by Mel »

I wouldn't recomend to use the first 4 textures for the vertex shaders, because you can have a shader without a pixel shader, and those are normally needed for the rest of the materials to render properly, Either use the next 4 textures, using an 8 textures setup, or create a new SMaterial derived from the original SMaterial which included those 4 vertex texture stages separated from the pixel shader textures.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: vertex shader textures

Post by Nadro »

I think that we should add information variable to texture layer struct, eg: TextureType, which will be declared as enum (ETT_VERTEX, ETT_PIXEL, ETT_GEOMETRY and combinations of their), so driver will be know how to bind textures properly, or just add to a layer variables like a VertexTexture and GeometryTexture.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: vertex shader textures

Post by Granyte »

But then this would create a diference between the dx9 drivers and the others even the dx11 driver only require binding a texture once to bind it to all shaders. How ever it seem the most eficient way to avoid the over head of rebinding a texture when it's not necesary.
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: vertex shader textures

Post by Nadro »

Hmmm... This is fact. So, it looks like overhead (automatic binding texture to vertex shader too in DX9) is currently the best idea. There is no sense to complicate API just for D3D9.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: vertex shader textures

Post by Granyte »

Code: Select all

 
//! sets transformation
void CD3D9Driver::setTransform(E_TRANSFORMATION_STATE state,
        const core::matrix4& mat)
{
    Transformation3DChanged = true;
 
    switch(state)
    {
    case ETS_VIEW:
        pID3DDevice->SetTransform(D3DTS_VIEW, (D3DMATRIX*)((void*)mat.pointer()));
        break;
    case ETS_WORLD:
        pID3DDevice->SetTransform(D3DTS_WORLD, (D3DMATRIX*)((void*)mat.pointer()));
        break;
    case ETS_PROJECTION:
        pID3DDevice->SetTransform( D3DTS_PROJECTION, (D3DMATRIX*)((void*)mat.pointer()));
        break;
    case ETS_COUNT:
        return;
    default:
        if (state-ETS_TEXTURE_0 < MATERIAL_MAX_TEXTURES)
        {
            if (mat.isIdentity())
                pID3DDevice->SetTextureStageState( state - ETS_TEXTURE_0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE );
            else
            {
                pID3DDevice->SetTextureStageState( state - ETS_TEXTURE_0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
                pID3DDevice->SetTransform((D3DTRANSFORMSTATETYPE)(D3DTS_TEXTURE0+ ( state - ETS_TEXTURE_0 )),
                    (D3DMATRIX*)((void*)mat.pointer()));
                if (state - ETS_TEXTURE_0 <= 4)
                {
                    
                    pID3DDevice->SetTextureStageState( D3DVERTEXTEXTURESAMPLER0+(state - ETS_TEXTURE_0), D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT3 );
                    pID3DDevice->SetTransform((D3DTRANSFORMSTATETYPE)(D3DTS_TEXTURE0+ ( D3DVERTEXTEXTURESAMPLER0)+(state - ETS_TEXTURE_0)),
                    (D3DMATRIX*)((void*)mat.pointer()));
                }
            }
        }
        break;
    }
 
    Matrices[state] = mat;
}
 
 
//! sets the current Texture
bool CD3D9Driver::setActiveTexture(u32 stage, const video::ITexture* texture)
{
    if (CurrentTexture[stage] == texture)
        return true;
 
    if (texture && texture->getDriverType() != EDT_DIRECT3D9)
    {
        os::Printer::log("Fatal Error: Tried to set a texture not owned by this driver.", ELL_ERROR);
        return false;
    }
 
    CurrentTexture[stage] = texture;
 
    if (!texture)
    {
        pID3DDevice->SetTexture(stage, 0);
        pID3DDevice->SetTextureStageState( stage, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE );
    }
    else
    {
        pID3DDevice->SetTexture(stage, ((const CD3D9Texture*)texture)->getDX9Texture());
        if (stage <= 4)
        {
            //os::Printer::log("VertexTexture Attempt", ELL_ERROR);
            pID3DDevice->SetTexture(D3DVERTEXTEXTURESAMPLER0+stage,((const CD3D9Texture*)texture)->getDX9Texture()); 
        }
    }
    return true;
}
 
 
This is the integral code for the vertex texture patch in DX9.

Any sugestion? test result?
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: vertex shader textures

Post by Nadro »

I'll check it tomorrow. If it will be working ok, we'll add it to v1.9 (commits window for new features will be open soon).
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: vertex shader textures

Post by devsh »

in the time you've spent on this so far, you could have:

A) implemented transform feedback in OGL
B) recast a PBO into a VBO and created geometry with pixel shader
C) scored poon
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: vertex shader textures

Post by Granyte »

They have been ready since august and i use them in my aplication but i have yet to recieve any feedback.


PS it took me so long to implement them because the DX driver irrlicht use works wonderfully for a piece of code that was written in the jurassic era.

EDIT if you need an aplication that makes use of it for demonstration i can write one
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: vertex shader textures

Post by Granyte »

After further Testing i noted that in most case the performance is the same but in some other this patch could divide the performance by a factor of 4 .

most case rendering 1 or 2 nodes will not cause any issue but in my project i have to render hundreeds of meshbuffers and uploading the heightmpas for this is causing a lot of over head.

i'm thinking about several way to deal with this and the only one that can be done without modification to the material interphase or texture would be a define in irr compile to determine the amount of texture to upload to the vertex Shader and let the user tweak it to the need of it's aplication
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: vertex shader textures

Post by Granyte »

any chances that this could be integrated in 1.8?

As a two line patch that evens out the functionality of opengl and dx9 i think it should be integrated asap so we can forget about it
Post Reply