diff options
Diffstat (limited to 'engine/res')
| -rw-r--r-- | engine/res/FiraMono-Regular.ttf | bin | 0 -> 170204 bytes | |||
| -rw-r--r-- | engine/res/default_shader.slang | 270 | ||||
| -rw-r--r-- | engine/res/imgui_shader.slang | 54 | ||||
| -rw-r--r-- | engine/res/sky_box_shader.slang | 34 | ||||
| -rw-r--r-- | engine/res/ui/delete.png | bin | 0 -> 424 bytes | |||
| -rw-r--r-- | engine/res/ui/warning.png | bin | 0 -> 1495 bytes |
6 files changed, 358 insertions, 0 deletions
diff --git a/engine/res/FiraMono-Regular.ttf b/engine/res/FiraMono-Regular.ttf Binary files differnew file mode 100644 index 0000000..67bbd42 --- /dev/null +++ b/engine/res/FiraMono-Regular.ttf diff --git a/engine/res/default_shader.slang b/engine/res/default_shader.slang new file mode 100644 index 0000000..7da164c --- /dev/null +++ b/engine/res/default_shader.slang @@ -0,0 +1,270 @@ +#define MAX_LIGHT_CNT 64 + +struct Material +{ + float3 ambient; + float3 diffuse; + float3 specular; + float shininess; +}; + +struct LightPhong +{ + float3 diffuse; + float3 specular; +}; + +struct AttenuationProperties +{ + float constant; + float linear; + float quadratic; +}; + +struct PointLight +{ + LightPhong phong; + float3 position; + AttenuationProperties attenuation_props; +}; + +struct DirectionalLight +{ + LightPhong phong; + float3 direction; +}; + +struct CalculatedLight +{ + float3 diffuse; + float3 specular; +}; + +struct BlinnPhongLighting +{ + float3 view_pos; + Material material; + + DirectionalLight directional_lights[MAX_LIGHT_CNT]; + uint directional_light_cnt; + + PointLight point_lights[MAX_LIGHT_CNT]; + uint point_light_cnt; + + float4 evaluate(in VertexData vertex_data) + { + float3 ambient_light = this.calc_ambient_light(vertex_data.texture_coords); + + float3 directional_light_sum = this.calc_dir_light_sum(vertex_data); + float3 point_light_sum = this.calc_point_light_sum(vertex_data); + + return float4((ambient_light + directional_light_sum + point_light_sum), 1.0); + } + + float3 calc_dir_light_sum(in VertexData vertex_data) + { + float3 directional_light_sum = float3(0.0, 0.0, 0.0); + + for (uint index = 0; index < this.directional_light_cnt; index++) { + CalculatedLight calculated_dir_light; + + this.calc_light( + // Negated since we want the light to point from the light + // direction + normalize(-this.directional_lights[index].direction), + this.directional_lights[index].phong, + vertex_data, + calculated_dir_light + ); + + directional_light_sum += + calculated_dir_light.diffuse + calculated_dir_light.specular; + } + + return directional_light_sum; + } + + float3 calc_point_light_sum(in VertexData vertex_data) + { + float3 point_light_sum = float3(0.0, 0.0, 0.0); + + for (uint index = 0; index < this.point_light_cnt; index++) { + float3 light_direction = normalize( + this.point_lights[index].position - vertex_data.world_space_pos + ); + + CalculatedLight calculated_point_light; + + this.calc_light( + light_direction, + this.point_lights[index].phong, + vertex_data, + calculated_point_light + ); + + float attenuation = this.calc_attenuation( + this.point_lights[index], vertex_data.world_space_pos + ); + + calculated_point_light.diffuse *= attenuation; + calculated_point_light.specular *= attenuation; + + point_light_sum += + calculated_point_light.diffuse + calculated_point_light.specular; + } + + return point_light_sum; + } + + void calc_light( + in float3 light_direction, + in LightPhong light_phong, + in VertexData vertex_data, + out CalculatedLight calculated_light + ) + { + float3 norm = normalize(vertex_data.world_space_normal); + + calculated_light.diffuse = this.calc_diffuse_light( + light_phong, light_direction, norm, vertex_data.texture_coords + ); + + calculated_light.specular = this.calc_specular_light( + light_phong, + light_direction, + norm, + vertex_data.world_space_pos, + vertex_data.texture_coords + ); + } + + float3 calc_ambient_light(in float2 texture_coords) + { + return ambient_map.Sample(texture_coords).xyz * this.material.ambient; + } + + float3 calc_diffuse_light( + in LightPhong light_phong, + in float3 light_dir, + in float3 norm, + in float2 texture_coords + ) + { + float diff = max(dot(norm, light_dir), 0.0); + + return light_phong.diffuse * + (diff * (diffuse_map.Sample(texture_coords).xyz * this.material.diffuse)); + } + + float3 calc_specular_light( + in LightPhong light_phong, + in float3 light_dir, + in float3 norm, + in float3 frag_pos, + in float2 texture_coords + ) + { + // The result of the below pow is undefined if both arguments is 0. This stops + // that problem. This prevents buggy specular light when shininess is 0. + if (this.material.shininess == 0.0) { + return light_phong.specular * + (specular_map.Sample(texture_coords).xyz * this.material.specular); + } + + float3 view_direction = normalize(this.view_pos - frag_pos); + + float3 halfway_direction = normalize(light_dir + view_direction); + + float spec = pow(max(dot(norm, halfway_direction), 0.0), this.material.shininess); + + return light_phong.specular * (spec * (specular_map.Sample(texture_coords).xyz * + this.material.specular)); + } + + float calc_attenuation(in PointLight point_light, in float3 position) + { + float light_distance = length(point_light.position - position); + + return 1.0 / (point_light.attenuation_props.constant + + point_light.attenuation_props.linear * light_distance + + point_light.attenuation_props.quadratic * pow(light_distance, 2)); + } +}; + +struct Model3D +{ + float4x4 model; + float4x4 model_inverted; + float4x4 view; + float4x4 projection; +} + +cbuffer Uniforms +{ + Model3D model_3d; + BlinnPhongLighting lighting; +} + +Sampler2D ambient_map; +Sampler2D diffuse_map; +Sampler2D specular_map; + +struct VertexData +{ + float2 texture_coords; + float3 world_space_pos; + float3 world_space_normal; +}; + +struct VertexStageOutput +{ + VertexData vertex_data : VertexData; + float4 sv_position : SV_Position; +}; + +struct Vertex +{ + float3 pos : STD_POSITION; + float2 texture_coords : STD_UV; + float3 normal : STD_NORMAL; +}; + +struct Fragment +{ + float4 color; +}; + +[shader("vertex")] +VertexStageOutput vertex_main(Vertex vertex) +{ + VertexStageOutput stage_output; + + float4x4 proj_view = mul(model_3d.projection, model_3d.view); + + float4x4 proj_view_model = mul(proj_view, model_3d.model); + + stage_output.sv_position = mul(proj_view_model, float4(vertex.pos, 1.0)); + + float4 vertex_pos = float4(vertex.pos, 1.0); + + stage_output.vertex_data.world_space_pos = + float3(mul(model_3d.model, vertex_pos).xyz); + + stage_output.vertex_data.texture_coords = vertex.texture_coords; + + stage_output.vertex_data.world_space_normal = + mul(float3x3(transpose(model_3d.model_inverted)), vertex.normal); + + return stage_output; +} + +[shader("fragment")] +Fragment fragment_main(VertexData vertex_data: VertexData) : SV_Target +{ + Fragment fragment; + + fragment.color = lighting.evaluate(vertex_data); + + return fragment; +} + diff --git a/engine/res/imgui_shader.slang b/engine/res/imgui_shader.slang new file mode 100644 index 0000000..29ad9bf --- /dev/null +++ b/engine/res/imgui_shader.slang @@ -0,0 +1,54 @@ +struct Vertex +{ + float3 pos : STD_POSITION; + float4 color : STD_COLOR; + float2 texture_coords : STD_UV; +}; + +struct VertexData +{ + float4 color; + float2 texture_coords; +}; + +struct VertexStageOutput +{ + VertexData vertex_data : VertexData; + float4 sv_position : SV_Position; +}; + +struct Fragment +{ + float4 color; +}; + +cbuffer Uniforms +{ + float4x4 projection; +}; + +Sampler2D main_texture; + +[shader("vertex")] +VertexStageOutput vertex_main(Vertex vertex) +{ + VertexStageOutput stage_output; + + stage_output.sv_position = mul(projection, float4(vertex.pos.xy, 0.f, 1.f)); + + stage_output.vertex_data.color = vertex.color; + stage_output.vertex_data.texture_coords = vertex.texture_coords; + + return stage_output; +} + +[shader("fragment")] +Fragment fragment_main(VertexData vertex_data: VertexData) : SV_Target +{ + Fragment fragment; + + fragment.color = vertex_data.color * main_texture.Sample(vertex_data.texture_coords); + + return fragment; +} + diff --git a/engine/res/sky_box_shader.slang b/engine/res/sky_box_shader.slang new file mode 100644 index 0000000..1a41220 --- /dev/null +++ b/engine/res/sky_box_shader.slang @@ -0,0 +1,34 @@ +SamplerCube cube_texture; + +cbuffer Uniforms +{ + float4x4 projection; + float4x4 view; +} + +struct VertexStageOutput +{ + float4 sv_position : SV_Position; + float3 vertex_pos : VertexPosition; +}; + +[shader("vertex")] +VertexStageOutput vertex_main(float3 pos: STD_POSITION) +{ + VertexStageOutput output; + + output.vertex_pos = pos; + + float4x4 proj_view = mul(projection, view); + + output.sv_position = mul(proj_view, float4(pos, 1.0)).xyww; + + return output; +} + +[shader("fragment")] +float4 fragment_main(float3 vertex_pos: VertexPosition) : SV_Target +{ + return cube_texture.Sample(vertex_pos); +} + diff --git a/engine/res/ui/delete.png b/engine/res/ui/delete.png Binary files differnew file mode 100644 index 0000000..f85ba1c --- /dev/null +++ b/engine/res/ui/delete.png diff --git a/engine/res/ui/warning.png b/engine/res/ui/warning.png Binary files differnew file mode 100644 index 0000000..4b8e6ad --- /dev/null +++ b/engine/res/ui/warning.png |
