/* * ====================================================================== * AUTHOR: Wei Qiao * Purdue Rendering and Perceptualization Lab (PURPL) * * Copyright (c) 2004-2006 Purdue Research Foundation * * See the file "license.terms" for information on usage and * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. * ====================================================================== */ // update velocity and position in a single pass using MRT #include "common.cg" void main(in float2 uv : TEXCOORD0, uniform samplerRECT pos_tex, uniform samplerRECT vel_tex, uniform sampler2D terrain_tex, uniform float timestep = 0.01, uniform float damping = 0.99, uniform float3 gravity = float3(0, -1, 0), uniform float3 spherePos, uniform float3 sphereVel, out float4 new_pos : COLOR0, out float4 new_vel : COLOR1 ) { const float3 terrain_scale = float3(8.0, 2.0, 8.0); const float3 terrain_offset = float3(-4.0, 0.01, -4.0); float3 pos = texRECT(pos_tex, uv).xyz; float3 vel = texRECT(vel_tex, uv).xyz; float3 pos_next = pos + vel * timestep; // predicted position next timestep // update velocity float3 force = gravity; // float3 force = 0.0; // Gravitation(pos, spherePos, force, 0.1); SphereCollide(pos_next, vel, spherePos, 1.0, sphereVel, 0.5, force); // FloorCollide(pos_next, vel, 0.0, 0.5, force); TerrainCollide(pos_next, vel, terrain_tex, terrain_scale, terrain_offset, 0.5); const float inv_mass = 1.0; vel += force * inv_mass * timestep; // F = ma vel *= damping; // update position SphereConstraint(pos, spherePos, 1.0f); // FloorConstraint(pos, 0.0f); TerrainConstraint(pos, terrain_tex, terrain_scale, terrain_offset); pos += vel * timestep; new_vel = float4(vel, 1); new_pos = float4(pos, 1); }