Example #1
0
 public ShaderBody(uint id)
 {
     Id                  = id;
     DiffuseTexture      = new CyclesTextureImage();
     BumpTexture         = new CyclesTextureImage();
     TransparencyTexture = new CyclesTextureImage();
     EnvironmentTexture  = new CyclesTextureImage();
     GiEnvTexture        = new CyclesTextureImage();
     BgEnvTexture        = new CyclesTextureImage();
     ReflRefrEnvTexture  = new CyclesTextureImage();
     CyclesMaterialType  = CyclesMaterial.No;
 }
Example #2
0
 internal static void SetTextureImage(ImageTextureNode imnode, CyclesTextureImage texture)
 {
     if (texture.HasTextureImage)
     {
         if (texture.HasByteImage)
         {
             imnode.ByteImage = texture.TexByte;
         }
         else if (texture.HasFloatImage)
         {
             imnode.FloatImage = texture.TexFloat;
         }
         imnode.Filename = texture.Name;
         imnode.Width    = (uint)texture.TexWidth;
         imnode.Height   = (uint)texture.TexHeight;
     }
 }
 internal static void SetTextureImage(ImageTextureNode imnode, CyclesTextureImage texture)
 {
     if (texture.HasTextureImage)
     {
         if (texture.HasByteImage)
         {
             imnode.ByteImage = texture.TexByte;
         }
         else if (texture.HasFloatImage)
         {
             imnode.FloatImage = texture.TexFloat;
         }
         imnode.Filename = texture.Name;
         imnode.Width = (uint) texture.TexWidth;
         imnode.Height = (uint) texture.TexHeight;
     }
 }
Example #4
0
 internal static void SetTextureImage(EnvironmentTextureNode envnode, CyclesTextureImage texture)
 {
     if (texture.HasTextureImage)
     {
         if (texture.HasByteImage)
         {
             envnode.ByteImage = texture.TexByte;
         }
         else if (texture.HasFloatImage)
         {
             envnode.FloatImage    = texture.TexFloat;
             envnode.Interpolation = InterpolationType.Cubic;
         }
         envnode.Filename = texture.Name;
         envnode.Width    = (uint)texture.TexWidth;
         envnode.Height   = (uint)texture.TexHeight;
     }
 }
 internal static void SetTextureImage(EnvironmentTextureNode envnode, CyclesTextureImage texture)
 {
     if (texture.HasTextureImage)
     {
         if (texture.HasByteImage)
         {
             envnode.ByteImage = texture.TexByte;
         }
         else if (texture.HasFloatImage)
         {
             envnode.FloatImage = texture.TexFloat;
             envnode.Interpolation = InterpolationType.Cubic;
         }
         envnode.Filename = texture.Name;
         envnode.Width = (uint) texture.TexWidth;
         envnode.Height = (uint) texture.TexHeight;
     }
 }
Example #6
0
        static private void LoadOneTexture(CyclesTextureImage tex, Dictionary <uint, ByteBitmap> bytes, Dictionary <uint, FloatBitmap> floats)
        {
            uint rid;

            if (uint.TryParse(tex.Name, out rid))
            {
                if (tex.HasByteImage)
                {
                    if (bytes.ContainsKey(rid))
                    {
                        tex.TexByte = bytes[rid].Data;
                    }
                }
                else if (tex.HasFloatImage)
                {
                    if (floats.ContainsKey(rid))
                    {
                        tex.TexFloat = floats[rid].Data;
                    }
                }
            }
        }
Example #7
0
 public CyclesShader()
 {
     DiffuseTexture = new CyclesTextureImage();
     BumpTexture = new CyclesTextureImage();
     TransparencyTexture = new CyclesTextureImage();
     EnvironmentTexture = new CyclesTextureImage();
     GiEnvTexture = new CyclesTextureImage();
     BgEnvTexture = new CyclesTextureImage();
     ReflRefrEnvTexture = new CyclesTextureImage();
     CyclesMaterialType = CyclesMaterial.No;
 }
Example #8
0
        /// <summary>
        /// Set image texture node and link up with correct TextureCoordinateNode output based on
        /// texture ProjectionMode.
        ///
        /// This may add new nodes to the shader!
        /// </summary>
        /// <param name="shader"></param>
        /// <param name="texture"></param>
        /// <param name="image_node"></param>
        /// <param name="texture_coordinates"></param>
        public static void SetProjectionMode(Shader shader, CyclesTextureImage texture, ImageTextureNode image_node,
                                             TextureCoordinateNode texture_coordinates)
        {
            if (!texture.HasTextureImage)
            {
                return;
            }

            Guid g = Guid.NewGuid();

            texture_coordinates.UseTransform = false;

            var tfm = new MatrixMathNode("texture transform" + g.ToString())
            {
                Transform = texture.Transform
            };

            shader.AddNode(tfm);

            image_node.Projection = TextureNode.TextureProjection.Flat;

            if (texture.ProjectionMode == TextureProjectionMode.WcsBox)
            {
                texture_coordinates.UseTransform = true;
                texture_coordinates.outs.WcsBox.Connect(tfm.ins.Vector);
                tfm.outs.Vector.Connect(image_node.ins.Vector);
            }
            else if (texture.ProjectionMode == TextureProjectionMode.Wcs)
            {
                texture_coordinates.UseTransform = true;
                texture_coordinates.outs.Object.Connect(tfm.ins.Vector);
                tfm.outs.Vector.Connect(image_node.ins.Vector);
            }
            else if (texture.ProjectionMode == TextureProjectionMode.Screen)
            {
                SeparateXyzNode sepvec  = new SeparateXyzNode();
                CombineXyzNode  combvec = new CombineXyzNode();
                MathNode        inverty = new MathNode {
                    Operation = MathNode.Operations.Subtract
                };
                inverty.ins.Value1.Value = 1.0f;
                shader.AddNode(sepvec);
                shader.AddNode(combvec);
                shader.AddNode(inverty);

                texture_coordinates.outs.Window.Connect(sepvec.ins.Vector);

                sepvec.outs.Y.Connect(inverty.ins.Value2);

                sepvec.outs.X.Connect(combvec.ins.X);
                inverty.outs.Value.Connect(combvec.ins.Y);
                sepvec.outs.Z.Connect(combvec.ins.Z);

                combvec.outs.Vector.Connect(tfm.ins.Vector);

                tfm.Transform = tfm.Transform;
                tfm.outs.Vector.Connect(image_node.ins.Vector);
            }
            else if (texture.ProjectionMode == TextureProjectionMode.View)
            {
                texture_coordinates.outs.Camera.Connect(tfm.ins.Vector);
                tfm.outs.Vector.Connect(image_node.ins.Vector);
            }
            else if (texture.ProjectionMode == TextureProjectionMode.EnvironmentMap)
            {
                texture_coordinates.UseTransform = false;
                switch (texture.EnvProjectionMode)
                {
                case TextureEnvironmentMappingMode.Spherical:
                    texture_coordinates.outs.EnvSpherical.Connect(image_node.ins.Vector);
                    break;

                case TextureEnvironmentMappingMode.EnvironmentMap:
                    texture_coordinates.outs.EnvEmap.Connect(image_node.ins.Vector);
                    break;

                case TextureEnvironmentMappingMode.Box:
                    texture_coordinates.outs.EnvBox.Connect(image_node.ins.Vector);
                    break;

                case TextureEnvironmentMappingMode.LightProbe:
                    texture_coordinates.outs.EnvLightProbe.Connect(image_node.ins.Vector);
                    break;

                case TextureEnvironmentMappingMode.Cube:
                    texture_coordinates.outs.EnvCubemap.Connect(image_node.ins.Vector);
                    break;

                case TextureEnvironmentMappingMode.VerticalCrossCube:
                    texture_coordinates.outs.EnvCubemapVerticalCross.Connect(image_node.ins.Vector);
                    break;

                case TextureEnvironmentMappingMode.HorizontalCrossCube:
                    texture_coordinates.outs.EnvCubemapHorizontalCross.Connect(image_node.ins.Vector);
                    break;

                case TextureEnvironmentMappingMode.Hemispherical:
                    texture_coordinates.outs.EnvHemispherical.Connect(image_node.ins.Vector);
                    break;

                default:
                    texture_coordinates.outs.EnvEmap.Connect(image_node.ins.Vector);
                    break;
                }
            }
            else
            {
                texture_coordinates.outs.UV.Connect(tfm.ins.Vector);
                tfm.outs.Vector.Connect(image_node.ins.Vector);
            }
        }
Example #9
0
        /// <summary>
        /// Set image texture node and link up with correct TextureCoordinateNode output based on
        /// texture ProjectionMode.
        /// 
        /// This may add new nodes to the shader!
        /// </summary>
        /// <param name="shader"></param>
        /// <param name="texture"></param>
        /// <param name="image_node"></param>
        /// <param name="texture_coordinates"></param>
        public static void SetProjectionMode(Shader shader, CyclesTextureImage texture, ImageTextureNode image_node,
			TextureCoordinateNode texture_coordinates)
        {
            if (!texture.HasTextureImage) return;

            Guid g = Guid.NewGuid();

            texture_coordinates.UseTransform = false;

            var tfm = new MatrixMathNode("texture transform" + g.ToString())
            {
                Transform = texture.Transform
            };
            shader.AddNode(tfm);

            image_node.Projection = TextureNode.TextureProjection.Flat;

            if (texture.ProjectionMode == TextureProjectionMode.WcsBox)
            {
                texture_coordinates.UseTransform = true;
                texture_coordinates.outs.WcsBox.Connect(tfm.ins.Vector);
                tfm.outs.Vector.Connect(image_node.ins.Vector);
            }
            else if (texture.ProjectionMode == TextureProjectionMode.Wcs)
            {
                texture_coordinates.UseTransform = true;
                texture_coordinates.outs.Object.Connect(tfm.ins.Vector);
                tfm.outs.Vector.Connect(image_node.ins.Vector);
            }
            else if (texture.ProjectionMode == TextureProjectionMode.Screen)
            {
                SeparateXyzNode sepvec = new SeparateXyzNode();
                CombineXyzNode combvec = new CombineXyzNode();
                MathNode inverty = new MathNode {Operation = MathNode.Operations.Subtract};
                inverty.ins.Value1.Value = 1.0f;
                shader.AddNode(sepvec);
                shader.AddNode(combvec);
                shader.AddNode(inverty);

                texture_coordinates.outs.Window.Connect(sepvec.ins.Vector);

                sepvec.outs.Y.Connect(inverty.ins.Value2);

                sepvec.outs.X.Connect(combvec.ins.X);
                inverty.outs.Value.Connect(combvec.ins.Y);
                sepvec.outs.Z.Connect(combvec.ins.Z);

                combvec.outs.Vector.Connect(tfm.ins.Vector);

                tfm.Transform = tfm.Transform;
                tfm.outs.Vector.Connect(image_node.ins.Vector);
            }
            else if (texture.ProjectionMode == TextureProjectionMode.View)
            {
                texture_coordinates.outs.Camera.Connect(tfm.ins.Vector);
                tfm.outs.Vector.Connect(image_node.ins.Vector);
            }
            else if (texture.ProjectionMode == TextureProjectionMode.EnvironmentMap)
            {
                texture_coordinates.UseTransform = false;
                switch (texture.EnvProjectionMode)
                {
                    case TextureEnvironmentMappingMode.Spherical:
                        texture_coordinates.outs.EnvSpherical.Connect(image_node.ins.Vector);
                        break;
                    case TextureEnvironmentMappingMode.EnvironmentMap:
                        texture_coordinates.outs.EnvEmap.Connect(image_node.ins.Vector);
                        break;
                    case TextureEnvironmentMappingMode.Box:
                        texture_coordinates.outs.EnvBox.Connect(image_node.ins.Vector);
                        break;
                    case TextureEnvironmentMappingMode.LightProbe:
                        texture_coordinates.outs.EnvLightProbe.Connect(image_node.ins.Vector);
                        break;
                    case TextureEnvironmentMappingMode.Cube:
                        texture_coordinates.outs.EnvCubemap.Connect(image_node.ins.Vector);
                        break;
                    case TextureEnvironmentMappingMode.VerticalCrossCube:
                        texture_coordinates.outs.EnvCubemapVerticalCross.Connect(image_node.ins.Vector);
                        break;
                    case TextureEnvironmentMappingMode.HorizontalCrossCube:
                        texture_coordinates.outs.EnvCubemapHorizontalCross.Connect(image_node.ins.Vector);
                        break;
                    case TextureEnvironmentMappingMode.Hemispherical:
                        texture_coordinates.outs.EnvHemispherical.Connect(image_node.ins.Vector);
                        break;
                    default:
                        texture_coordinates.outs.EnvLightProbe.Connect(image_node.ins.Vector);
                        break;
                }
            }
            else
            {
                texture_coordinates.outs.UV.Connect(tfm.ins.Vector);
                tfm.outs.Vector.Connect(image_node.ins.Vector);
            }
        }