/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ #include "particle_common.cg" void vpmain(in float4 posin : POSITION, in float4 colin : COLOR0, in float4 attr : TEXCOORD0, inout float pointSize : PSIZE, out float4 posout : POSITION, out float4 colout : COLOR0, out float2 center : TEXCOORD2, out float4 rotation : TEXCOORD3, out float skip : TEXCOORD4, out float mag : TEXCOORD5, out float zValue : TEXCOORD6, uniform sampler3D vfield, uniform float currentTime, uniform float tanHalfFOV, uniform float4x4 modelview, uniform float4x4 projection, uniform float4x4 mvp) { float4 vec; vec.xyz = posin.xyz; vec.w = 1.0; float timeOfBirth = attr.x; float lifeTime = attr.y; //float index = attr.w; // length // the scale of from bottom to top float4 v = tex3D(vfield, vec.xyz); float3 velocity = v.yzw * 2 - float3(1, 1, 1); mag = v.x; // bottom to top // scale center.y = ((((int) (length(velocity.xyz) * 511)) / SUBIMAGE_SIZE_Y) * SUBIMAGE_SIZE_Y) / 512.0; //center.y = ((((int) (511)) / SUBIMAGE_SIZE_Y) * SUBIMAGE_SIZE_Y) / 512.0; velocity = mul(modelview, float4(velocity.x, velocity.y, velocity.z, 0.0)).xyz; if (length(velocity) != 0.0) velocity = normalize(velocity); float a = (asin(velocity.z) / 3.141592 + 1) * 0.5; center.x = ((((int) (a * 511)) / SUBIMAGE_SIZE_X) * SUBIMAGE_SIZE_X) / 512.0; if ((abs(velocity.x) == 0.0) && (abs(velocity.y) == 0.0)) { rotation.x = 1; rotation.y = 0; rotation.z = 0; rotation.w = 1; } else { float2 xy = normalize(velocity.xy); rotation.x = xy.x * 0.8; rotation.y = -xy.y * 0.8; rotation.z = xy.y * 0.8; rotation.w = xy.x * 0.8; } float4 posEye = mul(modelview, posin); #ifndef USE_J_WIRE pointSize = tanHalfFOV / -posEye.z / 5; #else pointSize = tanHalfFOV / -posEye.z / 10; #endif //pointSize = 10 / -posEye.z; zValue = posEye.z; posout = mul(mvp, vec); if ((currentTime > timeOfBirth) && (currentTime < (timeOfBirth + lifeTime))) skip = 0.0; else skip = 1.0; colout = colin; }