1 |
|
---|
2 | float farplane = 1000.0; //far plane
|
---|
3 | float nearplane = 0.1; //far plane
|
---|
4 | float width = 800;
|
---|
5 | float height = 600;
|
---|
6 |
|
---|
7 | struct SBB_VS_OUT
|
---|
8 | {
|
---|
9 | float4 hPosition : POSITION;
|
---|
10 | float4 texCoord : TEXCOORD0;
|
---|
11 | float3 P : TEXCOORD1;
|
---|
12 | float3 Q : TEXCOORD2;
|
---|
13 | float r : TEXCOORD3;
|
---|
14 | float2 screenCoord : TEXCOORD4;
|
---|
15 | float4 color : COLOR0;
|
---|
16 | };
|
---|
17 |
|
---|
18 | SBB_VS_OUT FireVS (float4 position : POSITION,
|
---|
19 | float4 texCoord : TEXCOORD0,
|
---|
20 | float4 color : COLOR,
|
---|
21 | uniform float4x4 worldView,
|
---|
22 | uniform float4x4 Proj,
|
---|
23 | uniform float4x4 worldViewProj)
|
---|
24 | {
|
---|
25 | SBB_VS_OUT OUT;
|
---|
26 |
|
---|
27 | float2 offset = texCoord.zw;
|
---|
28 | float4 cPosition;
|
---|
29 | float4 wPosition = position;
|
---|
30 | cPosition = mul(worldView, wPosition);
|
---|
31 | OUT.P = cPosition.xyz;
|
---|
32 | OUT.P.z = - 1 * OUT.P.z;
|
---|
33 | cPosition.xy += offset;
|
---|
34 | OUT.Q = cPosition.xyz;
|
---|
35 | OUT.Q.z = OUT.P.z;
|
---|
36 | OUT.r = abs(texCoord.z);
|
---|
37 |
|
---|
38 | /*texCoord.y = 1.0 - texCoord.y;
|
---|
39 | float2 offset = texCoord.xy * 2.0 - 1.0;
|
---|
40 | float4 cPosition = mul(worldView, position);
|
---|
41 | OUT.P = cPosition.xyz;
|
---|
42 | OUT.P.z = - 1 * OUT.P.z; // - texCoord.w;
|
---|
43 | cPosition.xy += offset * texCoord.w;
|
---|
44 | OUT.Q = cPosition.xyz;
|
---|
45 | OUT.Q.z = OUT.P.z;
|
---|
46 | OUT.r = texCoord.w;*/
|
---|
47 |
|
---|
48 | OUT.hPosition = mul( Proj, cPosition );
|
---|
49 | OUT.screenCoord = (OUT.hPosition.xy / OUT.hPosition.w + 1.0) / 2.0;
|
---|
50 | OUT.screenCoord.y = 1.0 - OUT.screenCoord.y;
|
---|
51 | OUT.screenCoord += float2(0.5/width, 0.5/height);
|
---|
52 |
|
---|
53 | OUT.texCoord = texCoord;
|
---|
54 | OUT.color = color;
|
---|
55 |
|
---|
56 |
|
---|
57 | return OUT;
|
---|
58 | }
|
---|
59 |
|
---|
60 |
|
---|
61 | void FirePS(SBB_VS_OUT IN ,
|
---|
62 | // in screenCoord : VPOS,
|
---|
63 | uniform sampler2D colorTexture : register(s0),
|
---|
64 | uniform sampler2D DepthMap : register(s1)
|
---|
65 | ,uniform sampler2D PlanckMap : register(s2),
|
---|
66 | uniform sampler2D gradTex : register(s3),
|
---|
67 | uniform sampler2D heatTex : register(s4),
|
---|
68 | uniform float frametime,
|
---|
69 | out float4 Color : COLOR0,
|
---|
70 | out float4 Heat: COLOR1)
|
---|
71 | {
|
---|
72 | Color = IN.color;
|
---|
73 | float alpha = 0;
|
---|
74 |
|
---|
75 |
|
---|
76 | float d = length( IN.Q - IN.P );
|
---|
77 | float Zs;
|
---|
78 |
|
---|
79 | Heat = float4(0,0,0,0.8);
|
---|
80 |
|
---|
81 | if( d < IN.r )
|
---|
82 | {
|
---|
83 | float w = sqrt( IN.r * IN.r - d * d );
|
---|
84 | alpha = w / IN.r;
|
---|
85 | float alpha2 = alpha * alpha;
|
---|
86 | alpha = pow( alpha, 4);
|
---|
87 |
|
---|
88 | float F = IN.Q.z - w;
|
---|
89 | float B = IN.Q.z + w;
|
---|
90 |
|
---|
91 | Zs = tex2D( DepthMap, IN.screenCoord ).r;
|
---|
92 | if(Zs == 0) Zs = farplane;
|
---|
93 | float ds = min( Zs, B ) - max( nearplane, F );
|
---|
94 |
|
---|
95 | alpha *= ds / w * 0.5;
|
---|
96 | //alpha2 *= ds / w * 0.5;
|
---|
97 |
|
---|
98 | Heat.rg = alpha2;
|
---|
99 | }
|
---|
100 | if(alpha == 0)
|
---|
101 | discard;
|
---|
102 |
|
---|
103 | alpha = saturate(alpha);
|
---|
104 | Color.a = alpha * tex2D( colorTexture, IN.texCoord.xy).r ;
|
---|
105 | Color.a *= IN.color.a;
|
---|
106 | Color.rgb *= tex2D( PlanckMap, float2(Color.a, frametime)).rgb;
|
---|
107 | float grad = tex2D(gradTex, IN.texCoord.xy).r;
|
---|
108 | //Color.a *= grad;
|
---|
109 |
|
---|
110 | //Heat.rg *= (tex2D(heatTex, IN.texCoord.xy + frametime).rg * 2.0 - 1.0) * IN.color.a;
|
---|
111 | Heat.rg *= /*grad **/ (tex2D(heatTex, IN.texCoord.xy + frametime).rg * 2.0 - 1.0) * IN.color.a;
|
---|
112 |
|
---|
113 | Color.a *= 10.0;
|
---|
114 | //Color = 1;
|
---|
115 | //Heat = 1;
|
---|
116 | }
|
---|
117 |
|
---|
118 | struct VS_OUT
|
---|
119 | {
|
---|
120 | float4 hPosition : POSITION;
|
---|
121 | float2 texCoord : TEXCOORD0;
|
---|
122 | };
|
---|
123 |
|
---|
124 |
|
---|
125 | float4 FireHeatCompositorPS(VS_OUT IN,
|
---|
126 | uniform float width,
|
---|
127 | uniform float height,
|
---|
128 | uniform sampler2D Scene: register(s0)
|
---|
129 | ,uniform sampler2D FireColor: register(s1)
|
---|
130 | ,uniform sampler2D FireHeatNoise: register(s2)
|
---|
131 | ):COLOR
|
---|
132 | {
|
---|
133 | float maxOffset = 0.045;
|
---|
134 | float4 Color = 1;
|
---|
135 | float2 halfpixel = float2(1.0 / width, 1.0 / height);
|
---|
136 | float2 halfpixel2 = 2*halfpixel;
|
---|
137 |
|
---|
138 | float2 offset = tex2D(FireHeatNoise,IN.texCoord ).rg;
|
---|
139 |
|
---|
140 | offset *= maxOffset;
|
---|
141 | float2 newTex = IN.texCoord + offset;
|
---|
142 | float2 newTex2 = newTex + halfpixel2;
|
---|
143 | newTex = newTex + halfpixel;
|
---|
144 |
|
---|
145 | newTex = saturate(newTex);
|
---|
146 | float4 SceneSample = tex2D(Scene, newTex );
|
---|
147 | float4 FireSample = tex2D(FireColor, newTex2 );
|
---|
148 |
|
---|
149 | Color = SceneSample + FireSample;// + float4(offset,1,1);
|
---|
150 | Color.a = SceneSample.a;
|
---|
151 | return Color;
|
---|
152 | return float4(offset,0,1);
|
---|
153 | }
|
---|
154 |
|
---|