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

Login with username, password and session length
 
   Home   Help Search Calendar Login Register  
Pages: [1] 2 3
  Print  
Author Topic: Tutorial 7 :: A More Flexible BasicEffect  (Read 13097 times)
mikeschuld
Administrator
Sr. Member
*****
Offline Offline

Posts: 389


View Profile WWW
« on: 2006/11/30 05:57:57 »

This one is pretty long and drawn out. Let me know if you find any messups Wink
« Last Edit: 2006/11/30 05:59:48 by mikeschuld » Logged
solidarity
Newbie
*
Offline Offline

Posts: 1


View Profile
« Reply #1 on: 2006/11/30 11:08:05 »

I ran through it, all seemed to check out just fine.. I could've sworn there was a typo somewhere, but I didn't think much of it so I can't recall where it was anymore. Smiley Could have just been my fault too, of course.

Nice tutorial, if there's something I've never been good at, it's shaders.. XP
Logged
Nelson
Newbie
*
Offline Offline

Posts: 21


View Profile
« Reply #2 on: 2006/11/30 11:56:17 »

Thanks for this. It's an incredibly clear explination of how to get things going.

Logged
Chr0n1x
Global Moderator
Sr. Member
*****
Offline Offline

Posts: 307


View Profile WWW
« Reply #3 on: 2006/11/30 21:39:46 »

Nice tutorial, looking good. Now to get some of the functionality that the XNA BasicEffect has, like Normal Mapping. Smiley
Thanks.
Logged

mikeschuld
Administrator
Sr. Member
*****
Offline Offline

Posts: 389


View Profile WWW
« Reply #4 on: 2006/11/30 23:23:00 »

That's what the next tut is for Wink
Logged
Chr0n1x
Global Moderator
Sr. Member
*****
Offline Offline

Posts: 307


View Profile WWW
« Reply #5 on: 2006/12/01 02:51:13 »

Excellent, well just so you all know, I will be creating my tutorial to this one, unless Mike releases the Normal Mapping tutorial this weekend. So mine should be up soon enough.
Logged

mikeschuld
Administrator
Sr. Member
*****
Offline Offline

Posts: 389


View Profile WWW
« Reply #6 on: 2006/12/01 17:56:19 »

Let me know when you get it done and I'll stick it on in the same format as the rest of them on the main site as well.
Logged
Chr0n1x
Global Moderator
Sr. Member
*****
Offline Offline

Posts: 307


View Profile WWW
« Reply #7 on: 2006/12/01 21:47:49 »

Yeah I will be putting it on my blog in original format and PDF in original format, but first have to find a good way to render the 2d image since SpriteBatch doesn't work with custom pixel shaders. Sad

[EDIT] Okay all done, now to write it up in a tutorial form. Should be up soon enough.
[EDIT x 2] Okay, 99% done on the tutorial, just removing unecessary content like the skybox textures and the hmlogo.dds from the Content directory, to make it smaller. Also removing the bin and obj folders from both projects.
Final filesize is 709kb - Mike, suggest for future tutorials you do similar Tongue for those on lower speed internet. Unless you are reenabling the skybox next tutorial.
« Last Edit: 2006/12/02 03:27:54 by Chr0n1x » Logged

sTV
Newbie
*
Offline Offline

Posts: 2


View Profile
« Reply #8 on: 2006/12/02 04:09:36 »

Hi Mike,
Another great tutorial, thanks for your efforts, I'm really enjoying your XNA series. I have been looking for a good shader primer for a while.

When I follow this tutorial I'm getting different behaviour to you in the shader and I was wondering if you might know why. When I run the app, it seems that the value returned by the BasicShader pixel shader contains transparency information rather than color information. When you include the pixel shader below you get a black model but I get an invisible model.
float4 BasicShader() : COLOR0{
   return (float4)0.0f;
}
If I increase the value returned to 0.5f I get a transparent model, up to 1.0f which is a solid white model.

This seems to run through the rest of the example and I get some pretty exciting shader effects (!), though not what I was expecting or what you get. I'm sure I'm doing something dumb but I can't seem to spot it, I've redone the tutorial twice. Can you think of anything that might cause this behaviour?
Logged
Chr0n1x
Global Moderator
Sr. Member
*****
Offline Offline

Posts: 307


View Profile WWW
« Reply #9 on: 2006/12/02 04:21:27 »

Hi sTV,
When using a float4 to represent color in a Pixel shader, the float4 contains 4 float variables, as seen in its name. Now they are r,g,b, and a.
So if you return a float4 that simply equals 0.0f, then ALL of r,g,b and a will equal 0.0f, meaning you will have a transparent model.

One way around this is to set the alpha to 1 after you set it all to 0, an extra step, but all cards can do it.

Code:
float4 BasicShader() : COLOR0
{
? ? float4 color = (float4)0.0f;
? ? color.a = 1.0f;
? ? return color;
}

That will display a completely black model, but the alpha channel will be set to 1, so it will be fully visible.
Logged

sTV
Newbie
*
Offline Offline

Posts: 2


View Profile
« Reply #10 on: 2006/12/02 04:32:09 »

Awesome, thanks Chr0n1x, you nailed it, that solved the problem perfectly. I'm a shader n00b. Embarrassed
Logged
Chr0n1x
Global Moderator
Sr. Member
*****
Offline Offline

Posts: 307


View Profile WWW
« Reply #11 on: 2006/12/02 14:25:35 »

Nah thats one part noone really thinks about, the alpha channel, I onyl remembered it because I was working with it in a shader just then. Its good that thats solved.
Logged

mikeschuld
Administrator
Sr. Member
*****
Offline Offline

Posts: 389


View Profile WWW
« Reply #12 on: 2006/12/03 04:56:50 »

The alpha channel was only ignored there because a) we are going to be setting it specifically in the next tutorial with an Alpha parameter (like the one BasicEffect has) and b) because alpha blending should be off by default. If your current codebase sets any of the alpha rendering stuff to on somewhere that would cause the phantom mesh
Logged
jadams
Newbie
*
Offline Offline

Posts: 14


View Profile
« Reply #13 on: 2006/12/03 19:41:23 »

Thanks for another good tutorial mike.

You just answered my question as to why you hardcoded the alpha.

I'm assuming this will go away in the next tut:

Code:
myDiffuseColor = new Vector4(newColor, 1.0f);

I thought that was pretty wierd. Why not just include the alpha in the vector? I guess we'll see down the road.

I have a coule of other questions as well. Why didn't you include SetSpecularPower() in IHMHasMaterial as you did with the diffuse and ambient? It would only make sense. Or am I missing something important?

I just realized my other question isn't valid. I was thinking that the diffuse light wasn't updating correctly. this is because when I rotateted the camera I thought I was rotating the model. Never mind me Smiley

Last thing, How do we get textures in? I see three texture coords in the shader. Is it as simple as adding a TextureSampler and another set of coords?
Logged
mikeschuld
Administrator
Sr. Member
*****
Offline Offline

Posts: 389


View Profile WWW
« Reply #14 on: 2006/12/04 03:00:27 »

The textures will be using in TEXCOORD0 (which is why i started all the light components are coord1). Also, the SetSpecularPower is an object based thing. Think about having two objects lit in the scene, one being a basketball, and one being a shotput or other metal object. The shotput will have a much higher specular value because it is a lot shinier than the basketball. The way it is implemented now, we can set that component for each object in the Demo code somewhere (or in a custom importer etc.) so everything in the scene shines like it should.
Logged
Pages: [1] 2 3
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Tutorial 14 Hazy Mind 3D Engine serus 3 3901 Last post 2008/12/19 10:32:01
by mikeschuld
Next Tutorial Hazy Mind XNA Engine mikeschuld 12 4871 Last post 2006/11/12 15:40:51
by mikeschuld
Having issues with tutorial 3 Hazy Mind XNA Engine siferion 4 2377 Last post 2006/11/26 14:04:03
by mikeschuld
Working on tutorial 7 Hazy Mind 3D Engine tuxdalinux 6 2572 Last post 2006/12/11 17:37:02
by tuxdalinux
Tutorial 3 Hazy Mind XNA Engine hansonc 4 2482 Last post 2007/03/27 09:23:23
by hansonc
Tutorial 3 help... new question i believe Hazy Mind XNA Engine hansonc 9 3127 Last post 2007/05/15 01:32:01
by BackwardsBoxers
tutorial 4 problem Hazy Mind 3D Engine precious roy 3 2499 Last post 2007/08/03 12:24:26
by mikeschuld
Tutorial 2 Hazy Mind XNA Engine Classicwarrior 5 2687 Last post 2008/05/17 23:01:31
by Classicwarrior
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.17 seconds with 20 queries.