source: trunk/vizservers/nanovis/shaders/update_vel.cg @ 827

Last change on this file since 827 was 226, checked in by mmc, 18 years ago
  • Added code for Wei's visualization server.
  • Fixed the energyLevels widget so that it doesn't barf when the user attempts to download its contents.
File size: 1.7 KB
Line 
1/*
2 * ======================================================================
3 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
4 *           Purdue Rendering and Perceptualization Lab (PURPL)
5 *
6 *  Copyright (c) 2004-2006  Purdue Research Foundation
7 *
8 *  See the file "license.terms" for information on usage and
9 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10 * ======================================================================
11 */
12
13// update velocity based on acceleration
14
15#include "common.cg"
16
17float4 main(in float2 uv : TEXCOORD0,
18
19            uniform samplerRECT pos_tex,
20            uniform samplerRECT vel_tex,
21            uniform sampler2D terrain_tex,           
22           
23            uniform float timestep = 0.01,
24            uniform float damping = 0.99,
25            uniform float3 gravity = float3(0, -1, 0),
26            uniform float3 spherePos,
27            uniform float3 sphereVel           
28            ) : COLOR
29{
30    const float3 terrain_scale = float3(8.0, 2.0, 8.0);
31    const float3 terrain_offset = float3(-4.0, 0.01, -4.0);
32
33    float3 pos = texRECT(pos_tex, uv).xyz;
34    float3 vel = texRECT(vel_tex, uv).xyz;
35
36    float3 pos_next = pos + vel * timestep;  // predicted position next timestep
37
38    float3 force = gravity;
39//    float3 force = 0.0;
40//    Gravitation(pos, spherePos, force, 0.1);
41
42    SphereCollide(pos_next, vel, spherePos, 1.0, sphereVel, 0.5, force);
43//    FloorCollide(pos_next, vel, 0.0, 0.5, force);
44    TerrainCollide(pos_next, vel, terrain_tex, terrain_scale, terrain_offset, 0.5);
45   
46    const float inv_mass = 1.0;   
47    vel += force * inv_mass * timestep; // F = ma     
48    vel *= damping;
49
50    return float4(vel, 1.0);
51}
Note: See TracBrowser for help on using the repository browser.