Ejemplo n.º 1
0
        internal static int PrepareVolumePreview(Material material, Texture texture, Vector3 scale, float opacity,
                                                 FilterMode filterMode, bool colorRamp, Gradient customColorRamp, Camera camera, Matrix4x4 trs, float qualityModifier = 2)
        {
            float   inverseResolution;
            Vector3 inverseScale;

            PrepareGeneralPreview(material, texture, out inverseScale, out inverseResolution, customColorRamp);
            uint colorChannelCount = GraphicsFormatUtility.GetColorComponentCount(texture.graphicsFormat);

            material.SetVector(MaterialProps.globalScale, scale);
            material.SetFloat(MaterialProps.ramp, Convert.ToSingle(colorRamp));
            material.SetFloat(MaterialProps.invResolution, inverseResolution);
            material.SetVector(MaterialProps.invChannels, new Vector3(1.0f / colorChannelCount, 1.0f / colorChannelCount, 1.0f / colorChannelCount));
            material.SetFloat(MaterialProps.alpha, Mathf.Pow(Mathf.Clamp01(opacity), 3));
            material.SetFloat(MaterialProps.filterMode, Convert.ToSingle(filterMode));

            float quality = inverseResolution / qualityModifier / 2;

            material.SetFloat(MaterialProps.quality, quality);

            material.SetMatrix("_CamToW", camera.cameraToWorldMatrix);
            material.SetMatrix("_WToCam", camera.worldToCameraMatrix);
            material.SetMatrix("_ObjToW", trs);
            material.SetMatrix("_WToObj", trs.inverse);

            return(Convert.ToInt32(1 / inverseResolution * qualityModifier * 2));
        }
Ejemplo n.º 2
0
        void InitPreviewUtility()
        {
            if (m_PreviewUtility == null)
            {
                m_PreviewUtility = new PreviewRenderUtility();
                m_PreviewUtility.camera.fieldOfView = 30.0f;
                m_Preview3DMode = Preview3DMode.Volume;
                m_Texture       = target as Texture3D;
                m_PreviewDir    = new Vector2(0, 0);
                m_Channels      = Mathf.Clamp(GraphicsFormatUtility.GetColorComponentCount(m_Texture.graphicsFormat), 1, 3);

                CalculateResolutionAndScale(m_Texture);
                m_ViewDistance = Mathf.Lerp(1, 3, Mathf.Clamp01(m_Scale.magnitude - 0.414f));
                m_PreviewUtility.camera.farClipPlane  = s_MaxViewDistance + 1;
                m_PreviewUtility.camera.nearClipPlane = 0.01f;
            }
        }
Ejemplo n.º 3
0
        internal static void PrepareSlicePreview(Material material, Texture texture, Vector3 slice,
                                                 FilterMode filterMode, bool colorRamp = false, Gradient customColorRamp = null)
        {
            float   inverseResolution;
            Vector3 inverseScale;

            PrepareGeneralPreview(material, texture, out inverseScale, out inverseResolution, customColorRamp);
            uint colorChannelCount = GraphicsFormatUtility.GetColorComponentCount(texture.graphicsFormat);

            Vector3 voxelSize         = material.GetVector("_VoxelSize");
            Vector3 textureResolution = GetTextureResolution(texture);
            Vector3 positions         = new Vector3(slice.x / textureResolution.x, slice.y / textureResolution.y, slice.z / textureResolution.z);

            positions.x = Mathf.Clamp01(positions.x);
            positions.y = Mathf.Clamp01(positions.y);
            positions.z = Mathf.Clamp01(positions.z);
            positions  -= new Vector3(0.5f, 0.5f, 0.5f);
            positions.Scale(voxelSize);
            material.SetVector(MaterialProps.positions, positions);
            material.SetVector(MaterialProps.invChannels, new Vector3(1.0f / colorChannelCount, 1.0f / colorChannelCount, 1.0f / colorChannelCount));
            material.SetFloat(MaterialProps.filterMode, Convert.ToSingle(filterMode));
            material.SetFloat(MaterialProps.ramp, Convert.ToSingle(colorRamp));
        }