[1424] | 1 | #define method1
|
---|
| 2 |
|
---|
| 3 | struct VS_OUT
|
---|
| 4 | {
|
---|
| 5 | float4 hPosition : POSITION;
|
---|
| 6 | float4 cPosition : TEXCOORD1;
|
---|
| 7 | float2 texCoord : TEXCOORD0;
|
---|
| 8 | float r : TEXCOORD2;
|
---|
| 9 | float4 center : TEXCOORD3;
|
---|
| 10 | float4 Color : TEXCOORD4;
|
---|
| 11 | float2 screenCoord : TEXCOORD5;
|
---|
| 12 | };
|
---|
| 13 |
|
---|
| 14 | VS_OUT HPS_Smoke_L_Depth_VS (float4 position : POSITION,
|
---|
| 15 | float4 texCoord : TEXCOORD0,
|
---|
| 16 | float4 Color: COLOR0,
|
---|
| 17 | uniform float baseRadius,
|
---|
| 18 | uniform float4x4 worldView,
|
---|
| 19 | uniform float4x4 Proj,
|
---|
| 20 | uniform float4x4 worldViewProj)
|
---|
| 21 | {
|
---|
| 22 | VS_OUT OUT;
|
---|
| 23 | //texCoord.z = normalize(texCoord.z);
|
---|
| 24 | //texCoord.w = normalize(texCoord.w);
|
---|
| 25 | float2 offset = texCoord.zw * baseRadius;
|
---|
| 26 | OUT.r = abs(offset.x);
|
---|
| 27 | float4 cPosition;
|
---|
| 28 | cPosition = mul(worldView, position);
|
---|
| 29 | OUT.center = cPosition;
|
---|
| 30 | cPosition.xy += offset;
|
---|
| 31 | OUT.cPosition = cPosition;
|
---|
| 32 | OUT.cPosition.z *= -1;
|
---|
| 33 | //OUT.cPosition.z = OUT.cPosition.z - OUT.r;
|
---|
| 34 |
|
---|
| 35 | OUT.hPosition = mul( Proj, cPosition );
|
---|
| 36 | float4 sPosition = OUT.hPosition / OUT.hPosition.w;
|
---|
| 37 | OUT.screenCoord = (sPosition.xy + float2(1, 1)) / 2.0;
|
---|
| 38 | OUT.screenCoord.y = 1.0 - OUT.screenCoord.y;
|
---|
| 39 |
|
---|
| 40 | OUT.texCoord = texCoord.xy;
|
---|
| 41 | OUT.Color = Color;
|
---|
| 42 | return OUT;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 |
|
---|
| 46 | float4 HPS_Smoke_L_Depth_PS(VS_OUT IN,
|
---|
| 47 | uniform float4x4 Proj,
|
---|
| 48 | uniform sampler2D Texture : register(s0),
|
---|
| 49 | uniform sampler2D depthTexture : register(s1),
|
---|
| 50 | uniform float farplane,
|
---|
| 51 | uniform float width = 800,
|
---|
| 52 | uniform float height = 600
|
---|
| 53 | ) : COLOR
|
---|
| 54 | {
|
---|
| 55 | float4 Color = 0;
|
---|
| 56 | float4 impostor = tex2D(Texture, IN.texCoord);
|
---|
| 57 | float f = 1.0 - impostor.g;
|
---|
| 58 | float b = impostor.r;
|
---|
| 59 | float alpha = 0;
|
---|
| 60 |
|
---|
| 61 | if(b == 0)
|
---|
| 62 | discard;
|
---|
| 63 |
|
---|
| 64 | float2 halfpixel = float2(1.0 / width, 1.0 / height);
|
---|
| 65 | IN.screenCoord += halfpixel;
|
---|
| 66 |
|
---|
| 67 | float sceneDepth = tex2D(depthTexture, IN.screenCoord).r;
|
---|
| 68 | if(sceneDepth == 0)
|
---|
| 69 | //discard;
|
---|
| 70 | sceneDepth = farplane;
|
---|
| 71 |
|
---|
| 72 | float size = 2.0 * IN.r;
|
---|
| 73 | float frontDepth = IN.cPosition.z + size * (f - 0.5);
|
---|
| 74 | float backDepth = IN.cPosition.z + size * (b - 0.5);
|
---|
| 75 |
|
---|
| 76 | alpha = (sceneDepth - frontDepth) / (backDepth - frontDepth);
|
---|
| 77 | alpha = saturate(alpha) * impostor.a;
|
---|
| 78 |
|
---|
| 79 | //Color = float4(Color.g, 0, 0, 1);
|
---|
| 80 | Color = float4(1, 1, 1, alpha) * IN.Color;
|
---|
| 81 | //Color = float4(b - 0.5, 0, 0, 1);
|
---|
| 82 | //Color = sceneDepth / farplane;
|
---|
| 83 | //Color = 1;
|
---|
| 84 | return Color;
|
---|
| 85 |
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | struct VS_OUT_ILLUM
|
---|
| 89 | {
|
---|
| 90 | float4 hPosition : POSITION;
|
---|
| 91 | float4 cPosition : TEXCOORD1;
|
---|
| 92 | float2 texCoord : TEXCOORD0;
|
---|
| 93 | float r : TEXCOORD2;
|
---|
| 94 | float4 center : TEXCOORD3;
|
---|
| 95 | float4 Color : TEXCOORD4;
|
---|
| 96 | float2 screenCoord : TEXCOORD5;
|
---|
| 97 | float4 lightCoord : TEXCOORD6;
|
---|
| 98 | };
|
---|
| 99 |
|
---|
| 100 | VS_OUT_ILLUM HPS_Smoke_L_Depth_Illum_VS (float4 position : POSITION,
|
---|
| 101 | float4 texCoord : TEXCOORD0,
|
---|
| 102 | float4 Color: COLOR0,
|
---|
| 103 | uniform float width,
|
---|
| 104 | uniform float height,
|
---|
| 105 | uniform float baseRadius,
|
---|
| 106 | uniform float4x4 worldView,
|
---|
| 107 | uniform float4x4 worldViewInv,
|
---|
| 108 | uniform float4x4 lightViewProj,
|
---|
| 109 | uniform float4x4 Proj,
|
---|
| 110 | uniform float4x4 worldViewProj)
|
---|
| 111 | {
|
---|
| 112 | VS_OUT_ILLUM OUT;
|
---|
| 113 | //texCoord.z = normalize(texCoord.z);
|
---|
| 114 | //texCoord.w = normalize(texCoord.w);
|
---|
| 115 | float2 offset = texCoord.zw * baseRadius;
|
---|
| 116 | OUT.r = abs(offset.x);
|
---|
| 117 | float4 cPosition;
|
---|
| 118 | cPosition = mul(worldView, position);
|
---|
| 119 | OUT.center = cPosition;
|
---|
| 120 | cPosition.xy += offset;
|
---|
| 121 | OUT.cPosition = cPosition;
|
---|
| 122 | OUT.cPosition.z *= -1;
|
---|
| 123 | //OUT.cPosition.z = OUT.cPosition.z - OUT.r;
|
---|
| 124 |
|
---|
| 125 | OUT.hPosition = mul( Proj, cPosition );
|
---|
| 126 | float4 sPosition = OUT.hPosition / OUT.hPosition.w;
|
---|
| 127 | OUT.screenCoord = (sPosition.xy + float2(1, 1)) / 2.0;
|
---|
| 128 | OUT.screenCoord.y = 1.0 - OUT.screenCoord.y;
|
---|
| 129 | float2 halfpixel = float2(1.0 / width, 1.0 / height);
|
---|
| 130 | OUT.screenCoord += halfpixel;
|
---|
| 131 |
|
---|
| 132 |
|
---|
| 133 | OUT.texCoord = texCoord.xy;
|
---|
| 134 | OUT.Color = Color;
|
---|
| 135 | float4 wPosition = mul(worldViewInv, cPosition);
|
---|
| 136 | OUT.lightCoord = mul(lightViewProj, wPosition);
|
---|
| 137 | return OUT;
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | float ext(float z, sampler2D illumVolume, float2 lightCoord)
|
---|
| 141 | {
|
---|
| 142 | float4 extintion = tex2D(illumVolume, lightCoord);
|
---|
| 143 |
|
---|
| 144 | float intensities[5];
|
---|
| 145 | intensities[0] = 1.0;
|
---|
| 146 | intensities[1] = extintion.r;
|
---|
| 147 | intensities[2] = extintion.g;
|
---|
| 148 | intensities[3] = extintion.b;
|
---|
| 149 | intensities[4] = extintion.a;
|
---|
| 150 |
|
---|
| 151 | z = 4.0 * z;
|
---|
| 152 | int start = floor(z);
|
---|
| 153 | return lerp( intensities[start], intensities[start + 1], z - ((float) start));
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | float4 HPS_Smoke_L_Depth_Illum_PS(VS_OUT_ILLUM IN,
|
---|
| 157 | uniform float4x4 Proj,
|
---|
| 158 | uniform sampler2D Texture : register(s0),
|
---|
| 159 | uniform sampler2D depthTexture : register(s1),
|
---|
| 160 | uniform sampler2D illumVolume : register(s2),
|
---|
| 161 | uniform float farplane
|
---|
| 162 | ) : COLOR
|
---|
| 163 | {
|
---|
| 164 | float4 Color = 0;
|
---|
| 165 | float4 impostor = tex2D(Texture, IN.texCoord);
|
---|
| 166 | float f = 1.0 - impostor.g;
|
---|
| 167 | float b = impostor.r;
|
---|
| 168 | float alpha = 0;
|
---|
| 169 |
|
---|
| 170 | if(b == 0)
|
---|
| 171 | discard;
|
---|
| 172 |
|
---|
| 173 | float sceneDepth = tex2D(depthTexture, IN.screenCoord).r;
|
---|
| 174 | if(sceneDepth == 0)
|
---|
| 175 | {
|
---|
| 176 | alpha = impostor.a;
|
---|
| 177 | }
|
---|
| 178 | else
|
---|
| 179 | {
|
---|
| 180 | float size = 2.0 * IN.r;
|
---|
| 181 | float frontDepth = IN.cPosition.z + size * (f - 0.5);
|
---|
| 182 | float backDepth = IN.cPosition.z + size * (b - 0.5);
|
---|
| 183 |
|
---|
| 184 | alpha = (sceneDepth - frontDepth) / (backDepth - frontDepth);
|
---|
| 185 | alpha = saturate(alpha) * impostor.a;
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | float2 lightCoord;
|
---|
| 189 | lightCoord = (IN.lightCoord.xy + float2(1.0, 1.0)) / 2.0;
|
---|
| 190 | lightCoord.y = 1.0 - lightCoord.y;
|
---|
| 191 | float z = IN.lightCoord.z / IN.lightCoord.w;
|
---|
| 192 |
|
---|
| 193 | #ifdef method1
|
---|
| 194 |
|
---|
| 195 | float4 extintion = tex2D(illumVolume, lightCoord);
|
---|
| 196 |
|
---|
| 197 | float intensities[5];
|
---|
| 198 | intensities[0] = 1.0;
|
---|
| 199 | intensities[1] = extintion.r;
|
---|
| 200 | intensities[2] = extintion.g;
|
---|
| 201 | intensities[3] = extintion.b;
|
---|
| 202 | intensities[4] = extintion.a;
|
---|
| 203 |
|
---|
| 204 | float3 start;
|
---|
| 205 | float3 end;
|
---|
| 206 | float3 temp = 1.0;
|
---|
| 207 | float t;
|
---|
| 208 |
|
---|
| 209 | float4 planes = float4(0.33, 0.5, 0.66, 1);
|
---|
| 210 | if(z < planes.x)
|
---|
| 211 | {
|
---|
| 212 | start = intensities[0];
|
---|
| 213 | end = intensities[1];
|
---|
| 214 | t = z / planes.x;
|
---|
| 215 | temp = lerp(start, end, t);
|
---|
| 216 | }
|
---|
| 217 | if(z > planes.x && z < planes.y)
|
---|
| 218 | {
|
---|
| 219 | start = intensities[1];
|
---|
| 220 | end = intensities[2];
|
---|
| 221 | t = (z - planes.x) / (planes.y - planes.x);
|
---|
| 222 | temp = lerp(start, end, t);
|
---|
| 223 | }
|
---|
| 224 | if(z > planes.y && z < planes.z)
|
---|
| 225 | {
|
---|
| 226 | start = intensities[2];
|
---|
| 227 | end = intensities[3];
|
---|
| 228 | t = (z - planes.y) / (planes.z - planes.y);
|
---|
| 229 | temp = lerp(start, end, t);
|
---|
| 230 | }
|
---|
| 231 | if(z > planes.z)
|
---|
| 232 | {
|
---|
| 233 | start = intensities[3];
|
---|
| 234 | end = intensities[4];
|
---|
| 235 | t = (z - planes.z) / (planes.a - planes.z);
|
---|
| 236 | temp = lerp(start, end, t);
|
---|
| 237 | }
|
---|
| 238 | IN.Color.rgb *= temp;
|
---|
| 239 |
|
---|
| 240 | #else
|
---|
| 241 |
|
---|
| 242 | float4 extintion = tex3D(illumVolume, float3(lightCoord, z));
|
---|
| 243 | IN.Color.rgb *= extintion;
|
---|
| 244 | /*
|
---|
| 245 | float intensities[5];
|
---|
| 246 | intensities[0] = 1.0;
|
---|
| 247 | intensities[1] = extintion.r;
|
---|
| 248 | intensities[2] = extintion.g;
|
---|
| 249 | intensities[3] = extintion.b;
|
---|
| 250 | intensities[4] = extintion.a;
|
---|
| 251 |
|
---|
| 252 | z = 4.0 * z;
|
---|
| 253 | int start = floor(z);
|
---|
| 254 | float ext = lerp( intensities[start], intensities[start + 1], z - ((float) start));
|
---|
| 255 | IN.Color.rgb *= ext;*/
|
---|
| 256 |
|
---|
| 257 | #endif
|
---|
| 258 |
|
---|
| 259 | Color = float4(1, 1, 1, alpha) * IN.Color;
|
---|
| 260 | return Color;
|
---|
| 261 |
|
---|
| 262 | }
|
---|
| 263 |
|
---|
| 264 |
|
---|