Changeset 2175 for GTP/trunk/App/Demos/Illum/Ogre/Media
- Timestamp:
- 02/28/07 18:18:24 (18 years ago)
- Location:
- GTP/trunk/App/Demos/Illum/Ogre/Media/materials
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/GTPMultipleReflection.hlsl
r2131 r2175 10 10 return dist; 11 11 } 12 13 12 14 13 15 #define MAX_LIN_ITERATIONCOUNT 50 //80 14 16 #define MIN_LIN_ITERATIONCOUNT 30 //60 15 17 #define SECANT_ITERATIONCOUNT 1 16 #define MAX_RAY_DEPTH 2 17 18 void linearSearch( float3 x, float3 R, float3 N, samplerCUBE mp, 18 #define MAX_RAY_DEPTH 4 19 20 uniform samplerCUBE mp3Color : register(s0); 21 uniform samplerCUBE mp3Dist : register(s1); 22 uniform samplerCUBE mp1 : register(s2); 23 uniform samplerCUBE mp2 : register(s3); 24 25 26 void linearSearch( float3 x, float3 R, samplerCUBE mp, 19 27 out float3 p, 20 28 out float dl, … … 22 30 out float llp, 23 31 out float ppp) 24 { 25 float3 Ra = abs(R), xa = abs(x); 26 float xm = max(max(xa.x,xa.y),xa.z); 27 float Rm = max(max(Ra.x,Ra.y),Ra.z); 28 float a = xm / Rm; 32 { 33 p = 1; 34 35 float3 Ra = abs(R), xa = abs(x); 36 float a = max(max(xa.x, xa.y), xa.z) / max(max(Ra.x, Ra.y), Ra.z); 37 bool undershoot = false, overshoot = false; 38 39 float dt = length(x / max(max(xa.x, xa.y), xa.z) - R / max(max(Ra.x, Ra.y), Ra.z)) * MAX_LIN_ITERATIONCOUNT; 40 dt = max(dt, MIN_LIN_ITERATIONCOUNT); 41 dt = 1.0 / dt; 29 42 30 int shootL = 0, shootP = 0; 31 bool found = false; 32 33 float dt = length(x / xm - R / Rm) * MAX_LIN_ITERATIONCOUNT; 34 dt = max(dt, MIN_LIN_ITERATIONCOUNT); 35 dt = 1.0 / dt; 36 37 float t = 0.01;//dt; 38 float pa; 39 40 //Linear iteration 41 while(t <= 1.0 && !found) 42 { 43 dp = a * t / (1 - t); 44 p = x + R * dp; 45 pa = readDistanceCubeMap(mp, p); 46 47 if(pa > 0) 48 { 49 ppp = length(p) / pa; 50 if(ppp < 1) 51 shootP = -1; 52 else 53 shootP = 1; 54 if(shootL * shootP == -1) 55 found = true; 56 else 57 { 58 shootL = shootP; 59 dl = dp; 60 llp = ppp; 61 } 62 } 63 else 64 shootL = 0; 65 66 t += dt; 67 } 68 69 if(!found) 70 p = float3(0,0,0); 43 float t = 0.01; 44 while( t < 1 && !(overshoot && undershoot) ) { // iteration 45 float dr = a * t / (1 - t); // ray parameter corresponding to t 46 float3 r = x + R * dr; // point on the ray 47 float ra = readDistanceCubeMap(mp, r); // |p'|: distance direction of p 48 49 50 if (ra > 0) { // valid texel, i.e. anything is visible 51 float rrp = length(r)/ra; //|r|/|r'| 52 if (rrp < 1) { // undershooting 53 dl = dr; // store last undershooting as l 54 llp = rrp; 55 undershoot = true; 56 } else { 57 dp = dr; // store last overshooting as p 58 ppp = rrp; 59 overshoot = true;} 60 } else { // nothing is visible: restart search 61 undershoot = false; 62 overshoot = false; 63 } 64 t += dt; // next texel 65 } 66 67 68 if(!(overshoot && undershoot)) 69 p = float3(0,0,0); 71 70 } 72 71 … … 98 97 } 99 98 100 float3 Hit(float3 x, float3 R, float3 N, 101 samplerCUBE mp1, 102 samplerCUBE mp2, 103 samplerCUBE mp3Color, 104 samplerCUBE mp3Dist, 105 out float4 Il, out float3 Nl) 99 float3 Hit(float3 x, float3 R, out float4 Il, out float3 Nl) 106 100 { 107 101 float dl1 = 0, dp1, llp1, ppp1; 108 102 float3 p1; 109 linearSearch(x, R, N,mp1, p1, dl1, dp1, llp1, ppp1);103 linearSearch(x, R, mp1, p1, dl1, dp1, llp1, ppp1); 110 104 float dl2 = 0, dp2, llp2, ppp2; 111 105 float3 p2; 112 linearSearch(x, R, N,mp2, p2, dl2, dp2, llp2, ppp2);106 linearSearch(x, R, mp2, p2, dl2, dp2, llp2, ppp2); 113 107 114 108 bool valid1 = dot(p1,p1) != 0; … … 120 114 if(!valid1 && ! valid2) 121 115 { 122 linearSearch(x, R, N,mp3Dist, p, dl, dp, llp, ppp);116 linearSearch(x, R, mp3Dist, p, dl, dp, llp, ppp); 123 117 Il.a = 1; 124 118 secantSearch(x, R, mp3Dist, dl, dp, llp, ppp, p); … … 145 139 } 146 140 141 142 143 void SpecularReflectionVS( 144 in float4 Pos : POSITION, // modeling space 145 in float4 Norm : NORMAL, // normal vector 146 out float4 hPos : POSITION, // clipping space 147 out float3 x : TEXCOORD1, // cube map space 148 out float3 N : TEXCOORD2, // normal 149 out float3 V : TEXCOORD3, // view 150 uniform float4x4 WorldViewProj, 151 uniform float4x4 World, 152 uniform float4x4 WorldIT, 153 uniform float3 eyePos // eye position 154 ) { 155 hPos = mul(Pos, WorldViewProj); 156 x = mul(Pos, World).xyz; 157 N = mul(Norm, WorldIT).xyz; 158 V = x - eyePos; 159 } 160 161 float4 SingleReflectionPS( 162 float3 x : TEXCOORD1, // cube map space 163 float3 N : TEXCOORD2, // normal 164 float3 V : TEXCOORD3, // view 165 uniform float Fp0, 166 uniform float3 lastCenter // cube map center position 167 ) : COLOR 168 { 169 x -= lastCenter; 170 V = normalize(V); N = normalize(N); 171 float3 R = reflect(V, N); // reflection dir. 172 float3 Nl; // normal vector at the hit point 173 float3 Il; // radiance at the hit point 174 // ray hit l, radiance Il, normal Nl 175 float3 l = Hit(x, R, Il, Nl); 176 177 // Fresnel reflection 178 float3 F = Fp0 + pow(1-dot(N, -V), 5) * (1 - Fp0); 179 return float4(F * Il, 1); 180 } 181 182 float4 MultipleReflectionPS( 183 float3 x : TEXCOORD1, // shaded point in Cube map space 184 float3 N : TEXCOORD2, // normal vector 185 float3 V : TEXCOORD3, // view direction 186 uniform float3 Fp0, // Fresnel at perpendicular direction 187 uniform float3 refIndex, // index of refraction 188 uniform float3 lastCenter 189 ) : COLOR 190 { 191 x-= lastCenter; 192 V = normalize(V); N = normalize(N); 193 194 float3 I = float3(1, 1, 1);// radiance of the path 195 float3 Fp = Fp0; // Fresnel at 90 degrees at first hit 196 float n = refIndex; // index of refraction of the first hit 197 int depth = 0; // length of the path 198 while (depth < MAX_RAY_DEPTH) { 199 float3 R; // reflection or refraction dir 200 float3 F = Fp + pow(1-abs(dot(N, -V)), 5) * (1-Fp); // Fresnel 201 if (n <= 0) { 202 R = reflect(V, N); // reflection 203 I *= F; // Fresnel reflection 204 } 205 else{ // refraction 206 if (dot(V,N) > 0) { // coming from inside 207 n = 1.0 / n; 208 N = -N; 209 } 210 R = refract(V, N, n); 211 if (dot(R, R) == 0) // no refraction direction exits 212 R = reflect(V, N); // total reflection 213 else 214 I *= (1-F); // Fresnel refraction 215 } 216 217 float3 Nl; // normal vector at the hit point 218 float4 Il; // radiance at the hit point 219 // Trace ray x+R*d and obtain hit l, radiance Il, normal Nl 220 float3 l = Hit(x, R, Il, Nl); 221 if (Il.a == 0) { // hit point is on specular surface 222 depth += 1; 223 } else { // hit point is on diffuse surface 224 I *= Il.rgb; // multiply with the radiance 225 depth = MAX_RAY_DEPTH; // terminate 226 } 227 N = Nl; V = R; x = l; // hit point is the next shaded point 228 } 229 return float4(I, 1); 230 } 231 232 147 233 struct Shaded_OUT 148 234 { … … 152 238 }; 153 239 154 float4 MultipleReflectionPS(Shaded_OUT IN, 155 uniform samplerCUBE CubeMap : register(s0), 156 uniform samplerCUBE DistanceMap : register(s1), 157 uniform samplerCUBE NormDistMap1 : register(s2), 158 uniform samplerCUBE NormDistMap2 : register(s3), 240 float4 MultipleReflectionPS_o(Shaded_OUT IN, 159 241 uniform float3 cameraPos, 160 242 uniform float3 lastCenter) : COLOR0 161 243 { 244 return 1; 162 245 float4 I = float4(0,0,0,0); 163 246 … … 181 264 float3 Nl; 182 265 float4 Il = 0; 183 l = Hit(x, R, N, NormDistMap1, NormDistMap2, CubeMap, DistanceMap,Il, Nl);266 l = Hit(x, R, Il, Nl); 184 267 if(Il.a == 0) 185 268 { … … 197 280 } 198 281 if(I.a == 0) 199 I = readCubeMap( CubeMap, l);282 I = readCubeMap(mp3Color, l); 200 283 201 284 return I; … … 203 286 204 287 float4 MultipleRefractionPS(Shaded_OUT IN, 205 uniform samplerCUBE CubeMap : register(s0),206 uniform samplerCUBE DistanceMap : register(s1),207 uniform samplerCUBE NormDistMap1 : register(s2),208 uniform samplerCUBE NormDistMap2 : register(s3),209 288 uniform float3 cameraPos, 210 uniform float3 lastCenter, 289 uniform float3 lastCenter, 211 290 uniform float sFresnel, 212 291 uniform float refIndex ) : COLOR0 … … 238 317 float3 Nl; 239 318 float4 Il; 240 float3 l = Hit(x, R, N, NormDistMap1, NormDistMap2, CubeMap, DistanceMap,Il, Nl);319 float3 l = Hit(x, R, Il, Nl); 241 320 if(Il.a == 0) 242 321 { … … 252 331 V = R; 253 332 } 254 333 /* 255 334 if(I.a == 0) 256 335 { … … 263 342 float3 R = refract( V, N, ri); 264 343 if(dot(R,R) == 0) R = reflect( V, N); 265 I = readCubeMap( CubeMap, R);344 I = readCubeMap(mp3Color, R); 266 345 } 267 346 */ 268 347 I *= (1.0 - F); 269 348 … … 272 351 273 352 float4 MultipleRefractionPhotonMap_PS(Shaded_OUT IN, 274 uniform samplerCUBE DistanceMap : register(s0),275 uniform samplerCUBE NormDistMap1 : register(s1),276 uniform samplerCUBE NormDistMap2 : register(s2),277 uniform samplerCUBE CubeMap : register(s3), //NOT USED278 353 uniform float3 cameraPos, 279 354 uniform float3 lastCenter, … … 304 379 float3 Nl; 305 380 float4 Il; 306 l = Hit(x, R, N, NormDistMap1, NormDistMap2, CubeMap, DistanceMap,Il, Nl);381 l = Hit(x, R, Il, Nl); 307 382 if(Il.a == 0) 308 383 { -
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPAdvancedEnvMap/multibounce/multipleRefraction/GTPMultipleRefraction.material
r2131 r2175 1 fragment_program GTP/MultiBounce/Refraction_PS hlsl 2 { 3 1 vertex_program GTP/MultiBounce/MultiBounce_VS hlsl 2 { 4 3 source GTPMultipleReflection.hlsl 5 entry_point MultipleRefractionPS 4 entry_point SpecularReflectionVS 5 target vs_3_0 6 } 7 8 //fragment_program GTP/MultiBounce/SingleReflection_PS hlsl 9 //{ 10 // source GTPMultipleReflection.hlsl 11 // entry_point SingleReflectionPS 12 // target ps_3_0 13 // flow_control prefer 14 //} 15 16 fragment_program GTP/MultiBounce/MultipleReflection_PS hlsl 17 { 18 source GTPMultipleReflection.hlsl 19 entry_point MultipleReflectionPS 6 20 target ps_3_0 7 21 flow_control prefer 8 22 } 9 23 24 10 25 material GTP/MultiBounce/Refractor 26 { 27 technique 28 { 29 pass 30 { 31 //cull_hardware none 32 IllumTechniques 33 { 34 RenderTechnique ColorCubeMap 35 { 36 resolution 1024 37 update_interval 1 38 distance_calc false 39 face_angle_calc false 40 update_all_face true 41 42 } 43 RenderTechnique DistanceCubeMap 44 { 45 resolution 1024 46 update_interval 1 47 distance_calc false 48 face_angle_calc false 49 update_all_face true 50 } 51 RenderTechnique ColorCubeMap 52 { 53 resolution 1024 54 layer 1 55 texture_unit_id 2 56 update_interval 1 57 distance_calc false 58 face_angle_calc false 59 update_all_face true 60 render_env false 61 render_self true 62 self_material GTP/MultiBounce/NormalDistanceCCW 63 } 64 RenderTechnique ColorCubeMap 65 { 66 resolution 1024 67 layer 2 68 texture_unit_id 3 69 update_interval 1 70 distance_calc false 71 face_angle_calc false 72 update_all_face true 73 render_env false 74 render_self true 75 self_material GTP/MultiBounce/NormalDistanceCW 76 } 77 } 78 vertex_program_ref GTP/MultiBounce/MultiBounce_VS 79 { 80 param_named_auto WorldViewProj transpose_worldviewproj_matrix 81 param_named_auto World transpose_world_matrix 82 param_named_auto WorldIT inverse_world_matrix 83 param_named_auto eyePos camera_position 84 } 85 fragment_program_ref GTP/MultiBounce/MultipleReflection_PS 86 { 87 param_named refIndex float 0.77 88 param_named Fp0 float 0.1 89 } 90 91 //Cube map of environment 92 texture_unit 93 { 94 //filtering none 95 } 96 //Cube map of environment distances 97 texture_unit 98 { 99 filtering none 100 } 101 102 //Cube map of reflective object's normals and distances CCW 103 texture_unit 104 { 105 filtering none 106 } 107 //Cube map of reflective object's normals and distances CW 108 texture_unit 109 { 110 filtering none 111 } 112 } 113 } 114 } 115 116 117 //fragment_program GTP/MultiBounce/Refraction_PS hlsl 118 //{ 119 // source GTPMultipleReflection.hlsl 120 // entry_point MultipleRefractionPS 121 // target ps_3_0 122 // flow_control prefer 123 //} 124 125 material GTP/MultiBounce/Refractor_0 11 126 { 12 127 technique -
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPCaustic/GTPCaustic.material
r2136 r2175 40 40 param_named_auto WorldView worldview_matrix 41 41 param_named_auto Proj projection_matrix 42 param_named CauSpriteSize float 2042 param_named CauSpriteSize float 10 43 43 } 44 44 fragment_program_ref GTP/Caustic/CauCube_PointSprite_PS 45 45 { 46 param_named CausticColor float4 0.7 0.7 0.5 0.346 param_named CausticColor float4 1 1 1 0.8 47 47 } 48 48 texture_unit … … 120 120 121 121 } 122 vertex_program_ref GTP/Basic/Shaded Tex_VS122 vertex_program_ref GTP/Basic/Shaded_VS 123 123 { 124 124 param_named_auto WorldViewProj worldviewproj_matrix … … 146 146 } 147 147 } 148 149 material GTP/Caustic/Glass_PointSprite 150 { 151 technique 152 { 153 pass 154 { 155 IllumTechniques 156 { 157 RenderTechnique ColorCubeMap 158 { 159 update_interval 1 160 update_all_face true 161 } 162 RenderTechnique DistanceCubeMap 163 { 164 update_interval 1 165 update_all_face true 166 } 167 RenderTechnique CausticCaster 168 { 169 attenuation 1000 170 update_interval 1 171 update_all_face true 172 photonmap_resolution 64 173 caustic_cubemap_resolution 256 174 photon_map_material GTP/Caustic/PhotonMap_HitEnv 175 caustic_map_material GTP/Caustic/CauCube_PointSprite 176 blur_caustic_cubemap false 177 } 178 179 } 180 vertex_program_ref GTP/Basic/Shaded_VS 181 { 182 param_named_auto WorldViewProj worldviewproj_matrix 183 param_named_auto World world_matrix 184 param_named_auto WorldInv inverse_world_matrix 185 } 186 fragment_program_ref GTP/EnvMap/Localized_Refraction_PS 187 { 188 param_named_auto cameraPos camera_position 189 param_named lastCenter float3 0 0 0 190 param_named sFresnel float 0.1 191 param_named sRefraction float 0.9 192 } 193 //Cube map for reflections and refractions 194 texture_unit 195 { 196 197 } 198 //Cube map of distances 199 texture_unit 200 { 201 202 } 203 } 204 } 205 } -
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPEnvMap/GTPEnvMap.hlsl
r2054 r2175 98 98 float3 T = refract(V, N, sRefraction); 99 99 100 RR = R; TT = T; 100 RR = R; TT = T; 101 101 RR = Hit(cubePos, R, DistanceMap); 102 102 TT = Hit(cubePos, T, DistanceMap); -
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPEnvMap/GTPEnvMap.material
r2054 r2175 151 151 } 152 152 } 153 vertex_program_ref GTP/Basic/Shaded Tex_VS153 vertex_program_ref GTP/Basic/Shaded_VS 154 154 { 155 155 param_named_auto WorldViewProj worldviewproj_matrix -
GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/difflab.material
r2139 r2175 116 116 { 117 117 118 RenderTechnique CausticReciever119 {120 max_caster_count 1121 }118 // RenderTechnique CausticReciever 119 // { 120 // max_caster_count 1 121 // } 122 122 RenderTechnique DepthShadowReciever 123 123 { … … 147 147 { 148 148 149 RenderTechnique CausticReciever150 {151 max_caster_count 1152 }149 // RenderTechnique CausticReciever 150 // { 151 // max_caster_count 1 152 // } 153 153 RenderTechnique DepthShadowReciever 154 154 { … … 199 199 { 200 200 201 RenderTechnique CausticReciever202 {203 max_caster_count 1204 }201 //RenderTechnique CausticReciever 202 //{ 203 // max_caster_count 1 204 //} 205 205 RenderTechnique DepthShadowReciever 206 206 { … … 237 237 { 238 238 239 RenderTechnique CausticReciever240 {241 max_caster_count 1242 }239 //RenderTechnique CausticReciever 240 //{ 241 // max_caster_count 1 242 //} 243 243 RenderTechnique DepthShadowReciever 244 244 { … … 293 293 { 294 294 295 RenderTechnique CausticReciever296 {297 max_caster_count 1298 }295 //RenderTechnique CausticReciever 296 //{ 297 // max_caster_count 1 298 //} 299 299 RenderTechnique DepthShadowReciever 300 300 {
Note: See TracChangeset
for help on using the changeset viewer.