SpotLight in WPF cann't form a circle of light?  
Author Message
samonwang





PostPosted: Windows Presentation Foundation (WPF), SpotLight in WPF cann't form a circle of light? Top

Hi! Guys,
I have a problem. When I use a spotlight in the 3-D scene to light a side 
plane of a cube ,the result is not a circle light effect.
 <Viewport3D ClipToBounds="True" Width="150" Height="150" Canvas.Left="0" 
Canvas.Top="10">

        <!-- Defines the camera used to view the 3D object. -->
        <Viewport3D.Camera>
         <PerspectiveCamera Position="0,0,2" LookDirection="0,0,-1" 
FieldOfView="60" />
        </Viewport3D.Camera>

        <!-- The ModelVisual3D children contain the 3D models -->
        <Viewport3D.Children>
         <!-- A SpotLight is used to light the scene. The InnerConeAngle 
and OuterConeAngle are used
             to control the size of the light cone created by the 
SpotLight. The Direction and Position
             properties determine where the SpotLight is pointing in the 
scene. In this example, the Position
             of the SpotLight is set so that the SpotLight is only 
illuminating the upper right-hand corner
             of the 3D object. -->
         <ModelVisual3D>
           <ModelVisual3D.Content>
            <SpotLight x:Name="mySpotLight" InnerConeAngle="15.0" 
OuterConeAngle="22.0" Color="#FFFFFF" Direction="0,0,-1" 
              Position="0,0,5" Range="30"/>
           </ModelVisual3D.Content>
         </ModelVisual3D>
         <ModelVisual3D>
           <ModelVisual3D.Content>
            <GeometryModel3D>

              <!-- The geometry specifes the shape of the 3D plane. In 
this sample, a flat sheet is created. -->
              <GeometryModel3D.Geometry>
               <MeshGeometry3D
                TriangleIndices="0,1,2 3,4,5 "
                Normals="0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 "
                TextureCoordinates="0,0 1,0 1,1 1,1 0,1 0,0 "
                Positions="-0.5,-0.5,0.5 0.5,-0.5,0.5 0.5,0.5,0.5 
0.5,0.5,0.5 -0.5,0.5,0.5 -0.5,-0.5,0.5 " />
              </GeometryModel3D.Geometry>
              <GeometryModel3D.Material>
               <MaterialGroup>
                 <DiffuseMaterial>
                  <DiffuseMaterial.Brush>						  <SolidColorBrush  
Color="Blue" />
                  </DiffuseMaterial.Brush>
                 </DiffuseMaterial> 
                </MaterialGroup>
              </GeometryModel3D.Material>
            </GeometryModel3D>
           </ModelVisual3D.Content>
         </ModelVisual3D>
        </Viewport3D.Children>

      </Viewport3D>



Visual Studio 200821  
 
 
Adam Smith MS





PostPosted: Windows Presentation Foundation (WPF), SpotLight in WPF cann't form a circle of light? Top

What you're seeing is the fact that we're not a ray tracing engine. What I mean by that is that we're not running light calculations for every pixel, we take shortcuts (as does DX, OGL, etc). When lighting triangles, we light each corner of the triangle in question and then interpolate between the 3 corners to fill the inside of the triangle. You have a spotlight targetting the direct center of your quad - this means that each corner is equally lit, so you see a nice even illumination. If you want finer detail, you can sub-divide your quad into, say, a 5x5 grid of quads.

-Adam Smith [MS]