1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
2 | |
---|
3 | #include "particle_common.cg" |
---|
4 | |
---|
5 | void vpmain(in float4 posin : POSITION, |
---|
6 | in float4 colin : COLOR0, |
---|
7 | out float4 posout : POSITION, |
---|
8 | out float4 colout : COLOR0, |
---|
9 | out float2 center : TEXCOORD2, |
---|
10 | out float4 rotation : TEXCOORD3, |
---|
11 | out float4 pointSize : PSIZE, |
---|
12 | uniform sampler3D vfield : TEXUNIT1, |
---|
13 | uniform float tanHalfFOV, |
---|
14 | uniform float4x4 modelview, |
---|
15 | uniform float4x4 mvp) |
---|
16 | { |
---|
17 | float4 vec; |
---|
18 | vec.xyz = posin.xyz; |
---|
19 | vec.w = 1.0; |
---|
20 | |
---|
21 | // length |
---|
22 | // the scale of from bottom to top |
---|
23 | float3 velocity = tex3D(vfield, vec.xyz).yzw * 2 - float3(1, 1, 1); |
---|
24 | |
---|
25 | // bottom to top |
---|
26 | // scale |
---|
27 | center.y = ((((int) (length(velocity.xyz) * 511)) / SUBIMAGE_SIZE_Y) * SUBIMAGE_SIZE_Y) / 512.0; |
---|
28 | |
---|
29 | velocity = mul(modelview, float4(velocity.x, velocity.y, velocity.z, 0.0)).xyz; |
---|
30 | if (length(velocity) != 0.0) |
---|
31 | velocity = normalize(velocity); |
---|
32 | |
---|
33 | float a = (asin(velocity.z) / 3.141592 + 1) * 0.5; |
---|
34 | center.x = ((((int) (a * 511)) / SUBIMAGE_SIZE_X) * SUBIMAGE_SIZE_X) / 512.0; |
---|
35 | |
---|
36 | if ((abs(velocity.x) == 0.0) && (abs(velocity.y) == 0.0)) { |
---|
37 | rotation.x = 1; |
---|
38 | rotation.y = 0; |
---|
39 | rotation.z = 0; |
---|
40 | rotation.w = 1; |
---|
41 | } else { |
---|
42 | float2 xy = normalize(velocity.xy); |
---|
43 | rotation.x = xy.x * 0.8; |
---|
44 | rotation.y = -xy.y * 0.8; |
---|
45 | rotation.z = xy.y * 0.8; |
---|
46 | rotation.w = xy.x * 0.8; |
---|
47 | } |
---|
48 | |
---|
49 | float4 posEye = mul(modelview, posin); |
---|
50 | //pointSize = tanHalfFOV / -posEye.z / 5; |
---|
51 | //pointSize = tanHalfFOV / -posEye.z / 10; //j-wire |
---|
52 | pointSize = 20; //0 / -posEye.z; |
---|
53 | |
---|
54 | posout = mul(mvp, vec); |
---|
55 | |
---|
56 | colout = colin; |
---|
57 | } |
---|