[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 \
|
---|
| 15 | <levelutil/shader/prog/d3d9_hlsl/include_stddef_d3d9_hlsl.s3d_shadercode_run>
|
---|
| 16 |
|
---|
| 17 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 18 |
|
---|
| 19 | struct VS_INPUT
|
---|
| 20 | {
|
---|
| 21 | float4 posObj: POSITION;
|
---|
| 22 | float3 normalObj: NORMAL;
|
---|
| 23 | S3D_BONE_DECL_STD(boneWgh, boneSubscr)
|
---|
| 24 | float4 diffuse: COLOR0;
|
---|
| 25 | float2 mainTexCoord: TEXCOORD0;
|
---|
| 26 | };
|
---|
| 27 |
|
---|
| 28 | struct VS_OUTPUT
|
---|
| 29 | {
|
---|
| 30 | float4 posScr: POSITION;
|
---|
| 31 | float2 mainTexCoord: TEXCOORD0;
|
---|
| 32 | float4 diffuse: COLOR0;
|
---|
| 33 | float4 specular: COLOR1;
|
---|
| 34 | float fogCoord: TEXCOORD2;
|
---|
| 35 | };
|
---|
| 36 |
|
---|
| 37 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 38 |
|
---|
| 39 | const float4x4 projMat;
|
---|
| 40 |
|
---|
| 41 | S3D_MATBONE_DECL_STD(matBone)
|
---|
| 42 |
|
---|
| 43 | const float4 mtrlPower;
|
---|
| 44 | const float4 mtrlEmissive;
|
---|
| 45 |
|
---|
| 46 | #ifdef S3D_LIGHT_CNT
|
---|
| 47 | const s3d_StdProgLight lightArray[S3D_LIGHT_CNT];
|
---|
| 48 | const int activeLights;
|
---|
| 49 | #endif
|
---|
| 50 |
|
---|
| 51 | float4 anim; // Animation time between 0 and 1
|
---|
| 52 | float4 colorAlpha; // Color and alpha factor
|
---|
| 53 | float4 param; // x=Particle radius, y=Move-along-normal-factor
|
---|
| 54 | float4 moveLin; // Linear movement vector
|
---|
| 55 | float4 moveQuadr; // Quadratic movement vector
|
---|
| 56 | float4 moveVari; // Variation amount, see below
|
---|
| 57 | float4 moveJiggle; // Jiggle amount vector, see below.
|
---|
| 58 | float4 shrink; // x=fadeIn, y=fadeOut, z=flickerAmp, w=flickerVel
|
---|
| 59 | float4 other; // x=asyncFactor, y=repeat, z=jiggleVel, w=unused
|
---|
| 60 |
|
---|
| 61 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 62 | // Seed values:
|
---|
| 63 |
|
---|
| 64 | float4 seedVariX = float4(8576, 6968, 8285, 1375);
|
---|
| 65 | float4 seedVariY = float4(9257, 7911, 4491, 4178);
|
---|
| 66 | float4 seedVariZ = float4(9621, 7416, 9166, 1405);
|
---|
| 67 | float4 seedJiggleX = float4(9809, 4760, 6104, 3046);
|
---|
| 68 | float4 seedJiggleY = float4(7590, 5729, 8471, 1556);
|
---|
| 69 | float4 seedJiggleZ = float4(9904, 0636, 4127, 5254);
|
---|
| 70 | float4 seedAnim = float4(8891, 1068, 3747, 5529);
|
---|
| 71 | float4 seedRotU = float4(3147, 0722, 3324, 7158);
|
---|
| 72 | float4 seedRotV = float4(7020, 4337, 7956, 1530);
|
---|
| 73 |
|
---|
| 74 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 75 | // Utility functions:
|
---|
| 76 |
|
---|
| 77 | float quickSin(float phase)
|
---|
| 78 | {
|
---|
| 79 | float rel = frac(phase) - 0.5;
|
---|
| 80 | float val = - 16 * rel * (0.5 - abs(rel));
|
---|
| 81 | return val;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 85 | // Vertexshader
|
---|
| 86 | // Profile: 2x0
|
---|
| 87 |
|
---|
| 88 | VS_OUTPUT main(VS_INPUT input)
|
---|
| 89 | {
|
---|
| 90 | VS_OUTPUT output = (VS_OUTPUT)0;
|
---|
| 91 |
|
---|
| 92 | float animRandom = dot(input.posObj, seedAnim);
|
---|
| 93 | float curAnim = frac(other.x * animRandom + other.y * anim.x);
|
---|
| 94 |
|
---|
| 95 | // The movement direction is varied by a pseudo-random value.
|
---|
| 96 | float3 variRandom;
|
---|
| 97 | variRandom.x = dot(input.posObj, seedVariX);
|
---|
| 98 | variRandom.y = dot(input.posObj, seedVariY);
|
---|
| 99 | variRandom.z = dot(input.posObj, seedVariZ);
|
---|
| 100 | float3 variUnit = (2 * frac(variRandom) - 1);
|
---|
| 101 | float3 variDelta = variUnit * moveVari.xyz;
|
---|
| 102 |
|
---|
| 103 | // The particles jiggle in direction of a pseudo-random value.
|
---|
| 104 | float3 jiggleRandom;
|
---|
| 105 | jiggleRandom.x = dot(input.posObj, seedJiggleX);
|
---|
| 106 | jiggleRandom.y = dot(input.posObj, seedJiggleY);
|
---|
| 107 | jiggleRandom.z = dot(input.posObj, seedJiggleZ);
|
---|
| 108 | float3 jiggleUnit = (2 * frac(jiggleRandom) - 1);
|
---|
| 109 | float3 jiggleDelta = jiggleUnit * moveJiggle
|
---|
| 110 | * quickSin(curAnim * other.z);
|
---|
| 111 |
|
---|
| 112 | // Move particle in object coordinates:
|
---|
| 113 | float3 moveTot = moveLin.xyz; // Move into constant direction
|
---|
| 114 | moveTot += input.normalObj * param.y; // Move along normal vector
|
---|
| 115 | moveTot += curAnim * moveQuadr.xyz; // Move along a quadratic curve
|
---|
| 116 | moveTot += variDelta; // Move into a random direction
|
---|
| 117 | float4 posObj = input.posObj;
|
---|
| 118 | posObj.xyz += curAnim * moveTot; // Add move
|
---|
| 119 | posObj.xyz += jiggleDelta; // Jitter
|
---|
| 120 |
|
---|
| 121 | // Transformation from object into view coordinates:
|
---|
| 122 | float4x4 matBoneFinal;
|
---|
| 123 | S3D_BONE_TRANSF_STD(
|
---|
| 124 | matBoneFinal, matBone, input.boneWgh, input.boneSubscr);
|
---|
| 125 | // Transform vectors by matBoneFinal
|
---|
| 126 | float4 posView = mul(posObj, matBoneFinal);
|
---|
| 127 |
|
---|
| 128 | // Calculate effective particle radius.
|
---|
| 129 | // This includes fading in, fading out and flickering.
|
---|
| 130 | float fadeIn = curAnim * shrink.x;
|
---|
| 131 | float fadeOut = (1 - curAnim) * shrink.y;
|
---|
| 132 | float fade = min(1, min(fadeIn, fadeOut));
|
---|
| 133 | float flicker = 1 - shrink.z * quickSin(curAnim * shrink.w);
|
---|
| 134 | float radius = param.x * flicker * fade;
|
---|
| 135 |
|
---|
| 136 | // Until now we only have the particle center.
|
---|
| 137 | // Now we alculate the corner coordinates.
|
---|
| 138 | // The particle is rotated by a pseudo-random angle:
|
---|
| 139 | float2 rotRandom;
|
---|
| 140 | rotRandom.x = dot(input.posObj, seedRotU);
|
---|
| 141 | rotRandom.y = dot(input.posObj, seedRotV);
|
---|
| 142 | float2 rotDir = normalize(frac(rotRandom) - float2(0.5, 0.5));
|
---|
| 143 | float2 rotU = radius * 1.4142 * rotDir;
|
---|
| 144 | float2 rotV = float2(- rotU.y, rotU.x);
|
---|
| 145 | float2 coord = (input.mainTexCoord.xy - float2(0.5, 0.5));
|
---|
| 146 | posView.xy += rotU * coord.x + rotV * coord.y;
|
---|
| 147 |
|
---|
| 148 | // Projection:
|
---|
| 149 | output.posScr = mul(posView, projMat);
|
---|
| 150 | output.mainTexCoord = input.mainTexCoord;
|
---|
| 151 | output.fogCoord = posView.z / posView.w;
|
---|
| 152 |
|
---|
| 153 | // output.diffuse = input.diffuse;
|
---|
| 154 | // output.specular = 0;
|
---|
| 155 |
|
---|
| 156 | // Calculate vertex color:
|
---|
| 157 | #ifdef S3D_LIGHT_CNT
|
---|
| 158 | float4 colDiffuse = mtrlEmissive;
|
---|
| 159 | float4 colSpecular = 0;
|
---|
| 160 | for(int i = 0; i < activeLights; i++)
|
---|
| 161 | {
|
---|
| 162 | s3d_ColPair lightCol = s3d_calcPointLightTerm(
|
---|
| 163 | posView.xyz, 0, mtrlPower.w, lightArray[i]);
|
---|
| 164 | colDiffuse.rgb += lightCol.diffuse.rgb;
|
---|
| 165 | colSpecular.rgb += lightCol.specular.rgb;
|
---|
| 166 | }
|
---|
| 167 | output.diffuse = colDiffuse * colorAlpha * input.diffuse;
|
---|
| 168 | output.specular = colSpecular;
|
---|
| 169 | #else
|
---|
| 170 | output.diffuse = colorAlpha * input.diffuse;
|
---|
| 171 | output.specular = 0;
|
---|
| 172 | #endif
|
---|
| 173 |
|
---|
| 174 | return output;
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | ///////////////////////////////////////////////////////////////////////////////
|
---|