Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17560

whats wrong with this quad?

$
0
0

i'm getting shaders working in caveman 3.0

 

i just got the effect file from basicHLSL working in a test routine in the game, using SetVertexDeclartation SetStream SetIndices, Effect->SetTexture, and DrawInxededPrimitive, instead of mesh->DrawSubset.

 

the game only uses d3dxmeshes for loading. it only stores the vb's, ib's, numverts, num_prinitieves, and .x filename.

 

so far i've done tests that draw tiny.x with her texturemap, and tiny.x with textures from the game.

 

but when i tried to draw a a quad mesh from the game, the texture is messed up.  like clamp is on or something.   the quad is a unit quad centered on the origin  lying in the x,z plane. it was made in blender as i recall, and exported as .x

 

to make sure , i did a dump of the vb and ib:

 

vert    x           y     z        u    v

0       -0.5       0     .5       1    1

1       .5          0     .5        0    1

2       .5         -0     -.5      0     0

3      -.5         -0     -.5     1      0

 

note that all those .5's area actually .4999987's

 

 

index  vertex#

0            0

1            1

2            2

3            0

4            2

5            3

 

looking down from above with pos z towards the top,  both the quad verts and the verts for both tris are listed in clockwise order. the 1st tri is the upper right half of the quad, and the second is the lower left half.

 

but the u,v coords mirror the texture across the line x=z.

 

to determine what was wrong, i created a second qaud with code, and it works:

 

= vb1[0].position.x 0.0f
= vb1[0].position.y 1.0f
= vb1[0].position.z 0.0f
 
= vb1[1].position.x 1.0f
= vb1[1].position.y 1.0f
= vb1[1].position.z 0.0f
 
= vb1[2].position.x 1.0f
= vb1[2].position.y 0.0f
= vb1[2].position.z 0.0f
 
= vb1[3].position.x 0.0f
= vb1[3].position.y 0.0f
= vb1[3].position.z 0.0f
 
= vb1[0].tu 0.0f
= vb1[0].tv 0.0f
 
= vb1[1].tu 1.0f
= vb1[1].tv 0.0f
 
= vb1[2].tu 1.0f
= vb1[2].tv 1.0f
 
= vb1[3].tu 0.0f
= vb1[3].tv 1.0f
 
= ib1[0] 0
= ib1[1] 1
= ib1[2] 2
= ib1[3] 0
= ib1[4] 2
= ib1[5] 3
 
cr result Zd3d_device_ptr->CreateVertexBuffer (UINT)(sizeof(Zvertexrec)*4) D3DUSAGE_WRITEONLY ZFVF D3DPOOL_MANAGED &m1.vb NULL
cr result Zd3d_device_ptr->CreateIndexBuffer (UINT)(sizeof(short)*6) D3DUSAGE_WRITEONLY D3DFMT_INDEX16 D3DPOOL_MANAGED &m1.ib NULL
 
c m1.vb->Lock 0 0 &p 0
c memcpy p vb1 sizeof(Zvertexrec)*4
c m1.vb->Unlock
 
c m1.ib->Lock 0 0 &p 0
memcpy( p, ib1, sizeof(unsigned short)*6 );
c m1.ib->Unlock
 
the effect file is basicHLSL.fx, with the vertex transform based on sin(time) stripped out, and just the 1 light technique.
 
i've tried both linear and aniso for min and mag filters
i thought textureTrasnformFlags might be the cause, but it doesn't seem to be supported.
 
the test is triggered from playtest menu #3, off of the main playtest menu in the game, which is accessed while in FPS mode, via alt-F12.
 
so the pipeline is in whatever state it was when it finished the call to draw_outdoors(); the game keeps the pipeline in a default state of alpha test and blend and snow blending off, and aniso and mipmaps on.
 
so it seems there is something wrong with that quad. the  UVs most likely.    i need to test other meshes from the game as well. i did try one other mesh rock.x, but seemed to get the same results. the texture used for the tests is a 256x256 grass tile.
 
i'm concerned that maybe blender is spiiting out UVs that the shader doesn't like for some reason.  
 
the sampler code is 
 
 
sampler MeshTextureSampler = 
sampler_state
{
    Texture = <g_MeshTexture>;
    MipFilter = LINEAR;
    MinFilter = ANISOTROPIC;
    MagFilter = ANISOTROPIC;
// TextureTransformFlags = DISABLE;
};
 
 
PS_OUTPUT RenderScenePS( VS_OUTPUT In)     
PS_OUTPUT Output;
Output.RGBColor = tex2D(MeshTextureSampler, In.TextureUV);   //     * In.Diffuse;      // Lookup mesh texture and modulate it with diffuse
return Output;
}
 
 
 
EDIT:
it definitely seems to be the UVs.
 
i changed the quad made with code to a unit quad in the x,z plane centered at the origin.  that worked.  then i changed the UV's to mirror across x=z, the way the quad from the game does, and i get the banding and streaking - ie it doesn't work.  guess i'll try a fresh quad from blender next...
 
 
EDIT 2:
 
just tried a fresh quad from blender and it doesn't work.
 
blender version: 2.78a - should be the newest. it was installed on the new PC perhaps a month ago.
 
3d view - object mode - add - mesh - plane.
 
2nd window - UV editor - image - open image - grass_tile1.bmp
 
1st window - switch to edit mode - mesh - uv unwrap - unwrap
 
file - save as - plane2.blend
 
file - export  - directx -  plane2.x - LH ccords, up axis = y,  export selected (the plane), export: meshes, normals, and uv's.
 
change the game to load plane2.x instead of plane.x.
 
plane.x is the original one that doesn't work.
 
a dump of plane2.x reveals:
 
-1  0  -1      .0001    .9999
 1  0  -1      .9999    .9999
 1  0   1      .9999    .0001
-1  0   1      .0001    .0001
 
3,2,1
3,1,0
 
again, the tris are listed CW, not CCW.
 
but the texture is not mirrored across x=z.    UL of quad is UL of tex, and so on.
 
and it doesn't work.
 
i'm slowly rotating the quad around global x, and neither side works.  neither front nor back facing.
 
is it the CW listing of verts?
 
guess i'll try swizzling the indices....

Viewing all articles
Browse latest Browse all 17560

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>