/*********************************************************************NVMH3**** File: $Id: //sw/devtools/FXComposer2/Alpha4+/SDK/MEDIA/CgFX1.4/cage.cgfx#1 $ Copyright NVIDIA Corporation 2002-2004 TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED *AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Comments: 3D meshcage effect, created by procedural texturing. Texture is pre-calculated by HLSL. Wires are aligned to world coordinates in this sample. Works fine in effectedit $Date: 2006/04/10 $ ******************************************************************************/ #define DEFAULT_BALANCE (0.1) #include "stripe_tex.cgh" float Script : STANDARDSGLOBAL < string UIWidget = "none"; string ScriptClass = "object"; string ScriptOrder = "standard"; string ScriptOutput = "color"; string Script = "Technique=wires;"; > = 0.8; /************* UN-TWEAKABLES **************/ float4x4 WvpXf : WorldViewProjection < string UIWidget="None"; >; float4x4 WorldXf : World < string UIWidget="None"; >; /******** TWEAKABLES ****************************************/ float4 BrightColor : Diffuse < string UIName = "Wire Color"; > = {1.0f, 0.8f, 0.0f, 1.0f}; float4 EmptyColor < string UIName = "Color of 'Air'"; string UIWidget = "Color"; > = {0.0f, 0.0f, 0.0f, 0.0f}; DECLARE_BALANCE float Scale : UNITSSCALE < string units = "inches"; string UIWidget = "slider"; float uimin = 0.0; float uimax = 20.0; float uistep = 0.01; string UIName = "size of pattern"; > = 5.1; /////////////// prodecural texture ///////////// /************* DATA STRUCTS **************/ /* data from application vertex buffer */ struct appdata { float3 Position : POSITION; float4 UV : TEXCOORD0; float4 Normal : NORMAL; }; /* data passed from vertex shader to pixel shader */ struct vertexOutput { float4 HPosition : POSITION; float4 TexCoord : TEXCOORD0;// }; /*********** vertex shader ******/ vertexOutput mainVS(appdata IN) { vertexOutput OUT; float4 Po = float4(IN.Position.x,IN.Position.y,IN.Position.z,1.0); // object space float4 hpos = mul(WvpXf,Po); // position (projected) OUT.HPosition = hpos; float4 Pw = mul(WorldXf,Po); // world coords OUT.TexCoord = Pw * Scale; return OUT; } /******************** pixel shader *********************/ float4 strokeTexPS(vertexOutput IN) : COLOR { // result.z = stripe(XYZW.zw).x; float stripex = stripe(IN.TexCoord.x).x; float stripey = stripe(IN.TexCoord.y).x; float stripez = stripe(IN.TexCoord.z).x; // result.z = tex2D(_StripeSampler,XYZW.zw).x; // float stripex = tex2D(_StripeSampler,float2(IN.TexCoord.x,Balance)).x; // float stripey = tex2D(_StripeSampler,float2(IN.TexCoord.y,Balance)).x; // float stripez = tex2D(_StripeSampler,float2(IN.TexCoord.z,Balance)).x; float check = stripex * stripey * stripez; float4 dColor = lerp(BrightColor,EmptyColor,check); return dColor; } /*************/ technique wires < string Script = "Pass=p0; Pass=p1;"; > { pass p0 < string Script = "Draw=geometry;"; > { VertexProgram = compile arbvp1 mainVS(); DepthTestEnable = true; DepthMask = true; DepthFunc = LEqual; BlendEnable = true; BlendFunc = int2(SrcAlpha,DstAlpha); CullFace = front; FragmentProgram = compile arbfp1 strokeTexPS(); } pass p1 < string Script = "Draw=geometry;"; > { VertexProgram = compile arbvp1 mainVS(); DepthTestEnable = true; DepthMask = true; DepthFunc = LEqual; BlendEnable = true; BlendFunc = int2(SrcAlpha,DstAlpha); CullFace = back; FragmentProgram = compile arbfp1 strokeTexPS(); } } /***************************** eof ***/