Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
CubemapSourceComponent.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 
4 using System.ComponentModel;
5 
6 using SiliconStudio.Core;
7 using SiliconStudio.Core.Serialization.Converters;
8 using SiliconStudio.Paradox.EntityModel;
9 using SiliconStudio.Paradox.Graphics;
10 
11 namespace SiliconStudio.Paradox.Engine
12 {
13  /// <summary>
14  /// Puts a cubemap at the containing entity location. This could be dynamic (runtime rendered) or static (from a file).
15  /// </summary>
16  [DataConverter(AutoGenerate = true)]
17  [DataContract("CubemapSourceComponent")]
19  {
21 
22  [DataMemberIgnore]
23  private TextureCube textureCube;
24 
25  /// <summary>
26  /// Initializes a new instance of the <see cref="CubemapSourceComponent"/> class.
27  /// </summary>
29  {
30  Size = 256;
31  InfluenceRadius = 1.0f;
32  InfinityCubemap = false;
33  textureCube = null;
34  NearPlane = 0.1f;
35  FarPlane = 100.0f;
36  MaxLod = 0;
37  RenderTarget = null;
38  RenderTargets = null;
39  }
40 
41  public CubemapSourceComponent(TextureCube texture) : this()
42  {
43  textureCube = texture;
44  if (texture != null)
45  Size = texture.Width;
46  IsDynamic = false;
47  }
48 
49  /// <summary>
50  /// Enables the computation of the cubemap if this one is dynamic.
51  /// </summary>
52  [DataMemberConvert]
53  public bool Enabled { get; set; }
54 
55  /// <summary>
56  /// Enables runtime cubemap creation.
57  /// </summary>
58  [DataMemberConvert]
59  public bool IsDynamic { get; set; }
60 
61  /// <summary>
62  /// The size of the target cubemap if this one is dynamic.
63  /// </summary>
64  [DataMemberConvert]
65  [DefaultValue(256)]
66  public int Size { get; set; }
67 
68  /// <summary>
69  /// The cubemap has no location.
70  /// </summary>
71  [DataMemberConvert]
72  public bool InfinityCubemap { get; set; }
73 
74  /// <summary>
75  /// The influence radius of the cubemap. 0 is infinity?
76  /// </summary>
77  [DataMemberConvert]
78  [DefaultValue(1.0f)]
79  public float InfluenceRadius { get; set; }
80 
81  /// <summary>
82  /// The near plane of the cubemap.
83  /// </summary>
84  [DataMemberConvert]
85  [DefaultValue(0.1f)]
86  public float NearPlane { get; set; }
87 
88  /// <summary>
89  /// The far plane of the cubemap.
90  /// </summary>
91  [DataMemberConvert]
92  [DefaultValue(100.0f)]
93  public float FarPlane { get; set; }
94 
95  /// <summary>
96  /// The texture attached to this component.
97  /// </summary>
98  [DataMemberConvert]
99  [DataMemberCustomSerializer]
100  public TextureCube Texture
101  {
102  get
103  {
104  return textureCube;
105  }
106  set
107  {
108  textureCube = value;
109  if (textureCube != null)
110  MaxLod = textureCube.Description.MipLevels - 1;
111  }
112  }
113 
114  /// <summary>
115  /// The maximum lod of the texture.
116  /// </summary>
117  [DataMemberIgnore]
118  public int MaxLod { get; private set; }
119 
120  /// <summary>
121  /// The render target of the cubemap.
122  /// </summary>
123  [DataMemberIgnore]
124  public RenderTarget RenderTarget { get; private set; }
125 
126  /// <summary>
127  /// The render targets of the cubemap.
128  /// </summary>
129  [DataMemberIgnore]
130  public RenderTarget[] RenderTargets { get; private set; }
131 
132  /// <summary>
133  /// The texture attached to this component.
134  /// </summary>
135  [DataMemberIgnore]
136  public DepthStencilBuffer DepthStencil { get; set; }
137 
138  /// <summary>
139  /// Creates full view render targets on demand.
140  /// </summary>
142  {
143  // TODO: check previous status to dispose the rendertarget?
144  if (textureCube != null)
145  {
146  RenderTarget = textureCube.ToRenderTarget(ViewType.Full, 0, 0);
147  DepthStencil = Texture2D.New(textureCube.GraphicsDevice, Size, Size, PixelFormat.D24_UNorm_S8_UInt, TextureFlags.DepthStencil, 6).ToDepthStencilBuffer(false);
148  }
149  }
150 
151  /// <summary>
152  /// Creates single view render targets on demand.
153  /// </summary>
155  {
156  // TODO: check previous status to dispose the rendertarget?
157  if (textureCube != null)
158  {
159  RenderTargets = new[]
160  {
161  textureCube.ToRenderTarget(ViewType.Single, 0, 0),
162  textureCube.ToRenderTarget(ViewType.Single, 1, 0),
163  textureCube.ToRenderTarget(ViewType.Single, 2, 0),
164  textureCube.ToRenderTarget(ViewType.Single, 3, 0),
165  textureCube.ToRenderTarget(ViewType.Single, 4, 0),
166  textureCube.ToRenderTarget(ViewType.Single, 5, 0)
167  };
168  DepthStencil = Texture2D.New(textureCube.GraphicsDevice, Size, Size, PixelFormat.D24_UNorm_S8_UInt, TextureFlags.DepthStencil).ToDepthStencilBuffer(false);
169  }
170  }
171 
172  public override PropertyKey DefaultKey
173  {
174  get { return Key; }
175  }
176  }
177 }
A TextureCube frontend to SharpDX.Direct3D11.Texture2D.
Definition: TextureCube.cs:37
Base class for converters to/from a data type.
Puts a cubemap at the containing entity location. This could be dynamic (runtime rendered) or static ...
CubemapSourceComponent()
Initializes a new instance of the CubemapSourceComponent class.
ViewType
Defines how a view is selected from a resource.
Definition: ViewType.cs:31
void CreateSingleViewRenderTargets()
Creates single view render targets on demand.
void CreateFullViewRenderTarget()
Creates full view render targets on demand.
A class that represents a tag propety.
Definition: PropertyKey.cs:17
Base class for texture resources.
Definition: Texture.cs:38