2016-11-12 10 views
0

シェーダのプログラミングには新しく、以下のコードについて混乱させるだけである。 "noiseCoord.xy"それは本当に大きな分母です。私が知っているすべてのために、noiseCoordは通常0.0から1.0の範囲にあるべきです。実際には、このような状況がかなりあり、大きな分母で分けられました。実験値ですか? 。高度にありがとうございました!"TEXCOORD0"セマンティクスにバインドされた1つの変数に関連するシェーダスニペットが5で除算された理由

 //Vertex program 
     void main_vp_old(
       float4 pos   : POSITION, 
       float4 normal  : NORMAL, 
       float2 tex   : TEXCOORD0, 

       out float4 oPos  : POSITION, 
       out float fresnel : COLOR, 
       out float3 noiseCoord : TEXCOORD0, 
       out float4 projectionCoord : TEXCOORD1, 

       uniform float4x4 worldViewProjMatrix, 
       uniform float3 eyePosition, // object space 
       uniform float fresnelBias, 
       uniform float fresnelScale, 
       uniform float fresnelPower, 
       uniform float timeVal, 
       uniform float scale, // the amount to scale the noise texture by 
       uniform float scroll, // the amount by which to scroll the noise 
       uniform float noise // the noise perturb as a factor of the time 
       ) 
     { 
      oPos = mul(worldViewProjMatrix, pos); 
      .......................................... 
      .......................................... 
      // Noise map coords 
      noiseCoord.xy = (tex + (timeVal * scroll)) * scale; 
      noiseCoord.z = noise * timeVal; 
      .......................................... 
     } 







// Fragment program for distorting a texture using a 3D noise texture 
    void main_fp(
      float3 noiseCoord   : TEXCOORD0, 
      float4 projectionCoord  : TEXCOORD1, 
      float3 eyeDir    : TEXCOORD2, 
      float3 normal    : TEXCOORD3, 

      out float4 col  : COLOR, 

      uniform float4 tintColour, 
      uniform float noiseScale, 
      uniform float fresnelBias, 
      uniform float fresnelScale, 
      uniform float fresnelPower, 
      uniform sampler2D noiseMap : register(s0), 
      uniform sampler2D reflectMap : register(s1), 
      uniform sampler2D refractMap : register(s2) 
      ) 
    { 
     // Do the tex projection manually so we can distort _after_ 
     float2 final = projectionCoord.xy/projectionCoord.w; 

     // just here, why was divided by such 5 instead of others? 
     float3 noiseNormal = (tex2D(noiseMap, (noiseCoord.xy/5)).rgb - 0.5).rbg * noiseScale; 


     final += noiseNormal.xz; 

     // Fresnel 
     //normal = normalize(normal + noiseNormal.xz); 
     float fresnel = fresnelBias + fresnelScale * pow(1 + dot(eyeDir, normal), fresnelPower); 

     // Reflection/refraction 
     float4 reflectionColour = tex2D(reflectMap, final); 
     float4 refractionColour = tex2D(refractMap, final) + tintColour; 

     // Final colour 
     col = lerp(refractionColour, reflectionColour, fresnel); 

    } 

答えて

0

はい、それは私にはそこに何の正当な理由を持っていないように見えます。シェーダコードはすでに頂点シェーダ(「スケール」と呼ばれる均一)でのスケール係数を適用しています。フラグメントに別のハードコーディングされたスケールファクタを適用するシェイダーは私には正当ではないようです。 CPU上で均一な「スケール」に0.2fを掛けるほうが何倍も効率的です。

関連する問題