XNA Game Development Forums
2012/05/21 21:22:11 *
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)
Silvo
Newbie
*
Offline Offline

Posts: 10


View Profile
« Reply #30 on: 2008/04/14 03:30:15 »

I understand where you're coming from. I think that learning C++ (C would probably have been better still, but oh well) before other languages definitely helped me understand how the computer handles the code, which has helped me with optimising my source code in other languages, sometimes I'll even come up with them as I write it.

As far as shaders goes though, I wouldn't know where to start learning about programming them. I'll have to start googling for something, but if you have any helpful sites that would be excellent. Just a quick question, these shaders we write in the Hazy Mind engine, they are written in HLSL, aren't they? That would help get me started too, I think.

I used to wonder why they ditched the fixed function pipeline in favour of a programmable one -- it just seemed like more trouble to me -- but after seeing what some people have done with shaders... wow.
Logged
Nemo Krad
Global Moderator
Hero Member
*****
Offline Offline

Posts: 512


I have seen the fnords


View Profile WWW
« Reply #31 on: 2008/04/14 04:17:16 »

Shaders are awesome, just wish I was good at writing them....

Yes, all shaders here are in HLSL.
Logged
Silvo
Newbie
*
Offline Offline

Posts: 10


View Profile
« Reply #32 on: 2008/04/14 05:26:42 »

OK, I multiplied the matrices in C# and passed them to the shader (although I still had to pass in the World matrix as it is used without the View and Projection matrices in the shader itself). So it looks like I can only pass in 4 constants (unless their type has something to do with it, which means I can only pass 2 float4x4s and 2 float3s). Now I get this error:

error X4532: cannot map expression to pixel shader instruction set

which points to this line:

float3 Normal = normalize(Input.Normal);

Does this mean SM1.1 doesn't support normalize()??

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

Posts: 307


View Profile WWW
« Reply #33 on: 2008/04/14 18:35:14 »

In this case it gets a bit weird. Only vs_1_1 supports Normalize, so the Pixel Shader doesn't. (They have seperate instruction sets)

Hmm, try moving that command to your vertex shader, you'll find anyway you might need to rely on Vertex rather than Pixel lighting in SM1.1
http://msdn2.microsoft.com/en-us/library/bb509630(VS.85).aspx
Logged

Silvo
Newbie
*
Offline Offline

Posts: 10


View Profile
« Reply #34 on: 2008/04/14 21:10:06 »

Thanks for that. I moved the normalize() calls to the pixel shader, and now I have this:

Code:
float4x4 WorldViewProjection;
float4x4 World;
float3 AmbientLightColour;
float3 EyePosition;
 
struct VS_INPUT {
    float4 Position      : POSITION0;
    float3 Normal        : NORMAL0;
};
 
struct VS_OUTPUT {
    float4 Position      : POSITION0;
    float3 Normal        : TEXCOORD1;
    float3 ViewDirection : TEXCOORD2;
};

struct PS_INPUT {
float3 Normal        : TEXCOORD1;
float3 ViewDirection : TEXCOORD2;
};

VS_OUTPUT Transform(VS_INPUT input){
    float3 objectPosition = mul(input.Position, World);
   
    VS_OUTPUT output;
    output.Position = mul(input.Position, WorldViewProjection);
    output.Normal = normalize(mul(input.Normal, World));
    output.ViewDirection = normalize(EyePosition - objectPosition);
     
    return output;
}

float4 BasicShader(PS_INPUT input) : COLOR0 {
float edgeComponent = dot(input.Normal, input.ViewDirection);
float3 totalAmbient = saturate(AmbientLightColour * edgeComponent);

float4 finalColour = float4(saturate(totalAmbient), 1.0f);
return finalColour;
}

technique BasicShader {
    pass P0 {
        VertexShader = compile vs_1_1 Transform();
        PixelShader  = compile ps_1_1 BasicShader();
    }
}


No errors, but no output either. I just get a lovely cornflower blue background... If you could look to see if I've screwed anything up, that would be great. Thanks.
Logged
crazyhor77
Newbie
*
Offline Offline

Posts: 8


View Profile
« Reply #35 on: 2009/09/03 01:57:02 »

hi guys, i have followed through all the tutorials again recently and am trying to understand the hlsl side of things a lot better.

i would like to implement some simple transparency on some models i am loading however i am having some difficulties.

i have the quad loaded inside a model and for my pixelshader i am simply returning float4(0.5f, 0.5f, 0.5f, 0.5f) for testing purposes but i still cannot see the quad inside the model.

i have played with alphablendenable in the past from the code side and got things working using transparency in the png textures on my models, but now i would like to specify all my model attributes from the material accessors and not worry about textures at all.

i read in a previous post from mike to not set renderstates in the engine and instead specify it in the .fx file, can anyone elaborate on what is needed to get this working?

cheers for any help
Logged
crazyhor77
Newbie
*
Offline Offline

Posts: 8


View Profile
« Reply #36 on: 2009/09/03 17:44:31 »

well, i changed the order of drawing the objects to the scene and now it works correctly

atm, i am wondering what would happen once the objects are moving around in front of one another and the order of rendering doesnt change

does the order of rendering need to be based on the objects distance from the camera to render transparency correctly?
Logged
mikeschuld
Administrator
Sr. Member
*****
Offline Offline

Posts: 389


View Profile WWW
« Reply #37 on: 2009/09/04 10:02:55 »

Whenever you are working with transparency in your rendered objects you have to make sure they are sorted by depth away from the camera before rendering them because of the way the blending works on the video card. There are other methods to solve this problem as well, like precalculated alpha blending, but those become a lot more complicated than just sorting by depth pretty quickly.
Logged
crazyhor77
Newbie
*
Offline Offline

Posts: 8


View Profile
« Reply #38 on: 2009/09/07 16:07:51 »

yep, expected as much, now to determine what would be the best algorithm for determining depth in the scene

i dont think raw position will cut it for me, as i have a bunch of smaller transparent objects appearing within a larger transparent object

see what happens i guess Smiley
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.055 seconds with 19 queries.