- Home /
 
               Question by 
               scarecrow77 · Jan 27, 2013 at 01:52 AM · 
                shadertexture3dvolumetric  
              
 
              Unity 4 Texture3D problems
I'm using Unity 4 and wondering why this code I've adapted from code posted here doesn't work. My cube which I have applied my script and shader to ends up black. I've found someone here with the same problem but no answer.
My C# script to generate the Texture3D:
 using UnityEngine;
 using System.Collections;
 
 public class Create3DTex : MonoBehaviour {
     
     private Texture3D tex;
     public int size = 16;
     
     void Update ()
     {
         tex = new Texture3D(size, size, size, TextureFormat.ARGB32, true);
         Color[] cols = new Color[size*size*size];
         
         int colourCount = 0;
 
         for (int z = 0; z < size; z++)
         {
             for (int y = 0; y < size; y++)
             {
                 for (int x = 0; x < size; x++)
                 {
                     cols[colourCount] = new Color(1,0,0,1);
                     colourCount++;
                 }
             }
         }
         
         tex.SetPixels (cols);
         tex.Apply ();
 
         renderer.material.SetTexture ("_MyTex", tex);
     }
     
 }
My Shader code:
 Shader "Custom/VolumeShader" {
     Properties {
         _MyTex ("Some Texture",3D) = "white" {}
     }
     SubShader {
         Blend SrcAlpha OneMinusSrcAlpha
         Cull Off
         Pass {
 
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             #include "UnityCG.cginc"
             
             sampler3D _MyTex;
             
             struct v2f {
                 float4 pos : SV_POSITION;
                 float3 uv : TEXCOORD;
             };
 
             v2f vert (appdata_base v)
             {
                 v2f o;
                 o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
                 o.uv = v.vertex.xyz*0.5+0.5;
                 return o;
             }
             
             float4 frag (v2f i) : COLOR
             {
                 float4 outColor = tex3D (_MyTex, i.uv);
                 return outColor;
             }
             
             ENDCG
             
         }
     }
     FallBack "VertexLit"
 }
Thank you!
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                