Reiiden notes h (complete example of ogre materilas/HLSL)

Source: Internet
Author: User

Materilas Summary
All attributes of materilas are listed in: ogrereadme-> the Ogre manual-> scripts-> material scripts (FLIP pages)

Mygrematerials. cpp

# Include "mygrematerials. H "</P> <p> void mygrematerials: createscene (void) <br/>{< br/> // a self-built grid <br/> ogre :: manualobject * manual = mscenemgr-> createmanualobject ("Quad"); </P> <p> manual-> begin ("basewhitenolighting", ogre: renderoperation: ot_triangle_list ); // The previous value is texture <br/> manual-> position (5.0, 0.0, 0.0); <br/> manual-> texturecoord (0, 2 ); <br/> manual-> position (-5.0, 10.0, 0.0); <br/> manual-> texturecoord (2, 0 ); <br/> manual-> position (-5.0, 0.0, 0.0); <br/> manual-> texturecoord (2, 2 ); <br/> manual-> position (5.0, 10.0, 0.0); <br/> manual-> texturecoord (0, 0 ); </P> <p> manual-> index (0); <br/> manual-> index (1); <br/> manual-> index (2 ); <br/> manual-> index (0); <br/> manual-> index (3); <br/> manual-> index (1 ); <br/> manual-> end (); <br/> manual-> converttomesh ("Quad "); </P> <p> entity = mscenemgr-> createentity ("Quad"); <br/> node = mscenemgr-> getrootscenenode ()-> createchildscenenode ("node1 "); <br/> node-> attachobject (entity); <br/>}</P> <p> void mygrematerials: destroyscene () <br/>{< br/>}</P> <p> bool mygrematerials: keypressed (const ois: keyevent & Arg) <br/>{< br/> switch (Arg. key) <br/>{< br/> case ois: kc_1: <br/> entity-> setmaterialname ("Mine/materilas_1"); <br/> break; <br/> case ois: kc_2: <br/> entity-> setmaterialname ("Mine/materilas_2"); <br/> break; <br/> case ois :: kc_3: <br/> entity-> setmaterialname ("Mine/materilas_3"); <br/> break; <br/> case ois: kc_4: <br/> entity-> setmaterialname ("Mine/materilas_4"); <br/> break; <br/> case ois: kc_5: <br/> {<br/> static int B5 = 0; <br/> If (B5 = 0) <br/>{< br/> entity-> setmaterialname ("Mine/materilas_5"); <br/> B5 = 1; <br/>}< br/> else <br/> {<br/> entity-> setmaterialname ("Mine/materilas_5_1"); <br/> B5 = 0; <br/>}< br/> break; <br/> case ois: kc_6: <br/> entity-> setmaterialname ("Mine/materilas_6"); <br/> break; <br/> default: <br/> break; <br/>}< br/> return baseapplication: keypressed (ARG); <br/>}

Mine. Material

// Simple texture <br/> material mine/materilas_1 <br/>{< br/> technique <br/>{< br/> pass <br/>{< br/> texture_unit <br/>{< br/> Texture leaf.png <br/>}</P> <p> // texture + addressing (mirror, clamp, Border) <br/> material mine/materilas_2 <br/>{< br/> technique <br/>{< br/> pass <br/>{< br/> texture_unit <br />{< br/> Texture leaf.png <br/> tex_address_mode mirror <br/>}</P> <p> // texture + addressing + border color <br/> material mine/materilas_3 <br/> {<br/> technique <br/>{< br/> pass <br />{< br/> texture_unit <br/>{< br/> Texture leaf.png <br/> tex_border_colour 1.0 0.0 0.0 <br/> tex_address_mode border <br/>} <br />}< br/>}</P> <p> // texture + addressing + border color + offset <br/> material mine/materilas_4 <br />{< br/> technique <br/>{< br/> pass <br/>{< br/> texture_unit <br/>{< br/> Texture leaf.png <br/> tex_border_colour 1.0 0.0 0.0 <br/> tex_address_mode border <br/> scroll 0.8 0.8 <br/>}< br/>} </P> <p> // animation <br/> material mine/materilas_5 <br/> {<br/> technique <br/>{< br/> pass <br />{< br/> texture_unit t1 <br/>{< br/> Texture leaf.png <br/> rotate_anim 0.1 <br/>}< br/>} <br/>}</P> <p> // inherit <br/> material mine/materilas_5_1: mine/materilas_5 <br/>{< br/> set_texture_alias T1 water02.jpg <br/>}</P> <p> // HLSL <br/> vertex_program deferred_vs HLSL <br/ >{< br/> source deferred_vs.hlsl <br/> Target vs_2_0 <br/> entry_point main </P> <p> default_params <br/>{< br/> param_named_auto worldviewproj worldviewprojmatrix <br/>}< br/> fragment_program deferred_ps HLSL <br/>{< br/> source deferred_ps.hlsl <br/> Target ps_2_0 <br/> entry_point main <br/>}</P> <p> material mine/materilas_6 <br/> {<br/> technique <br/>{< br/> pass <br/> {<br/> vertex_program_ref deferred_vs <br/>{< br/>}< br/> fragment_program_ref deferred_ps <br/>{< br/>}</P> <p> texture_unit <br/>{< br/> // sampler S0 <br/> Texture leaf.png <br/>}< br/> texture_unit <br/>{< br/>/ /sampler S1 <br/> Texture water02.jpg <br/>}</P> <p> 

Deferred_vs.hlsl

Struct vs_output <br/>{< br/> float4 pos: position; <br/> float2 texcoord0: texcoord0; <br/> }; </P> <p> float4x4 worldviewproj; </P> <p> vs_output main (float4 pos: Position, float3 normal: Normal, float2 texcoord0: texcoord0) <br/>{< br/> vs_output out; <br/> out. pos = MUL (worldviewproj, POS); <br/> out. texcoord0 = texcoord0; <br/> return out; <br/>} 

Deferred_ps.hlsl

Sampler tex0: Register (S0); </P> <p> float4 main (float4 texcoord0: texcoord0): color0 <br/>{< br/> return tex2d (tex0, texcoord0); <br/>}

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.