Example a/arbitrary_shaders: Arbitrary Shaders: Using GLSL shaders to create reflective effect on material.

Using an arbitrary shaders to similate the reflection of a mirror on a model.

Note that the current implementation of arbitraray GLSL shaders does not work well with THE current Mesa3D libraries and this model will simply appear to have a texture applied to the material when it is used. This example however should run on computer with a decent graphics card and this example has only been tested with nvidia graphics card only.

Special thanks to Dr. Hayley Reynolds for providing the human model.

The background picture is taken in front of the Hong Kong Jockey Club, Shatin, Hong Kong. Created April, 2009 by Alan Wu.

Screenshot of example a/arbitrary_shaders


The comfile run by this example is as follows:

#A short example to demonstrate the capability of arbitrary shaders in cmgui.
#It uses an arbitrary shaders to simulate the effect of a mirror, the effect will
#be much nicer with a cube map.

#Read in the model and texture.
gfx read node $example/final_all_skin.exnode;
gfx read element $example/final_all_skin.exelem;
gfx create texture base repeat_wrap image $example/background.jpg;

#Read in the arbitrary program.
CORE::open VPFILE, "<$example/mirror.vert";
@vp = <VPFILE>;
CORE::open FPFILE, "<$example/mirror.frag";
@fp = <FPFILE>;

#Set the material properties.
gfx create material T-1000 ambient 1 1 1 diffuse 0.8 0.8 0.8 emission 0 0 0 specular 0 0 0 alpha 1 shininess 0 texture base;

#Set the material to use the shaders.
gfx modify material T-1000 vertex_program_string "@vp" fragment_program_string "@fp"; 
gfx modify material T-1000 uniform_name FresnelPower uniform_value 5.0;
gfx modify material T-1000 uniform_name Eta uniform_value 0.66;

#Set up the graphical settings.
gfx modify g_element final_all_skin surface material T-1000 texture_coordinates xi;
gfx modify g_element final_all_skin general clear circle_discretization 6 default_coordinate coordinates element_discretization "5*5*1" native_discretization none;
gfx modify g_element final_all_skin lines select_on material default selected_material default_selected invisible;
gfx modify g_element final_all_skin surfaces select_on material T-1000 texture_coordinates xi selected_material default_selected render_shaded;

#Set up the display windows.
gfx cre win 1;
gfx mod win 1 layout width 800 height 800;
gfx mod win 1 set anti 8;
gfx mod win 1 bac texture base;
gfx modify window 1 view perspective eye_point -968.304 4214.24 -878.345 interest_point 290.504 186.619 -910.696 up_vector 0.0170221 -0.00271091 0.999851 view_angle 40 near_clipping_plane 42.1987 far_clipping_plane 15080.4 relative_viewport ndc_placement -1 1 2 2 viewport_coordinates 0 0 1 1;

#You can adjust the diffuse colour and alpha of material T-1000 to see the effect they have on the model.

Files used by this example are:

Name                           Modified     Size

example_arbitrary_shaders.com 17-Mar-2014 2.0k COPYRIGHT 17-Mar-2014 504 background.jpg 17-Mar-2014 552k final_all_skin.exelem 17-Mar-2014 1.1M final_all_skin.exnode 17-Mar-2014 249k mirror.frag 17-Mar-2014 714 mirror.vert 17-Mar-2014 929

Download the entire example:

Name                                 Modified     Size

examples_a_arbitrary_shaders.tar.gz 09-Mar-2016 2.4M

Testing status by version:

StatusTestedReal time (s)
i686-linux
cmgui-wxFailureSun Mar 6 00:16:47 20164
last breakTue Feb 24 03:19:00 20155
cmgui-wx-debugFailureSun Mar 6 00:18:59 20165
last breakTue Feb 24 03:22:00 20155
cmgui-wx-debug-memorycheckFailureSun Mar 6 00:23:14 20166
last breakTue Feb 24 03:21:00 20156
cmgui-wx-debug-valgrindFailureSun Mar 6 01:59:55 2016267
last breakSun Mar 6 01:55:00 2016267
x86_64-linux
cmgui-wxFailureSun Mar 6 00:01:28 20160
last breakSun Mar 6 00:01:00 20160
cmgui-wx-debugFailureSun Mar 6 00:01:28 20160
last breakSun Mar 6 00:01:00 20160
cmgui-wx-debug-memorycheckFailureSun Mar 6 00:01:28 20160
last breakSun Mar 6 00:01:00 20160
cmgui-wx-debug-valgrindFailureSun Mar 6 00:02:52 20169
last breakSun Mar 6 00:02:00 20169
cmgui-wx-gcc-cad-debug-valgrindSuccessThu Jan 7 00:02:07 20167

Testing status by file:


Html last generated: Wed Mar 9 16:01:27 2016

Input last modified: Wed Mar 9 15:49:33 2016


CMISS Help / Examples / a / arbitrary_shaders