Welcome Guest [Log In] [Register]
We hope you enjoy your visit.


You're currently viewing the Ultimate 3D Community as a guest. This means that you can only read posts, but can not create posts or topics by yourself. To be able to post you need to register. Then you can participate in the community active and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.

Join our community!

If you are already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Heya...what's with my UV's?
Topic Started: Apr 8 2009, 02:12 AM (431 Views)
skarik
Member Avatar
kitten eating scum
[ *  *  *  *  *  * ]
Hey, is AddMeshInverseTangentSpaceMatrices supposed to warp UV coordinates like crazy? I mean, there's no overlap, there's just me and my normals. Could it be caused my leaving my computer on too long?

Heya look! My first plugin ever for Garry's Mod is working! Yay Ima flying dragon!

Okay, but seriously, it just started from nowhere.

*Deletes duplicate object*

Heya, this might need a little looking into, 'cause it's fixed now.

Here's my code, if it'll help:
model_barrel
Code:
 
file = "models\large_barrel.u3d";
password = "";

z = 1;
scalx = 0.1;
scaly = 0.1;
scalz = 0.1;

// We load the base mesh and smooth out the normals
mesh_base = CreateMesh(file,password);
SmoothMesh( mesh_base,100 );
SmoothMesh( mesh_base,100 );
SmoothMesh( mesh_base,100 );
SmoothMesh( mesh_base,100 );

// Add correct normals
AddMeshInverseTangentSpaceMatrices( mesh_base );

// We set the diffuse color
SetMeshMatDiffuseColor( mesh_base,0,128,128,128,255 );

// Load the cel shading effect
LoadMeshMatFX( mesh_base,0,"shaders\NM2SpecLight1_4.ufx" );
//LoadMeshMatFX( mesh_base,0,"shaders\NMDSpecLight1_4.ufx" );

// To get the meshes to cast correctly, the shader requires
// a point to cast from. This is passed as a light position,
// so instead of manually setting coordinates, all you need
// to do is pass a light index. Make sure your light exists
// first before passing it.
//SetMeshMatFX_LightSource( mesh_base,0,light_directional,light_point,light_point2 );
SetMeshMatFX_LightSource( mesh_base,0,light_point2,light_point );
//SetMeshMatFX_LightSource( mesh_base,0,light_directional,light_point2 );

// Set the textures for use, is commented
SetMeshMatStageTexture( mesh_base,0,0,105 ); // Diffuse Map
SetMeshMatStageTexture( mesh_base,0,1,106 ); // Bump Map
SetMeshMatStageTexture( mesh_base,0,2,1009 ); // Cubic
SetMeshMatStageTexture( mesh_base,0,3,1009 ); // Cubic

// Set the constants since they usually don't work right
// when they are defined in the shader.
//SetMeshMatFX_PSConst( mesh_base,0,0, 0.33,0.33,0.33,1 );

// Turn on shadow casting and receiving and crap
OptimizeMeshShadowGeometry( mesh_base,0, true );
AddStencilShadowMeshCaster( mesh_base,light_directional, true );
AddStencilShadowMeshReciever( mesh_base,light_directional, true );
AddStencilShadowMeshCaster( mesh_base,light_point, true );
AddStencilShadowMeshReciever( mesh_base,light_point, true );
AddStencilShadowMeshCaster( mesh_base,light_point2, true );
AddStencilShadowMeshReciever( mesh_base,light_point2, true );


model_barrel_2
Code:
 
file = "models\large_barrel.u3d";
password = "";

z = 1;
scalx = 0.1;
scaly = 0.1;
scalz = 0.1;

// We load the base mesh and smooth out the normals
mesh_base = CreateMesh(file,password);
SmoothMesh( mesh_base,100 );
SmoothMesh( mesh_base,100 );
SmoothMesh( mesh_base,100 );
SmoothMesh( mesh_base,100 );

// Add correct normals
AddMeshInverseTangentSpaceMatrices( mesh_base );

// We set the diffuse color
SetMeshMatDiffuseColor( mesh_base,0,128,128,128,255 );

// Load the cel shading effect
LoadMeshMatFX( mesh_base,0,"shaders\NM2SpecLightSpecMask1_4.ufx" );
//LoadMeshMatFX( mesh_base,0,"shaders\NMDSpecLight1_4.ufx" );

// To get the meshes to cast correctly, the shader requires
// a point to cast from. This is passed as a light position,
// so instead of manually setting coordinates, all you need
// to do is pass a light index. Make sure your light exists
// first before passing it.
//SetMeshMatFX_LightSource( mesh_base,0,light_directional,light_point,light_point2 );
SetMeshMatFX_LightSource( mesh_base,0,light_point2,light_point );
//SetMeshMatFX_LightSource( mesh_base,0,light_directional,light_point2 );

// Set the textures for use, is commented
SetMeshMatStageTexture( mesh_base,0,0,105 ); // Diffuse Map
SetMeshMatStageTexture( mesh_base,0,1,106 ); // Bump Map
SetMeshMatStageTexture( mesh_base,0,2,1009 ); // Cubic
SetMeshMatStageTexture( mesh_base,0,3,1009 ); // Cubic
SetMeshMatStageTexture( mesh_base,0,4,105 ); // Specular Map

// Set the constants since they usually don't work right
// when they are defined in the shader.
//SetMeshMatFX_PSConst( mesh_base,0,0, 0.33,0.33,0.33,1 );

// Turn on shadow casting and receiving and crap
OptimizeMeshShadowGeometry( mesh_base,0, true );
AddStencilShadowMeshCaster( mesh_base,light_directional, true );
AddStencilShadowMeshReciever( mesh_base,light_directional, true );
AddStencilShadowMeshCaster( mesh_base,light_point, true );
AddStencilShadowMeshReciever( mesh_base,light_point, true );
AddStencilShadowMeshCaster( mesh_base,light_point2, true );
AddStencilShadowMeshReciever( mesh_base,light_point2, true );


I'd post a demo, but I still have 3 more specular shaders to finish.
Edited by skarik, Apr 8 2009, 02:12 AM.
Blog|EHS
Offline Profile Quote Post Goto Top
 
skarik
Member Avatar
kitten eating scum
[ *  *  *  *  *  * ]
I figured it out. SmoothMesh affects all instances of a given model. I forgot about that.
Blog|EHS
Offline Profile Quote Post Goto Top
 
Gandalf20000
Member Avatar
Geek
[ *  *  *  *  *  * ]
The problem is that for some reason, using smooth normals and inverse tangent space normals doesn't work well. You have to recalculate the normals before you can use the inverse tangent space normals if they've been smoothed.
Offline Profile Quote Post Goto Top
 
ashrat3000
Member Avatar
u3d raytracer
[ *  *  *  *  *  * ]
Posted Image



...woah


Edited by ashrat3000, Apr 8 2009, 03:51 AM.
그대를 사랑해


Offline Profile Quote Post Goto Top
 
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
As chance will have it, I also ran into this problem just now. Since every model I load from a .u3d file (created using U3D version 2.1.1) has wrong UV's, this seems to be a genuine bug related to ExportToU3DFile(...). Looks like shaders and normals have nothing to do with it. Here's a pic:

Posted Image
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
Dr. Best
Member Avatar
Administrator
[ *  *  *  *  *  * ]
Thanks for reporting this. It is on the list of things I will check for Ultimate 3D 2.1.2 now.
Offline Profile Quote Post Goto Top
 
« Previous Topic · Questions about Ultimate 3D · Next Topic »
Add Reply