瀏覽代碼

Aniso Direction

sebavan 6 年之前
父節點
當前提交
019c321b76

+ 2 - 1
inspector/src/components/actionTabs/tabs/propertyGrids/materials/pbrMaterialPropertyGridComponent.tsx

@@ -8,6 +8,7 @@ import { PropertyChangedEvent } from "../../../../propertyChangedEvent";
 import { LineContainerComponent } from "../../../lineContainerComponent";
 import { Color3LineComponent } from "../../../lines/color3LineComponent";
 import { CheckBoxLineComponent } from "../../../lines/checkBoxLineComponent";
+import { Vector2LineComponent } from "../../../lines/vector2LineComponent";
 import { SliderLineComponent } from "../../../lines/sliderLineComponent";
 import { OptionsLineComponent } from "../../../lines/optionsLineComponent";
 import { CommonMaterialPropertyGridComponent } from "./commonMaterialPropertyGridComponent";
@@ -170,7 +171,7 @@ export class PBRMaterialPropertyGridComponent extends React.Component<IPBRMateri
                         material.anisotropy.isEnabled &&
                         <div>
                             <SliderLineComponent label="Intensity" target={material.anisotropy} propertyName="intensity" minimum={0} maximum={1} step={0.01} onPropertyChangedObservable={this.props.onPropertyChangedObservable} />
-                            <CheckBoxLineComponent label="Follow tangents" target={material.anisotropy} propertyName="followTangents" onPropertyChangedObservable={this.props.onPropertyChangedObservable} />
+                            <Vector2LineComponent label="Direction" target={material.anisotropy} propertyName="direction" onPropertyChangedObservable={this.props.onPropertyChangedObservable} />
                         </div>
                     }
                 </LineContainerComponent>

+ 8 - 7
src/Materials/PBR/pbrAnisotropicConfiguration.ts

@@ -1,8 +1,9 @@
-import { SerializationHelper, serialize, expandToProperty } from "../../Misc/decorators";
+import { SerializationHelper, serialize, expandToProperty, serializeAsVector2 } from "../../Misc/decorators";
 import { EffectFallbacks } from "../../Materials/effect";
 import { UniformBuffer } from "../../Materials/uniformBuffer";
 import { AbstractMesh } from "../../Meshes/abstractMesh";
 import { VertexBuffer } from "../../Meshes/buffer";
+import { Vector2 } from "../../Maths/math";
 
 /**
  * @hidden
@@ -35,11 +36,11 @@ export class PBRAnisotropicConfiguration {
     public intensity: number = 1;
 
     /**
-     * Defines if the effect is along the tangents or bitangents.
+     * Defines if the effect is along the tangents, bitangents or in between.
      * By default, the effect is "strectching" the highlights along the tangents.
      */
-    @serialize()
-    public followTangents = true;
+    @serializeAsVector2()
+    public direction = new Vector2(1, 0);
 
     /** @hidden */
     private _internalMarkAllSubMeshesAsMiscDirty: () => void;
@@ -78,7 +79,7 @@ export class PBRAnisotropicConfiguration {
     public bindForSubMesh(uniformBuffer: UniformBuffer, isFrozen: boolean): void {
         if (!uniformBuffer.useUbo || !isFrozen || !uniformBuffer.isSync) {
             // Clear Coat
-            uniformBuffer.updateFloat("anisotropy", this.followTangents ? this.intensity : -this.intensity);
+            uniformBuffer.updateFloat3("vAnisotropy", this.direction.x, this.direction.y, this.intensity);
         }
     }
 
@@ -133,7 +134,7 @@ export class PBRAnisotropicConfiguration {
      * @param uniforms defines the current uniform list.
      */
     public static AddUniforms(uniforms: string[]): void {
-        uniforms.push("anisotropy");
+        uniforms.push("vAnisotropy");
     }
 
     /**
@@ -141,6 +142,6 @@ export class PBRAnisotropicConfiguration {
      * @param uniformBuffer defines the current uniform buffer.
      */
     public static PrepareUniformBuffer(uniformBuffer: UniformBuffer): void {
-        uniformBuffer.addUniform("anisotropy", 1);
+        uniformBuffer.addUniform("vAnisotropy", 3);
     }
 }

+ 1 - 0
src/Materials/PBR/pbrBaseMaterial.ts

@@ -197,6 +197,7 @@ class PBRMaterialDefines extends MaterialDefines
     public CLEARCOAT_TINT_TEXTUREDIRECTUV = 0;
 
     public ANISOTROPIC = false;
+    public ANISOTROPIC_DIRECTION = false;
 
     public BRDF_V_HEIGHT_CORRELATED = false;
     public MS_BRDF_ENERGY_CONSERVATION = false;

+ 1 - 1
src/Shaders/ShadersInclude/lightFragment.fx

@@ -63,7 +63,7 @@
             // Specular contribution
             #ifdef SPECULARTERM
                 #ifdef ANISOTROPIC
-                    info.specular = computeAnisotropicSpecularLighting(preInfo, viewDirectionW, normalW, normalize(TBN[0]), normalize(TBN[1]), anisotropy, specularEnvironmentR0, specularEnvironmentR90, AARoughnessFactors.x, light{X}.vLightDiffuse.rgb);
+                    info.specular = computeAnisotropicSpecularLighting(preInfo, viewDirectionW, normalW, anisotropicTangent, anisotropicBitangent, anisotropy, specularEnvironmentR0, specularEnvironmentR90, AARoughnessFactors.x, light{X}.vLightDiffuse.rgb);
                 #else
                     info.specular = computeSpecularLighting(preInfo, normalW, specularEnvironmentR0, specularEnvironmentR90, AARoughnessFactors.x, light{X}.vLightDiffuse.rgb);
                 #endif

+ 1 - 1
src/Shaders/ShadersInclude/pbrFragmentDeclaration.fx

@@ -94,7 +94,7 @@ uniform mat4 view;
 
 // Anisotropy
 #ifdef ANISOTROPIC
-    uniform float anisotropy;
+    uniform vec3 vAnisotropy;
 #endif
 
 // Sheen

+ 2 - 2
src/Shaders/ShadersInclude/pbrFunctions.fx

@@ -226,8 +226,8 @@ vec2 getAnisotropicRoughness(float alphaG, float anisotropy) {
 
 // Aniso Bent Normals
 // Mc Alley https://www.gdcvault.com/play/1022235/Rendering-the-World-of-Far 
-vec3 getAnisotropicBentNormals(const mat3 TBN, const vec3 V, const vec3 N, float anisotropy) {
-    vec3 anisotropicFrameDirection = anisotropy >= 0.0 ? TBN[1] : TBN[0];
+vec3 getAnisotropicBentNormals(const vec3 T, const vec3 B, const vec3 N, const vec3 V, float anisotropy) {
+    vec3 anisotropicFrameDirection = anisotropy >= 0.0 ? B : T;
     vec3 anisotropicFrameTangent = cross(normalize(anisotropicFrameDirection), V);
     vec3 anisotropicFrameNormal = cross(anisotropicFrameTangent, anisotropicFrameDirection);
     vec3 anisotropicNormal = normalize(mix(N, anisotropicFrameNormal, abs(anisotropy)));

+ 1 - 1
src/Shaders/ShadersInclude/pbrUboDeclaration.fx

@@ -50,7 +50,7 @@ uniform Material
     uniform vec2 vClearCoatTintInfos;
     uniform mat4 clearCoatTintMatrix;
 
-    uniform float anisotropy;
+    uniform vec3 vAnisotropy;
 
     uniform vec4 vSheenColor;
     uniform vec2 vSheenInfos;

+ 8 - 1
src/Shaders/pbr.fragment.fx

@@ -503,7 +503,14 @@ void main(void) {
     #endif
 
     #ifdef ANISOTROPIC
-        vec3 anisotropicNormal = getAnisotropicBentNormals(TBN, viewDirectionW, normalW, anisotropy);
+        float anisotropy = vAnisotropy.b;
+
+        vec3 anisotropyDirection = vec3(vAnisotropy.xy, 0.);
+        mat3 anisoTBN = mat3(normalize(TBN[0]), normalize(TBN[1]), normalize(TBN[2]));
+        vec3 anisotropicTangent = normalize(anisoTBN * anisotropyDirection);
+        vec3 anisotropicBitangent = normalize(cross(anisoTBN[2], anisotropicTangent));
+        
+        vec3 anisotropicNormal = getAnisotropicBentNormals(anisotropicTangent, anisotropicBitangent, normalW, viewDirectionW, anisotropy);
     #endif
 
     // _____________________________ Refraction Info _______________________________________