source: nanovis/trunk/shaders/velocity.cg @ 4880

Last change on this file since 4880 was 2877, checked in by ldelgass, 8 years ago

Some minor refactoring, also add some more fine grained config.h defines
(e.g. replace NV40 define with feature defines). Add tests for some required
OpenGL extensions (should always check for extensions or base version before
calling entry points from the extension). Also, clamp diffuse and specular
values on input and warn when they are out of range.

File size: 3.9 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2// Copyright (c) 2004-2005 Lutz Latta
3//
4// Permission is hereby granted, free of charge, to any person obtaining
5// a copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included
12// in all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22// Velocity change operations.
23//#include "velocityOps.cg"
24
25// Uniform parameters influencing velocity.
26uniform float3 _SphereCenter;
27uniform samplerRECT _TerrainTexture : register(s2);
28uniform samplerRECT _FlowFieldTexture : register(s3);
29uniform float3 _LocalAttractorPosition[4];
30
31float3 advanceVelocity(float3 _Velocity, float3 _Position, float _TimeStep)
32{
33    float3 gravity = float3(0, -.01, 0);
34
35    float3 acceleration = gravity;
36
37    //acceleration +=
38    //    localAttractor(_Position,
39    //                   getClosestPointOnLine(_LocalAttractorPosition[0],
40    //                                         _LocalAttractorPosition[1], _Position), 0.05, 0.2);
41    //acceleration += localAttractor(_Position, _LocalAttractorPosition[0], 0.02, 0.4);
42    //acceleration += localAttractor(_Position, _LocalAttractorPosition[1], 0.02, 0.02);
43    //acceleration += localRepulsor(_Position, _LocalAttractorPosition[2], 0.02, 0.1);
44    //acceleration += localRepulsor(_Position, _LocalAttractorPosition[3], 0.02, 0.1);
45    //acceleration += flowFieldVector(_Position, _FlowFieldTexture, float2(512, 512),
46    //                                float3(4, 4, 4), float3(256, 0, 256), 0.01);
47
48    float3 velocity = _Velocity + _TimeStep * acceleration;
49
50    //velocity = lerp(velocity, flowFieldVector(_Position, _FlowFieldTexture, float2(512, 512),
51    //                                          float3(4, 4, 4), float3(256, 0, 256), 1), 0.2);
52    //velocity = length(velocity) * normalize(flowFieldVector(_Position, _FlowFieldTexture, float2(512, 512),
53    //                                                        float3(4, 4, 4), float3(256, 0, 256), 1));
54
55    //spiral(velocity, _TimeStep, normalize(_LocalAttractorPosition[0] - _LocalAttractorPosition[1]), .3);
56
57    //dampen(velocity, 1.1);
58    //undampen(velocity, 1.01);
59
60    floorConstraint(velocity, _Position, 0, 0.4, 0.1, 0.01);
61    sphereConstraint(velocity, _Position, _SphereCenter, 1, 0.3, 0.7, 0.01);
62    //terrainConstraint(velocity, _Position, _TerrainTexture, float2(128, 128),
63    //                  float3(4, 4, 4), float3(64, 0, 64), 0.02, 0.7, 0.01);
64
65    return velocity;
66}
67
68float4 main(float2 _TexCoord : TEXCOORD0,
69            uniform samplerRECT _VelocityTexture : register(s0),
70            uniform samplerRECT _PositionTexture : register(s1),
71            uniform float _TimeStep) : COLOR
72{
73    float3 velocity = (float3)texRECT(_VelocityTexture, _TexCoord);
74    float3 position = (float3)texRECT(_PositionTexture, _TexCoord);
75
76    return float4(advanceVelocity(velocity, position, _TimeStep), 0);
77}
78
79float4 mainInitialization(float3 _VelocityInit : TEXCOORD0,
80                          float3 _PositionInit : TEXCOORD1,
81                          float _TimeStep : TEXCOORD2) : COLOR
82{
83    return float4(advanceVelocity(_VelocityInit, _PositionInit, _TimeStep), 0);
84}
Note: See TracBrowser for help on using the repository browser.