Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uniform int iUseTexture0;
- uniform int iUseTexture1;
- uniform int iUseTexture2;
- uniform int iUseTexture3;
- uniform sampler2D iTexture0;
- uniform sampler2D iTexture1;
- uniform sampler2D iTexture2;
- uniform sampler2D iTexture3;
- uniform vec4 iClipPlane;
- uniform int iUseClipPlane;
- uniform int iUseLighting;
- uniform int iMultiplyAmbient;
- //fog-related uniforms
- uniform int iFogEnabled;
- uniform int iFogMode; //0 - linear, 1 - exp, 2 - exp2
- uniform float iFogDensity;
- uniform float iFogStart;
- uniform float iFogEnd;
- uniform vec3 iFogCol;
- varying vec3 iPositionWorld;
- varying vec3 iPositionCamera;
- varying vec3 iNormalCamera;
- uniform float resolution;
- uniform float radius;
- uniform vec2 dir;
- uniform float screenWidth = 1920;
- uniform float screenHeight = 1080;
- void main()
- {
- //clipping plane part of shader
- if (iUseClipPlane == 1 && dot(iPositionWorld, iClipPlane.xyz) < iClipPlane.w) {
- discard;
- }
- vec3 N = normalize(iNormalCamera);
- vec3 v = normalize(iPositionCamera);
- vec3 R = reflect(-v,N);
- vec4 ambient = vec4(0,0,0,0);
- vec4 diffuse = vec4(0,0,0,0);
- vec4 specular = vec4(0,0,0,0);
- //ambient component
- if (iUseTexture1 == 1) {
- ambient = texture2D(iTexture1, gl_TexCoord[1].xy);
- }
- ambient.w = 1.0;
- //diffuse component
- if (iUseTexture0 == 1) {
- diffuse = texture2D(iTexture0, gl_TexCoord[0].xy);
- }
- else {
- diffuse = gl_FrontMaterial.diffuse;
- }
- if(ambient.w < 0.01 || diffuse.w < 0.01) {
- discard;
- }
- if (iUseLighting == 1) {
- diffuse.xyz *= abs(dot(N, v));
- }
- //specular component - note disabled if "lighting" is off
- if (iUseLighting == 1) {
- //specular component
- if (iUseTexture2 == 1) {
- specular = texture2D(iTexture2, gl_TexCoord[2].xy);
- }
- else {
- specular = gl_FrontMaterial.specular;
- }
- //specular *= clamp(pow(max(dot(R,v),0.0), gl_FrontMaterial.shininess), 0.0, 1.0);
- //specular *= pow(max(dot(R,v),0.0), max(gl_FrontMaterial.shininess, 1.0));
- specular *= pow(max(dot(R,v),0.0), max(gl_FrontMaterial.shininess, 1.0));
- if (iUseTexture3 == 1) {
- specular *= texture2D(iTexture3, gl_TexCoord[3].xy);
- }
- }
- specular.w = 1.0;
- //global scaling via colour
- gl_FragColor = gl_Color;
- if (iMultiplyAmbient == 0) {
- gl_FragColor.xyz *= (ambient + diffuse + specular).xyz;
- }
- else {
- if (iUseTexture1 == 1) {
- //gl_FragColor.xyz *= ((vec4(1,1,1,1) * 0.2 + ambient * 0.8) * diffuse + specular).xyz;
- gl_FragColor.xyz *= (0.1 + ambient * diffuse * 1.25).xyz;
- }
- else {
- gl_FragColor.xyz *= (diffuse + specular).xyz;
- //gl_FragColor.xyz *= (diffuse).xyz;
- }
- }
- if (iUseTexture0 == 1) {
- gl_FragColor.w = diffuse.w;
- }
- //apply fog
- if (iFogEnabled == 1) {
- //compute length from eye to fragment
- float c = length(iPositionCamera);
- //compute blend value
- float f;
- if (iFogMode == 0) {
- f = (iFogEnd - c) / (iFogEnd - iFogStart);
- }
- else if (iFogMode == 1) {
- f = exp(-iFogDensity * c);
- }
- else if (iFogMode == 2) {
- f = exp(-(iFogDensity * c)*(iFogDensity * c));
- }
- f = clamp(f, 0, 1);
- //blend with fragment's post-texturing colour using the appropriate blending factor
- gl_FragColor.xyz = gl_FragColor.xyz * f + iFogCol * (1.0 - f);
- }
- // Converting (x,y,z) to range [0,1]
- float x = gl_FragCoord.x/screenWidth;
- float y = gl_FragCoord.y/screenHeight;
- float z = gl_FragCoord.z; // Already in range [0,1]
- // Converting from range [0,1] to NDC [-1,1]
- float ndcx = x * 2.0 - 1.0;
- float ndcy = y * 2.0 - 1.0;
- float ndcz = z * 2.0 - 1.0;
- vec3 ndc = vec3(ndcx, ndcy, ndcz);
- vec4 blurSample = 0.0;
- vec4 tmpPix;
- vec4 offPix;
- vec2 uv = vec2(ndcx, ndcy);
- for(int i=-4;i<5;i++)
- {
- tmpPix = texture2D(iTexture0,uv + vec2( i*0.005,0 ));
- offPix = -0.3+tmpPix;
- offPix = offPix * 15;
- if( (offPix.r+offPix.g+offPix.b)>0 )
- {
- blurSample = blurSample + offPix;
- }
- }
- for(int i=-4;i<5;i++)
- {
- tmpPix = texture2D(iTexture0,uv + vec2( 0,i*0.005 ));
- offPix = -0.3+tmpPix;
- offPix = offPix * 15;
- if( (offPix.r+offPix.g+offPix.b)>0 )
- {
- blurSample += offPix;
- }
- }
- blurSample = blurSample / 64;
- gl_FragColor.xyz = blurSample*1.2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement