Difference between revisions of "GLTF Overrides"

From Second Life Wiki
Jump to navigation Jump to search
m (→‎Texture transforms: fixed external link)
 
(13 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{hint
|mode=warning
|title_desc=Future feature
|desc=This function will be supported in the upcoming PBR Terrain project.</b><br/>Currently it will only work in supported testing areas with a supported test viewer.
}}
[[Category:glTF]]
[[Category:glTF]]


== What are they? ==
== What are they? ==


GLTF Overrides are an implementation detail of [[PBR_Materials|PBR materials]], which only makes sense when a GLTF material is applied to a face of a prim.
glTF overrides are an implementation detail of [[PBR_Materials|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.
A glTF override is a collection of changes applied on top of a glTF material asset, plus texture transforms.


== Texture transforms ==
== Texture transforms ==


GLTF texture transforms behave differently than their Blinn-Phong counterparts, and instead follow the [[https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform KHR_texture_transform spec]]. Because of this, [[LlSetTextureAnim|texture animations]] are animated independently of the texture transforms.
glTF texture transforms behave differently than their Blinn-Phong counterparts, and instead follow the [https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_texture_transform KHR texture transform spec]. Because of this, [[LlSetTextureAnim|texture animations]] are animated independently of the texture transforms.


== Applying a GLTF material from LSL ==
== Applying a glTF material from LSL ==


These prim params affect the GLTF material on a face:
These prim params affect the glTF material on a face:


* [[PRIM_RENDER_MATERIAL]]
* [[PRIM_RENDER_MATERIAL]]
Line 27: Line 21:
* [[PRIM_GLTF_EMISSIVE]]
* [[PRIM_GLTF_EMISSIVE]]


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).
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.


The rest of these prim params are GLTF overrides. For example, [[PRIM_GLTF_BASE_COLOR]] includes the GLTF base color properties as well as the base color texture transform. Setting any GLTF override parameter to the empty string ("") will unset it, causing the property of the underlying GLTF material asset to be used instead.
{{LSL Constants/PrimitiveParams/gltf caveats‎}}


Note that it is not possible to read properties of the underlying GLTF material asset from scripts. If a property is unset, it will appear to be the default value when read from a script.
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.
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 ==
== 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.
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;
        list toDo;
       
        list transforms = llGetPrimitiveParams([PRIM_GLTF_BASE_COLOR,ALL_SIDES]); //Get transform info for each face.
        list repeats = llList2ListSlice(transforms,0,-1,9,1); //Store repeat information for each face in a list
        list offsets = llList2ListSlice(transforms,0,-1,9,2); //Same as above, but for offset info.
       
        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.
            toDo += [PRIM_GLTF_BASE_COLOR, i, "", llList2Vector(repeats,i), llList2Vector(offsets,i), "", ""]; //Start glTF command while preserving existing transforms for active face.
            toDo += llList2ListSlice(["",0.5,"", PRIM_GLTF_ALPHA_MODE_BLEND],0,-1,2,enable); //Either set the face to 50% transparent and alpha blending mode, or revert to material defaults, based on the value of enable.
            toDo += ["", ""]; //Finish the glTF command, but don't change anything.
        }
       
        llSetLinkPrimitiveParamsFast(0,toDo); //Make the changes.
        llSay(0, "Making surfaces " + llList2String(["default","transparent"],enable));
    }
}
</syntaxhighlight>

Latest revision as of 09:36, 28 September 2024


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.

This parameter's arguments are GLTF overrides.

KBwarning.png Warning: Setting an argument to the empty string ("") will clear the respective override. GLTF texture transforms are always overrides, so setting them to the empty string ("") will clear them. See this example for a workaround. The SL team is open to feedback on LSL improvements for GLTF.

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;
        list toDo;
        
        list transforms = llGetPrimitiveParams([PRIM_GLTF_BASE_COLOR,ALL_SIDES]); //Get transform info for each face.
        list repeats = llList2ListSlice(transforms,0,-1,9,1); //Store repeat information for each face in a list
        list offsets = llList2ListSlice(transforms,0,-1,9,2); //Same as above, but for offset info.
        
        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.
            toDo += [PRIM_GLTF_BASE_COLOR, i, "", llList2Vector(repeats,i), llList2Vector(offsets,i), "", ""]; //Start glTF command while preserving existing transforms for active face.
            toDo += llList2ListSlice(["",0.5,"", PRIM_GLTF_ALPHA_MODE_BLEND],0,-1,2,enable); //Either set the face to 50% transparent and alpha blending mode, or revert to material defaults, based on the value of enable.
            toDo += ["", ""]; //Finish the glTF command, but don't change anything.
        }
        
        llSetLinkPrimitiveParamsFast(0,toDo); //Make the changes.
        llSay(0, "Making surfaces " + llList2String(["default","transparent"],enable));
    }
}