//**************************************************************// // Effect File exported by RenderMonkey 1.6 // // - Although many improvements were made to RenderMonkey FX // file export, there are still situations that may cause // compilation problems once the file is exported, such as // occasional naming conflicts for methods, since FX format // does not support any notions of name spaces. You need to // try to create workspaces in such a way as to minimize // potential naming conflicts on export. // // - Note that to minimize resulting name collisions in the FX // file, RenderMonkey will mangle names for passes, shaders // and function names as necessary to reduce name conflicts. //**************************************************************// //--------------------------------------------------------------// // Whiteboard //--------------------------------------------------------------// //--------------------------------------------------------------// // Draw //--------------------------------------------------------------// string NPR_Whiteboard_Draw_Elephant : ModelData = "..\\..\\..\\Program Files\\ATI Research Inc\\RenderMonkey 1.62\\Examples\\Media\\Models\\ElephantBody.3ds"; texture ImageMap_Tex : RenderColorTarget < float2 RenderTargetDimensions = {512,512}; string Format="D3DFMT_G16R16"; float ClearDepth=1.000000; int ClearColor=0; >; float4x4 view_proj_matrix : ViewProjection; float depthScale < string UIName = "depthScale"; string UIWidget = "Numeric"; bool UIVisible = true; float UIMin = 0.00; float UIMax = 0.03; > = float( 0.00 ); struct VS_OUTPUT { float4 Pos: POSITION; float texCoord: TEXCOORD; }; VS_OUTPUT NPR_Whiteboard_Draw_Vertex_Shader_main(float4 Pos: POSITION){ VS_OUTPUT Out; Out.Pos = mul(view_proj_matrix, Pos); // Pass depth Out.texCoord = depthScale * mul(view_proj_matrix, Pos).z; return Out; } float4 NPR_Whiteboard_Draw_Pixel_Shader_main(float4 depth: TEXCOORD) : COLOR { return depth; } //--------------------------------------------------------------// // Edge //--------------------------------------------------------------// string NPR_Whiteboard_Edge_ScreenAlignedQuad : ModelData = "..\\..\\..\\Program Files\\ATI Research Inc\\RenderMonkey 1.62\\Examples\\Media\\Models\\ScreenAlignedQuad.3ds"; texture EdgeMap_Tex : RenderColorTarget < float2 RenderTargetDimensions = {512,512}; string Format="D3DFMT_G16R16"; float ClearDepth=1.000000; int ClearColor=0; >; float4x4 NPR_Whiteboard_Edge_Vertex_Shader_view_proj_matrix; struct NPR_Whiteboard_Edge_Vertex_Shader_VS_OUTPUT { float4 Pos: POSITION; float2 texCoord: TEXCOORD; }; NPR_Whiteboard_Edge_Vertex_Shader_VS_OUTPUT NPR_Whiteboard_Edge_Vertex_Shader_main(float4 Pos: POSITION){ NPR_Whiteboard_Edge_Vertex_Shader_VS_OUTPUT Out; // Clean up inaccuracies Pos.xy = sign(Pos.xy); Out.Pos = float4(Pos.xy, 0, 1); // Image-space Out.texCoord.x = 0.5 * (1 + Pos.x); Out.texCoord.y = 0.5 * (1 - Pos.y); return Out; } sampler ImageMap = sampler_state { Texture = (ImageMap_Tex); ADDRESSU = CLAMP; ADDRESSV = CLAMP; MAGFILTER = LINEAR; MINFILTER = LINEAR; MIPFILTER = LINEAR; }; // This shader applies a Sobel filter to detect edges in the image. // The Sobel filter extracts the first order derivates of the image, // that is, the slope. Where the slope is sharp there is an edge. // These are the filter kernels: // // SobelX SobelY // 1 0 -1 1 2 1 // 2 0 -2 0 0 0 // 1 0 -1 -1 -2 -1 // One pixel offset const float off = 1.0 / 512.0; float4 NPR_Whiteboard_Edge_Pixel_Shader_main(float2 texCoord: TEXCOORD) : COLOR { // Sample neighbor pixels float s00 = tex2D(ImageMap, texCoord + float2(-off, -off)).r; float s01 = tex2D(ImageMap, texCoord + float2( 0, -off)).r; float s02 = tex2D(ImageMap, texCoord + float2( off, -off)).r; float s10 = tex2D(ImageMap, texCoord + float2(-off, 0)).r; float s12 = tex2D(ImageMap, texCoord + float2( off, 0)).r; float s20 = tex2D(ImageMap, texCoord + float2(-off, off)).r; float s21 = tex2D(ImageMap, texCoord + float2( 0, off)).r; float s22 = tex2D(ImageMap, texCoord + float2( off, off)).r; // Sobel filter in X direction float sobelX = s00 + 2 * s10 + s20 - s02 - 2 * s12 - s22; // Sobel filter in Y direction float sobelY = s00 + 2 * s01 + s02 - s20 - 2 * s21 - s22; // Find edge, skip sqrt() to improve performance ... float edgeSqr = (sobelX * sobelX + sobelY * sobelY); // ... and threshold against a squared value instead. return edgeSqr > 0.07 * 0.07; } //--------------------------------------------------------------// // AntiAlias //--------------------------------------------------------------// string NPR_Whiteboard_AntiAlias_ScreenAlignedQuad : ModelData = "..\\..\\..\\Program Files\\ATI Research Inc\\RenderMonkey 1.62\\Examples\\Media\\Models\\ScreenAlignedQuad.3ds"; float4x4 NPR_Whiteboard_AntiAlias_Vertex_Shader_view_proj_matrix; struct NPR_Whiteboard_AntiAlias_Vertex_Shader_VS_OUTPUT { float4 Pos: POSITION; float2 texCoord: TEXCOORD; }; NPR_Whiteboard_AntiAlias_Vertex_Shader_VS_OUTPUT NPR_Whiteboard_AntiAlias_Vertex_Shader_main(float4 Pos: POSITION){ NPR_Whiteboard_AntiAlias_Vertex_Shader_VS_OUTPUT Out; // Clean up inaccuracies Pos.xy = sign(Pos.xy); Out.Pos = float4(Pos.xy, 0, 1); // Image-space Out.texCoord.x = 0.5 * (1 + Pos.x); Out.texCoord.y = 0.5 * (1 - Pos.y); return Out; } float hardness < string UIName = "hardness"; string UIWidget = "Numeric"; bool UIVisible = true; float UIMin = 0.00; float UIMax = 2.00; > = float( 0.24 ); float AA_SampleDist < string UIName = "AA_SampleDist"; string UIWidget = "Numeric"; bool UIVisible = true; float UIMin = 0.00; float UIMax = 0.10; > = float( 0.01 ); sampler EdgeMap = sampler_state { Texture = (EdgeMap_Tex); }; const float2 samples[12] = { -0.326212, -0.405805, -0.840144, -0.073580, -0.695914, 0.457137, -0.203345, 0.620716, 0.962340, -0.194983, 0.473434, -0.480026, 0.519456, 0.767022, 0.185461, -0.893124, 0.507431, 0.064425, 0.896420, 0.412458, -0.321940, -0.932615, -0.791559, -0.597705, }; float4 NPR_Whiteboard_AntiAlias_Pixel_Shader_main(float2 texCoord: TEXCOORD) : COLOR { // Apply a simple blur filter to get rid of aliasing and // get a wider spread of the edges and a softer image. float sum = tex2D(EdgeMap, texCoord).r; for (int i = 0; i < 12; i++){ sum += tex2D(EdgeMap, texCoord + AA_SampleDist * samples[i]).r; } return 1 - hardness * sum; } //--------------------------------------------------------------// // Technique Section for Effect Workspace.NPR.Whiteboard //--------------------------------------------------------------// technique Whiteboard { pass Draw < string Script = "RenderColorTarget0 = ImageMap_Tex;" "ClearColor = (0, 0, 0, 0);" "ClearDepth = 1.000000;"; > { CULLMODE = CCW; VertexShader = compile vs_1_1 NPR_Whiteboard_Draw_Vertex_Shader_main(); PixelShader = compile ps_2_0 NPR_Whiteboard_Draw_Pixel_Shader_main(); } pass Edge < string Script = "RenderColorTarget0 = EdgeMap_Tex;" "ClearColor = (0, 0, 0, 0);" "ClearDepth = 1.000000;"; > { CULLMODE = NONE; VertexShader = compile vs_2_0 NPR_Whiteboard_Edge_Vertex_Shader_main(); PixelShader = compile ps_2_0 NPR_Whiteboard_Edge_Pixel_Shader_main(); } pass AntiAlias { VertexShader = compile vs_1_1 NPR_Whiteboard_AntiAlias_Vertex_Shader_main(); PixelShader = compile ps_2_0 NPR_Whiteboard_AntiAlias_Pixel_Shader_main(); } }