1 | ///////////////////////////////////////////////////////////////////////////////
|
---|
2 | //
|
---|
3 | // ## ######
|
---|
4 | // ###### ###
|
---|
5 | // ## ############### Shark 3D Engine (www.shark3d.com)
|
---|
6 | // ########## # # #
|
---|
7 | // ######## Copyright (c) 1996-2006 Spinor GmbH.
|
---|
8 | // ######### # # # All rights reserved.
|
---|
9 | // ## ##########
|
---|
10 | // ##
|
---|
11 | //
|
---|
12 | ///////////////////////////////////////////////////////////////////////////////
|
---|
13 |
|
---|
14 | struct PS_INPUT
|
---|
15 | {
|
---|
16 | float2 mainTexCoord: TEXCOORD0;
|
---|
17 | float2 offsScale: TEXCOORD1;
|
---|
18 | };
|
---|
19 |
|
---|
20 | ///////////////////////////////////////////////////////////////////////////////
|
---|
21 |
|
---|
22 | sampler tex0: register(s0);
|
---|
23 |
|
---|
24 | ///////////////////////////////////////////////////////////////////////////////
|
---|
25 | // Pixelshader
|
---|
26 | // Profile: 2x0
|
---|
27 |
|
---|
28 | float4 main(PS_INPUT input): COLOR0
|
---|
29 | {
|
---|
30 | float2 mainTexCoord = input.mainTexCoord;
|
---|
31 | float2 offsScale = input.offsScale;
|
---|
32 |
|
---|
33 | // Use filtering for additional smoothing effect.
|
---|
34 | // The source-texture should be a filter-texture.
|
---|
35 | // The size (width resp. height) of the destination-texture
|
---|
36 | // should be 2 or 4 smaller than the size of the source-texture.
|
---|
37 | //
|
---|
38 | // Pixel in target-texture: X
|
---|
39 | //
|
---|
40 | // Source-sampling positions: S
|
---|
41 | // *---*
|
---|
42 | // Pixel in source-texture: | |
|
---|
43 | // *---*
|
---|
44 | // downscaling by 2 or more
|
---|
45 | // no downscaling
|
---|
46 | // *---*---*---*---*
|
---|
47 | // *---*---*---* | | | | |
|
---|
48 | // | S | | S | *---S---*---S---*
|
---|
49 | // *---*---*---* | | | | |
|
---|
50 | // | | X | | *---*---X---*---*
|
---|
51 | // *---*---*---* | | | | |
|
---|
52 | // | S | | S | *---S---*---S---*
|
---|
53 | // *---*---*---* | | | | |
|
---|
54 | // *---*---*---*---*
|
---|
55 | //
|
---|
56 | // Note: Since this filter cannot sample more than a 4x4 neighbourhood,
|
---|
57 | // downscaling factor of 4 cannot be exceeded without skipping pixels.
|
---|
58 | // With downsampling of 1 or less filtering can't be used for smoothing
|
---|
59 | // because it results in an undesirable filter pattern.
|
---|
60 | // Thus a scaling factor of 2 or 4 is recommanded.
|
---|
61 |
|
---|
62 | const float2 offsPix0 = float2(-1.0f,-1.0f);
|
---|
63 | const float2 offsPix1 = float2( 1.0f,-1.0f);
|
---|
64 | const float2 offsPix2 = float2(-1.0f, 1.0f);
|
---|
65 | const float2 offsPix3 = float2( 1.0f, 1.0f);
|
---|
66 |
|
---|
67 | // neighbour texture coordinates:
|
---|
68 | float2 neigh0 = offsScale * offsPix0 + mainTexCoord.xy;
|
---|
69 | float2 neigh1 = offsScale * offsPix1 + mainTexCoord.xy;
|
---|
70 | float2 neigh2 = offsScale * offsPix2 + mainTexCoord.xy;
|
---|
71 | float2 neigh3 = offsScale * offsPix3 + mainTexCoord.xy;
|
---|
72 |
|
---|
73 | float4 avg =
|
---|
74 | (tex2D(tex0, neigh0)
|
---|
75 | + tex2D(tex0, neigh1)
|
---|
76 | + tex2D(tex0, neigh2)
|
---|
77 | + tex2D(tex0, neigh3)) * 0.25;
|
---|
78 | return clamp(avg - 0.8, 0.0, 1.0) * 5.0; // STD
|
---|
79 | }
|
---|
80 |
|
---|
81 | ///////////////////////////////////////////////////////////////////////////////
|
---|