[2453] | 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 curAnim = 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
|
---|
| 77 | * quickSin(curAnim * other.z);
|
---|
| 78 |
|
---|
| 79 | // Move particle in object coordinates:
|
---|
| 80 | vec3 moveTot = moveLin.xyz; // Move into constant direction
|
---|
| 81 | moveTot += gl_Normal * param.y; // Move along normal vector
|
---|
| 82 | moveTot += curAnim * moveQuadr.xyz; // Move along a quadratic curve
|
---|
| 83 | moveTot += variDelta; // Move into a random direction
|
---|
| 84 | vec4 posObj = gl_Vertex;
|
---|
| 85 | posObj.xyz += curAnim * moveTot; // Add move
|
---|
| 86 | posObj.xyz += jiggleDelta; // Jitter
|
---|
| 87 |
|
---|
| 88 | // Transformation from object into view coordinates:
|
---|
| 89 | S3D_BONE_TRANSF_STD(matBoneFinal, matBone, boneWgh, boneSubscr);
|
---|
| 90 | vec4 posView = matBoneFinal * posObj;
|
---|
| 91 |
|
---|
| 92 | // Calculate effective particle radius.
|
---|
| 93 | // This includes fading in, fading out and flickering.
|
---|
| 94 | float fadeIn = curAnim * shrink.x;
|
---|
| 95 | float fadeOut = (1.0 - curAnim) * shrink.y;
|
---|
| 96 | float fade = min(1.0, min(fadeIn, fadeOut));
|
---|
| 97 | float flicker = 1.0 - shrink.z * quickSin(curAnim * shrink.w);
|
---|
| 98 | float radius = param.x * flicker * fade;
|
---|
| 99 |
|
---|
| 100 | // Until now we only have the particle center.
|
---|
| 101 | // Now we alculate the corner coordinates.
|
---|
| 102 | // The particle is rotated by a pseudo-random angle:
|
---|
| 103 | vec2 rotRandom;
|
---|
| 104 | rotRandom.x = dot(gl_Vertex, seedRotU);
|
---|
| 105 | rotRandom.y = dot(gl_Vertex, seedRotV);
|
---|
| 106 | vec2 rotDir = normalize(fract(rotRandom) - vec2(0.5, 0.5));
|
---|
| 107 | vec2 rotU = radius * 1.4142 * rotDir;
|
---|
| 108 | vec2 rotV = vec2(- rotU.y, rotU.x);
|
---|
| 109 | vec2 coord = (gl_MultiTexCoord0.xy - vec2(0.5, 0.5));
|
---|
| 110 | posView.xy += rotU * coord.x + rotV * coord.y;
|
---|
| 111 |
|
---|
| 112 | // Projection:
|
---|
| 113 | gl_Position = gl_ProjectionMatrix * posView; //
|
---|
| 114 | gl_TexCoord[0] = gl_MultiTexCoord0;
|
---|
| 115 | gl_FogFragCoord = posView.z / posView.w;
|
---|
| 116 |
|
---|
| 117 | vec4 diffuseOut = gl_FrontMaterial.emission;
|
---|
| 118 | vec4 specularOut = vec4(0);
|
---|
| 119 |
|
---|
| 120 | @ifdef S3D_LIGHT_CNT
|
---|
| 121 | // Work-around to detect nvidia:
|
---|
| 122 | #ifdef __GLSL_CG_DATA_TYPES
|
---|
| 123 | for(int i = 0; i < gl_MaxLights; i++)
|
---|
| 124 | {
|
---|
| 125 | s3d_ColPair result;
|
---|
| 126 | s3d_calcPointLightTerm(
|
---|
| 127 | result, posView.xyz, normalView, gl_FrontMaterial.shininess,
|
---|
| 128 | gl_LightSource[i], gl_FrontLightProduct[i]);
|
---|
| 129 | diffuseOut.rgb += result.diffuse.rgb;
|
---|
| 130 | specularOut.rgb += result.specular.rgb;
|
---|
| 131 | }
|
---|
| 132 | #else
|
---|
| 133 | s3d_ColPair result;
|
---|
| 134 | s3d_calcPointLightTerm(
|
---|
| 135 | result, posView.xyz, vec3(0.0, 0.0, 0.0),
|
---|
| 136 | gl_FrontMaterial.shininess,
|
---|
| 137 | gl_LightSource[0], gl_FrontLightProduct[0]);
|
---|
| 138 | diffuseOut.rgb += result.diffuse.rgb;
|
---|
| 139 | specularOut.rgb += result.specular.rgb;
|
---|
| 140 |
|
---|
| 141 | s3d_calcPointLightTerm(
|
---|
| 142 | result, posView.xyz, vec3(0.0, 0.0, 0.0),
|
---|
| 143 | gl_FrontMaterial.shininess,
|
---|
| 144 | gl_LightSource[1], gl_FrontLightProduct[1]);
|
---|
| 145 | diffuseOut.rgb += result.diffuse.rgb;
|
---|
| 146 | specularOut.rgb += result.specular.rgb;
|
---|
| 147 |
|
---|
| 148 | s3d_calcPointLightTerm(
|
---|
| 149 | result, posView.xyz, vec3(0.0, 0.0, 0.0),
|
---|
| 150 | gl_FrontMaterial.shininess,
|
---|
| 151 | gl_LightSource[2], gl_FrontLightProduct[2]);
|
---|
| 152 | diffuseOut.rgb += result.diffuse.rgb;
|
---|
| 153 | specularOut.rgb += result.specular.rgb;
|
---|
| 154 | #endif
|
---|
| 155 | gl_FrontColor = diffuseOut * colorAlpha * gl_Color;
|
---|
| 156 | gl_FrontSecondaryColor = specularOut;
|
---|
| 157 | @else
|
---|
| 158 | gl_FrontColor = colorAlpha * gl_Color;
|
---|
| 159 | gl_FrontSecondaryColor = vec4(0.0);
|
---|
| 160 | @endif
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | ///////////////////////////////////////////////////////////////////////////////
|
---|