3DRaddict
Member
|
MeshRender normals?
I've been using the MeshRender functions vtxLock(), etc to successfully change vertex positions in my mesh. However a change in vertex position makes it necessary to recalculate the vertex normals. I have been battling to do this using the MeshRender functions.
I have been using:
Int nrm_ofs=myMesh->parts(0).render.vtxOfs(VTX_NRM);
to obtain the vertex Normal Offset in the same manner as I used:
Int pos_ofs=myMesh->parts(0).render.vtxOfs(VTX_POS);
to obtain the vertex Position Offset.
However, updating *((Vec*)(data + nrm_ofs + i*vtx_size)) with the recalculated Normal vector causes ugly shading patches in the final render.
As mentioned. the vertex position updates work perfectly.
I do notice in the MeshRender documention the following comment:
// lock vertex data and return it, this method may be used to directly modify values of hardware mesh vertexes after getting their offset in the data by using 'vtxOfs' method (currently you should use it only for 'VTX_POS' as 'Vec', 'VTX_TEX' as 'Vec2' and 'VTX_COLOR' as 'Color' components, as others may be stored in compressed format)
Does this imply that VTX_NRM cannot be used?
|
|
08-10-2014 10:16 AM |
|
3DRaddict
Member
|
RE: MeshRender normals?
I found a small error in my Normal recalculation code, which I corrected.
The rendered mesh looks a great deal better, but whether all is 100% correct at this stage, I cannot say until I've done some more work on it.
EDIT: I'm still having problems...even though the Normals are now evenly distributed, the mesh's original texture is flat and unshaded. It seems that something has to be done with the UV coords as well?
It would be really helpful to see a complete coded example showing a simple textured mesh being transformed realtime using the provided MeshRender functionality (not using shaders), and demonstrating how the changes in vertex normals and UV coords are accounted for.
(This post was last modified: 08-10-2014 08:55 PM by 3DRaddict.)
|
|
08-10-2014 03:52 PM |
|
Esenthel
Administrator
|
|
08-11-2014 03:12 AM |
|
3DRaddict
Member
|
RE: MeshRender normals?
Thank you, Greg. Using the compression/decompression I've been able to get my mesh rendering correctly. HOWEVER, this only happens when I compile and run in VisualStudio. When the same code is compiled and run in the CodeEditor , I get the ugly visual artifacts on my mesh. Strange,eh?!
I transfer between CodeEditor and VisualStudio using the CodeEditor "Open in Visual Studio" option.
(This post was last modified: 08-11-2014 03:29 PM by 3DRaddict.)
|
|
08-11-2014 03:29 PM |
|
3DRaddict
Member
|
RE: MeshRender normals?
On testing again today, I've found that the difference appears to be related to whether I compile and run in the CodeEditor with DX9 or DX10+ selected.
With DX9 I get perfect rendering, whereas with DX10+ I get the artifacting.
Switching to VisualStudio with either DX9 or DX10+, I get perfect rendering.
A couple of pics to clarify:
DX10+ in CodeEditor
DX9 in CodeEditor and DX9/DX10+ in VisualStudio
|
|
08-12-2014 06:17 AM |
|
Esenthel
Administrator
|
RE: MeshRender normals?
Please remember that DX9/DX10+ may have different 'storageSigned()' as in the source, for which you need to use different functions.
|
|
08-12-2014 06:43 AM |
|
3DRaddict
Member
|
RE: MeshRender normals?
Yes... that solves it! Thanks for that pointer.
I can't immediately find any method in the API to determine if the App is running with DX9 or DX10+, so for the time being I'm using two different Apps... one for DX9 and one for DX10+
|
|
08-12-2014 10:15 AM |
|
amit
Member
|
RE: MeshRender normals?
Sorry for bump, but can you post the code, for updatin the mesh?
so far i was able to do,
Byte *base_data_ptr=arch_sm->parts(0).render.vtxLock(LOCK_READ_WRITE);
Int vtx_size=arch_sm->parts(0).render.vtxSize();
Int pos_offset=arch_sm->parts(0).render.vtxOfs(VTX_POS);
for(int i=0;i<arch_sm->parts(0).render.vtxs();i++)
{
Vec t;
t.x = morph1[3*i ]; // a list of doubles, morph
t.y = morph1[3*i+1];
t.z = morph1[3*i+2];
(*(Vec*)( base_data_ptr + pos_offset + (i*vtx_size) ))=t;
}
arch_sm->parts(0).render.vtxUnlock();
I am new to 3d maths, so some help would be appreciated.
|
|
09-17-2014 07:57 PM |
|
3DRaddict
Member
|
RE: MeshRender normals?
amit:
Replied via PM
|
|
09-18-2014 07:05 AM |
|