[12115] | 1 | ////////////////////////////////////////////// |
---|
| 2 | // CASTER PASS // |
---|
| 3 | // HEAT // |
---|
| 4 | ////////////////////////////////////////////// |
---|
| 5 | |
---|
| 6 | // vs_1_1 |
---|
| 7 | void HeatCaster_vp( |
---|
| 8 | // in |
---|
| 9 | float4 vPos: POSITION, |
---|
| 10 | float4 vNormal: NORMAL, |
---|
| 11 | |
---|
| 12 | // out |
---|
| 13 | out float4 oPos: POSITION, |
---|
| 14 | out float2 oNDotV: TEXCOORD0, |
---|
| 15 | |
---|
| 16 | // parameters |
---|
| 17 | uniform float4x4 worldViewProj, |
---|
| 18 | uniform float3 eyePosition // object space |
---|
| 19 | ) |
---|
| 20 | { |
---|
| 21 | float4 eyeDir = float4(eyePosition - vPos.xyz, 0); |
---|
| 22 | eyeDir = normalize(eyeDir); |
---|
| 23 | oPos = mul( worldViewProj, vPos ); |
---|
| 24 | oNDotV = clamp( dot( vNormal, eyeDir ), 0, 1 ); |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | // ps_2_0 |
---|
| 28 | float4 HeatCaster_fp( |
---|
| 29 | // input from vp |
---|
| 30 | float2 iNDotV: TEXCOORD0 |
---|
| 31 | ) : COLOR0 |
---|
| 32 | { |
---|
| 33 | return iNDotV.x; |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | ////////////////////////////////////////////// |
---|
| 38 | // CASTER PASS // |
---|
| 39 | // COLD // |
---|
| 40 | ////////////////////////////////////////////// |
---|
| 41 | |
---|
| 42 | // vs_1_1 |
---|
| 43 | void ColdCaster_vp( |
---|
| 44 | // in |
---|
| 45 | float4 vPos: POSITION, |
---|
| 46 | float4 vNormal: NORMAL, |
---|
| 47 | |
---|
| 48 | // out |
---|
| 49 | out float4 oPos: POSITION, |
---|
| 50 | out float2 oNDotV: TEXCOORD0, |
---|
| 51 | |
---|
| 52 | // parameters |
---|
| 53 | uniform float4x4 worldViewProj, |
---|
| 54 | uniform float3 eyePosition // object space |
---|
| 55 | ) |
---|
| 56 | { |
---|
| 57 | float4 eyeDir = float4(eyePosition - vPos.xyz, 0); |
---|
| 58 | eyeDir = normalize(eyeDir); |
---|
| 59 | oPos = mul( worldViewProj, vPos ); |
---|
| 60 | oNDotV = clamp( dot( vNormal, eyeDir ), 0, 1 ); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | // ps_2_0 |
---|
| 64 | float4 ColdCaster_fp( |
---|
| 65 | // input from vp |
---|
| 66 | float2 iNDotV: TEXCOORD0 |
---|
| 67 | ) : COLOR0 |
---|
| 68 | { |
---|
| 69 | return iNDotV.x / 2; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | ////////////////////////////////////////////// |
---|
| 74 | // PASS 1 - Light to heat conversion // |
---|
| 75 | ////////////////////////////////////////////// |
---|
| 76 | |
---|
| 77 | // ps_2_0 |
---|
| 78 | void LightToHeat_fp( |
---|
| 79 | // input from vp |
---|
| 80 | float4 inDiffuse: COLOR0, |
---|
| 81 | float2 inUV0: TEXCOORD0, |
---|
| 82 | |
---|
| 83 | // out |
---|
| 84 | out float4 outColor: COLOR0, |
---|
| 85 | |
---|
| 86 | // params |
---|
| 87 | uniform float4 random_fractions, |
---|
| 88 | uniform float4 heatBiasScale, |
---|
| 89 | uniform float4 depth_modulator, |
---|
| 90 | |
---|
| 91 | uniform sampler2D Input, // output of HeatVisionCaster_fp (NdotV) |
---|
| 92 | uniform sampler2D NoiseMap, |
---|
| 93 | uniform sampler2D HeatLookup |
---|
| 94 | ) |
---|
| 95 | { |
---|
| 96 | float depth, heat, interference; |
---|
| 97 | |
---|
| 98 | // Output constant color: |
---|
| 99 | depth = tex2D( Input, inUV0 ); |
---|
| 100 | depth *= (depth * depth_modulator); |
---|
| 101 | |
---|
| 102 | heat = (depth * heatBiasScale.y); |
---|
| 103 | |
---|
| 104 | // if (depth > 0) |
---|
| 105 | { |
---|
| 106 | interference = -0.5 + tex2D( NoiseMap, inUV0 + float2( random_fractions.x, random_fractions.y ) ); |
---|
| 107 | interference *= interference; |
---|
| 108 | interference *= 1 - heat; |
---|
| 109 | heat += interference;//+ heatBiasScale.x; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | /* |
---|
| 113 | heatBias isn't used for now |
---|
| 114 | if (heat > 0) |
---|
| 115 | heat += heatBiasScale.x; |
---|
| 116 | */ |
---|
| 117 | |
---|
| 118 | // Clamp UVs |
---|
| 119 | heat = max( 0.005, min( 0.995, heat ) ); |
---|
| 120 | outColor = tex2D( HeatLookup, float2( heat, 0.f ) ); |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | ////////////////////////////////////////////// |
---|
| 125 | // PASS 2 - add simple blur (final pass) // |
---|
| 126 | ////////////////////////////////////////////// |
---|
| 127 | |
---|
| 128 | // ps_2_0 |
---|
| 129 | void Blur_fp( |
---|
| 130 | // input from vp |
---|
| 131 | float4 inDiffuse: COLOR0, |
---|
| 132 | float2 inUV0: TEXCOORD0, |
---|
| 133 | |
---|
| 134 | // out |
---|
| 135 | out float4 outColor: COLOR0, |
---|
| 136 | |
---|
| 137 | // parameters |
---|
| 138 | uniform sampler2D Input, // output of HeatVision_fp1 (HeatRenderTexture) |
---|
| 139 | uniform float4 blurAmount |
---|
| 140 | ) |
---|
| 141 | { |
---|
| 142 | int i; |
---|
| 143 | float4 tmpOutColor; |
---|
| 144 | float diffuseGlowFactor; |
---|
| 145 | const float2 offsets[4] = |
---|
| 146 | { |
---|
| 147 | /* |
---|
| 148 | // hazy blur |
---|
| 149 | -1.8, -1.8, |
---|
| 150 | -1.8, 1.8, |
---|
| 151 | 1.8, -1.8, |
---|
| 152 | 1.8, 1.8 |
---|
| 153 | */ |
---|
| 154 | /* |
---|
| 155 | // less-hazy blur |
---|
| 156 | -1.0, 2.0, |
---|
| 157 | -1.0, -1.0, |
---|
| 158 | 1.0, -1.0, |
---|
| 159 | 1.0, 1.0 |
---|
| 160 | */ |
---|
| 161 | /* |
---|
| 162 | -0.326212, -0.405805, |
---|
| 163 | -0.840144, -0.073580, |
---|
| 164 | -0.695914, 0.457137, |
---|
| 165 | -0.203345, 0.620716 |
---|
| 166 | */ |
---|
| 167 | |
---|
| 168 | -0.3, 0.4, |
---|
| 169 | -0.3, -0.4, |
---|
| 170 | 0.3, -0.4, |
---|
| 171 | 0.3, 0.4 |
---|
| 172 | |
---|
| 173 | }; |
---|
| 174 | |
---|
| 175 | tmpOutColor = tex2D( Input, inUV0 ); // UV coords are in image space |
---|
| 176 | |
---|
| 177 | // calculate glow amount |
---|
| 178 | diffuseGlowFactor = 0.0113f * (2.0 - max( tmpOutColor.r, tmpOutColor.g )); |
---|
| 179 | |
---|
| 180 | // basic blur filter |
---|
| 181 | for (i = 0; i < 4; i++) { |
---|
| 182 | tmpOutColor += tex2D( Input, inUV0 + blurAmount.x * diffuseGlowFactor * offsets[i] ); |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | tmpOutColor *= 0.25; |
---|
| 186 | |
---|
| 187 | // TIPS (old-skool strikes again!) |
---|
| 188 | // Pay attention here! If you use the "out float4 outColor" directly |
---|
| 189 | // in your steps while creating the output color (like you remove |
---|
| 190 | // the "tmpOutColor" var and just use the "outColor" directly) |
---|
| 191 | // your pixel-color output IS CHANGING EACH TIME YOU DO AN ASSIGNMENT TOO! |
---|
| 192 | // A temporary variable, instead, acts like a per-pixel double buffer, and |
---|
| 193 | // best of all, lead to better performance. |
---|
| 194 | outColor = tmpOutColor; |
---|
| 195 | } |
---|