Possible bug with uniforms in PBRCustomMaterial

Hello, everyone!
In my project I wrote a custom material which is based on PBRCustomMaterial. I pass some data via uniforms into it.
For two days I was trying to catch a following bug in my code:
If a mesh which uses this material is scaled, suddenly uniforms stop working.
But if the mesh was scaled previously and then material applied, it looks normal until it is scaled to default (1,1,1).
I was thinking that it was mistake somewhere in my code or I’m using these functions in an unintended way.
I prepared a small example which reproduces https://www.babylonjs-playground.com/#I8SFV3#2
Bug appears in playground when mesh is scaled in the debugging window.
Also in a small sinusoidal loop mesh is painted in black when scale is 1.

1 Like

Pinging @nasimiasl

1 Like

i don’t get the bug ?

The idea or reproduction? In playground every 360 frames sphere blinks to black. Maybe it would be better to change denominator to 36. Then every 10 frames.

https://www.babylonjs-playground.com/#I8SFV3#3

I’m sorry. But in version #3 the scale never hits the value of 1. Do I understand correctly that for my project I should somehow write a workaround to ensure that scale never lands on a value of 1?

https://www.babylonjs-playground.com/#I8SFV3#4
that is not depend to scale 1 as i know

Hello again. But on what does this bug depend on then? Because in all examples value of 1 is avoided in slightly different ways.

ok let me look deeper :slight_smile:

just for ask is it necessary you scale object to -1?

I think no. Let me check in my project.

Well, I think I can work without negative scaling.

haha catch it
dont trust javascript the Math in Javascript not same as Math in real
j +=Math.PI/3.6;
j=Math.floor(1000000*j)/1000000.;

https://www.babylonjs-playground.com/#I8SFV3#5

https://www.babylonjs-playground.com/#I8SFV3#6

Thank you. But the problem is not in the Math class. I just use it to demonstrate the bug. In my project scaling is performed by inputs in textboxes.
if initial scale=1 i can’t scale
if initial scale!=1 i can scale to all values except 1.
The source of problem should be PBRCustomMaterial or the ways I handle uniforms.
Can this depend on Matrix manipulations in WorldMatrix?

if you can share in here or private some part that can help otherwise you most try make it in PG

So here I added keyboard handles. If line 47 is commented, we have case 1. If uncommented case 2. Btw using cache_txt alters the colors, but problem is still in place.
https://www.babylonjs-playground.com/#I8SFV3#8

mybe that depend to “NONUNIFORMSCALING”
i dont know what is this ?

1 Like

Looks like it is an answer. If ignorenonuniformscaling=true, then on first observation it works. I will try to use this in project. Will mark it as solution if I succeed. Thanks!

2 Likes