Difference between revisions of "GLTF Overrides"

From Second Life Wiki
Jump to navigation Jump to search
(Minor formatting tweak.)
(Add example script of how to change a glTF override while preserving texture transform information on each face.)
Line 34: Line 34:


When a no-mod glTF material is applied to a prim face, its glTF overrides cannot be modified, with the exception of texture transforms.
When a no-mod glTF material is applied to a prim face, its glTF overrides cannot be modified, with the exception of texture transforms.
== Examples ==
Set all faces of a prim to 50% transparent, while preserving texture transforms.
<syntaxhighlight lang="lsl2">
integer enable;
default
{
    state_entry()
    {
        llSay(0, "glTF alpha script!");
    }
    touch_start(integer total_number)
    {
        enable = !enable;
        llSay(0, "Making surfaces " + llList2String(["default","transparent"],enable));
        list toDo;
       
        list transforms = llGetPrimitiveParams([PRIM_GLTF_BASE_COLOR,ALL_SIDES]); //Get transform info for each face.
       
        integer faceCount = llGetLinkNumberOfSides(0); //Get the number of faces in this prim.
       
        integer i;
        for(; i < faceCount; ++i) //Act on all faces of this prim.
        {
            //Loop to build out toDo list while preserving transforms of each face.
            vector repeats = llList2Vector(transforms, 1 + (i*9));
            vector offsets = llList2Vector(transforms, 2 + (i*9));
            toDo += [PRIM_GLTF_BASE_COLOR, i, "", repeats, offsets, "", ""]; //Start glTF command while preserving existing transforms for active face.
            if(enable)
            {
                toDo += [0.5, PRIM_GLTF_ALPHA_MODE_BLEND]; //Set face to 50% transparent, and enable alpha blending.
            }
            else
                toDo += ["",""]; //Revert to material defaults (disable override)
            toDo += ["", ""]; //Finish the glTF command, but don't change anything.
        }
       
        llSetLinkPrimitiveParamsFast(0,toDo); //Make the changes.
    }
}
</syntaxhighlight>

Revision as of 15:01, 22 December 2023


What are they?

glTF overrides are an implementation detail of PBR materials, which only makes sense when a glTF material is applied to a face of a prim.

A glTF override is a collection of changes applied on top of a glTF material asset, plus texture transforms.

Texture transforms

glTF texture transforms behave differently than their Blinn-Phong counterparts, and instead follow the [KHR_texture_transform spec]. Because of this, texture animations are animated independently of the texture transforms.

Applying a glTF material from LSL

These prim params affect the glTF material on a face:

When setting PRIM_RENDER_MATERIAL on a face, most of the glTF overrides will be cleared on that face, with the exception of texture transforms (repeats, offsets, and rotation_in_radians).

The rest of these prim params are for glTF overrides. For example, PRIM_GLTF_BASE_COLOR includes the glTF base color property overrides as well as the base color texture transform. Setting nearly any glTF override to the empty string ("") will unset it, causing the property of the underlying glTF material asset to be used instead.

KBwarning.png Warning: Currently, texture transforms are (destructively) overwritten, meaning that setting an empty string ("") will cause them to revert to their appropriate default values instead, losing the original value. This may change in future.

Note that it is not possible to read properties of the underlying glTF material asset from scripts. If a property is unset, it will be the empty string ("") when read from a script.

Attempting to set a glTF override when PRIM_RENDER_MATERIAL is NULL_KEY will clear most glTF overrides on that face, with the exceptions of texture transforms.

Permissions

When a no-mod glTF material is applied to a prim face, its glTF overrides cannot be modified, with the exception of texture transforms.

Examples

Set all faces of a prim to 50% transparent, while preserving texture transforms.

integer enable;

default
{
    state_entry()
    {
        llSay(0, "glTF alpha script!");
    }

    touch_start(integer total_number)
    {
        enable = !enable;
        llSay(0, "Making surfaces " + llList2String(["default","transparent"],enable));
        list toDo;
        
        list transforms = llGetPrimitiveParams([PRIM_GLTF_BASE_COLOR,ALL_SIDES]); //Get transform info for each face.
        
        integer faceCount = llGetLinkNumberOfSides(0); //Get the number of faces in this prim.
        
        integer i;
        for(; i < faceCount; ++i) //Act on all faces of this prim.
        {
            //Loop to build out toDo list while preserving transforms of each face.
            vector repeats = llList2Vector(transforms, 1 + (i*9));
            vector offsets = llList2Vector(transforms, 2 + (i*9));
            toDo += [PRIM_GLTF_BASE_COLOR, i, "", repeats, offsets, "", ""]; //Start glTF command while preserving existing transforms for active face.
            if(enable)
            {
                toDo += [0.5, PRIM_GLTF_ALPHA_MODE_BLEND]; //Set face to 50% transparent, and enable alpha blending.
            }
            else
                toDo += ["",""]; //Revert to material defaults (disable override)
            toDo += ["", ""]; //Finish the glTF command, but don't change anything.
        }
        
        llSetLinkPrimitiveParamsFast(0,toDo); //Make the changes.
    }
}