Add light in the scene-Add a mirror highlight on the reflective surface

Source: Internet
Author: User
Problem

Even if pixel-by-pixel brightness is enabled, some metal or flashing surfaces are still a little dimmed. In real life, when you look at metal, glass, or plastic, you will find that some areas are very reflective. Such a dotted circle in Area 6-6 is shown. These highlighted areas are called specular highlights ).

Figure 6-6 highlights

Solution

Like pixel-by-pixel illumination, you simply need to tell basiceffect to create a mirror highlight to enable it.

Note:The mirror highlight should only be added to the luminous material. Do not add them to soft surfaces such as clothing or grass, or at least make the reflection very weak.

Working Principle

It is very easy to enable the mirror highlight with basiceffect. Specify the highlight color for each light source. Then, set the highlight intensity. This intensity can specify the width of the highlight. The higher the intensity, the narrower the mirror height. See the tutorial 6-8 to learn the relevant details.

 
Basiceffect. lightingenabled = true; basiceffect. directionallight0.direction = lightdirection; basiceffect. directionallight0.diffusecolor = color. white. tovector3 (); basiceffect. directionallight0.enabled = true; basiceffect. preferperpixellighting = true; basiceffect. directionallight0.specularcolor = color. white. tovector3 (); basiceffect. specularpower = 32;

Note:When using a mirror highlight, always use pixel-by-pixel illumination. This is because the mirror highlight is usually a small, non-linear point, so they should not be interpolated, but should be calculated pixel by pixel.

Code

The following code defines the vertex and draws a rectangle:

 
Private void initvertices () {vertices = new vertexpositionnormaltexture [4]; vertices [0] = new vertexpositionnormaltexture (New vector3 (0, 0, 0), new vector3 (0, 1, 0), new vector2 (0, 1); vertices [1] = new vertexpositionnormaltexture (New vector3 (0, 0,-10), new vector3 (0, 1, 0), new vector2 (0, 0); vertices [2] = new vertexpositionnormaltexture (New vector3 (10, 0, 0), new vector3 (0, 1, 0 ), new vector2 (1, 1); vertices [3] = new vertexpositionnormaltexture (New vector3 (10, 0,-10), new vector3 (0, 1, 0 ), new vector2 (1, 0); myvertexdeclaration = new vertexdeclaration (device, vertexpositionnormaltexture. vertexelements );}

In the draw method, add the following code to create basiceffect and add a mirror highlight to the rectangle:

Basiceffect. world = matrix. identity; basiceffect. view = fpscam. viewmatrix; basiceffect. projection = fpscam. projectionmatrix; basiceffect. texture = bluetexture; basiceffect. textureenabled = true; vector3 lightdirection = new vector3 (0,-3,-10); lightdirection. normalize (); basiceffect. lightingenabled = true; basiceffect. directionallight0.direction = lightdirection; basiceffect. directionallight0.diffusecolor = color. white. tovector3 (); basiceffect. directionallight0.enabled = true; basiceffect. preferperpixellighting = true; basiceffect. directionallight0.specularcolor = color. white. tovector3 (); basiceffect. specularpower = 32; basiceffect. begin (); foreach (effectpass pass in basiceffect. currenttechnique. passes) {pass. begin (); device. vertexdeclaration = myvertexdeclaration; device. drawuserprimitives <vertexpositionnormaltexture> (primitivetype. trianglestrip, vertices, 0, 2); pass. end ();} basiceffect. end ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.