응애맘마조
231012 강의 본문
물 표현에 있어서 마무리를 지었습니다. hlsl 파일을 2개 사용했습니다.
#include "Common.hlsl"
struct VertexInput
{
float4 Position : POSITION0;
float2 Uv : UV0;
float3 Normal : NORMAL0;
float3 Tangent : TANGENT0;
//정점변환때만 쓰이는 멤버
float4 Indices : INDICES0;
float4 Weights : WEIGHTS0;
};
struct GeometryInput
{
float4 Position : SV_POSITION;
float3 wPosition : POSITION0;
float2 Uv : UV0;
float3 Normal : NORMAL;
float3 Tangent : TANGENT;
float3 Binormal : BINORMAL;
float Clip : SV_ClipDistance0;
};
struct PixelInput
{
uint TargetIndex : SV_RenderTargetArrayIndex;
float4 Position : SV_POSITION;
float3 wPosition : POSITION0;
float2 Uv : UV0;
float3 Normal : NORMAL;
float3 Tangent : TANGENT;
float3 Binormal : BINORMAL;
float Clip : SV_ClipDistance0;
};
GeometryInput VS(VertexInput input)
{
GeometryInput output;
output.Uv = input.Uv;
Matrix world;
[flatten]
if (input.Weights.x)
world = SkinWorld(input.Indices, input.Weights);
else
world = World;
output.Position = mul(input.Position, world);
output.Clip = dot(output.Position, ClipPlane);
output.wPosition = output.Position.xyz;
output.Normal = mul(input.Normal, (float3x3) world);
output.Tangent = mul(input.Tangent, (float3x3) world);
output.Binormal = cross(output.Normal.xyz, output.Tangent.xyz);
return output;
}
[maxvertexcount(18)]
void GS(triangle GeometryInput input[3], inout TriangleStream<PixelInput> stream)
{
int vertex = 0;
PixelInput output;
[unroll(6)]
for (int i = 0; i < 6; i++)
{
output.TargetIndex = i;
[unroll(3)]
for (vertex = 0; vertex < 3; vertex++)
{
output.Position = input[vertex].Position;
output.Position = mul(output.Position, (CubeViews[i]));
output.Position = mul(output.Position, CubeProjection);
output.Uv = input[vertex].Uv;
output.Normal = input[vertex].Normal;
output.Binormal = input[vertex].Binormal;
output.Tangent = input[vertex].Tangent;
output.wPosition = input[vertex].wPosition;
output.Clip = input[vertex].Clip;
stream.Append(output);
}
stream.RestartStrip();
}
}
float4 PS(PixelInput input) : SV_TARGET
{
float4 BaseColor = DiffuseMapping(input.Uv);
float3 Normal = NormalMapping(input.Normal, input.Tangent, input.Binormal, input.Uv);
BaseColor = Lighting(BaseColor, input.Uv, Normal, input.wPosition);
return BaseColor;
}
#include "Common.hlsl"
struct VertexInput
{
float4 Position : POSITION0;
float2 Uv : UV0;
float3 Normal : NORMAL0;
float4 Weights : WEIGHTS0;
};
struct GeometryInput
{
float4 Position : SV_POSITION;
float3 Normal : NORMAL0;
float3 wPosition : POSITION0;
float2 Uv : UV0;
float4 Weights : WEIGHTS0;
float Clip : SV_ClipDistance0;
};
struct PixelInput
{
uint TargetIndex : SV_RenderTargetArrayIndex;
float4 Position : SV_POSITION;
float3 Normal : NORMAL0;
float3 wPosition : POSITION0;
float2 Uv : UV0;
float4 Weights : WEIGHTS0;
float Clip : SV_ClipDistance0;
};
GeometryInput VS(VertexInput input)
{
GeometryInput output;
output.Uv = input.Uv;
output.Position = mul(input.Position, World);
output.Clip = dot(output.Position, ClipPlane);
output.wPosition = output.Position.xyz;
output.Normal = mul(input.Normal, (float3x3) World);
output.Weights = input.Weights;
return output;
}
[maxvertexcount(18)]
void GS(triangle GeometryInput input[3], inout TriangleStream<PixelInput> stream)
{
int vertex = 0;
PixelInput output;
[unroll(6)]
for (int i = 0; i < 6; i++)
{
output.TargetIndex = i;
[unroll(3)]
for (vertex = 0; vertex < 3; vertex++)
{
output.Position = input[vertex].Position;
output.Position = mul(output.Position, (CubeViews[i]));
output.Position = mul(output.Position, CubeProjection);
output.Uv = input[vertex].Uv;
output.Normal = input[vertex].Normal;
output.Weights = input[vertex].Weights;
output.wPosition = input[vertex].wPosition;
output.Clip = input[vertex].Clip;
stream.Append(output);
}
stream.RestartStrip();
}
}
float4 PS(PixelInput input) : SV_TARGET
{
float4 BaseColor = 0;
[flatten]
if (Kd.a)
BaseColor += TextureD.Sample(SamplerD, input.Uv) * input.Weights.y;
[flatten]
if (Ks.a)
BaseColor += TextureS.Sample(SamplerS, input.Uv) * input.Weights.z;
[flatten]
if (Ka.a)
BaseColor += TextureN.Sample(SamplerN, input.Uv) * input.Weights.x;
[flatten]
if (Ke.a)
BaseColor += TextureE.Sample(SamplerE, input.Uv) * input.Weights.w;
float3 SpecularMap = float3(1, 1, 1);
float4 Result = float4(DirLighting(BaseColor.rgb, SpecularMap,
normalize(input.Normal.xyz), input.wPosition),
BaseColor.a);
if (Result.a > Opacity)
Result.a = Opacity;
//광원 수만큼 반복
for (int i = 0; i < lights[0].Size; i++)
{
[flatten]
if (!lights[i].isActive)
continue;
[flatten]
if (lights[i].Type == 0)
{
Result.rgb += PointLighting(BaseColor.rgb, SpecularMap,
input.Normal.xyz, input.wPosition, i);
}
else if (lights[i].Type == 1)
{
Result.rgb += SpotLighting(BaseColor.rgb, SpecularMap,
input.Normal.xyz, input.wPosition, i);
}
}
//발광
//Ambient
Result.rgb += Ka.rgb * BaseColor.rgb;
return Result;
}
정점 타입에 따라 4번과 5번으로 파일을 사용했습니다.
읽어주셔서 감사합니다.
Comments