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 / Question about Shader Model 3

Author
Message
Green Gandalf
13
Years of Service
User Offline
Joined: 3rd Jan 2005
Location: Cornwall UK
Posted: 1st Dec 2017 19:07
Does anyone have a working shader demo which uses texture reads in the vertex shader? That feature was introduced in Shader Model 3 and I'm having unexpected problems getting it to work properly .

I'm fairly sure Evolved posted a demo for one of his water effects several years ago (2007/8 perhaps?) but I don't seem to have a copy on my current machines . If I recall correctly () the demo used the vertex shader to manipulate the heights of the vertices of a high poly plain object representing the ocean or sea. I've got a simple demo of something similar but it just will not work as required - the shader compiles and runs but the vertex texture reads all seem to return the value 1 which is probably a default value set by the GFX card or by DX9 when the texture read fails. I can't seem to locate a single demo shader which shows this feature working - and the MS docs are opaque to put it politely.

Any help or suggestions?
Kuper
10
Years of Service
User Offline
Joined: 25th Feb 2008
Playing: Planescape:Torment
Posted: 2nd Dec 2017 13:03
Evolved use such vertex parallax for water and terrain.You can just check them on his website.
Anyway I attach one from old demo.

Attachments

Login to view attachments
Green Gandalf
13
Years of Service
User Offline
Joined: 3rd Jan 2005
Location: Cornwall UK
Posted: 2nd Dec 2017 14:32 Edited at: 2nd Dec 2017 15:26
Hi Kuper,

Thanks for that. As it happens, Evolved kindly sent me the same demo last night and, after a LOT of checking and experimentation () I discovered my error. It was the sort of error that doesn't get flagged by the compiler and took me some time to spot.

The error was a simple type casting error. I had written the following line of shader code:



The float4 version of the UV coordinates is needed by the tex2Dlod intrinsic function which in turn is the only texture lookup function allowed in an SM3 vertex shader. (No texture lookups are allowed at all in the earlier shader models SM1 and SM2.) However, the extra brackets that I had carelessly put in meant that the final value of tempUV was not what I wanted at all .

I should have written the following:



With that simple change my demo worked perfectly and I am now adding all the extra stuff I need.

Shader connoisseurs might like to consider what values my original version gave to the four components of tempUV. They should have been, In.x, In.y, 0.0 and 0.0. The first two are just the UV coordinates of the current vertex and vary from 0.0 to 1.0 from one edge of the object to the other but in fact my original code meant that a constant value was set. Can you see what that value was - and why?

Edit: the casting rules described on this page explain what happened in my original version - see especially the sections about Cast Operator and Comma Operator.

https://msdn.microsoft.com/en-us/library/windows/desktop/bb509631(v=vs.85).aspx

Login to post a reply

Server time is: 2018-11-21 15:45:43
Your offset time is: 2018-11-21 15:45:43