source: nanovis/trunk/shaders/update_pos.cg

Last change on this file was 5587, checked in by ldelgass, 5 years ago

Some fixes from release branch

File size: 1.3 KB
Line 
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// update positions based on velocity
10
11#include "common.cg"
12
13float4 main(in float2 uv : TEXCOORD0,
14            uniform samplerRECT pos_tex,
15            uniform samplerRECT init_pos_tex,
16            uniform sampler3D vel_tex,
17            uniform float timestep,
18            uniform float max,
19            uniform float3 scale) : COLOR
20{
21    float4 ret;
22    // get previous position
23    float4 pos = texRECT(pos_tex, uv);
24    float time = pos.w;
25
26    if (max > 0) {
27#ifdef EXPIRE
28        time -= timestep;
29
30        // Lifetime ended?
31        if (time < 0) {
32            return texRECT(init_pos_tex, uv);
33        }
34#endif
35        //reconstruct negative value
36        float4 vel = float4(tex3D(vel_tex, pos.xyz).yzw, 0.0) * 2.0 - float4(1.0, 1.0, 1.0, 0.0);
37        vel = vel * max;
38        //vel *= float4(scale, 1);
39        ret = pos + (vel * timestep);
40    } else {
41        ret = pos;
42    }
43
44    //not drawing if the particle is out of bound
45    if (ret.x < 0 || ret.x > 1 || ret.y < 0 || ret.y > 1 || ret.z < 0 || ret.z > 1) {
46        ret = texRECT(init_pos_tex, uv);
47    } else {
48        ret.w = time;
49    }
50
51    return ret;
52}
Note: See TracBrowser for help on using the repository browser.