RFR: 8217472: Add attenuation for PointLight [v5]
Ambarish Rapte
arapte at openjdk.java.net
Wed Jul 29 08:05:49 UTC 2020
On Tue, 28 Jul 2020 12:44:18 GMT, Nir Lisker <nlisker at openjdk.org> wrote:
>> modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main3Lights.frag line 92:
>>
>>> 91: d += clamp(dot(n,l), 0.0, 1.0) * (lights[0].color).rgb * att;
>>> 92: s += pow(clamp(dot(-refl, l), 0.0, 1.0), power) * lights[0].color.rgb * att;
>>> 93: }
>>
>> These three lines can be changed as:
>> float attenuatedColor = (lights[0].color).rgb / (lights[0].attn.x + lights[0].attn.y * dist + lights[0].attn.z * dist *
>> dist); d += clamp(dot(n,l), 0.0, 1.0) * attenuatedColor;
>> s += pow(clamp(dot(-refl, l), 0.0, 1.0), power) * attenuatedColor;
>> Similar change in the 1 light and 2 lights shader.
>
> Interesting, I'd think the compiler would have optimized it.
The optimizations done by `glCompileShader()` is implementation specific and so little gray area (There may be a way to
compare the compiled shaders but I have not investigated on that). But the similar change in hlsl shader is saving one
multiplication instruction. So I am assuming that this change might also save just one multiplication instruction. As
with this change there is no difference in FPS, it seems trivial. But given it is in fragment shader it is worth saving
instructions. I will leave it to you to make a call on this(for both hlsl and glsl). Just that we should keep similar
arithmetics in both glsl and hlsl shaders. So either change both or none.
-------------
PR: https://git.openjdk.java.net/jfx/pull/43
More information about the openjfx-dev
mailing list