1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
2 | #include "particle_common.cg" |
---|
3 | void vpmain(in float4 posin : POSITION, |
---|
4 | in float4 colin : COLOR0, |
---|
5 | in float4 attr : TEXCOORD0, |
---|
6 | inout float pointSize : PSIZE, |
---|
7 | out float4 posout : POSITION, |
---|
8 | out float4 colout : COLOR0, |
---|
9 | out float2 center : TEXCOORD2, |
---|
10 | out float4 rotation : TEXCOORD3, |
---|
11 | out float skip : TEXCOORD4, |
---|
12 | out float mag : TEXCOORD5, |
---|
13 | out float zValue : TEXCOORD6, |
---|
14 | uniform sampler3D vfield, |
---|
15 | uniform float currentTime, |
---|
16 | uniform float tanHalfFOV, |
---|
17 | uniform float4x4 modelview, |
---|
18 | uniform float4x4 projection, |
---|
19 | uniform float4x4 mvp) |
---|
20 | { |
---|
21 | float4 vec; |
---|
22 | vec.xyz = posin.xyz; |
---|
23 | vec.w = 1.0; |
---|
24 | |
---|
25 | float timeOfBirth = attr.x; |
---|
26 | float lifeTime = attr.y; |
---|
27 | //float index = attr.w; |
---|
28 | |
---|
29 | // length |
---|
30 | // the scale of from bottom to top |
---|
31 | float4 v = tex3D(vfield, vec.xyz); |
---|
32 | float3 velocity = v.yzw * 2 - float3(1, 1, 1); |
---|
33 | mag = v.x; |
---|
34 | |
---|
35 | // bottom to top |
---|
36 | // scale |
---|
37 | center.y = ((((int) (length(velocity.xyz) * 511)) / SUBIMAGE_SIZE_Y) * SUBIMAGE_SIZE_Y) / 512.0; |
---|
38 | //center.y = ((((int) (511)) / SUBIMAGE_SIZE_Y) * SUBIMAGE_SIZE_Y) / 512.0; |
---|
39 | |
---|
40 | velocity = mul(modelview, float4(velocity.x, velocity.y, velocity.z, 0.0)).xyz; |
---|
41 | if (length(velocity) != 0.0) |
---|
42 | velocity = normalize(velocity); |
---|
43 | |
---|
44 | float a = (asin(velocity.z) / 3.141592 + 1) * 0.5; |
---|
45 | center.x = ((((int) (a * 511)) / SUBIMAGE_SIZE_X) * SUBIMAGE_SIZE_X) / 512.0; |
---|
46 | |
---|
47 | if ((abs(velocity.x) == 0.0) && (abs(velocity.y) == 0.0)) { |
---|
48 | rotation.x = 1; |
---|
49 | rotation.y = 0; |
---|
50 | rotation.z = 0; |
---|
51 | rotation.w = 1; |
---|
52 | } else { |
---|
53 | float2 xy = normalize(velocity.xy); |
---|
54 | rotation.x = xy.x * 0.8; |
---|
55 | rotation.y = -xy.y * 0.8; |
---|
56 | rotation.z = xy.y * 0.8; |
---|
57 | rotation.w = xy.x * 0.8; |
---|
58 | } |
---|
59 | |
---|
60 | float4 posEye = mul(modelview, posin); |
---|
61 | #ifndef USE_J_WIRE |
---|
62 | pointSize = tanHalfFOV / -posEye.z / 5; |
---|
63 | #else |
---|
64 | pointSize = tanHalfFOV / -posEye.z / 10; |
---|
65 | #endif |
---|
66 | //pointSize = 10 / -posEye.z; |
---|
67 | zValue = posEye.z; |
---|
68 | posout = mul(mvp, vec); |
---|
69 | |
---|
70 | if ((currentTime > timeOfBirth) && (currentTime < (timeOfBirth + lifeTime))) skip = 0.0; |
---|
71 | else skip = 1.0; |
---|
72 | |
---|
73 | colout = colin; |
---|
74 | } |
---|
75 | |
---|