noob shader question

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • noob shader question

      hi guys,

      I have a vertexshader-input defined like this:

      Source Code

      1. struct VS_IN {
      2. float3 pos : POSITION;
      3. float2 uv : TEXCOORD0;
      4. float4 fillColor : COLOR0;
      5. };


      in the struct the type for the color is specified as float4, which afaik is a float[4]-vector. but in the flexible-vertex-format I've specified a diffuse component which is a uint32-type?!?

      D3DFVF_DIFFUSE - DWORD in ARGB order.

      what for an type is it really? or is it converted internally by the directx-runtime? when I write to the vertexbuffer I fill the color as a dword.

      thanks :)
    • Colors are defined as float4's in RGBA format where each value has a range of 0 - 1. So, if you have a diffuse of 0xffffffff (white), it will come through as (1.0,1.0,1.0,1.0).

      -Rez
    • yeah, but who's doing the conversion? four floats are much more than one uint if you count the bytes, so it would be much better for the bus if the card would convert it.
      (and sadly it means I can't use the colors for parameters for the shader because they're getting converted and I would bet not every card convert it to the exact same float-value)
    • I honestly don't know who does the conversion; I believe it happens on the driver side but I'm not sure if it's a CPU or GPU task. My understanding is that the conversion happens whether or not you use a shader because that's how the video card treats color (as intensities of the four channels).

      Personally, I prefer to work with four floats because there's no conversion necessary if I'm using 16-bit vs 32-bit color; the shader will work either way. It also tends to make the math easier since the range is essentially a ratio.

      You're correct that using the diffuse color as an input for a logical branch wouldn't be practical. Have you looked into the shader API for getting at the contants table? It allows you to set variables in the shader which is the preferred way to parametrize your shader.

      Another thing to keep in mind is that video cards tend to think in floating point numbers, so on many video cards an int may be slower because it would have to be emulated.

      -Rez
    • Dunno if you are still looking at this or not, but generally the reason you call SetVertexFormat is to tell the GPU how to interpret the data in your vertex buffer. It stays in that format while being fetched directly to the hardware (so packing them tightly results in better memory bandwidth), which implies the GPU itself does the conversion of types into the shader's desired vectorized formats.

      In brief, an ARGB color packed into a uint32 will be converted to float4 by the GPU internally before presenting to your vertex shader.

      JH