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

How to change the opacity of extended material ? #44

Closed
TheoGil opened this issue Oct 3, 2023 · 3 comments
Closed

How to change the opacity of extended material ? #44

TheoGil opened this issue Oct 3, 2023 · 3 comments

Comments

@TheoGil
Copy link

TheoGil commented Oct 3, 2023

Hello

I would like to change only the alpha component of final color but cannot figure out how to do so.

Is this something that is currently easily feasible ?

To illustrate what I'm trying to achieve, here's to different pseudo-code solutions that would both satisfy my use case.

// In this pseudo-code example, the (imaginary) csm_Alpha is used to set the final gl_FragColor alpha component
void main() {
    csm_Alpha = 0.5;
}

// In this other pseudo-code example, I am able to retrieve the "temporary color" and update its alpha component.
// The cms_TemporaryColor is not a "real property", here it would hold the color value as set by the extended material, before any CSM modification.
void main() {
    csm_DiffuseColor = vec4(cms_TemporaryColor.r, cms_TemporaryColor.g, cms_TemporaryColor.b, 0.5);
}

Using the Material's opacity property is not a viable option in my case because I am working with an InstancedBufferGeometry and would like every instance to have a different alpha value.

Thanks!

@TheoGil
Copy link
Author

TheoGil commented Oct 3, 2023

Ok i've figured it out 🤦 ...

void main() {
    csm_DiffuseColor.a = 0.5;
}

Closing the issue, sorry about the rubberducking...

@TheoGil TheoGil closed this as completed Oct 3, 2023
@FarazzShaikh
Copy link
Owner

FarazzShaikh commented Oct 3, 2023

Yes, csm_DiffuseColor is preloaded with the materials color prop. However, for InstancedMesh, you need to pass the color as an attribute, then as a varying or use the pre-existing vColor varying like so:

#ifdef USE_INSTANCING_COLOR
    csm_DiffuseColor.rgb = vColor;
#endif
csm_DiffuseColor.a = 0.5;

https://codesandbox.io/s/async-rain-2qw5tx?file=/src/App.tsx:909-954

@TheoGil
Copy link
Author

TheoGil commented Oct 3, 2023

Awesome, thank you @FarazzShaikh for the precision

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants