-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
Refraction #316
Closed
Closed
Refraction #316
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
be59c8f
feat: support iridescence in ShaderLab PBR
hhhhkrx cac0c74
Merge branch 'dev/1.4' of github.com:galacean/engine-toolkit into GLT…
hhhhkrx 3984cee
Merge branch 'dev/1.4' of github.com:galacean/engine-toolkit into GLT…
hhhhkrx 2f0e91a
fix: merge
hhhhkrx e15d3e8
fix: iridescnence shader
hhhhkrx dd0e023
fix: delate sheen
hhhhkrx 329e0f8
fix: Iridescnence name
hhhhkrx 451b976
fix: pow2
hhhhkrx 6d89218
fix: iridescence name
hhhhkrx 6c6e710
fix: iridesceceIOR name
hhhhkrx 128094c
fix: topIOR name
hhhhkrx 8efd617
fix: ior name
hhhhkrx 59b4ca5
fix: name of hump
hhhhkrx 09a5ebb
fix: name
hhhhkrx 3c0a0d6
fix: name
hhhhkrx ba66708
fix: iridescence
hhhhkrx adb8bde
fix: iridescence
hhhhkrx 1021e27
Merge branch 'dev/1.4' of github.com:galacean/engine-toolkit into dev…
hhhhkrx eb32da3
Merge branch 'dev/1.4' of github.com:galacean/engine-toolkit into dev…
hhhhkrx 45fa3cb
Merge branch 'dev/1.4' of github.com:galacean/engine-toolkit into ref…
hhhhkrx c5dbbcc
Merge branch 'dev/1.4' of github.com:galacean/engine-toolkit into ref…
hhhhkrx d1620dc
feat: refraction
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#ifndef BTDF_INCLUDED | ||
#define BTDF_INCLUDED | ||
|
||
#include "Refraction.glsl" | ||
|
||
vec4 renderer_texelSize; // x: 1/width, y: 1/height, z: width, w: height | ||
sampler2D camera_OpaqueTexture; | ||
|
||
#ifdef MATERIAL_ENABLE_SS_REFRACTION | ||
vec3 evaluateRefraction(Varyings varyings, SurfaceData surfaceData, BRDFData brdfData, vec3 speculaColor) { | ||
RefractionModel ray; | ||
#if REFRACTION_SPHERE | ||
RefractionModelSphere(surfaceData.viewDir, varyings.positionWS, varyings.normalWS, surfaceData.IOR, surfaceData.thickness, ray); | ||
#elif REFRACTION_PLANE | ||
RefractionModelBox(surfaceData.viewDir, varyings.positionWS, varyings.normalWS, surfaceData.IOR, surfaceData.thickness, ray); | ||
#elif REFRACTION_THIN | ||
RefractionModelBox(surfaceData.viewDir, varyings.positionWS, varyings.normalWS, surfaceData.IOR, surfaceData.thickness, ray); | ||
#endif | ||
|
||
vec3 refractedRayExit = ray.position; //ray.position + ray.direction; | ||
|
||
// Project refracted vector on the framebuffer, while mapping to normalized device coordinates. | ||
vec4 ndcPos = camera_ProjMat * camera_ViewMat * vec4( refractedRayExit, 1.0 ); | ||
vec2 refractionCoords = ndcPos.xy / ndcPos.w; | ||
refractionCoords *= 0.5; | ||
refractionCoords += 0.5; | ||
|
||
// compute transmission | ||
vec3 absorptionCoefficient = max(vec3(0), -log(surfaceData.attenuationColor)/surfaceData.attenuationDistance); | ||
#ifdef MATERIAL_HAS_ABSORPTION | ||
vec3 transmittance = min(vec3(1.0), exp(-absorptionCoefficient * ray.dist)); | ||
#else | ||
vec3 transmittance = 1.0 - absorptionCoefficient; | ||
#endif | ||
|
||
// vec4 transmittedLight = texture2D(camera_OpaqueTexture, varyings.uv); | ||
vec4 transmittedLight = sampleTexture2DBicubic(camera_OpaqueTexture, refractionCoords, renderer_texelSize); | ||
// vec3 transmittanceColor = brdfData.diffuseColor * transmittance; | ||
vec3 E = envBRDFApprox(speculaColor, brdfData.roughness, surfaceData.dotNV); | ||
|
||
vec3 ft = transmittedLight.rgb; | ||
ft *= brdfData.diffuseColor; | ||
ft *= 1.0 - E; | ||
|
||
#ifdef MATERIAL_HAS_ABSORPTION | ||
ft *= transmittance; | ||
#endif | ||
|
||
return ft; | ||
} | ||
#endif | ||
|
||
#endif |
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#ifndef REFRACTION_INCLUDED | ||
#define REFRACTION_INCLUDED | ||
|
||
#ifdef MATERIAL_ENABLE_SS_REFRACTION | ||
|
||
struct RefractionModel{ | ||
float dist; // length of the transmission during refraction through the shape | ||
vec3 position; // out ray position | ||
vec3 direction; // out ray direction | ||
}; | ||
|
||
void RefractionModelSphere(vec3 V, vec3 positionWS, vec3 normalWS, float ior, float thickness, out RefractionModel ray){ | ||
// Sphere shape model: | ||
// We approximate locally the shape of the object as sphere, that is tangent to the shape. | ||
// The sphere has a diameter of {thickness} | ||
// The center of the sphere is at {positionWS} - {normalWS} * {thickness} * 0.5 | ||
// So the light is refracted twice: in and out of the tangent sphere | ||
|
||
// First refraction (tangent sphere in) | ||
// 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 NoR1 = dot(normalWS, R1); | ||
// Optical depth within the sphere | ||
float dist = -NoR1 * thickness; | ||
// Out hit point in the tangent sphere | ||
vec3 P1 = positionWS + R1 * dist; | ||
// Out normal | ||
vec3 N1 = normalize(C - P1); | ||
// Out refracted ray | ||
vec3 R2 = refract(R1, N1, ior); | ||
|
||
ray.dist = dist; | ||
ray.position = P1; | ||
ray.direction = R2; | ||
} | ||
|
||
void RefractionModelBox(vec3 V, vec3 positionWS, vec3 normalWS, float ior, float thickness, out RefractionModel ray){ | ||
// Plane shape model: | ||
// We approximate locally the shape of the object as a plane with normal {normalWS} at {positionWS} | ||
// with a thickness {thickness} | ||
// Refracted ray | ||
vec3 R = refract(V, normalWS, 1.0 / ior); | ||
|
||
// Optical depth within the thin plane | ||
float dist = thickness / max(dot(R, -normalWS), 0.001); | ||
|
||
ray.dist = dist; | ||
ray.position = positionWS + R * dist; | ||
ray.direction = V; | ||
} | ||
#endif | ||
#endif |
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
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 range constraints to material_Thickness.
The
material_Thickness
property should have range constraints to prevent invalid values that could affect rendering calculations.📝 Committable suggestion