Vertex textures under SM 3.0

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Vertex textures under SM 3.0

Post by robmar »

Anyone got this working? I'm querying away with d3dusage_query_vertextexture but no textures seem to be supported.

I'll post some code if I get anywhere...
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Vertex textures under SM 3.0

Post by Mel »

I thought the vertex textures were currently supported, at least, they seem to be supported on GL, on D3D9 i don't know though, but i think some texture stage is set for the vertex shaders. I'm not sure.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Vertex textures under SM 3.0

Post by robmar »

I had to pass the current format correctly, and now all the textures indicate as supported for vertex textures.

But I have another problem says Grantye, that Vertex textures is only supported on 1.8.1, and I'm using 1.7.3

Any idea what I need to patch to get the texture data connected, as I'm getting zero back from tex2dlod, using SM 3.0.
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Vertex textures under SM 3.0

Post by Mel »

You better get a SVN client, such as RapidSVN and download the latest SVN version, the current release is outdated compared to it.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Vertex textures under SM 3.0

Post by robmar »

I saw in the 1.8.1 driver that the first 4 textures are being registered with the vertextexture flag, so I added that, but I'm not getting the correct texture values... so still investigating
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Vertex textures under SM 3.0

Post by robmar »

The download link for the latest SVN is broken. Is there a new link?
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: Vertex textures under SM 3.0

Post by Granyte »

How are you trying to read texture from the vertex shader?
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Vertex textures under SM 3.0

Post by robmar »

The recommended method, tex2dlod. Is it necessary also to use D3DVERTEXTEXTURESAMPLER0-3 with SetSamplerState? I saw a note saying that it could also be used with that function.

Code: Select all

 
 
// HLSL Vertex texture shader
 
// Uses single texture as colormap and heightmap - test only
 
float4x4 mWorld, mView, mProj;
float   fMag;
 
texture cmap;       // This texture will point to the heightmap
sampler colorMap = sampler_state      // This sampler will be used to read (sample) the heightmap
{
        Texture = <cmap>;
        MipFilter = Point;
        MinFilter = Point;
        MagFilter = Point;
        AddressU = Clamp;
        AddressV = Clamp;
};
 
struct VS_INPUT
{
    float4 position : POSITION;
    float2 TexCoord : TEXCOORD0;
};
 
struct VS_OUTPUT
{
    float4 Position : POSITION;
    float2 TexCoord : TEXCOORD0;    
};
 
struct PS_OUTPUT
{
    float4 color:COLOR;
};
 
VS_OUTPUT mainVS(VS_INPUT In)
{
    VS_OUTPUT Out;
 
    float4x4 viewProj = mul(mView, mProj);                         //compute View * Projection matrix
    float4x4 worldViewProj = mul(mWorld, viewProj);                //finally, compute the World * View * Projection matrix
 
    // this instruction reads from the heightmap, the value at the corresponding texture coordinate
    // Note: we selected level 0 for the mipmap parameter of tex2Dlod, since we want to read data exactly as it appears in the heightmap
 
    float height = tex2Dlod ( colorMap, float4(In.TexCoord.xy, 0, 0 ) );
 
    // with the newly read height, we compute the new value of the Y coordinate
    // we multiply the height, which is in the (0,1) range by a value representing the Maximum Height of the Terrain
 
    In.position.y = height * fMag;   // Does not work!  Just shifts the cube up and down along Y-axis
                   
    Out.Position = mul( In.position, worldViewProj);
 
    Out.TexCoord = In.TexCoord; 
 
    return Out;
}
 
PS_OUTPUT mainPS(VS_OUTPUT In)
{   
    PS_OUTPUT Out;
 
    float3 rgb = tex2D(colorMap, In.TexCoord).rgb;
 
    float g16 = (rgb.r*31.0)*2048 + (rgb.g*63.0)*64 + (rgb.b*31.0);  // Convert RGB565 (stored as int 16 across RGB) to single greyscale int value per pixel
 
    // ECF_R5G6B5 grayscale
    float f16 = g16 / 32768.0;
 
    Out.color = float4( f16, f16, f16, 1.0 );       // Grey scale (works!)
 
    return Out;
}
 
 
technique RGB565Shader
{
  pass Pass1
  {
    VertexShader = compile vs_3_0 mainVS();
    PixelShader = compile ps_3_0 mainPS();
  }
}
 
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Vertex textures under SM 3.0

Post by robmar »

Displacement Mapping (Direct3D 9) https://msdn.microsoft.com/en-us/librar ... s.85).aspx

Displacement maps are similar to texture maps but are accessed by the vertex engine.

Block Diagram

An additional sampler stage is present in the early part of the vertex pipe, as shown in the following diagram, which can sample a displacement map to provide vertex displacement data.

The displacement map sampler state can be set by the SetSamplerState using stage number 256, which is a new stage number. The displacement map texture is set by SetTexture.

The map can be presampled or not, which means that it can be ordered in a way that enables the lookup of the displacement values without filtering.
•Displacement maps are analogous to texture maps but are accessed by the vertex engine.
•An additional sampler stage is present in the early part of the vertex pipe that can sample a displacement map. This stage is accessed by the usual SetSamplerState API but the stage number is D3DDMAPSAMPLER = 256.
•The displacement map sampler state can be set by the SetSamplerState(D3DDMAPSAMPLER, ...) API.
•The displacement map texture is set by the SetTexture(D3DDMAPSAMPLER, texture) API.
•The map can be pre-sampled or not. This means that it can be ordered in a particular way that enables the lookup of the displacement values without filtering.
•The changes in the declaration structure allow the specification of the texture coordinate used to look up the texture map. For example, Stream0, Offset, FLOAT2, LOOKUP, Displacement_value. This tells the tessellator to use the 2D float vector in stream0 at a certain offset as a texture coordinate to look up the displacement map and associate the Displacement_value usage semantic to it. The vertex shader declaration would contain a line similar to {dcl_texture0, v0} indicating that the texture0 semantic is to be associated with the v0 input register. The displacement value looked up is copied into input register v0.
•There is a special type of displacement mapping, when the texture map is pre-sampled. Sequential index of generated vertices is used as a texture coordinate to a texture map. For example, 0,0,(D3DDECLTYPE)0,D3DDECLMETHOD_LOOKUPPRESAMPLED, Usage, UsageIndex.
•The output of the lookup is 4 floats.
•Displacement mapping is supported only with N-patches.
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: Vertex textures under SM 3.0

Post by Granyte »

Have you tried running it in 1.8.3 ? or in the latest trunk?
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Vertex textures under SM 3.0

Post by robmar »

The problem was that the texture sequence wasn't being set as I had though.

I thought that the first sampler I declared in the shader would be the first texture (s0), etc, but it wasn't until I explicitly declared the samplers as s0 and s1 that it worked, and then only after I added the D3DVertextexture... to the stage in the SetTexture and SetStage... functions.

So now it works in my old 1.7.3. driver perfectly!
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: Vertex textures under SM 3.0

Post by Granyte »

yes that's a quirk of dx first used first texture
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Vertex textures under SM 3.0

Post by robmar »

Really? First texture used in pixel shader becomes s0? I never read that anywhere!!
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: Vertex textures under SM 3.0

Post by Granyte »

This is because of the way we use dx9 with irrlicht texture are not explicitly declared and assigned so they don't exist until a sampler try to sample them.

To force work around this you can assing both a sampler and a texture register when declaring a sampler

sampler2d tex0 :register(s0) register(t0);
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Vertex textures under SM 3.0

Post by robmar »

wow that's confusing, I didn't know you could specify both, or why you would. I have it working using (S0) along now, thankfully!
Post Reply