-
-
Notifications
You must be signed in to change notification settings - Fork 310
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
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
dd09252
feat: shaderlab pbr support refraction
hhhhkrx 1fc002e
fix: disableMacro
hhhhkrx adfdfec
fix: name
hhhhkrx 62844aa
Merge branch 'dev/1.4' of github.com:galacean/engine into refraction
hhhhkrx ffa2912
fix: refraction mode
hhhhkrx 1fc63b2
fix: keep iridescenceRange unified
hhhhkrx bab9582
fix: refraction
hhhhkrx 174e0e7
fix: refraction
hhhhkrx 47fb197
fix: refraction mode
hhhhkrx f9b748c
fix: refraction
hhhhkrx 4ef6387
Merge branch 'dev/1.4' of github.com:galacean/engine into refraction
hhhhkrx 76b40b1
fix: refraction
hhhhkrx 3abe5c1
fix: refraction
hhhhkrx b81bbeb
fix: refraction
hhhhkrx bcc9daf
fix: refraction
hhhhkrx b9b9558
fix: refraction
hhhhkrx 9d8a37e
Merge branch 'dev/1.4' of github.com:galacean/engine into refraction
hhhhkrx 84e2f0d
fix: refraction mode
hhhhkrx e977cbc
fix: refraction mode
hhhhkrx 4040c26
fix: refraction shader
hhhhkrx 420566d
fix: refraction
hhhhkrx 4a3ce3e
fix: refraction mode
hhhhkrx 6b19600
fix: refraction
hhhhkrx 129ac02
fix: refraction value
hhhhkrx 1ff952d
fix: refraction
hhhhkrx 1f011eb
Merge branch 'dev/1.4' into refraction
hhhhkrx 76d9063
fix: dev/1.4
hhhhkrx d2c26cf
refactor: opt code
hhhhkrx 9d9e4ae
fix: refraction mode
hhhhkrx 02ae05e
fix: refractionModel name
hhhhkrx a493e26
fix: refraction mode
hhhhkrx 59e0da3
fix: sort
hhhhkrx e062e18
fix: include
hhhhkrx aa434e4
fix: refraction mode enable
hhhhkrx 82d9754
fix: refracion mode number
hhhhkrx 4c5eb18
fix: refraction model
hhhhkrx b6c874a
fix: refraction name
hhhhkrx 0bf8d73
fix: refraction mode
hhhhkrx 1f20667
fix: annotation
hhhhkrx d4b5d11
fix: attenuation
hhhhkrx df27aef
fix: attenuation
hhhhkrx 1ba3440
fix: refraction
hhhhkrx 09397f0
fix: annotation
hhhhkrx e7718de
fix: refraction mode
hhhhkrx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,28 +5,35 @@ | |
|
||
#ifdef MATERIAL_ENABLE_TRANSMISSION | ||
sampler2D camera_OpaqueTexture; | ||
vec3 evaluateRefraction(SurfaceData surfaceData, BRDFData brdfData) { | ||
vec3 evaluateTransmission(SurfaceData surfaceData, BRDFData brdfData) { | ||
RefractionModelResult ray; | ||
#ifdef REFRACTION_MODE | ||
refractionModelBox(-surfaceData.viewDir, surfaceData.position, surfaceData.normal, surfaceData.IOR, 0.005, ray); | ||
#if REFRACTION_MODE == 0 | ||
// RefractionMode.Sphere | ||
refractionModelSphere(-surfaceData.viewDir, surfaceData.position, surfaceData.normal, surfaceData.IOR, surfaceData.thickness, ray); | ||
#elif REFRACTION_MODE == 1 | ||
// RefractionMode.Planar | ||
refractionModelPlanar(-surfaceData.viewDir, surfaceData.position, surfaceData.normal, surfaceData.IOR, surfaceData.thickness, ray); | ||
#endif | ||
//TODO: support cubemap refraction. | ||
|
||
vec3 refractedRayExit = ray.positionExit; | ||
|
||
// 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @todo: No need to process if the coord exceeds the screen? |
||
|
||
// Sample the opaque texture to get the transmitted light | ||
vec4 getTransmission = texture2D(camera_OpaqueTexture, refractionCoords); | ||
vec3 refractionTransmitted = getTransmission.rgb; | ||
vec3 refractionTransmitted = texture2D(camera_OpaqueTexture, refractionCoords).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 specularDFG = brdfData.envSpecularDFG; | ||
refractionTransmitted *= (1.0 - brdfData.envSpecularDFG); | ||
|
||
GuoLei1990 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
refractionTransmitted *= (1.0 - specularDFG); | ||
#ifdef MATERIAL_HAS_THICKNESS | ||
// Absorption coefficient from Disney: http://blog.selfshadow.com/publications/s2015-shading-course/burley/s2015_pbs_disney_bsdf_notes.pdf | ||
vec3 transmittance = min(vec3(1.0), exp(-surfaceData.absorptionCoefficient * ray.transmissionLength)); | ||
refractionTransmitted *= transmittance; | ||
#endif | ||
|
||
return refractionTransmitted; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,28 @@ struct RefractionModelResult{ | |
// vec3 directionExit; // out ray direction | ||
}; | ||
|
||
void refractionModelBox(vec3 V, vec3 positionWS, vec3 normalWS, float ior, float thickness, out RefractionModelResult ray){ | ||
//https://docs.unity3d.com/Packages/[email protected]/manual/refraction-models.html | ||
void refractionModelSphere(vec3 V, vec3 positionWS, vec3 normalWS, float ior, float thickness, out RefractionModelResult ray){ | ||
// Refracted ray | ||
vec3 R1 = refract(V, normalWS, 1.0 / ior); | ||
// Center of the tangent sphere | ||
// vec3 C = positionWS - normalWS * thickness * 0.5; | ||
|
||
// Second refraction (tangent sphere out) | ||
float dist = dot(-normalWS, R1) * thickness; | ||
// Out hit point in the tangent sphere | ||
vec3 P1 = positionWS + R1 * dist; | ||
// Out normal | ||
// vec3 N1 = safeNormalize(C - P1); | ||
// Out refracted ray | ||
// vec3 R2 = refract(R1, N1, ior); | ||
|
||
ray.transmissionLength = dist; | ||
ray.positionExit = P1; | ||
// ray.directionExit = R2; | ||
} | ||
|
||
void refractionModelPlanar(vec3 V, vec3 positionWS, vec3 normalWS, float ior, float thickness, out RefractionModelResult ray){ | ||
// Refracted ray | ||
vec3 R = refract(V, normalWS, 1.0 / ior); | ||
// Optical depth within the thin plane | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add macro cleanup and value validation.
The current implementation has potential issues:
Apply this diff to fix these issues:
📝 Committable suggestion