Răsfoiți Sursa

Merge pull request #20095 from Mugen87/dev51

ShaderMaterial: Improve typings and docs for glslVersion.
Mr.doob 5 ani în urmă
părinte
comite
b9ecd4e6b2

+ 6 - 8
docs/api/en/materials/ShaderMaterial.html

@@ -346,6 +346,12 @@ this.extensions = {
 		as a string directly or loaded via AJAX instead.
 		</p>
 
+		<h3>[property:String glslVersion]</h3>
+		<p>
+		Defines the GLSL version of custom shader code. Only relevant for WebGL 2 in order to define whether to use
+		GLSL 3.0 or not. Valid values are *THREE.GLSL1* or *THREE.GLSL3*. Default is *null*.
+		</p>
+
 		<h3>[property:String index0AttributeName]</h3>
 		<p>
 			If set, this calls [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/bindAttribLocation gl.bindAttribLocation]
@@ -378,19 +384,11 @@ this.extensions = {
 		When set to true, morph normal attributes are available in the vertex shader. Default is *false*.
 		</p>
 
-
-		<h3>[property:WebGLProgram program]</h3>
-		<p>
-		The compiled shader program associated with this material, generated by [page:WebGLRenderer].
-		You should not need to access this property.
-		</p>
-
 		<h3>[property:Boolean flatShading]</h3>
 		<p>
 		Define whether the material is rendered with flat shading. Default is false.
 		</p>
 
-
 		<h3>[property:Boolean skinning]</h3>
 		<p>
 		Define whether the material uses skinning; true to pass skinning attributes to the shader. Default is false.

+ 6 - 4
docs/api/zh/materials/ShaderMaterial.html

@@ -310,6 +310,12 @@ this.extensions = {
 			它也可以作为一个字符串直接传递或者通过AJAX加载。
 		</p>
 
+		<h3>[property:String glslVersion]</h3>
+		<p>
+		Defines the GLSL version of custom shader code. Only relevant for WebGL 2 in order to define whether to use
+		GLSL 3.0 or not. Valid values are *THREE.GLSL1* or *THREE.GLSL3*. Default is *null*.
+		</p>
+
 		<h3>[property:String index0AttributeName]</h3>
 		<p> 如果设置,则调用[link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/bindAttribLocation gl.bindAttribLocation]
 			将通用顶点索引绑定到属性变量。默认值未定义。
@@ -333,10 +339,6 @@ this.extensions = {
 		<p> When set to true, morph normal attributes are available in the vertex shader. Default is *false*.
 		</p>
 
-		<h3>[property:WebGLProgram program]</h3>
-		<p> 与此材质相关联的编译后的shader程序,由[page:WebGLRenderer]生成。您应该不需要访问此属性。
-		</p>
-
 		<h3>[property:Boolean flatShading]</h3>
 		<p> 定义材质是否使用平面着色进行渲染。默认值为false。
 		</p>

+ 3 - 2
src/constants.d.ts

@@ -366,5 +366,6 @@ export const StaticCopyUsage: Usage;
 export const DynamicCopyUsage: Usage;
 export const StreamCopyUsage: Usage;
 
-export const GLSL1: string;
-export const GLSL3: string;
+export enum GLSLVersion {}
+export const GLSL1: GLSLVersion;
+export const GLSL3: GLSLVersion;

+ 7 - 2
src/materials/ShaderMaterial.d.ts

@@ -1,5 +1,6 @@
 import { IUniform } from '../renderers/shaders/UniformsLib';
 import { MaterialParameters, Material } from './Material';
+import { GLSLVersion } from '../constants';
 
 /**
  * @deprecated Use {@link PointsMaterial THREE.PointsMaterial} instead
@@ -29,7 +30,7 @@ export interface ShaderMaterialParameters extends MaterialParameters {
 		drawBuffers?: boolean;
 		shaderTextureLOD?: boolean;
 	};
-	glslVersion?: string;
+	glslVersion?: GLSLVersion;
 }
 
 export class ShaderMaterial extends Material {
@@ -126,7 +127,11 @@ export class ShaderMaterial extends Material {
 	 * @default false
 	 */
 	uniformsNeedUpdate: boolean;
-	glslVersion: string;
+
+	/**
+	 * @default null
+	 */
+	glslVersion: GLSLVersion | null;
 
 	setValues( parameters: ShaderMaterialParameters ): void;
 	toJSON( meta: any ): any;

+ 1 - 1
src/renderers/webgl/WebGLProgram.js

@@ -669,7 +669,7 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
 
 	if ( parameters.isWebGL2 && ! parameters.isRawShaderMaterial ) {
 
-		// overwrite GLSL version for built-in materials
+		// GLSL 3.0 conversion for built-in materials and ShaderMaterial
 
 		versionString = '#version 300 es\n';