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

Allow to control intensity of SSR #27166

Closed
NoriyukiIchijo opened this issue Nov 10, 2023 · 1 comment
Closed

Allow to control intensity of SSR #27166

NoriyukiIchijo opened this issue Nov 10, 2023 · 1 comment
Milestone

Comments

@NoriyukiIchijo
Copy link

Description

SSR adds reality to rendering and despite I'm new to three.js, I feel its SSR post effect is fine.
But you can only control on or off of the "metalness" of each object by applying substitute material below depending on if it's in "selects" or not.

SSRPass.js:

// metalnessOn material

this.metalnessOnMaterial = new MeshBasicMaterial({
    color: 'white'
});

// metalnessOff material

this.metalnessOffMaterial = new MeshBasicMaterial({
    color: 'black'
});

And it is uses like switch as below.

SSRShader.js:

void main(){
    #ifdef SELECTIVE
        float metalness=texture2D(tMetalness,vUv).r;
        if(metalness==0.) return;
    #endif

So the scene tends to be shown too metallic.

Solution

The workaround I use is to make intermediate materials like

SSRPass.js:

// withMetalness material

this.withMetalnessMaterial = [];
for (let i = 0; i < 256; i++) {
    const rgb = i / 255.0;
    this.withMetalnessMaterial[i] = new MeshBasicMaterial({
        color: new Color(rgb, rgb, rgb),
    });
}

and use it instead of metalnessOnMaterial like

if (this._selects.includes(child)) {

     // child.material = this.metalnessOnMaterial;
    const metalness = child.material.metalness ?? 0;
    child.material = this.withMetalnessMaterial[Math.round(metalness * 255)];
    
} else {

    child.material = this.metalnessOffMaterial;

}

Then use it as below.

SSRShader.js:

gl_FragColor.a=op * metalness;

Alternatives

As I said, I'm new to three.js thus there might be better or even existing solution.

Additional context

No response

@Mugen87 Mugen87 added the Addons label Nov 10, 2023
@Mugen87
Copy link
Collaborator

Mugen87 commented Oct 22, 2024

This is solved with the new SRRNode implementation, see #29597 and #29605.

A solution for the legacy SSRPass is not planned. So you have to switch to WebGPURenderer.

@Mugen87 Mugen87 closed this as completed Oct 22, 2024
@Mugen87 Mugen87 modified the milestones: r169, r170 Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants