Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move glsl code from ShaderLib to *.glsl files using the new #include system #8223

Merged
merged 3 commits into from
Feb 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
919 changes: 24 additions & 895 deletions src/renderers/shaders/ShaderLib.js

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions src/renderers/shaders/ShaderLib/cube_frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
uniform samplerCube tCube;
uniform float tFlip;

varying vec3 vWorldPosition;

#include <common>
#include <logdepthbuf_pars_fragment>

void main() {

gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );

#include <logdepthbuf_fragment>

}
14 changes: 14 additions & 0 deletions src/renderers/shaders/ShaderLib/cube_vert.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
varying vec3 vWorldPosition;

#include <common>
#include <logdepthbuf_pars_vertex>

void main() {

vWorldPosition = transformDirection( position, modelMatrix );

gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );

#include <logdepthbuf_vertex>

}
33 changes: 33 additions & 0 deletions src/renderers/shaders/ShaderLib/depthRGBA_frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <common>
#include <logdepthbuf_pars_fragment>

vec4 pack_depth( const in float depth ) {

const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );
const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );
vec4 res = mod( depth * bit_shift * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );
res -= res.xxyz * bit_mask;
return res;

}

void main() {

#include <logdepthbuf_fragment>

#ifdef USE_LOGDEPTHBUF_EXT

gl_FragData[ 0 ] = pack_depth( gl_FragDepthEXT );

#else

gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );

#endif

//gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z / gl_FragCoord.w );
//float z = ( ( gl_FragCoord.z / gl_FragCoord.w ) - 3.0 ) / ( 4000.0 - 3.0 );
//gl_FragData[ 0 ] = pack_depth( z );
//gl_FragData[ 0 ] = vec4( z, z, z, 1.0 );

}
16 changes: 16 additions & 0 deletions src/renderers/shaders/ShaderLib/depthRGBA_vert.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <common>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <logdepthbuf_pars_vertex>

void main() {

#include <skinbase_vertex>

#include <begin_vertex>
#include <morphtarget_vertex>
#include <skinning_vertex>
#include <project_vertex>
#include <logdepthbuf_vertex>

}
25 changes: 25 additions & 0 deletions src/renderers/shaders/ShaderLib/depth_frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
uniform float mNear;
uniform float mFar;
uniform float opacity;

#include <common>
#include <logdepthbuf_pars_fragment>

void main() {

#include <logdepthbuf_fragment>

#ifdef USE_LOGDEPTHBUF_EXT

float depth = gl_FragDepthEXT / gl_FragCoord.w;

#else

float depth = gl_FragCoord.z / gl_FragCoord.w;

#endif

float color = 1.0 - smoothstep( mNear, mFar, depth );
gl_FragColor = vec4( vec3( color ), opacity );

}
12 changes: 12 additions & 0 deletions src/renderers/shaders/ShaderLib/depth_vert.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <common>
#include <morphtarget_pars_vertex>
#include <logdepthbuf_pars_vertex>

void main() {

#include <begin_vertex>
#include <morphtarget_vertex>
#include <project_vertex>
#include <logdepthbuf_vertex>

}
26 changes: 26 additions & 0 deletions src/renderers/shaders/ShaderLib/distanceRGBA_frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
uniform vec3 lightPos;
varying vec4 vWorldPosition;

#include <common>

vec4 pack1K ( float depth ) {

depth /= 1000.0;
const vec4 bitSh = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );
const vec4 bitMsk = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );
vec4 res = mod( depth * bitSh * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );
res -= res.xxyz * bitMsk;
return res;

}

float unpack1K ( vec4 color ) {

const vec4 bitSh = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );
return dot( color, bitSh ) * 1000.0;

}

void main () {

gl_FragColor = pack1K( length( vWorldPosition.xyz - lightPos.xyz ) );
18 changes: 18 additions & 0 deletions src/renderers/shaders/ShaderLib/distanceRGBA_vert.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
varying vec4 vWorldPosition;

#include <common>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>

void main() {

#include <skinbase_vertex>
#include <begin_vertex>
#include <morphtarget_vertex>
#include <skinning_vertex>
#include <project_vertex>
#include <worldpos_vertex>

vWorldPosition = worldPosition;

}
20 changes: 20 additions & 0 deletions src/renderers/shaders/ShaderLib/equirect_frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
uniform sampler2D tEquirect;
uniform float tFlip;

varying vec3 vWorldPosition;

#include <common>
#include <logdepthbuf_pars_fragment>

void main() {

// gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );
vec3 direction = normalize( vWorldPosition );
vec2 sampleUV;
sampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );
sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;
gl_FragColor = texture2D( tEquirect, sampleUV );

#include <logdepthbuf_fragment>

}
14 changes: 14 additions & 0 deletions src/renderers/shaders/ShaderLib/equirect_vert.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
varying vec3 vWorldPosition;

#include <common>
#include <logdepthbuf_pars_vertex>

void main() {

vWorldPosition = transformDirection( position, modelMatrix );

gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );

#include <logdepthbuf_vertex>

}
34 changes: 34 additions & 0 deletions src/renderers/shaders/ShaderLib/linedashed_frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
uniform vec3 diffuse;
uniform float opacity;

uniform float dashSize;
uniform float totalSize;

varying float vLineDistance;

#include <common>
#include <color_pars_fragment>
#include <fog_pars_fragment>
#include <logdepthbuf_pars_fragment>

void main() {

if ( mod( vLineDistance, totalSize ) > dashSize ) {

discard;

}

vec3 outgoingLight = vec3( 0.0 );
vec4 diffuseColor = vec4( diffuse, opacity );

#include <logdepthbuf_fragment>
#include <color_fragment>

outgoingLight = diffuseColor.rgb; // simple shader

#include <fog_fragment>

gl_FragColor = vec4( outgoingLight, diffuseColor.a );

}
21 changes: 21 additions & 0 deletions src/renderers/shaders/ShaderLib/linedashed_vert.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
uniform float scale;
attribute float lineDistance;

varying float vLineDistance;

#include <common>
#include <color_pars_vertex>
#include <logdepthbuf_pars_vertex>

void main() {

#include <color_vertex>

vLineDistance = scale * lineDistance;

vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
gl_Position = projectionMatrix * mvPosition;

#include <logdepthbuf_vertex>

}
49 changes: 49 additions & 0 deletions src/renderers/shaders/ShaderLib/meshbasic_frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
uniform vec3 diffuse;
uniform float opacity;

#ifndef FLAT_SHADED

varying vec3 vNormal;

#endif

#include <common>
#include <color_pars_fragment>
#include <uv_pars_fragment>
#include <uv2_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <aomap_pars_fragment>
#include <envmap_pars_fragment>
#include <fog_pars_fragment>
#include <specularmap_pars_fragment>
#include <logdepthbuf_pars_fragment>

void main() {

vec4 diffuseColor = vec4( diffuse, opacity );

#include <logdepthbuf_fragment>
#include <map_fragment>
#include <color_fragment>
#include <alphamap_fragment>
#include <alphatest_fragment>
#include <specularmap_fragment>

ReflectedLight reflectedLight;
reflectedLight.directDiffuse = vec3( 0.0 );
reflectedLight.directSpecular = vec3( 0.0 );
reflectedLight.indirectDiffuse = diffuseColor.rgb;
reflectedLight.indirectSpecular = vec3( 0.0 );

#include <aomap_fragment>

vec3 outgoingLight = reflectedLight.indirectDiffuse;

#include <envmap_fragment>
#include <linear_to_gamma_fragment>
#include <fog_fragment>

gl_FragColor = vec4( outgoingLight, diffuseColor.a );

}
35 changes: 35 additions & 0 deletions src/renderers/shaders/ShaderLib/meshbasic_vert.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <common>
#include <uv_pars_vertex>
#include <uv2_pars_vertex>
#include <envmap_pars_vertex>
#include <color_pars_vertex>
#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <logdepthbuf_pars_vertex>

void main() {

#include <uv_vertex>
#include <uv2_vertex>
#include <color_vertex>
#include <skinbase_vertex>

#ifdef USE_ENVMAP

#include <beginnormal_vertex>
#include <morphnormal_vertex>
#include <skinnormal_vertex>
#include <defaultnormal_vertex>

#endif

#include <begin_vertex>
#include <morphtarget_vertex>
#include <skinning_vertex>
#include <project_vertex>
#include <logdepthbuf_vertex>

#include <worldpos_vertex>
#include <envmap_vertex>

}
Loading