Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Material must set Material.customProgramCacheKey #13

Closed
gromgull opened this issue Feb 7, 2022 · 4 comments
Closed

Material must set Material.customProgramCacheKey #13

gromgull opened this issue Feb 7, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@gromgull
Copy link

gromgull commented Feb 7, 2022

Currently, if you use multiple of these materials, only one (the first) shader gets used.

If you use onBeforeCompile you must set the cache key:
https://threejs.org/docs/?q=meshstand#api/en/materials/Material.customProgramCacheKey

See mrdoob/three.js#17567 and mrdoob/three.js#19377

@FarazzShaikh
Copy link
Owner

Ah yes we ran into this issue in another lib. The Cache key is the shader program itself, since each new instance of CSM is initialized with the same base material shader they get the same cache key.

Thanks, will fix

@FarazzShaikh FarazzShaikh added the bug Something isn't working label Feb 7, 2022
@FarazzShaikh
Copy link
Owner

Currently, if you use multiple of these materials, only one (the first) shader gets used.

Do you have any code I can take a look at for this? If I duplicate the water material and give them different colors, it works as expected:

image

    <Water base={Base} />
    <group position={[-5, 0, 0]}>
        <Water color="#ff0000" base={Base} />
    </group>
    <group position={[0, 0, -5]}>
        <Water color="#ff00ff" base={Base} />
    </group>

I think you might be running this this

That like overrides the unifroms on the Water material, so it appears as though even duplicates are the same material.

Closing for now, will re open if I run into this.

@FarazzShaikh
Copy link
Owner

Never mind, I found that this is the case where you use 2 completely separate instances of <CustomLayerMaterial />

@FarazzShaikh
Copy link
Owner

FarazzShaikh commented Feb 11, 2022

Ok applied patch

this.customProgramCacheKey = () => {
return this.uuid
}

Little hacky but will do for now. Need to find a better, cache-friendly solution. Thanks so much for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants