init
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
/* Copyright (c) 2024, Sascha Willems
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 the "License";
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
Texture2DArray textureArray : register(t1);
|
||||
SamplerState samplerArray : register(s1);
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
[[vk::location(0)]] float3 Normal : NORMAL0;
|
||||
[[vk::location(1)]] float3 Color : COLOR0;
|
||||
[[vk::location(2)]] float3 UV : TEXCOORD0;
|
||||
[[vk::location(3)]] float3 ViewVec : TEXCOORD1;
|
||||
[[vk::location(4)]] float3 LightVec : TEXCOORD2;
|
||||
};
|
||||
|
||||
float4 main(VSOutput input) : SV_TARGET
|
||||
{
|
||||
float4 color = textureArray.Sample(samplerArray, input.UV) * float4(input.Color, 1.0);
|
||||
float3 N = normalize(input.Normal);
|
||||
float3 L = normalize(input.LightVec);
|
||||
float3 V = normalize(input.ViewVec);
|
||||
float3 R = reflect(-L, N);
|
||||
float3 diffuse = max(dot(N, L), 0.1) * input.Color;
|
||||
float3 specular = (dot(N, L) > 0.0) ? pow(max(dot(R, V), 0.0), 16.0) * float3(0.75, 0.75, 0.75) * color.r : float3(0.0, 0.0, 0.0);
|
||||
return float4(diffuse * color.rgb + specular, 1.0);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,113 @@
|
||||
/* Copyright (c) 2024, Sascha Willems
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 the "License";
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
struct VSInput
|
||||
{
|
||||
// Vertex attributes
|
||||
[[vk::location(0)]] float3 Pos : POSITION0;
|
||||
[[vk::location(1)]] float3 Normal : NORMAL0;
|
||||
[[vk::location(2)]] float2 UV : TEXCOORD0;
|
||||
|
||||
// Instanced attributes
|
||||
[[vk::location(3)]] float3 instancePos : POSITION1;
|
||||
[[vk::location(4)]] float3 instanceRot : TEXCOORD1;
|
||||
[[vk::location(5)]] float instanceScale : TEXCOORD2;
|
||||
[[vk::location(6)]] int instanceTexIndex : TEXCOORD3;
|
||||
};
|
||||
|
||||
struct UBO
|
||||
{
|
||||
float4x4 projection;
|
||||
float4x4 modelview;
|
||||
float4 lightPos;
|
||||
float locSpeed;
|
||||
float globSpeed;
|
||||
};
|
||||
[[vk::binding(0, 0)]]
|
||||
ConstantBuffer<UBO> ubo : register(b0);
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
[[vk::location(0)]] float3 Normal : NORMAL0;
|
||||
[[vk::location(1)]] float3 Color : COLOR0;
|
||||
[[vk::location(2)]] float3 UV : TEXCOORD0;
|
||||
[[vk::location(3)]] float3 ViewVec : TEXCOORD1;
|
||||
[[vk::location(4)]] float3 LightVec : TEXCOORD2;
|
||||
};
|
||||
|
||||
VSOutput main(VSInput input)
|
||||
{
|
||||
VSOutput output = (VSOutput) 0;
|
||||
output.Color = float3(1.0, 1.0, 1.0);
|
||||
output.UV = float3(input.UV, input.instanceTexIndex);
|
||||
|
||||
// rotate around x
|
||||
float s = sin(input.instanceRot.x + ubo.locSpeed);
|
||||
float c = cos(input.instanceRot.x + ubo.locSpeed);
|
||||
|
||||
float3x3 mx =
|
||||
{
|
||||
c, -s, 0.0,
|
||||
s, c, 0.0,
|
||||
0.0, 0.0, 1.0
|
||||
};
|
||||
|
||||
// rotate around y
|
||||
s = sin(input.instanceRot.y + ubo.locSpeed);
|
||||
c = cos(input.instanceRot.y + ubo.locSpeed);
|
||||
|
||||
float3x3 my =
|
||||
{
|
||||
c, 0.0, -s,
|
||||
0.0, 1.0, 0.0,
|
||||
s, 0.0, c
|
||||
};
|
||||
|
||||
// rot around z
|
||||
s = sin(input.instanceRot.z + ubo.locSpeed);
|
||||
c = cos(input.instanceRot.z + ubo.locSpeed);
|
||||
|
||||
float3x3 mz =
|
||||
{
|
||||
1.0, 0.0, 0.0,
|
||||
0.0, c, -s,
|
||||
0.0, s, c
|
||||
};
|
||||
|
||||
float3x3 rotMat = mul(mz, mul(my, mx));
|
||||
|
||||
float4x4 gRotMat;
|
||||
s = sin(input.instanceRot.y + ubo.globSpeed);
|
||||
c = cos(input.instanceRot.y + ubo.globSpeed);
|
||||
gRotMat[0] = float4(c, 0.0, -s, 0.0);
|
||||
gRotMat[1] = float4(0.0, 1.0, 0.0, 0.0);
|
||||
gRotMat[2] = float4(s, 0.0, c, 0.0);
|
||||
gRotMat[3] = float4(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
float4 locPos = float4(mul(rotMat, input.Pos.xyz), 1.0);
|
||||
float4 pos = float4((locPos.xyz * input.instanceScale) + input.instancePos, 1.0);
|
||||
|
||||
output.Pos = mul(ubo.projection, mul(ubo.modelview, mul(gRotMat, pos)));
|
||||
output.Normal = mul((float3x3) mul(ubo.modelview, gRotMat), mul(rotMat, input.Normal));
|
||||
|
||||
pos = mul(ubo.modelview, float4(input.Pos.xyz + input.instancePos, 1.0));
|
||||
float3 lPos = mul((float3x3) ubo.modelview, ubo.lightPos.xyz);
|
||||
output.LightVec = lPos - pos.xyz;
|
||||
output.ViewVec = -pos.xyz;
|
||||
return output;
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,40 @@
|
||||
/* Copyright (c) 2024, Sascha Willems
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 the "License";
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
Texture2D textureColorMap : register(t1);
|
||||
SamplerState samplerColorMap : register(s1);
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
[[vk::location(0)]] float3 Normal : NORMAL0;
|
||||
[[vk::location(1)]] float3 Color : COLOR0;
|
||||
[[vk::location(2)]] float2 UV : TEXCOORD0;
|
||||
[[vk::location(3)]] float3 ViewVec : TEXCOORD1;
|
||||
[[vk::location(4)]] float3 LightVec : TEXCOORD2;
|
||||
};
|
||||
|
||||
float4 main(VSOutput input) : SV_TARGET
|
||||
{
|
||||
float4 color = textureColorMap.Sample(samplerColorMap, input.UV) * float4(input.Color, 1.0) * 1.5;
|
||||
float3 N = normalize(input.Normal);
|
||||
float3 L = normalize(input.LightVec);
|
||||
float3 V = normalize(input.ViewVec);
|
||||
float3 R = reflect(-L, N);
|
||||
float3 diffuse = max(dot(N, L), 0.0) * input.Color;
|
||||
float3 specular = pow(max(dot(R, V), 0.0), 4.0) * float3(0.5, 0.5, 0.5) * color.r;
|
||||
return float4(diffuse * color.rgb + specular, 1.0);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,57 @@
|
||||
/* Copyright (c) 2024, Sascha Willems
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 the "License";
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
struct VSInput
|
||||
{
|
||||
[[vk::location(0)]] float3 Pos : POSITION0;
|
||||
[[vk::location(1)]] float3 Normal : NORMAL0;
|
||||
[[vk::location(2)]] float2 UV : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct UBO
|
||||
{
|
||||
float4x4 projection;
|
||||
float4x4 modelview;
|
||||
float4 lightPos;
|
||||
};
|
||||
[[vk::binding(0, 0)]]
|
||||
ConstantBuffer<UBO> ubo : register(b0);
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
[[vk::location(0)]] float3 Normal : NORMAL0;
|
||||
[[vk::location(1)]] float3 Color : COLOR0;
|
||||
[[vk::location(2)]] float2 UV : TEXCOORD0;
|
||||
[[vk::location(3)]] float3 ViewVec : TEXCOORD1;
|
||||
[[vk::location(4)]] float3 LightVec : TEXCOORD2;
|
||||
};
|
||||
|
||||
VSOutput main(VSInput input)
|
||||
{
|
||||
VSOutput output = (VSOutput) 0;
|
||||
output.Color = float3(1.0, 1.0, 1.0);
|
||||
output.UV = input.UV * float2(10.0, 6.0);
|
||||
output.Pos = mul(ubo.projection, mul(ubo.modelview, float4(input.Pos.xyz, 1.0)));
|
||||
|
||||
float4 pos = mul(ubo.modelview, float4(input.Pos, 1.0));
|
||||
output.Normal = mul((float3x3) ubo.modelview, input.Normal);
|
||||
float3 lPos = mul((float3x3) ubo.modelview, ubo.lightPos.xyz);
|
||||
output.LightVec = lPos - pos.xyz;
|
||||
output.ViewVec = -pos.xyz;
|
||||
return output;
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,45 @@
|
||||
/* Copyright (c) 2024, Sascha Willems
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 the "License";
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define HASHSCALE3 float3(443.897, 441.423, 437.195)
|
||||
#define STARFREQUENCY 0.01
|
||||
|
||||
// Hash function by Dave Hoskins (https://www.shadertoy.com/view/4djSRW)
|
||||
float hash33(float3 p3)
|
||||
{
|
||||
p3 = frac(p3 * HASHSCALE3);
|
||||
p3 += dot(p3, p3.yxz + float3(19.19, 19.19, 19.19));
|
||||
return frac((p3.x + p3.y) * p3.z + (p3.x + p3.z) * p3.y + (p3.y + p3.z) * p3.x);
|
||||
}
|
||||
|
||||
float3 starField(float3 pos)
|
||||
{
|
||||
float3 color = float3(0.0, 0.0, 0.0);
|
||||
float threshhold = (1.0 - STARFREQUENCY);
|
||||
float rnd = hash33(pos);
|
||||
if (rnd >= threshhold)
|
||||
{
|
||||
float starCol = pow((rnd - threshhold) / (1.0 - threshhold), 16.0);
|
||||
color += starCol.xxx;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
float4 main([[vk::location(0)]] float3 inUVW : TEXCOORD0) : SV_TARGET
|
||||
{
|
||||
return float4(starField(inUVW), 1.0);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,30 @@
|
||||
/* Copyright (c) 2024, Sascha Willems
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 the "License";
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
float4 Pos : SV_POSITION;
|
||||
[[vk::location(0)]] float3 UVW : TEXCOORD0;
|
||||
};
|
||||
|
||||
VSOutput main(uint VertexIndex : SV_VertexID)
|
||||
{
|
||||
VSOutput output = (VSOutput) 0;
|
||||
output.UVW = float3((VertexIndex << 1) & 2, VertexIndex & 2, VertexIndex & 2);
|
||||
output.Pos = float4(output.UVW.xy * 2.0f - 1.0f, 0.0f, 1.0f);
|
||||
return output;
|
||||
}
|
||||
Binary file not shown.
Reference in New Issue
Block a user