source: nanovis/tags/1.1.1/shaders/velocityslicevp.cg

Last change on this file was 2964, checked in by ldelgass, 12 years ago

Convert arrow glyph shaders to new NvShader? API. Fix velocity arrow glpyh and
line implementation, add arrow head to line arrows. Alpha channel of arrow
texture atlas still needs cleanup -- should probably just create a utility to
generate the texture to allow changes in lighting, FOV, etc. Note that volumes
and flows are currently not scaled properly -- the aspect ratios of the number
of samples is used rather than the physical lengths of the volumes/flows. This will be fixed for volumes, flows and the grid in a future commit. Also, client doesn't currently enable arrows, this will also be enabled in another commit.

File size: 1.7 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
3#include "particle_common.cg"
4
5void vpmain(in float4 posin : POSITION,
6            in float4 colin : COLOR0,
7            out float4 posout : POSITION,
8            out float4 colout : COLOR0,
9            out float2 center : TEXCOORD2,
10            out float4 rotation : TEXCOORD3,
11            out float4 pointSize : PSIZE,
12            uniform sampler3D vfield : TEXUNIT1,
13            uniform float tanHalfFOV,
14            uniform float4x4 modelview,
15            uniform float4x4 mvp)
16{
17    float4 vec;
18    vec.xyz = posin.xyz;
19    vec.w = 1.0;
20
21    // length
22    // the scale of from bottom to top
23    float3 velocity = tex3D(vfield, vec.xyz).yzw * 2 - float3(1, 1, 1);
24
25    // bottom to top
26    // scale
27    center.y = ((((int) (length(velocity.xyz) * 511)) / SUBIMAGE_SIZE_Y) * SUBIMAGE_SIZE_Y) / 512.0;
28
29    velocity = mul(modelview, float4(velocity.x, velocity.y, velocity.z, 0.0)).xyz;
30    if (length(velocity) != 0.0)
31        velocity = normalize(velocity);
32
33    float a = (asin(velocity.z) / 3.141592 + 1) * 0.5;
34    center.x = ((((int) (a * 511)) / SUBIMAGE_SIZE_X) * SUBIMAGE_SIZE_X) / 512.0;
35
36    if ((abs(velocity.x) == 0.0) && (abs(velocity.y) == 0.0)) {
37        rotation.x = 1;
38        rotation.y = 0;
39        rotation.z = 0;
40        rotation.w = 1;
41    } else {
42        float2 xy = normalize(velocity.xy);
43        rotation.x = xy.x * 0.8;
44        rotation.y = -xy.y * 0.8;
45        rotation.z = xy.y * 0.8;
46        rotation.w = xy.x * 0.8;
47    }
48
49    float4 posEye =  mul(modelview, posin);
50    //pointSize = tanHalfFOV / -posEye.z / 5;
51    //pointSize = tanHalfFOV / -posEye.z / 10; //j-wire
52    pointSize = 20; //0 / -posEye.z;
53
54    posout = mul(mvp, vec);
55
56    colout = colin;
57}
Note: See TracBrowser for help on using the repository browser.