Use Mesh: Material and Light

xiaoxiao2021-03-06  104

Using the Light render the top, but this rendered vertex is color, then when we render an entity, when his vertices do not color, we still use light as the previous method, what happens? The answer is a solid paint black, why? This is because D3D is when calculating a point in a 3D entity, it not only needs to know the color of its light, but also know if the Light is on the entity, the entity should reflect colour. In D3D, there is a concept of Materials to describe this property.

Let's create a mesh, you can understand that Mesh is a collection of a large number of vertices (graphic data), which includes a vertex, as well as some ways to operate these vertices. Mesh is mainly used to load complex 3D objects. In Mananged DX, Mesh includes some static methods that make it easy for you to create simple entities such as Cube, Box, etc. Using Mesh, you must first refer to its class library: Microsoft.directx.direct3dx, look at the specific implementation step: 1. Create a Mesh object: Mesh Mesh = NULL; 2. Many static methods in Mesh can be used to create simple 3D Entity, here is a Teapot (Teapot) as an example: Mesh = Mesh.Teapot (Device) Now our mesh is a collection of teapot vertex data. 3. Rendering it. Call mesh.drawsubset (0), at least parameters, later introduced. How, compares to the vertices directly, use VertexBuffer, because Mesh is automatically handled 4. Try it. Is it white? This is because we have created Mesh, in fact, just the vertex coordinate set, the vertex is not color, we will use the light to color on this white teapot. First set the deivce.renderstate.lighting = true (actually the default is true, or not this statement). We have already mentioned Material, here we have to react out in our teapot, we use Material to implement, first build the Material object, instantiate. Then, set its .diffuse = system.drawing.color.gold property to specify reflected light. Finally, we also put our equipment device.material = (just created by the Material object), to this, our Material is set. The next step is to set the lighting property. Assume that there is only one lamp in the scene, then we set the properties of Device.lights [0], including type, direction, diffuse, enable properties (of course, you have to set other, or) the Diffuse property means reflecting light, Finally, our entity is present, and is determined by Lights.Diffuse and Material.Diffuse here. 5. Compile operation. Is it a teapot that appeared? Oh ... Note: Visit information "Managed DirectX 9 Kick Start: graphics and game programming" Chapter 5

转载请注明原文地址:https://www.9cbs.com/read-100616.html

New Post(0)