Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
pictionaryjr
17
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 8th Oct 2013 04:59 Edited at: 8th Oct 2013 05:06
Okay I've been around the forums for a while, but I've never ventured into the area of Shaders. I understand the pipeline, but am wondering where to get started with writing my own Shader code. What are programs I can use to do this. Is FX composer still even an option considering its soo old. Any tutorial links to help me out.

@All
I would have posted this on the learning to write shaders thread, but it has finally expired

Edit:
I do own Dark Shader and am wondering if I can use that to create my own shaders
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 8th Oct 2013 13:47 Edited at: 8th Oct 2013 13:49
Dark Shader is a nice tool for simple shader development. Why not take a look at some of the shader projects that ship with it. See how they are writen and observe what happens when you make adjustments.

Shaders where developed to provide a scriptable 3D pipline and are broken down into two areas; vertex and pixel.

Vertex shaders deal with the actual 3D, the positioning of points which define the overal shape of the object; the polygons which are composed of 3 or more vertices in most situations, but can also feature vertices scattered without forming polygons for use with point sprites; or particle effects. A vertex function found in most of the Dark Shader examples return a class instance which contains UV coordinates and 3D positions amongst other things.

Pixel shaders are called by the engine to render the polygons on screen, pixel by pixel. This is where textures can are sampled using a customizable source of UV coordinates to return a colour back to the enginer for use in the screen render.

You can get a run down on the HLSL language in the MSDN library

You can browse the HLSL documentation here

It would be good idea to post any questions regarding what you do not understand in the shaders examples specifically.

pictionaryjr
17
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 8th Oct 2013 18:13
Thanks for the help Chris. Will be diving in
pictionaryjr
17
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 9th Oct 2013 01:02
Okay... So I've been looking into this all day today and now I'm wondering. How can I get a shader to effect a point in 3d space.

Better Explained

I have a plain demonstrated by the 0's, and I basically want to draw a square on it. How can I specify to my shader where I want this square to be drawn at?

0000000000000000000
0000000000000000000
00000000000------00
00000000000-0000-00
00000000000-0000-00
00000000000------00
0000000000000000000
0000000000000000000
0000000000000000000
0000000000000000000
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 9th Oct 2013 04:18
That requires colour control, which is handled by your pixel shader function. This function is called every time your shader needs to draw a single pixel representing your object. You can select a colour for the pixels positioned on top of the border of the square like so:



I used constant colours but you could also sample various textures using the tex2D function. It is only worth hard coding a square pattern if a texture with a square on it would not suffice; but at least it is a reasonable example of how it could all work.

It was compiled using shader model 2 as shown again here:

VertexShader = compile vs_2_0 DefaultVertexShader( );
PixelShader = compile vs_2_0 DefaultPixelShader( );

pictionaryjr
17
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 9th Oct 2013 05:47 Edited at: 9th Oct 2013 05:50
I gave it a run and got an error, but fixed it. I think I can manipulate this to what I would like to do with it. This shader stuff is far trickier than I was originally anticipating. Random question. I was viewing some of evolved's light code from his flashlight coding and was confused about this one bit of code:



I'm trying to get this whole shader thing down and I hit this and started getting a little confused at whats going on. I believe he uses vector 1 containing 4 floats to pass off the camera positions as the light position to the shader. Then he takes the x and y angles of the camera, converts them to radians and stores them somewhere( confused here ) inside the matrices. He then multiplies the matrices together which I assume is like performing a rotation matrice. He then appears to create vectors that contain normals or is building anothing rotation matrice. He then creates the lhmatrix and another for the field of view matrix and then multiplies them which is a way of getting the rotated 3d points I assume? Like I said I'm pretty lost so if someone could please explain that to me it would be greatly appreciated.
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 9th Oct 2013 12:24 Edited at: 9th Oct 2013 12:25
Interesting, what kind of error was that? No error should have occurred.

I have not looked at the Evolved light projection shader before; your question is more about trigonometry than HLSL. All of those parameters are trigonometry used to emulate a projector shining towards the given surfaces; a projection matrix is calculated so that the shader can determine which polygons are in the frustum of the flash light.

I could not tell you why it works because I am not familiar with this technology; perhaps someone else or possibly Evolved himself will give you a mathematical answer, but your guess is as good as mine.

If a trig-wizard doesn't give you an answer, it might be worth tracking down this algorithm on the internet, where it may be explained in depth.

pictionaryjr
17
Years of Service
User Offline
Joined: 12th Mar 2009
Location:
Posted: 9th Oct 2013 15:54
The error was in the bottom of the code where you tell the program which one is the vertex shader and which is the pixel shader.

You used
compile vs_2_0 DefaultPixelShader( )
instead of
compile ps_2_0 DefaultPixelShader( )

and yea sorry the trig question was a bit random and thanks for explaining the projection part. I think I understand the math now. I was looking at it as a simple rotation matrix instead of a projection. Now I understand why he did it like this. I will be positing a pic of what I got working with the shader box thing in a second. Thank you for all your help Chris
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 9th Oct 2013 22:09
Silly mistake. I saw no error message on my system though. Good luck.

Login to post a reply

Server time is: 2026-07-07 03:47:26
Your offset time is: 2026-07-07 03:47:26