Ejemplo n.º 1
0
        private static void InternalMaterialBitmapFromEvaluator(ShaderBody shader, RenderTexture renderTexture,
                                                                RenderMaterial.StandardChildSlots textureType, Rhino.Geometry.Transform rhinotfm, uint rId, TextureEvaluator actualEvaluator,
                                                                TextureProjectionMode projectionMode, TextureEnvironmentMappingMode envProjectionMode, bool repeat)
        {
            int pheight;
            int pwidth;

            try
            {
                int u, v, w;
                renderTexture.PixelSize(out u, out v, out w);
                pheight = u;
                pwidth  = v;
            }
            catch (Exception)
            {
                pheight = 1024;
                pwidth  = 1024;
            }

            if (pheight == 0 || pwidth == 0)
            {
                pheight = 1024;
                pwidth  = 1024;
            }

            Transform t = new Transform(
                rhinotfm.ToFloatArray(true)
                );

            var isFloat  = renderTexture.IsHdrCapable();
            var isLinear = renderTexture.IsLinear();

            if (isFloat)
            {
                var img = RetrieveFloatsImg(rId, pwidth, pheight, actualEvaluator, false, false, isLinear);
                img.ApplyGamma(shader.Gamma);
                switch (textureType)
                {
                case RenderMaterial.StandardChildSlots.Diffuse:
                    shader.DiffuseTexture.IsLinear = isLinear;
                    shader.DiffuseTexture.TexFloat = img.Data;
                    shader.DiffuseTexture.TexByte  = null;
                    break;

                case RenderMaterial.StandardChildSlots.Bump:
                    shader.BumpTexture.IsLinear = isLinear;
                    shader.BumpTexture.TexFloat = img.Data;
                    shader.BumpTexture.TexByte  = null;
                    break;

                case RenderMaterial.StandardChildSlots.Transparency:
                    shader.TransparencyTexture.IsLinear = isLinear;
                    shader.TransparencyTexture.TexFloat = img.Data;
                    shader.TransparencyTexture.TexByte  = null;
                    break;

                case RenderMaterial.StandardChildSlots.Environment:
                    shader.EnvironmentTexture.IsLinear = isLinear;
                    shader.EnvironmentTexture.TexFloat = img.Data;
                    shader.EnvironmentTexture.TexByte  = null;
                    break;
                }
            }
            else
            {
                var img = RetrieveBytesImg(rId, pwidth, pheight, actualEvaluator, false, false, isLinear);
                img.ApplyGamma(shader.Gamma);
                switch (textureType)
                {
                case RenderMaterial.StandardChildSlots.Diffuse:
                    shader.DiffuseTexture.IsLinear = isLinear;
                    shader.DiffuseTexture.TexFloat = null;
                    shader.DiffuseTexture.TexByte  = img.Data;
                    break;

                case RenderMaterial.StandardChildSlots.Bump:
                    shader.BumpTexture.IsLinear = isLinear;
                    shader.BumpTexture.TexFloat = null;
                    shader.BumpTexture.TexByte  = img.Data;
                    break;

                case RenderMaterial.StandardChildSlots.Transparency:
                    shader.TransparencyTexture.IsLinear = isLinear;
                    shader.TransparencyTexture.TexFloat = null;
                    shader.TransparencyTexture.TexByte  = img.Data;
                    break;

                case RenderMaterial.StandardChildSlots.Environment:
                    shader.EnvironmentTexture.IsLinear = isLinear;
                    shader.EnvironmentTexture.TexFloat = null;
                    shader.EnvironmentTexture.TexByte  = img.Data;
                    break;
                }
            }
            switch (textureType)
            {
            case RenderMaterial.StandardChildSlots.Diffuse:
                shader.DiffuseTexture.TexWidth          = pwidth;
                shader.DiffuseTexture.TexHeight         = pheight;
                shader.DiffuseTexture.ProjectionMode    = projectionMode;
                shader.DiffuseTexture.EnvProjectionMode = envProjectionMode;
                shader.DiffuseTexture.Transform         = t;
                shader.DiffuseTexture.Repeat            = repeat;
                shader.DiffuseTexture.Name = rId.ToString(CultureInfo.InvariantCulture);
                break;

            case RenderMaterial.StandardChildSlots.Bump:
                shader.BumpTexture.TexWidth          = pwidth;
                shader.BumpTexture.TexHeight         = pheight;
                shader.BumpTexture.ProjectionMode    = projectionMode;
                shader.BumpTexture.EnvProjectionMode = envProjectionMode;
                shader.BumpTexture.Transform         = t;
                shader.BumpTexture.Repeat            = repeat;
                shader.BumpTexture.Name = rId.ToString(CultureInfo.InvariantCulture);
                break;

            case RenderMaterial.StandardChildSlots.Transparency:
                shader.TransparencyTexture.TexWidth          = pwidth;
                shader.TransparencyTexture.TexHeight         = pheight;
                shader.TransparencyTexture.ProjectionMode    = projectionMode;
                shader.TransparencyTexture.EnvProjectionMode = envProjectionMode;
                shader.TransparencyTexture.Transform         = t;
                shader.TransparencyTexture.Repeat            = repeat;
                shader.TransparencyTexture.Name = rId.ToString(CultureInfo.InvariantCulture);
                break;

            case RenderMaterial.StandardChildSlots.Environment:
                shader.EnvironmentTexture.TexWidth  = pwidth;
                shader.EnvironmentTexture.TexHeight = pheight;
                // special texture, always set to Environment/Emap
                shader.EnvironmentTexture.ProjectionMode    = TextureProjectionMode.EnvironmentMap;
                shader.EnvironmentTexture.EnvProjectionMode = TextureEnvironmentMappingMode.EnvironmentMap;
                shader.EnvironmentTexture.Transform         = t;
                shader.EnvironmentTexture.Repeat            = repeat;
                shader.EnvironmentTexture.Name = rId.ToString(CultureInfo.InvariantCulture);
                break;
            }
        }
Ejemplo n.º 2
0
 public static bool GetEnvironmentMappingProjection(TextureEnvironmentMappingMode mode, Vector3d reflectionVector, out float u, out float v)
 {
   u = v = 0;
   return UnsafeNativeMethods.Rdk_RenderTexture_EnvironmentMappingProjection((int) mode, reflectionVector, ref u, ref v);
 }
Ejemplo n.º 3
0
 public void SetEnvironmentMappingMode(TextureEnvironmentMappingMode value, ChangeContexts changeContext)
 {
   var pointer = NonConstPointer();
   UnsafeNativeMethods.Rdk_RenderTexture_SetIntValue(pointer, ENVIRONMENT_MAPPING_MODE, (int)value, (int)changeContext);
 }
Ejemplo n.º 4
0
        private static void InternalMaterialBitmapFromEvaluator(CyclesShader shader, RenderTexture renderTexture,
			RenderMaterial.StandardChildSlots textureType, Rhino.Geometry.Transform rhinotfm, uint rId, TextureEvaluator actualEvaluator,
			TextureProjectionMode projectionMode, TextureEnvironmentMappingMode envProjectionMode)
        {
            int pheight;
            int pwidth;
            try
            {
                int u, v, w;
                renderTexture.PixelSize(out u, out v, out w);
                pheight = u;
                pwidth = v;
            }
            catch (Exception)
            {
                pheight = 1024;
                pwidth = 1024;
            }

            if (pheight == 0 || pwidth == 0)
            {
                pheight = 1024;
                pwidth = 1024;
            }

            Transform t = new Transform(
                rhinotfm.ToFloatArray(true)
                );

            var isFloat = renderTexture.IsHdrCapable();
            var isLinear = renderTexture.IsLinear();

            if (isFloat)
            {
                var img = RetrieveFloatsImg(rId, pwidth, pheight, actualEvaluator, false, false, isLinear);
                img.ApplyGamma(shader.Gamma);
                switch (textureType)
                {
                    case RenderMaterial.StandardChildSlots.Diffuse:
                        shader.DiffuseTexture.IsLinear = isLinear;
                        shader.DiffuseTexture.TexFloat = img.Data;
                        shader.DiffuseTexture.TexByte = null;
                        break;
                    case RenderMaterial.StandardChildSlots.Bump:
                        shader.BumpTexture.IsLinear = isLinear;
                        shader.BumpTexture.TexFloat = img.Data;
                        shader.BumpTexture.TexByte = null;
                        break;
                    case RenderMaterial.StandardChildSlots.Transparency:
                        shader.TransparencyTexture.IsLinear = isLinear;
                        shader.TransparencyTexture.TexFloat = img.Data;
                        shader.TransparencyTexture.TexByte = null;
                        break;
                    case RenderMaterial.StandardChildSlots.Environment:
                        shader.EnvironmentTexture.IsLinear = isLinear;
                        shader.EnvironmentTexture.TexFloat = img.Data;
                        shader.EnvironmentTexture.TexByte = null;
                        break;
                }
            }
            else
            {
                var img = RetrieveBytesImg(rId, pwidth, pheight, actualEvaluator, false, false, isLinear);
                img.ApplyGamma(shader.Gamma);
                switch (textureType)
                {
                    case RenderMaterial.StandardChildSlots.Diffuse:
                        shader.DiffuseTexture.IsLinear = isLinear;
                        shader.DiffuseTexture.TexFloat = null;
                        shader.DiffuseTexture.TexByte = img.Data;
                        break;
                    case RenderMaterial.StandardChildSlots.Bump:
                        shader.BumpTexture.IsLinear = isLinear;
                        shader.BumpTexture.TexFloat = null;
                        shader.BumpTexture.TexByte = img.Data;
                        break;
                    case RenderMaterial.StandardChildSlots.Transparency:
                        shader.TransparencyTexture.IsLinear = isLinear;
                        shader.TransparencyTexture.TexFloat = null;
                        shader.TransparencyTexture.TexByte = img.Data;
                        break;
                    case RenderMaterial.StandardChildSlots.Environment:
                        shader.EnvironmentTexture.IsLinear = isLinear;
                        shader.EnvironmentTexture.TexFloat = null;
                        shader.EnvironmentTexture.TexByte = img.Data;
                        break;
                }
            }
            switch (textureType)
            {
                case RenderMaterial.StandardChildSlots.Diffuse:
                    shader.DiffuseTexture.TexWidth = pwidth;
                    shader.DiffuseTexture.TexHeight = pheight;
                    shader.DiffuseTexture.ProjectionMode = projectionMode;
                    shader.DiffuseTexture.EnvProjectionMode = envProjectionMode;
                    shader.DiffuseTexture.Transform = t;
                    shader.DiffuseTexture.Name = rId.ToString(CultureInfo.InvariantCulture);
                    break;
                case RenderMaterial.StandardChildSlots.Bump:
                    shader.BumpTexture.TexWidth = pwidth;
                    shader.BumpTexture.TexHeight = pheight;
                    shader.BumpTexture.ProjectionMode = projectionMode;
                    shader.BumpTexture.EnvProjectionMode = envProjectionMode;
                    shader.BumpTexture.Transform = t;
                    shader.BumpTexture.Name = rId.ToString(CultureInfo.InvariantCulture);
                    break;
                case RenderMaterial.StandardChildSlots.Transparency:
                    shader.TransparencyTexture.TexWidth = pwidth;
                    shader.TransparencyTexture.TexHeight = pheight;
                    shader.TransparencyTexture.ProjectionMode = projectionMode;
                    shader.TransparencyTexture.EnvProjectionMode = envProjectionMode;
                    shader.TransparencyTexture.Transform = t;
                    shader.TransparencyTexture.Name = rId.ToString(CultureInfo.InvariantCulture);
                    break;
                case RenderMaterial.StandardChildSlots.Environment:
                    shader.EnvironmentTexture.TexWidth = pwidth;
                    shader.EnvironmentTexture.TexHeight = pheight;
                    // special texture, always set to Environment/Emap
                    shader.EnvironmentTexture.ProjectionMode = TextureProjectionMode.EnvironmentMap;
                    shader.EnvironmentTexture.EnvProjectionMode = TextureEnvironmentMappingMode.EnvironmentMap;
                    shader.EnvironmentTexture.Transform = t;
                    shader.EnvironmentTexture.Name = rId.ToString(CultureInfo.InvariantCulture);
                    break;
            }
        }
Ejemplo n.º 5
0
 public static bool GetEnvironmentMappingProjection(TextureEnvironmentMappingMode mode, Vector3d reflectionVector, out float u, out float v)
 {
     u = v = 0;
     return(UnsafeNativeMethods.Rdk_RenderTexture_EnvironmentMappingProjection((int)mode, reflectionVector, ref u, ref v));
 }
Ejemplo n.º 6
0
        public void SetEnvironmentMappingMode(TextureEnvironmentMappingMode value, ChangeContexts changeContext)
        {
            var pointer = NonConstPointer();

            UnsafeNativeMethods.Rdk_RenderTexture_SetIntValue(pointer, ENVIRONMENT_MAPPING_MODE, (int)value, (int)changeContext);
        }