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

WebGPU: Custom Lighting Model #21706

Merged
merged 9 commits into from
Apr 29, 2021
Merged

WebGPU: Custom Lighting Model #21706

merged 9 commits into from
Apr 29, 2021

Conversation

sunag
Copy link
Collaborator

@sunag sunag commented Apr 23, 2021

Description

An example of how to create custom lighting model with NodeMaterial and PointsMaterial.

Related

#17618

image

@sunag sunag changed the title WebGPU: Custom Model Light WebGPU: Custom Light Behavior Apr 23, 2021
@sunag
Copy link
Collaborator Author

sunag commented Apr 23, 2021

A points distanced based light model example: (this example)

lightColor already returns the color with the intensity calculated.

void ( vec3 lightColor ) {

	ReflectedLightDirectDiffuse += lightColor;

}

A mesh bling phong light model example:

void RE_Direct_BlinnPhong( vec3 lightDirection, vec3 lightColor ) {

	float dotNL = saturate( dot( NormalView, lightDirection ) );
	vec3 irradiance = dotNL * lightColor;

#ifndef PHYSICALLY_CORRECT_LIGHTS

		irradiance *= PI; // punctual light

#endif

	ReflectedLightDirectDiffuse += irradiance * BRDF_Diffuse_Lambert( MaterialDiffuseColor.rgb );

	ReflectedLightDirectSpecular += irradiance * BRDF_Specular_BlinnPhong( lightDirection, MaterialSpecularColor, MaterialSpecularShininess );

}

@sunag sunag changed the title WebGPU: Custom Light Behavior WebGPU: Custom Lighting Model Apr 23, 2021
@sunag
Copy link
Collaborator Author

sunag commented Apr 23, 2021

/ping @mrdoob @Mugen87

@Mugen87
Copy link
Collaborator

Mugen87 commented Apr 23, 2021

Looks interesting!

I like the idea introduced in #21322 to represent components of a lighting model as instances of FunctionNode that can be changed/modified by the user. In this way, users are implementing nodes instead of implementing the raw vertex/fragment shader or overriding shader chunks via onBeforeCompile().

This goes definitely into the right direction 👍 .

@Mugen87 Mugen87 added this to the r129 milestone Apr 29, 2021
@Mugen87 Mugen87 merged commit 8eba7f6 into mrdoob:dev Apr 29, 2021
@mrdoob
Copy link
Owner

mrdoob commented May 3, 2021

Thanks!

@Mugen87
Copy link
Collaborator

Mugen87 commented Sep 6, 2022

BTW: It seems the spheres representing the point lights in webgpu_lights_custom and webgpu_lights_selective are black now. Is it because both examples still use MeshBasicMaterial instead of MeshBasicNodeMaterial?

@sunag
Copy link
Collaborator Author

sunag commented Sep 6, 2022

BTW: It seems the spheres representing the point lights in webgpu_lights_custom and webgpu_lights_selective are black now. Is it because both examples still use MeshBasicMaterial instead of MeshBasicNodeMaterial?

Ohh… I will fix it.

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

Successfully merging this pull request may close these issues.

3 participants