Changeset 2852 for trunk/packages/vizservers/nanovis/shaders
- Timestamp:
- Mar 13, 2012 10:54:40 PM (12 years ago)
- 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 -*- */ 1 2 /* 2 3 * ====================================================================== … … 30 31 31 32 // constrain particle to heightfield stored in texture 32 void TerrainConstraint(inout float3 pos, uniform sampler2D terrain_tex, float3 scale, float3 offset) 33 void TerrainConstraint(inout float3 pos, uniform sampler2D terrain_tex, 34 float3 scale, float3 offset) 33 35 { 34 36 float2 uv = (pos.xz - offset.xz) / scale.xz; … … 39 41 } 40 42 41 void SphereCollide(inout float3 x, inout float3 vel, float3 center, float r, float3 sphere_vel, float friction, inout float3 force) 43 void SphereCollide(inout float3 x, inout float3 vel, float3 center, float r, 44 float3 sphere_vel, float friction, inout float3 force) 42 45 { 43 46 float3 delta = x - center; 44 47 float dist = length(delta); 45 48 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; 49 52 } 50 53 } 51 54 52 void FloorCollide(inout float3 x, inout float3 vel, float level, float friction, inout float3 force) 55 void FloorCollide(inout float3 x, inout float3 vel, float level, 56 float friction, inout float3 force) 53 57 { 54 58 if (x.y < level) { 55 //x.y = level;56 //force.y += -vel.y*friction;59 // x.y = level; 60 // force.y += -vel.y*friction; 57 61 vel.y += -vel.y*friction; 58 62 } … … 61 65 void Gravitation(float3 pos, float3 mass_pos, inout float3 force, float epsilon) 62 66 { 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)); 67 71 } 68 72 69 void TerrainCollide(float3 pos, inout float3 vel, uniform sampler2D terrain_tex, float3 scale, float3 offset, float friction) 73 void TerrainCollide(float3 pos, inout float3 vel, uniform sampler2D terrain_tex, 74 float3 scale, float3 offset, float friction) 70 75 { 71 76 const float2 texelSize = float2( 1.0 / 256.0, 1.0 / 256.0 ); … … 77 82 float h1 = tex2D(terrain_tex, uv + texelSize*float2(1, 0) ).r; 78 83 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)); 80 86 N = normalize(N); 81 87 vel = reflect(vel, N); … … 86 92 struct a2v 87 93 { 88 //For semantics, see pages 230-240 of Cg_Toolkit.pdf89 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; 91 97 }; 92 98 93 99 struct v2f 94 100 { 95 float4 HPosition: HPOS; //Clip space pos. Not readable in frag prog96 float4 TexCoord: TEXCOORD0;97 float3 EyeVector: TEXCOORD1; //world space eye vector98 float3 Light: TEXCOORD2; //world space light vector101 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 99 105 }; 100 106 101 107 struct PixelOut { 102 float4 Color: COLOR0;103 //float Depth: DEPTH;108 float4 Color: COLOR0; 109 //float Depth: DEPTH; 104 110 }; 105 -
trunk/packages/vizservers/nanovis/shaders/copy_texcoord.cg
r226 r2852 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 1 2 /* 2 3 * ====================================================================== -
trunk/packages/vizservers/nanovis/shaders/distance.cg
r1702 r2852 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 1 2 // Copyright (c) 2004-2005 Lutz Latta 2 3 // … … 30 31 float2 initSortIndex(float2 sortIndex : TEXCOORD0) : COLOR 31 32 { 32 33 34 33 // TBD... 34 return float2(0, pack_2half(sortIndex)); 35 //return float2(sortIndex.x, sortIndex.y); 35 36 } 36 37 37 38 float2 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 42 42 { 43 44 43 float sortIndex = texRECT(sortTexture, texCoord.xy).y; 44 half2 particleIndex = unpack_2half(sortIndex); 45 45 46 46 float3 particlePos = (float3)texRECT(positionTexture, particleIndex); 47 47 48 49 48 float3 delta = viewerPosition - particlePos; 49 float distanceSqr = dot(delta, delta); 50 50 51 52 53 51 // Prevent unused, far-away particles from destroying comparisons in sorting. 52 if (distanceSqr > 1e6 || isnan(distanceSqr)) 53 distanceSqr = 1e6; 54 54 55 55 return float2(distanceSqr, sortIndex); 56 56 } 57 57 float4 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 61 60 { 62 63 64 61 float sortIndex = texRECT(sortTexture, texCoord.xy).y; 62 half2 particleIndex = unpack_2half(sortIndex); 63 float4 particlePos = (float4)texRECT(positionTexture, particleIndex); 65 64 66 65 return particlePos; 67 66 } 68 67 … … 70 69 float3 initSortIndex(float2 sortIndex : TEXCOORD0) : COLOR 71 70 { 72 73 71 //return float3(0, sortIndex.x, sortIndex.y); 72 return float3(1e6, sortIndex.x, sortIndex.y); 74 73 } 75 74 76 75 float3 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 81 79 { 82 83 80 float2 particleIndex = texRECT(sortTexture, texCoord.xy).yz; 81 float3 particlePos = texRECT(positionTexture, particleIndex).xyz; 84 82 85 86 83 float3 delta = viewerPosition - particlePos; 84 float distanceSqr = dot(delta, delta); 87 85 88 89 90 86 // Prevent unused, far-away particles from destroying comparisons in sorting. 87 if (distanceSqr > 1e6 || isnan(distanceSqr)) 88 distanceSqr = 1e6; 91 89 92 90 return float3(distanceSqr, particleIndex.x, particleIndex.y); 93 91 } 94 92 95 93 float3 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 99 96 { 100 101 97 float2 particleIndex = texRECT(sortTexture, texCoord.xy).yz; 98 float3 particlePos = texRECT(positionTexture, particleIndex).xyz; 102 99 103 100 return particlePos; 104 101 } 105 102 #endif -
trunk/packages/vizservers/nanovis/shaders/distancesort.cg
r1702 r2852 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 1 2 // Copyright (c) 2004-2005 Lutz Latta 2 3 // … … 29 30 float2 initSortIndex(float2 _SortIndex : TEXCOORD0) : COLOR 30 31 { 31 32 return float2(0, pack_2half(_SortIndex)); 32 33 } 33 34 34 35 float2 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 39 39 { 40 41 40 float sortIndex = texRECT(_SortTexture, _TexCoord.xy).y; 41 half2 particleIndex = unpack_2half(sortIndex); 42 42 43 43 float3 particlePos = (float3)texRECT(_PositionTexture, particleIndex); 44 44 45 46 45 float3 delta = _ViewerPosition - particlePos; 46 float distanceSqr = dot(delta, delta); 47 47 48 49 50 48 // Prevent unused, far-away particles from destroying comparisons in sorting. 49 if (distanceSqr > 1e6 || isnan(distanceSqr)) 50 distanceSqr = 1e6; 51 51 52 52 return float2(distanceSqr, sortIndex); 53 53 } 54 54 55 55 float4 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 59 58 { 60 61 62 59 float sortIndex = texRECT(_SortTexture, _TexCoord.xy).y; 60 half2 particleIndex = unpack_2half(sortIndex); 61 float4 particlePos = (float4)texRECT(_PositionTexture, particleIndex); 63 62 64 63 return particlePos; 65 64 } -
trunk/packages/vizservers/nanovis/shaders/heightcolor.cg
r1546 r2852 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 1 2 2 float4 main( 3 float4 texCoord : TEXCOORD0, 4 uniform float opacity, 5 uniform sampler1D tf) : COLOR 3 float4 main(float4 texCoord : TEXCOORD0, 4 uniform float opacity, 5 uniform sampler1D tf) : COLOR 6 6 { 7 7 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 -*- */ 1 2 // Copyright (c) 2004-2005 Lutz Latta 2 3 // … … 27 28 float3 28 29 #endif 29 mergeSortEnd( 30 float2 current : TEXCOORD0, 31 uniform samplerRECT sortData : register(s0), 32 uniform int2 size, 33 uniform int step 34 ) : COLOR 30 mergeSortEnd(float2 current : TEXCOORD0, 31 uniform samplerRECT sortData : register(s0), 32 uniform int2 size, 33 uniform int step) : COLOR 35 34 { 36 35 #ifndef USE_RGB_FORMAT 37 36 float2 currentSample = texRECT(sortData, (float2)current).xy; 38 37 #else 39 38 float3 currentSample = texRECT(sortData, (float2)current).xyz; 40 39 #endif 41 40 42 43 41 float i = (current.y - 0.5) * size.x + current.x; 42 //float i = current.y * size.x + current.x; 44 43 45 46 44 // swap direction 45 float b = (fmod(i / step, 2.0) < 1.0 ? 1.0 : -1.0); 47 46 48 47 49 50 51 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)); 52 51 #ifndef USE_RGB_FORMAT 53 52 float2 otherSample = texRECT(sortData, otherPos).xy; 54 53 #else 55 54 float3 otherSample = texRECT(sortData, otherPos).xyz; 56 55 #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 } 65 61 } 66 62 #ifndef USE_RGB_FORMAT … … 69 65 float3 70 66 #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 67 mergeSortRecursion(float2 _Current : TEXCOORD0, 68 uniform samplerRECT _SortData : register(s0), 69 uniform int2 _Size, 70 uniform int _Step, 71 uniform int _Count) : COLOR 78 72 { 79 73 #ifndef USE_RGB_FORMAT 80 74 float2 currentSample = texRECT(_SortData, (float2)_Current).xy; 81 75 #else 82 76 float3 currentSample = texRECT(_SortData, (float2)_Current).xyz; 83 77 #endif 84 85 78 float i = (_Current.y - 0.5) * _Size.x + _Current.x; 79 //float i = _Current.y * _Size.x + _Current.x; 86 80 87 81 float iMod = fmod((float)(i / _Step), (float)_Count); 88 82 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); 92 85 93 94 95 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)); 96 89 97 90 #ifndef USE_RGB_FORMAT 98 91 float2 otherSample = texRECT(_SortData, otherPos).xy; 99 92 #else 100 93 float3 otherSample = texRECT(_SortData, otherPos).xyz; 101 94 #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; 113 102 } -
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 -*- */ 2 float4 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 13 11 { 14 12 if (maxScale > 100) maxScale = 100; 15 13 16 17 18 19 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; 20 18 21 22 19 float3 position = oldPosition + velocity * timeStep * 0.01; 20 //float3 position = oldPosition; 23 21 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 //} 33 29 34 30 return float4(position, 1); 35 31 } 36 32 37 float4 initParticlePosMain 38 ( 39 float3 initPos : TEXCOORD0, 40 float2 texCoord : TEXCOORD1, 41 float timeStep : TEXCOORD2, 42 uniform sampler3D vfield 43 ) : COLOR 33 float4 initParticlePosMain(float3 initPos : TEXCOORD0, 34 float2 texCoord : TEXCOORD1, 35 float timeStep : TEXCOORD2, 36 uniform sampler3D vfield) : COLOR 44 37 { 45 46 47 48 49 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); 50 43 } 51 44 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 45 float4 mainlines(float2 texCoord : TEXCOORD0, 46 uniform samplerRECT posTexture : register(s0), 47 uniform sampler3D vfield, 48 uniform float2 offset, 49 uniform float timeStep) : COLOR 60 50 { 61 62 51 float3 oldPosition = f3texRECT(posTexture, texCoord); 52 float3 velocity = tex3D(vfield, oldPosition).yzw * 2 - float3(1, 1, 1); 63 53 64 54 float3 position = oldPosition + velocity * timeStep; 65 55 66 56 return float4(position, 1); 67 57 } -
trunk/packages/vizservers/nanovis/shaders/one_plane.cg
r1497 r2852 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 1 2 /* 2 3 * ====================================================================== -
trunk/packages/vizservers/nanovis/shaders/one_volume.cg
r1188 r2852 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 1 2 /* 2 3 * ====================================================================== … … 16 17 * render one volume 17 18 */ 19 PixelOut 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); 18 31 32 //sample the transfer function texture 33 float4 color = tex1D(tf, sample.x); 19 34 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 } 32 50 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); 35 54 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 48 59 // 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 } 52 81 } 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 computation59 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 slices78 //to avoid very opaque volume when number of slices is high79 // INSOO (iso)80 //color.w = renderParameters.y*color.w/renderParameters.x * 0.2; //opacity is modulated by the number of total slices81 }82 }83 82 84 83 OUT.Color = color; … … 86 85 return OUT; 87 86 } 88 -
trunk/packages/vizservers/nanovis/shaders/particle_common.cg
r1489 r2852 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 1 2 #define SUBIMAGE_SIZE_X 32 2 3 #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 -*- */ 1 2 #include "particlemacro.h" 2 3 #include "particle_common.cg" … … 11 12 12 13 float4 fpmain(float2 texCoord : TEXCOORD0, 13 14 15 16 17 18 19 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 20 21 { 21 22 23 22 if (skip > 0.5) { 23 discard; 24 } 24 25 25 26 27 28 29 30 31 32 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; 33 34 #ifdef USE_J_WIRE 34 35 36 37 38 39 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); 40 41 #else 41 42 43 44 45 46 47 48 49 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); 50 51 #endif 51 52 53 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)); 54 55 55 56 return c * refColor; 56 57 } -
trunk/packages/vizservers/nanovis/shaders/particlevp.cg
r1702 r2852 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 1 2 #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) 3 void 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) 20 20 { 21 22 23 21 float4 vec; 22 vec.xyz = posin.xyz; 23 vec.w = 1.0; 24 24 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; 61 28 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; 63 34 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); 65 61 #ifndef USE_J_WIRE 66 62 pointSize = tanHalfFOV / -posEye.z / 5; 67 63 #else 68 64 pointSize = tanHalfFOV / -posEye.z / 10; 69 65 #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; 80 74 } 81 75 -
trunk/packages/vizservers/nanovis/shaders/passthrough.cg
r1702 r2852 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 1 2 float4 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 6 6 { 7 7 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 -*- */ 1 2 /* 2 3 * ====================================================================== -
trunk/packages/vizservers/nanovis/shaders/pointsvp.cg
r1497 r2852 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 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 { 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); 1 20 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; 15 23 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); 56 27 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 */ 60 57 } -
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 -*- */ 2 float4 main (float3 pos : TEXCOORD0, 3 uniform sampler3D vfield 4 ) : COLOR 6 5 { 7 8 6 float3 velocity = tex3D(vfield, pos).yzw * 2 - float3(1, 1, 1); 7 return float4(velocity, 1); 9 8 } -
trunk/packages/vizservers/nanovis/shaders/render_vel.cg
r1311 r2852 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 1 2 /* 2 3 * ====================================================================== … … 18 19 uniform sampler3D vel_tex, 19 20 uniform float4 plane_normal, 20 uniform float vmax 21 ) : COLOR 21 uniform float vmax) : COLOR 22 22 { 23 23 float3 ret; -
trunk/packages/vizservers/nanovis/shaders/renderparticle.cg
r1702 r2852 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 1 2 2 3 /* 3 4 void main(in float4 posin : POSITION, 4 5 6 7 8 9 /*uniform sampler2D normal,*/ 10 11 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) 15 16 { 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); 16 22 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); 36 35 } 37 36 */ -
trunk/packages/vizservers/nanovis/shaders/update_pos.cg
r1497 r2852 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 1 2 /* 2 3 * ====================================================================== … … 19 20 uniform samplerRECT init_pos_tex, 20 21 uniform sampler3D vel_tex, 21 //uniform sampler1D tf_tex,22 // uniform sampler1D tf_tex, 22 23 uniform float timestep, 23 24 uniform float max, 24 25 uniform float mode, 25 uniform float3 scale 26 ) : COLOR 26 uniform float3 scale) : COLOR 27 27 { 28 28 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 */ 40 37 // get previous position and velocity 41 38 float4 pos = texRECT(pos_tex, uv); … … 45 42 //time -= 0.01; 46 43 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; 51 47 } 52 48 53 54 49 /// INSOO 50 // TEMP 55 51 if (max > 100) max = 100; 56 52 … … 70 66 //not drawing if the particle is out of bound 71 67 /* 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 else75 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; 76 72 */ 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; 84 77 } 85 78 // } -
trunk/packages/vizservers/nanovis/shaders/update_pos_vel.cg
r1497 r2852 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 1 2 /* 2 3 * ====================================================================== … … 15 16 #include "common.cg" 16 17 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 ) 18 void 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) 32 29 { 33 30 const float3 terrain_scale = float3(8.0, 2.0, 8.0); … … 41 38 // update velocity 42 39 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); 45 42 46 43 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); 48 45 TerrainCollide(pos_next, vel, terrain_tex, terrain_scale, terrain_offset, 0.5); 49 46 … … 54 51 // update position 55 52 SphereConstraint(pos, spherePos, 1.0f); 56 //FloorConstraint(pos, 0.0f);53 // FloorConstraint(pos, 0.0f); 57 54 TerrainConstraint(pos, terrain_tex, terrain_scale, terrain_offset); 58 55 59 56 pos += vel * timestep; 60 57 61 58 new_vel = float4(vel, 1); 62 59 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 -*- */ 1 2 /* 2 3 * ====================================================================== … … 16 17 17 18 float4 main(in float2 uv : TEXCOORD0, 18 19 19 uniform samplerRECT pos_tex, 20 20 uniform samplerRECT vel_tex, 21 21 uniform sampler2D terrain_tex, 22 23 22 uniform float timestep = 0.01, 24 23 uniform float damping = 0.99, 25 24 uniform float3 gravity = float3(0, -1, 0), 26 25 uniform float3 spherePos, 27 uniform float3 sphereVel 28 ) : COLOR 26 uniform float3 sphereVel) : COLOR 29 27 { 30 28 const float3 terrain_scale = float3(8.0, 2.0, 8.0); … … 37 35 38 36 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); 41 39 42 40 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); 44 42 TerrainCollide(pos_next, vel, terrain_tex, terrain_scale, terrain_offset, 0.5); 45 43 46 44 const float inv_mass = 1.0; 47 45 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 -*- */ 1 2 // Copyright (c) 2004-2005 Lutz Latta 2 3 // … … 30 31 float3 advanceVelocity(float3 _Velocity, float3 _Position, float _TimeStep) 31 32 { 32 33 float3 gravity = float3(0, -.01, 0); 33 34 34 35 float3 acceleration = gravity; 35 36 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); 45 47 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; 52 49 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)); 54 54 55 //dampen(velocity, 1.1); 56 //undampen(velocity, 1.01); 55 //spiral(velocity, _TimeStep, normalize(_LocalAttractorPosition[0] - _LocalAttractorPosition[1]), .3); 57 56 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; 64 66 } 65 67 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 68 float4 main(float2 _TexCoord : TEXCOORD0, 69 uniform samplerRECT _VelocityTexture : register(s0), 70 uniform samplerRECT _PositionTexture : register(s1), 71 uniform float _TimeStep) : COLOR 73 72 { 74 75 73 float3 velocity = (float3)texRECT(_VelocityTexture, _TexCoord); 74 float3 position = (float3)texRECT(_PositionTexture, _TexCoord); 76 75 77 76 return float4(advanceVelocity(velocity, position, _TimeStep), 0); 78 77 } 79 78 80 float4 mainInitialization 81 ( 82 float3 _VelocityInit : TEXCOORD0, 83 float3 _PositionInit : TEXCOORD1, 84 float _TimeStep : TEXCOORD2 85 ) : COLOR 79 float4 mainInitialization(float3 _VelocityInit : TEXCOORD0, 80 float3 _PositionInit : TEXCOORD1, 81 float _TimeStep : TEXCOORD2) : COLOR 86 82 { 87 83 return float4(advanceVelocity(_VelocityInit, _PositionInit, _TimeStep), 0); 88 84 } -
trunk/packages/vizservers/nanovis/shaders/velocityslicefp.cg
r1489 r2852 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 1 2 #include "particle_common.cg" 2 3 3 4 float4 fpmain(float2 texCoord : TEXCOORD0, 4 5 6 7 5 float3 color : COLOR, 6 float2 center : TEXCOORD2, 7 float4 rotation : TEXCOORD3, 8 uniform sampler2D arrows : register(s0)) : COLOR 8 9 { 9 10 11 12 13 14 15 16 17 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); 18 19 } -
trunk/packages/vizservers/nanovis/shaders/velocityslicevp.cg
r1702 r2852 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 1 2 #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) 3 void 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) 15 15 { 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; 50 19 51 } 20 // length 21 // the scale of from bottom to top 22 float3 velocity = tex3D(vfield, vec.xyz).yzw * 2 - float3(1, 1, 1); 52 23 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; 61 56 } -
trunk/packages/vizservers/nanovis/shaders/vertex_std.cg
r392 r2852 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 1 2 /* 2 3 * ====================================================================== … … 13 14 #include "common.cg" 14 15 15 v2f main(a2v IN, 16 uniform float4x4 modelViewProjMatrix, 17 16 v2f main(a2v IN, 17 uniform float4x4 modelViewProjMatrix, 18 uniform float4x4 modelViewInv) 18 19 { 19 20 v2f OUT; 20 21 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)); 26 24 27 //world space eye position28 OUT.EyeVector = normalize(-IN.Position.xyz);25 //eye space texture coordinates 26 OUT.TexCoord = IN.TexCoord; 29 27 30 //world space light postion31 OUT.Light = normalize(float3(1,1,1)-IN.Position.xyz);28 //world space eye position 29 OUT.EyeVector = normalize(-IN.Position.xyz); 32 30 33 return OUT; 31 //world space light postion 32 OUT.Light = normalize(float3(1,1,1)-IN.Position.xyz); 33 34 return OUT; 34 35 } -
trunk/packages/vizservers/nanovis/shaders/volqd_volume.cg
r581 r2852 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 1 2 #include "common.cg" 2 3 3 4 PixelOut 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) 9 10 { 10 11 PixelOut OUT; 11 12 12 13 float tf_coord_s, tf_coord_p, tf_coord_d, tf_coord_ss; 13 14 14 15 15 float4 twice_cell_size = cell_size*2.0; … … 18 18 float4 tex_coord_b = tex_coord - float4(twice_cell_size.x, 0, twice_cell_size.z, 0); 19 19 float4 tex_coord_c = tex_coord - float4(0, twice_cell_size.y, twice_cell_size.z, 0); 20 21 20 22 21 float4 voxel_corner = f4tex3D(vol_grid_s, tex_coord); … … 29 28 float4 color = tex1D(tf, sample.x); 30 29 31 if(renderParameters.x < 0.5) 32 { 30 if (renderParameters.x < 0.5) { 33 31 //If single slice render, only flat shading, completely opaque. 34 32 color.w = 1; 35 } 36 else 37 { //regular volume rendering, we do FLAT SHADING 33 } else { 34 //regular volume rendering, we do FLAT SHADING 38 35 //since all 4 components of the volume texture has been used to store orbital data, 39 36 //there is no room to store normal vector. If we really need PHONG shading we have to pass more volumes to … … 49 46 return OUT; 50 47 } 51 -
trunk/packages/vizservers/nanovis/shaders/zincblende_volume.cg
r870 r2852 1 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 1 2 /* 2 3 * ====================================================================== … … 18 19 19 20 PixelOut main(v2f IN, 20 21 22 23 24 25 26 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) 27 28 28 29 { 30 PixelOut OUT; 29 31 30 PixelOut OUT; 32 float4 tex_coord = mul(modelViewInv, IN.TexCoord); 33 float4 twice_cell_size = cellSize * 2.0; 31 34 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); 34 50 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 */ 44 58 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); 58 61 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. 59 70 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 } 62 75 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; 80 78 }
Note: See TracChangeset
for help on using the changeset viewer.