Browse Source

Add .isGLSL3 to ShaderMaterial

Takahiro 7 năm trước cách đây
mục cha
commit
32cb6727ce
2 tập tin đã thay đổi với 6 bổ sung2 xóa
  1. 2 0
      src/materials/ShaderMaterial.js
  2. 4 2
      src/renderers/webgl/WebGLProgram.js

+ 2 - 0
src/materials/ShaderMaterial.js

@@ -34,6 +34,8 @@ function ShaderMaterial( parameters ) {
 	this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
 	this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
 
+	this.isGLSL3 = false;
+
 	this.linewidth = 1;
 
 	this.wireframe = false;

+ 4 - 2
src/renderers/webgl/WebGLProgram.js

@@ -518,6 +518,8 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters
 
 	if ( isWebGL2 && ! material.isRawShaderMaterial ) {
 
+		var isGLSL3ShaderMaterial = material.isShaderMaterial && material.isGLSL3;
+
 		// GLSL 3.0 conversion
 		prefixVertex = [
 			'#version 300 es\n',
@@ -529,8 +531,8 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters
 		prefixFragment = [
 			'#version 300 es\n',
 			'#define varying in',
-			'out highp vec4 pc_fragColor;',
-			'#define gl_FragColor pc_fragColor',
+			isGLSL3ShaderMaterial ? '' : 'out highp vec4 pc_fragColor;',
+			isGLSL3ShaderMaterial ? '' : '#define gl_FragColor pc_fragColor',
 			'#define gl_FragDepthEXT gl_FragDepth',
 			'#define texture2D texture',
 			'#define textureCube texture',