Integrate ogre terrain and PSSM + lissms shadow Algorithm

Source: Internet
Author: User

Ogre version 1.7.1 contains the terrain example and uses PSSM + lissms.

Today, I tried to place character's Sinbad model on the terrain, but the model material itself does not support PSSM.

After reading the implementation of the terrain example, it is found that when it transfers PSSM demarcation point data to the shader, it uses the method of cloning the template material, and then sets diffusemap and PSSM demarcation points, quite speechless ....

 

View plaincopy to clipboardprint?
  1. Materialptr ret = materialmanager: getsingleton (). getbyname (matname );
  2. Materialptr basemat = materialmanager: getsingleton (). getbyname ("Ogre/shadow/depth/integrated/PSSM ");
  3. Ret = basemat-> clone (matname );
  4. Pass * P = ret-> gettechnique (0)-> getpass (0 );
  5. P-> gettextureunitstate ("diffuse")-> settexturename (texturename );
  6. Vector4 splitpoints;
  7. ConstPssmshadowcamerasetup: splitpointlist & splitpointlist =
  8. Static_cast<Pssmshadowcamerasetup *> (mpssmsetup. Get ()-> getsplitpoints ();
  9. For(IntI = 0; I <3; ++ I)
  10. {
  11. Splitpoints [I] = splitpointlist [I];
  12. }
  13. P-> getfragmentprogramparameters ()-> setnamedconstant ("pssmsplitpoints", splitpoints );

Materialptr ret = materialmanager: getsingleton (). getbyname (matname); <br/> materialptr basemat = materialmanager: getsingleton (). getbyname ("Ogre/shadow/depth/integrated/PSSM"); <br/> ret = basemat-> clone (matname ); <br/> Pass * P = ret-> gettechnique (0)-> getpass (0); <br/> P-> gettextureunitstate ("diffuse ") -> settexturename (texturename); <br/> vector4 splitpoints; <br/> const attributes: splitpointlist & splitpointlist = <br/> static_cast <comment *> (mpssmsetup. get ()-> getsplitpoints (); <br/> for (INT I = 0; I <3; ++ I) <br/>{< br/> splitpoints [I] = splitpointlist [I]; <br/>}< br/> P-> getfragmentprogramparameters () -> setnamedconstant ("pssmsplitpoints", splitpoints ); 

 

If there are hundreds of objects with different textures, You have to manually set diffusemap and PSSM demarcation points for each object in the Code. The former can be overwritten by inheritance in the material script, the latter actually uses the same data in the entire scenario. Fortunately, shared_params is added to ogre, so that multiple shader can share the same parameter. You can set it only once in the code.

Modified FP:

 

View plaincopy to clipboardprint?
  1. Shared_params pssm_params
  2. {
  3. Shared_param_named pssmsplitpoints float4
  4. }
  5. Fragment_program ogre/shadow/receiver/depth/pssm3/FP CG
  6. {
  7. Source depthshadowobject. CG
  8. Profiles ps_2_x arbfp1
  9. Entry_point main_fp
  10. Compile_arguments-dshadowcaster = 0-ddepth_shadowcaster = 0-ddepth_shadowreceiver = 1
  11. Default_params
  12. {
  13. Param_named_auto materialambient derived_ambient_light_colour
  14. // Shadow samplers are indexes 1/2/3
  15. Param_named_auto inverseshadowmapsize0 inverse_texture_size 1
  16. Param_named_auto inverseshadowmapsize1 inverse_texture_size 2
  17. Param_named_auto inverseshadowmapsize2 inverse_texture_size 3
  18. // Set this manually!
  19. // Param_named pssmsplitpoints 0 0 0
  20. Shared_params_ref pssm_params
  21. }
  22. }

Shared_params pssm_params <br/>{< br/> paipssmsplitpoints float4 <br/>}< br/> fragment_program ogre/shadow/receiver/depth/pssm3/fp cg <br/> {<br/> source depthshadowobject. CG <br/> profiles ps_2_x arbfp1 <br/> entry_point main_fp <br/> compile_arguments-dshadowcaster = 0-Snapshot = 0-Snapshot = 1 <br/> default_params <br/> {<br/> param_named_auto materialambient derived _ Ambient_light_colour <br/> // shadow samplers are indexes 1/2/3 <br/> param_named_auto scaling limit 1 <br/> param_named_auto scaling limit 2 <br/> param_named_auto limit 3 <br/> // set this manually! <Br/> // param_named pssmsplitpoints 0 0 0 <br/> shared_params_ref pssm_params <br/>}< br/>} 

 

C ++:

 

View plaincopy to clipboardprint?
  1. Vector4 splitpoints;
  2. ConstPssmshadowcamerasetup: splitpointlist & splitpointlist =
  3. Static_cast<Pssmshadowcamerasetup *> (mpssmsetup. Get ()-> getsplitpoints ();
  4. For(IntI = 0; I <3; ++ I)
  5. {
  6. Splitpoints [I] = splitpointlist [I];
  7. }
  8. Gpusharedparametersptr P = gpuprogrammanager: getsingleton (). getsharedparameters ("pssm_params ");
  9. P-> setnamedconstant ("pssmsplitpoints", splitpoints );

Vector4 splitpoints; <br/> const pssmshadowcamerasetup: splitpointlist & splitpointlist = <br/> static_cast <pssmshadowcamerasetup *> (mpssmsetup. get ()-> getsplitpoints (); <br/> for (INT I = 0; I <3; ++ I) <br/>{< br/> splitpoints [I] = splitpointlist [I]; <br/>}< br/> gpusharedparametersptr P = gpuprogrammanager: getsingleton (). getsharedparameters ("pssm_params"); <br/> P-> setnamedconstant ("pssmsplitpoints", splitpoints ); 

 

 

Http://blog.csdn.net/cometeor/archive/2010/06/09/5657168.aspx

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.