提交 3cd1a348 编写于 作者: M Mugen87

LensFlarePlugin: Simplify code

This commit removes the MAX_VERTEX_TEXTURE_IMAGE_UNITS === 0 code path.
上级 3164a6f8
......@@ -9,8 +9,7 @@ THREE.LensFlarePlugin = function ( renderer, flares ) {
var state = renderer.state;
var vertexBuffer, elementBuffer;
var program, attributes, uniforms;
var hasVertexTexture;
var shader, program, attributes, uniforms;
var tempTexture, occlusionTexture;
......@@ -58,193 +57,99 @@ THREE.LensFlarePlugin = function ( renderer, flares ) {
gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
hasVertexTexture = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ) > 0;
shader = {
var shader;
vertexShader: [
if ( hasVertexTexture ) {
"uniform lowp int renderType;",
shader = {
"uniform vec3 screenPosition;",
"uniform vec2 scale;",
"uniform float rotation;",
vertexShader: [
"uniform sampler2D occlusionMap;",
"uniform lowp int renderType;",
"attribute vec2 position;",
"attribute vec2 uv;",
"uniform vec3 screenPosition;",
"uniform vec2 scale;",
"uniform float rotation;",
"varying vec2 vUV;",
"varying float vVisibility;",
"uniform sampler2D occlusionMap;",
"void main() {",
"attribute vec2 position;",
"attribute vec2 uv;",
"vUV = uv;",
"varying vec2 vUV;",
"varying float vVisibility;",
"vec2 pos = position;",
"void main() {",
"if ( renderType == 2 ) {",
"vUV = uv;",
"vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
"vec2 pos = position;",
"vVisibility = visibility.r / 9.0;",
"vVisibility *= 1.0 - visibility.g / 9.0;",
"vVisibility *= visibility.b / 9.0;",
"vVisibility *= 1.0 - visibility.a / 9.0;",
"if ( renderType == 2 ) {",
"pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
"pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
"vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
"visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
"}",
"vVisibility = visibility.r / 9.0;",
"vVisibility *= 1.0 - visibility.g / 9.0;",
"vVisibility *= visibility.b / 9.0;",
"vVisibility *= 1.0 - visibility.a / 9.0;",
"gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
"pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
"pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
"}"
"}",
].join( "\n" ),
"gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
fragmentShader: [
"}"
"uniform lowp int renderType;",
].join( "\n" ),
"uniform sampler2D map;",
"uniform float opacity;",
"uniform vec3 color;",
fragmentShader: [
"varying vec2 vUV;",
"varying float vVisibility;",
"uniform lowp int renderType;",
"void main() {",
"uniform sampler2D map;",
"uniform float opacity;",
"uniform vec3 color;",
// pink square
"varying vec2 vUV;",
"varying float vVisibility;",
"if ( renderType == 0 ) {",
"void main() {",
"gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
// pink square
// restore
"if ( renderType == 0 ) {",
"} else if ( renderType == 1 ) {",
"gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
"gl_FragColor = texture2D( map, vUV );",
// restore
// flare
"} else if ( renderType == 1 ) {",
"} else {",
"gl_FragColor = texture2D( map, vUV );",
"vec4 texture = texture2D( map, vUV );",
"texture.a *= opacity * vVisibility;",
"gl_FragColor = texture;",
"gl_FragColor.rgb *= color;",
// flare
"}",
"} else {",
"}"
"vec4 texture = texture2D( map, vUV );",
"texture.a *= opacity * vVisibility;",
"gl_FragColor = texture;",
"gl_FragColor.rgb *= color;",
].join( "\n" )
"}",
"}"
].join( "\n" )
};
} else {
shader = {
vertexShader: [
"uniform lowp int renderType;",
"uniform vec3 screenPosition;",
"uniform vec2 scale;",
"uniform float rotation;",
"attribute vec2 position;",
"attribute vec2 uv;",
"varying vec2 vUV;",
"void main() {",
"vUV = uv;",
"vec2 pos = position;",
"if ( renderType == 2 ) {",
"pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
"pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
"}",
"gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"precision mediump float;",
"uniform lowp int renderType;",
"uniform sampler2D map;",
"uniform sampler2D occlusionMap;",
"uniform float opacity;",
"uniform vec3 color;",
"varying vec2 vUV;",
"void main() {",
// pink square
"if ( renderType == 0 ) {",
"gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );",
// restore
"} else if ( renderType == 1 ) {",
"gl_FragColor = texture2D( map, vUV );",
// flare
"} else {",
"float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a;",
"visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a;",
"visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a;",
"visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;",
"visibility = ( 1.0 - visibility / 4.0 );",
"vec4 texture = texture2D( map, vUV );",
"texture.a *= opacity * visibility;",
"gl_FragColor = texture;",
"gl_FragColor.rgb *= color;",
"}",
"}"
].join( "\n" )
};
}
};
program = createProgram( shader );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册