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

shaderlab pbr support refraction #2470

Merged
merged 44 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
dd09252
feat: shaderlab pbr support refraction
hhhhkrx Dec 18, 2024
1fc002e
fix: disableMacro
hhhhkrx Dec 19, 2024
adfdfec
fix: name
hhhhkrx Dec 19, 2024
62844aa
Merge branch 'dev/1.4' of github.com:galacean/engine into refraction
hhhhkrx Dec 20, 2024
ffa2912
fix: refraction mode
hhhhkrx Dec 20, 2024
1fc63b2
fix: keep iridescenceRange unified
hhhhkrx Dec 20, 2024
bab9582
fix: refraction
hhhhkrx Dec 20, 2024
174e0e7
fix: refraction
hhhhkrx Dec 20, 2024
47fb197
fix: refraction mode
hhhhkrx Dec 20, 2024
f9b748c
fix: refraction
hhhhkrx Dec 24, 2024
4ef6387
Merge branch 'dev/1.4' of github.com:galacean/engine into refraction
hhhhkrx Dec 24, 2024
76b40b1
fix: refraction
hhhhkrx Dec 24, 2024
3abe5c1
fix: refraction
hhhhkrx Dec 24, 2024
b81bbeb
fix: refraction
hhhhkrx Dec 24, 2024
bcc9daf
fix: refraction
hhhhkrx Dec 24, 2024
b9b9558
fix: refraction
hhhhkrx Dec 24, 2024
9d8a37e
Merge branch 'dev/1.4' of github.com:galacean/engine into refraction
hhhhkrx Dec 24, 2024
84e2f0d
fix: refraction mode
hhhhkrx Dec 24, 2024
e977cbc
fix: refraction mode
hhhhkrx Dec 24, 2024
4040c26
fix: refraction shader
hhhhkrx Dec 24, 2024
420566d
fix: refraction
hhhhkrx Dec 24, 2024
4a3ce3e
fix: refraction mode
hhhhkrx Dec 24, 2024
6b19600
fix: refraction
hhhhkrx Dec 24, 2024
129ac02
fix: refraction value
hhhhkrx Dec 24, 2024
1ff952d
fix: refraction
hhhhkrx Dec 24, 2024
1f011eb
Merge branch 'dev/1.4' into refraction
hhhhkrx Dec 27, 2024
76d9063
fix: dev/1.4
hhhhkrx Dec 27, 2024
d2c26cf
refactor: opt code
hhhhkrx Dec 27, 2024
9d9e4ae
fix: refraction mode
hhhhkrx Dec 27, 2024
02ae05e
fix: refractionModel name
hhhhkrx Dec 27, 2024
a493e26
fix: refraction mode
hhhhkrx Dec 27, 2024
59e0da3
fix: sort
hhhhkrx Dec 27, 2024
e062e18
fix: include
hhhhkrx Dec 27, 2024
aa434e4
fix: refraction mode enable
hhhhkrx Dec 27, 2024
82d9754
fix: refracion mode number
hhhhkrx Dec 27, 2024
4c5eb18
fix: refraction model
hhhhkrx Dec 27, 2024
b6c874a
fix: refraction name
hhhhkrx Dec 27, 2024
0bf8d73
fix: refraction mode
hhhhkrx Dec 27, 2024
1f20667
fix: annotation
hhhhkrx Dec 27, 2024
d4b5d11
fix: attenuation
hhhhkrx Dec 27, 2024
df27aef
fix: attenuation
hhhhkrx Dec 27, 2024
1ba3440
fix: refraction
hhhhkrx Dec 27, 2024
09397f0
fix: annotation
hhhhkrx Dec 27, 2024
e7718de
fix: refraction mode
hhhhkrx Dec 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 136 additions & 1 deletion packages/core/src/material/PBRMaterial.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MathUtil, Vector2, Vector3, Vector4, Color } from "@galacean/engine-math";
import { Engine } from "../Engine";
import { ShaderProperty } from "../shader";
import { ShaderMacro, ShaderProperty } from "../shader";
import { Shader } from "../shader/Shader";
import { Texture2D } from "../texture/Texture2D";
import { PBRBaseMaterial } from "./PBRBaseMaterial";
Expand Down Expand Up @@ -31,6 +31,14 @@
private static _sheenTextureProp = ShaderProperty.getByName("material_SheenTexture");
private static _sheenRoughnessTextureProp = ShaderProperty.getByName("material_SheenRoughnessTexture");

private _refractionEnabled = false;
private static _refactionMacro: ShaderMacro = ShaderMacro.getByName("MATERIAL_ENABLE_SS_REFRACTION");
private static _transmissionProp = ShaderProperty.getByName("material_transmission");
private static _transmissionTextureProp = ShaderProperty.getByName("material_TransmissionTexture");
private static _attenuationColorProp = ShaderProperty.getByName("material_attenuationColor");
private static _attenuationDistanceProp = ShaderProperty.getByName("material_attenuationDistance");
private static _thicknessProp = ShaderProperty.getByName("material_thickness");
private static _thicknessTextureProp = ShaderProperty.getByName("material_ThicknessTexture");
zhuxudong marked this conversation as resolved.
Show resolved Hide resolved
/**
* Index Of Refraction.
* @defaultValue `1.5`
Expand Down Expand Up @@ -289,6 +297,122 @@
}
}

/**
* Refraction switch.
*/
get enableRefraction(): boolean {
return this._refractionEnabled;
}

Check warning on line 305 in packages/core/src/material/PBRMaterial.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/material/PBRMaterial.ts#L304-L305

Added lines #L304 - L305 were not covered by tests

set enableRefraction(value: boolean) {
zhuxudong marked this conversation as resolved.
Show resolved Hide resolved
if (value !== this._refractionEnabled) {
this._refractionEnabled = value;
if (value) {
this.shaderData.enableMacro(PBRMaterial._refactionMacro);
} else {
this.shaderData.enableMacro(PBRMaterial._refactionMacro);
}
}
}

Check warning on line 316 in packages/core/src/material/PBRMaterial.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/material/PBRMaterial.ts#L308-L316

Added lines #L308 - L316 were not covered by tests
hhhhkrx marked this conversation as resolved.
Show resolved Hide resolved

/**
* Transmission factor.
* @defaultValue `0.0`
*/
get transmission(): number {
return this.shaderData.getFloat(PBRMaterial._transmissionProp);
}

Check warning on line 324 in packages/core/src/material/PBRMaterial.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/material/PBRMaterial.ts#L323-L324

Added lines #L323 - L324 were not covered by tests

set transmission(value: number) {
this.shaderData.setFloat(PBRMaterial._transmissionProp, value);
zhuxudong marked this conversation as resolved.
Show resolved Hide resolved
if (value) {
zhuxudong marked this conversation as resolved.
Show resolved Hide resolved
this.shaderData.enableMacro("MATERIAL_HAS_TRANSMISSION");
} else {
this.shaderData.disableMacro("MATERIAL_HAS_TRANSMISSION");
zhuxudong marked this conversation as resolved.
Show resolved Hide resolved
}
}

Check warning on line 333 in packages/core/src/material/PBRMaterial.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/material/PBRMaterial.ts#L327-L333

Added lines #L327 - L333 were not covered by tests
zhuxudong marked this conversation as resolved.
Show resolved Hide resolved

/**
* Transmission texture.
* @remarks Use red channel, and multiply 'transmission'.
*/
get transmissionTexture(): Texture2D {
return <Texture2D>this.shaderData.getTexture(PBRMaterial._transmissionTextureProp);
}

Check warning on line 341 in packages/core/src/material/PBRMaterial.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/material/PBRMaterial.ts#L340-L341

Added lines #L340 - L341 were not covered by tests

set transmissionTexture(value: Texture2D) {
this.shaderData.setTexture(PBRMaterial._transmissionTextureProp, value);
if (value) {
this.shaderData.enableMacro("MATERIAL_HAS_TRANSMISSION_TEXTURE");
} else {
this.shaderData.disableMacro("MATERIAL_HAS_TRANSMISSION_TEXTURE");
zhuxudong marked this conversation as resolved.
Show resolved Hide resolved
}
}

Check warning on line 350 in packages/core/src/material/PBRMaterial.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/material/PBRMaterial.ts#L344-L350

Added lines #L344 - L350 were not covered by tests

/**
* Attenuation color.
* @defaultValue `[1,1,1]`
*/
get attenuationColor(): Color {
return this.shaderData.getColor(PBRMaterial._attenuationColorProp);
}

Check warning on line 358 in packages/core/src/material/PBRMaterial.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/material/PBRMaterial.ts#L357-L358

Added lines #L357 - L358 were not covered by tests

set attenuationColor(value: Color) {
const attenuationColor = this.shaderData.getColor(PBRMaterial._attenuationColorProp);
if (value !== attenuationColor) {
attenuationColor.copyFrom(value);
}
}

Check warning on line 365 in packages/core/src/material/PBRMaterial.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/material/PBRMaterial.ts#L361-L365

Added lines #L361 - L365 were not covered by tests

/**
* Attenuation distance, greater than 0.0.
* @defaultValue `infinity`
*/
get attenuationDistance(): number {
zhuxudong marked this conversation as resolved.
Show resolved Hide resolved
return this.shaderData.getFloat(PBRMaterial._attenuationDistanceProp);
}

Check warning on line 373 in packages/core/src/material/PBRMaterial.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/material/PBRMaterial.ts#L372-L373

Added lines #L372 - L373 were not covered by tests

set attenuationDistance(value: number) {
if (value <= 0) {
zhuxudong marked this conversation as resolved.
Show resolved Hide resolved
throw new Error("attenuationDistance must be greater than 0.0");
}
this.shaderData.setFloat(PBRMaterial._attenuationDistanceProp, value);
}

Check warning on line 380 in packages/core/src/material/PBRMaterial.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/material/PBRMaterial.ts#L376-L380

Added lines #L376 - L380 were not covered by tests

/**
* Thickness, greater than or equal to 0.0.
* @defaultValue `0.0`
*/
get thickness(): number {
return this.shaderData.getFloat(PBRMaterial._thicknessProp);
zhuxudong marked this conversation as resolved.
Show resolved Hide resolved
}

Check warning on line 388 in packages/core/src/material/PBRMaterial.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/material/PBRMaterial.ts#L387-L388

Added lines #L387 - L388 were not covered by tests

set thickness(value: number) {
value = Math.max(0, value);
this.shaderData.setFloat(PBRMaterial._thicknessProp, value);
zhuxudong marked this conversation as resolved.
Show resolved Hide resolved
if (value) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, debounce the macro

this.shaderData.enableMacro("MATERIAL_HAS_THICKNESS");
} else {
this.shaderData.disableMacro("MATERIAL_HAS_THICKNESS");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cache macro name

}
}

Check warning on line 398 in packages/core/src/material/PBRMaterial.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/material/PBRMaterial.ts#L391-L398

Added lines #L391 - L398 were not covered by tests

/**
* Thickness texture.
* @remarks Use green channel, and multiply 'thickness', range is 0.0 to 1.0.
*/
get thicknessTexture(): Texture2D {
return <Texture2D>this.shaderData.getTexture(PBRMaterial._thicknessTextureProp);
}

Check warning on line 406 in packages/core/src/material/PBRMaterial.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/material/PBRMaterial.ts#L405-L406

Added lines #L405 - L406 were not covered by tests

set thicknessTexture(value: Texture2D) {
this.shaderData.setTexture(PBRMaterial._thicknessTextureProp, value);
if (value) {
this.shaderData.enableMacro("MATERIAL_HAS_THICKNESS_TEXTURE");
} else {
this.shaderData.disableMacro("MATERIAL_HAS_THICKNESS_TEXTURE");
zhuxudong marked this conversation as resolved.
Show resolved Hide resolved
}
}

Check warning on line 415 in packages/core/src/material/PBRMaterial.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/material/PBRMaterial.ts#L409-L415

Added lines #L409 - L415 were not covered by tests
/**
* Create a pbr metallic-roughness workflow material instance.
* @param engine - Engine to which the material belongs
Expand All @@ -304,6 +428,8 @@
shaderData.setVector4(PBRMaterial._iridescenceInfoProp, new Vector4(0, 1.3, 100, 400));
const sheenColor = new Color(0, 0, 0);
shaderData.setColor(PBRMaterial._sheenColorProp, sheenColor);
const attenuationColor = new Color(1, 1, 1);
shaderData.setColor(PBRMaterial._attenuationColorProp, attenuationColor);
// @ts-ignore
this._iridescenceRange._onValueChanged = this._onIridescenceRangeChanged.bind(this);
zhuxudong marked this conversation as resolved.
Show resolved Hide resolved
// @ts-ignore
Expand All @@ -318,6 +444,15 @@
}
}
};
// @ts-ignore
attenuationColor._onValueChanged = () => {
const enableAbsorption = attenuationColor.r + attenuationColor.g + attenuationColor.b > 1;
zhuxudong marked this conversation as resolved.
Show resolved Hide resolved
if (enableAbsorption) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cache absorption state to switch macro

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@todo: do you need MATERIAL_HAS_ABSORPTION

this.shaderData.enableMacro("MATERIAL_HAS_ABSORPTION");
zhuxudong marked this conversation as resolved.
Show resolved Hide resolved
} else {
this.shaderData.disableMacro("MATERIAL_HAS_ABSORPTION");
}

Check warning on line 454 in packages/core/src/material/PBRMaterial.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/material/PBRMaterial.ts#L453-L454

Added lines #L453 - L454 were not covered by tests
};
zhuxudong marked this conversation as resolved.
Show resolved Hide resolved
}

private _onIridescenceRangeChanged(): void {
Expand Down
11 changes: 11 additions & 0 deletions packages/loader/src/gltf/extensions/GLTFExtensionSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,16 @@ export interface IKHRMaterialsIridescence {
iridescenceThicknessTexture?: ITextureInfo;
}

/**
* Interfaces from the KHR_materials_volume extension
*/
export interface IKHRMaterialsVolume {
thicknessFactor?: number;
thicknessTexture?: ITextureInfo;
attenuationDistance?: number;
attenuationColor?: number[];
}

export type GLTFExtensionSchema =
| IKHRLightsPunctual_Light
| IKHRMaterialsClearcoat
Expand All @@ -207,4 +217,5 @@ export type GLTFExtensionSchema =
| IKHRXmp_Node
| IGalaceanAnimation
| IKHRMaterialsIridescence
| IKHRMaterialsVolume
| Object;
23 changes: 23 additions & 0 deletions packages/loader/src/gltf/extensions/KHR_materials_transmission.ts
Original file line number Diff line number Diff line change
@@ -1,0 +1,23 @@
import { PBRMaterial, Texture2D } from "@galacean/engine-core";
import { GLTFMaterialParser } from "../parser/GLTFMaterialParser";
import { registerGLTFExtension } from "../parser/GLTFParser";
import { GLTFParserContext, GLTFParserType } from "../parser/GLTFParserContext";
import { GLTFExtensionMode, GLTFExtensionParser } from "./GLTFExtensionParser";
import { IKHRMaterialsTransmission } from "./GLTFExtensionSchema";

@registerGLTFExtension("KHR_materials_transmission", GLTFExtensionMode.AdditiveParse)
class KHR_materials_transmission extends GLTFExtensionParser {
override additiveParse(context: GLTFParserContext, material: PBRMaterial, schema: IKHRMaterialsTransmission): void {
const { transmissionFactor = 0, transmissionTexture } = schema;

material.transmission = transmissionFactor;

if (transmissionTexture) {
GLTFMaterialParser._checkOtherTextureTransform(transmissionTexture, "Transmission texture");

context.get<Texture2D>(GLTFParserType.Texture, transmissionTexture.index).then((texture) => {
material.transmissionTexture = texture;
});
}
}

Check warning on line 22 in packages/loader/src/gltf/extensions/KHR_materials_transmission.ts

View check run for this annotation

Codecov / codecov/patch

packages/loader/src/gltf/extensions/KHR_materials_transmission.ts#L11-L22

Added lines #L11 - L22 were not covered by tests
}
34 changes: 34 additions & 0 deletions packages/loader/src/gltf/extensions/KHR_materials_volume.ts
Original file line number Diff line number Diff line change
@@ -1,0 +1,34 @@
import { PBRMaterial, Texture2D } from "@galacean/engine-core";
import { Color } from "@galacean/engine-math";
import { GLTFMaterialParser } from "../parser/GLTFMaterialParser";
import { registerGLTFExtension } from "../parser/GLTFParser";
import { GLTFParserContext, GLTFParserType } from "../parser/GLTFParserContext";
import { GLTFExtensionMode, GLTFExtensionParser } from "./GLTFExtensionParser";
import { IKHRMaterialsVolume } from "./GLTFExtensionSchema";

@registerGLTFExtension("KHR_materials_volume", GLTFExtensionMode.AdditiveParse)
class KHR_materials_volume extends GLTFExtensionParser {
override additiveParse(context: GLTFParserContext, material: PBRMaterial, schema: IKHRMaterialsVolume): void {
const { thicknessFactor = 0, thicknessTexture, attenuationDistance = Infinity, attenuationColor } = schema;

material.thickness = thicknessFactor;
material.attenuationDistance = attenuationDistance;

if (attenuationColor) {
material.attenuationColor.set(
Color.linearToGammaSpace(attenuationColor[0]),
Color.linearToGammaSpace(attenuationColor[1]),
Color.linearToGammaSpace(attenuationColor[2]),
undefined
);
}
hhhhkrx marked this conversation as resolved.
Show resolved Hide resolved

if (thicknessTexture) {
GLTFMaterialParser._checkOtherTextureTransform(thicknessTexture, "Thickness texture");

context.get<Texture2D>(GLTFParserType.Texture, thicknessTexture.index).then((texture) => {
material.thicknessTexture = texture;
});
}
hhhhkrx marked this conversation as resolved.
Show resolved Hide resolved
}

Check warning on line 33 in packages/loader/src/gltf/extensions/KHR_materials_volume.ts

View check run for this annotation

Codecov / codecov/patch

packages/loader/src/gltf/extensions/KHR_materials_volume.ts#L12-L33

Added lines #L12 - L33 were not covered by tests
}
7 changes: 7 additions & 0 deletions packages/shader-shaderlab/src/shaders/shadingPBR/BRDF.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct SurfaceData{
float specularAO;
float f0;
float opacity;
float IOR;

// geometry
vec3 position;
Expand Down Expand Up @@ -64,6 +65,12 @@ struct SurfaceData{
vec3 sheenColor;
#endif

#ifdef MATERIAL_ENABLE_SS_REFRACTION
vec3 attenuationColor;
float attenuationDistance;
float transmission;
float thickness;
#endif
};


Expand Down
54 changes: 54 additions & 0 deletions packages/shader-shaderlab/src/shaders/shadingPBR/BTDF.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#ifndef BTDF_INCLUDED
#define BTDF_INCLUDED

#include "Refraction.glsl"

sampler2D camera_OpaqueTexture;
zhuxudong marked this conversation as resolved.
Show resolved Hide resolved

#ifdef MATERIAL_ENABLE_SS_REFRACTION
vec3 evaluateRefraction(SurfaceData surfaceData, BRDFData brdfData, vec3 specularColor) {
RefractionModel ray;
#if defined(REFRACTION_SPHERE)
zhuxudong marked this conversation as resolved.
Show resolved Hide resolved
RefractionModelSphere(-surfaceData.viewDir, surfaceData.position, surfaceData.normal, surfaceData.IOR, surfaceData.thickness, ray);
#elif defined(REFRACTION_PLANE)
RefractionModelBox(-surfaceData.viewDir, surfaceData.position, surfaceData.normal, surfaceData.IOR, surfaceData.thickness, ray);
#elif defined(REFRACTION_THIN)
Copy link
Member

@zhuxudong zhuxudong Dec 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you can't find a basis for 5 mm, i suggest just keep the two modes, and delete thin mode

RefractionModelBox(-surfaceData.viewDir, surfaceData.position, surfaceData.normal, surfaceData.IOR, 0.005, ray);
zhuxudong marked this conversation as resolved.
Show resolved Hide resolved
#endif
//TODO: support cubemap refraction.
vec3 refractedRayExit = ray.position;

// We calculate the screen space position of the refracted point
vec4 samplingPositionNDC = camera_ProjMat * camera_ViewMat * vec4( refractedRayExit, 1.0 );
vec2 refractionCoords = (samplingPositionNDC.xy / samplingPositionNDC.w) * 0.5 + 0.5;
Copy link
Member

@zhuxudong zhuxudong Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@todo: No need to process if the coord exceeds the screen?


// Absorption coefficient from Disney: http://blog.selfshadow.com/publications/s2015-shading-course/burley/s2015_pbs_disney_bsdf_notes.pdf
#ifdef MATERIAL_HAS_ABSORPTION
GuoLei1990 marked this conversation as resolved.
Show resolved Hide resolved
vec3 absorptionCoefficient = -log(clamp(surfaceData.attenuationColor, 1e-5f, 1.0f)) / max(1e-5f, surfaceData.attenuationDistance);
zhuxudong marked this conversation as resolved.
Show resolved Hide resolved
zhuxudong marked this conversation as resolved.
Show resolved Hide resolved
#ifdef MATERIAL_HAS_THICKNESS
vec3 transmittance = min(vec3(1.0), exp(-absorptionCoefficient * ray.dist));
#else
vec3 transmittance = 1.0 - absorptionCoefficient;
#endif
#endif

// Sample the opaque texture to get the transmitted light
vec4 getTransmission = texture2D(camera_OpaqueTexture, refractionCoords);

vec3 refractionTransmitted = getTransmission.rgb;
refractionTransmitted *= brdfData.diffuseColor;

// Use specularFGD as an approximation of the fresnel effect
// https://blog.selfshadow.com/publications/s2017-shading-course/imageworks/s2017_pbs_imageworks_slides_v2.pdf
vec3 specularFGD = envBRDFApprox(specularColor, surfaceData.roughness, surfaceData.dotNV);
refractionTransmitted *= (1.0 - specularFGD);
zhuxudong marked this conversation as resolved.
Show resolved Hide resolved

GuoLei1990 marked this conversation as resolved.
Show resolved Hide resolved
#ifdef MATERIAL_HAS_ABSORPTION
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@todo: camera distance

refractionTransmitted *= transmittance;
#endif

return refractionTransmitted;
}
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@todo: diffuse Intensity ?


#endif
40 changes: 40 additions & 0 deletions packages/shader-shaderlab/src/shaders/shadingPBR/FragmentPBR.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,25 @@ float material_OcclusionTextureCoord;
#endif
#endif

#ifdef MATERIAL_ENABLE_SS_REFRACTION
vec3 material_attenuationColor;
float material_attenuationDistance;

#ifdef MATERIAL_HAS_TRANSMISSION
float material_transmission;
#ifdef MATERIAL_HAS_TRANSMISSION_TEXTURE
sampler2D material_TransmissionTexture;
#endif
#endif

#ifdef MATERIAL_HAS_THICKNESS
float material_thickness;
#ifdef MATERIAL_HAS_THICKNESS_TEXTURE
sampler2D material_ThicknessTexture;
#endif
#endif
#endif

// Texture
#ifdef MATERIAL_HAS_BASETEXTURE
sampler2D material_BaseTexture;
Expand Down Expand Up @@ -292,6 +311,27 @@ SurfaceData getSurfaceData(Varyings v, vec2 aoUV, bool isFrontFacing){
#endif
#endif

#ifdef MATERIAL_ENABLE_SS_REFRACTION
surfaceData.attenuationColor = material_attenuationColor;
surfaceData.IOR = material_IOR;
zhuxudong marked this conversation as resolved.
Show resolved Hide resolved
surfaceData.attenuationDistance = max(material_attenuationDistance, 0.001);

#ifdef MATERIAL_HAS_TRANSMISSION
surfaceData.transmission = material_transmission;
#ifdef MATERIAL_HAS_TRANSMISSION_TEXTURE
surfaceData.transmission *= texture2D(material_TransmissionTexture, uv).r;
#endif
#else
surfaceData.transmission = 1.0;
#endif

#ifdef MATERIAL_HAS_THICKNESS
surfaceData.thickness = max(material_thickness, 0.0);
#ifdef MATERIAL_HAS_THICKNESS_TEXTURE
surfaceData.thickness *= texture2D( material_ThicknessTexture, uv).g;
zhuxudong marked this conversation as resolved.
Show resolved Hide resolved
#endif
#endif
#endif
// AO
float diffuseAO = 1.0;
float specularAO = 1.0;
Expand Down
Loading
Loading