As the venture in the realm of Shaders and materials you may encounter the odd obstacle. Please post your shader issue for the community to help.

entity::setSubMaterialName

entity::setSubMaterialName

Postby Shando » 08 Oct 2013, 03:20

Hi all,

In the description for entity::setSubMaterialName it states:

Note: Only put the material name that would exist inside the .material file and NOT the .material file name.


Can you please confirm that this means that *all* materials that will be used by an entity will need to be declared in the .material file?

Thanks

Shando
Last edited by Shando on 02 Jan 2014, 22:11, edited 1 time in total.
User avatar
Shando
Skyline Moderator
Skyline Moderator
 
Posts: 560
Joined: 06 Mar 2013, 22:35
Location: Moffat Beach, Queensland
Skill: Programmer
Skill: Scripter
Skill: Level Designer

Re: entity::setSubMaterialName

Postby SolarPortal » 08 Oct 2013, 12:10

yes, all materials that you wish to call through lua using the "setEntityMaterialName" or "setSubMaterialName" have to be declared inside a .material file.

They don't have to be in the same .material file. You could have as many .material files as you want with any number of materials inside each one, but when calling you have to call the material file name that would exist inside any of those .material files.

Obviously, the .material files have to exist within the asset library or your project

Check out the "$(Tech Demos)\Lua\Entity Materials\setEntityMaterial" tech demo.
In this demo we change the material when the number 1 or 2 key is pressed, which sets the material either as "Proto_Red_adv" or "Proto_Sand_adv", both of these materials exist in different .material files.

Hope this helps :D
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3631
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: entity::setSubMaterialName

Postby Shando » 08 Oct 2013, 13:05

Cool 8-)

At least I don't have to worry about remembering to include everything I need from the start :P as I can just set up another .material file when needed.

Shando
User avatar
Shando
Skyline Moderator
Skyline Moderator
 
Posts: 560
Joined: 06 Mar 2013, 22:35
Location: Moffat Beach, Queensland
Skill: Programmer
Skill: Scripter
Skill: Level Designer

Re: entity::setSubMaterialName

Postby Shando » 02 Jan 2014, 13:10

Hi all,

I'm trying to set the Materials using entity.setSubMaterialName:

Code: Select all
   id = entity.spawn ( "crystal_mine", nLocX, 0.78, nLocZ, 0.012, 0.012, 0.012 );

sky.lprint("Original Material");      
for i = 0, 4 do
   j = entity.getMaterialName(id, i);
   sky.lprint(j);
end

   if ( playNo == 1 ) then
      entity.setSubMaterialName ( id, 2, "crystals_b_adv" );
      entity.setSubMaterialName ( id, 3, "sec_b_adv" );
      entity.setSubMaterialName ( id, 4, "main_b_adv" );
   elseif ( playNo == 2 ) then
      entity.setSubMaterialName ( id, 2, "crystals_g_adv" );
      entity.setSubMaterialName ( id, 3, "sec_g_adv" );
      entity.setSubMaterialName ( id, 4, "main_g_adv" );
   elseif ( playNo == 3 ) then
      entity.setSubMaterialName ( id, 2, "crystals_r_adv" );
      entity.setSubMaterialName ( id, 3, "sec_r_adv" );
      entity.setSubMaterialName ( id, 4, "main_r_adv" );
   elseif ( playNo == 4 ) then
      entity.setSubMaterialName ( id, 2, "crystals_y_adv" );
      entity.setSubMaterialName ( id, 3, "sec_y_adv" );
      entity.setSubMaterialName ( id, 4, "main_y_adv" );
   end

sky.lprint("");
sky.lprint("Changed Material");

for i = 0, 4 do
   j = entity.getMaterialName(id, i);
   sky.lprint(j);
end   


Unfortunately, only the "crystals" actually change (see image):

Image

The areas highlighted show up as BLACK, even though they seem to change (according to the log output)??

My main .material file is as follows:

Code: Select all
import * from "metal_sheet.material"
import * from "metal_plain.material"
import * from "main_b.material"
import * from "main_g.material"
import * from "main_r.material"
import * from "main_y.material"
import * from "sec_b.material"
import * from "sec_g.material"
import * from "sec_r.material"
import * from "sec_y.material"
import * from "crystals_b.material"
import * from "crystals_g.material"
import * from "crystals_r.material"
import * from "crystals_y.material"

material crm_mat_1 : metal_sheet
{
}

material crm_mat_1_adv : metal_sheet_adv
{
}

material crm_mat_1_deferred : metal_sheet_deferred
{
}

material crm_mat_2 : metal_plain
{
}

material crm_mat_2_adv : metal_plain_adv
{
}

material crm_mat_2_deferred : metal_plain_deferred
{
}

material crm_mat_3 : crystals_b
{
}

material crm_mat_3_adv : crystals_b_adv
{
}

material crm_mat_3_deferred : crystals_b_deferred
{
}

material crm_mat_4 : sec_b
{
}

material crm_mat_4_adv : sec_b_adv
{
}

material crm_mat_4_deferred : sec_b_deferred
{
}

material crm_mat_5 : main_b
{
}

material crm_mat_5_adv : main_b_adv
{
}

material crm_mat_5_deferred : main_b_deferred
{
}


main_g.material is like this:

Code: Select all
import * from "Base_Multilight_V1.material"
import * from "Base_Multilight_V1_AlphaSmooth.material"

material main_g
{
   technique
   {
      pass
      {
         ambient 0.5 0.5 0.5 1
         diffuse 1 1 1 1
         specular 1.53 1.53 1.53 1 22
         emissive 0 0 0 0
           
         texture_unit
         {
            texture green_main.dds
            scale 1 1
         }
      }
   }
}

material main_g_adv : Base_Multilight_V1
{
   set $diffuseMap "green_main.dds"
   set $normalMap "Blank_N.dds"
   set $specularMap "white.bmp"
   set $UV_Scale "1 1 0"
   set $diffuse_tint_color "1 1 1 1"
   set $rimlight_tint_color "1 1 1"
   set $diffuseParam "1 0 0"
   set $normalParam "0 1.5 0"
   set $misc1 "1.53 22 0 1"
   set $RimLight_Params "2.5 2.5 0.3 3"
   set $LodDistance_0 "50"
   set $UV_LodScale "1 1"
}

material main_g_deferred
{
   technique
   {
      pass
      {
         diffuse 1 1 1 1
         specular 1.53 1.53 1.53 1 22   
         texture_unit
         {
            texture "green_main.dds"
         }

         texture_unit NormalMap
         {
            texture "Blank_N.dds"
         }
      }
   }
}


sec_g.material is:

Code: Select all
import * from "Base_Multilight_V1.material"
import * from "Base_Multilight_V1_AlphaSmooth.material"

material sec_g
{
   technique
   {
      pass
      {
         ambient 0.5 0.5 0.5 1
         diffuse 1 1 1 1
         specular 1.53 1.53 1.53 1 22
         emissive 0 0 0 0
           
         texture_unit
         {
            texture green_secondary.dds
            scale 1 1
         }
      }
   }
}

material sec_g_adv : Base_Multilight_V1
{
   set $diffuseMap "green_secondary.dds"
   set $normalMap "Blank_N.dds"
   set $specularMap "black.dds"
   set $UV_Scale "1 1 0"
   set $diffuse_tint_color "1 1 1 1"
   set $rimlight_tint_color "1 1 1"
   set $diffuseParam "1 0 0"
   set $normalParam "0 1.5 0"
   set $misc1 "1.53 22 0 1"
   set $RimLight_Params "2.5 2.5 0.3 3"
   set $LodDistance_0 "50"
   set $UV_LodScale "1 1"
}

material sec_g_deferred
{
   technique
   {
      pass
      {
         diffuse 1 1 1 1
         specular 1.53 1.53 1.53 1 22   
         texture_unit
         {
            texture "green_secondary.dds"
         }

         texture_unit NormalMap
         {
            texture "Blank_N.dds"
         }
      }
   }
}


and finally, crystals_g.material:

Code: Select all
import * from "Base_Multilight_V1.material"
import * from "Base_Multilight_V1_AlphaSmooth.material"
import * from "Shadowmap_Depth1.material"

material crystals_g_ShadowCaster : Shadowmap_depth1_Caster_Alpha
{
   set $diffuseMap "green_main_transparent_75.dds"
}

material crystals_g
{
   technique
   {
      pass
      {
         ambient 0.5 0.5 0.5 1
         diffuse 1 1 1 1
         specular 1.53 1.53 1.53 1 22
         emissive 0 0 0 0
           
         texture_unit
         {
            texture green_main_transparent_75.dds
            scale 1 1
         }
      }
   }
}

material crystals_g_adv : Base_Multilight_V1_AlphaSmooth
{
   set $diffuseMap "green_main_transparent_75.dds"
   set $normalMap "Blank_N.dds"
   set $specularMap "white.bmp"
   set $UV_Scale "1 1 0"
   set $diffuse_tint_color "1 1 1 1"
   set $rimlight_tint_color "1 1 1"
   set $diffuseParam "1 0 0"
   set $normalParam "0 1.5 0"
   set $misc1 "1.53 22 0 1"
   set $RimLight_Params "2.5 2.5 0.3 3"
   set $LodDistance_0 "50"
   set $UV_LodScale "1 1"
   set $shadowCasterMaterial "crystals_g_ShadowCaster"
}

material crystals_g_deferred
{
   technique
   {
      pass
      {
         diffuse 1 1 1 1
         specular 1.53 1.53 1.53 1 22   
         texture_unit
         {
            texture "green_main_transparent_75.dds"
         }

         texture_unit NormalMap
         {
            texture "Blank_N.dds"
         }
      }
   }
}


Based on the above, I can't figure out why the "crystals" change colour, but the others come up as BLACK??

Any help would be greatly appreciated.

Regards

Shando

PS: forgot to mention that if I just change the crystals colour, the main and secondary colours show the correct default colours (so I assume it's not a normals issue?).
PS: Happy New Year to you all!
User avatar
Shando
Skyline Moderator
Skyline Moderator
 
Posts: 560
Joined: 06 Mar 2013, 22:35
Location: Moffat Beach, Queensland
Skill: Programmer
Skill: Scripter
Skill: Level Designer

Re: entity::setSubMaterialName

Postby Shando » 03 Jan 2014, 06:26

OK, been doing some digging, and this problem is to do with "Shadows" :?:

I've switched from "Stencil" to "Mapped" in the "Scene Settings" dialog, and everything is now coloured correctly :D BUT I now have no Shadows :(

Any ideas on how I can have both????

Thanks

Shando
User avatar
Shando
Skyline Moderator
Skyline Moderator
 
Posts: 560
Joined: 06 Mar 2013, 22:35
Location: Moffat Beach, Queensland
Skill: Programmer
Skill: Scripter
Skill: Level Designer

Re: entity::setSubMaterialName

Postby SolarPortal » 03 Jan 2014, 10:52

lol shadows :P

in the scene settings, to get the original shadows back choose these settings.
Code: Select all
Shadows: Mapped
Shadow Tech: Additive Integrated
Shadow Cam: Focused
Shadow Size: 1024 - but anything works.


If your working with a material that is set using the "entity.setSubMaterialName", then are you working with the advanced material as you need to specify "_adv" after the material name.
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3631
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: entity::setSubMaterialName

Postby Shando » 03 Jan 2014, 12:49

Hi SolarPortal,

Thanks, I now have Shadows back :D Unfortunately, the colours are gone :(

This code:

Code: Select all
id = entity.spawn ( "crystal_mine", nLocX, 0.78, nLocZ, 0.012, 0.012, 0.012 );
playNo = math.random ( 4 );

sky.lprint("Original Material");
for i = 0, 4 do
   j = entity.getMaterialName(id, i);
   sky.lprint(j);
end

if ( playNo == 1 ) then
   entity.setSubMaterialName ( id, 2, "crystals_b_adv" );
   entity.setSubMaterialName ( id, 3, "sec_b_adv" );
   entity.setSubMaterialName ( id, 4, "main_b_adv" );
elseif ( playNo == 2 ) then
   entity.setSubMaterialName ( id, 2, "crystals_g_adv" );
   entity.setSubMaterialName ( id, 3, "sec_g_adv" );
   entity.setSubMaterialName ( id, 4, "main_g_adv" );
elseif ( playNo == 3 ) then
   entity.setSubMaterialName ( id, 2, "crystals_r_adv" );
   entity.setSubMaterialName ( id, 3, "sec_r_adv" );
   entity.setSubMaterialName ( id, 4, "main_r_adv" );
elseif ( playNo == 4 ) then
   entity.setSubMaterialName ( id, 2, "crystals_y_adv" );
   entity.setSubMaterialName ( id, 3, "sec_y_adv" );
   entity.setSubMaterialName ( id, 4, "main_y_adv" );
end

sky.lprint("");
sky.lprint("Changed Material");
for i = 0, 4 do
   j = entity.getMaterialName(id, i);
   sky.lprint(j);
end   


generates this output in the log:

Code: Select all
Original Material
crm_mat_1
crm_mat_2
crm_mat_3
crm_mat_4
crm_mat_5

Changed Material
crm_mat_1
crm_mat_2
crystals_g_adv
sec_g_adv
main_g_adv


So, you can see that I'm using the Advanced Materials, but it seems like I can have either:

1) correct colours with no Shadows? or
2) Shadows with only the Crystals showing the correct colours?

Any thoughts????

Thanks

Shando
User avatar
Shando
Skyline Moderator
Skyline Moderator
 
Posts: 560
Joined: 06 Mar 2013, 22:35
Location: Moffat Beach, Queensland
Skill: Programmer
Skill: Scripter
Skill: Level Designer

Re: entity::setSubMaterialName

Postby SolarPortal » 03 Jan 2014, 13:41

sounds like the materials being changed to e.g. "sec_" + "main_" have got a material problem or missing properties.
Are they using the same base material as the crystal, and are they using the set mat property (example: set $color"1 1 1") or inheriting from the base.

I cant imagine it being the shadows if the crystals are working.
i would compare the crystals material to the other materials.

Without seeing anything, i can only guess. lol :P

Hope this helps :D
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3631
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: entity::setSubMaterialName

Postby Shando » 03 Jan 2014, 22:20

Hi SolarPortal,

They are identical, except for the $diffuseMap, and that the Crystals use a ShadowCaster (see my earlier post for the details of the various materials).

Regards

Shando
User avatar
Shando
Skyline Moderator
Skyline Moderator
 
Posts: 560
Joined: 06 Mar 2013, 22:35
Location: Moffat Beach, Queensland
Skill: Programmer
Skill: Scripter
Skill: Level Designer


Return to Shaders n Materials

Who is online

Users browsing this forum: No registered users and 4 guests

cron