Scripting Second Life Materials Testing

We have a new aspect of Materials arriving, the ability to script materials as we script textures (diffuse map).

Simon Linden has posted in the Server Beta UG agenda about the coming Materials Scripting feature to allow script control of the new Materials. Quoting:

  • LSL support for materials is in testing
    • Certain Aditi regions (DRTSIM-253 channel, presently) have LSL support for materials
      • Regions “roller-test102” and “roller-test103” are on this channel
      • This is still a work-in-progress – testing is still underway
    • Materials can be added to object faces with llSetPrimitiveParams() functions
      • [PRIM_SPECULAR, integer face, string texture, vector repeats, vector offsets, float rotation_in_radians, vector color, integer glossy, integer environment]
      • [PRIM_NORMAL, integer face, string texture, vector repeats, vector offsets, float rotation_in_radians]
      • [PRIM_ALPHA_MODE, integer face, integer alpha_mode, integer alpha_cutoff]
        • Valid alpha_mode options are PRIM_ALPHA_MODE_NONE, PRIM_ALPHA_MODE_BLEND, PRIM_ALPHA_MODE_MASK, PRIM_ALPHA_MODE_EMISSIVE
    • Materials can be read with the various llGetPrimitiveParams() functions
      • [PRIM_SPECULAR, integer face] returns [string texture, vector repeats, vector offsets, float rotation_in_radians, vector color, integer glossy, integer environment]
      • [PRIM_NORMAL, integer face] returns [string texture, vector repeats, vector offsets, float rotation_in_radians]
      • [PRIM_ALPHA_MODE, integer face] returns [integer alpha_mode, integer alpha_cutoff]
  • Behavior for both getting and setting materials parameters should basically correspond to behavior with PRIM_TEXTURE
  • The color vectors use 0.0-1.0 as the range, as with llSetColor()
  • The integer parameters for PRIM_SPECULAR correspond to the same values that you see in the build tool
  • Components of a material can be ‘reset’ as follows:
    • PRIM_NORMAL and PRIM_SPECULAR settings are set to ‘default’ values by setting the texture to NULL_KEY
    • PRIM_ALPHA_MODE settings are set to ‘default’ values by setting the alpha_mode to PRIM_ALPHA_MODE_BLEND
      • mask_cutoff is actually reset to 0 unless the alpha mode is PRIM_ALPHA_MODE_MASK
    • When PRIM_NORMAL, PRIM_SPECULAR, and PRIM_ALPHA_MODE settings are all set to ‘default’ values, the material is deleted from that prim face, and LI may be updated accordingly
  • Known issues
    • There is a viewer rendering issue, where the face will not be rendered and you’ll see log spam (BUG-6187),
      • If the viewer has ALM enabled
      • and a prim face has a material on it
      • and PRIM_ALPHA_MODE is PRIM_ALPHA_MODE_BLEND (this is the default after a material is added)
      • and the diffuse texture does not have an alpha channel (e.g. plywood)
    • The version currently on Aditi lacks proper throttling, so there could be performance issues if scripts behave badly

You can test this new code in ADITI regions; “roller-test102” and “roller-test103”. These are mainland regions (meaning they are running the code currently on the main grid) in the ADITI grid.

Maestro Linden tells us, “Those are both mainland [ADITI] and allow building. Well, on some parcels at least. I may have to update a few of them.

You could do some work by scripting attachments, but that may not let you test Land Impact updates (the build tool always seems to show LI = 0 for attachments).

One thing to keep in mind with that BUG-6187 (Certain location cause excessive log spam when ALM is enabled: WARNING: LLDrawPoolAlpha::renderAlpha: Missing required components, skipping render batch)  ‘known issue’ is that if your diffuse texture lacks an alpha channel, you’ll also want to set the alpha mode to PRIM_ALPHA_MODE_NONE to avoid the bug, even if you really just want to add a normal map maybe, but it’s a viewer rendering bug, so don’t expect a fix for a while.”

Arton Rotaru: So every time we change a material map, we should set alpha mode as well?

Mæstro Linden: Well, not every time, arton. Only when adding a material to a face which previously didn’t have a material, so what happens when you add a material via the build tool, is that the viewer inspects whether the current diffuse texture has an alpha channel and automatically sets the alpha mode to ALPHA_MODE_NONE if the diffuse texture is opaque. But, keeps it at _BLEND if there’s an alpha channel.

Unfortunately, the simulator can’t do this, because it doesn’t necessarily have the texture asset and doesn’t have the right libraries to process texture assets in that manner. The build tool has some trickery where it always grays out the UI for alpha mode when the texture doesn’t have an alpha channel.

Anyway, it’s kind of a hassle, but once PRIM_ALPHA_MODE is set to something ‘friendly’, you should be able to update normal or specular settings without touching it again.

The other known issue is that the current version on Aditi does not have throttling. but we plan to add some sort of throttle in the future. First we want to see what sort of rates cause which sort of performance issues.

Simon Linden: So, we’re also curious what ways you find to abuse it that will need to be fixed. Your feedback now will really help us avoid shipping problems.

Summary

To play with these changes you need to have ALM enabled. These changes are a first pass. There will be more fixes, changes, and possibly additions. If you find problems, file JIRA reports.

You also need recent viewers to catch the server side changes in the scripting language. The viewers can now update the scripting language from the region server. So, the roller_test### regions will have the language changes the viewer can pickup. These functions will NOT work in other regions.

Have fun.

5 thoughts on “Scripting Second Life Materials Testing

  1. Pingback: Testregionen für LSL-Unterstützung des Materialsystems (Post-48882) - [O.L.D.] Old London Docks Best Feeds

  2. Can you animate norm and spec maps via script, along with the diffuse map? If so, it will change water in the world. I don’t know if this would be a drain on resources or not. With moving norm and spec maps, your swimming pool water could have ripples or waves.

    • As it is now the diffuse and other maps animate in lock step. In this first pass I doubt that changes.

      The Lindens are trying to figure out how people will use the ability and what kind of load it will apply. Basically if the animation thing is worked out animation of materials, separate from the diffuse, would make for very little server load. If the script is changing maps and their positions, then the server has to pass along those changes and some load would be added. How much is the question now.

Leave a Reply

Your email address will not be published. Required fields are marked *