XNA Game Development Forums
2012/05/21 20:38:59 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Search Calendar Login Register  
Pages: [1]
  Print  
Author Topic: Texturing Models  (Read 2112 times)
Peregrinati
Newbie
*
Offline Offline

Posts: 4


View Profile
« on: 2008/12/15 09:31:31 »

Hi - following the tutorials and I'm wondering if the BasicShader provided is supposed to show textures on models that have them included in the file? I can't get it to, even though when I set a breakpoint and check the line:
Code:
myDevice.Textures[0] = ((BasicEffect)part.Effect).Texture;
works properly - at least the value of "Texture" is a texture of the same dimensions as the one the model uses - but the texture is not being rendered. From what I can tell by looking at the shader code, the texture should be displayed (I am, however, very new at this), but something is wrong somewhere.

I also tried modifying things so that textures can manually be set on models (giving the Model two asset strings, one for the model and one for the texture, and setting myDevice.Textures[0] to a Texture2D loaded in LoadContent) - but that didn't work either.
Logged
Peregrinati
Newbie
*
Offline Offline

Posts: 4


View Profile
« Reply #1 on: 2008/12/15 11:38:08 »

Ok, I figured it out... kinda. If you look at this code:

Code:
float4 BasicShader(PS_INPUT Input) : COLOR0 {
    float3 Normal = normalize(Input.Normal);
    float3 ViewDirection = normalize(Input.ViewDirection);
    LightDirection = normalize(-LightDirection);
   
    float EdgeComponent = dot(Normal, ViewDirection);
    float3 TotalAmbient = saturate(AmbientColor * EdgeComponent);

    float NDotL = dot(Normal, LightDirection);
    float3 DiffuseAverage = (DiffuseColor + LightDiffuseColor) * 0.5f;
    float3 TotalDiffuse = saturate(DiffuseAverage * NDotL);
   
    float3 Reflection = normalize(2.0f * Normal * NDotL - LightDirection);
    float RDotV = max(0.0f, dot(Reflection, ViewDirection));
    float3 TotalSpecular = saturate(LightSpecularColor * pow(RDotV, SpecularPower));

>>>>float4 TextureColor = (Input.Color.rgba + 1) * tex2D(TextureSampler, Input.Texcoord);<<<<
    float4 LightingColor = float4(TotalAmbient + TotalDiffuse + TotalSpecular, 1.0f);
   
    return TextureColor > 0 ? TextureColor * LightingColor : LightingColor;
}

I figured that TextureColor was always <=0, and I was right. I did some further testing and discovered that it's always 0 because Input.Color.rgba is always 0, but I don't understand why. If I add 1 to it before multiplying it by tex2D(TextureSampler, Input.Texcoord) (see the highlighted line of code), then my textures are displayed, although with errors (both using the built in model textures, and the tweak I made for setting the model texture in the engine). I don't think this is a nice solution though - how would I go about setting it in the engine? I suppose I could pass a color in as a parameter to the shader, but I don't know what I'd call it... what exactly does the Input.Color : COLOR0 come from, and what is it supposed to do?

Thanks
« Last Edit: 2008/12/15 11:41:06 by Peregrinati » Logged
Peregrinati
Newbie
*
Offline Offline

Posts: 4


View Profile
« Reply #2 on: 2008/12/15 11:51:50 »

Ok, forget adding 1 - thought about it for a second and that's the same thing as just removing the Input.Color.rgba from the TextureColor assignment. And I said it displays perfectly, but not really - there's a bunch of speckles on the texture... kind of like parts of it are inverted or something strange. :S Any ideas?
Logged
mikeschuld
Administrator
Sr. Member
*****
Offline Offline

Posts: 389


View Profile WWW
« Reply #3 on: 2008/12/15 12:00:01 »

I might have you zip the whole deal up and send it to me so I can play with it. Much easier to debug things that way Cheesy
Logged
Peregrinati
Newbie
*
Offline Offline

Posts: 4


View Profile
« Reply #4 on: 2008/12/15 12:14:41 »

Ok, it was too big to put on the forum attachment, so I sent it to the hotmail address you have in your profile... hope that's ok.
Logged
Pages: [1]
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Shaders and rotating models.... General Discussion Nemo Krad 3 2827 Last post 2007/03/03 17:42:12
by Nemo Krad
Moving the models aroung Hazy Mind XNA Engine Squeezle42 6 2478 Last post 2007/03/07 14:40:48
by Squeezle42
Question: Texturing Terrain General Discussion Ashe 1 2341 Last post 2007/03/17 10:28:36
by DaphydTheBard
Nice models and free models, new site! General Discussion 3d4ya 2 3056 Last post 2010/08/03 03:05:01
by ThackeG67
xsi models not displaying correctly Hazy Mind XNA Engine crazyhor77 2 1476 Last post 2009/09/21 22:48:16
by crazyhor77
Powered by MySQL Powered by PHP Powered by SMF 1.1.12 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.105 seconds with 18 queries.