[2270] | 1 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 2 | //
|
---|
| 3 | // ## ######
|
---|
| 4 | // ###### ###
|
---|
| 5 | // ## ############### Shark 3D Engine (www.shark3d.com)
|
---|
| 6 | // ########## # # #
|
---|
| 7 | // ######## Copyright (c) 1996-2006 Spinor GmbH.
|
---|
| 8 | // ######### # # # All rights reserved.
|
---|
| 9 | // ## ##########
|
---|
| 10 | // ##
|
---|
| 11 | //
|
---|
| 12 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 13 |
|
---|
| 14 | @include "levelutil/shader/prog/ogl_glsl/" \
|
---|
| 15 | "include_stddef_ogl_glsl_vs1x0.s3d_shadercode_run"
|
---|
| 16 |
|
---|
| 17 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 18 |
|
---|
| 19 | S3D_BONE_DECL_STD(boneWgh, boneSubscr)
|
---|
| 20 | S3D_MATBONE_DECL_STD(matBone)
|
---|
| 21 |
|
---|
| 22 | uniform vec4 anim; // Animation time between 0 and 1
|
---|
| 23 | uniform vec4 colorAlpha; // Color and alpha factor
|
---|
| 24 | uniform vec4 param; // x=Particle radius, y=Move-along-normal-factor
|
---|
| 25 | uniform vec4 moveLin; // Linear movement vector
|
---|
| 26 | uniform vec4 moveQuadr; // Quadratic movement vector
|
---|
| 27 | uniform vec4 moveVari; // Variation amount, see below
|
---|
| 28 | uniform vec4 moveJiggle; // Jiggle amount vector, see below.
|
---|
| 29 | uniform vec4 shrink; // x=fadeIn, y=fadeOut, z=flickerAmp, w=flickerVel
|
---|
| 30 | uniform vec4 other; // x=asyncFactor, y=repeat, z=jiggleVel, w=unused
|
---|
| 31 |
|
---|
| 32 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 33 | // Seed values:
|
---|
| 34 |
|
---|
| 35 | vec4 seedVariX = vec4(8576, 6968, 8285, 1375);
|
---|
| 36 | vec4 seedVariY = vec4(9257, 7911, 4491, 4178);
|
---|
| 37 | vec4 seedVariZ = vec4(9621, 7416, 9166, 1405);
|
---|
| 38 | vec4 seedJiggleX = vec4(9809, 4760, 6104, 3046);
|
---|
| 39 | vec4 seedJiggleY = vec4(7590, 5729, 8471, 1556);
|
---|
| 40 | vec4 seedJiggleZ = vec4(9904, 0636, 4127, 5254);
|
---|
| 41 | vec4 seedAnim = vec4(8891, 1068, 3747, 5529);
|
---|
| 42 | vec4 seedRotU = vec4(3147, 0722, 3324, 7158);
|
---|
| 43 | vec4 seedRotV = vec4(7020, 4337, 7956, 1530);
|
---|
| 44 |
|
---|
| 45 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 46 | // Utility functions:
|
---|
| 47 |
|
---|
| 48 | float quickSin(float phase)
|
---|
| 49 | {
|
---|
| 50 | float rel = fract(phase) - 0.5;
|
---|
| 51 | float val = - 16.0 * rel * (0.5 - abs(rel));
|
---|
| 52 | return val;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 56 |
|
---|
| 57 | void main(void)
|
---|
| 58 | {
|
---|
| 59 | float animRandom = dot(gl_Vertex, seedAnim);
|
---|
| 60 | float anim = fract(other.x * animRandom + other.y * anim.x);
|
---|
| 61 |
|
---|
| 62 | // The movement direction is varied by a pseudo-random value.
|
---|
| 63 | vec3 variRandom;
|
---|
| 64 | variRandom.x = dot(gl_Vertex, seedVariX);
|
---|
| 65 | variRandom.y = dot(gl_Vertex, seedVariY);
|
---|
| 66 | variRandom.z = dot(gl_Vertex, seedVariZ);
|
---|
| 67 | vec3 variUnit = (2.0 * fract(variRandom) - 1.0);
|
---|
| 68 | vec3 variDelta = variUnit * moveVari.xyz;
|
---|
| 69 |
|
---|
| 70 | // The particles jiggle in direction of a pseudo-random value.
|
---|
| 71 | vec3 jiggleRandom;
|
---|
| 72 | jiggleRandom.x = dot(gl_Vertex, seedJiggleX);
|
---|
| 73 | jiggleRandom.y = dot(gl_Vertex, seedJiggleY);
|
---|
| 74 | jiggleRandom.z = dot(gl_Vertex, seedJiggleZ);
|
---|
| 75 | vec3 jiggleUnit = (2.0 * fract(jiggleRandom) - 1.0);
|
---|
| 76 | vec3 jiggleDelta = jiggleUnit * moveJiggle.xyz * quickSin(anim * other.z);
|
---|
| 77 |
|
---|
| 78 | // Move particle in object coordinates:
|
---|
| 79 | vec3 moveTot = moveLin.xyz; // Move into constant direction
|
---|
| 80 | moveTot += gl_Normal * param.y; // Move along normal vector
|
---|
| 81 | moveTot += anim * moveQuadr.xyz; // Move along a quadratic curve
|
---|
| 82 | moveTot += variDelta; // Move into a random direction
|
---|
| 83 | vec4 posObj = gl_Vertex;
|
---|
| 84 | posObj.xyz += anim * moveTot; // Add move
|
---|
| 85 | posObj.xyz += jiggleDelta; // Jitter
|
---|
| 86 |
|
---|
| 87 | // Transformation from object into view coordinates:
|
---|
| 88 | S3D_BONE_TRANSF_STD(matBoneFinal, matBone, boneWgh, boneSubscr);
|
---|
| 89 | vec4 posView = matBoneFinal * posObj;
|
---|
| 90 |
|
---|
| 91 | // Calculate effective particle radius.
|
---|
| 92 | // This includes fading in, fading out and flickering.
|
---|
| 93 | float fadeIn = anim * shrink.x;
|
---|
| 94 | float fadeOut = (1.0 - anim) * shrink.y;
|
---|
| 95 | float fade = min(1.0, min(fadeIn, fadeOut));
|
---|
| 96 | float flicker = 1.0 - shrink.z * quickSin(anim * shrink.w);
|
---|
| 97 | float radius = param.x * flicker * fade;
|
---|
| 98 |
|
---|
| 99 | // Until now we only have the particle center.
|
---|
| 100 | // Now we alculate the corner coordinates.
|
---|
| 101 | // The particle is rotated by a pseudo-random angle:
|
---|
| 102 | vec2 rotRandom;
|
---|
| 103 | rotRandom.x = dot(gl_Vertex, seedRotU);
|
---|
| 104 | rotRandom.y = dot(gl_Vertex, seedRotV);
|
---|
| 105 | vec2 rotDir = normalize(fract(rotRandom) - vec2(0.5, 0.5));
|
---|
| 106 | vec2 rotU = radius * 1.4142 * rotDir;
|
---|
| 107 | vec2 rotV = vec2(- rotU.y, rotU.x);
|
---|
| 108 | vec2 coord = (gl_MultiTexCoord0.xy - vec2(0.5, 0.5));
|
---|
| 109 | posView.xy += rotU * coord.x + rotV * coord.y;
|
---|
| 110 |
|
---|
| 111 | // Projection:
|
---|
| 112 | gl_Position = gl_ProjectionMatrix * posView; //
|
---|
| 113 | gl_TexCoord[0] = gl_MultiTexCoord0;
|
---|
| 114 | gl_FogFragCoord = posView.z / posView.w;
|
---|
| 115 |
|
---|
| 116 | vec4 diffuseOut = gl_FrontMaterial.emission;
|
---|
| 117 | vec4 specularOut = vec4(0);
|
---|
| 118 |
|
---|
| 119 | @ifdef S3D_LIGHT_CNT
|
---|
| 120 | // Work-around to detect nvidia:
|
---|
| 121 | #ifdef __GLSL_CG_DATA_TYPES
|
---|
| 122 | for(int i = 0; i < gl_MaxLights; i++)
|
---|
| 123 | {
|
---|
| 124 | s3d_ColPair result;
|
---|
| 125 | s3d_calcPointLightTerm(
|
---|
| 126 | result, posView.xyz, normalView, gl_FrontMaterial.shininess,
|
---|
| 127 | gl_LightSource[i], gl_FrontLightProduct[i]);
|
---|
| 128 | diffuseOut.rgb += result.diffuse.rgb;
|
---|
| 129 | specularOut.rgb += result.specular.rgb;
|
---|
| 130 | }
|
---|
| 131 | #else
|
---|
| 132 | s3d_ColPair result;
|
---|
| 133 | s3d_calcPointLightTerm(
|
---|
| 134 | result, posView.xyz, vec3(0.0, 0.0, 0.0),
|
---|
| 135 | gl_FrontMaterial.shininess,
|
---|
| 136 | gl_LightSource[0], gl_FrontLightProduct[0]);
|
---|
| 137 | diffuseOut.rgb += result.diffuse.rgb;
|
---|
| 138 | specularOut.rgb += result.specular.rgb;
|
---|
| 139 |
|
---|
| 140 | s3d_calcPointLightTerm(
|
---|
| 141 | result, posView.xyz, vec3(0.0, 0.0, 0.0),
|
---|
| 142 | gl_FrontMaterial.shininess,
|
---|
| 143 | gl_LightSource[1], gl_FrontLightProduct[1]);
|
---|
| 144 | diffuseOut.rgb += result.diffuse.rgb;
|
---|
| 145 | specularOut.rgb += result.specular.rgb;
|
---|
| 146 |
|
---|
| 147 | s3d_calcPointLightTerm(
|
---|
| 148 | result, posView.xyz, vec3(0.0, 0.0, 0.0),
|
---|
| 149 | gl_FrontMaterial.shininess,
|
---|
| 150 | gl_LightSource[2], gl_FrontLightProduct[2]);
|
---|
| 151 | diffuseOut.rgb += result.diffuse.rgb;
|
---|
| 152 | specularOut.rgb += result.specular.rgb;
|
---|
| 153 | #endif
|
---|
| 154 | gl_FrontColor = diffuseOut * colorAlpha * gl_Color;
|
---|
| 155 | gl_FrontSecondaryColor = specularOut;
|
---|
| 156 | @else
|
---|
| 157 | gl_FrontColor = colorAlpha * gl_Color;
|
---|
| 158 | gl_FrontSecondaryColor = vec4(0.0);
|
---|
| 159 | @endif
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | ///////////////////////////////////////////////////////////////////////////////
|
---|