59 lines
1.8 KiB
Plaintext
59 lines
1.8 KiB
Plaintext
import Common;
|
|
import FluidGridData;
|
|
import LightEnv;
|
|
import MaterialParameter;
|
|
|
|
struct Params
|
|
{
|
|
StructuredBuffer<float> vertexBuffer;
|
|
StructuredBuffer<float> normalBuffer;
|
|
StructuredBuffer<uint> indexBuffer;
|
|
};
|
|
ParameterBlock<Params> params;
|
|
|
|
struct VertexOut
|
|
{
|
|
float3 position_WS : POSITION;
|
|
float4 position_CS : SV_Position;
|
|
float3 normal : NORMAL;
|
|
};
|
|
|
|
[shader("vertex")]
|
|
VertexOut vertexMain(uint vertexId : SV_VertexID)
|
|
{
|
|
VertexOut output;
|
|
uint index = params.indexBuffer[vertexId];
|
|
float3 vertex = float3(params.vertexBuffer[index * 3 + 0],
|
|
params.vertexBuffer[index * 3 + 1],
|
|
params.vertexBuffer[index * 3 + 2]) * 5;
|
|
float3 normal = float3(params.normalBuffer[index * 3 + 0],
|
|
params.normalBuffer[index * 3 + 1],
|
|
params.normalBuffer[index * 3 + 2]);
|
|
output.position_WS = vertex;
|
|
output.position_CS = mul(pViewParams.viewProjectionMatrix, float4(vertex, 1));
|
|
output.normal = normal;
|
|
return output;
|
|
}
|
|
|
|
[shader("pixel")]
|
|
float4 fragmentMain(VertexOut input) : SV_Target
|
|
{
|
|
BlinnPhong brdf;
|
|
brdf.baseColor = float3(0, 0, 1);
|
|
brdf.alpha = 1;
|
|
brdf.specularColor = float3(1, 1, 1);
|
|
brdf.normal = input.normal;
|
|
brdf.shininess = 32;
|
|
brdf.ambient = float3(0.1, 0.1, 0.1);
|
|
brdf.emissive = float3(0, 0, 0);
|
|
float3 result = float3(0, 0, 0);
|
|
float3 viewDir = normalize(pViewParams.cameraPosition_WS.xyz - input.position_WS);
|
|
for(int i = 0; i < pLightEnv.numDirectionalLights; i++)
|
|
{
|
|
LightingParameter lightParams;
|
|
lightParams.position_WS = input.position_WS;
|
|
lightParams.viewDir_WS = viewDir;
|
|
result += pLightEnv.directionalLights[i].illuminate(lightParams, brdf);
|
|
}
|
|
return float4(result, 1);
|
|
} |