XNA Creators Club Online
Page 1 of 1 (8 items)
Sort Posts: Previous Next

Shader issue, 2D index texture to 1D color texture

Last post 08-29-2008 8:08 PM by dimple. 7 replies.
  • 03-21-2007 6:46 AM

    Shader issue, 2D index texture to 1D color texture

    Posted this on the old forums, thought I'd bring it here aswell:

    Ross Ridge wrote:

    You would use the tex2D() intrinsic to sample your 2D Format.L8 texture containing the colour indexes and tex1D() to lookup the index in the 1D "palette" texture. Both intrinsics return 4 element float vector, representing the colour sampled. In the case of sampling from the 2D Format.L8 texture, the unsigned value in the range of 0 to 255 will be scaled to a floating-point value in the range of 0.0 to 1.0 and replicated in all 4 elements (RGBA) of the returned colour.

    Your vertex data would actually have a value from 0 to 255 for each component, assuming you're using the standard 32-bit RGBA diffuse colour values. When passed to your vertex shader the diffuse colour would be converted into a 4 element float vector with a value of 0.0 to 1.0 for each component. Your vertex shader would then presumably output the colour unmodified and after being interpolated it would be passed to your pixel shader. You would normally apply the diffuse colour by multiplying (modulating) it with the colour sampled from the texture.

    btw. D3DFMT_L8 is the unmanaged equivilent of Format.L8

     

    Hi, I'm trying to do this exact thing. The problem I get is when I try to use the index from my 2d texture to look in the 1d texture, it doesn't seem to produce any output. If I pass the index as a color directly I get something so the indexTexture seems to work correctly.
    In the pixel shader:
    index = tex2D(positionToIndex,PSIn.TexCoords);
    color = tex1D(arrayToColor, index);

    I've figured that the problem either is in the sampler:
    Texture indexTexture;
    Texture colorTexture;
    sampler positionToIndex = sampler_state { texture = <indexTexture> ;
    magfilter = POINT; minfilter = POINT; mipfilter=POINT; ADDRESSU = mirror; ADDRESSV = mirror;};
    sampler arrayToColor = sampler_state { texture = <colorTexture> ;
    magfilter = POINT; minfilter = POINT; mipfilter=POINT; ADDRESSU = mirror; ADDRESSV = mirror;};

    Or in ny texture decleration (the texture seems to contain the correct typ of data):
    Texture txtrManaged = new Texture(_device, 255, 1, 1, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed); //colorTexture

    Texture txtrManaged = new Texture(_device, _textureSize, _textureSize, 1, Usage.AutoGenerateMipMap, Format.L8, Pool.Managed); // indexTexture

    Any help would be great, hopefully I've only done some stupid mistake somewhere above.

     

  • 03-22-2007 5:49 AM In reply to

    Re: Shader issue, 2D index texture to 1D color texture

    The idea and the code seems good. Have you try to output from the pixel shader 2d texture sampled value? It might help understand what's wrong with it. Also, you could have a try with Pix because what you need is a debugger in order to understand what's going on...
    ___________________________________________
    BLANC Guillaume - Game Developper - Lyon FRANCE
  • 03-22-2007 8:20 AM In reply to

    Re: Shader issue, 2D index texture to 1D color texture

    Problem solved by borrowing some code for my texture creation (the colorTexture) so my mistake was somewhere in that area.

    Still, I got no clue what I did wrong, but hey, it works now. 

  • 03-22-2007 10:13 AM In reply to

    Re: Shader issue, 2D index texture to 1D color texture

    I'm too curious, now I'd like to know what was wrong. Please tell if some day you find the answer.
    ___________________________________________
    BLANC Guillaume - Game Developper - Lyon FRANCE
  • 03-24-2007 8:06 PM In reply to

    Re: Shader issue, 2D index texture to 1D color texture

    Pretty sure this is where things went wrong, still can't tell you why:

    private void ProduceColorTexture()
            {

                Color _color;

                Texture txtrManaged = new Texture(_device, 255, 1, 1, Usage.None, Format.A8R8G8B8, Pool.Managed);
                uint[,] data = (uint[,])txtrManaged.LockRectangle(typeof(uint), 0, LockFlags.None, 255,1);
                for (int i = 0; i < 255; i++)
                {
                    _color = Color.FromArgb(255, 100, 0, 0);//_colors[i]);
                    data[i, 0] = (uint)_color.ToArgb();
                }

                _colorTexture = txtrManaged;
            }

  • 03-25-2007 4:56 AM In reply to

    Re: Shader issue, 2D index texture to 1D color texture

    Can you write the ColorTexture on the disk (.bmp, ... file) in order to see what it look likes and if it is what you're expecting? It might help understanding

    ___________________________________________
    BLANC Guillaume - Game Developper - Lyon FRANCE
  • 08-29-2008 8:05 PM In reply to

    Re: Shader issue, 2D index texture to 1D color texture

    Hi ,

    i am facing a similar issue that when i sample a texture in my pixel shader i am getting blocks in my output picture.

    I am creating a D3DFMT_L8 texture where i am having difficulties when i sample the texture in my pixel shader.

    HRESULT hRes = D3DXCreateTexture(g_lpDevice, width, height, 0, 0, D3DFMT_L8, D3DPOOL_MANAGED, &g_lpTexture);

    Basically i am loading this texture with Y content from a YV12 frame.

    I am not sure if the sampling is the problem but the output image looks blocky kind of though it is correct.

    I am setting the below flag for the sampler -

    g_lpDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_NONE );

    g_lpDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_NONE );

    g_lpDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE );

    g_lpDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_MIRROR );

    g_lpDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_MIRROR );

    Please if some one has any clue of what i am doing wrong it will be very helpful . I have to make the Y component right before i can proceed.

    HELP

     

  • 08-29-2008 8:08 PM In reply to

    Re: Shader issue, 2D index texture to 1D color texture

    dimple:

    ForGot to mention i am using 2D texture sampling in the pixel shader

    tex2D (input, IN.texcoord1)

    Hi ,

    i am facing a similar issue that when i sample a texture in my pixel shader i am getting blocks in my output picture.

    I am creating a D3DFMT_L8 texture where i am having difficulties when i sample the texture in my pixel shader.

    HRESULT hRes = D3DXCreateTexture(g_lpDevice, width, height, 0, 0, D3DFMT_L8, D3DPOOL_MANAGED, &g_lpTexture);

    Basically i am loading this texture with Y content from a YV12 frame.

    I am not sure if the sampling is the problem but the output image looks blocky kind of though it is correct.

    I am setting the below flag for the sampler -

    g_lpDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_NONE );

    g_lpDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_NONE );

    g_lpDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE );

    g_lpDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_MIRROR );

    g_lpDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_MIRROR );

    Please if some one has any clue of what i am doing wrong it will be very helpful . I have to make the Y component right before i can proceed.

    HELP

     

Page 1 of 1 (8 items) Previous Next