Ignore:
Timestamp:
03/09/07 10:31:48 (17 years ago)
Author:
szirmay
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Illum/Ogre/Media/PMDemo/PathMapWeightCompute.hlsl

    r2213 r2217  
    11#define SAMPLECUTDIST2 0.01 
    2 #define WEIGHTCUTOFF 0.01 
     2#define WEIGHTCUTOFF   0.01 
     3#define DIST_BIAS      0.005 
    34 
    45uniform int nRadionColumns; 
    5 uniform sampler2D radionSampler       : register(s0); 
    6 uniform sampler2D entryPointCountSampler : register(s1); 
    7 uniform sampler2D allWeightsSampler   : register(s2); 
    86uniform float3 lightPos; 
    97uniform float3 lightDir; 
    108uniform float clusterCount; 
     9uniform float4x4 lightViewProj; 
     10uniform float lightFarPlane; 
    1111 
    1212struct vsInputComputeWeights 
     
    2828    output.pos = input.pos; 
    2929    output.tex = (input.pos + 1.0) / 2.0; 
     30    //output.tex = input.tex; 
    3031    output.tex.y = 1.0 - output.tex.y; 
     32    
    3133    return output; 
    3234} 
    3335 
    34 float4 psComputeWeights(vsOutputComputeWeights input) : COLOR0 
     36float4 psComputeWeights(vsOutputComputeWeights input, 
     37                                                uniform sampler2D radionSampler : register(s0), 
     38                                                uniform sampler2D shadowMap : register(s1)) : COLOR0 
    3539{ 
    3640        float dataColumnWidth = 1.0 / (float)nRadionColumns; 
     
    4953        float cosb = max(dot(dir, diff), 0);     
    5054         
    51         /* 
    52         float4 occProjPos = mul(float4(pos, 1), occWorldToProjMatrix);   
    53         occProjPos /= occProjPos.w; 
    54         float2 occTexPos = mul( occProjPos.xyw, occProjToTexMatrix); 
    55         float visibility = tex2Dproj(depthMapSampler, float4(occTexPos, occProjPos.z - 0.1, 1) ); 
     55         
     56        float4 lightVPos = mul(lightViewProj, float4(pos,1)); 
     57        float dist = sqrt(dist2) / lightFarPlane; 
     58        lightVPos /= lightVPos.w; 
     59        lightVPos.xy = (lightVPos.xy + 1.0) / 2.0; 
     60        lightVPos.y = 1.0 - lightVPos.y; 
     61        float storedDist = tex2D(shadowMap, lightVPos.xy).r; 
     62        dist -= DIST_BIAS; 
     63        float visibility = (dist <= storedDist);         
    5664 
    57         float3 lightToPos = pos - lightPos; 
    58         float actualDepth = length(lightToPos); 
    59 */ 
    60         float visibility = 1; 
     65        //float visibility = 1; 
     66        //visibility = visibility * 0.00001 + 1.0; 
    6167         
    62         float4 ret = pow(cosa, 9) * cosb / dist2; 
    63  
    64         //float ize = 0; 
    65         //if(pos.y > 0) ize = 1; 
    66         //return float4(lightDir + ret.x * 0.00000000001, 1); 
    67         //return ret; 
     68        float4 ret = visibility * pow(cosa, 9) * cosb / dist2; 
    6869        return ret; 
    6970} 
    7071 
    71 float4 psSumWeights(vsOutputComputeWeights input) : COLOR0 
     72float4 psSumWeights(vsOutputComputeWeights input, 
     73                                        uniform sampler2D radionSampler       : register(s0), 
     74                                        uniform sampler2D entryPointCountSampler : register(s1), 
     75                                        uniform sampler2D allWeightsSampler   : register(s2)) : COLOR0 
    7276{ 
    7377        float halfPixel = 0.5 / clusterCount; 
     
    8084        for(int i = 0; i < entryPointCount; i++) 
    8185        { 
    82                 float hp = float2(0.5 / (float) nRadionColumns, 0.5 / 4096.0); 
    83                 float2 coord1 = float2((float)(currentEntryPoint % nRadionColumns)  / (float) nRadionColumns, 
    84                                                                 currentEntryPoint / (float) nRadionColumns / 4096.0) + hp; 
    85                 float2 coord2 = coord1 + float2(hp.x / 2.0, 0); 
    86                 float radrad = tex2Dlod(radionSampler, float4(coord2, 0, 0)).a; 
    87                 //weight += tex2Dlod(allWeightsSampler, float4(coord1, 0, 0)).r * radrad; 
    88                 weight += tex2Dlod(allWeightsSampler, float4(coord1, 0, 0)).r; 
     86                 
     87                float dataColumnWidth = 1.0 / (float)nRadionColumns; 
     88                int werx = currentEntryPoint % nRadionColumns; 
     89                int wery = currentEntryPoint / nRadionColumns; 
     90                float2 coord1 = float2((werx + 0.5) * dataColumnWidth, (wery  + 0.5) / 4096.0); 
     91                float2 coord2 = coord1 + float2(0.25 * dataColumnWidth, 0); 
     92                float w = tex2Dlod(allWeightsSampler, float4(coord1, 0, 0)).r; 
     93                float radrad = tex2Dlod(radionSampler, float4(coord1, 0, 0)).a;          
     94                weight += w * radrad;            
    8995                clusterRad += radrad; 
    9096                currentEntryPoint++; 
    9197        }        
    9298         
    93         /*if(clusterRad >= 0) 
     99        if(clusterRad >= 0) 
    94100                weight /= clusterRad; 
    95101        else 
    96                 weight = 0;*/ 
    97                          
    98     weight /= (float) entryPointCount; 
    99                  
     102                weight = 0; 
     103    
    100104        return weight; 
    101105} 
Note: See TracChangeset for help on using the changeset viewer.