1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| cbuffer wrinkle_weight : register(b0) { float3 red_weights; float3 green_weights; float3 blue_weights; float3 alpha_weights; };
Texture2D baseNormal : register(t0); Texture2D wrinkleMask : register(t1); Texture2D wrinkleNormal : register(t2);
SamplerState baseSampler : register(s0); SamplerState maskSampler : register(s1); SamplerState wrinkleSampler : register(s2);
float computeWeight(uint4 mask) { int rIdx = mask.r / 90; int rOffset = value % 90; float rWeight = step(offset , 75) * clamp(offset * 0.014f , 0.0f , 1.0f) * red_Weight[rIdx];
int gIdx = mask.g / 90; int gOffset = value % 90; float gWeight = step(offset , 75) * clamp(offset * 0.014f , 0.0f , 1.0f) * greend_weight[gIdx];
int bIdx = mask.b / 90; int bOffset = value % 90; float bWeight = step(offset , 75) * clamp(offset * 0.014f , 0.0f , 1.0f) * blue_Weight[bIdx];
int aIdx = mask.a / 90; int aOffset = value % 90; float aWeight = step(offset , 75) * clamp(offset * 0.014f , 0.0f , 1.0f) * alpha_Weight[aIdx];
return max(rWeight , max(gWeight , max(bWeight , aWeight))); }
PixelOut ps_main(PixelIn input) { PixelOut out;
float4 maskColor = wrinkleMask.Sample(maskSampler, input.texcoord); clip(maskColor.r + maskColor.g + maskColor.b + maskColor.a - 0.01f);
uint4 uMask = maskColor * 255; float weight = computeWeight(uMask);
clip(weight - 0.001f);
float3 normalColor = baseNormal.Sample(baseSampler , input.texcoord); normalColor = NormalMapping(input.Normal, input.Tangent, input.Binormal, normalColor);
float3 wrinkleNormalColor = wrinkleNormal.Sample(wrinkleSampler,input.Texcoord); wrinkleNormalColor = NormalMapping(input.Normal, input.Tangent, input.Binormal, wrinkleNormalColor);
out.Normal = lerp(normalColor , wrinkleNormalColor , weight);
return out; }
|
Comments