오늘은 미쳤나부다.
왜이리 코딩이 잘돼냐
별 거 아닌 기술이지만 그동안 버벅거리던 속도와는 다르게 후다닥 짜버렸다는게 대견.
아주 간단하다.
위 이미지를 이용해서 하이라이트 부분에 뿌려주기만 하면 끝.
그전까지 궁금하던 ‘이미지의 X축에서 값을 받아오는 것’ 은 단순히 셈플러와 tex연산만으로 끝내면 된다는…

그러면, 이런 이미지가 나오게 된다.
// 메탈 느낌의 쉐이더
float4x4 WorldViewProj : WORLDVIEWPROJ ;
float4x4 World : WORLD ;
float4x4 ViewI : VIEWI ;
float3 Lightdirection : DIRECTION
<
string UIName = “DiffuseLight”;
string Object = “Directionallight”;
>;
float3 AmbientColor : AMBIENT
<
string UIName = “AmbientColor”;
> = {0.5f,0.5f,0.5f};
texture2D basetexture : DIFFUSE
<
string UIName = “Basetexture”;
int Texcoord = 0;
int MapChannel = 1;
;
sampler2D BaseSampler = sampler_state
{
texture = ;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};
texture2D Gradienttexture : GRADIENT
<
string UIName = “Gradienttexture”;
int Texcoord = 0;
int MapChannel = 1;
;
sampler2D GradientSampler = sampler_state
{
AddressU = Clamp;
AddressV = Clamp;
texture = ;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};
void VS
(
in float4 iPos : POSITION,
in float4 iNormal : NORMAL,
in float2 itex : TEXCOORD0,
out float4 oPos : POSITION,
out float2 otex : TEXCOORD0,
out float3 Diffuselight : TEXCOORD1,
out float3 Specularlight : TEXCOORD2
)
{
float4 WorldPos = mul(iPos , World) ;
float3 oNormal = normalize(mul(iNormal,(float3x3)World));
float3 ViewDirection = normalize ( ViewI[3].xyz - WorldPos.xyz );
float3 HalfVecter = normalize ( Lightdirection + ViewDirection );
Specularlight = pow(max(0,dot(HalfVecter, oNormal)),20);
Diffuselight = max(0, dot(Lightdirection, oNormal));
oPos = mul(iPos, WorldViewProj);
otex = itex;
}
void PS
(
in float3 itex : TEXCOORD0,
in float3 Diffuselight : TEXCOORD1,
in float3 Specularlight : TEXCOORD2,
out float4 oColor : COLOR
)
{
float3 otex = tex2D(BaseSampler, itex);
float3 Metaltex = tex2D(GradientSampler, Specularlight);
oColor = float4((otex*Diffuselight+AmbientColor + Metaltex),1);
}
technique jp13
{
pass p0
{
AlphaBlendEnable = true;
//SrcBlend = SRCALPHA;
//DestBlend = ONE;
Vertexshader = compile vs_2_0 VS();
Pixelshader = compile ps_2_0 PS();
}
}