Ignore:
Timestamp:
Mar 13, 2012 10:54:40 PM (12 years ago)
Author:
ldelgass
Message:

Fix up line endings and formatting in shader code, also add emacs magic line
to get C++ mode highlighting

Location:
trunk/packages/vizservers/nanovis/shaders
Files:
27 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/nanovis/shaders/common.cg

    r392 r2852  
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    12/*
    23 * ======================================================================
     
    3031
    3132// constrain particle to heightfield stored in texture
    32 void TerrainConstraint(inout float3 pos, uniform sampler2D terrain_tex, float3 scale, float3 offset)
     33void TerrainConstraint(inout float3 pos, uniform sampler2D terrain_tex,
     34                       float3 scale, float3 offset)
    3335{
    3436    float2 uv = (pos.xz - offset.xz) / scale.xz;
     
    3941}
    4042
    41 void SphereCollide(inout float3 x, inout float3 vel, float3 center, float r, float3 sphere_vel, float friction, inout float3 force)
     43void SphereCollide(inout float3 x, inout float3 vel, float3 center, float r,
     44                   float3 sphere_vel, float friction, inout float3 force)
    4245{
    4346    float3 delta = x - center;
    4447    float dist = length(delta);
    4548    if (dist < r) {
    46 //      x = center + delta*(r / dist);   
    47       vel += (delta / dist) * friction;
    48       vel += sphere_vel;
     49        // x = center + delta*(r / dist);   
     50        vel += (delta / dist) * friction;
     51        vel += sphere_vel;
    4952    }
    5053}
    5154
    52 void FloorCollide(inout float3 x, inout float3 vel, float level, float friction, inout float3 force)
     55void FloorCollide(inout float3 x, inout float3 vel, float level,
     56                  float friction, inout float3 force)
    5357{
    5458    if (x.y < level) {
    55 //        x.y = level;
    56 //        force.y += -vel.y*friction;
     59        // x.y = level;
     60        // force.y += -vel.y*friction;
    5761        vel.y += -vel.y*friction;
    5862    }
     
    6165void Gravitation(float3 pos, float3 mass_pos, inout float3 force, float epsilon)
    6266{
    63   float3 delta = mass_pos - pos;
    64   float dist = length(delta);
    65   float3 dir = delta / dist;
    66   force += dir * (1.0 / (epsilon + dist*dist));
     67    float3 delta = mass_pos - pos;
     68    float dist = length(delta);
     69    float3 dir = delta / dist;
     70    force += dir * (1.0 / (epsilon + dist*dist));
    6771}
    6872
    69 void TerrainCollide(float3 pos, inout float3 vel, uniform sampler2D terrain_tex, float3 scale, float3 offset, float friction)
     73void TerrainCollide(float3 pos, inout float3 vel, uniform sampler2D terrain_tex,
     74                    float3 scale, float3 offset, float friction)
    7075{
    7176    const float2 texelSize = float2( 1.0 / 256.0, 1.0 / 256.0 );
     
    7782        float h1 = tex2D(terrain_tex, uv + texelSize*float2(1, 0) ).r;
    7883        float h2 = tex2D(terrain_tex, uv + texelSize*float2(0, 1) ).r;
    79         float3 N = cross( float3(scale.x*texelSize.x, (h1-h0)*scale.y, 0), float3(0, (h2-h0)*scale.y, scale.z*texelSize.y) );
     84        float3 N = cross(float3(scale.x*texelSize.x, (h1-h0)*scale.y, 0),
     85                         float3(0, (h2-h0)*scale.y, scale.z*texelSize.y));
    8086        N = normalize(N);
    8187        vel = reflect(vel, N);
     
    8692struct a2v
    8793{
    88   //For semantics, see pages 230-240 of Cg_Toolkit.pdf
    89   float4 Position :     POSITION;
    90   float4 TexCoord :     TEXCOORD0;
     94    //For semantics, see pages 230-240 of Cg_Toolkit.pdf
     95    float4 Position : POSITION;
     96    float4 TexCoord : TEXCOORD0;
    9197};
    9298
    9399struct v2f
    94100{
    95   float4 HPosition              : HPOS;         //Clip space pos. Not readable in frag prog
    96   float4 TexCoord               : TEXCOORD0;
    97   float3 EyeVector              : TEXCOORD1;    //world space eye vector
    98   float3 Light                  : TEXCOORD2;    //world space light vector
     101    float4 HPosition: HPOS;             //Clip space pos. Not readable in frag prog
     102    float4 TexCoord : TEXCOORD0;
     103    float3 EyeVector: TEXCOORD1;        //world space eye vector
     104    float3 Light    : TEXCOORD2;    //world space light vector
    99105};
    100106
    101107struct PixelOut {
    102   float4 Color: COLOR0;
    103   //float Depth:        DEPTH;
     108    float4 Color:       COLOR0;
     109    //float Depth:      DEPTH;
    104110};
    105 
  • trunk/packages/vizservers/nanovis/shaders/copy_texcoord.cg

    r226 r2852  
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    12/*
    23 * ======================================================================
  • trunk/packages/vizservers/nanovis/shaders/distance.cg

    r1702 r2852  
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    12// Copyright (c) 2004-2005 Lutz Latta
    23//
     
    3031float2 initSortIndex(float2 sortIndex : TEXCOORD0) : COLOR
    3132{
    32         // TBD...
    33         return float2(0, pack_2half(sortIndex));
    34         //return float2(sortIndex.x, sortIndex.y);
     33    // TBD...
     34    return float2(0, pack_2half(sortIndex));
     35    //return float2(sortIndex.x, sortIndex.y);
    3536}
    3637
    3738float2 computeDistance(float2 texCoord : TEXCOORD0,
    38         uniform samplerRECT sortTexture : register(s0),
    39         uniform samplerRECT positionTexture : register(s1),
    40         uniform float3 viewerPosition
    41 ) : COLOR
     39                       uniform samplerRECT sortTexture : register(s0),
     40                       uniform samplerRECT positionTexture : register(s1),
     41                       uniform float3 viewerPosition) : COLOR
    4242{
    43         float sortIndex = texRECT(sortTexture, texCoord.xy).y;
    44         half2 particleIndex = unpack_2half(sortIndex);
     43    float sortIndex = texRECT(sortTexture, texCoord.xy).y;
     44    half2 particleIndex = unpack_2half(sortIndex);
    4545
    46         float3 particlePos = (float3)texRECT(positionTexture, particleIndex);
     46    float3 particlePos = (float3)texRECT(positionTexture, particleIndex);
    4747       
    48         float3 delta = viewerPosition - particlePos;
    49         float distanceSqr = dot(delta, delta);
     48    float3 delta = viewerPosition - particlePos;
     49    float distanceSqr = dot(delta, delta);
    5050
    51         // Prevent unused, far-away particles from destroying comparisons in sorting.
    52         if (distanceSqr > 1e6 || isnan(distanceSqr))
    53                 distanceSqr = 1e6;
     51    // Prevent unused, far-away particles from destroying comparisons in sorting.
     52    if (distanceSqr > 1e6 || isnan(distanceSqr))
     53        distanceSqr = 1e6;
    5454
    55         return float2(distanceSqr, sortIndex);
     55    return float2(distanceSqr, sortIndex);
    5656}
    5757float4 lookupPosition(float2 texCoord : TEXCOORD0,
    58         uniform samplerRECT sortTexture : register(s0),
    59         uniform samplerRECT positionTexture : register(s1)
    60 ) : COLOR
     58                      uniform samplerRECT sortTexture : register(s0),
     59                      uniform samplerRECT positionTexture : register(s1)) : COLOR
    6160{
    62         float sortIndex = texRECT(sortTexture, texCoord.xy).y;
    63         half2 particleIndex = unpack_2half(sortIndex);
    64         float4 particlePos = (float4)texRECT(positionTexture, particleIndex);
     61    float sortIndex = texRECT(sortTexture, texCoord.xy).y;
     62    half2 particleIndex = unpack_2half(sortIndex);
     63    float4 particlePos = (float4)texRECT(positionTexture, particleIndex);
    6564
    66         return particlePos;
     65    return particlePos;
    6766}
    6867
     
    7069float3 initSortIndex(float2 sortIndex : TEXCOORD0) : COLOR
    7170{
    72         //return float3(0, sortIndex.x, sortIndex.y);
    73         return float3(1e6, sortIndex.x, sortIndex.y);
     71    //return float3(0, sortIndex.x, sortIndex.y);
     72    return float3(1e6, sortIndex.x, sortIndex.y);
    7473}
    7574
    7675float3 computeDistance(float2 texCoord : TEXCOORD0,
    77         uniform samplerRECT sortTexture : register(s0),
    78         uniform samplerRECT positionTexture : register(s1),
    79         uniform float3 viewerPosition
    80 ) : COLOR
     76                       uniform samplerRECT sortTexture : register(s0),
     77                       uniform samplerRECT positionTexture : register(s1),
     78                       uniform float3 viewerPosition) : COLOR
    8179{
    82         float2 particleIndex = texRECT(sortTexture, texCoord.xy).yz;
    83         float3 particlePos = texRECT(positionTexture, particleIndex).xyz;
     80    float2 particleIndex = texRECT(sortTexture, texCoord.xy).yz;
     81    float3 particlePos = texRECT(positionTexture, particleIndex).xyz;
    8482
    85         float3 delta = viewerPosition - particlePos;
    86         float distanceSqr = dot(delta, delta);
     83    float3 delta = viewerPosition - particlePos;
     84    float distanceSqr = dot(delta, delta);
    8785
    88         // Prevent unused, far-away particles from destroying comparisons in sorting.
    89         if (distanceSqr > 1e6 || isnan(distanceSqr))
    90                 distanceSqr = 1e6;
     86    // Prevent unused, far-away particles from destroying comparisons in sorting.
     87    if (distanceSqr > 1e6 || isnan(distanceSqr))
     88        distanceSqr = 1e6;
    9189
    92         return float3(distanceSqr, particleIndex.x, particleIndex.y);
     90    return float3(distanceSqr, particleIndex.x, particleIndex.y);
    9391}
    9492
    9593float3 lookupPosition(float2 texCoord : TEXCOORD0,
    96         uniform samplerRECT sortTexture : register(s0),
    97         uniform samplerRECT positionTexture : register(s1)
    98 ) : COLOR
     94                      uniform samplerRECT sortTexture : register(s0),
     95                      uniform samplerRECT positionTexture : register(s1)) : COLOR
    9996{
    100         float2 particleIndex = texRECT(sortTexture, texCoord.xy).yz;
    101         float3 particlePos = texRECT(positionTexture, particleIndex).xyz;
     97    float2 particleIndex = texRECT(sortTexture, texCoord.xy).yz;
     98    float3 particlePos = texRECT(positionTexture, particleIndex).xyz;
    10299
    103         return particlePos;
     100    return particlePos;
    104101}
    105102#endif
  • trunk/packages/vizservers/nanovis/shaders/distancesort.cg

    r1702 r2852  
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    12// Copyright (c) 2004-2005 Lutz Latta
    23//
     
    2930float2 initSortIndex(float2 _SortIndex : TEXCOORD0) : COLOR
    3031{
    31         return float2(0, pack_2half(_SortIndex));
     32    return float2(0, pack_2half(_SortIndex));
    3233}
    3334
    3435float2 computeDistance(float2 _TexCoord : TEXCOORD0,
    35         uniform samplerRECT _SortTexture : register(s0),
    36         uniform samplerRECT _PositionTexture : register(s1),
    37         uniform float3 _ViewerPosition
    38 ) : COLOR
     36                       uniform samplerRECT _SortTexture : register(s0),
     37                       uniform samplerRECT _PositionTexture : register(s1),
     38                       uniform float3 _ViewerPosition) : COLOR
    3939{
    40         float sortIndex = texRECT(_SortTexture, _TexCoord.xy).y;
    41         half2 particleIndex = unpack_2half(sortIndex);
     40    float sortIndex = texRECT(_SortTexture, _TexCoord.xy).y;
     41    half2 particleIndex = unpack_2half(sortIndex);
    4242
    43         float3 particlePos = (float3)texRECT(_PositionTexture, particleIndex);
     43    float3 particlePos = (float3)texRECT(_PositionTexture, particleIndex);
    4444
    45         float3 delta = _ViewerPosition - particlePos;
    46         float distanceSqr = dot(delta, delta);
     45    float3 delta = _ViewerPosition - particlePos;
     46    float distanceSqr = dot(delta, delta);
    4747
    48         // Prevent unused, far-away particles from destroying comparisons in sorting.
    49         if (distanceSqr > 1e6 || isnan(distanceSqr))
    50                 distanceSqr = 1e6;
     48    // Prevent unused, far-away particles from destroying comparisons in sorting.
     49    if (distanceSqr > 1e6 || isnan(distanceSqr))
     50        distanceSqr = 1e6;
    5151
    52         return float2(distanceSqr, sortIndex);
     52    return float2(distanceSqr, sortIndex);
    5353}
    5454
    5555float4 lookupPosition(float2 _TexCoord : TEXCOORD0,
    56         uniform samplerRECT _SortTexture : register(s0),
    57         uniform samplerRECT _PositionTexture : register(s1)
    58 ) : COLOR
     56                      uniform samplerRECT _SortTexture : register(s0),
     57                      uniform samplerRECT _PositionTexture : register(s1)) : COLOR
    5958{
    60         float sortIndex = texRECT(_SortTexture, _TexCoord.xy).y;
    61         half2 particleIndex = unpack_2half(sortIndex);
    62         float4 particlePos = (float4)texRECT(_PositionTexture, particleIndex);
     59    float sortIndex = texRECT(_SortTexture, _TexCoord.xy).y;
     60    half2 particleIndex = unpack_2half(sortIndex);
     61    float4 particlePos = (float4)texRECT(_PositionTexture, particleIndex);
    6362
    64         return particlePos;
     63    return particlePos;
    6564}
  • trunk/packages/vizservers/nanovis/shaders/heightcolor.cg

    r1546 r2852  
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    12
    2 float4 main(
    3     float4 texCoord : TEXCOORD0,
    4     uniform float opacity,
    5     uniform sampler1D tf) : COLOR
     3float4 main(float4 texCoord : TEXCOORD0,
     4            uniform float opacity,
     5            uniform sampler1D tf) : COLOR
    66{
    77    float4 color = tex1D(tf, texCoord.z);
  • trunk/packages/vizservers/nanovis/shaders/mergesort.cg

    r1702 r2852  
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    12// Copyright (c) 2004-2005 Lutz Latta
    23//
     
    2728float3
    2829#endif
    29 mergeSortEnd(
    30         float2 current : TEXCOORD0,
    31         uniform samplerRECT sortData : register(s0),
    32         uniform int2 size,
    33         uniform int step
    34 ) : COLOR
     30mergeSortEnd(float2 current : TEXCOORD0,
     31             uniform samplerRECT sortData : register(s0),
     32             uniform int2 size,
     33             uniform int step) : COLOR
    3534{
    3635#ifndef USE_RGB_FORMAT
    37         float2 currentSample = texRECT(sortData, (float2)current).xy;
     36    float2 currentSample = texRECT(sortData, (float2)current).xy;
    3837#else
    39         float3 currentSample = texRECT(sortData, (float2)current).xyz;
     38    float3 currentSample = texRECT(sortData, (float2)current).xyz;
    4039#endif
    4140
    42         float i = (current.y - 0.5) * size.x + current.x;
    43         //float i = current.y * size.x + current.x;
     41    float i = (current.y - 0.5) * size.x + current.x;
     42    //float i = current.y * size.x + current.x;
    4443
    45         // swap direction
    46         float b = (fmod(i / step, 2.0) < 1.0 ? 1.0 : -1.0);
     44    // swap direction
     45    float b = (fmod(i / step, 2.0) < 1.0 ? 1.0 : -1.0);
    4746
    4847       
    49         float otherI = i + (b * step);
    50         float2 otherPos = float2(fmod(otherI, size.x), floor(otherI / size.x) + 0.5);
    51         //float2 otherPos = float2(fmod(otherI, size.x), floor(otherI / size.x));
     48    float otherI = i + (b * step);
     49    float2 otherPos = float2(fmod(otherI, size.x), floor(otherI / size.x) + 0.5);
     50    //float2 otherPos = float2(fmod(otherI, size.x), floor(otherI / size.x));
    5251#ifndef USE_RGB_FORMAT
    53         float2 otherSample = texRECT(sortData, otherPos).xy;
     52    float2 otherSample = texRECT(sortData, otherPos).xy;
    5453#else
    55         float3 otherSample = texRECT(sortData, otherPos).xyz;
     54    float3 otherSample = texRECT(sortData, otherPos).xyz;
    5655#endif
    57         if (b >= 0)
    58         {
    59                 return currentSample.x > otherSample.x ? currentSample : otherSample;
    60         }
    61         else
    62         {
    63                 return currentSample.x < otherSample.x ? currentSample : otherSample;
    64         }
     56    if (b >= 0) {
     57        return currentSample.x > otherSample.x ? currentSample : otherSample;
     58    } else {
     59        return currentSample.x < otherSample.x ? currentSample : otherSample;
     60    }
    6561}
    6662#ifndef USE_RGB_FORMAT
     
    6965float3
    7066#endif
    71 mergeSortRecursion(
    72         float2 _Current : TEXCOORD0,
    73         uniform samplerRECT _SortData : register(s0),
    74         uniform int2 _Size,
    75         uniform int _Step,
    76         uniform int _Count
    77 ) : COLOR
     67mergeSortRecursion(float2 _Current : TEXCOORD0,
     68                   uniform samplerRECT _SortData : register(s0),
     69                   uniform int2 _Size,
     70                   uniform int _Step,
     71                   uniform int _Count) : COLOR
    7872{
    7973#ifndef USE_RGB_FORMAT
    80         float2 currentSample = texRECT(_SortData, (float2)_Current).xy;
     74    float2 currentSample = texRECT(_SortData, (float2)_Current).xy;
    8175#else
    82         float3 currentSample = texRECT(_SortData, (float2)_Current).xyz;
     76    float3 currentSample = texRECT(_SortData, (float2)_Current).xyz;
    8377#endif
    84         float i = (_Current.y - 0.5) * _Size.x + _Current.x;
    85         //float i = _Current.y * _Size.x + _Current.x;
     78    float i = (_Current.y - 0.5) * _Size.x + _Current.x;
     79    //float i = _Current.y * _Size.x + _Current.x;
    8680
    87         float iMod = fmod((float)(i / _Step), (float)_Count);
     81    float iMod = fmod((float)(i / _Step), (float)_Count);
    8882
    89         if (iMod >= 1.0 && iMod < _Count - 1.0)
    90         {
    91                 float b = (fmod((float)iMod, 2.0) > 1.0 ? 1.0 : -1.0);
     83    if (iMod >= 1.0 && iMod < _Count - 1.0) {
     84        float b = (fmod((float)iMod, 2.0) > 1.0 ? 1.0 : -1.0);
    9285
    93                 float otherI = i + (b * _Step);
    94                 float2 otherPos = float2(fmod(otherI, _Size.x), floor(otherI / _Size.x) + 0.5);
    95                 //float2 otherPos = float2(fmod(otherI, _Size.x), floor(otherI / _Size.x));
     86        float otherI = i + (b * _Step);
     87        float2 otherPos = float2(fmod(otherI, _Size.x), floor(otherI / _Size.x) + 0.5);
     88        //float2 otherPos = float2(fmod(otherI, _Size.x), floor(otherI / _Size.x));
    9689
    9790#ifndef USE_RGB_FORMAT 
    98                 float2 otherSample = texRECT(_SortData, otherPos).xy;
     91        float2 otherSample = texRECT(_SortData, otherPos).xy;
    9992#else
    100                 float3 otherSample = texRECT(_SortData, otherPos).xyz;
     93        float3 otherSample = texRECT(_SortData, otherPos).xyz;
    10194#endif
    102                 if (b >= 0)
    103                 {
    104                         return currentSample.x > otherSample.x ? currentSample : otherSample;
    105                 }
    106                 else
    107                 {
    108                         return currentSample.x < otherSample.x ? currentSample : otherSample;
    109                 }
    110         }
    111         else
    112                 return currentSample;
     95        if (b >= 0) {
     96            return currentSample.x > otherSample.x ? currentSample : otherSample;
     97        } else {
     98            return currentSample.x < otherSample.x ? currentSample : otherSample;
     99        }
     100    } else
     101        return currentSample;
    113102}
  • trunk/packages/vizservers/nanovis/shaders/moveparticles.cg

    r1702 r2852  
    1 float4 main
    2 (
    3         float2 texCoord : TEXCOORD0,
    4         uniform samplerRECT posTexture : register(s0),
    5         uniform samplerRECT initTexture : register(s1),
    6         uniform sampler3D vfield,
    7         uniform float3 scale,
    8         uniform float maxScale,
    9         uniform float useInitPos,
    10         uniform float timeStep,
    11         uniform float currentTime
    12 ) : COLOR
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
     2float4 main (float2 texCoord : TEXCOORD0,
     3             uniform samplerRECT posTexture : register(s0),
     4             uniform samplerRECT initTexture : register(s1),
     5             uniform sampler3D vfield,
     6             uniform float3 scale,
     7             uniform float maxScale,
     8             uniform float useInitPos,
     9             uniform float timeStep,
     10             uniform float currentTime) : COLOR
    1311{
    14         if (maxScale > 100) maxScale = 100;
     12    if (maxScale > 100) maxScale = 100;
    1513
    16         float3 oldPosition = f3texRECT(posTexture, texCoord);
    17         float3 velocity = tex3D(vfield, oldPosition).yzw - float3(0.5, 0.5, 0.5);
    18         velocity = velocity * (2 * maxScale);
    19         velocity = velocity * scale;
     14    float3 oldPosition = f3texRECT(posTexture, texCoord);
     15    float3 velocity = tex3D(vfield, oldPosition).yzw - float3(0.5, 0.5, 0.5);
     16    velocity = velocity * (2 * maxScale);
     17    velocity = velocity * scale;
    2018       
    21         float3 position = oldPosition + velocity * timeStep * 0.01;
    22         //float3 position = oldPosition;
     19    float3 position = oldPosition + velocity * timeStep * 0.01;
     20    //float3 position = oldPosition;
    2321
    24         //if (useInitPos)
    25         {
    26                 if ((position.x < 0) || (position.x > 1) ||
    27                         (position.y < 0) || (position.y > 1) ||
    28                         (position.z < 0) || (position.z > 1))
    29                 {
    30                         position = f3texRECT(initTexture, texCoord);
    31                 }
    32         }
     22    //if (useInitPos) {
     23        if ((position.x < 0) || (position.x > 1) ||
     24            (position.y < 0) || (position.y > 1) ||
     25            (position.z < 0) || (position.z > 1)) {
     26            position = f3texRECT(initTexture, texCoord);
     27        }
     28    //}
    3329
    34         return float4(position, 1);
     30    return float4(position, 1);
    3531}
    3632
    37 float4 initParticlePosMain
    38 (
    39         float3 initPos : TEXCOORD0,
    40         float2 texCoord : TEXCOORD1,
    41         float timeStep : TEXCOORD2,
    42         uniform sampler3D vfield
    43 ) : COLOR
     33float4 initParticlePosMain(float3 initPos : TEXCOORD0,
     34                           float2 texCoord : TEXCOORD1,
     35                           float timeStep : TEXCOORD2,
     36                           uniform sampler3D vfield) : COLOR
    4437{
    45         float3 oldPosition = initPos;
    46         //float3 velocity = tex3D(vfield, oldPosition).yzw * 2 - float3(1, 1, 1);
    47         //float3 position = oldPosition + timeStep * velocity;
    48         //return float4(position, 1);
    49         return float4(initPos, 1);
     38    float3 oldPosition = initPos;
     39    //float3 velocity = tex3D(vfield, oldPosition).yzw * 2 - float3(1, 1, 1);
     40    //float3 position = oldPosition + timeStep * velocity;
     41    //return float4(position, 1);
     42    return float4(initPos, 1);
    5043}
    5144
    52 float4 mainlines
    53 (
    54         float2 texCoord : TEXCOORD0,
    55         uniform samplerRECT posTexture : register(s0),
    56         uniform sampler3D vfield,
    57         uniform float2 offset,
    58         uniform float timeStep
    59 ) : COLOR
     45float4 mainlines(float2 texCoord : TEXCOORD0,
     46                 uniform samplerRECT posTexture : register(s0),
     47                 uniform sampler3D vfield,
     48                 uniform float2 offset,
     49                 uniform float timeStep) : COLOR
    6050{
    61         float3 oldPosition = f3texRECT(posTexture, texCoord);
    62         float3 velocity = tex3D(vfield, oldPosition).yzw * 2 - float3(1, 1, 1);
     51    float3 oldPosition = f3texRECT(posTexture, texCoord);
     52    float3 velocity = tex3D(vfield, oldPosition).yzw * 2 - float3(1, 1, 1);
    6353       
    64         float3 position = oldPosition + velocity * timeStep;
     54    float3 position = oldPosition + velocity * timeStep;
    6555
    66         return float4(position, 1);
     56    return float4(position, 1);
    6757}
  • trunk/packages/vizservers/nanovis/shaders/one_plane.cg

    r1497 r2852  
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    12/*
    23 * ======================================================================
  • trunk/packages/vizservers/nanovis/shaders/one_volume.cg

    r1188 r2852  
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    12/*
    23 * ======================================================================
     
    1617 * render one volume
    1718 */
     19PixelOut main(v2f IN,
     20              uniform sampler3D volume,
     21              uniform sampler1D tf,
     22              //uniform sampler1D tf_cutplane,
     23              uniform float4x4 modelViewInv,
     24              uniform float4x4 modelView,
     25              uniform float4 renderParameters,
     26              uniform float4 options)
     27{
     28    PixelOut OUT;
     29    float4 tex_coord = mul(modelViewInv, IN.TexCoord);
     30    float4 sample = tex3D(volume, tex_coord.xyz);
    1831
     32    //sample the transfer function texture
     33    float4 color = tex1D(tf, sample.x);
    1934
    20 PixelOut main(v2f IN,
    21                 uniform sampler3D volume,
    22                 uniform sampler1D tf,
    23                 //uniform sampler1D tf_cutplane,
    24                 uniform float4x4 modelViewInv,
    25                 uniform float4x4 modelView,
    26                 uniform float4 renderParameters,
    27                 uniform float4 options)
    28 {
    29   PixelOut OUT;
    30   float4 tex_coord = mul(modelViewInv, IN.TexCoord);
    31   float4 sample = tex3D(volume, tex_coord.xyz);
     35    if (renderParameters.x < 0.5) {
     36        //If single slice render, only flat shading, completely opaque.
     37        //color = tex1D(tf_cutplane, sample.x);
     38        color.w = 1;
     39        //color.w = renderParameters.y*color.w/renderParameters.x;
     40    } else {
     41        //regular volume rendering, we do PHONG SHADING
     42        //lighting parameters
     43        float3 normal;
     44        if (length(sample.yzw) > 0.0) {
     45            // INSOO (iso)
     46            //normal = sample.yzw * 2.0 - 1.0; //(iso)
     47            //normal = normalize(normal);
     48            normal = normalize(sample.yzw);
     49        }
    3250
    33   //sample the transfer function texture
    34   float4 color = tex1D(tf, sample.x);
     51        float3 light_vector = normalize(IN.Light);
     52        float3 eye_vector = normalize(IN.EyeVector);
     53        float3 half_vector = normalize(eye_vector+light_vector);
    3554
    36   if(renderParameters.x < 0.5)
    37   { //If single slice render, only flat shading, completely opaque.
    38     //color = tex1D(tf_cutplane, sample.x);
    39     color.w = 1;
    40     //color.w = renderParameters.y*color.w/renderParameters.x;
    41   }
    42   else
    43   { //regular volume rendering, we do PHONG SHADING
    44     //lighting parameters
    45     float3 normal;
    46     if(length(sample.yzw)>0.0)
    47     {
     55        //lighting computation
     56        float normal_dot_light = max(dot(normal, light_vector), 0);
     57        float normal_dot_half = max(dot(normal, half_vector), 0);
     58
    4859        // INSOO (iso)
    49         //normal = sample.yzw * 2.0 - 1.0; //(iso)
    50         //normal = normalize(normal);
    51         normal = normalize(sample.yzw);
     60        //float normal_dot_light = abs(dot(normal, light_vector));
     61        //float normal_dot_half = abs(dot(normal, half_vector));
     62
     63        float ambient = 0.8;
     64
     65        float diffuse = normal_dot_light * renderParameters.z;
     66
     67        float specular = pow(normal_dot_half, renderParameters.w)*(1-ambient-diffuse);
     68
     69        float lighting = ambient + diffuse + specular;
     70        color.xyz = color.xyz * lighting;
     71
     72        if (options.y < 0.5) {
     73            //opacity is modulated by the number of total slices
     74            //to avoid very opaque volume when number of slices is high
     75            color.w = renderParameters.y*color.w/renderParameters.x;
     76
     77            // INSOO (iso)
     78            //opacity is modulated by the number of total slices
     79            //color.w = renderParameters.y*color.w/renderParameters.x * 0.2;
     80        }
    5281    }
    53 
    54     float3 light_vector = normalize(IN.Light);
    55     float3 eye_vector = normalize(IN.EyeVector);
    56     float3 half_vector = normalize(eye_vector+light_vector);
    57 
    58     //lighting computation
    59     float normal_dot_light = max(dot(normal, light_vector), 0);
    60     float normal_dot_half = max(dot(normal, half_vector), 0);
    61 
    62     // INSOO (iso)
    63     //float normal_dot_light = abs(dot(normal, light_vector));
    64     //float normal_dot_half = abs(dot(normal, half_vector));
    65 
    66     float ambient = 0.8;
    67 
    68     float diffuse = normal_dot_light * renderParameters.z;
    69 
    70     float specular = pow(normal_dot_half, renderParameters.w)*(1-ambient-diffuse);
    71 
    72     float lighting = ambient + diffuse + specular;
    73     color.xyz = color.xyz * lighting;
    74 
    75     if (options.y < 0.5)
    76     {
    77         color.w = renderParameters.y*color.w/renderParameters.x; //opacity is modulated by the number of total slices
    78                                                         //to avoid very opaque volume when number of slices is high
    79         // INSOO (iso)
    80         //color.w = renderParameters.y*color.w/renderParameters.x * 0.2; //opacity is modulated by the number of total slices
    81     }
    82   }
    8382
    8483  OUT.Color = color;
     
    8685  return OUT;
    8786}
    88 
  • trunk/packages/vizservers/nanovis/shaders/particle_common.cg

    r1489 r2852  
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    12#define SUBIMAGE_SIZE_X 32
    23#define SUBIMAGE_SIZE_Y 32
  • trunk/packages/vizservers/nanovis/shaders/particlefp.cg

    r1702 r2852  
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    12#include "particlemacro.h"
    23#include "particle_common.cg"
     
    1112
    1213float4 fpmain(float2 texCoord : TEXCOORD0,
    13                 float3 color : COLOR,
    14                 float2 center : TEXCOORD2,
    15                 float4 rotation : TEXCOORD3,
    16                 float skip : TEXCOORD4,
    17                 float mag : TEXCOORD5,
    18                 float zValue : TEXCOORD6,
    19                 uniform sampler2D arrows : register(s0)) : COLOR
     14              float3 color : COLOR,
     15              float2 center : TEXCOORD2,
     16              float4 rotation : TEXCOORD3,
     17              float skip : TEXCOORD4,
     18              float mag : TEXCOORD5,
     19              float zValue : TEXCOORD6,
     20              uniform sampler2D arrows : register(s0)) : COLOR
    2021{
    21         if (skip > 0.5) {
    22                 discard;
    23         }
     22    if (skip > 0.5) {
     23        discard;
     24    }
    2425
    25         float2 newTexCoord = float2((texCoord.x - 0.5) / NUM_SUBIMAGE_X, (texCoord.y - 0.5) / NUM_SUBIMAGE_Y);
    26         float2 rotTexCoord;
    27         rotTexCoord.x = rotation.x * newTexCoord.x + rotation.y * newTexCoord.y;
    28         rotTexCoord.y = rotation.z * newTexCoord.x + rotation.w * newTexCoord.y;
    29         rotTexCoord.x = rotTexCoord.x + 0.5 / NUM_SUBIMAGE_X;
    30         rotTexCoord.y = rotTexCoord.y + 0.5 / NUM_SUBIMAGE_Y;
    31         rotTexCoord = rotTexCoord + center;
    32         float4 refColor;
     26    float2 newTexCoord = float2((texCoord.x - 0.5) / NUM_SUBIMAGE_X, (texCoord.y - 0.5) / NUM_SUBIMAGE_Y);
     27    float2 rotTexCoord;
     28    rotTexCoord.x = rotation.x * newTexCoord.x + rotation.y * newTexCoord.y;
     29    rotTexCoord.y = rotation.z * newTexCoord.x + rotation.w * newTexCoord.y;
     30    rotTexCoord.x = rotTexCoord.x + 0.5 / NUM_SUBIMAGE_X;
     31    rotTexCoord.y = rotTexCoord.y + 0.5 / NUM_SUBIMAGE_Y;
     32    rotTexCoord = rotTexCoord + center;
     33    float4 refColor;
    3334#ifdef USE_J_WIRE       
    34         if (mag > 0.2)
    35                 refColor = float4(1, 0, 0, 1.0);
    36         else if (mag > 0.1)
    37                 refColor = float4(1, 1, 0, 0.3);
    38         else
    39                 refColor = float4(1, 1, 1, 0.3);
     35    if (mag > 0.2)
     36        refColor = float4(1, 0, 0, 1.0);
     37    else if (mag > 0.1)
     38        refColor = float4(1, 1, 0, 0.3);
     39    else
     40        refColor = float4(1, 1, 1, 0.3);
    4041#else
    41         if (mag > LEVEL1)
    42                 refColor = float4(1, 0, 0, 1.0);
    43                 //refColor = float4(1, 0, 0, 1.0 * (3.0 + zValue) / 3);
    44         else if (mag > LEVEL2)
    45                 refColor = float4(1, 1, 0, 0.3);
    46                 //refColor = float4(1, 1, 0, 1.0);
    47         else
    48                 refColor = float4(0.5, 0.5, 0.5, 0.2);
    49                 //refColor = float4(0.5, 0.5, 0.5, 1.0);
     42    if (mag > LEVEL1)
     43        refColor = float4(1, 0, 0, 1.0);
     44    //refColor = float4(1, 0, 0, 1.0 * (3.0 + zValue) / 3);
     45    else if (mag > LEVEL2)
     46        refColor = float4(1, 1, 0, 0.3);
     47    //refColor = float4(1, 1, 0, 1.0);
     48    else
     49        refColor = float4(0.5, 0.5, 0.5, 0.2);
     50    //refColor = float4(0.5, 0.5, 0.5, 1.0);
    5051#endif
    51         float4 arrowc = tex2D(arrows, rotTexCoord.xy);
    52         float4 c = float4(arrowc.xyz, ((arrowc.w == 1.0)? 1 : 0));
    53         //float4 c = float4(arrowc.xyz, ((arrowc.w != 0.0)? 1 : 0));
     52    float4 arrowc = tex2D(arrows, rotTexCoord.xy);
     53    float4 c = float4(arrowc.xyz, ((arrowc.w == 1.0)? 1 : 0));
     54    //float4 c = float4(arrowc.xyz, ((arrowc.w != 0.0)? 1 : 0));
    5455       
    55         return c * refColor;
     56    return c * refColor;
    5657}
  • trunk/packages/vizservers/nanovis/shaders/particlevp.cg

    r1702 r2852  
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    12#include "particle_common.cg"
    2 void vpmain(
    3         in float4 posin : POSITION,
    4         in float4 colin : COLOR0,
    5         in float4 attr : TEXCOORD0,
    6         inout float pointSize : PSIZE,
    7         out float4 posout : POSITION,
    8         out float4 colout : COLOR0,
    9         out float2 center : TEXCOORD2,
    10         out float4 rotation : TEXCOORD3,
    11         out float skip : TEXCOORD4,
    12         out float mag : TEXCOORD5,
    13         out float zValue : TEXCOORD6,
    14         uniform sampler3D vfield,
    15         uniform float currentTime,
    16         uniform float tanHalfFOV,
    17         uniform float4x4 modelview,
    18         uniform float4x4 projection,
    19         uniform float4x4 mvp)
     3void vpmain(in float4 posin : POSITION,
     4            in float4 colin : COLOR0,
     5            in float4 attr : TEXCOORD0,
     6            inout float pointSize : PSIZE,
     7            out float4 posout : POSITION,
     8            out float4 colout : COLOR0,
     9            out float2 center : TEXCOORD2,
     10            out float4 rotation : TEXCOORD3,
     11            out float skip : TEXCOORD4,
     12            out float mag : TEXCOORD5,
     13            out float zValue : TEXCOORD6,
     14            uniform sampler3D vfield,
     15            uniform float currentTime,
     16            uniform float tanHalfFOV,
     17            uniform float4x4 modelview,
     18            uniform float4x4 projection,
     19            uniform float4x4 mvp)
    2020{
    21         float4 vec;
    22         vec.xyz = posin.xyz;
    23         vec.w = 1.0;
     21    float4 vec;
     22    vec.xyz = posin.xyz;
     23    vec.w = 1.0;
    2424
    25         float timeOfBirth = attr.x;
    26         float lifeTime = attr.y;
    27         //float index = attr.w;
    28        
    29         // length
    30         // the scale of from bottom to top
    31         float4 v = tex3D(vfield, vec.xyz);
    32         float3 velocity = v.yzw * 2 - float3(1, 1, 1);
    33         mag = v.x;
    34        
    35         // bottom to top
    36         // scale
    37         center.y = ((((int) (length(velocity.xyz) * 511)) / SUBIMAGE_SIZE_Y) * SUBIMAGE_SIZE_Y) / 512.0;
    38         //center.y = ((((int) (511)) / SUBIMAGE_SIZE_Y) * SUBIMAGE_SIZE_Y) / 512.0;
    39        
    40         velocity = mul(modelview, float4(velocity.x, velocity.y, velocity.z, 0.0)).xyz;
    41         if (length(velocity) != 0.0)
    42                 velocity = normalize(velocity);
    43        
    44         float a = (asin(velocity.z) / 3.141592 + 1) * 0.5;
    45         center.x = ((((int) (a * 511)) / SUBIMAGE_SIZE_X) * SUBIMAGE_SIZE_X) / 512.0;
    46        
    47         if ((abs(velocity.x) == 0.0) && (abs(velocity.y) == 0.0))
    48         {
    49                 rotation.x = 1;
    50                 rotation.y = 0;
    51                 rotation.z = 0;
    52                 rotation.w = 1;
    53         }
    54         else
    55         {
    56                 float2 xy = normalize(velocity.xy);
    57                 rotation.x = xy.x * 0.8;
    58                 rotation.y = -xy.y * 0.8;
    59                 rotation.z = xy.y * 0.8;
    60                 rotation.w = xy.x * 0.8;
     25    float timeOfBirth = attr.x;
     26    float lifeTime = attr.y;
     27    //float index = attr.w;
    6128
    62         }
     29    // length
     30    // the scale of from bottom to top
     31    float4 v = tex3D(vfield, vec.xyz);
     32    float3 velocity = v.yzw * 2 - float3(1, 1, 1);
     33    mag = v.x;
    6334
    64         float4 posEye =  mul(modelview, posin);
     35    // bottom to top
     36    // scale
     37    center.y = ((((int) (length(velocity.xyz) * 511)) / SUBIMAGE_SIZE_Y) * SUBIMAGE_SIZE_Y) / 512.0;
     38    //center.y = ((((int) (511)) / SUBIMAGE_SIZE_Y) * SUBIMAGE_SIZE_Y) / 512.0;
     39
     40    velocity = mul(modelview, float4(velocity.x, velocity.y, velocity.z, 0.0)).xyz;
     41    if (length(velocity) != 0.0)
     42        velocity = normalize(velocity);
     43
     44    float a = (asin(velocity.z) / 3.141592 + 1) * 0.5;
     45    center.x = ((((int) (a * 511)) / SUBIMAGE_SIZE_X) * SUBIMAGE_SIZE_X) / 512.0;
     46
     47    if ((abs(velocity.x) == 0.0) && (abs(velocity.y) == 0.0)) {
     48        rotation.x = 1;
     49        rotation.y = 0;
     50        rotation.z = 0;
     51        rotation.w = 1;
     52    } else {
     53        float2 xy = normalize(velocity.xy);
     54        rotation.x = xy.x * 0.8;
     55        rotation.y = -xy.y * 0.8;
     56        rotation.z = xy.y * 0.8;
     57        rotation.w = xy.x * 0.8;
     58    }
     59
     60    float4 posEye =  mul(modelview, posin);
    6561#ifndef USE_J_WIRE
    66         pointSize = tanHalfFOV / -posEye.z / 5;
     62    pointSize = tanHalfFOV / -posEye.z / 5;
    6763#else
    68         pointSize = tanHalfFOV / -posEye.z / 10;
     64    pointSize = tanHalfFOV / -posEye.z / 10;
    6965#endif
    70         //pointSize = 10 / -posEye.z;
    71         zValue = posEye.z;
    72         posout = mul(mvp, vec);
    73        
    74         if ((currentTime > timeOfBirth) && (currentTime < (timeOfBirth + lifeTime))) skip = 0.0;
    75         else skip = 1.0;
    76        
    77        
    78         colout = colin;
    79        
     66    //pointSize = 10 / -posEye.z;
     67    zValue = posEye.z;
     68    posout = mul(mvp, vec);
     69
     70    if ((currentTime > timeOfBirth) && (currentTime < (timeOfBirth + lifeTime))) skip = 0.0;
     71    else skip = 1.0;
     72
     73    colout = colin;
    8074}
    8175
  • trunk/packages/vizservers/nanovis/shaders/passthrough.cg

    r1702 r2852  
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    12float4 main(float2 texCoord : TEXCOORD0,
    2         uniform samplerRECT tex : register(s0),
    3         uniform float4 scale,
    4         uniform float4 bias
    5 ) : COLOR
     3            uniform samplerRECT tex : register(s0),
     4            uniform float4 scale,
     5            uniform float4 bias) : COLOR
    66{
    77    return texRECT(tex, texCoord.xy) * scale + bias;
  • trunk/packages/vizservers/nanovis/shaders/passthru.cg

    r430 r2852  
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    12/*
    23 * ======================================================================
  • trunk/packages/vizservers/nanovis/shaders/pointsvp.cg

    r1497 r2852  
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
     2void main(in float4 posin : POSITION,
     3          in float4 colin : COLOR0,
     4          out float psize : PSIZE,
     5          out float4 posout : POSITION,
     6          out float4 colout : COLOR0,
     7          uniform float atten,
     8          /*uniform sampler2D normal,*/
     9          uniform float4 posoffset,
     10          uniform float4 basepos,
     11          uniform float4 scale,         
     12          uniform float4x4 modelview,
     13          uniform float4x4 projection)
     14{
     15    float4 vec, homeye, eye;
     16    vec.xyz = posin.xyz;
     17    vec.w = 1.0;
     18    homeye = mul(modelview, vec);
     19    posout = mul(projection, homeye);
    120
    2 void main(in float4 posin : POSITION,
    3                 in float4 colin : COLOR0,
    4                 out float psize : PSIZE,
    5                 out float4 posout : POSITION,
    6                 out float4 colout : COLOR0,
    7                 uniform float atten,
    8                 /*uniform sampler2D normal,*/
    9                 uniform float4 posoffset,
    10                 uniform float4 basepos,
    11                 uniform float4 scale,           
    12         uniform float4x4 modelview,
    13         uniform float4x4 projection)
    14 {
     21    float4 p = mul(modelview, vec);
     22    //psize = scale.x   *(p.w / -p.z) * 10;
    1523
    16         float4 vec, homeye, eye;
    17         vec.xyz = posin.xyz;
    18         vec.w = 1.0;
    19         homeye = mul(modelview, vec);
    20         posout = mul(projection, homeye);
    21        
    22         float4 p = mul(modelview, vec);
    23         //psize = scale.x   *(p.w / -p.z) * 10;
    24        
    25         //psize = 5 * scale.x;
    26         //psize = 2 * p.w / -p.z;
    27         //colout = float4(colin.xyz,0.1);
    28        
    29        
    30 //      float tmp = posin.w * rsqrt(dot(eye.xyz, eye.xyz));
    31 //      psize = scale.x * max(tmp, 1.0);
    32         psize = 10 * p.w / -p.z;
    33        
    34         colout = float4(colin.xyz, colin.w * 0.25);
    35 /*
    36         float4 vec, homeye, eye;
    37         float tmp;
    38        
    39         vec.xyz = posin.xyz;//(posin.xyz + posoffset.www) * basepos.www + basepos.xyz;
    40         vec.w = 1.0;
    41        
    42         homeye = mul(modelview, vec);
    43         posout = mul(projection, homeye);
    44        
    45         //eye = homeye / homeye.w;
    46        
    47         //tmp = posin.w * basepos.w * scale.w * rsqrt(atten * dot(eye.xyz, eye.xyz));
    48        
    49         //psize = scale.x * max(tmp, 1.0);
    50         //tmp = min(tmp, 1.0);
    51         //colout = colin;
    52         //tmp = colin.w * scale.z * tmp * tmp;
    53         //colout.w = max(tmp, 4.0/256);
    54        
    55         psize = 5.0;
     24    //psize = 5 * scale.x;
     25    //psize = 2 * p.w / -p.z;
     26    //colout = float4(colin.xyz,0.1);
    5627
    57        
    58         colout = float4(0.0, 0.0, 1.0, 0.1);
    59 */     
     28    //  float tmp = posin.w * rsqrt(dot(eye.xyz, eye.xyz));
     29    //  psize = scale.x * max(tmp, 1.0);
     30    psize = 10 * p.w / -p.z;
     31
     32    colout = float4(colin.xyz, colin.w * 0.25);
     33    /*
     34      float4 vec, homeye, eye;
     35      float tmp;
     36
     37      vec.xyz = posin.xyz;//(posin.xyz + posoffset.www) * basepos.www + basepos.xyz;
     38      vec.w = 1.0;
     39
     40      homeye = mul(modelview, vec);
     41      posout = mul(projection, homeye);
     42
     43      //eye = homeye / homeye.w;
     44
     45      //tmp = posin.w * basepos.w * scale.w * rsqrt(atten * dot(eye.xyz, eye.xyz));
     46
     47      //psize = scale.x * max(tmp, 1.0);
     48      //tmp = min(tmp, 1.0);
     49      //colout = colin;
     50      //tmp = colin.w * scale.z * tmp * tmp;
     51      //colout.w = max(tmp, 4.0/256);
     52
     53      psize = 5.0;
     54
     55      colout = float4(0.0, 0.0, 1.0, 0.1);
     56    */ 
    6057}
  • trunk/packages/vizservers/nanovis/shaders/queryvelocity.cg

    r1702 r2852  
    1 float4 main
    2 (
    3         float3 pos : TEXCOORD0,
    4         uniform sampler3D vfield
    5 ) : COLOR
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
     2float4 main (float3 pos : TEXCOORD0,
     3             uniform sampler3D vfield
     4             ) : COLOR
    65{
    7         float3 velocity = tex3D(vfield, pos).yzw * 2 - float3(1, 1, 1);
    8         return float4(velocity, 1);
     6    float3 velocity = tex3D(vfield, pos).yzw * 2 - float3(1, 1, 1);
     7    return float4(velocity, 1);
    98}
  • trunk/packages/vizservers/nanovis/shaders/render_vel.cg

    r1311 r2852  
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    12/*
    23 * ======================================================================
     
    1819            uniform sampler3D vel_tex,
    1920            uniform float4 plane_normal,
    20             uniform float vmax
    21             ) : COLOR
     21            uniform float vmax) : COLOR
    2222{
    2323    float3 ret;
  • trunk/packages/vizservers/nanovis/shaders/renderparticle.cg

    r1702 r2852  
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    12
    23/*
    34void main(in float4 posin : POSITION,
    4                 in float4 colin : COLOR0,
    5                 out float psize : PSIZE,
    6                 out float4 posout : POSITION,
    7                 out float4 colout : COLOR0,
    8                 uniform float atten,
    9                 /*uniform sampler2D normal,*/
    10                 uniform float4 posoffset,
    11                 uniform float4 basepos,
    12                 uniform float4 scale,           
    13         uniform float4x4 modelview,
    14         uniform float4x4 projection)
     5          in float4 colin : COLOR0,
     6          out float psize : PSIZE,
     7          out float4 posout : POSITION,
     8          out float4 colout : COLOR0,
     9          uniform float atten,
     10          //uniform sampler2D normal,
     11          uniform float4 posoffset,
     12          uniform float4 basepos,
     13          uniform float4 scale,
     14          uniform float4x4 modelview,
     15          uniform float4x4 projection)
    1516{
     17    float4 vec, homeye, eye;
     18    vec.xyz = posin.xyz;
     19    vec.w = 1.0;
     20    homeye = mul(modelview, vec);
     21    posout = mul(projection, homeye);
    1622
    17         float4 vec, homeye, eye;
    18         vec.xyz = posin.xyz;
    19         vec.w = 1.0;
    20         homeye = mul(modelview, vec);
    21         posout = mul(projection, homeye);
    22        
    23         float4 p = mul(modelview, vec);
    24         //psize = scale.x   *(p.w / -p.z) * 10;
    25        
    26         //psize = 5 * scale.x;
    27         //psize = 2 * p.w / -p.z;
    28         //colout = float4(colin.xyz,0.1);
    29        
    30        
    31         float tmp = posin.w * rsqrt(dot(eye.xyz, eye.xyz));
    32         psize = scale.x * max(tmp, 1.0);
    33         psize = 10 * p.w / -p.z;
    34        
    35         colout = float4(colin.xyz, colin.w * 0.25);
     23    float4 p = mul(modelview, vec);
     24    //psize = scale.x   *(p.w / -p.z) * 10;
     25
     26    //psize = 5 * scale.x;
     27    //psize = 2 * p.w / -p.z;
     28    //colout = float4(colin.xyz,0.1);
     29
     30    float tmp = posin.w * rsqrt(dot(eye.xyz, eye.xyz));
     31    psize = scale.x * max(tmp, 1.0);
     32    psize = 10 * p.w / -p.z;
     33
     34    colout = float4(colin.xyz, colin.w * 0.25);
    3635}
    3736*/
  • trunk/packages/vizservers/nanovis/shaders/update_pos.cg

    r1497 r2852  
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    12/*
    23 * ======================================================================
     
    1920            uniform samplerRECT init_pos_tex,
    2021            uniform sampler3D vel_tex,
    21 //            uniform sampler1D tf_tex,
     22            // uniform sampler1D tf_tex,
    2223            uniform float timestep,
    2324            uniform float max,
    2425            uniform float mode,
    25             uniform float3 scale
    26             ) : COLOR
     26            uniform float3 scale) : COLOR
    2727{
    2828    float4 ret;
    29 /*
    30     if (mode == 0)
    31     {
    32         float4 pos = texRECT(pos_tex, uv);
    33         float4 vel = tex3D(vel_tex, pos.xyz);
    34         ret.xyz = tex1D(tf_tex, vel.x).xyz;
    35         ret.w = 1;
    36     }
    37     else
    38     {
    39 */
     29    /*
     30      if (mode == 0) {
     31          float4 pos = texRECT(pos_tex, uv);
     32          float4 vel = tex3D(vel_tex, pos.xyz);
     33          ret.xyz = tex1D(tf_tex, vel.x).xyz;
     34          ret.w = 1;
     35      } else {
     36    */
    4037    // get previous position and velocity
    4138    float4 pos = texRECT(pos_tex, uv);
     
    4542    //time -= 0.01;
    4643
    47     if (time < 0)
    48     {
    49         pos = texRECT(init_pos_tex, uv);
    50         time = pos.w;
     44    if (time < 0) {
     45        pos = texRECT(init_pos_tex, uv);
     46        time = pos.w;
    5147    }
    5248
    53         /// INSOO
    54         // TEMP
     49    /// INSOO
     50    // TEMP
    5551    if (max > 100) max = 100;
    5652
     
    7066    //not drawing if the particle is out of bound
    7167    /*
    72     if(ret.x<0 || ret.x>1 || ret.y<0 || ret.y>1 || ret.z<0 || ret.z>1 || time==0)
    73       ret = float4(0,0,0,0);
    74     else
    75       ret.w = 1;
     68      if (ret.x<0 || ret.x>1 || ret.y<0 || ret.y>1 || ret.z<0 || ret.z>1 || time==0)
     69          ret = float4(0,0,0,0);
     70      else
     71          ret.w = 1;
    7672    */
    77     if(ret.x<0 || ret.x>1 || ret.y<0 || ret.y>1 || ret.z<0 || ret.z>1)
    78     {
    79         ret = texRECT(init_pos_tex, uv);
    80     }
    81     else
    82     {
    83       ret.w = time;
     73    if (ret.x<0 || ret.x>1 || ret.y<0 || ret.y>1 || ret.z<0 || ret.z>1){
     74        ret = texRECT(init_pos_tex, uv);
     75    } else {
     76        ret.w = time;
    8477    }
    8578//    }
  • trunk/packages/vizservers/nanovis/shaders/update_pos_vel.cg

    r1497 r2852  
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    12/*
    23 * ======================================================================
     
    1516#include "common.cg"
    1617
    17 void   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            
    29             out float4 new_pos : COLOR0,
    30             out float4 new_vel : COLOR1
    31             )
     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)
    3229{
    3330    const float3 terrain_scale = float3(8.0, 2.0, 8.0);
     
    4138    // update velocity
    4239    float3 force = gravity;
    43 //    float3 force = 0.0;
    44 //    Gravitation(pos, spherePos, force, 0.1);
     40    // float3 force = 0.0;
     41    // Gravitation(pos, spherePos, force, 0.1);
    4542
    4643    SphereCollide(pos_next, vel, spherePos, 1.0, sphereVel, 0.5, force);
    47 //    FloorCollide(pos_next, vel, 0.0, 0.5, force);   
     44    // FloorCollide(pos_next, vel, 0.0, 0.5, force);   
    4845    TerrainCollide(pos_next, vel, terrain_tex, terrain_scale, terrain_offset, 0.5);
    4946
     
    5451    // update position
    5552    SphereConstraint(pos, spherePos, 1.0f);
    56 //    FloorConstraint(pos, 0.0f);
     53    // FloorConstraint(pos, 0.0f);
    5754    TerrainConstraint(pos, terrain_tex, terrain_scale, terrain_offset);
    5855
    5956    pos += vel * timestep;
    60    
     57
    6158    new_vel = float4(vel, 1);
    6259    new_pos = float4(pos, 1);
  • trunk/packages/vizservers/nanovis/shaders/update_vel.cg

    r1497 r2852  
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    12/*
    23 * ======================================================================
     
    1617
    1718float4 main(in float2 uv : TEXCOORD0,
    18 
    1919            uniform samplerRECT pos_tex,
    2020            uniform samplerRECT vel_tex,
    2121            uniform sampler2D terrain_tex,           
    22            
    2322            uniform float timestep = 0.01,
    2423            uniform float damping = 0.99,
    2524            uniform float3 gravity = float3(0, -1, 0),
    2625            uniform float3 spherePos,
    27             uniform float3 sphereVel           
    28             ) : COLOR
     26            uniform float3 sphereVel) : COLOR
    2927{
    3028    const float3 terrain_scale = float3(8.0, 2.0, 8.0);
     
    3735
    3836    float3 force = gravity;
    39 //    float3 force = 0.0;
    40 //    Gravitation(pos, spherePos, force, 0.1);
     37    // float3 force = 0.0;
     38    // Gravitation(pos, spherePos, force, 0.1);
    4139
    4240    SphereCollide(pos_next, vel, spherePos, 1.0, sphereVel, 0.5, force);
    43 //    FloorCollide(pos_next, vel, 0.0, 0.5, force);
     41    // FloorCollide(pos_next, vel, 0.0, 0.5, force);
    4442    TerrainCollide(pos_next, vel, terrain_tex, terrain_scale, terrain_offset, 0.5);
    45    
     43
    4644    const float inv_mass = 1.0;   
    4745    vel += force * inv_mass * timestep; // F = ma     
  • trunk/packages/vizservers/nanovis/shaders/velocity.cg

    r1702 r2852  
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    12// Copyright (c) 2004-2005 Lutz Latta
    23//
     
    3031float3 advanceVelocity(float3 _Velocity, float3 _Position, float _TimeStep)
    3132{
    32         float3 gravity = float3(0, -.01, 0);
     33    float3 gravity = float3(0, -.01, 0);
    3334       
    34         float3 acceleration = gravity;
     35    float3 acceleration = gravity;
    3536
    36         //acceleration += localAttractor(_Position,
    37         //      getClosestPointOnLine(_LocalAttractorPosition[0], _LocalAttractorPosition[1], _Position),
    38         //      0.05, 0.2);
    39         //acceleration += localAttractor(_Position, _LocalAttractorPosition[0], 0.02, 0.4);
    40         //acceleration += localAttractor(_Position, _LocalAttractorPosition[1], 0.02, 0.02);
    41         //acceleration += localRepulsor(_Position, _LocalAttractorPosition[2], 0.02, 0.1);
    42         //acceleration += localRepulsor(_Position, _LocalAttractorPosition[3], 0.02, 0.1);
    43         //acceleration += flowFieldVector(_Position, _FlowFieldTexture, float2(512, 512),
    44         //      float3(4, 4, 4), float3(256, 0, 256), 0.01);
     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);
    4547
    46         float3 velocity = _Velocity + _TimeStep * acceleration;
    47        
    48         //velocity = lerp(velocity, flowFieldVector(_Position, _FlowFieldTexture, float2(512, 512),
    49         //      float3(4, 4, 4), float3(256, 0, 256), 1), 0.2);
    50         //velocity = length(velocity) * normalize(flowFieldVector(_Position, _FlowFieldTexture, float2(512, 512),
    51         //      float3(4, 4, 4), float3(256, 0, 256), 1));
     48    float3 velocity = _Velocity + _TimeStep * acceleration;
    5249
    53         //spiral(velocity, _TimeStep, normalize(_LocalAttractorPosition[0] - _LocalAttractorPosition[1]), .3);
     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));
    5454
    55         //dampen(velocity, 1.1);
    56         //undampen(velocity, 1.01);
     55    //spiral(velocity, _TimeStep, normalize(_LocalAttractorPosition[0] - _LocalAttractorPosition[1]), .3);
    5756
    58         floorConstraint(velocity, _Position, 0, 0.4, 0.1, 0.01);
    59         sphereConstraint(velocity, _Position, _SphereCenter, 1, 0.3, 0.7, 0.01);
    60         //terrainConstraint(velocity, _Position, _TerrainTexture, float2(128, 128),
    61         //      float3(4, 4, 4), float3(64, 0, 64), 0.02, 0.7, 0.01);
    62        
    63         return velocity;
     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;
    6466}
    6567
    66 float4 main
    67 (
    68         float2 _TexCoord : TEXCOORD0,
    69         uniform samplerRECT _VelocityTexture : register(s0),
    70         uniform samplerRECT _PositionTexture : register(s1),
    71         uniform float _TimeStep
    72 ) : COLOR
     68float4 main(float2 _TexCoord : TEXCOORD0,
     69            uniform samplerRECT _VelocityTexture : register(s0),
     70            uniform samplerRECT _PositionTexture : register(s1),
     71            uniform float _TimeStep) : COLOR
    7372{
    74         float3 velocity = (float3)texRECT(_VelocityTexture, _TexCoord);
    75         float3 position = (float3)texRECT(_PositionTexture, _TexCoord);
     73    float3 velocity = (float3)texRECT(_VelocityTexture, _TexCoord);
     74    float3 position = (float3)texRECT(_PositionTexture, _TexCoord);
    7675       
    77         return float4(advanceVelocity(velocity, position, _TimeStep), 0);
     76    return float4(advanceVelocity(velocity, position, _TimeStep), 0);
    7877}
    7978
    80 float4 mainInitialization
    81 (
    82         float3 _VelocityInit : TEXCOORD0,
    83         float3 _PositionInit : TEXCOORD1,
    84         float _TimeStep : TEXCOORD2
    85 ) : COLOR
     79float4 mainInitialization(float3 _VelocityInit : TEXCOORD0,
     80                          float3 _PositionInit : TEXCOORD1,
     81                          float _TimeStep : TEXCOORD2) : COLOR
    8682{
    87         return float4(advanceVelocity(_VelocityInit, _PositionInit, _TimeStep), 0);
     83    return float4(advanceVelocity(_VelocityInit, _PositionInit, _TimeStep), 0);
    8884}
  • trunk/packages/vizservers/nanovis/shaders/velocityslicefp.cg

    r1489 r2852  
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    12#include "particle_common.cg"
    23
    34float4 fpmain(float2 texCoord : TEXCOORD0,
    4                 float3 color : COLOR,
    5                 float2 center : TEXCOORD2,
    6                 float4 rotation : TEXCOORD3,
    7                 uniform sampler2D arrows : register(s0)) : COLOR
     5              float3 color : COLOR,
     6              float2 center : TEXCOORD2,
     7              float4 rotation : TEXCOORD3,
     8              uniform sampler2D arrows : register(s0)) : COLOR
    89{
    9         float2 newTexCoord = float2((texCoord.x - 0.5) / NUM_SUBIMAGE_X, (texCoord.y - 0.5) / NUM_SUBIMAGE_Y);
    10         float2 rotTexCoord;
    11         rotTexCoord.x = rotation.x * newTexCoord.x + rotation.y * newTexCoord.y;
    12         rotTexCoord.y = rotation.z * newTexCoord.x + rotation.w * newTexCoord.y;
    13         rotTexCoord.x = rotTexCoord.x + 0.5 / NUM_SUBIMAGE_X;
    14         rotTexCoord.y = rotTexCoord.y + 0.5 / NUM_SUBIMAGE_Y;
    15         rotTexCoord = rotTexCoord + center;
    16        
    17         return float4(tex2D(arrows, rotTexCoord.xy).xyz * color, 1.0);
     10    float2 newTexCoord = float2((texCoord.x - 0.5) / NUM_SUBIMAGE_X, (texCoord.y - 0.5) / NUM_SUBIMAGE_Y);
     11    float2 rotTexCoord;
     12    rotTexCoord.x = rotation.x * newTexCoord.x + rotation.y * newTexCoord.y;
     13    rotTexCoord.y = rotation.z * newTexCoord.x + rotation.w * newTexCoord.y;
     14    rotTexCoord.x = rotTexCoord.x + 0.5 / NUM_SUBIMAGE_X;
     15    rotTexCoord.y = rotTexCoord.y + 0.5 / NUM_SUBIMAGE_Y;
     16    rotTexCoord = rotTexCoord + center;
     17
     18    return float4(tex2D(arrows, rotTexCoord.xy).xyz * color, 1.0);
    1819}
  • trunk/packages/vizservers/nanovis/shaders/velocityslicevp.cg

    r1702 r2852  
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    12#include "particle_common.cg"
    2 void vpmain(
    3         in float4 posin : POSITION,
    4         in float4 colin : COLOR0,
    5         out float4 posout : POSITION,
    6         out float4 colout : COLOR0,
    7         out float2 center : TEXCOORD2,
    8         out float4 rotation : TEXCOORD3,
    9         out float4 pointSize : PSIZE,
    10         uniform sampler3D vfield,
    11         uniform float tanHalfFOV,
    12     uniform float4x4 modelview,
    13     uniform float4x4 projection,
    14     uniform float4x4 mvp)
     3void vpmain(in float4 posin : POSITION,
     4            in float4 colin : COLOR0,
     5            out float4 posout : POSITION,
     6            out float4 colout : COLOR0,
     7            out float2 center : TEXCOORD2,
     8            out float4 rotation : TEXCOORD3,
     9            out float4 pointSize : PSIZE,
     10            uniform sampler3D vfield,
     11            uniform float tanHalfFOV,
     12            uniform float4x4 modelview,
     13            uniform float4x4 projection,
     14            uniform float4x4 mvp)
    1515{
    16         float4 vec;
    17         vec.xyz = posin.xyz;
    18         vec.w = 1.0;
    19        
    20         // length
    21         // the scale of from bottom to top
    22         float3 velocity = tex3D(vfield, vec.xyz).yzw * 2 - float3(1, 1, 1);
    23        
    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         {
    38                 rotation.x = 1;
    39                 rotation.y = 0;
    40                 rotation.z = 0;
    41                 rotation.w = 1;
    42         }
    43         else
    44         {
    45                 float2 xy = normalize(velocity.xy);
    46                 rotation.x = xy.x * 0.8;
    47                 rotation.y = -xy.y * 0.8;
    48                 rotation.z = xy.y * 0.8;
    49                 rotation.w = xy.x * 0.8;
     16    float4 vec;
     17    vec.xyz = posin.xyz;
     18    vec.w = 1.0;
    5019
    51         }
     20    // length
     21    // the scale of from bottom to top
     22    float3 velocity = tex3D(vfield, vec.xyz).yzw * 2 - float3(1, 1, 1);
    5223
    53         float4 posEye =  mul(modelview, posin);
    54         //pointSize = tanHalfFOV / -posEye.z / 5;
    55         pointSize = tanHalfFOV / -posEye.z / 10; //j-wire
    56         //pointSize = 10 / -posEye.z;
    57        
    58         posout = mul(mvp, vec);
    59        
    60         colout = colin;
     24    // bottom to top
     25    // scale
     26    center.y = ((((int) (length(velocity.xyz) * 511)) / SUBIMAGE_SIZE_Y) * SUBIMAGE_SIZE_Y) / 512.0;
     27
     28    velocity = mul(modelview, float4(velocity.x, velocity.y, velocity.z, 0.0)).xyz;
     29    if (length(velocity) != 0.0)
     30        velocity = normalize(velocity);
     31
     32    float a = (asin(velocity.z) / 3.141592 + 1) * 0.5;
     33    center.x = ((((int) (a * 511)) / SUBIMAGE_SIZE_X) * SUBIMAGE_SIZE_X) / 512.0;
     34
     35    if ((abs(velocity.x) == 0.0) && (abs(velocity.y) == 0.0)) {
     36        rotation.x = 1;
     37        rotation.y = 0;
     38        rotation.z = 0;
     39        rotation.w = 1;
     40    } else {
     41        float2 xy = normalize(velocity.xy);
     42        rotation.x = xy.x * 0.8;
     43        rotation.y = -xy.y * 0.8;
     44        rotation.z = xy.y * 0.8;
     45        rotation.w = xy.x * 0.8;
     46    }
     47
     48    float4 posEye =  mul(modelview, posin);
     49    //pointSize = tanHalfFOV / -posEye.z / 5;
     50    pointSize = tanHalfFOV / -posEye.z / 10; //j-wire
     51    //pointSize = 10 / -posEye.z;
     52
     53    posout = mul(mvp, vec);
     54
     55    colout = colin;
    6156}
  • trunk/packages/vizservers/nanovis/shaders/vertex_std.cg

    r392 r2852  
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    12/*
    23 * ======================================================================
     
    1314#include "common.cg"
    1415 
    15 v2f main(a2v IN, 
    16                 uniform float4x4 modelViewProjMatrix,
    17                 uniform float4x4 modelViewInv)
     16v2f main(a2v IN,
     17         uniform float4x4 modelViewProjMatrix,
     18         uniform float4x4 modelViewInv)
    1819{
    19         v2f OUT;
     20    v2f OUT;
    2021
    21         //clip space vertex position
    22         OUT.HPosition = mul(modelViewProjMatrix, mul(modelViewInv, IN.Position));
    23        
    24         //eye space texture coordinates
    25         OUT.TexCoord = IN.TexCoord;
     22    //clip space vertex position
     23    OUT.HPosition = mul(modelViewProjMatrix, mul(modelViewInv, IN.Position));
    2624
    27         //world space eye position
    28         OUT.EyeVector = normalize(-IN.Position.xyz);
     25    //eye space texture coordinates
     26    OUT.TexCoord = IN.TexCoord;
    2927
    30         //world space light postion
    31         OUT.Light = normalize(float3(1,1,1)-IN.Position.xyz);
     28    //world space eye position
     29    OUT.EyeVector = normalize(-IN.Position.xyz);
    3230
    33         return OUT;
     31    //world space light postion
     32    OUT.Light = normalize(float3(1,1,1)-IN.Position.xyz);
     33
     34    return OUT;
    3435}
  • trunk/packages/vizservers/nanovis/shaders/volqd_volume.cg

    r581 r2852  
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    12#include "common.cg"
    23
    34PixelOut main(v2f IN,
    4     uniform sampler1D tf,
    5     uniform sampler3D vol_grid_s,
    6     uniform float4 cell_size,
    7     uniform float4x4 ModelViewInv,
    8     uniform float4 renderParameters)
     5              uniform sampler1D tf,
     6              uniform sampler3D vol_grid_s,
     7              uniform float4 cell_size,
     8              uniform float4x4 ModelViewInv,
     9              uniform float4 renderParameters)
    910{
    1011    PixelOut OUT;
    1112
    1213    float tf_coord_s, tf_coord_p, tf_coord_d, tf_coord_ss;
    13                    
    1414
    1515    float4 twice_cell_size = cell_size*2.0;
     
    1818    float4 tex_coord_b = tex_coord - float4(twice_cell_size.x, 0, twice_cell_size.z, 0);
    1919    float4 tex_coord_c = tex_coord - float4(0, twice_cell_size.y, twice_cell_size.z, 0);
    20 
    2120
    2221    float4 voxel_corner = f4tex3D(vol_grid_s, tex_coord);
     
    2928    float4 color = tex1D(tf, sample.x);
    3029
    31     if(renderParameters.x < 0.5)
    32     {
     30    if (renderParameters.x < 0.5) {
    3331        //If single slice render, only flat shading, completely opaque.
    3432        color.w = 1;
    35     }
    36     else
    37     {   //regular volume rendering, we do FLAT SHADING
     33    } else {
     34        //regular volume rendering, we do FLAT SHADING
    3835        //since all 4 components of the volume texture has been used to store orbital data,
    3936        //there is no room to store normal vector. If we really need PHONG shading we have to pass more volumes to
     
    4946    return OUT;
    5047}
    51 
  • trunk/packages/vizservers/nanovis/shaders/zincblende_volume.cg

    r870 r2852  
     1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    12/*
    23 * ======================================================================
     
    1819
    1920PixelOut main(v2f IN,
    20                 uniform sampler1D tf,
    21                 uniform sampler3D volumeA,
    22                 uniform sampler3D volumeB,
    23                 uniform float4 cellSize,
    24                 uniform float4x4 modelViewInv,
    25                 uniform float4 renderParameters,
    26                 uniform float4 options)
     21              uniform sampler1D tf,
     22              uniform sampler3D volumeA,
     23              uniform sampler3D volumeB,
     24              uniform float4 cellSize,
     25              uniform float4x4 modelViewInv,
     26              uniform float4 renderParameters,
     27              uniform float4 options)
    2728
    2829{
     30    PixelOut OUT;
    2931
    30   PixelOut OUT;
     32    float4 tex_coord = mul(modelViewInv, IN.TexCoord);
     33    float4 twice_cell_size = cellSize * 2.0;
    3134
    32   float4 tex_coord = mul(modelViewInv, IN.TexCoord);
    33   float4 twice_cell_size = cellSize * 2.0;
     35    // volumeA : outer
     36    // volumeB : inner
     37    float4 tex_coord_2 = tex_coord + float4(twice_cell_size.x, 0,                 twice_cell_size.z, 0);
     38    float4 tex_coord_3 = tex_coord + float4(0,                 twice_cell_size.y, twice_cell_size.z, 0);
     39    float4 tex_coord_4 = tex_coord + float4(twice_cell_size.x, twice_cell_size.y, 0, 0);
     40    float4 voxel_corner = f4tex3D(volumeB, tex_coord) + f4tex3D(volumeA, tex_coord - cellSize);
     41    float4 voxel_face_center_2 = f4tex3D(volumeB, tex_coord_2) + f4tex3D(volumeA, tex_coord_2 - cellSize);
     42    float4 voxel_face_center_3 = f4tex3D(volumeB, tex_coord_3) + f4tex3D(volumeA, tex_coord_3 - cellSize);
     43    float4 voxel_face_center_4 = f4tex3D(volumeB, tex_coord_4) + f4tex3D(volumeA, tex_coord_4 - cellSize);
     44
     45    float sample = (voxel_corner.x + voxel_face_center_2.y + voxel_face_center_3.z + voxel_face_center_4.w) * 0.125;
     46    /*
     47      float4 tex_coord_a = tex_coord - float4(twice_cell_size.x, twice_cell_size.y, 0, 0);
     48      float4 tex_coord_b = tex_coord - float4(twice_cell_size.x, 0, twice_cell_size.z, 0);
     49      float4 tex_coord_c = tex_coord - float4(0, twice_cell_size.y, twice_cell_size.z, 0);
    3450       
    35   // volumeA : outer
    36   // volumeB : inner
    37   float4 tex_coord_2 = tex_coord + float4(twice_cell_size.x, 0,                 twice_cell_size.z, 0);
    38   float4 tex_coord_3 = tex_coord + float4(0,                 twice_cell_size.y, twice_cell_size.z, 0);
    39   float4 tex_coord_4 = tex_coord + float4(twice_cell_size.x, twice_cell_size.y, 0, 0);
    40   float4 voxel_corner = f4tex3D(volumeB, tex_coord) + f4tex3D(volumeA, tex_coord - cellSize);
    41   float4 voxel_face_center_2 = f4tex3D(volumeB, tex_coord_2) + f4tex3D(volumeA, tex_coord_2 - cellSize);
    42   float4 voxel_face_center_3 = f4tex3D(volumeB, tex_coord_3) + f4tex3D(volumeA, tex_coord_3 - cellSize);
    43   float4 voxel_face_center_4 = f4tex3D(volumeB, tex_coord_4) + f4tex3D(volumeA, tex_coord_4 - cellSize);
     51      float4 voxel_corner = f4tex3D(volumeA, tex_coord) + f4tex3D(volumeB, tex_coord - cellSize);
     52      float4 voxel_face_center_a = f4tex3D(volumeA, tex_coord_a) + f4tex3D(volumeB, tex_coord_a - cellSize);
     53      float4 voxel_face_center_b = f4tex3D(volumeA, tex_coord_b) + f4tex3D(volumeB, tex_coord_b - cellSize);
     54      float4 voxel_face_center_c = f4tex3D(volumeA, tex_coord_c) + f4tex3D(volumeB, tex_coord_c - cellSize);
     55      //combine 8 sampling results
     56      float sample = (voxel_corner.x + voxel_face_center_a.y + voxel_face_center_b.z + voxel_face_center_c.w) * 0.125;
     57    */
    4458
    45   float sample = (voxel_corner.x + voxel_face_center_2.y + voxel_face_center_3.z + voxel_face_center_4.w) * 0.125;
    46 /*
    47   float4 tex_coord_a = tex_coord - float4(twice_cell_size.x, twice_cell_size.y, 0, 0);
    48   float4 tex_coord_b = tex_coord - float4(twice_cell_size.x, 0, twice_cell_size.z, 0);
    49   float4 tex_coord_c = tex_coord - float4(0, twice_cell_size.y, twice_cell_size.z, 0);
    50        
    51   float4 voxel_corner = f4tex3D(volumeA, tex_coord) + f4tex3D(volumeB, tex_coord - cellSize);
    52   float4 voxel_face_center_a = f4tex3D(volumeA, tex_coord_a) + f4tex3D(volumeB, tex_coord_a - cellSize);
    53   float4 voxel_face_center_b = f4tex3D(volumeA, tex_coord_b) + f4tex3D(volumeB, tex_coord_b - cellSize);
    54   float4 voxel_face_center_c = f4tex3D(volumeA, tex_coord_c) + f4tex3D(volumeB, tex_coord_c - cellSize);
    55   //combine 8 sampling results
    56   float sample = (voxel_corner.x + voxel_face_center_a.y + voxel_face_center_b.z + voxel_face_center_c.w) * 0.125;
    57 */
     59    //sample transfor function texture
     60    float4 color = f4tex1D(tf, sample);
    5861
     62    if (renderParameters.x < 0.5) {
     63        //If single slice render, only flat shading, completely opaque.
     64        color.w = 1;
     65    } else {
     66        //regular volume rendering, we do FLAT SHADING
     67        //since all 4 components of the volume texture has been used to store orbital data,
     68        //there is no room to store normal vector. If we really need PHONG shading we have to pass more volumes to
     69        //the shader. We might add this later.
    5970
    60   //sample transfor function texture
    61   float4 color = f4tex1D(tf, sample);
     71        //opacity is modulated by the number of total slices
     72        //to avoid very opaque volume when number of slices is high
     73        color.w = renderParameters.y * color.w / renderParameters.x;
     74    }
    6275
    63 
    64   if(renderParameters.x < 0.5)
    65   { //If single slice render, only flat shading, completely opaque.
    66     color.w = 1;
    67   }
    68   else
    69   { //regular volume rendering, we do FLAT SHADING
    70     //since all 4 components of the volume texture has been used to store orbital data,
    71     //there is no room to store normal vector. If we really need PHONG shading we have to pass more volumes to
    72     //the shader. We might add this later.
    73 
    74     color.w = renderParameters.y * color.w / renderParameters.x; //opacity is modulated by the number of total slices
    75                                                         //to avoid very opaque volume when number of slices is high
    76   }
    77 
    78   OUT.Color = color;
    79   return OUT;
     76    OUT.Color = color;
     77    return OUT;
    8078}
Note: See TracChangeset for help on using the changeset viewer.