Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
MaterialTextureNode.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.ComponentModel;
5 using SiliconStudio.Assets;
6 using SiliconStudio.Core;
7 using SiliconStudio.Core.IO;
8 using SiliconStudio.Core.Mathematics;
9 using SiliconStudio.Core.Serialization.Contents;
10 using SiliconStudio.Paradox.Assets.Texture;
11 using SiliconStudio.Paradox.Effects;
12 using SiliconStudio.Paradox.Graphics;
13 
14 namespace SiliconStudio.Paradox.Assets.Materials.Nodes
15 {
16  [ContentSerializer(typeof(DataContentSerializer<MaterialTextureNode>))]
17  [DataContract("MaterialTextureNode")]
19  {
20  /// <summary>
21  /// Constructor
22  /// </summary>
25  {
26  }
27 
28  public MaterialTextureNode(string texturePath, int texcoordIndex, Vector2 scale, Vector2 offset)
29  : this(texturePath, (TextureCoordinate)texcoordIndex, scale, offset)
30  {
31  }
32 
33  /// <summary>
34  /// Initializes a new instance of the <see cref="MaterialTextureNode"/> class.
35  /// </summary>
36  /// <param name="texturePath">Name of the texture.</param>
37  /// <param name="texcoordIndex">Index of the texcoord.</param>
38  /// <param name="scale">The scale.</param>
39  /// <param name="offset">The offset.</param>
40  public MaterialTextureNode(string texturePath, TextureCoordinate texcoordIndex, Vector2 scale, Vector2 offset)
41  {
42  if (texturePath == null)
43  throw new ArgumentNullException("texturePath");
44 
45  TextureReference = new AssetReference<TextureAsset>(Guid.Empty, new UFile(texturePath));
46  TexcoordIndex = texcoordIndex;
47  Sampler = new NodeParameterSampler();
48  Scale = scale;
49  Offset = offset;
50  AutoAssignKey = true;
51  Key = null;
52  UsedParameterKey = null;
53  }
54 
55  /// <summary>
56  /// The texture Reference.
57  /// </summary>
58  /// <userdoc>
59  /// The texture.
60  /// </userdoc>
61  [DataMember(10)]
62  [DefaultValue(null)]
63  public AssetReference<TextureAsset> TextureReference { get; set; }
64 
65  /// <summary>
66  /// The texture coordinate used to sample the texture.
67  /// </summary>
68  /// <userdoc>
69  /// The set of uv used to sample the texture.
70  /// </userdoc>
71  [DataMember(30)]
72  [DefaultValue(TextureCoordinate.Texcoord0)]
73  public TextureCoordinate TexcoordIndex { get; set; }
74 
75  /// <summary>
76  /// The sampler of the texture.
77  /// </summary>
78  /// <userdoc>
79  /// The sampler of the texture.
80  /// </userdoc>
81  [DataMemberIgnore]
82  public NodeParameterSampler Sampler { get; set; }
83 
84  /// <summary>
85  /// The texture filtering mode.
86  /// </summary>
87  /// <userdoc>
88  /// The filtering of the texture.
89  /// </userdoc>
90  [DataMember(41)]
91  [DefaultValue(TextureFilter.Linear)]
92  public TextureFilter Filtering
93  {
94  get
95  {
96  return Sampler.Filtering;
97  }
98  set
99  {
100  Sampler.Filtering = value;
101  }
102  }
103 
104  /// <summary>
105  /// The texture address mode.
106  /// </summary>
107  /// <userdoc>
108  /// The wrapping of the texture along U.
109  /// </userdoc>
110  [DataMember(42)]
111  [DefaultValue(TextureAddressMode.Wrap)]
112  public TextureAddressMode AddressModeU
113  {
114  get
115  {
116  return Sampler.AddressModeU;
117  }
118  set
119  {
120  Sampler.AddressModeU = value;
121  }
122  }
123 
124  /// <summary>
125  /// The texture address mode.
126  /// </summary>
127  /// <userdoc>
128  /// The wrapping of the texture along V.
129  /// </userdoc>
130  [DataMember(43)]
131  [DefaultValue(TextureAddressMode.Wrap)]
132  public TextureAddressMode AddressModeV
133  {
134  get
135  {
136  return Sampler.AddressModeV;
137  }
138  set
139  {
140  Sampler.AddressModeV = value;
141  }
142  }
143 
144  /// <summary>
145  /// The scale of the texture coordinates.
146  /// </summary>
147  /// <userdoc>
148  /// The scale on texture coordinates. Lower than 1 means that the texture will be zoomed in.
149  /// </userdoc>
150  [DataMember(50)]
151  public Vector2 Scale { get; set; }
152 
153  /// <summary>
154  /// The offset in the texture coordinates.
155  /// </summary>
156  /// <userdoc>
157  /// The offset on texture coordinates.
158  /// </userdoc>
159  [DataMember(60)]
160  public Vector2 Offset { get; set; }
161 
162  /// <summary>
163  /// A flag stating if the paramater key is automatically assigned.
164  /// </summary>
165  /// <userdoc>
166  /// If not checked, you can define the key to access the texture at runtime for dynamic changes.
167  /// </userdoc>
168  [DataMember(70)]
169  [DefaultValue(true)]
170  public bool AutoAssignKey { get; set; }
171 
172  /// <summary>
173  /// The desired parameter key.
174  /// </summary>
175  /// <userdoc>
176  /// The key to access the texture at runtime. AutoAssignKey should be checked.
177  /// </userdoc>
178  [DataMember(80)]
179  [DefaultValue(null)]
180  public ParameterKey<Graphics.Texture> Key { get; set; }
181 
182  /// <summary>
183  /// The parameter key used in the shader.
184  /// </summary>
185  [DataMemberIgnore]
186  public ParameterKey<Graphics.Texture> UsedParameterKey { get; set; }
187 
188  /// <summary>
189  /// The name of the texture;
190  /// </summary>
191  public string TextureName
192  {
193  get
194  {
195  return TextureReference != null && TextureReference.Location != null ? TextureReference.Location : null;
196  }
197  }
198 
199  /// <inheritdoc/>
200  public override string ToString()
201  {
202  return "Texture";
203  }
204  }
205 }
MaterialTextureNode(string texturePath, int texcoordIndex, Vector2 scale, Vector2 offset)
Key of an effect parameter.
Definition: ParameterKey.cs:15
Represents a two dimensional mathematical vector.
Definition: Vector2.cs:42
MaterialTextureNode(string texturePath, TextureCoordinate texcoordIndex, Vector2 scale, Vector2 offset)
Initializes a new instance of the MaterialTextureNode class.
TextureAddressMode
Identify a technique for resolving texture coordinates that are outside of the boundaries of a textur...
TextureCoordinate
The texture coordinate.
TextureFilter
Filtering options during texture sampling.
The data source is the color white (1, 1, 1, 1). No pre-blend operation.
The data source is the color black (0, 0, 0, 0). No pre-blend operation.
Defines a normalized file path. See UPath for details. This class cannot be inherited.
Definition: UFile.cs:13
Base class for texture resources.
Definition: Texture.cs:38