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