OpenGL ES Illumination Model-ambient illumination (Rendermonkey test)

Source: Internet
Author: User

Overview and Catalogue (All rights reserved, please do not reprint

This article summarizes how to do a simple OpenGL ES ambient light illumination model test under Rendermonkey.

The main contents include the following:

1. use Rendermonkey to create a simple project

2, environmental care model analysis and the corresponding input data creation

3, Shader code writing

4. Effect display

use Rendermonkey to create a simple project

Rendermoney Creating an OpenGL ES render project is simple, so you can create a solid-color spherical model rendering project just according to the following picture steps.

(OpenGL ES model rendering project creation)

Analysis of environmental care model and creation of corresponding input data

Ambient light is modeled as a type of light with no starting point and no direction, and its greatest feature is its equal effect on all objects in the scene. The model formula is as follows:

In the following photo step we created the illumination model input data in Rendermonkey and created a map for the sphere, where ganbientcolor is the ambient light color input, gambientstrength is the ambient light intensity input, Basemap is a liberal arts data object, we add a picture of the Earth's surface to the sphere.

(Environment illumination model data input and sphere Mapping arts and Sciences creation)

Shader Code Writing

  First, Vertex Shader

The vertex shader code we wrote for the ambient lighting model example is as follows.


Matviewprojection: The projection matrix for the Rendermonkey preset;

Rm_vertex: Vertex data input for the model;

RM_TEXCOORD0: For the model of the coordinates of science and arts input;

Rm_texcoord: For us to the fragment shader in the output of the arts and sciences coordinate data;

//Ambient lighting model Vertex shader Sample Code 1.0 uniform mat4 matviewprojection;attribute vec4 rm_vertex;attribute vec2 rm_texcoord0;varying vec2 Rm_texcoord; void void ) {    = matviewprojection * Rm_vertex;    Rm_texcoord    = rm_texcoord0.xy;}

Second, Fragment Shader

The fragment shader code we wrote for the environmental lighting model example is as follows.


Basemap: Input for model and arts map data;
Ganbientcolor: Environmental care color input;
Gambientstrength: Ambient light intensity input;
Rm_texcoord: The interpolated data of arts and sciences coordinates which are output from the vertex shader;
 //Ambient lighting model Fragment Shader Sample code 1.0
#ifdef Gl_fragment_precision_high//Default PrecisionPrecision HIGHPfloat;#elsePrecision Mediumpfloat;#endifuniform sampler2d basemap;uniform vec4 ganbientcolor;uniformfloatgambientstrength;varying vec2 Rm_texcoord;voidMainvoid) {VEC4 color=texture2d (Basemap,rm_texcoord); Gl_fragcolor= Color * Ganbientcolor *gambientstrength; }

Finally, after the code is compiled, we draw an Earth model object in the Rendermonkey rendering scene, as shown in:

(Shader code writing)

Effect Show

 , we show the actual results of the test environment care model by adjusting the light input intensity and illumination color:

(Effect show)

OpenGL ES Illumination Model-ambient illumination (Rendermonkey test)

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: 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.