FORUM CLOSED, PLEASE REGISTER AT FORUM.SIO2INTERACTIVE.COM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Best Practice for an Object with Variable Material Properties

2 posters

Go down

Best Practice for an Object with Variable Material Properties Empty Best Practice for an Object with Variable Material Properties

Post  jj Thu Nov 20, 2008 5:40 pm

Hi,

Here is what I am trying to accomplish: Given a game state variable (0, 1) I wish to toggle the color of the material on a 3D object. The 2 materials I want to toggle between should both be transparent by 50%, and the only difference is that one material is red, and the other is green.

1. How should I initally set up the object and it's material assignment in Blender?

2. How do I change the material attributes of the given object's material in templateRender()? Is it best practice to simply make adjustment to the material->diffuse->x,y, z and use ONE material? Or create two materials?

I am looking through tutorial06, and have tried the following code block inside of templateRender(), but the object's material stays the same (right now, initially set as a RGBA .tga texture in Blender)...

Code:

/*at top:  */

//SIO2material *_SIO2material_greenArrow = NULL;

/*inside templateRender()    */

//set the material color of the arrow based on if aimStatus is selected.
if (readyStatus == 1) { //arrow is green
  if (!_SIO2material_greenArrow) { //initialize material it if it hasn't been already            
    _SIO2material_greenArrow = sio2MaterialInit("greenArrow");
            
                                _SIO2material_greenArrow->diffuse->x = 0.0f;
            _SIO2material_greenArrow->diffuse->y = 0.0f;
            _SIO2material_greenArrow->diffuse->z = 0.0f;
            _SIO2material_greenArrow->diffuse->w = 0.5f;
            
            //change the blending mode
            _SIO2material_greenArrow->blend = SIO2_MATERIAL_ALPHA;
            
            NSLog(@"material INIT");
         }
         
         //set to green
                      _SIO2material_greenArrow->diffuse->x = 0.0f;
         _SIO2material_greenArrow->diffuse->y = 1.0f;

         //render the material
         sio2MaterialRender(_SIO2material_greenArrow);
         
         sio2ObjectRender(_readyArrow, sio2->_SIO2camera, 0);
         
         sio2ObjectReset();
      }
      if (readyStatus == 0) { //arrow is red
         if (!_SIO2material_greenArrow) { //initialize material it if it hasn't been already            
                                  _SIO2material_greenArrow = sio2MaterialInit("greenArrow");
            
                                _SIO2material_greenArrow->diffuse->x = 0.0f;
            _SIO2material_greenArrow->diffuse->y = 0.0f;
            _SIO2material_greenArrow->diffuse->z = 0.0f;
            _SIO2material_greenArrow->diffuse->w = 0.5f;
            
            //change the blending mode
            _SIO2material_greenArrow->blend = SIO2_MATERIAL_ALPHA;
            
            NSLog(@"material INIT");
         }
         
         //set to red
                        _SIO2material_greenArrow->diffuse->x = 1.0f;
         _SIO2material_greenArrow->diffuse->y = 0.0f;
         
         //render the material
         sio2MaterialRender(_SIO2material_greenArrow);
         
         sio2ObjectRender(_readyArrow, sio2->_SIO2camera, 0);
         
         sio2ObjectReset();
      }
}

jj

Posts : 77
Join date : 2008-09-24

Back to top Go down

Best Practice for an Object with Variable Material Properties Empty Re: Best Practice for an Object with Variable Material Properties

Post  sio2interactive Thu Nov 20, 2008 5:59 pm

As part of the optimization process, SIO2 remember the last material pointer that have been bind to the OpenGL context, if NO other material(s) is/are rendered after SIO2 assume that every GL_STATES are already set to render it... If you make some changes on the material properties make sure to call sio2MaterialReset() at least once after you change the values, so the changes will be applied...

In addition to tutorial06 check the font tutorial... it also uses the same technique...

Cheers,
sio2interactive
sio2interactive

Posts : 1526
Join date : 2008-08-26
Age : 45
Location : Shanghai

http://sio2interactive.com

Back to top Go down

Best Practice for an Object with Variable Material Properties Empty Re: Best Practice for an Object with Variable Material Properties

Post  jj Thu Nov 20, 2008 6:07 pm

Great! Thanks...
I was able to update the ->diffuse colors accordingly.

jj

Posts : 77
Join date : 2008-09-24

Back to top Go down

Best Practice for an Object with Variable Material Properties Empty Re: Best Practice for an Object with Variable Material Properties

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum