DirectX 10+. Copies of textiles in buffers



  • The texture data should be used as a z-coordinate in the vetertex buffer. How do we arrange a copy from the texture to the buffer or reinterpret the textur like a buffer? MSDN says that using the method ID3D10Device::CopyResource The type of resources should be the same, so the cover-up doesn't work. I am now forced to turn the data back through the CPU, which is not a comilpho in terms of speed. Are there any more effective solutions?



  • Actually, it sounds like an attempt to draw a landscape, but since it's not explicitly stated, we'll assume everything.

    Now, if you really want to use the textur as a hatemap in landscape drawing, as stated above, you can just read the textur in the top shepherd. It is assumed that the grid has already been formed in advance, and the textur coordinates for each top are already computed. It's only right to announce resources. If there is only one numerical component per picsel in the map (i.e. one colour channel, e.g. R), the texture resource should have a format:

    DXGI_FORMAT_R16_FLOAT или DXGI_FORMAT_R32_FLOAT 
    

    And the shepherd should be declared as

    Texture2D<float>            Texture : register(t0);
    

    Then read from the texture the data in the top shepherd can be as follows:

    float h = Texture.SampleLevel(Sampler, Tex,0);
    

    Please note that: 1. The resource format has at the end the word _FLOAT (these are still DXGI_FORMAT_R16_UNORM, which provide normalized data, i.e. variables only within 0.1). 2. There is also a key word in the resource announcement in the shepherd that resource has not normalized data inside. It's logical for a map of height representing a vertical shift of the top in the world's coordinates. 3. To get data from the texture, the function of SampleLevel is because in the top shepherd you can't just use Sample - the system doesn't know what criterion to choose the Mip level automatically and you'll get a mistake "error X4532: cannot map expression to vs__ instruction set."

    Now, with regard to the same reading of the textur in the top shepherd, but when we are not able to access the textur coordinates and we need to get it from the texture, depending on the order number of the top in the buffer.

    Here. https://msdn.microsoft.com/ru-ru/library/windows/desktop/bb509647(v=vs.85).aspx You can find a description of predetermined constants and system keywords that provide access to different system values, and we are particularly interested in SV_VertexID. This system constant shall be declared in the entrance data to the top shepherd as well as, as you declare the entrance coordinates of the top:

    struct VS__INPUT
    {
        float4 Pos          : POSITION;
        uint   VertexID     : SV_VertexID;
    };
    

    It's the number of the top that came to the conway, starting with 0. On it, we can easily determine which top of the buffer is now being processed and thus obtain the necessary reference for reading from the texture.

    Example of use https://msdn.microsoft.com/ru-ru/library/windows/desktop/bb232912(v=vs.85).aspx ♪


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2