U 3.0 surface shader : access to list of other objects

Can surface shader access a list of other objects’s position?

I’d like to darken objects based on other object’s proximity to simulate inter-object AO.

“Surface shaders” is not some magic that suddenly gives you access to everything in the world :slight_smile: Surface shader is just something from which a vertex a pixel shader is generated.

A vertex shader works on one vertex.
A pixel shader works on one pixel.

They don’t know anything about any other vertices or any other pixels or any other objects.

That said, you can make a shader with a set of vector properies and set them to the positions of nearby objects in Update(). This is nothing new in Unity 3.

Thanks guys, this is so frikin’ awesome !!!

Now I’d like to compute the delta position on the shader, so all the c# script does is pipe in the occluding object’s positions.

I see that surface shaders have IN.worldPos and I tried the same keyword for s.worldPos, Unity is giving me an error. Is the keyword different ?

error : “Program ‘surf’, expression left of .“worldPos” is not a struct or array at line 29”

What is “s.worldPos”? Moar context please.

half4 CustomProxymityLighting (SurfaceOutput s, half3 lightDir, half atten)

s.worldPos is the world position of the surface point that’s being processed

Well, SurfaceOutput structure does not have a member “worldPos”. SurfaceOutput is declared in UnityCG.cginc, and it is:

struct SurfaceOutput {
    half3 Albedo;
    half3 Normal;
    half3 Emission;
    half Specular;
    half Gloss;
    half Alpha;
};

Is there further documentation on what I can put after #pragma ? ie. #pragma surface surf Blinn or Phong? (They don’t work at the moment, only Lambert).

It’s BlinnPhong, all one word. All the options are documented on the first page about surface shaders.