我是着色器编程的新手。只是有些人对下面的代码感到困惑,"noiseCoord.xy“除以5,这真的是很大的denominator.for我所知道的,noiseCoord应该像往常一样从0.0到1.0。其实我有这么多这样的情况,都是被一个大分母除以的。它有实验价值吗?希望你们能帮我找出答案。非常感谢您的支持!
//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);
}发布于 2016-11-12 23:16:40
是的,看起来它对我来说没有很好的理由。着色器代码已经在顶点着色器中应用了一个比例因子(称为“比例”的均匀比例)。在片段着色器中应用另一个硬编码的比例因子对我来说似乎是不合理的。在CPU上,只要将均匀的“比例”乘以0.2f,效率就会提高许多倍。
https://stackoverflow.com/questions/40564025
复制相似问题