- Home /
Question by
Chimera3D · Sep 01, 2014 at 06:56 AM ·
shader3drendertexturefragment
Writing from fragment shader into 3D render texture
It's pretty much all in the title, how can I go about rendering into a 3D render texture with a fragment shader?
EDIT: Is there some sort of "layer" input I can use?
Comment
Answer by EJSainz · Mar 05, 2017 at 03:30 PM
Better late than never...
Shader "Custom/Tex3DSlice" {
Properties
{
_MainTex("3D Texture", 3D) = "white" {}
_Depth("Depth", Range(0,1)) = 0.5
}
SubShader {
Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" }
LOD 200
Cull Off
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows alpha:fade
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler3D _MainTex;
struct Input {
float2 uv_MainTex;
};
half _Depth;
void surf (Input IN, inout SurfaceOutputStandard o) {
// Albedo comes from a texture tinted by color
float3 uvw = float3(IN.uv_MainTex.x, IN.uv_MainTex.y, _Depth);
fixed4 c = tex3D (_MainTex, uvw);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Standard"
}