source: nanovis/branches/1.1/shaders/update_pos_vel.cg @ 4883

Last change on this file since 4883 was 3177, checked in by mmc, 12 years ago

Updated all of the copyright notices to reference the transfer to
the new HUBzero Foundation, LLC.

File size: 2.0 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * ======================================================================
4 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
5 *           Purdue Rendering and Perceptualization Lab (PURPL)
6 *
7 *  Copyright (c) 2004-2012  HUBzero Foundation, LLC
8 *
9 *  See the file "license.terms" for information on usage and
10 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 * ======================================================================
12 */
13
14// update velocity and position in a single pass using MRT
15
16#include "common.cg"
17
18void main(in float2 uv : TEXCOORD0,
19          uniform samplerRECT pos_tex,
20          uniform samplerRECT vel_tex,
21          uniform sampler2D terrain_tex,
22          uniform float timestep = 0.01,
23          uniform float damping = 0.99,
24          uniform float3 gravity = float3(0, -1, 0),
25          uniform float3 spherePos,
26          uniform float3 sphereVel,
27          out float4 new_pos : COLOR0,
28          out float4 new_vel : COLOR1)
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    // update velocity
39    float3 force = gravity;
40    // float3 force = 0.0;
41    // Gravitation(pos, spherePos, force, 0.1);
42
43    SphereCollide(pos_next, vel, spherePos, 1.0, sphereVel, 0.5, force);
44    // FloorCollide(pos_next, vel, 0.0, 0.5, force);   
45    TerrainCollide(pos_next, vel, terrain_tex, terrain_scale, terrain_offset, 0.5);
46
47    const float inv_mass = 1.0;   
48    vel += force * inv_mass * timestep; // F = ma     
49    vel *= damping;
50
51    // update position
52    SphereConstraint(pos, spherePos, 1.0f);
53    // FloorConstraint(pos, 0.0f);
54    TerrainConstraint(pos, terrain_tex, terrain_scale, terrain_offset);
55
56    pos += vel * timestep;
57
58    new_vel = float4(vel, 1);
59    new_pos = float4(pos, 1);
60}
Note: See TracBrowser for help on using the repository browser.