- Home /
Referencing the current pixel's world coordinates in the SURF block of a shader
I have been reading, searching and experimenting for a couple days now, and I cannot seem to figure this out. And excuse me if I'm asking completely the wrong question; If there's an easier way to generate specular reflection in a surface shader, PLEASE let me know!
I've been reading the Manual and various blogs, but the information is both far too sparse AND too immediately advanced to figure out.
I have a number of questions about shaders but at the moment I'd just like to know how to get and then reference the world coordinates of the pixel currently being determined by a shader. In my 'surf' struct I need to reference the current pixels' position to calculate specular reflection. I've seen pages that say I should have a vert struct, but then how to I then access the appdata_full.vertex elsewhere in my shader - namely in the surf function where the color calculations are made?
Cheers.
Answer by moosefetcher · Jan 21, 2016 at 04:18 PM
Maybe I didn't quite have a good enough grip of what I was asking, but, in case it's useful to someone, I've figured it out:
You can access the current pixel's interpolated world coordinates through the 'Input IN' parameter of the surf struct. Just Include
float3 worldPos;
in the Input struct and you will have access to the pixel's world coordinates via IN.worldPos. Sorted.