PRIM_GLTF_BASE_COLOR, tint vector change when trying to set Alpha
closed
Dodgeman DeCuir
Hello,
I am working on a LSL script to be able to use transparency on a PBR material applied to a Mesh object.
I am switching from OPAQUE to BLEND but doing so i am loosing the tint color memorized in a constant.
starting from:
PRIM_GLTF_BASE_COLOR, ALL_SIDES, Part3Text, PrimTextRepeatsText, PrimTextOffsetsText, PrimTextRotationText,ActiveColor,Transp,PRIM_GLTF_ALPHA_MODE_OPAQUE,Maskcutoff,Dside,
ending:
PRIM_GLTF_BASE_COLOR, ALL_SIDES, Part3Text, PrimTextRepeatsText, PrimTextOffsetsText, PrimTextRotationText,ActiveColor,Transp,PRIM_GLTF_ALPHA_MODE_BLEND,Maskcutoff,Dside,
The effect is that the Tint value of the base color is being modified to a different value in the same color range,
Example Black <0.0,0.0,0.0> is turning to grey <0.25,0.25,0.25> for no reason.
Why???
It does the same effect to any memorized tint value,
a blue dark is turning to turquoise,
a dark red turn bright red,
etc...
I am only changed the PRIM_GLTF_ALPHA_MODE from Opaque to Blend and it create that bug.
Anyone knows how to fix it?
Thank you.
Log In
Dodgeman DeCuir
Hello,
To complete this topic, i would like to thanks again Maestro and Kristy.
I modified the script with "llsRGB2Linear" as recommanded by Kristy and it ended up fixing the issue i face with having the tint being modified when trying to apply a transparency effect over it.
Here is a sample of the script fix:
}else if(message=="TranspDress25"){
Transp = 0.99;
llSetLinkPrimitiveParamsFast(Part3,[
PRIM_GLTF_BASE_COLOR, ALL_SIDES, Part3Text, PrimTextRepeatsText, PrimTextOffsetsText, PrimTextRotationText,llsRGB2Linear(ActivePart3Color),Transp,PRIM_GLTF_ALPHA_MODE_BLEND,Maskcutoff,Dside,
PRIM_GLTF_NORMAL, ALL_SIDES, Part3Norm, PrimNormRepeatsText, PrimNormOffsetsText, PrimNormRotationText]);
llSetLinkPrimitiveParamsFast(Part4,[
PRIM_GLTF_BASE_COLOR, ALL_SIDES, Part3Text, PrimTextRepeatsText, PrimTextOffsetsText, PrimTextRotationText,llsRGB2Linear(ActivePart3Color),Transp,PRIM_GLTF_ALPHA_MODE_BLEND,Maskcutoff,Dside,
PRIM_GLTF_NORMAL, ALL_SIDES, Part3Norm, PrimNormRepeatsText, PrimNormOffsetsText, PrimNormRotationText]);
It is now working perfectly.
Thank you again for your help!
Dodgeman DeCuir
Thank you all for your answers, i was away for a week and just returned, i am sorry if i haven't been able to answer earlier.
However i will make the tests considering Maestro & Kristy's comments.
Thank you very much,
Dodge.
Maestro Linden
closed
Closing for lack of repro steps.
Kristy Aurelia
PBR functions take Linear RGB colour and not sRGB, you have to call https://wiki.secondlife.com/wiki/LlsRGB2Linear before passing in colour to PRIM_GLTF_BASE_COLOR.
The viewer always shows sRGB values in the editor.
So if you take values from the viewer, let's say sRGB of 0.5 0.5 0.5, and set that as PBR colour, it gets set as linear, but then the viewer converts it back to sRGB and it becomes something like sRGB 0.7 0.7 0.7
Edit: Technically PBR Tint is not colour, it is a 'multiplier' on the texture value and only acts as colour when texture is empty or pure white. So it makes sense for it to be linear, as all the other PBR numeric values are multipliers as well.
Maestro Linden
Thanks for the repro script. How are you using it to demonstrate the bug - what is the sequence of chat commands?
Also, the script is missing debug messaging - please add some chat output which logs the PRIM_GLTF_BASE_COLOR parameters before you sets them with
llSetLinkPrimitiveParamsFast()
and also reads back the resulting PRIM_GLTF_BASE_COLOR values with llGetLinkPrimitiveParams()
both before and
after llSetLinkPrimitiveParamsFast()
operation. I'd recommend using something similar to what I had in my script.If there is a bug in the SL server, it would be that PRIM_GLTF_BASE_COLOR was updated by the
llSetLinkPrimitiveParamsFast()
operation but somehow the values were misapplied.Dodgeman DeCuir
Maestro Linden Hello Maestro, i ll try to answer in details as soon as possible, working actually on a project that doesn't give me much time left. Thank you!
Plus, i am unfamiliar with Debug console on SL or the Dev part, not sure how to proceed to be able to get the logs out of the commands that would be sent by the HUD i scripted.
To make it short,
The HUD allows choice of colors, the mesh got a script receiver listening on the channel, when a button for a color on the hud is pressed, it send a message to the receiver with the color name, then on receiving the message, the function matching the message is initiated, line by line.
How to check this line by line... like on a debug, i don't know, never did before on SL.
Maestro Linden
Dodgeman DeCuir: I would recommend adding lines like I put in my test script:
```
llOwnerSay("After new override, PRIM_GLTF_BASE_COLOR now reads back:\n"
+ llList2Json(JSON_ARRAY, llGetLinkPrimitiveParams(LINK_THIS, [PRIM_GLTF_BASE_COLOR, 0])));
```
Similarly, it would be good to print out the parameters (including tint) before you set them. That way, we can see if something like tint changed unexpectedly given what the script is actually setting.
Maestro Linden
needs info
Maestro Linden
I can't reproduce this on Second Life Server 2024-06-11.9458617693. Here's what I did:
- Rezez a sphere
- Placed the script below in the sphere, which uses the same variable names you used. I set up some basic values for the override parameters.
- When the script runs, it sets an initial override with the alpha mode set to PRIM_GLTF_ALPHA_MODE_OPAQUE. The override is applied exactly as I set it:
Set initial PRIM_GLTF_BASE_COLOR overrides to:
["4b5f6112-ae68-7439-32c8-8f289cc0737d","<1.000000, 1.000000, 0.000000>","<0.000000, 0.000000, 0.000000>",0.000000,"<1.000000, 0.000000, 0.000000>",0.800000,0,0.100000,0]
With initial override, PRIM_GLTF_BASE_COLOR now reads back:
["4b5f6112-ae68-7439-32c8-8f289cc0737d","<1.000000, 1.000000, 0.000000>","<0.000000, 0.000000, 0.000000>",0.000000,"<1.000000, 0.000000, 0.000000>",0.800000,0,0.100000,0]
- When the user touches the object, it applies a nearly-identical PRIM_GLTF_BASE_COLOR override. The override is the same as the previous one, _except_ that the alpha mode is now PRIM_GLTF_ALPHA_MODE_BLEND.
- On reading back the new override, the script reports that the tint is exactly the same as before (<1,0,0> - red) and that the only thing that changed was the alpha mode (it went from _OPAQUE = 0 to _BLEND = 1):
After new override, PRIM_GLTF_BASE_COLOR now reads back:
["4b5f6112-ae68-7439-32c8-8f289cc0737d","<1.000000, 1.000000, 0.000000>","<0.000000, 0.000000, 0.000000>",0.000000,"<1.000000, 0.000000, 0.000000>",0.800000,1,0.100000,0]
- Upon editing the material with the build tool, I see that it agrees with the latest PRIM_GLTF_BASE_COLOR parameters that were reported by the script.
key Part3Text = "4b5f6112-ae68-7439-32c8-8f289cc0737d"; // some texture with an alpha channel from library
vector PrimTextRepeatsText = <1,1,0>; // texture repeats
vector PrimTextOffsetsText = ZERO_VECTOR; // texture offset
float PrimTextRotationText = 0; // texture rotation
vector ActiveColor = <1,0,0>; // texture tint
float Transp = 0.8 ; // Alpha level
float Maskcutoff = 0.1; // alpha mask cutoff
integer Dside = FALSE; // double sided flag
default
{
state_entry()
{
// this material has an alpha-blended base color with a white tint and alpha = 0.5
llSetLinkRenderMaterial(LINK_THIS, "c9d18d51-4d4a-76cb-5914-91959327e41d", ALL_SIDES);
list initOverride = [Part3Text, PrimTextRepeatsText, PrimTextOffsetsText, PrimTextRotationText, ActiveColor, Transp, PRIM_GLTF_ALPHA_MODE_OPAQUE, Maskcutoff, Dside];
llOwnerSay("Set initial PRIM_GLTF_BASE_COLOR overrides to:\n" + llList2Json(JSON_ARRAY, initOverride));
llSetLinkPrimitiveParams(LINK_THIS, [PRIM_GLTF_BASE_COLOR, ALL_SIDES] + initOverride);
llOwnerSay("With initial override, PRIM_GLTF_BASE_COLOR now reads back:\n"
+ llList2Json(JSON_ARRAY, llGetLinkPrimitiveParams(LINK_THIS, [PRIM_GLTF_BASE_COLOR, 0])));
}
touch_start(integer total_number)
{
// same as initOverride but using PRIM_GLTF_ALPHA_MODE_BLEND
list newOverride = [Part3Text, PrimTextRepeatsText, PrimTextOffsetsText, PrimTextRotationText, ActiveColor, Transp, PRIM_GLTF_ALPHA_MODE_BLEND, Maskcutoff, Dside];
llSetLinkPrimitiveParams(LINK_THIS, [PRIM_GLTF_BASE_COLOR, ALL_SIDES] + newOverride);
llOwnerSay("After new override, PRIM_GLTF_BASE_COLOR now reads back:\n"
+ llList2Json(JSON_ARRAY, llGetLinkPrimitiveParams(LINK_THIS, [PRIM_GLTF_BASE_COLOR, 0])));
}
}
It's possible that this bug only reproduces for certain values of PRIM_GLTF_BASE_COLOR - if you update my script to use your actual values for ActiveColor and friends, are you able still able to reproduce the issue?
Dodgeman DeCuir
Maestro Linden,
Thank you for your answer, to give more details i ll post here a short version of the script i used:
/* VARIABLES DEFINITION */
//MESH FRONT PART
integer Part3 = 1;
//COM CHANNEL
integer channel_active = 123456;
//ACTIVE MATERIALS
string ActiveMatMesh = "";
//MESH PART MATERIALS SETTINGS
string Part3Material1 ="a1ba5f2b-09ac-0f08-c927-8e597cdc3ab4"; //BLACK TINTED
string Part3Material2 ="c4e8e84c-8965-f1f3-415b-6e1bc00efe2c"; // WHITE
string Part3Material3 ="66ffeb62-1f0e-f769-64c2-6e398b2f6822"; // RED
string Part3Material4 ="73d3d656-933c-94db-632c-b74025cf79a6"; // PURPLE
string Part3Text ="4f6cbef4-d7fa-7b42-97cb-bb4dbe0dd150";
string Part3Norm ="9fdffc78-3c3c-062c-d883-acb31662d183";
string Part3Spec ="529efb5a-621a-e114-370b-8c029ab20fb8";
string Part3Emissive ="7bd5ecc5-275a-a5a9-f158-5bf0756e1f8a";
//STORING ACTIVE COLOR
vector ActivePart3Color = <1.0, 1.0, 1.0>;
// COLORS LIST
vector Part3Color1 = <0.051, 0.051, 0.051>;
vector Part3Color2 = <1.0, 1.0, 1.0>;
vector Part3Color3 = <0.361, 0.000, 0.000>;
vector Part3Color4 = <0.380, 0.016, 0.400>;
//GLOSSINESS COLOR
vector SpecColor0 = <1.0, 1.0, 1.0>;
vector SpecColor1 = <0.000, 0.773, 0.773>;
vector SpecColor2 = <0.502, 0.502, 1.000>;
vector SpecColor3 = <0.016, 0.341, 0.757>;
//OTHER SETTINGS
vector PrimTextRepeatsText = <1.0, 1.0, 0.0>;
vector PrimTextOffsetsText = <0.0, 0.0, 0.0>;
float PrimTextRotationText = 0.0;
vector PrimNormRepeatsText = <1.0, 1.0, 0.0>;
vector PrimNormOffsetsText = <0.0, 0.0, 0.0>;
float PrimNormRotationText = 0.0;
vector PrimSpecRepeatsText = <1.0, 1.0, 0.0>;
vector PrimSpecOffsetsText = <0.0, 0.0, 0.0>;
float PrimSpecRotationText = 0.0;
//TRANSPARENCY
float Transp = 1.0;
//ALPHA MASK CUTOFF
float Maskcutoff = 0.5;
//DOUBLE SIDED VALUE
integer Dside = 0;
//METALLIC
float Metallic = 0.3;
//ROUGHNESS
float Roughness = 0.5;
//SPECULAR TINT
vector PrimSpecColor = <1.0, 1.0, 1.0>;
default
{
state_entry(){
llListen(channel_active, "", NULL_KEY, "" );
}
listen(integer number, string name, key id, string message){
if (llGetOwnerKey(id) == llGetOwner()){
/* SETTING MESH PART MATERIAL */
//MESH FRONT PART
if(message=="MeshText1"){
ActiveMatMesh = Part3Material1;
ActivePart3Color = Part3Color1;
llSetLinkPrimitiveParamsFast(Part3,[
PRIM_RENDER_MATERIAL, ALL_SIDES, ActiveMatMesh,
PRIM_GLTF_BASE_COLOR, ALL_SIDES, Part3Text, PrimTextRepeatsText, PrimTextOffsetsText, PrimTextRotationText,ActivePart3Color,Transp,PRIM_GLTF_ALPHA_MODE_OPAQUE,Maskcutoff,Dside,
PRIM_GLTF_NORMAL, ALL_SIDES, Part3Norm, PrimNormRepeatsText, PrimNormOffsetsText, PrimNormRotationText,
PRIM_GLTF_METALLIC_ROUGHNESS, ALL_SIDES, Part3Emissive, PrimTextRepeatsText, PrimTextOffsetsText, PrimTextRotationText, Metallic, Roughness,
PRIM_GLTF_EMISSIVE, ALL_SIDES, Part3Spec, PrimSpecRepeatsText, PrimSpecOffsetsText, PrimSpecRotationText, PrimSpecColor]);
}else if(message=="MeshText2"){
ActiveMatMesh = Part3Material2;
ActivePart3Color = Part3Color2;
llSetLinkPrimitiveParamsFast(Part3,[
PRIM_RENDER_MATERIAL, ALL_SIDES, ActiveMatMesh,
PRIM_GLTF_BASE_COLOR, ALL_SIDES, Part3Text, PrimTextRepeatsText, PrimTextOffsetsText, PrimTextRotationText,ActivePart3Color,Transp,PRIM_GLTF_ALPHA_MODE_OPAQUE,Maskcutoff,Dside,
PRIM_GLTF_NORMAL, ALL_SIDES, Part3Norm, PrimNormRepeatsText, PrimNormOffsetsText, PrimNormRotationText,
PRIM_GLTF_METALLIC_ROUGHNESS, ALL_SIDES, Part3Emissive, PrimTextRepeatsText, PrimTextOffsetsText, PrimTextRotationText, Metallic, Roughness,
PRIM_GLTF_EMISSIVE, ALL_SIDES, Part3Spec, PrimSpecRepeatsText, PrimSpecOffsetsText, PrimSpecRotationText, PrimSpecColor]);
}else if(message=="MeshText3"){
ActiveMatMesh = Part3Material3;
ActivePart3Color = Part3Color3;
llSetLinkPrimitiveParamsFast(Part3,[
PRIM_RENDER_MATERIAL, ALL_SIDES, ActiveMatMesh,
PRIM_GLTF_BASE_COLOR, ALL_SIDES, Part3Text, PrimTextRepeatsText, PrimTextOffsetsText, PrimTextRotationText,ActivePart3Color,Transp,PRIM_GLTF_ALPHA_MODE_OPAQUE,Maskcutoff,Dside,
PRIM_GLTF_NORMAL, ALL_SIDES, Part3Norm, PrimNormRepeatsText, PrimNormOffsetsText, PrimNormRotationText,
PRIM_GLTF_METALLIC_ROUGHNESS, ALL_SIDES, Part3Emissive, PrimTextRepeatsText, PrimTextOffsetsText, PrimTextRotationText, Metallic, Roughness,
PRIM_GLTF_EMISSIVE, ALL_SIDES, Part3Spec, PrimSpecRepeatsText, PrimSpecOffsetsText, PrimSpecRotationText, PrimSpecColor]);
//ETC.... ETC....
//SETTING MESH PART TRANSPARENCY
}else if(message=="TranspMesh0"){
Transp = 1.0;
llSetLinkPrimitiveParamsFast(Part3,[
PRIM_RENDER_MATERIAL, ALL_SIDES, ActiveMatMesh,
PRIM_GLTF_BASE_COLOR, ALL_SIDES, Part3Text, PrimTextRepeatsText, PrimTextOffsetsText, PrimTextRotationText,ActivePart3Color,Transp,PRIM_GLTF_ALPHA_MODE_OPAQUE,Maskcutoff,Dside,
PRIM_GLTF_NORMAL, ALL_SIDES, Part3Norm, PrimNormRepeatsText, PrimNormOffsetsText, PrimNormRotationText]);
}else if(message=="TranspMesh2"){
Transp = 0.97;
llSetLinkPrimitiveParamsFast(Part3,[
PRIM_GLTF_BASE_COLOR, ALL_SIDES, Part3Text, PrimTextRepeatsText, PrimTextOffsetsText, PrimTextRotationText,ActivePart3Color,Transp,PRIM_GLTF_ALPHA_MODE_BLEND,Maskcutoff,Dside,
PRIM_GLTF_NORMAL, ALL_SIDES, Part3Norm, PrimNormRepeatsText, PrimNormOffsetsText, PrimNormRotationText]);
}else if(message=="TranspMesh3"){
Transp = 0.95;
llSetLinkPrimitiveParamsFast(Part3,[
PRIM_GLTF_BASE_COLOR, ALL_SIDES, Part3Text, PrimTextRepeatsText, PrimTextOffsetsText, PrimTextRotationText,ActivePart3Color,Transp,PRIM_GLTF_ALPHA_MODE_BLEND,Maskcutoff,Dside,
PRIM_GLTF_NORMAL, ALL_SIDES, Part3Norm, PrimNormRepeatsText, PrimNormOffsetsText, PrimNormRotationText]);
//Etc.... Etc...
}
}
}
}
Here is the final Result when switching from Opaque PBR to Blend PBR.
on the PBR, the RGB / LSL / Hex defined values have changed when applied Transparency.
on the Standard texture (NO PBR), the RGB / LSL / Hex values are identicals to what has been defined in the "colors" settings.
I really don't get it...
I hope those details will help figure out what goes wrong.
Thank you.