Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1] 2 3 ... 5
  Print  
Author Topic: Shader FAQ  (Read 35371 times)
bruffner
Customers
Community Member
*****
Posts: 200


« on: August 19, 2004, 06:35:58 PM »

*** Updated 7/1/2005 ***
See Revision 4 Notes for changes at end of FAQ

We are putting together a shader FAQ.  I will update the FAQ as new replies are added.  Please post any questions or Questions and answers for common items you have found.

------------------------------------------------------------------------------
What Types of Shaders are Supported?

FX files which would include HLSL, and ASM code including a Technique encapsulating the PS and VS functions are supported.

------------------------------------------------------------------------------
Where can i learn more about HLSL Language?

Microsoft has an introductory HLSL reference that I found quite good to learn from:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnhlsl/html/shaderx2_introductionto.asp

http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/directx9_c/directx/graphics/reference/Shaders/HighLevelShaderLanguage.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnhlsl/html/shaderx2_introductionto.asp

http://www.fusionindustries.com/content/lore/code/articles/fi-faq-cg.php3

http://www.imm.dtu.dk/visiondag/VD03/grafisk/WolfgangEngel.pdf

http://www.shaderx.com/direct3d.net/tutorials/RenderMonkey%20Movies/1Steps/RenderMonkey.htm

------------------------------------------------------------------------------
What are some good books about shaders?

Real-Time Shader Programming Covering Directx 9.0 By Ron Fosner
Published by Morgan Kaufmann
ISBN 1-55860-853-2

The book describes low level shader programming, which isn't as much of as a headache as the math involved. I'm finding its giving me a very good base understanding of shaders and a good spring board from which to later pickup HLSL.

A really nice touch is that every page is in colour. unusual for this type of book.


------------------------------------------------------------------------------
Where can i find example Shaders?

Microsoft includes a number of examples with the Directx SDK.  A nice tutorial site can be found here with several examples:

http://www.neatware.com/lbstudio/web/hlsl.html


------------------------------------------------------------------------------
What are some programs that can be used to edit shaders?

Rendermonkey from ATI
NVidia FX Composer
RTZen - RTShader
Soul Shader (see bottom of FAQ for more info)


------------------------------------------------------------------------------
What is an example of a HLSL Shader?

Code:
// View Matrix Projection
float4x4 matViewProjection : ViewProjection;

//Format for Output for Vertex Shader
struct VS_OUTPUT
{
   float4 Pos:     POSITION;
};

// Vertex Shader
VS_OUTPUT vs_main( float4 inPos: POSITION )
{
   VS_OUTPUT Out;

    Out.Pos = mul(inPos, matViewProjection);

   return Out;
}

// Pixel Shader
float4 ps_main( float4 inDiffuse: COLOR0 ) : COLOR0
{
   //  Output constant color:
   float4 color;
   color[0] = color[3] = 1.0;
   color[1] = color[2] = 0.0;
   return color;
}

technique Effect1
{
   pass Pass_0
   {
      VertexShader = compile vs_1_1 vs_main();
      PixelShader = compile ps_1_1 ps_main();
   }

}



------------------------------------------------------------------------------
Is there an example of a full screen shader?

Thanks to Sylvain, yes there is:

http://www.shelter7.com/FullscreenShader.fx


------------------------------------------------------------------------------
How do I Apply a Shader FX file to a TVMesh?

Declare your Variables and Create them
Delphi:
  Mesh: TVMesh;
  Shader: TVShader;

  Mesh := scene.CreateMeshBuilder();
  Shader := scene.CreateShader();

VB:
  Dim Mesh as TVMesh;
  Dim Shader as TVShader;

  Set Mesh = scene.CreateMeshBuilder()
  Set Shader = scene.CreateShader()

Setup your Mesh:
Mesh.LoadTVM(FileName, true, true)

Setup Your Shader:
if not Shader.CreateFromEffectFile(FXFile) then
  ErrorMessage := Shader.GetLastError;

Finally apply the shader to the mesh:
Mesh.SetShader(Shader);

------------------------------------------------------------------------------
How do I assign a shader to a specific group in a TVMesh?

The Shader can be assigned with SetShaderEx to a specific group.  If one group has a shader though, the rest of the models groups must also have a shader or they will not be visible.


------------------------------------------------------------------------------
My shader has multiple vertex/pixel shaders in the same file (aka techniques). How can I choose which one i want to apply on my mesh ?

Use TVShader.SetTechniqueByID or TVShader.SetTechnique.

------------------------------------------------------------------------------
I want to have multiple versions of a shader ( 2.0, 1.1) How do i setup my shader to automatically select the latest version the card supports?

When setting up techniques such as the following:

Code:
technique Effect1
{
   pass Pass_0
   {
      VertexShader = compile vs_2_0 vs_main();
      PixelShader = compile ps_2_0 ps_main();
   }

}
technique Effect1b
{
   pass Pass_0
   {
      VertexShader = compile vs_1_1 vs_main();
      PixelShader = compile ps_1_1 ps_main();
   }

}


The first technique Effect1 will be used.  If the card does not support 2.0 PS or 2.0 VS then the next technique in the file will be used.  In this case Effect1b would be used if only 1.1 PS and VS are available on the card.

if you have several techniques and you set the technique it will start from that technique and work to lower in the file from the selected point.


------------------------------------------------------------------------------
How can I pass parameters to my shader?

Try to locate the parameters in your shader.
Determine if their value is assigned by TV (See TV Semantics reference).
If not u should set them up yourself in your code by using functions like:

    TVShader.SetEffectParamMatrix
    TVShader.SetEffectParamVector
    TVShader.SetEffectParamBoolean
    TVShader.SetEffectParamFloat
    TVShader.SetEffectParamTexture



------------------------------------------------------------------------------
I tried to Load a .FX file that contains a texture but it will not load (Mesh does not show up)

A Texture can be loaded as follows:

Code:
texture Noise_Tex
<
   string filename = "C:\Textures\Texture.dds";
>;


The problem is the "\" is a escape character in C++ and confuses the loader.  You will want to pass in "\\" and this should take care of the problem.  So the above becomes:

Code:
texture Noise_Tex
<
   string filename = "C:\\Textures\\Texture.dds";

>;



------------------------------------------------------------------------------
My meshes are completely white when i apply a shader on them.
 
Verify if your shader use one of those semantics: AMBIENT, DIFFUSE, EMISSIVE, SPECULARPOWER TV will fill those parameters with your mesh material values.
You should apply a correct material on the mesh or remove the semantic from the shader file.


------------------------------------------------------------------------------
Rendermonkey is producing FX files that do not work

There are a number of problems with RenderMonkey's output.

    Non-escaped characters for textures "\" should be "\\" for texture paths.
    The vectors are output with parentesis insted of curley braces "(" should be "{"
    Out.Pos = mul(matViewProjection, isPos); is reversed and should be Out.Pos = mul(inPos, matViewProjection);



As more incompatabilities are found they will be added to this list.

------------------------------------------------------------------------------
TV Semantics Reference
TV will automaticaly set a few parameters value in your shaders, here is a list:

Code:

Description TV equivalent DataType Semantics
World matrix Mesh.GetMatrix float4x4 "WORLD", "WORLDMATRIX", "MWORLD", "MATWORLD"
View matrix Inverse Camera.GetMatrix float4x4 "VIEW", "VIEWMATRIX"
Projection matrix Camera.GetProjectionMatrix float4x4 "PROJ", "PROJECTION", "PROJECTIONMATRIX", "PROJMATRIX"
World-view matrix float4x4 "WORLDVIEW", "WORLDVIEWMATRIX", "WV", "WVIEWMATRIX"
World-view-projection matrix float4x4 "WORLDVIEWPROJ", "WVP", "WORLDVIEWPROJECTION", "WORLDVIEWPROJECTIONMATRIX"
View-projection matrix float4x4 "VIEWPROJ", "VIEWPROJECTION", "VIEWPROJMATRIX", "VIEWPROJECTIONMATRIX"
Inverse view matrix Camera.GetMatrix float4x4 "VIEWI", "VIEWINVERSE", "VIEWINVERSEMATRIX", "VI"
Transposed, inverse world matrix float4x4 "WORLDIT", "WORLDINVERSETRANSPOSE", "WORLDTRANSPOSEINVERSE", "WIT"
Transposed, inverse view matrix float4x4 "VIEWIT", "VIEWINVERSETRANSPOSE", "VIEWTRANSPOSEINVERSE", "VIT"
Camera (Eye) position Camera.GetPosition float3   "CAMERAPOS", "CAMERAPOSITION", "VIEWPOS", "VIEWPOSITION"
Simulation time TV.TickCount float    "TIME", "TIMECOUNT", "TICKCOUNT", "SECONDS"
Directional Light Direction float3    "LIGHTDIR0_DIRECTION"
Point Light Positionfloat3    "LIGHTPOINT0_POSITION"
Directional Light Color                          float     "LIGHTDIR0_COLOR"
Point Light Color                          float     "LIGHTPOINT0_COLOR"

you can have 5 simulaneous point/directional lights. (replacing 0 with a number between 0 and 4 will do)


Lights 0-4 are available.

------------------------------------------------------------------------------
How do you apply HLSL Shaders to 3ds Max?

Read this nice tutorial for a good step by step.

http://www.monitorstudios.com/bcloward/tutorials_shaders1.html

------------------------------------------------------------------------------
Is there an editor that lets you use TV to edit shaders

Soul Shader is available.  Please let me know of any problems.

Soul Shader

You must download the ATL/COM dll and register it for this to work.  If it no longer works
its likely the dll interface has changed.  Let me know and I will recompile it.  I will always try to keep everything up to date as possible.

What version is this document?

Revision 4

*Changes and Additions
  - Soul Shader Link Update
  - Spelling Fix
  - Added HLSL 3ds Max Tutorial
Logged

Visit us at:
Chroma
Community Member
*
Posts: 173


« Reply #1 on: August 19, 2004, 07:11:12 PM »

(edit) see above
Logged
sashelas
Community Member
*
Posts: 227


WWW
« Reply #2 on: August 20, 2004, 12:31:19 AM »

Below is a shader demo screenshot.  I'm just blown away by the speed and quality output.  My VB.NET based sample is running at 126 fps at 1600x1200.

http://www.evolvable.com/tv3dshaderdemo.jpg

I need to learn more about passing parameters and using the auto set parameters.  This is fun!!
Logged
Chroma
Community Member
*
Posts: 173


« Reply #3 on: August 25, 2004, 05:17:09 PM »

My meshes are completely white when i apply a shader on them.
Verify if your shader use one of those semantics: AMBIENT, DIFFUSE, EMISSIVE, SPECULARPOWER
TV will fill those parameters with your mesh material values.
U should apply a correct material on the mesh or remove the semantic from the shader file.
Logged
punkouter
Community Member
*
Posts: 202


« Reply #4 on: August 25, 2004, 05:38:51 PM »

are all these FAQ going to be put in one centralized document  maybe along with the 6.5 help file at some point?
Logged

http://www.mattherb.com
now with CATCAM!!
SylvainTV
Administrator
Community Member
*****
Posts: 4944


WWW
« Reply #5 on: August 25, 2004, 05:49:46 PM »

Yes of course.
Logged

Regards

Sylvain Dupont
TrueVision3D Developer
sylvain@truevision3d.com

TV3D IRC at http://chat.truevision3d.com or on server irc.truevision3d.com #Truevision3D. Come talk with us !
[SSSB]Chgros
Community Member
*
Posts: 132


« Reply #6 on: August 26, 2004, 01:59:49 AM »

i have tested shader on tvmesh , and the program don't response mostly....

and after i must reboot.....

It's a big pb... i have tested on exemple with cartoon.fx.

This one don't crash my program but the mesh is not visible.

I have remove the instruction settexture 0 and i see my mesh, but the effect don't render like cartoon effect....


i'm a little bit desapointed...

I have successfully translated a 6.2 program to 6.5 but i'm not able to render shader correctly.

Perhaps some shader effect can't be rendered by my graphics card.

But the shader seem load correctly ... The creation of the shader return the value true

How to prevent crash when i apply a shader on my tvmesh Huh?
Logged
SylvainTV
Administrator
Community Member
*****
Posts: 4944


WWW
« Reply #7 on: August 26, 2004, 05:57:33 AM »

Well thats why it's a "Beta", there are still some problems.
However for most people it works

For the cartoon.fx, I think you need some mesh features that are not by default in the shader. As the engine can't detect yet what semantics to use for the shader, you must give it a hint.

Mesh.SetMeshFormat 17 Smiley

It actually put the bumpmaping info into the mesh.

Please tell me also some information about the crash:
 -> What 3d card do you use ? Latest drivers?
 -> The exact code you used
 -> The cartoon.fx

I need to make sure that it never crashs again. It must be some thing about the shader. I must add more validation to the engine.

Thanks for testing !!
Logged

Regards

Sylvain Dupont
TrueVision3D Developer
sylvain@truevision3d.com

TV3D IRC at http://chat.truevision3d.com or on server irc.truevision3d.com #Truevision3D. Come talk with us !
[SSSB]Chgros
Community Member
*
Posts: 132


« Reply #8 on: August 30, 2004, 01:39:34 AM »

i have reinstall my graphics driver card and now it work !!!!


So i have a question,

I's possible to apply cartoon.fx shader and keeping the textures of my model ?

I  would like to have DBZBUKOKAI effect like...

There's a way for ?
Logged
[SSSB]Chgros
Community Member
*
Posts: 132


« Reply #9 on: September 16, 2004, 02:04:35 AM »

I have tried to use the shaderEx function .

The paramater who interessest me is the idgroup. I have a mesh with a group for cloth and another for the skin.

And i want to apply a metal effect shader on the cloth.


But with shaderex, the cloth are invisible. If i applied the shader on entire mesh the metal effect is on the mesh correctly...

But i don't want to have this effect on the skin of my model....


I sure about my model and his groups. Have done a settextureEx on my two groups for verify and it's work. I can change the cloth texture or the skin texture with no problem.


But i can't do the same with shaderex.

Could you help me please ?

You don't speak about that in this faq, but i think it's important :-p
Logged
Chroma
Community Member
*
Posts: 173


« Reply #10 on: September 16, 2004, 12:09:07 PM »

If u set a shader on a group within a mesh, all other groups of that mesh needs a shader too.
Yes, it's annoying..
Logged
Dan
Customers
Community Member
*****
Posts: 707


WWW
« Reply #11 on: October 13, 2004, 04:13:24 AM »

Am reading a great book at the momment, Is really helping me understand shaders.

Real-Time Shader Programming Covering Directx 9.0 By Ron Fosner
Published by Morgan Kaufmann
ISBN 1-55860-853-2

The book describes low level shader programming, which isn't as much of as a headache as the math involved. I'm finding its giving me a very good base understanding of shaders and a good spring board from which to later pickup HLSL.

A really nice touch is that every page is in colour. unusual for this type of book.
Logged
yor
Community Member
*
Posts: 6


« Reply #12 on: April 07, 2005, 08:38:44 AM »

Ati does not support DirectX 9's Pixel Shader 3.0 - unlike its rival, the GeForce 6800, unveiled by Nvidia.

How do we match the Compatibility

REF:http://www.theregister.co.uk/2004/05/04/ati_confirms_no_shader_3/

This could cause serious problems how can we obtain the compatibly then
Logged
AriusMyst
Guest
« Reply #13 on: April 07, 2005, 09:33:23 AM »

Quote from: "yor"
Ati does not support DirectX 9's Pixel Shader 3.0 - unlike its rival, the GeForce 6800, unveiled by Nvidia.

How do we match the Compatibility

REF:http://www.theregister.co.uk/2004/05/04/ati_confirms_no_shader_3/

This could cause serious problems how can we obtain the compatibly then


You can use TvDeviceInfo to find out the max pixel shader version. Or, you can just add ps2.0 and ps3.0 techniques into your shader. I think tv will automatically go through an see whats supported an pick the right one( i think it does this automatically ).
Logged
Arli
Administrator
Community Member
*****
Posts: 993


« Reply #14 on: April 07, 2005, 11:43:04 AM »

The new R530 (I think that was the code name) thats due in June or something like that will have Shader Model 3 support.. and i doubt that ATI really suffered from leaving out SM3 support in the x800 series as not many games really used it.. and they still had the throne (from reading most reviews) over nvidia.
Logged

Happy Coding

Arli
Truevision3D Developer
Arli@Truevision3D.com
aeon
Customers
Community Member
*****
Posts: 364


WWW
« Reply #15 on: April 12, 2005, 05:38:41 AM »

I have an X300 card and i'm more than happy with it (was an nvidia freak for the longest time!)  VIVA LA ATI!
Logged

GD
Customers
Community Member
*****
Posts: 384


« Reply #16 on: July 29, 2005, 05:36:50 AM »

thanks to Sylvain I found out that if you put semantic TEXTURE0 (or 1,2,3) for texture in your shader, you can change those textures from TV with SetTextureEx.
Logged
brimstone
Community Member
*
Posts: 300


WWW
« Reply #17 on: August 09, 2005, 08:39:26 PM »

the following link in the original post no longer works:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnhlsl/html/shaderx2_introductionto.asp
Logged

Project: ^
Status: ^^.^% complete
dxman.net
klined
Customers
Community Member
*****
Posts: 94


« Reply #18 on: September 01, 2005, 10:59:55 AM »

Maybe thi sis a stupid question. I have tryed to use sharders with TV with no sucess, i have tryed everything and read all posts/sites/articles related, im begining to belive that its not supported by my graphic card, i've serached in nvidia's site, but coundnt find, i have a geforce 4 MX, maybe is this ? Should i have a geforce 4 FX or greater ? Can my card support shader ?

Also, im getting this in SoulShader debug file starts:

09-01-2005 11:59:44 | DEVICE INFO : Pixel Shaders not supported by hardware. Some effects will be disabled.

And this loading shaders:

09-01-2005 11:59:49 | SHADER MANAGER : Shader technique 'Ambient' couldn't be valided.

Thanks!
Logged

--
Andrei Daldegan
GD
Customers
Community Member
*****
Posts: 384


« Reply #19 on: September 01, 2005, 03:33:06 PM »

My GeForce 4 MX didn't have pixel shaders. So, yours don't have either I suppose...
Logged
Pages: [1] 2 3 ... 5
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks