浏览代码

Offset added

Temechon 9 年之前
父节点
当前提交
5ce062703d

文件差异内容过多而无法显示
+ 5 - 2
materialsLibrary/dist/babylon.gradientMaterial.js


文件差异内容过多而无法显示
+ 1 - 1
materialsLibrary/dist/babylon.gradientMaterial.min.js


+ 1 - 0
materialsLibrary/dist/dts/babylon.gradientMaterial.d.ts

@@ -3,6 +3,7 @@ declare module BABYLON {
     class GradientMaterial extends Material {
         topColor: Color3;
         bottomColor: Color3;
+        offset: number;
         disableLighting: boolean;
         private _worldViewProjectionMatrix;
         private _scaledDiffuse;

+ 5 - 1
materialsLibrary/materials/gradient/babylon.gradientMaterial.ts

@@ -66,6 +66,9 @@ module BABYLON {
         // The gradient top color, blue by default
         public bottomColor = new Color3(0, 0, 1);
 
+        // Gradient offset
+        public offset = 0;
+
         public disableLighting = false;
 
         private _worldViewProjectionMatrix = Matrix.Zero();
@@ -347,7 +350,7 @@ module BABYLON {
                         "vDiffuseInfos", 
                         "mBones",
                         "vClipPlane", "diffuseMatrix",
-                        "shadowsInfo0", "shadowsInfo1", "shadowsInfo2", "shadowsInfo3", "depthValues", "topColor", "bottomColor"
+                        "shadowsInfo0", "shadowsInfo1", "shadowsInfo2", "shadowsInfo3", "depthValues", "topColor", "bottomColor", "offset"
                     ],
                     ["diffuseSampler",
                         "shadowSampler0", "shadowSampler1", "shadowSampler2", "shadowSampler3"
@@ -473,6 +476,7 @@ module BABYLON {
 
             this._effect.setColor3("topColor", this.topColor);
             this._effect.setColor3("bottomColor", this.bottomColor);
+            this._effect.setFloat("offset", this.offset);
 
             super.bind(world, mesh);
         }

+ 2 - 1
materialsLibrary/materials/gradient/gradient.fragment.fx

@@ -6,6 +6,7 @@ uniform vec3 vEyePosition;
 // Gradient variables
 uniform vec3 topColor;
 uniform vec3 bottomColor;
+uniform float offset;
 varying vec2 vUV;
 
 // Input
@@ -379,7 +380,7 @@ void main(void) {
 	vec3 viewDirectionW = normalize(vEyePosition - vPositionW);
 
 	// Base color
-	vec4  baseColor = vec4(mix(topColor, bottomColor, vUV.y), 1.0);
+	vec4  baseColor = vec4(mix(topColor, bottomColor, vUV.y +offset), 1.0);
 	vec3 diffuseColor = vec3(1,1,1);
 
 	// Alpha

+ 7 - 0
materialsLibrary/test/add/addgradient.js

@@ -15,5 +15,12 @@ window.prepareGradient = function() {
         return grad.bottomColor.toHexString();
     });
 
+    // offset
+    registerRangeUI("gradient", "offset", -1, 1, function(value) {
+        grad.offset = value;
+    }, function() {
+        return grad.offset;
+    });
+
     return grad;
 };