Ignore:
Timestamp:
02/28/07 18:18:24 (18 years ago)
Author:
szirmay
Message:
 
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  
    1010        return dist; 
    1111} 
     12 
     13 
    1214 
    1315#define MAX_LIN_ITERATIONCOUNT 50  //80 
    1416#define MIN_LIN_ITERATIONCOUNT 30  //60 
    1517#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 
     20uniform samplerCUBE mp3Color : register(s0); 
     21uniform samplerCUBE mp3Dist : register(s1); 
     22uniform samplerCUBE mp1 : register(s2); 
     23uniform samplerCUBE mp2 : register(s3); 
     24                                                         
     25 
     26void linearSearch(  float3 x, float3 R, samplerCUBE mp, 
    1927                    out float3 p, 
    2028                    out float dl, 
     
    2230                    out float llp, 
    2331                    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; 
    2942  
    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);  
    7170} 
    7271 
     
    9897} 
    9998 
    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) 
     99float3 Hit(float3 x, float3 R, out float4 Il, out float3 Nl) 
    106100{ 
    107101 float dl1 = 0, dp1, llp1, ppp1; 
    108102 float3 p1; 
    109  linearSearch(x, R, N, mp1, p1, dl1, dp1, llp1, ppp1); 
     103 linearSearch(x, R, mp1, p1, dl1, dp1, llp1, ppp1); 
    110104 float dl2 = 0, dp2, llp2, ppp2; 
    111105 float3 p2; 
    112  linearSearch(x, R, N, mp2, p2, dl2, dp2, llp2, ppp2); 
     106 linearSearch(x, R, mp2, p2, dl2, dp2, llp2, ppp2); 
    113107  
    114108 bool valid1 = dot(p1,p1) != 0; 
     
    120114 if(!valid1 && ! valid2) 
    121115 { 
    122     linearSearch(x, R, N, mp3Dist, p, dl, dp, llp, ppp); 
     116    linearSearch(x, R, mp3Dist, p, dl, dp, llp, ppp); 
    123117    Il.a = 1;  
    124118    secantSearch(x, R, mp3Dist, dl, dp, llp, ppp, p); 
     
    145139} 
    146140 
     141 
     142 
     143void 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 
     161float4 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 
     182float4 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 
    147233struct Shaded_OUT 
    148234{ 
     
    152238}; 
    153239 
    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), 
     240float4 MultipleReflectionPS_o(Shaded_OUT IN, 
    159241                                                        uniform float3 cameraPos, 
    160242                                                        uniform float3 lastCenter) : COLOR0 
    161243{        
     244        return 1; 
    162245         float4 I = float4(0,0,0,0); 
    163246                         
     
    181264           float3 Nl; 
    182265           float4 Il = 0; 
    183            l = Hit(x, R, N, NormDistMap1, NormDistMap2, CubeMap, DistanceMap, Il, Nl); 
     266           l = Hit(x, R, Il, Nl); 
    184267           if(Il.a == 0) 
    185268           {        
     
    197280        } 
    198281        if(I.a == 0) 
    199            I = readCubeMap(CubeMap, l); 
     282           I = readCubeMap(mp3Color, l); 
    200283         
    201284        return I; 
     
    203286 
    204287float4 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), 
    209288                                                        uniform float3 cameraPos, 
    210                                                         uniform float3 lastCenter, 
     289                                                        uniform float3 lastCenter,                                                       
    211290                                                        uniform float sFresnel, 
    212291                                                        uniform float refIndex ) : COLOR0 
     
    238317          float3 Nl; 
    239318          float4 Il; 
    240           float3 l = Hit(x, R, N, NormDistMap1, NormDistMap2, CubeMap, DistanceMap, Il, Nl); 
     319          float3 l = Hit(x, R, Il, Nl); 
    241320          if(Il.a == 0) 
    242321          {                
     
    252331          V = R;                    
    253332        }  
    254                  
     333        /*       
    255334        if(I.a == 0) 
    256335        { 
     
    263342         float3 R = refract( V, N, ri); 
    264343         if(dot(R,R) == 0) R = reflect( V, N); 
    265          I = readCubeMap(CubeMap, R); 
     344         I = readCubeMap(mp3Color, R); 
    266345        } 
    267          
     346        */ 
    268347        I *= (1.0 - F);  
    269348     
     
    272351 
    273352float4 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 USED 
    278353                                                                        uniform float3 cameraPos, 
    279354                                                                        uniform float3 lastCenter, 
     
    304379          float3 Nl; 
    305380          float4 Il; 
    306           l = Hit(x, R, N, NormDistMap1, NormDistMap2, CubeMap, DistanceMap, Il, Nl); 
     381          l = Hit(x, R, Il, Nl); 
    307382          if(Il.a == 0) 
    308383          { 
  • 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          
     1vertex_program GTP/MultiBounce/MultiBounce_VS hlsl 
     2{        
    43        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 
     16fragment_program GTP/MultiBounce/MultipleReflection_PS hlsl 
     17{        
     18        source GTPMultipleReflection.hlsl 
     19   entry_point MultipleReflectionPS 
    620        target ps_3_0 
    721        flow_control prefer 
    822} 
    923 
     24 
    1025material 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 
     125material GTP/MultiBounce/Refractor_0 
    11126{  
    12127   technique  
  • GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPCaustic/GTPCaustic.material

    r2136 r2175  
    4040     param_named_auto WorldView     worldview_matrix 
    4141     param_named_auto Proj          projection_matrix 
    42      param_named CauSpriteSize      float 20 
     42     param_named CauSpriteSize      float 10 
    4343   }  
    4444   fragment_program_ref GTP/Caustic/CauCube_PointSprite_PS 
    4545   { 
    46      param_named CausticColor float4          0.7 0.7 0.5 0.3 
     46     param_named CausticColor float4          1 1 1 0.8 
    4747   } 
    4848   texture_unit 
     
    120120                         
    121121                 }       
    122          vertex_program_ref GTP/Basic/ShadedTex_VS 
     122         vertex_program_ref GTP/Basic/Shaded_VS 
    123123         {        
    124124            param_named_auto WorldViewProj worldviewproj_matrix  
     
    146146   } 
    147147} 
     148 
     149material 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  
    9898        float3 T = refract(V, N, sRefraction); 
    9999                 
    100         RR = R; TT = T; 
     100        RR = R; TT = T;  
    101101        RR = Hit(cubePos, R, DistanceMap); 
    102102        TT = Hit(cubePos, T, DistanceMap); 
  • GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPEnvMap/GTPEnvMap.material

    r2054 r2175  
    151151                        }                        
    152152                 }       
    153              vertex_program_ref GTP/Basic/ShadedTex_VS 
     153             vertex_program_ref GTP/Basic/Shaded_VS 
    154154         {        
    155155            param_named_auto WorldViewProj worldviewproj_matrix  
  • GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/difflab.material

    r2139 r2175  
    116116                    { 
    117117                         
    118                         RenderTechnique CausticReciever 
    119                         { 
    120                                 max_caster_count        1                                        
    121                         } 
     118                        // RenderTechnique CausticReciever 
     119                        // { 
     120                        //      max_caster_count        1                                        
     121                        // } 
    122122                         RenderTechnique DepthShadowReciever 
    123123                         { 
     
    147147                    { 
    148148                         
    149                         RenderTechnique CausticReciever 
    150                         { 
    151                                 max_caster_count        1                                        
    152                         } 
     149                        // RenderTechnique CausticReciever 
     150                        // { 
     151                        //      max_caster_count        1                                        
     152                        // } 
    153153                         RenderTechnique DepthShadowReciever 
    154154                         { 
     
    199199                { 
    200200                         
    201                         RenderTechnique CausticReciever 
    202                         { 
    203                                 max_caster_count        1                                        
    204                         } 
     201                        //RenderTechnique CausticReciever 
     202                        //{ 
     203                        //      max_caster_count        1                                        
     204                        //} 
    205205                        RenderTechnique DepthShadowReciever 
    206206                        { 
     
    237237                { 
    238238                         
    239                         RenderTechnique CausticReciever 
    240                         { 
    241                                 max_caster_count        1                                        
    242                         } 
     239                        //RenderTechnique CausticReciever 
     240                        //{ 
     241                        //      max_caster_count        1                                        
     242                        //} 
    243243                        RenderTechnique DepthShadowReciever 
    244244                        { 
     
    293293                { 
    294294                         
    295                         RenderTechnique CausticReciever 
    296                         { 
    297                                 max_caster_count        1                                        
    298                         } 
     295                        //RenderTechnique CausticReciever 
     296                        //{ 
     297                        //      max_caster_count        1                                        
     298                        //} 
    299299                        RenderTechnique DepthShadowReciever 
    300300                        { 
Note: See TracChangeset for help on using the changeset viewer.