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.

DarkBASIC Professional Discussion / Problem running a simple shader in DBPro

Author
Message
GrumpyOne
18
Years of Service
User Offline
Joined: 27th Nov 2007
Location: London, UK
Posted: 24th Oct 2010 21:39
Hi All,

I've written a few shaders, no problems. However, I just tried to write a really simple program just to test a shader and it won't work. I've even tried using the most simple shader I can think of, still no dice. I don't think it is the shader code, but I can't see any problem with the way I've called it from DBPro. I've spent several hours staring at it now, changing variables etc, and it is driving me a little bit crazy. The object the shader is applied to disappears.

The DBPro code is real simple:



The shader just applies an ambient light and is real simple. See below:



Is there something really simple I am missing?

Thanks,
Mr Grumpy

GrumpyOne - the natural state of the programmer
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 24th Oct 2010 23:00 Edited at: 24th Oct 2010 23:01
You forgot to add the semantics which tell DBPro which variables contain the World, View and Projection matrices. It is not enough to give the variables the same names (you might have used them for something else in the shader for example).

This is what you need:



With those semantics added your shader works fine.

I usually give the matrices different names so I don't make that mistake. For example, I often use the following (with corresponding changes to the variable names elsewhere in the code of course)



In your particular shader you only need the WorldViewProjection matrix of course, but I guess you were just practising.

Shaders are fun when you get past the basics. Good luck with this.
GrumpyOne
18
Years of Service
User Offline
Joined: 27th Nov 2007
Location: London, UK
Posted: 24th Oct 2010 23:37
Thanks GG! So much for the quality of the tutorial I was following! But perhaps because it was for shaders run in XNA.

Would you know what the difference between the View and WorldView semantics are?

Many thanks,
Grumpy One

GrumpyOne - the natural state of the programmer
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 25th Oct 2010 00:47
Quote: "Would you know what the difference between the View and WorldView semantics are?"


Yes.

You need the World matrix to allow for the model's world position and any scaling that's been applied. If the object is at the world's origin and you haven't scaled it then you probably don't need the World matrix - but the overhead in using it is tiny so it's best to play safe. The WorldView matrix is just the product of the World and View matrices.

In coordinate space terms, the shader reads object space coordinates (these are the things you'll find in an X file for example). These then get converted to World space coordinates using the World matrix to allow for the object's position in the world plus any scaling. These then have to be converted to the camera's coordinate system with the View matrix. Finally the View space coordinates need to be projected into screen space coordinates using the Projection matrix. These steps use, in turn, the World, View and Projection matrices and in different shaders you might see them combined into the WorldView, ViewProjection or WorldViewProjection matrices. Typically the output position is calculated using something like



(using my naming system mentioned earlier).

This is the same as



or



or

.

The first of these four is obviously more efficient (unless the shader compiler's optimizer spots the simplification anyway). Occasionally you need to separate the steps beause of other calculations you are doing.

Your code was using the second version written out as three separate lines of code.

Login to post a reply

Server time is: 2026-07-22 03:51:35
Your offset time is: 2026-07-22 03:51:35