YO @sebavan, @Deltakosh or anyone for that matter… Maybe you can help me figure out how to use normalW
in a Material Plugin albedo update fragment.
I used to use normalW
in my PBRCustomMaterial fragments all the time. But after switching to material plugins I get undeclared identifier
for:
normalW
uvOffset
TBN
I used to just be able to use them as they were defined other fragments like:
#include<pbrBlockNormalGeometric>
Does the Material Plugin work ultimately use pbr.fragment.fx
which includes the pbrBlockNormalGeometric
block ?
Here is playground:
Yo @Deltakosh
Hmmm… It seems any code in the CUSTOM_FRAGMENT_UPDATE_ALBEDO section cannot read SOME params… If i move to the offending line of code to the CUSTOM_FRAGMENT_MAIN_END … it can see normalW…
Why would that be ?
Looking at the PBR shader code, normalW
is a local variable in the scope of the main
function, while CUSTOM_FRAGMENT_UPDATE_ALBEDO
adds your code in another function albedoOpacityBlock
.
So you can either :
- Use another hook point like you did with
CUSTOM_FRAGMENT_MAIN_END
, where the variable you are looking for is in the scope
- Use other variables available in the scope of
CUSTOM_FRAGMENT_UPDATE_ALBEDO
. For example with normalW
, you can simply use the shader input vNormalW
: vec3 normalW = normalize(vNormalW);
Here is your updated playground code :
2 Likes
vNormalW
is the normal passed from the vertex to the shader fragment, but depending on your material settings, this value may be updated.
If you want to get the final normal (normalW
), you can make it available to the albedoOpacityBlock
by declaring a global variable, setting its value to normalW
and using this variable in albedoOpacityBlock
:
This PG uses a regexp to inject some code just before the call to albedoOpacityBlock
.
1 Like
I see… Also found a workaround by by modifying the surfaceAlbedo from
CUSTOM_FRAGMENT_BEFORE_LIGHTS
where
normalW
uvOffset
TBN
work just fine
2 Likes
Sorry for the delay and thanks to al the ppl who helped 