/*********************************************************************NVMH3**** File: $Id: //sw/devtools/SDK/9.5/SDK/MEDIA/HLSL/post_colorCurve.fx#3 $ Copyright NVIDIA Corporation 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. Texture-based remap of color space. Color ramp textures can be easily generated by Photoshop and the PS "Curves" command. The technique is described in "GPU Gems" in the section on color control. If "CURVE_FROM_FILE" is undefined, then use a color spline function to make a stand-in ramp. ******************************************************************************/ // #define CURVE_FROM_FILE #include float Script : STANDARDSGLOBAL < string UIWidget = "none"; string ScriptClass = "scene"; string ScriptOrder = "postprocess"; string ScriptOutput = "color"; string Script = "Technique=ColorCurve;"; > = 0.8; // version # float4 ClearColor < string UIWidget = "color"; string UIName = "background"; > = {0,0,0,0}; float ClearDepth = 1.0; /////////////////////////////////////////////////////////// /////////////////////////////////////// Tweakables //////// /////////////////////////////////////////////////////////// QUAD_REAL Fade < string UIWidget = "slider"; QUAD_REAL UIMin = 0.0f; QUAD_REAL UIMax = 1.0f; QUAD_REAL UIStep = 0.01f; > = 1.0f; /////////////////////////////////////////////////////////// ///////////////////////////// Curve Texture /////////////// /////////////////////////////////////////////////////////// #ifdef CURVE_FROM_FILE texture ColorCurveTex < string name="some_user_curve_map.dds"; string ResourceType = "2D"; >; #else /* ! CURVE_FROM_FILE */ // assume "t" ranges from 0 to 1 safely // brute-force this, it's running on the CPU QUAD_REAL3 c_bezier(QUAD_REAL3 c0, QUAD_REAL3 c1, QUAD_REAL3 c2, QUAD_REAL3 c3, QUAD_REAL t) { QUAD_REAL t2 = t*t; QUAD_REAL t3 = t2*t; QUAD_REAL nt = 1.0 - t; QUAD_REAL nt2 = nt*nt; QUAD_REAL nt3 = nt2 * nt; QUAD_REAL3 b = nt3*c0 + (3.0*t*nt2)*c1 + (3.0*t2*nt)*c2 + t3*c3; return b; } // function used to fill the volume noise texture QUAD_REAL4 color_curve(QUAD_REAL2 Pos : POSITION) : COLOR { QUAD_REAL3 kolor0 = QUAD_REAL3(0.0,0.0,0.0); QUAD_REAL3 kolor1 = QUAD_REAL3(0.8,0.3,0.0); QUAD_REAL3 kolor2 = QUAD_REAL3(0.7,0.7,0.9); QUAD_REAL3 kolor3 = QUAD_REAL3(1.0,0.9,1.0); QUAD_REAL3 sp = c_bezier(kolor0,kolor1,kolor2,kolor3,Pos.x); return QUAD_REAL4(sp,1); } texture ColorCurveTex < string ResourceType = "2D"; string function = "color_curve"; string UIWidget = "None"; float2 Dimensions = { 256.0f, 4 }; // could be height=1, but I want it to be visible in the Texture View... >; #endif /* ! CURVE_FROM_FILE */ sampler ColorCurveSampler = sampler_state { texture = ; AddressU = CLAMP; AddressV = CLAMP; MIPFILTER = LINEAR; MINFILTER = LINEAR; MAGFILTER = LINEAR; }; /////////////////////////////////////////////////////////// ///////////////////////////// Render-to-Texture Data ////// /////////////////////////////////////////////////////////// DECLARE_QUAD_TEX(SceneTexture,SceneSampler,"X8R8G8B8") DECLARE_QUAD_DEPTH_BUFFER(DepthBuffer,"D24S8") ////////////////////////////////////////////////////// ////////////////////////////////// pixel shaders ///// ////////////////////////////////////////////////////// QUAD_REAL4 recolorPS(QuadVertexOutput IN) : COLOR { QUAD_REAL3 scnColor = tex2D(SceneSampler, IN.UV).xyz; QUAD_REAL red = tex2D(ColorCurveSampler,QUAD_REAL2(scnColor.x,0)).x; QUAD_REAL grn = tex2D(ColorCurveSampler,QUAD_REAL2(scnColor.y,0)).y; QUAD_REAL blu = tex2D(ColorCurveSampler,QUAD_REAL2(scnColor.z,0)).z; QUAD_REAL3 newColor = QUAD_REAL3(red,grn,blu); QUAD_REAL3 result = lerp(scnColor,newColor,Fade); return QUAD_REAL4(result,1); } //////////////////////////////////////////////////////////// /////////////////////////////////////// techniques ///////// //////////////////////////////////////////////////////////// technique ColorCurve < string ScriptClass = "scene"; string ScriptOrder = "postprocess"; string ScriptOutput = "color"; string Script = "RenderColorTarget0=SceneTexture;" "RenderDepthStencilTarget=DepthBuffer;" "ClearSetColor=ClearColor;" "ClearSetDepth=ClearDepth;" "Clear=color;" "Clear=depth;" "ScriptExternal=color;" "Pass=p0;"; > { pass p0 < string Script = "RenderColorTarget0=;" "Draw=Buffer;"; > { cullmode = none; ZEnable = false; VertexShader = compile vs_2_0 ScreenQuadVS(); PixelShader = compile ps_2_0 recolorPS(); } } ////////////////// eof ///