瀏覽代碼

GLSL: Add glsl tag for highlight plugin.

linbingquan 5 年之前
父節點
當前提交
0a0a104726
共有 2 個文件被更改,包括 70 次插入70 次删除
  1. 68 68
      examples/jsm/utils/RoughnessMipmapper.js
  2. 2 2
      examples/webgl_materials_envmaps_parallax.html

+ 68 - 68
examples/jsm/utils/RoughnessMipmapper.js

@@ -129,74 +129,74 @@ function _getMipmapMaterial() {
 			texelSize: { value: new Vector2( 1, 1 ) }
 			texelSize: { value: new Vector2( 1, 1 ) }
 		},
 		},
 
 
-		vertexShader: `
-precision mediump float;
-precision mediump int;
-attribute vec3 position;
-attribute vec2 uv;
-varying vec2 vUv;
-void main() {
-  vUv = uv;
-  gl_Position = vec4( position, 1.0 );
-}
-            `,
-
-		fragmentShader: `
-precision mediump float;
-precision mediump int;
-varying vec2 vUv;
-uniform sampler2D roughnessMap;
-uniform sampler2D normalMap;
-uniform vec2 texelSize;
-
-#define ENVMAP_TYPE_CUBE_UV
-vec4 envMapTexelToLinear(vec4 a){return a;}
-#include <cube_uv_reflection_fragment>
-
-float roughnessToVariance(float roughness) {
-float variance = 0.0;
-if (roughness >= r1) {
-  variance = (r0 - roughness) * (v1 - v0) / (r0 - r1) + v0;
-} else if (roughness >= r4) {
-  variance = (r1 - roughness) * (v4 - v1) / (r1 - r4) + v1;
-} else if (roughness >= r5) {
-  variance = (r4 - roughness) * (v5 - v4) / (r4 - r5) + v4;
-} else {
-  float roughness2 = roughness * roughness;
-  variance = 1.79 * roughness2 * roughness2;
-}
-return variance;
-}
-float varianceToRoughness(float variance) {
-float roughness = 0.0;
-if (variance >= v1) {
-  roughness = (v0 - variance) * (r1 - r0) / (v0 - v1) + r0;
-} else if (variance >= v4) {
-  roughness = (v1 - variance) * (r4 - r1) / (v1 - v4) + r1;
-} else if (variance >= v5) {
-  roughness = (v4 - variance) * (r5 - r4) / (v4 - v5) + r4;
-} else {
-  roughness = pow(0.559 * variance, 0.25);// 0.559 = 1.0 / 1.79
-}
-return roughness;
-}
-
-void main() {
-  gl_FragColor = texture2D(roughnessMap, vUv, -1.0);
-  if (texelSize.x == 0.0) return;
-  float roughness = gl_FragColor.g;
-  float variance = roughnessToVariance(roughness);
-  vec3 avgNormal;
-  for (float x = -1.0; x < 2.0; x += 2.0) {
-  for (float y = -1.0; y < 2.0; y += 2.0) {
-      vec2 uv = vUv + vec2(x, y) * 0.25 * texelSize;
-      avgNormal += normalize(texture2D(normalMap, uv, -1.0).xyz - 0.5);
-  }
-  }
-  variance += 1.0 - 0.25 * length(avgNormal);
-  gl_FragColor.g = varianceToRoughness(variance);
-}
-`,
+		vertexShader: /* glsl */`
+			precision mediump float;
+			precision mediump int;
+			attribute vec3 position;
+			attribute vec2 uv;
+			varying vec2 vUv;
+			void main() {
+				vUv = uv;
+				gl_Position = vec4( position, 1.0 );
+			}
+		`,
+
+		fragmentShader: /* glsl */`
+			precision mediump float;
+			precision mediump int;
+			varying vec2 vUv;
+			uniform sampler2D roughnessMap;
+			uniform sampler2D normalMap;
+			uniform vec2 texelSize;
+
+			#define ENVMAP_TYPE_CUBE_UV
+			vec4 envMapTexelToLinear(vec4 a){return a;}
+			#include <cube_uv_reflection_fragment>
+
+			float roughnessToVariance(float roughness) {
+				float variance = 0.0;
+				if (roughness >= r1) {
+					variance = (r0 - roughness) * (v1 - v0) / (r0 - r1) + v0;
+				} else if (roughness >= r4) {
+					variance = (r1 - roughness) * (v4 - v1) / (r1 - r4) + v1;
+				} else if (roughness >= r5) {
+					variance = (r4 - roughness) * (v5 - v4) / (r4 - r5) + v4;
+				} else {
+					float roughness2 = roughness * roughness;
+					variance = 1.79 * roughness2 * roughness2;
+				}
+				return variance;
+			}
+			float varianceToRoughness(float variance) {
+				float roughness = 0.0;
+				if (variance >= v1) {
+					roughness = (v0 - variance) * (r1 - r0) / (v0 - v1) + r0;
+				} else if (variance >= v4) {
+					roughness = (v1 - variance) * (r4 - r1) / (v1 - v4) + r1;
+				} else if (variance >= v5) {
+					roughness = (v4 - variance) * (r5 - r4) / (v4 - v5) + r4;
+				} else {
+					roughness = pow(0.559 * variance, 0.25);// 0.559 = 1.0 / 1.79
+				}
+				return roughness;
+			}
+
+			void main() {
+				gl_FragColor = texture2D(roughnessMap, vUv, -1.0);
+				if (texelSize.x == 0.0) return;
+				float roughness = gl_FragColor.g;
+				float variance = roughnessToVariance(roughness);
+				vec3 avgNormal;
+				for (float x = -1.0; x < 2.0; x += 2.0) {
+					for (float y = -1.0; y < 2.0; y += 2.0) {
+						vec2 uv = vUv + vec2(x, y) * 0.25 * texelSize;
+						avgNormal += normalize(texture2D(normalMap, uv, -1.0).xyz - 0.5);
+					}
+				}
+				variance += 1.0 - 0.25 * length(avgNormal);
+				gl_FragColor.g = varianceToRoughness(variance);
+			}
+		`,
 
 
 		blending: NoBlending,
 		blending: NoBlending,
 		depthTest: false,
 		depthTest: false,

+ 2 - 2
examples/webgl_materials_envmaps_parallax.html

@@ -23,7 +23,7 @@
 			import { RectAreaLightUniformsLib } from './jsm/lights/RectAreaLightUniformsLib.js';
 			import { RectAreaLightUniformsLib } from './jsm/lights/RectAreaLightUniformsLib.js';
 
 
 			// shader injection for box projected cube environment mapping
 			// shader injection for box projected cube environment mapping
-			var worldposReplace = `
+			var worldposReplace = /* glsl */`
 			#define BOX_PROJECTED_ENV_MAP
 			#define BOX_PROJECTED_ENV_MAP
 
 
 			#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )
 			#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )
@@ -39,7 +39,7 @@
 			#endif
 			#endif
 			`;
 			`;
 
 
-			var envmapPhysicalParsReplace = `
+			var envmapPhysicalParsReplace = /* glsl */`
 			#if defined( USE_ENVMAP )
 			#if defined( USE_ENVMAP )
 
 
 				#define BOX_PROJECTED_ENV_MAP
 				#define BOX_PROJECTED_ENV_MAP