Ignore:
Timestamp:
10/17/08 18:33:41 (16 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/App/Demos/Vis/FriendlyCulling/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp

    r3039 r3040  
    478478 
    479479        //InitCg(); 
    480  
     480        ShaderProgram *treeAnimation = loader->CreateVertexProgram("treeanimation", "animateVtx"); 
    481481        const float turbitiy = 5.0f; 
    482482        preetham = new SkyPreetham(turbitiy, skyDome); 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/sky_preetham.cg

    r3009 r3040  
    55 
    66 
    7 struct VertexInput 
     7struct vtxin 
    88{ 
    99        float4 position: POSITION; 
     
    2424        float3 normal: TEXCOORD2; 
    2525        float4 mypos: TEXCOORD3; 
    26         float4 color2: TEXCOORD4; 
    27 }; 
    28  
    29  
    30 struct pixel 
    31 { 
    32         float4 col: COLOR0; 
    33         float4 norm: COLOR1; 
    34         float3 pos: COLOR2; 
     26        float4 hdrColor: TEXCOORD4; 
    3527}; 
    3628 
     
    4436 
    4537        float4 projPos: WPOS; 
    46         float4 worldPos: TEXCOORD1; // world position 
    4738        float3 normal: TEXCOORD2; 
    48         float4 mypos: TEXCOORD3; 
    49         float4 color2: TEXCOORD4; 
     39        float4 hdrColor: TEXCOORD4; 
    5040}; 
     41 
     42 
     43struct fragout 
     44{ 
     45        float4 col: COLOR0; 
     46        float4 norm: COLOR1; 
     47        float3 pos: COLOR2; 
     48}; 
     49 
     50 
     51 
    5152//-------------------------------------------------------------------------------------- 
    5253// Vertex Shaders 
     
    5455 
    5556 
    56 vtxout default_vs(VertexInput IN, 
     57vtxout default_vs(vtxin IN, 
    5758                                  uniform float3 lightDir, 
    5859                                  uniform float2 thetaSun, 
     
    6364                                  uniform float3 dColor, 
    6465                                  uniform float3 eColor, 
    65                                   uniform float4x4 ModelView, 
    6666                                  uniform float multiplier) 
    6767{ 
     
    7070        OUT.position = mul(glstate.matrix.mvp, IN.position); 
    7171 
    72  
    7372        const float dotLN = dot(lightDir, IN.normal);    
    7473        const float cos2gamma = dotLN * dotLN;  
    7574 
    7675        const float gamma = acos(dotLN);     
    77         const float theta = dot(float3(0.0, 0.0, 1.0), IN.normal); 
     76        const float theta = dot(float3(.0f, .0f, 1.0f), IN.normal); 
    7877 
    79     float3 num = (1.0 + aColor * exp(bColor / theta)) * (1.0 + cColor * exp(dColor * gamma) + eColor * cos2gamma);     
    80         float3 den = (1.0 + aColor * exp(bColor)) * (1.0 + cColor * exp(dColor * thetaSun.x) + eColor * thetaSun.y);    
     78    float3 num = (1.0f + aColor * exp(bColor / theta)) * (1.0f + cColor * exp(dColor * gamma) + eColor * cos2gamma);     
     79        float3 den = (1.0f + aColor * exp(bColor)) * (1.0f + cColor * exp(dColor * thetaSun.x) + eColor * thetaSun.y);    
    8180    float3 xyY = (num / den) * zenithColor;     
    8281     
     
    8887         
    8988    const static float3x3 conv_Mat =  
    90                 float3x3(3.240479, -1.537150, -0.498535, 
    91                          -0.969256, 1.875992,  0.041556, 
    92                              0.055648, -0.204043,  1.057311); 
     89                float3x3( 3.240479f, -1.537150f, -0.498535f, 
     90                         -0.969256f,  1.875992f,  0.041556f, 
     91                              0.055648f, -0.204043f,  1.057311f); 
    9392 
    9493        float3 hcol = mul(conv_Mat, XYZ); 
    95         OUT.color = float4(hcol, 1.0); 
     94        OUT.color = float4(hcol, 1.0f); 
    9695 
    9796        OUT.color.rgb *= multiplier; 
    98  
    99         OUT.color2 = OUT.color; 
    100         OUT.worldPos = mul(ModelView, IN.position); 
     97        /// put out color into different color channel to avoid clamping 
     98        OUT.hdrColor  = OUT.color; 
    10199 
    102100        OUT.normal = IN.normal; 
    103         OUT.mypos = OUT.position; 
    104101 
    105102        return OUT; 
     
    107104 
    108105 
    109 pixel frag_skydome(fragin IN) 
     106fragout frag_skydome(fragin IN) 
    110107{ 
    111         pixel pix; 
     108        fragout pix; 
    112109 
    113         pix.col = IN.color2; 
     110        pix.col = IN.hdrColor; 
    114111        pix.col.w = 1e20f; 
    115  
    116         pix.norm.xyz = IN.normal; 
    117         pix.norm.w = IN.mypos.w; 
    118  
    119         //pix.pos = 1e20f; 
     112        pix.norm = IN.normal; 
    120113         
    121114        return pix; 
  • GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/treeanimation.cg

    r3038 r3040  
    44 
    55 
    6  
    7 struct VertexInput 
     6struct vtxin 
    87{ 
    98        float4 position: POSITION; 
     
    2120 
    2221        float4 color: COLOR0;   
    23         float4 worldPos: TEXCOORD1; // world position 
    2422        float3 normal: TEXCOORD2; 
    25         float4 mypos: TEXCOORD3; 
    26         float4 color2: TEXCOORD4; 
     23        float4 eyePos: TEXCOORD3; 
    2724}; 
    2825 
    2926 
    30 struct pixel 
    31 { 
    32         float4 col: COLOR0; 
    33         float4 norm: COLOR1; 
    34         float3 pos: COLOR2; 
    35 }; 
    3627 
    37  
    38 // fragment input 
    39 struct fragin 
    40 { 
    41         float4 color: COLOR0;   
    42         float4 position: POSITION; // eye space 
    43         float4 texCoord: TEXCOORD0;     
    44  
    45         float4 projPos: WPOS; 
    46         float4 worldPos: TEXCOORD1; // world position 
    47         float3 normal: TEXCOORD2; 
    48         float4 mypos: TEXCOORD3; 
    49         float4 color2: TEXCOORD4; 
    50 }; 
    5128//-------------------------------------------------------------------------------------- 
    5229// Vertex Shaders 
     
    5431 
    5532 
    56 vtxout default_vs(VertexInput IN, 
    57                                   uniform float3 lightDir, 
    58                                   uniform float2 thetaSun, 
    59                                   uniform float3 zenithColor, 
    60                                   uniform float3 aColor, 
    61                                   uniform float3 bColor, 
    62                                   uniform float3 cColor, 
    63                                   uniform float3 dColor, 
    64                                   uniform float3 eColor, 
    65                                   uniform float4x4 ModelView, 
    66                                   uniform float multiplier) 
     33vtxout animateVtx(vtxin IN, 
     34                                  uniform float3 windDir, 
     35                                  uniform float windStrength, 
     36                                  uniform float2 minmaxPos, 
     37                                  uniform float timer) 
    6738{ 
    6839        vtxout OUT; 
    6940 
     41        OUT.color = IN.color; 
     42        OUT.texCoord = IN.texCoord; 
     43        // transform the vertex position into eye space 
     44        OUT.eyePos = mul(glstate.matrix.modelview[0], IN.position); 
     45         
     46        const float pos = (minmaxPos.x - IN.position.y / (minmaxPos.x - minmaxPos.y); 
     47 
     48        float factor = windStrength * sin(timer); 
     49 
     50        // displace the input position 
     51        float4 newPos = IN.position + float4(factor * windDir, 0.0f); 
     52        // transform the vertex position into post projection space 
    7053        OUT.position = mul(glstate.matrix.mvp, IN.position); 
    7154 
    72  
    73         const float dotLN = dot(lightDir, IN.normal);    
    74         const float cos2gamma = dotLN * dotLN;  
    75  
    76         const float gamma = acos(dotLN);     
    77         const float theta = dot(float3(0.0, 0.0, 1.0), IN.normal); 
    78  
    79     float3 num = (1.0 + aColor * exp(bColor / theta)) * (1.0 + cColor * exp(dColor * gamma) + eColor * cos2gamma);     
    80         float3 den = (1.0 + aColor * exp(bColor)) * (1.0 + cColor * exp(dColor * thetaSun.x) + eColor * thetaSun.y);    
    81     float3 xyY = (num / den) * zenithColor;     
    82      
    83     float3 XYZ;                                                                                              
    84                                                                                                              
    85     XYZ.x = (xyY.x / xyY.y) * xyY.z;                                                                         
    86         XYZ.y = xyY.z;                                                                                           
    87         XYZ.z = ((1.0f - xyY.x - xyY.y) / xyY.y) * xyY.z;    
    88          
    89     const static float3x3 conv_Mat =  
    90                 float3x3(3.240479, -1.537150, -0.498535, 
    91                          -0.969256, 1.875992,  0.041556, 
    92                              0.055648, -0.204043,  1.057311); 
    93  
    94         float3 hcol = mul(conv_Mat, XYZ); 
    95         OUT.color = float4(hcol, 1.0); 
    96  
    97         OUT.color.rgb *= multiplier; 
    98  
    99         OUT.color2 = OUT.color; 
    100         OUT.worldPos = mul(ModelView, IN.position); 
    101  
    10255        OUT.normal = IN.normal; 
    103         OUT.mypos = OUT.position; 
    10456 
    10557        return OUT; 
    10658} 
    107  
    108  
    109 pixel frag_skydome(fragin IN) 
    110 { 
    111         pixel pix; 
    112  
    113         pix.col = IN.color2; 
    114         pix.col.w = 1e20f; 
    115  
    116         pix.norm.xyz = IN.normal; 
    117         pix.norm.w = IN.mypos.w; 
    118  
    119         //pix.pos = 1e20f; 
    120          
    121         return pix; 
    122 } 
Note: See TracChangeset for help on using the changeset viewer.