- Home /
Question by
bpears · May 26, 2018 at 11:27 PM ·
reflectionsurface shaderprobesdeferred
How to use realtime reflection probe in custom surface shader (Deferred Rendering)?
Is there a way to assign a reflection cube in the inspector? Is there an input type for them? I have the object set up to use it in its renderer, but in deferred rendering, it does not work I'm aware. But how to MAKE it work?
How can I for example use this unity example of fragment reflection as a surface shader?
Shader "Unlit/SkyReflection"
{
SubShader
{
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f {
half3 worldRefl : TEXCOORD0;
float4 pos : SV_POSITION;
};
v2f vert (float4 vertex : POSITION, float3 normal : NORMAL)
{
v2f o;
o.pos = UnityObjectToClipPos(vertex);
// compute world space position of the vertex
float3 worldPos = mul(_Object2World, vertex).xyz;
// compute world space view direction
float3 worldViewDir = normalize(UnityWorldSpaceViewDir(worldPos));
// world space normal
float3 worldNormal = UnityObjectToWorldNormal(normal);
// world space reflection vector
o.worldRefl = reflect(-worldViewDir, worldNormal);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the default reflection cubemap, using the reflection vector
half4 skyData = UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, i.worldRefl);
// decode cubemap data into actual color
half3 skyColor = DecodeHDR (skyData, unity_SpecCube0_HDR);
// output it!
fixed4 c = 0;
c.rgb = skyColor;
return c;
}
ENDCG
}
}
}
Comment
Any idears? Or am I looking at this all wrong? I'm on latest unity 5 btw not 2018. Not sure if there is a difference in regards to this.