@@ -101,11 +101,11 @@ private static Visual LoadScene_DamagedHelmet(Compositor compositor)
101101
102102 // Generate mipmaps from the bitmaps, which are needed for 3D rendering.
103103
104- var materialInput0 = LoadMipmapFromBitmap ( graphicsDevice , canvasBitmap0 . Result ) ;
105- var materialInput1 = LoadMipmapFromBitmap ( graphicsDevice , canvasBitmap1 . Result ) ;
106- var materialInput2 = LoadMipmapFromBitmap ( graphicsDevice , canvasBitmap2 . Result ) ;
107- var materialInput3 = LoadMipmapFromBitmap ( graphicsDevice , canvasBitmap3 . Result ) ;
108- var materialInput4 = LoadMipmapFromBitmap ( graphicsDevice , canvasBitmap4 . Result ) ;
104+ var materialInput0 = SceneNodeCommon . LoadMipmapFromBitmap ( graphicsDevice , canvasBitmap0 . Result ) ;
105+ var materialInput1 = SceneNodeCommon . LoadMipmapFromBitmap ( graphicsDevice , canvasBitmap1 . Result ) ;
106+ var materialInput2 = SceneNodeCommon . LoadMipmapFromBitmap ( graphicsDevice , canvasBitmap2 . Result ) ;
107+ var materialInput3 = SceneNodeCommon . LoadMipmapFromBitmap ( graphicsDevice , canvasBitmap3 . Result ) ;
108+ var materialInput4 = SceneNodeCommon . LoadMipmapFromBitmap ( graphicsDevice , canvasBitmap4 . Result ) ;
109109
110110
111111 // Copy loaded binary data into mesh: verticies, normals, ...
@@ -128,77 +128,28 @@ private static Visual LoadScene_DamagedHelmet(Compositor compositor)
128128 sceneNodeForTheGLTFMesh0 . Components . Add ( renderComponent0 ) ;
129129
130130 sceneMaterial0 . BaseColorFactor = new Vector4 ( 1.0f , 1.0f , 1.0f , 1.0f ) ;
131- sceneMaterial0 . BaseColorInput = CreateMaterial (
131+ sceneMaterial0 . BaseColorInput = SceneNodeCommon . CreateMaterial (
132132 compositor , materialInput0 , renderComponent0 , "BaseColorInput" ) ; ;
133133
134134 sceneMaterial0 . RoughnessFactor = 1.0f ;
135135 sceneMaterial0 . MetallicFactor = 1.0f ;
136- sceneMaterial0 . MetallicRoughnessInput = CreateMaterial (
136+ sceneMaterial0 . MetallicRoughnessInput = SceneNodeCommon . CreateMaterial (
137137 compositor , materialInput1 , renderComponent0 , "MetallicRoughnessInput" ) ;
138138
139139 sceneMaterial0 . NormalScale = 1.0f ;
140- sceneMaterial0 . NormalInput = CreateMaterial (
140+ sceneMaterial0 . NormalInput = SceneNodeCommon . CreateMaterial (
141141 compositor , materialInput2 , renderComponent0 , "NormalInput" ) ;
142142
143143 sceneMaterial0 . OcclusionStrength = 1.0f ;
144- sceneMaterial0 . OcclusionInput = CreateMaterial (
144+ sceneMaterial0 . OcclusionInput = SceneNodeCommon . CreateMaterial (
145145 compositor , materialInput3 , renderComponent0 , "OcclusionInput" ) ;
146146
147147 sceneMaterial0 . AlphaMode = SceneAlphaMode . Opaque ;
148148 sceneMaterial0 . IsDoubleSided = false ;
149149 sceneMaterial0 . EmissiveFactor = new Vector3 ( 1.0f , 1.0f , 1.0f ) ;
150- sceneMaterial0 . EmissiveInput = CreateMaterial (
150+ sceneMaterial0 . EmissiveInput = SceneNodeCommon . CreateMaterial (
151151 compositor , materialInput4 , renderComponent0 , "EmissiveInput" ) ;
152152
153153 return sceneVisual ;
154154 }
155-
156-
157- public static CompositionMipmapSurface LoadMipmapFromBitmap (
158- CompositionGraphicsDevice graphicsDevice , CanvasBitmap canvasBitmap )
159- {
160- var size = new SizeInt32 ( 2048 , 2048 ) ;
161- var mipmapSurface = graphicsDevice . CreateMipmapSurface (
162- size ,
163- DirectXPixelFormat . B8G8R8A8UIntNormalized ,
164- DirectXAlphaMode . Premultiplied ) ;
165-
166- var drawDestRect = new Rect ( 0 , 0 , size . Width , size . Height ) ;
167- var drawSourceRect = new Rect ( 0 , 0 , size . Width , size . Height ) ;
168- for ( uint level = 0 ; level < mipmapSurface . LevelCount ; ++ level )
169- {
170- // Draw the image to the surface
171- var drawingSurface = mipmapSurface . GetDrawingSurfaceForLevel ( level ) ;
172-
173- using ( var session = CanvasComposition . CreateDrawingSession ( drawingSurface ) )
174- {
175- session . Clear ( Windows . UI . Color . FromArgb ( 0 , 0 , 0 , 0 ) ) ;
176- session . DrawImage ( canvasBitmap , drawDestRect , drawSourceRect ) ;
177- }
178-
179- drawDestRect = new Rect ( 0 , 0 , drawDestRect . Width / 2 , drawDestRect . Height / 2 ) ;
180- }
181-
182- return mipmapSurface ;
183- }
184-
185-
186- private static SceneSurfaceMaterialInput CreateMaterial (
187- Compositor compositor ,
188- CompositionMipmapSurface mipmap ,
189- SceneMeshRendererComponent rendererComponent ,
190- string mapping )
191- {
192- var materialInput = SceneSurfaceMaterialInput . Create ( compositor ) ;
193- materialInput . Surface = mipmap ;
194- materialInput . BitmapInterpolationMode =
195- CompositionBitmapInterpolationMode . MagLinearMinLinearMipLinear ;
196-
197- materialInput . WrappingUMode = SceneWrappingMode . Repeat ;
198- materialInput . WrappingVMode = SceneWrappingMode . Repeat ;
199-
200- rendererComponent . UVMappings [ mapping ] = SceneAttributeSemantic . TexCoord0 ;
201-
202- return materialInput ;
203- }
204155}
0 commit comments