2016-11-12 87 views
0

我是着色器編程的新手,只是對下面的代碼感到迷惑,它將「noiseCoord.xy」除以5,這是一個很大的分母,儘管我知道noiseCoord的範圍通常在0.0到1.0之間,但實際上我有這麼多的情況,除以一個很大的分母,它是否具有實驗價值?謝謝你在先進的!爲什麼與一個綁定到「TEXCOORD0」語義的變量相關的着色器代碼片段除以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

是的,看起來它沒有充分的理由來給我。這個shader代碼已經在頂點着色器(稱爲「規模」統一)應用比例因子。在片段中應用另一個硬編碼比例因子着色器對我來說似乎是不合理的。在CPU上乘以統一的「比例」0.2f將會高出很多倍。

相關問題