Irrlicht The study of the light of learning

I've recently studied Irrlicht The light of the sun . Find out Irrlicht It's still relatively simple , Compared to what's below it OpenGL and Direct3D, Setting the light source and setting the lighting parameters is more user-friendly ( Probably because OpenGL Is based on C Of ,Direct3D Is based on COM Of , It's not as easy to understand as object-oriented ?) But the implementation of lighting depends on the underlying render , In other words, it could be OpenGL Gauld's illumination model , It could be Direct3D The lighting model in .

Demo program and source code download address : here

In order to show exactly Irrlicht Set and display the properties of lighting , You need to load a scene model . Here I am from Entertainment Network I downloaded one from max Model , And then through 3DS Max To obj Format , This can be Irrlicht Identify and display . After the model is loaded, it needs to set its material so that it can receive light . Here's the setup code :

pDoorNode->setMaterialFlag(EMF_LIGHTING, true );// Take the light 
pDoorNode->setMaterialFlag(EMF_ANISOTROPIC_FILTER, true );// Using anisotropic filtering
pDoorNode->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL_REF );// Material on Alpha passageway

The first sentence here is to let Irrlicht The light of the node can act on the material of the node ; The second sentence is to use the heterosexual filter , Usually in the projection time can get a clear filtering effect in the distance ; The third sentence is to open the material Alpha passageway , Can solve some Alpha And the question of depth , Specific functions need to be explored ( You can comment it out to see the effect ).

After the preparatory work , It's time to set up the lighting . As far as my learning practice is concerned, it can be divided into these steps :

1、 Set the global light color ;

2、 Add light nodes to the scene ( It's commonly known as lighting );

3、 Set the properties of each light source .

The properties of light sources are diffuse color 、 Specular color 、 Self luminous color, etc ,OpenGL and Direct3D be-all Irrlicht There should be no lack of ( For the properties of the light source, see what I wrote before A journal ). The difference is ,Irrlicht As a node attribute, the light source becomes a part of scene management , This sum Blender And other mature 3D The scene management properties of modeling software are similar .

Here is a screenshot of the demo , There are four lights on in the screenshot , It's in the position of four torches . It seems that the original author only wants to make a static model , So torches are not made into particle systems , It's just a piece of dough . The program also creates a FPS The camera , We can easily roam the scene .

Here is part of the program code :

#include "IrrInclude.h"
void CreateMap( ISceneManager* pSMgr )
{
IMesh* pDoorMesh = pSMgr->getMesh( "Door/Door.obj");
if ( pDoorMesh == nullptr ) return; ISceneNode* pDoorNode = pSMgr->addMeshSceneNode( pDoorMesh );
if ( pDoorNode == nullptr ) return; pDoorNode->setMaterialFlag( EMF_LIGHTING, true );// Take the light
pDoorNode->setMaterialFlag( EMF_ANISOTROPIC_FILTER, true );// Using anisotropic filtering
pDoorNode->setMaterialType( EMT_TRANSPARENT_ALPHA_CHANNEL_REF);// Material on Alpha passageway // Set global illumination
pSMgr->setAmbientLight( SColor( 255, 80, 0, 0 ) ); // Add a point light
ILightSceneNode* pBlueFireLight_1 = pSMgr->addLightSceneNode(pDoorNode );
ILightSceneNode* pBlueFireLight_2 = pSMgr->addLightSceneNode(pDoorNode );
ILightSceneNode* pRedFireLight_1 = pSMgr->addLightSceneNode(pDoorNode );
ILightSceneNode* pRedFireLight_2 = pSMgr->addLightSceneNode(pDoorNode ); SLight blueFireLight;
blueFireLight.DiffuseColor = SColor( 255, 80, 80, 225 );
blueFireLight.SpecularColor = SColor( 255, 230, 230, 210 ); SLight redFireLight;
blueFireLight.DiffuseColor = SColor( 255, 225, 80, 80 );
blueFireLight.SpecularColor = SColor( 255, 230, 230, 210 ); // Set light properties
pBlueFireLight_1->setLightData( blueFireLight );
pBlueFireLight_1->setPosition( vector3df( 7.0f, 12.0f, 9.0f )); pBlueFireLight_2->setLightData( blueFireLight );
pBlueFireLight_2->setPosition( vector3df( -7.0f, 12.0f, 9.0f )); pRedFireLight_1->setLightData( redFireLight );
pRedFireLight_1->setPosition( vector3df( 20.0f, 2.0f, 6.0f )); pRedFireLight_2->setLightData( redFireLight );
pRedFireLight_2->setPosition( vector3df( -20.0f, 2.0f, 6.0f )); } void CreateGUI( IGUIEnvironment* pGUIEnv )
{
// Create Chinese Fonts
IGUIFont* pChineseFont = CGUITTFont::createTTFont(
pGUIEnv, // GUI Environmental Science
FONTPATH, // Font name
20, // font size ( How many pounds )
true, // Anti aliasing ?
true ); // Translucent ? // Set up GUI style
pGUIEnv->getSkin( )->setFont( pChineseFont );
pGUIEnv->getSkin( )->setColor( EGDC_BUTTON_TEXT, SColor(255, 255, 255, 255 ) );
} int main( int argc, char** argv )
{
IrrlichtDevice* pDevice = createDevice(
EDT_OPENGL, // Rendering devices
dimension2d<u32>( 640, 480 ), // Width and height
16, // Color bit
false, // Is it full screen
false, // Template cache
false, // Vertical synchronization
nullptr ); // Event receiver if ( pDevice == nullptr ) return -1;
pDevice->setWindowCaption( L" Ghost fire engine Demo - The study of light " ); IVideoDriver* pDriver = pDevice->getVideoDriver( );
ISceneManager* pSMgr = pDevice->getSceneManager( );
IGUIEnvironment* pGUIEnv = pDevice->getGUIEnvironment( ); CreateMap( pSMgr );// Create map
ICameraSceneNode* pCamera = pSMgr->addCameraSceneNodeFPS(
nullptr,
100.0f,
0.2f );
pCamera->setPosition( vector3df( -4.0f, -4.0f, 12.0f ) );
pCamera->setRotation( vector3df( 0.0f, 90.0f, 90.0f ) ); CreateGUI( pGUIEnv );// establish GUI
IGUIStaticText* pInfoText = pGUIEnv->addStaticText( L"", rect<s32>( 10, 10, 400, 100 )); pDevice->getCursorControl( )->setVisible( false );// Hide the mouse cursor while ( pDevice->run( ) )
{
vector3df pos = pCamera->getPosition( );
wchar_t info[100] = { 0 };
swprintf( info, L" Current camera coordinates (%.2f,%.2f, %.2f)\nMade By Jiangcaiyang",
pos.X, pos.Y, pos.Z );
pInfoText->setText( info ); pDriver->beginScene(
true, // Background cache
true, //Z cache
SColor( 0, 0, 0, 0 ) ); // Fill color
pSMgr->drawAll( );
pGUIEnv->drawAll( );
pDriver->endScene( );
} return 0;
}

Irrlicht More articles on the study of the light of learning

  1. J2EE Learn some open source items worth studying ( turn )

    This article is written in my research J2SE.J2EE Nearly three years later . front 3 I studied J2SE Of Swing.Applet.Net.RMI.Collections. IO.JNI…… Studied J2EE Of JDBC.Sevlet.JSP ...

  2. Nagios Learning practice series —— Configuration research [ Monitor the current server ]

    In fact, part one Nagios Learning practice series —— The basic installation section only installs Nagios Basic components , Although I can open the home page , But if you don't configure the relevant configuration file , So many pages of the menu on the left can't be opened , It's just an empty shell . Next , Let's learn to research ...

  3. The first part of set learning Hashmap Mechanism research

    1. Two ways to implement traversal // newly build Map map=new HashMap(); // Stored value map.put() ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // Traverse the way ...

  4. Ueditor Before the back-end source code learning and simple research

    This is my project catalog Picture description here 1. From the access path http://localhost:8081/Test/_examples/simpleDemo.html, We mainly want to see , Before the rich text box is loaded , Can tune ...

  5. HBase Learning notes -HBase Performance Studies (1)

    Use Java API And HBase When clusters interact , Need to build HTable object , Use the method provided by the object to insert / Delete / Query and so on . To create a HTable object , First, create one with HBase The configuration object of cluster information Confi ...

  6. Study es6 setter/getter Research

    1. background stay ES6 in , Our definition of a class is as follows class Person { // Constructors constructor (name) { // Property initialization this.name = name; } // Members ...

  7. Arduino Car learning and Research

    Basic practice module of Xin'an system design Arduino Car learning and Research ================== Chen Du (20135328) Yu Jiayuan (20135321) mofi (20135225) ---------- Indexes ...

  8. Arduino Car learning and Research Blog

    Arduino Car learning and Research Blog Basic practice module of Xin'an system design Arduino Car learning and Research ================== Chen Du (20135328) Yu Jiayuan (20135321) mofi (201352 ...

  9. Deep learning combined with SLAM Research Summary

    The blog is reproduced from :https://blog.csdn.net/u010821666/article/details/78793225  Original title : Deep learning combined with SLAM Research ideas of / Sorting out the achievements 1. Deep learning and S ...

Random recommendation

  1. java Initialization sequence

    java The variable types are as follows : Instance variables : Class variables : The initialization process is as follows : Instance variables -- When making a statement , initialization : -- In a non static initialization block , initialization : -- Inside the constructor , initialization : example 1: public class bean ...

  2. Use flow.ci Realization Android Automated testing and continuous integration

    In the last article -- How to achieve Android Continuous deployment of applications , We use flow.ci + Github + fir.im Realization Android Continuous deployment of applications . about Android developer , They may ...

  3. smarty3--registerPlugin() Function error problem

    smarty edition :smarty3.1.30 registerPlugin error message : Notice: Trying to get property of non-object in E:\Joomla\ ...

  4. ./filezilla: error while loading shared libraries: libpng12.so.0: cannot open shared object file: No such file or directory

    opensuse System stay filezilla Download the compressed file from the official website, unzip and run it ./filezilla: error while loading shared libraries: libpng12.so.0 ...

  5. Solve the whole station ie6 Next PNG The image opacity problem only needs a few lines of code

    Solve the whole station ie6 Next PNG The picture is opaque. Just copy the following lines of code and paste them at the bottom of your document , The package you need to use DD_belatedPNG_0.0.8a.js Download it on the Internet The code starts /* Add the following code at the bottom of the document */ &l ...

  6. Oracle database Pick up the leak and fill in the gap

    select Basic use of sentences You can query the required columns , That's ok , You can link multiple tables , Link query . from p_emp e select This is followed by the results to be displayed , It can be a pseudo column by operation or join symbol null   Null value ...

  7. 【 fact 】-《 University of Birmingham College diploma 》UCB It's as like as two peas

    * University of Birmingham College diploma [ tiny /Q:865121257◆WeChat:CC6669834]UC graduation certificate / Contacts Alice[ View click Baidu snapshot to view ][ Liuxin Education Certification & Doctor & master & Returnees ...

  8. SAML 2.0 initial

    One . Background knowledge : SAML Security assertion markup language , The full English name is Security Assertion Markup Language. It is based on XML Standards for , Used in different security domains (security domain ...

  9. Android framework -- Room

    gradle rely on : // add for room implementation "android.arch.persistence.room:runtime:1.1.1" // ...

  10. shiro The project from log4j1X Migrate to log4j2X

    But first, let me say ,shiro The dependent project is not log4j It is SLF4J frame . We used to use 1X Version of jar The package is as follows : log4j-1.2.17.jar slf4j-api-1.7.22.jar slf4j-log ...