03.05.2014, 17:17
|
#120
|
Бывалый
Регистрация: 23.11.2011
Сообщений: 863
Написано 334 полезных сообщений (для 866 пользователей)
|
Ответ: Xors3D. Шейдеры. Урок первый
Мой семпл BPCM (Box Projected Cube Map)
Автогенератор нормалей (Приятная мелочь)
float3 AutoNormalGen(sampler2D sample,float2 texCoord) {
float off = 1.0 / 512;
float4 lightness = float4(0.2,0.59,0.11,0);
// Take all neighbor samples
float4 s00 = tex2D(sample, texCoord + float2(-off, -off));
float4 s01 = tex2D(sample, texCoord + float2( 0, -off));
float4 s02 = tex2D(sample, texCoord + float2( off, -off));
float4 s10 = tex2D(sample, texCoord + float2(-off, 0));
float4 s12 = tex2D(sample, texCoord + float2( off, 0));
float4 s20 = tex2D(sample, texCoord + float2(-off, off));
float4 s21 = tex2D(sample, texCoord + float2( 0, off));
float4 s22 = tex2D(sample, texCoord + float2( off, off));
// Slope in X direction
float4 sobelX = s00 + 2 * s10 + s20 - s02 - 2 * s12 - s22;
// Slope in Y direction
float4 sobelY = s00 + 2 * s01 + s02 - s20 - 2 * s21 - s22;
// Weight the slope in all channels, we use grayscale as height
float sx = dot(sobelX, lightness);
float sy = dot(sobelY, lightness);
// Compose the normal
float3 normal = normalize(float3(sx, sy, 1));
// Pack [-1, 1] into [0, 1]
return normal * 0.5 + 0.5;
}
|
(Offline)
|
|