From 3beea443e615231a7c9451d709cf60b8c9190ff5 Mon Sep 17 00:00:00 2001 From: bi Date: Mon, 16 Jul 2018 15:14:44 +0300 Subject: [PATCH] [Core] Remove unused shaders [2] --- .../output_nodes/anisotropic_base.shader_node | 345 --- .../output_nodes/billboard_base.shader_node | 361 --- .../billboard_unlit_base.shader_node | 243 -- .../output_nodes/decal_base.shader_node | 1107 -------- .../output_nodes/light_base.shader_node | 434 --- .../output_nodes/particle_base.shader_node | 1105 -------- .../particle_distortion_base.shader_node | 175 -- .../particle_gbuffer_base.shader_node | 198 -- .../output_nodes/probe_base.shader_node | 321 --- .../output_nodes/ribbon_base.shader_node | 532 ---- .../output_nodes/skydome_base.shader_node | 207 -- .../output_nodes/standard_base.shader_node | 2340 ----------------- .../standard_base_bitsquid.shader_node | 1740 ------------ .../output_nodes/terrain_base.shader_node | 764 ------ .../output_nodes/unlit_base.shader_node | 746 ------ 15 files changed, 10618 deletions(-) delete mode 100644 vmf/core/stingray_renderer/output_nodes/anisotropic_base.shader_node delete mode 100644 vmf/core/stingray_renderer/output_nodes/billboard_base.shader_node delete mode 100644 vmf/core/stingray_renderer/output_nodes/billboard_unlit_base.shader_node delete mode 100644 vmf/core/stingray_renderer/output_nodes/decal_base.shader_node delete mode 100644 vmf/core/stingray_renderer/output_nodes/light_base.shader_node delete mode 100644 vmf/core/stingray_renderer/output_nodes/particle_base.shader_node delete mode 100644 vmf/core/stingray_renderer/output_nodes/particle_distortion_base.shader_node delete mode 100644 vmf/core/stingray_renderer/output_nodes/particle_gbuffer_base.shader_node delete mode 100644 vmf/core/stingray_renderer/output_nodes/probe_base.shader_node delete mode 100644 vmf/core/stingray_renderer/output_nodes/ribbon_base.shader_node delete mode 100644 vmf/core/stingray_renderer/output_nodes/skydome_base.shader_node delete mode 100644 vmf/core/stingray_renderer/output_nodes/standard_base.shader_node delete mode 100644 vmf/core/stingray_renderer/output_nodes/standard_base_bitsquid.shader_node delete mode 100644 vmf/core/stingray_renderer/output_nodes/terrain_base.shader_node delete mode 100644 vmf/core/stingray_renderer/output_nodes/unlit_base.shader_node diff --git a/vmf/core/stingray_renderer/output_nodes/anisotropic_base.shader_node b/vmf/core/stingray_renderer/output_nodes/anisotropic_base.shader_node deleted file mode 100644 index 056d308..0000000 --- a/vmf/core/stingray_renderer/output_nodes/anisotropic_base.shader_node +++ /dev/null @@ -1,345 +0,0 @@ -group = "Output" -display_name = "Anisostropic Base" -output_node = true -render_configs = ["core/stingray_renderer/renderer"] - -inputs = { - "aee6e47b-be7b-4d67-a123-2ab5d660b94e" = { - name = "vertex_offset" - display_name = "Position offset" - is_required = false - type = { vector3: ["HAS_VERTEX_OFFSET"] } - domain = "vertex" - } - - "aca690cb-6305-4a2f-bf3d-69183a493db3" = { - name = "base_color" - is_required = false - display_name = "Base Color" - type = { vector3: ["HAS_BASE_COLOR"] } - domain = "pixel" - } - - "34259752-b962-4b65-92c3-903a57338519" = { - name = "opacity" - is_required = false - display_name = "Opacity" - type = { scalar: ["HAS_OPACITY"] } - domain = "pixel" - } - - "7a9306c6-95ae-4cdb-9fef-0eedacce4e83" = { - name = "opacity_threshold" - is_required = false - display_name = "Opacity Threshold" - type = { scalar: ["HAS_OPACITY_THRESHOLD"] } - domain = "pixel" - } - - "b1c86408-aacb-4466-b754-ddcf37a3a2c8" = { - is_required = false - name = "normal" - display_name = "Normal" - type = { vector3: ["HAS_NORMAL"] } - domain = "pixel" - } - - "ad5e052f-d316-4a0f-8b79-53c38204d61b" = { - is_required = false - name = "metallic" - display_name = "Metallic" - type = { scalar: ["HAS_METALLIC"] } - domain = "pixel" - } - - "36ba46d2-f6ea-4e60-a428-fdc17c75bc62" = { - is_required = false - name = "roughness" - display_name = "Roughness" - type = { scalar: ["HAS_ROUGHNESS"] } - domain = "pixel" - } - - "e142ce4c-8a75-4602-a079-2996646bf37b" = { - is_required = false - name = "anisotropy" - display_name = "Anisotropy" - type = { scalar: ["HAS_ANISOTROPY"] } - domain = "pixel" - } - - "1164a5ef-4563-4795-b3b5-42825d6df037" = { - is_required = false - name = "emissive" - display_name = "Emissive" - type = { vector3: ["HAS_EMISSIVE" ] } - domain = "pixel" - } - - "59fd1cf4-f736-470d-8510-1dd7c016639e" = { - is_required = false - name = "ambient_occlusion" - display_name = "Ambient Occlusion" - type = { scalar: ["HAS_AMBIENT_OCCLUSION"] } - domain = "pixel" - } -} - -options = { - "b2c7c0d2-beff-4b1a-a9d4-068a507625a2" = "USE_FBX_PERMUTATIONS" - "d1a42a54-0794-4d57-9aa0-eb35acb6b35c" = "INSTANCED" - "8df1b8f7-17c2-4ae4-8c4e-25517ec1df46" = "CULL_NONE" - "c198c109-2cdf-49ee-af18-a982c23e2729" = "CULL_FRONT" - "2b136447-676e-4943-997b-04a28ae68497" = "WORLD_SPACE_NORMAL" - "dd7fcf97-0627-48ab-b29a-95b5685bb123" = "TRANSPARENT" - "3b55d6c6-4398-4dbc-b9ef-570aff8696ae" = "TRANSPARENT_FADE" - "b5bb2062-c8fa-43c5-8657-493a0be6860c" = "SKINNED_DISABLED" - "901b44ce-d128-498a-9912-32cd9635c556" = "HAS_FOV" - "da4e717b-5d0d-47fa-93b0-01c988f8f3ff" = "LOCK_NORMAL_ROTATION" - "979cb7cf-c255-42d0-a389-78fc0fb0539f" = "DEFERRED_DECALS_GROUP_1" - "d557b597-fa90-46b4-a751-eb51ae61ba5b" = "DEFERRED_DECALS_GROUP_2" - "fe20cc01-4cec-4217-98a0-07220ad3add9" = "DEFERRED_DECALS_GROUP_3" - "524a5842-23b7-46d1-ab22-cb3a14746ce0" = "USE_GLOBAL_ROUGHNESS_MULTIPLIER" - "11256995-4805-4018-bd6b-9214414fd363" = "NORMAL_FLIP_DISABLED" - "580cc6eb-3591-4c71-aa50-528af18ba160" = "JITTER_TRANSPARENCY" -} - -ui = [ - { - type = "drop_down" - display_name = "Normals In" - options = { - "Tangent Space" = "00000000-0000-0000-0000-000000000000" - "World Space" = "2b136447-676e-4943-997b-04a28ae68497" - } - default = "00000000-0000-0000-0000-000000000000" - } - { - type = "drop_down" - display_name = "Blend Mode" - options = { - "Opaque" = "00000000-0000-0000-0000-000000000000" - "Transparent" = "dd7fcf97-0627-48ab-b29a-95b5685bb123" - "Transparent Fade" = "3b55d6c6-4398-4dbc-b9ef-570aff8696ae" - } - default = "00000000-0000-0000-0000-000000000000" - } - { - type = "drop_down" - display_name = "Face Culling" - options = { - "Back" = "00000000-0000-0000-0000-000000000000" - "Front" = "c198c109-2cdf-49ee-af18-a982c23e2729" - "None (double sided)" = "8df1b8f7-17c2-4ae4-8c4e-25517ec1df46" - } - default = "00000000-0000-0000-0000-000000000000" - } - - { type = "checkbox" display_name = "Disable Skinning" option = "b5bb2062-c8fa-43c5-8657-493a0be6860c" } - { type = "checkbox" display_name = "Instancing" option = "d1a42a54-0794-4d57-9aa0-eb35acb6b35c" } - { type = "checkbox" display_name = "Custom FOV" option = "901b44ce-d128-498a-9912-32cd9635c556" } - { type = "checkbox" display_name = "Avoid Tangent Space Transform" option = "da4e717b-5d0d-47fa-93b0-01c988f8f3ff" } - { type = "checkbox" display_name = "Use Global Roughness Multiplier" option = "524a5842-23b7-46d1-ab22-cb3a14746ce0" } - { type = "checkbox" display_name = "Normal Flip Disabled (double sided)" option = "11256995-4805-4018-bd6b-9214414fd363" } - { type = "checkbox" display_name = "Jitter Transparency" option = "580cc6eb-3591-4c71-aa50-528af18ba160" } -] - - -render_state = { -} - -sampler_state = { -} - -channels = { - "(defined(HAS_NORMAL) && !defined(WORLD_SPACE_NORMAL)) || defined(NEEDS_TANGENT_SPACE) || defined(HAS_ANISOTROPY)": { - vertex_tangent = { type = "float3" semantic = "TANGENT" domain = "vertex" } - vertex_binormal = { type = "float3" semantic = "BINORMAL" domain = "vertex" } - - tsm0 = { type = "float3" domains = ["vertex", "pixel"] } - tsm1 = { type = "float3" domains = ["vertex", "pixel"] } - tsm2 = { type = "float3" domains = ["vertex", "pixel"] } - } - - "defined(NEEDS_EYE_VECTOR)": { - eye_vector = { type = "float3" domain = "vertex" } - } - - "!defined(HAS_NORMAL) || defined(NEEDS_WORLD_SPACE_NORMAL)": { - world_space_normal = { type = "float3" domains = ["vertex", "pixel"] } - } - - "defined(MOTION_BLUR)": { - last_clip_position = { type = "float3" domains = ["vertex", "pixel"] } - } - - vertex_position = { type = "float4" domain = "vertex" } - vertex_normal = { type = "float3" semantic = "NORMAL" domain = "vertex" } - - "defined(HAS_VERTEX_BAKED_DIFFUSE_LIGHTING)": { - vertex_color1 = { type = "float4" semantic = "COLOR1" domains = ["vertex"] } - baked_light = { type = "float3" domains = ["vertex", "pixel"] } - } - - "defined(HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING)": { - lightmap_uv_input = { type = "float2" semantic="TEXCOORD1" domains = ["vertex"] } - lightmap_uv = { type = "float2" domains = ["vertex", "pixel"] } - } - - "defined(MATERIAL_TRANSFER)": { - lightmap_uv = { type = "float2" semantic="TEXCOORD1" domains = ["vertex"] } - } - - "defined(NEEDS_UNSKINNED_WORLD_POS)": { - unskinned_world_pos = { type = "float3" domains = ["vertex", "pixel"] } - unskinned_normal = { type = "float3" domains = ["vertex", "pixel"] } - } - - "defined(NEEDS_PIXEL_DEPTH)": { - pixel_depth = { type = "float" domain = "pixel" } - } - - "defined(NEEDS_SCREEN_POS)": { - screen_pos = { type = "float2" domain = "pixel" } - } - - "defined(NEEDS_SUN_SHADOW_MASK)": { - //"defined(NEEDS_SUN_SHADOW_MASK) && (defined(EMISSIVE_PASS) || defined(TRANSPARENT) || defined(TRANSPARENT_FADE))": { - sun_shadow_mask = { type = "float" domain = "pixel" } - } -} - -//log_permutations = true -permutation_sets = { - vertex_modifiers = [ - { if: "num_skin_weights() == 4" define: { "macros": ["SKINNED_4WEIGHTS"] stages: ["vertex"] } } - { if: "num_skin_weights() == 3" define: { "macros": ["SKINNED_3WEIGHTS"] stages: ["vertex"] } } - { if: "num_skin_weights() == 2" define: { "macros": ["SKINNED_2WEIGHTS"] stages: ["vertex"] } } - { if: "num_skin_weights() == 1" define: { "macros": ["SKINNED_1WEIGHT"] stages: ["vertex"] } } - { default = true } - ] - - instanced_modifiers = [ - // { if: "mesh_baked_lighting_type() == lightmap" define: ["HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING"] } - { default = true } - ] - - lightmap_modifiers = [ - { if: "lightmap_format() == directional_irradiance" define: ["HAS_DIRECTIONAL_LIGHTMAPS"] } - { default = true } - ] - - non_instanced_modifiers = [ - // { if: "mesh_baked_lighting_type() == lightmap" define: ["HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING"] permute_with: "lightmap_modifiers" } - // { if: "mesh_baked_lighting_type() == vertex" define: ["HAS_VERTEX_BAKED_DIFFUSE_LIGHTING"] } - { permute_with: "vertex_modifiers" } - ] - - instanced_and_non_instanced = [ - { if: "defined(INSTANCED)" permute_with: "instanced_modifiers" } - { if: "!defined(INSTANCED)" permute_with: "non_instanced_modifiers" } - ] - - default = [ - // FBX Standard material exclusive permutations, these will only compile of the - // 'USE_FBX_PERMUTATIONS' option is set, which it is in the shader used for imported fbx files. - { if: "defined(USE_FBX_PERMUTATIONS) && is_any_material_variable_set(use_emissive_map, emissive)" define: ["FBX_EMISSIVE"] permute_with: "instanced_and_non_instanced" } - - // Normal default permutation set - { if: "on_renderer(D3D11, D3D12, GNM, GL) && (defined(TRANSPARENT) || defined(TRANSPARENT_FADE)) && render_setting(low_res_transparency)" defines=["LOW_RES_ENABLED"] permute_with: "instanced_and_non_instanced" } - { permute_with: "instanced_and_non_instanced" } - ] - - shadow_caster = [ - { if: "defined(INSTANCED)" } - { if: "!defined(INSTANCED)" permute_with: "vertex_modifiers" } - ] -} - -shader_contexts = { - shadow_caster = { - passes_sort_mode = "immediate" - compile_with = [ - { if: "on_renderer(D3D11, D3D12, GNM, GL)" permute_with: "shadow_caster" } - ] - - passes = [ - { code_block="core/stingray_renderer/output_nodes/standard_base#depth_only" render_state="core/stingray_renderer/output_nodes/standard_base#shadow_caster" } - ] - } - - material_transfer = { - passes_sort_mode = "immediate" - compile_with = [ - { if: "on_renderer(D3D11, D3D12)" } - ] - - passes = [ - { if: "defined(HAS_ANISOTROPY)" then: [ - { code_block="core/stingray_renderer/output_nodes/standard_base#gbuffer_base" defines=["MATERIAL_TRANSFER" "TRANSPARENT_FADE"] render_state="core/stingray_renderer/output_nodes/standard_base#material_transfer" } - ] else: [ - { code_block="core/stingray_renderer/output_nodes/standard_base#gbuffer_base" defines=["MATERIAL_TRANSFER"] render_state="core/stingray_renderer/output_nodes/standard_base#material_transfer" } - ]} - ] - } - - default = { - passes_sort_mode = "deferred" - compile_with = [ - { if: "on_renderer(D3D11, D3D12, GNM, GL)" permute_with: [ - // TODO: create permutation for when local lights is off. - { permute_with: "default" } - ] } - ] - - passes = [ - { if: "defined(HAS_ANISOTROPY)" then: [ - { if: "defined(TRANSPARENT) || defined(TRANSPARENT_FADE)" then: [ - { if: "defined(CULL_NONE)" then: [ - { layer="hdr_transparent" code_block="core/stingray_renderer/output_nodes/standard_base#gbuffer_base" render_state="core/stingray_renderer/output_nodes/standard_base#transparent_double_sided_ccw" } - { layer="hdr_transparent" code_block="core/stingray_renderer/output_nodes/standard_base#gbuffer_base" render_state="core/stingray_renderer/output_nodes/standard_base#transparent_double_sided_cw" } - ] else: [ - { layer="hdr_transparent" code_block="core/stingray_renderer/output_nodes/standard_base#gbuffer_base" render_state="core/stingray_renderer/output_nodes/standard_base#transparent" } - ]} - ] else: [ - { layer="hdr_transparent" code_block="core/stingray_renderer/output_nodes/standard_base#gbuffer_base" defines=["TRANSPARENT_FADE"] render_state="core/stingray_renderer/output_nodes/standard_base#gbuffer_material" } // TODO: write o another layer - ]} - // todo has fov? - ] else: [ - // Standard base logic. - { if: "defined(TRANSPARENT) || defined(TRANSPARENT_FADE)" then: [ - { layer="hdr_transparent" code_block="core/stingray_renderer/output_nodes/standard_base#gbuffer_base" render_state="core/stingray_renderer/output_nodes/standard_base#transparent" } - ] else: [ - { if: "defined(HAS_FOV)" then: [ - { layer="gbuffer_fpr" code_block="core/stingray_renderer/output_nodes/standard_base#gbuffer_base" defines="MOTION_BLUR" render_state="core/stingray_renderer/output_nodes/standard_base#gbuffer_material" } - ] else: [ - { if: "defined(HAS_OPACITY)" then: [ - { layer="gbuffer_alpha_masked" code_block="core/stingray_renderer/output_nodes/standard_base#gbuffer_base" defines="MOTION_BLUR" render_state="core/stingray_renderer/output_nodes/standard_base#gbuffer_material" } - ] else: [ - { layer="gbuffer" code_block="core/stingray_renderer/output_nodes/standard_base#gbuffer_base" defines="MOTION_BLUR" render_state="core/stingray_renderer/output_nodes/standard_base#gbuffer_material" } - ]} - ]} - - // This bit of logic is a bit complicated. The gist of it is that we want to disable this pass - // for materials that has a value connected on emissive for all permutations, but should have it - // discarded for all but the special permutations with the define FBX_EMISSIVE - { if: "defined(HAS_EMISSIVE) && (!defined(USE_FBX_PERMUTATIONS) || defined(FBX_EMISSIVE))" then: [ - { layer="emissive" code_block="core/stingray_renderer/output_nodes/standard_base#gbuffer_base" defines={ macros: ["EMISSIVE_PASS"] stages: ["pixel"] } render_state="core/stingray_renderer/output_nodes/standard_base#emissive" } - ]} - ]} - ]} - - { if: "!on_renderer(GL)" then: [ - { layer="wireframe" code_block="core/stingray_renderer/output_nodes/standard_base#depth_only" define="DRAW_WIREFRAME" render_state="core/stingray_renderer/output_nodes/standard_base#wireframe" branch_key="dev_wireframe" } - ]} - - { layer="outline" code_block="core/stingray_renderer/output_nodes/standard_base#depth_only" define="DRAW_OUTLINE" render_state="core/stingray_renderer/output_nodes/standard_base#outline_stencil_write" branch_key="outline_unit" } - { layer="outline" code_block="core/stingray_renderer/output_nodes/standard_base#depth_only" define="DRAW_OUTLINE" render_state="core/stingray_renderer/output_nodes/standard_base#outline_stencil_write_z" branch_key="outline_unit_z" } - - { layer="outline_mask" code_block="core/stingray_renderer/output_nodes/standard_base#depth_only" defines=["DRAW_OUTLINE" "OUTLINE_MASK_WRITE"] render_state="core/stingray_renderer/output_nodes/standard_base#outline_mask_write" branch_key="outline_unit_z_fail" } - { layer="outline" code_block="core/stingray_renderer/output_nodes/standard_base#depth_only" defines=["DRAW_OUTLINE" "OUTLINE_MASK_READ"] render_state="core/stingray_renderer/output_nodes/standard_base#outline_stencil_write" branch_key="outline_unit_z_fail" } - - { layer="cascade_visualizer" code_block="core/stingray_renderer/output_nodes/standard_base#gbuffer_base" define="CASCADE_VISUALIZER" render_state="core/stingray_renderer/output_nodes/standard_base#cascade_visualizer" branch_key="cascade_visualizer" } - ] - } -} \ No newline at end of file diff --git a/vmf/core/stingray_renderer/output_nodes/billboard_base.shader_node b/vmf/core/stingray_renderer/output_nodes/billboard_base.shader_node deleted file mode 100644 index 80d0183..0000000 --- a/vmf/core/stingray_renderer/output_nodes/billboard_base.shader_node +++ /dev/null @@ -1,361 +0,0 @@ -group = "Output" -display_name = "Billboard Base" -output_node = true -render_configs = ["core/stingray_renderer/renderer"] - -inputs = { - "aee6e47b-be7b-4d67-a123-2ab5d660b94e" = { - name = "vertex_offset" - display_name = "Position offset" - is_required = false - type = { vector3: ["HAS_VERTEX_OFFSET"] } - domain = "vertex" - } - - "aca690cb-6305-4a2f-bf3d-69183a493db3" = { - name = "base_color" - is_required = false - display_name = "Base Color" - type = { vector3: ["HAS_BASE_COLOR"] } - domain = "pixel" - } - - "34259752-b962-4b65-92c3-903a57338519" = { - name = "opacity" - is_required = false - display_name = "Opacity" - type = { scalar: ["HAS_OPACITY"] } - domain = "pixel" - } - - "7a9306c6-95ae-4cdb-9fef-0eedacce4e83" = { - name = "opacity_threshold" - is_required = false - display_name = "Opacity Threshold" - type = { scalar: ["HAS_OPACITY_THRESHOLD"] } - domain = "pixel" - } - - "b1c86408-aacb-4466-b754-ddcf37a3a2c8" = { - is_required = false - name = "normal" - display_name = "Normal" - type = { vector3: ["HAS_NORMAL"] } - domain = "pixel" - } - - "ad5e052f-d316-4a0f-8b79-53c38204d61b" = { - is_required = false - name = "metallic" - display_name = "Metallic" - type = { scalar: ["HAS_METALLIC"] } - domain = "pixel" - } - - "36ba46d2-f6ea-4e60-a428-fdc17c75bc62" = { - is_required = false - name = "roughness" - display_name = "Roughness" - type = { scalar: ["HAS_ROUGHNESS"] } - domain = "pixel" - } - - "1164a5ef-4563-4795-b3b5-42825d6df037" = { - is_required = false - name = "emissive" - display_name = "Emissive" - type = { vector3: ["HAS_EMISSIVE" ] } - domain = "pixel" - } - - "59fd1cf4-f736-470d-8510-1dd7c016639e" = { - is_required = false - name = "ambient_occlusion" - display_name = "Ambient Occlusion" - type = { scalar: ["HAS_AMBIENT_OCCLUSION"] } - domain = "pixel" - } - - "0544ddb6-e168-452d-86f2-42a79e8c98e3" = { - is_required = false - name = "sss_strength" - display_name = "Skin SSS" - type = { scalar: ["SKIN", "HAS_SKIN_SSS_STRENGTH"] } - domain = "pixel" - } -} - -options = { - "b2c7c0d2-beff-4b1a-a9d4-068a507625a2" = "USE_FBX_PERMUTATIONS" - "d1a42a54-0794-4d57-9aa0-eb35acb6b35c" = "INSTANCED" - "8df1b8f7-17c2-4ae4-8c4e-25517ec1df46" = "CULL_NONE" - "c198c109-2cdf-49ee-af18-a982c23e2729" = "CULL_FRONT" - "34994d84-9d51-48ac-af85-bc053b2c65c3" = "SKIN" - "2b136447-676e-4943-997b-04a28ae68497" = "WORLD_SPACE_NORMAL" - "dd7fcf97-0627-48ab-b29a-95b5685bb123" = "TRANSPARENT" - "3b55d6c6-4398-4dbc-b9ef-570aff8696ae" = "TRANSPARENT_FADE" - "b5bb2062-c8fa-43c5-8657-493a0be6860c" = "SKINNED_DISABLED" - "901b44ce-d128-498a-9912-32cd9635c556" = "HAS_FOV" - "da4e717b-5d0d-47fa-93b0-01c988f8f3ff" = "LOCK_NORMAL_ROTATION" - "979cb7cf-c255-42d0-a389-78fc0fb0539f" = "DEFERRED_DECALS_GROUP_1" - "d557b597-fa90-46b4-a751-eb51ae61ba5b" = "DEFERRED_DECALS_GROUP_2" - "fe20cc01-4cec-4217-98a0-07220ad3add9" = "DEFERRED_DECALS_GROUP_3" - "524a5842-23b7-46d1-ab22-cb3a14746ce0" = "USE_GLOBAL_ROUGHNESS_MULTIPLIER" - "11256995-4805-4018-bd6b-9214414fd363" = "NORMAL_FLIP_DISABLED" - "580cc6eb-3591-4c71-aa50-528af18ba160" = "JITTER_TRANSPARENCY" - - "a669a3b8-2bf0-4b3f-ba67-aebdeaf0e0d1" = "BILLBOARD_TANGENT_ALIGNED" - "b2df1da0-8e59-4ad4-9ab7-7a4d5ddcf998" = "BILLBOARD_CAMERA_ALIGNED" - "f0642710-b291-4a17-80d0-1319d0decfd9" = "BILLBOARD_TANGENT_ALIGNED_X_LOCKED" - "32b48986-5602-4157-8a25-44fc7f71ee47" = "BILLBOARD_TANGENT_ALIGNED_Y_LOCKED" - "5bdca8b0-737e-417e-a2b4-d35cc935f605" = "BILLBOARD_SPHERICAL_NORMAL" - "c1c06809-56d3-4a8e-882c-7d84c31299ba" = "SECONDARY_SUN_DIRECTION" -} - -ui = [ - { - type = "drop_down" - display_name = "Billboard Option" - options = { - "Screen Aligned" = "00000000-0000-0000-0000-000000000000" - "Camera Aligned" = "b2df1da0-8e59-4ad4-9ab7-7a4d5ddcf998" - "Tangent Aligned" = "a669a3b8-2bf0-4b3f-ba67-aebdeaf0e0d1" - } - default = "00000000-0000-0000-0000-000000000000" - } - { - type = "drop_down" - display_name = "Tangent Aligned Axis" - options = { - "Z-Axis" = "00000000-0000-0000-0000-000000000000" - "Y-Axis" = "32b48986-5602-4157-8a25-44fc7f71ee47" - "X-Axis" = "f0642710-b291-4a17-80d0-1319d0decfd9" - } - default = "00000000-0000-0000-0000-000000000000" - } - { - type = "drop_down" - display_name = "Normal Options" - options = { - "Plane Normal" = "00000000-0000-0000-0000-000000000000" - "Spherical Plane Normal" = "5bdca8b0-737e-417e-a2b4-d35cc935f605" - - } - default = "00000000-0000-0000-0000-000000000000" - } - { - type = "drop_down" - display_name = "Normals In" - options = { - "Tangent Space" = "00000000-0000-0000-0000-000000000000" - "World Space" = "2b136447-676e-4943-997b-04a28ae68497" - } - default = "00000000-0000-0000-0000-000000000000" - } - { - type = "drop_down" - display_name = "Blend Mode" - options = { - "Opaque" = "00000000-0000-0000-0000-000000000000" - "Transparent" = "dd7fcf97-0627-48ab-b29a-95b5685bb123" - "Transparent Fade" = "3b55d6c6-4398-4dbc-b9ef-570aff8696ae" - } - default = "00000000-0000-0000-0000-000000000000" - } - { - type = "drop_down" - display_name = "Decal Group" - options = { - "Group 0" = "00000000-0000-0000-0000-000000000000" - "Group 1" = "979cb7cf-c255-42d0-a389-78fc0fb0539f" - "Group 2" = "d557b597-fa90-46b4-a751-eb51ae61ba5b" - "Group 3" = "fe20cc01-4cec-4217-98a0-07220ad3add9" - } - default = "00000000-0000-0000-0000-000000000000" - } - - { type = "checkbox" display_name = "Disable Skinning" option = "b5bb2062-c8fa-43c5-8657-493a0be6860c" } - { type = "checkbox" display_name = "Instancing" option = "d1a42a54-0794-4d57-9aa0-eb35acb6b35c" } - { type = "checkbox" display_name = "Custom FOV" option = "901b44ce-d128-498a-9912-32cd9635c556" } - { type = "checkbox" display_name = "Avoid Tangent Space Transform" option = "da4e717b-5d0d-47fa-93b0-01c988f8f3ff" } - { type = "checkbox" display_name = "Use Global Roughness Multiplier" option = "524a5842-23b7-46d1-ab22-cb3a14746ce0" } - { type = "checkbox" display_name = "Normal Flip Disabled (double sided)" option = "11256995-4805-4018-bd6b-9214414fd363" } - { type = "checkbox" display_name = "Jitter Transparency" option = "580cc6eb-3591-4c71-aa50-528af18ba160" } -] - -render_state = { -} - -sampler_state = { -} - -channels = { - "(defined(HAS_NORMAL) && !defined(WORLD_SPACE_NORMAL)) || defined(NEEDS_TANGENT_SPACE)": { - vertex_tangent = { type = "float3" semantic = "TANGENT" domain = "vertex" } - vertex_binormal = { type = "float3" semantic = "BINORMAL" domain = "vertex" } - - tsm0 = { type = "float3" domains = ["vertex", "pixel"] } - tsm1 = { type = "float3" domains = ["vertex", "pixel"] } - tsm2 = { type = "float3" domains = ["vertex", "pixel"] } - } - - "defined(NEEDS_EYE_VECTOR)": { - eye_vector = { type = "float3" domain = "vertex" } - } - - "!defined(HAS_NORMAL) || defined(NEEDS_WORLD_SPACE_NORMAL)": { - world_space_normal = { type = "float3" domains = ["vertex", "pixel"] } - } - - "defined(MOTION_BLUR)": { - last_clip_position = { type = "float3" domains = ["vertex", "pixel"] } - } - - vertex_position = { type = "float4" domain = "vertex" } - vertex_normal = { type = "float3" semantic = "NORMAL" domain = "vertex" } - - "defined(HAS_VERTEX_BAKED_DIFFUSE_LIGHTING)": { - vertex_color1 = { type = "float4" semantic = "COLOR1" domains = ["vertex"] } - baked_light = { type = "float3" domains = ["vertex", "pixel"] } - } - - "defined(HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING)": { - lightmap_uv_input = { type = "float2" semantic="TEXCOORD1" domains = ["vertex"] } - lightmap_uv = { type = "float2" domains = ["vertex", "pixel"] } - } - - "defined(MATERIAL_TRANSFER)": { - lightmap_uv = { type = "float2" semantic="TEXCOORD1" domains = ["vertex"] } - } - - "defined(NEEDS_UNSKINNED_WORLD_POS)": { - unskinned_world_pos = { type = "float3" domains = ["vertex", "pixel"] } - unskinned_normal = { type = "float3" domains = ["vertex", "pixel"] } - } - - "defined(NEEDS_PIXEL_DEPTH)": { - pixel_depth = { type = "float" domain = "pixel" } - } - - "defined(NEEDS_SCREEN_POS)": { - screen_pos = { type = "float2" domain = "pixel" } - } - - "defined(NEEDS_SUN_SHADOW_MASK)": { - //"defined(NEEDS_SUN_SHADOW_MASK) && (defined(EMISSIVE_PASS) || defined(TRANSPARENT) || defined(TRANSPARENT_FADE))": { - sun_shadow_mask = { type = "float" domain = "pixel" } - } -} - -//log_permutations = true -permutation_sets = { - vertex_modifiers = [ - { if: "num_skin_weights() == 4" define: { "macros": ["SKINNED_4WEIGHTS"] stages: ["vertex"] } } - { if: "num_skin_weights() == 3" define: { "macros": ["SKINNED_3WEIGHTS"] stages: ["vertex"] } } - { if: "num_skin_weights() == 2" define: { "macros": ["SKINNED_2WEIGHTS"] stages: ["vertex"] } } - { if: "num_skin_weights() == 1" define: { "macros": ["SKINNED_1WEIGHT"] stages: ["vertex"] } } - { default = true } - ] - - instanced_modifiers = [ - // { if: "mesh_baked_lighting_type() == lightmap" define: ["HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING"] } - { default = true } - ] - - lightmap_modifiers = [ - { if: "lightmap_format() == directional_irradiance" define: ["HAS_DIRECTIONAL_LIGHTMAPS"] } - { default = true } - ] - - non_instanced_modifiers = [ - // { if: "mesh_baked_lighting_type() == lightmap" define: ["HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING"] permute_with: "lightmap_modifiers" } - // { if: "mesh_baked_lighting_type() == vertex" define: ["HAS_VERTEX_BAKED_DIFFUSE_LIGHTING"] } - { permute_with: "vertex_modifiers" } - ] - - instanced_and_non_instanced = [ - { if: "defined(INSTANCED)" permute_with: "instanced_modifiers" } - { if: "!defined(INSTANCED)" permute_with: "non_instanced_modifiers" } - ] - - default = [ - // FBX Standard material exclusive permutations, these will only compile of the - // 'USE_FBX_PERMUTATIONS' option is set, which it is in the shader used for imported fbx files. - { if: "defined(USE_FBX_PERMUTATIONS) && is_any_material_variable_set(use_emissive_map, emissive)" define: ["FBX_EMISSIVE"] permute_with: "instanced_and_non_instanced" } - - // Normal default permutation set - { if: "on_renderer(D3D11, D3D12, GNM, GL) && (defined(TRANSPARENT) || defined(TRANSPARENT_FADE)) && render_setting(low_res_transparency)" defines=["LOW_RES_ENABLED"] permute_with: "instanced_and_non_instanced" } - { permute_with: "instanced_and_non_instanced" } - ] - - shadow_caster = [ - { if: "defined(INSTANCED)" } - { if: "!defined(INSTANCED)" permute_with: "vertex_modifiers" } - ] -} - -shader_contexts = { - shadow_caster = { - passes_sort_mode = "immediate" - compile_with = [ - { if: "on_renderer(D3D11, D3D12, GNM, GL)" permute_with: "shadow_caster" } - ] - - passes = [ - { code_block="core/stingray_renderer/output_nodes/standard_base#depth_only" defines={ macros: ["BILLBOARD"] stages: ["vertex"] } render_state="core/stingray_renderer/output_nodes/standard_base#shadow_caster" } - ] - } - - material_transfer = { - passes_sort_mode = "immediate" - compile_with = [ - { if: "on_renderer(D3D11, D3D12)" } - ] - - passes = [ - { code_block="core/stingray_renderer/output_nodes/standard_base#gbuffer_base" defines=["BILLBOARD" "MATERIAL_TRANSFER"] render_state="core/stingray_renderer/output_nodes/standard_base#material_transfer" } - ] - } - - default = { - passes_sort_mode = "deferred" - compile_with = [ - { if: "on_renderer(D3D11, D3D12, GNM, GL)" permute_with: [ - // TODO: create permutation for when local lights is off. - { permute_with: "default" } - ] } - ] - - passes = [ - { if: "(defined(TRANSPARENT) || defined(TRANSPARENT_FADE))" then: [ - { if: "defined(CULL_NONE)" then: [ - { layer="hdr_transparent" code_block="core/stingray_renderer/output_nodes/standard_base#gbuffer_base" defines={ macros: ["BILLBOARD"] stages: ["vertex"] } render_state="core/stingray_renderer/output_nodes/standard_base#transparent_double_sided_ccw" } - { layer="hdr_transparent" code_block="core/stingray_renderer/output_nodes/standard_base#gbuffer_base" defines={ macros: ["BILLBOARD"] stages: ["vertex"] } render_state="core/stingray_renderer/output_nodes/standard_base#transparent_double_sided_cw" } - ] else: [ - { layer="hdr_transparent" code_block="core/stingray_renderer/output_nodes/standard_base#gbuffer_base" defines={ macros: ["BILLBOARD"] stages: ["vertex"] } render_state="core/stingray_renderer/output_nodes/standard_base#transparent" } - ]} - ] else: [ - { if: "defined(HAS_FOV)" then: [ - { layer="gbuffer_fpr" code_block="core/stingray_renderer/output_nodes/standard_base#gbuffer_base" defines=["BILLBOARD" "MOTION_BLUR"] render_state="core/stingray_renderer/output_nodes/standard_base#gbuffer_material" } - ] else: [ - { if: "defined(HAS_OPACITY)" then: [ - { layer="gbuffer_alpha_masked" code_block="core/stingray_renderer/output_nodes/standard_base#gbuffer_base" defines=["BILLBOARD" "MOTION_BLUR"] render_state="core/stingray_renderer/output_nodes/standard_base#gbuffer_material" } - ] else: [ - { layer="gbuffer" code_block="core/stingray_renderer/output_nodes/standard_base#gbuffer_base" defines=["BILLBOARD" "MOTION_BLUR"] render_state="core/stingray_renderer/output_nodes/standard_base#gbuffer_material" } - ]} - ]} - - // This bit of logic is a bit complicated. The gist of it is that we want to disable this pass - // for materials that has a value connected on emissive for all permutations, but should have it - // discarded for all but the special permutations with the define FBX_EMISSIVE - { if: "defined(HAS_EMISSIVE) && (!defined(USE_FBX_PERMUTATIONS) || defined(FBX_EMISSIVE))" then: [ - { layer="emissive" code_block="core/stingray_renderer/output_nodes/standard_base#gbuffer_base" defines=["BILLBOARD" "EMISSIVE_PASS"] render_state="core/stingray_renderer/output_nodes/standard_base#emissive" } - ]} - ]} - - { if: "!on_renderer(GL)" then: [ - { layer="wireframe" code_block="core/stingray_renderer/output_nodes/standard_base#depth_only" defines=["BILLBOARD" "DRAW_WIREFRAME"] render_state="core/stingray_renderer/output_nodes/standard_base#wireframe" branch_key="dev_wireframe" } - ]} - ] - } -} \ No newline at end of file diff --git a/vmf/core/stingray_renderer/output_nodes/billboard_unlit_base.shader_node b/vmf/core/stingray_renderer/output_nodes/billboard_unlit_base.shader_node deleted file mode 100644 index 0cd106b..0000000 --- a/vmf/core/stingray_renderer/output_nodes/billboard_unlit_base.shader_node +++ /dev/null @@ -1,243 +0,0 @@ -group = "Output" -display_name = "Billboard Unlit Base" -output_node = true -render_configs = ["core/stingray_renderer/renderer"] - -inputs = { - "aee6e47b-be7b-4d67-a123-2ab5d660b94e" = { - name = "vertex_offset" - display_name = "Position offset" - is_required = false - type = { vector3: ["HAS_VERTEX_OFFSET"] } - domain = "vertex" - } - - "aca690cb-6305-4a2f-bf3d-69183a493db3" = { - name = "base_color" - is_required = false - display_name = "Base Color" - type = { vector3: ["HAS_BASE_COLOR"] } - domain = "pixel" - } - - "34259752-b962-4b65-92c3-903a57338519" = { - name = "opacity" - is_required = false - display_name = "Opacity" - type = { scalar: ["HAS_OPACITY"] } - domain = "pixel" - } -} - - -options = { - "d1a42a54-0794-4d57-9aa0-eb35acb6b35c" = "INSTANCED" - "8df1b8f7-17c2-4ae4-8c4e-25517ec1df46" = "DOUBLE_SIDED" - "34994d84-9d51-48ac-af85-bc053b2c65c3" = "SKIN" - "e1bfa889-2503-4ac3-9134-c08a7fa04568" = "PROJECT_TO_FAR_PLANE" - "6a6241cc-7d21-4e2e-87c8-8d9c7bdcd322" = "CAMERA_TRANSLATION_LOCK" - "435e14e4-556d-4ac1-af14-8dafe63aff8f" = "BLEND_TRANSPARENT" - "52c7ce01-ee57-4770-914e-727fc1966962" = "LAYER_EMISSIVE" - "da09a694-b81f-4684-9912-61294914fd70" = "LAYER_SKYDOME_BILLBOARD" - "4c3163d4-c086-4645-ba1c-0d68a98022a1" = "LAYER_HDR_TRANSPARENT" - "c8d8b754-c567-4c7b-9cbd-8acab22beff5" = "LAYER_TRANSPARENT" - "afe47c59-33c4-43b2-af4a-817085b1113c" = "DEPTH_TEST_INVERTED" - "774556cd-2d1e-4df8-8ae2-5e84800f0c04" = "DEPTH_TEST_DISABLED" - "7b8bc0bf-c453-49d2-9415-0e80fec1039f" = "DISABLE_DEPTH_WRITE" - "b2556764-e8e9-47cf-9ecc-f53b5d5d73c7" = "HAS_CUSTOM_FOV" - "72ecf75c-f85f-49a2-8708-cd3158c1afa8" = "BILLBOARD_TANGENT_ALIGNED" - "33aec36d-02fd-4494-81b5-02b9d6ebf4bb" = "BILLBOARD_CAMERA_ALIGNED" - "7ae0cdd4-6508-433d-a994-9f2d4ba7b336" = "BILLBOARD_TANGENT_ALIGNED_X_LOCKED" - "774ef841-1d96-4a1f-8b6d-da8007bfe93e" = "BILLBOARD_TANGENT_ALIGNED_Y_LOCKED" - "d8ad7502-a44d-4cf0-920e-957a477f5c86" = "BILLBOARD_SPHERICAL_NORMAL" - "7afd3648-ebd1-4a40-94b4-a07e59a6fbb2" = "DISABLE_WRITE_DEPTH" - "7fb0b18d-1725-4e76-b3fe-f7a59b607f98" = "SECONDARY_SUN_DIRECTION" -} - -ui = [ - { - type = "drop_down" - display_name = "Billboard Option" - options = { - "Screen Aligned" = "00000000-0000-0000-0000-000000000000" - "Camera Aligned" = "33aec36d-02fd-4494-81b5-02b9d6ebf4bb" - "Tangent Aligned" = "72ecf75c-f85f-49a2-8708-cd3158c1afa8" - } - default = "00000000-0000-0000-0000-000000000000" - } - { - type = "drop_down" - display_name = "Tangent Aligned Axis" - options = { - "Z-Axis" = "00000000-0000-0000-0000-000000000000" - "Y-Axis" = "774ef841-1d96-4a1f-8b6d-da8007bfe93e" - "X-Axis" = "7ae0cdd4-6508-433d-a994-9f2d4ba7b336" - } - default = "00000000-0000-0000-0000-000000000000" - } - { - type = "drop_down" - display_name = "Skydome Billboard Direction" - options = { - "Sun Direction" = "00000000-0000-0000-0000-000000000000" - "Secondary Sun Direction" = "7fb0b18d-1725-4e76-b3fe-f7a59b607f98" - } - default = "00000000-0000-0000-0000-000000000000" - } - { - type = "drop_down" - display_name = "Normal Options" - options = { - "Plane Normal" = "00000000-0000-0000-0000-000000000000" - "Spherical Plane Normal" = "d8ad7502-a44d-4cf0-920e-957a477f5c86" - - } - default = "00000000-0000-0000-0000-000000000000" - } - - { - type = "drop_down" - display_name = "Layer" - options = { - "Emissive" = "52c7ce01-ee57-4770-914e-727fc1966962" - "Skydome Billboard" = "da09a694-b81f-4684-9912-61294914fd70" - "HDR Transparent" = "4c3163d4-c086-4645-ba1c-0d68a98022a1" - "LDR Transparent" = "c8d8b754-c567-4c7b-9cbd-8acab22beff5" - } - default = "4c3163d4-c086-4645-ba1c-0d68a98022a1" - } - - { - type = "drop_down" - display_name = "Depth Testing" - options = { - "Normal" = "00000000-0000-0000-0000-000000000000" - "Inverted" = "afe47c59-33c4-43b2-af4a-817085b1113c" - "Disabled" = "774556cd-2d1e-4df8-8ae2-5e84800f0c04" - } - default = "00000000-0000-0000-0000-000000000000" - } - - { - type = "drop_down" - display_name = "Blend Mode" - options = { - "Opaque" = "00000000-0000-0000-0000-000000000000" - "Transparent" = "435e14e4-556d-4ac1-af14-8dafe63aff8f" - } - default = "00000000-0000-0000-0000-000000000000" - } - - { type = "checkbox" display_name = "Disable Depth Writes" option = "7b8bc0bf-c453-49d2-9415-0e80fec1039f" } - { type = "checkbox" display_name = "Double Sided" option = "8df1b8f7-17c2-4ae4-8c4e-25517ec1df46" } - { type = "checkbox" display_name = "Instancing" option = "d1a42a54-0794-4d57-9aa0-eb35acb6b35c" } - { type = "checkbox" display_name = "Project to Far Plane" option = "e1bfa889-2503-4ac3-9134-c08a7fa04568" } - { type = "checkbox" display_name = "Camera Translation Lock" option = "6a6241cc-7d21-4e2e-87c8-8d9c7bdcd322" } - { type = "checkbox" display_name = "Custom FOV" option = "b2556764-e8e9-47cf-9ecc-f53b5d5d73c7" } -] - -render_state = { - skydome_billboard = { - inherit: ["core/stingray_renderer/shader_libraries/common#default"] - state: { - write_mask0 = "red|green|blue" - - "defined(BLEND_TRANSPARENT)" = { - blend_enable = "true" - blend_op = "blend_op_add" - dest_blend = "blend_inv_src_alpha" - src_blend = "blend_one" - } - - "defined(DEPTH_TEST_DISABLED)" = { - z_enable = "false" - } - - z_write_enable = "false" - } - } -} - -sampler_state = { } - -channels = { - "defined(NEEDS_EYE_VECTOR)": { - eye_vector = { type = "float3" domain = "vertex" } - } - - "defined(NEEDS_WORLD_SPACE_NORMAL)": { - world_space_normal = { type = "float3" domains = ["vertex", "pixel"] } - } - - "defined(MOTION_BLUR)": { - last_clip_position = { type = "float3" domains = ["vertex", "pixel"] } - } - - "defined(MATERIAL_TRANSFER)": { - lightmap_uv = { type = "float2" semantic="TEXCOORD1" domains = ["vertex"] } - } - - "defined(NEEDS_SCREEN_POS)": { - screen_pos = { type = "float2" domain = "pixel" } - } - - "defined(NEEDS_PIXEL_DEPTH)": { - pixel_depth = { type = "float" domain = "pixel" } - } - - vertex_position = { type = "float4" domain = "vertex" } - vertex_normal = { type = "float3" semantic = "NORMAL" domain = "vertex" } -} - -permutation_sets = { - vertex_modifiers = [ - { if: "num_skin_weights() == 4" define: { "macros": ["SKINNED_4WEIGHTS"] stages: ["vertex"] } } - { if: "num_skin_weights() == 3" define: { "macros": ["SKINNED_3WEIGHTS"] stages: ["vertex"] } } - { if: "num_skin_weights() == 2" define: { "macros": ["SKINNED_2WEIGHTS"] stages: ["vertex"] } } - { if: "num_skin_weights() == 1" define: { "macros": ["SKINNED_1WEIGHT"] stages: ["vertex"] } } - { default = true } - ] - - instanced_modifiers = [ - { default = true } - ] - - non_instanced_modifiers = [ - { permute_with: "vertex_modifiers" } - ] - - default = [ - { if: "defined(INSTANCED)" permute_with: "instanced_modifiers" } - { if: "!defined(INSTANCED)" permute_with: "non_instanced_modifiers" } - ] -} - -shader_contexts = { - default = { - passes_sort_mode = "deferred" - compile_with = [ - { if: "on_renderer(D3D11, D3D12, GNM, GL) && defined(BLEND_TRANSPARENT) && defined(LAYER_HDR_TRANSPARENT) && render_setting(low_res_transparency)" defines=["LOW_RES_ENABLED"] permute_with: "default" } - { if: "on_renderer(D3D11, D3D12, GNM, GL)" permute_with: "default" } - ] - - passes = [ - { if: "defined(LAYER_EMISSIVE)" then: [ - { layer="emissive" code_block="core/stingray_renderer/output_nodes/unlit_base#unlit" defines=["BILLBOARD" "MOTION_BLUR"] render_state="core/stingray_renderer/output_nodes/unlit_base#unlit" } - ]} - { if: "defined(LAYER_SKYDOME_BILLBOARD)" then: [ - { layer="skydome_billboard" code_block="core/stingray_renderer/output_nodes/unlit_base#unlit" defines={ macros: ["BILLBOARD"] stages: ["vertex"] } render_state="skydome_billboard" } - ]} - { if: "defined(LAYER_HDR_TRANSPARENT)" then: [ - { layer="hdr_transparent" code_block="core/stingray_renderer/output_nodes/unlit_base#unlit" defines={ macros: ["BILLBOARD"] stages: ["vertex"] } render_state="core/stingray_renderer/output_nodes/unlit_base#unlit" } - ]} - - { if: "defined(LAYER_TRANSPARENT)" then: [ - { layer="transparent" code_block="core/stingray_renderer/output_nodes/unlit_base#unlit" defines={ macros: ["BILLBOARD"] stages: ["vertex"] } render_state="core/stingray_renderer/output_nodes/unlit_base#unlit" } - ] else: [ - { if: "!on_renderer(GL)" then: [ - { layer="wireframe" code_block="core/stingray_renderer/output_nodes/unlit_base#unlit" defines=["BILLBOARD" "DRAW_WIREFRAME"] render_state="core/stingray_renderer/output_nodes/unlit_base#wireframe" branch_key="dev_wireframe" } - ]} - ]} - ] - } -} \ No newline at end of file diff --git a/vmf/core/stingray_renderer/output_nodes/decal_base.shader_node b/vmf/core/stingray_renderer/output_nodes/decal_base.shader_node deleted file mode 100644 index 03d6d09..0000000 --- a/vmf/core/stingray_renderer/output_nodes/decal_base.shader_node +++ /dev/null @@ -1,1107 +0,0 @@ -group = "Output" -display_name = "Decal Base" -output_node = true -render_configs = ["core/stingray_renderer/renderer"] - -inputs = { - "aca690cb-6305-4a2f-bf3d-69183a493db3" = { - name = "base_color" - is_required = false - display_name = "Base Color" - type = { vector3: ["HAS_BASE_COLOR"] } - domain = "pixel" - } - - "ad5e052f-d316-4a0f-8b79-53c38204d61b" = { - is_required = false - name = "base_color_opacity" - display_name = "Base Color Opacity" - type = { scalar: ["HAS_BASE_COLOR_OPACITY"] } - domain = "pixel" - } - - "b1c86408-aacb-4466-b754-ddcf37a3a2c8" = { - is_required = false - name = "normal" - display_name = "Normal" - type = { vector3: ["HAS_NORMAL"] } - domain = "pixel" - } - - "36ba46d2-f6ea-4e60-a428-fdc17c75bc62" = { - is_required = false - name = "normal_opacity" - display_name = "Normal Opacity" - type = { scalar: ["HAS_NORMAL_OPACITY"] } - domain = "pixel" - } - - "7cadc6f1-f753-41c0-9d6d-ca9fb101f144" = { - is_required = false - name = "metallic" - display_name = "Metallic" - type = { scalar: ["HAS_METALLIC"] } - domain = "pixel" - } - - "f6a9f7bc-f229-42ce-9240-146828cbf665" = { - is_required = false - name = "roughness" - display_name = "Roughness" - type = { scalar: ["HAS_ROUGHNESS"] } - domain = "pixel" - } - - "7c1ec98b-14e9-41fb-b356-e881723b8731" = { - is_required = false - name = "metallic_roughness_mask" - display_name = "Metallic/Roughness Mask" - type = { scalar: ["HAS_METALLIC_ROUGHNESS_MASK"] } - domain = "pixel" - } - - "927a23bd-14d7-48a8-9934-04199a82af19" = { - is_required = false - name = "metallic_roughness_threshold" - display_name = "Metallic/Roughness Threshold" - type = { scalar: ["HAS_METALLIC_ROUGHNESS_THRESHOLD"] } - domain = "pixel" - } - - "1164a5ef-4563-4795-b3b5-42825d6df037" = { - is_required = false - name = "emissive" - display_name = "Emissive" - type = { vector3: ["HAS_EMISSIVE"] } - domain = "pixel" - } - - "34259752-b962-4b65-92c3-903a57338519" = { - name = "mask" - is_required = false - display_name = "Mask" - type = { scalar: ["HAS_MASK"] } - domain = "pixel" - } - - "7a9306c6-95ae-4cdb-9fef-0eedacce4e83" = { - name = "mask_threshold" - is_required = false - display_name = "Mask Threshold" - type = { scalar: ["HAS_MASK_THRESHOLD"] } - domain = "pixel" - } - - "59fd1cf4-f736-470d-8510-1dd7c016639e" = { - is_required = false - name = "normal_threshold" - display_name = "Angle Threshold" - type = { scalar: ["HAS_NORMAL_THRESHOLD"] } - domain = "pixel" - } -} - -options = { - "d1a42a54-0794-4d57-9aa0-eb35acb6b35c" = "INSTANCED" - "2b136447-676e-4943-997b-04a28ae68497" = "WORLD_SPACE_NORMAL" - "8df1b8f7-17c2-4ae4-8c4e-25517ec1df46" = "TANGENT_BASIS_FROM_SURFACE" - "d00a0e06-a753-47fd-9ffd-20f091ff7810" = "SOFT_NORMAL_THRESHOLD" - "a2c093fa-a258-44ba-a16d-dc43792ffa38" = "COLOR_ALPHA_FADE" - "462ac943-c3a7-4a8a-ad2e-95f1e7ab9db3" = "FADE_OVER_TIME" - - "d902d6eb-36e4-479f-aac8-10a7afdcbf35" = "GROUP_0" - "2395c420-550a-41fb-9d06-d6988794dca4" = "GROUP_1" - "6cc950bc-76c1-43a5-a413-979084d5f841" = "GROUP_2" - "efb12ce5-bcf8-47ad-94aa-c9094833b2d1" = "GROUP_3" - "421b1c9b-9eb1-4ca6-9364-99178675c355" = "GROUP_01" - "81bd528a-a801-452b-b237-3b442c80557e" = "GROUP_02" - "2c0f5484-4d92-4d38-8e88-972885de2ba4" = "GROUP_13" - "2f1738ff-75c4-4ccf-8345-6879833536a9" = "GROUP_23" - "4035efa3-d637-4d4d-865d-24653f90b7a3" = "GROUP_012" - "82ad5599-11b0-4bf8-bcdf-f77c817f183d" = "GROUP_123" - "1695f356-fa07-4ccd-b181-9d0e6844570d" = "GROUP_023" - "cf3416fb-c210-463b-bb8d-0cf789b72e6c" = "GROUP_013" -} - -ui = [ - { - type = "drop_down" - display_name = "Decal Group" - options = { - "None" = "00000000-0000-0000-0000-000000000000" - "0" = "d902d6eb-36e4-479f-aac8-10a7afdcbf35" - "1" = "2395c420-550a-41fb-9d06-d6988794dca4" - "2" = "6cc950bc-76c1-43a5-a413-979084d5f841" - "3" = "efb12ce5-bcf8-47ad-94aa-c9094833b2d1" - "0, 1" = "421b1c9b-9eb1-4ca6-9364-99178675c355" - "0, 2" = "81bd528a-a801-452b-b237-3b442c80557e" - "1, 3" = "2c0f5484-4d92-4d38-8e88-972885de2ba4" - "2, 3" = "2f1738ff-75c4-4ccf-8345-6879833536a9" - "0, 1, 2" = "4035efa3-d637-4d4d-865d-24653f90b7a3" - "1, 2, 3" = "82ad5599-11b0-4bf8-bcdf-f77c817f183d" - "0, 2, 3" = "1695f356-fa07-4ccd-b181-9d0e6844570d" - "0, 1, 3" = "cf3416fb-c210-463b-bb8d-0cf789b72e6c" - } - default = "00000000-0000-0000-0000-000000000000" - } - - { - type = "drop_down" - display_name = "Normals In" - options = { - "Tangent Space" = "00000000-0000-0000-0000-000000000000" - "World Space" = "2b136447-676e-4943-997b-04a28ae68497" - } - default = "00000000-0000-0000-0000-000000000000" - } - - { - type = "drop_down" - display_name = "Normal Threshold" - options = { - "Hard" = "00000000-0000-0000-0000-000000000000" - "Soft" = "d00a0e06-a753-47fd-9ffd-20f091ff7810" - } - default = "00000000-0000-0000-0000-000000000000" - } - - { - type = "drop_down" - display_name = "Tangent Basis From" - options = { - "Decal Box" = "00000000-0000-0000-0000-000000000000" - "Surface" = "8df1b8f7-17c2-4ae4-8c4e-25517ec1df46" - } - default = "00000000-0000-0000-0000-000000000000" - } - - { - type = "drop_down" - display_name = "Particle Option" - options = { - "none" = "00000000-0000-0000-0000-000000000000" - "Color Alpha Fade" = "a2c093fa-a258-44ba-a16d-dc43792ffa38" - } - default = "00000000-0000-0000-0000-000000000000" - } - - { type = "checkbox" display_name = "Instancing" option = "d1a42a54-0794-4d57-9aa0-eb35acb6b35c" } - { type = "checkbox" display_name = "Fade over time" option = "462ac943-c3a7-4a8a-ad2e-95f1e7ab9db3" } - -] - -render_state = { - decal_stencil = { - state: { - "defined(GROUP_0) || defined(GROUP_1) || defined(GROUP_2) || defined(GROUP_3) || - defined(GROUP_01) || defined(GROUP_02) || defined(GROUP_13) || defined(GROUP_23) || - defined(GROUP_012) || defined(GROUP_123) || defined(GROUP_023) || defined(GROUP_013)" = { - stencil_enable = "true" - stencil_fail = "stencil_op_keep" - stencil_pass = "stencil_op_keep" - stencil_z_fail = "stencil_op_keep" - - stencil_fail_back_side = "stencil_op_keep" - stencil_pass_back_side = "stencil_op_keep" - stencil_z_fail_back_side = "stencil_op_keep" - - stencil_write_mask = "0x0" - } - - "defined(GROUP_0)" = { - stencil_func = "equal" - stencil_func_back_side = "equal" - stencil_mask = "0x60" - stencil_ref = "0x0" - } - "defined(GROUP_1)" = { - stencil_func = "equal" - stencil_func_back_side = "equal" - stencil_mask = "0x60" - stencil_ref = "0x20" - } - "defined(GROUP_2)" = { - stencil_func = "equal" - stencil_func_back_side = "equal" - stencil_mask = "0x60" - stencil_ref = "0x40" - } - "defined(GROUP_3)" = { - stencil_func = "equal" - stencil_func_back_side = "equal" - stencil_mask = "0x60" - stencil_ref = "0x60" - } - "defined(GROUP_01)" = { - stencil_func = "equal" - stencil_func_back_side = "equal" - stencil_mask = "0x40" - stencil_ref = "0x0" - } - "defined(GROUP_02)" = { - stencil_func = "equal" - stencil_func_back_side = "equal" - stencil_mask = "0x20" - stencil_ref = "0x0" - } - "defined(GROUP_13)" = { - stencil_func = "equal" - stencil_func_back_side = "equal" - stencil_mask = "0x20" - stencil_ref = "0x60" - } - "defined(GROUP_23)" = { - stencil_func = "equal" - stencil_func_back_side = "equal" - stencil_mask = "0x40" - stencil_ref = "0x60" - } - "defined(GROUP_012)" = { - stencil_func = "not_equal" - stencil_func_back_side = "not_equal" - stencil_mask = "0x60" - stencil_ref = "0x60" - } - "defined(GROUP_123)" = { - stencil_func = "not_equal" - stencil_func_back_side = "not_equal" - stencil_mask = "0x60" - stencil_ref = "0x0" - } - "defined(GROUP_023)" = { - stencil_func = "not_equal" - stencil_func_back_side = "not_equal" - stencil_mask = "0x60" - stencil_ref = "0x20" - } - "defined(GROUP_013)" = { - stencil_func = "not_equal" - stencil_func_back_side = "not_equal" - stencil_mask = "0x60" - stencil_ref = "0x40" - } - } - } - - decal = { - inherit: ["core/stingray_renderer/shader_libraries/common#opacity" "decal_stencil"] - state: { - cull_mode = "cull_ccw" - z_func = "greater_equal" - z_write_enable = "false" - - "defined(HAS_BASE_COLOR)": { - write_mask0 = "red|green|blue" - } - "!defined(HAS_BASE_COLOR)": { - write_mask0 = "0x0" - } - "defined(HAS_NORMAL)": { - write_mask1 = "red|green|blue" - } - "!defined(HAS_NORMAL)": { - write_mask1 = "0x0" - } - - - } - } - - decal_metal_roughness = { - inherit: ["core/stingray_renderer/shader_libraries/common#default" "decal_stencil"] - state: { - cull_mode = "cull_ccw" - z_func = "greater_equal" - z_write_enable = "false" - - independent_blend_enable = "true" - - "defined(HAS_METALLIC)": { - write_mask0 = "alpha" - } - "!defined(HAS_METALLIC)": { - write_mask0 = "0x0" - } - "defined(HAS_ROUGHNESS)": { - write_mask1 = "alpha" - } - "!defined(HAS_ROUGHNESS)": { - write_mask1 = "0x0" - } - } - } - - emissive = { - inherit: ["core/stingray_renderer/shader_libraries/common#default" "decal_stencil"] - state: { - cull_mode = "cull_ccw" - write_mask0 = "red|green|blue" - z_write_enable = "false" - z_func = "greater_equal" - blend_enable = "true" - blend_op = "blend_op_add" - dest_blend = "blend_one" - src_blend = "blend_one" - } - } - - wireframe = { - inherit: ["core/stingray_renderer/shader_libraries/common#opacity"] - state: { - fill_mode = "fill_wireframe" - "on_renderer(D3D11, D3D12)" = { - depth_bias = "-1" - depth_bias_clamp = "-0.00015" - slope_scale_depth_bias = "-2.0" - } - } - } -} - -sampler_state = {} - -channels = { - "(defined(HAS_NORMAL) && !defined(WORLD_SPACE_NORMAL)) || defined(NEEDS_TANGENT_SPACE)": { - tsm0 = { type = "float3" domain = "pixel" } - tsm1 = { type = "float3" domain = "pixel" } - tsm2 = { type = "float3" domain = "pixel" } - } - - "defined(NEEDS_EYE_VECTOR)": { - eye_vector = { type = "float3" domain = "pixel" } - } - - decal_uv = { type = "float2" domain = "pixel" } - - "defined(NEEDS_OBJECT_POSITION)": { - object_position = { type = "float3" domain = "pixel" } - } - - "defined(NEEDS_WORLD_SPACE_POSITION)": { - world_position = { type = "float3" domain = "pixel" } - } -} - -//log_permutations = true -permutation_sets = { -} - -shader_contexts = { - default = { - passes_sort_mode = "deferred" - compile_with = [ - { if: "on_renderer(D3D11, D3D12, GNM, GL)" } - ] - - passes = [ - { if: "defined(HAS_BASE_COLOR) || defined(HAS_NORMAL)" then: [ - { layer="decals" code_block="decal" defines=["GBUFFER_PASS" "BASE_COLOR_NORMAL_PASS"] render_state="decal" } - ]} - - { if: "defined(HAS_METALLIC) || defined(HAS_ROUGHNESS)" then: [ - { layer="decals" code_block="decal" defines=["GBUFFER_PASS" "METALLIC_ROUGHNESS_PASS"] render_state="decal_metal_roughness" } - ]} - - { if: "defined(HAS_EMISSIVE)" then: [ - { layer="emissive" code_block="decal" defines=["EMISSIVE_PASS"] render_state="emissive" } - ]} - - { if: "!on_renderer(GL)" then: [ - { layer="wireframe" code_block="decal" defines=["WIREFRAME_PASS"] render_state="wireframe" branch_key="dev_wireframe" } - ]} - ] - } -} - -code_blocks = { - decal_common = { - code = { - shared = """ - #if !(defined(RENDERER_GL) && defined(STAGE_VERTEX)) - inline float2 compute_decal_uv(in float3 op, in float4x4 bounding_volume) { - #if defined(RENDERER_GL) - vec2 uv = (op.xz / (vec2(bounding_volume[0].z, bounding_volume[2].z) * 0.5)) * 0.5 + 0.5; - #else - float2 uv = (op.xz / (bounding_volume._m20_m22 * 0.5)) * 0.5 + 0.5; - #endif - - uv.y = 1.0 - uv.y; - return uv; - } - - // Reference: - // Schuler C., "Normal Mapping without Precomputed Tangents", - // Shader X5, pp. 131-140, 2006. - // - inline float3x3 tangent_frame(in float3 n, in float3 p, in float2 uv) - { - // Get edge vectors of the pixel triangle - float3 dp1 = ddx(p); - float3 dp2 = ddy(p); - float2 duv1 = ddx(uv); - float2 duv2 = ddy(uv); - - // solve the linear system - float3 dp2perp = cross(dp2, n); - float3 dp1perp = cross(n, dp1); - float3 tangent = dp2perp * duv1.x + dp1perp * duv2.x; - float3 binormal = dp2perp * duv1.y + dp1perp * duv2.y; - - // construct a scale-invariant frame - float invmax = rsqrt(max(dot(tangent,tangent), dot(binormal,binormal))); - return float3x3(tangent * invmax, binormal * invmax, n); - } - #endif - """ - } - } - - decal = { - include:[ - "core/stingray_renderer/shader_libraries/common#common", - "core/stingray_renderer/shader_libraries/common#gbuffer_access", - "core/stingray_renderer/shader_libraries/common#taa_offsets", - "decal_common" - ] - - instance_data = { - "on_renderer(D3D11, D3D12) && defined(INSTANCED)" : { - world = { type = "matrix4x4" } - - "defined(WIREFRAME_PASS)" : { - dev_wireframe_color = { type = "vector4" } - } - } - } - - samplers = { - linear_depth = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_point" - source = "resource_set" - slot_name = "linear_depth" - type = "2d" - } - - "defined(EMISSIVE_PASS)" : { - gbuffer1 = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "gbuffer1" - type = "2d" - } - } - "defined(GBUFFER_PASS)" : { - normals_copy = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "normals_copy" - type = "2d" - } - } - } - - code = { - glsl = """ - #define INVERSE_Y_TEXCOORD - - #if defined(HAS_NORMAL) && !defined(WORLD_SPACE_NORMAL) - #define NEEDS_TANGENT_SPACE - #endif - - #if defined(HAS_NORMAL_THRESHOLD) || (defined(NEEDS_TANGENT_SPACE) && defined(TANGENT_BASIS_FROM_SURFACE)) - #define NEEDS_GBUFFER_NORMAL - #endif - - CBUFFER_START(c_per_object) - UNIFORM mat4 world_view_proj; - UNIFORM mat4 world; - UNIFORM mat4 inv_world; - UNIFORM mat4 bounding_volume; - CBUFFER_END - - #if defined(STAGE_VERTEX) - layout (location = POSITION0) in vec4 in_position; - - out vec4 v_w; - - #if defined(NEEDS_TANGENT_SPACE) && !defined(TANGENT_BASIS_FROM_SURFACE) - flat out vec3 v_tsm0; - flat out vec3 v_tsm1; - flat out vec3 v_tsm2; - #endif - - #if defined(HAS_NORMAL_THRESHOLD) - flat out vec3 v_decal_box_y; - #endif - - void main() { - vec4 p = in_position * world_view_proj; - v_w = encode_world_pos(p); - - #if defined(NEEDS_TANGENT_SPACE) && !defined(TANGENT_BASIS_FROM_SURFACE) - tspace_transpose( - v_tsm0, v_tsm1, v_tsm2, - normalize(vec3(world[0].x,world[1].x,world[2].x)), - normalize(vec3(world[0].z,world[1].z,world[2].z)), - -normalize(vec3(world[0].y,world[1].y,world[2].y)) - ); - #endif - - #if defined(HAS_NORMAL_THRESHOLD) - v_decal_box_y = -normalize(vec3(world[0].y,world[1].y,world[2].y)); - #endif - - gl_Position = p; - } - #elif defined(STAGE_FRAGMENT) - uniform highp usampler2D linear_depth; - #if defined(NEEDS_GBUFFER_NORMAL) - DECLARE_SAMPLER_2D(gbuffer1); - #endif - - in highp vec4 v_w; - - #if defined(HAS_NORMAL_THRESHOLD) - flat in highp vec3 v_decal_box_y; - #endif - - #if defined(GBUFFER_PASS) - #if defined(NEEDS_TANGENT_SPACE) && !defined(TANGENT_BASIS_FROM_SURFACE) - flat in highp vec3 v_tsm0; - flat in highp vec3 v_tsm1; - flat in highp vec3 v_tsm2; - #endif - - layout(location = 0) out mediump vec4 out_gbuffer0; - layout(location = 1) out mediump vec4 out_gbuffer1; - - #define out_base_color_opacity out_gbuffer0.a - #define out_normal_opacity out_gbuffer1.a - - void main() { - highp vec2 uv = gl_FragCoord.xy/back_buffer_size; - highp float depth = uintBitsToFloat(texture(linear_depth, uv).r); - highp vec3 wp = decode_world_pos(v_w, depth); - highp vec3 op = (vec4(wp, 1.0) * inv_world).xyz; - - // Discard pixel out of decal volume - if (!(all(greaterThan(op, vec3(bounding_volume[0].x,bounding_volume[1].x,bounding_volume[2].x))) && - all(lessThan(op,vec3(bounding_volume[0].y,bounding_volume[1].y,bounding_volume[2].y))))) - discard; - - GraphManualChannels params; - GraphResults graph; - - // Compute graph input data - highp vec2 decal_uv = compute_decal_uv(op, bounding_volume); - GRAPH_PARAM(params, decal_uv) = decal_uv; - - // Compute eye vector - highp vec3 eye_vector = camera_pos - wp; - #if defined(NEEDS_EYE_VECTOR) - GRAPH_PARAM(params, eye_vector) = eye_vector; - #endif - - #if defined(NEEDS_GBUFFER_NORMAL) - highp vec3 wn = gbuffer_decode_normal(TEX2D(gbuffer1, uv)); - #endif - - #if defined(NEEDS_TANGENT_SPACE) - #if defined(TANGENT_BASIS_FROM_SURFACE) - mat3 surface_tbn = tangent_frame(wn, eye_vector, decal_uv); - tspace_transpose( - GRAPH_PARAM(params, tsm0), - GRAPH_PARAM(params, tsm1), - GRAPH_PARAM(params, tsm2), - surface_tbn[0], - -surface_tbn[1], - surface_tbn[2] - ); - #else - GRAPH_PARAM(params, tsm0) = v_tsm0; - GRAPH_PARAM(params, tsm1) = v_tsm1; - GRAPH_PARAM(params, tsm2) = v_tsm2; - #endif - #endif - - graph_evaluate(graph, params); - - #if defined(HAS_MASK) - #if defined(HAS_MASK_THRESHOLD) - float mask_threshold = graph.mask_threshold; - #else - float mask_threshold = 0.5; - #endif - if (graph.mask <= mask_threshold) - discard; - #endif - - #if defined(HAS_NORMAL_THRESHOLD) - if (dot(v_decal_box_y, wn) < graph.normal_threshold) - discard; - #endif - - // Base color - #if defined(HAS_BASE_COLOR) - out_base_color = gbuffer_encode_base_color(graph.base_color); - #if defined(HAS_BASE_COLOR_OPACITY) - out_base_color_opacity = graph.base_color_opacity; - #else - out_base_color_opacity = 1.0; - #endif - #endif - - // Normal - #if defined(HAS_NORMAL) - highp vec3 graph_normal = graph.normal; - #if !defined(WORLD_SPACE_NORMAL) - graph_normal = rotate_vector3( - graph_normal, - GRAPH_PARAM(params, tsm0), - GRAPH_PARAM(params, tsm1), - GRAPH_PARAM(params, tsm2) - ); - #endif - - out_normal = gbuffer_encode_normal(graph_normal); - #if defined(HAS_NORMAL_OPACITY) - out_normal_opacity = graph.normal_opacity; - #else - out_normal_opacity = 1.0; - #endif - #endif - } - #elif defined(EMISSIVE_PASS) - layout(location = 0) out mediump vec4 out_color; - - void main() { - highp vec2 uv = gl_FragCoord.xy/back_buffer_size; - highp float depth = uintBitsToFloat(texture(linear_depth, uv).r); - highp vec3 wp = decode_world_pos(v_w, depth); - highp vec3 op = (vec4(wp, 1.0) * inv_world).xyz; - - // Discard pixel out of decal volume - if (!(all(greaterThan(op, vec3(bounding_volume[0].x,bounding_volume[1].x,bounding_volume[2].x))) && - all(lessThan(op,vec3(bounding_volume[0].y,bounding_volume[1].y,bounding_volume[2].y))))) - discard; - - GraphManualChannels params; - GraphResults graph; - - highp vec2 decal_uv = compute_decal_uv(op, bounding_volume); - GRAPH_PARAM(params, decal_uv) = decal_uv; - graph_evaluate(graph, params); - - #if defined(HAS_MASK) - #if defined(HAS_MASK_THRESHOLD) - float mask_threshold = graph.mask_threshold; - #else - float mask_threshold = 0.5; - #endif - if (graph.mask <= mask_threshold) - discard; - #endif - - #if defined(HAS_NORMAL_THRESHOLD) - highp vec3 wn = gbuffer_decode_normal(TEX2D(gbuffer1, uv)); - if (dot(v_decal_box_y, wn) < graph.normal_threshold) - discard; - #endif - - out_color = vec4(graph.emissive, 0); - } - #endif - #endif - """ - - hlsl = """ - #if defined(INSTANCED) && defined(RENDERER_D3D11) - #define HAS_INSTANCING - #endif - - #if defined(HAS_NORMAL) && !defined(WORLD_SPACE_NORMAL) - #define NEEDS_TANGENT_SPACE - #endif - - #if defined(HAS_NORMAL_THRESHOLD) || (defined(NEEDS_TANGENT_SPACE) && defined(TANGENT_BASIS_FROM_SURFACE)) - #define NEEDS_GBUFFER_NORMAL - #endif - - #if defined(GBUFFER_PASS) || defined(EMISSIVE_PASS) - DECLARE_SAMPLER_2D(linear_depth); - #if defined(NEEDS_GBUFFER_NORMAL) - DECLARE_SAMPLER_2D(gbuffer1); - #if defined(EMISSIVE_PASS) - #else - DECLARE_SAMPLER_2D(normals_copy); - #endif - #endif - #endif - - struct VS_INPUT { - float4 position : POSITION; - }; - - inline void tspace_transpose(out float3 tsm0, out float3 tsm1, in float3 t, in float3 b, in float3 n) { - tsm0 = float3(t.x, b.x, n.x); - tsm1 = float3(t.y, b.y, n.y); - } - - #if defined(HAS_NORMAL_THRESHOLD) - #define DECAL_BOX_Y(o) o.decal_box_y.xyz - #if defined(FADE_OVER_TIME) - #define FADE_ALPHA(o) o.decal_box_y.w - #endif - #else - #if defined(FADE_OVER_TIME) - #define FADE_ALPHA(o) o.fade_alpha - #endif - #endif - - struct PS_INPUT { - float4 position : SV_POSITION; - - #if defined(GBUFFER_PASS) || defined(EMISSIVE_PASS) - float4 w : TEXCOORD0; - #endif - - #if defined(HAS_NORMAL_THRESHOLD) - #if defined(FADE_OVER_TIME) - NO_INTERPOLATION float4 decal_box_y : TEXCOORD1; - #else - NO_INTERPOLATION float3 decal_box_y : TEXCOORD1; - #endif - #else - #if defined(FADE_OVER_TIME) - NO_INTERPOLATION float fade_alpha: TEXCOORD1; - #endif - #endif - - #if defined(NEEDS_TANGENT_SPACE) && !defined(TANGENT_BASIS_FROM_SURFACE) - NO_INTERPOLATION float3 tsm0 : TEXCOORD2; - NO_INTERPOLATION float3 tsm1 : TEXCOORD3; - // NO_INTERPOLATION float3 tsm2 : TEXCOORD4; // cross in ps to calculate this instead of exporting - #endif - - - #if defined(HAS_INSTANCING) - float4 instance_wireframe_color : COLOR0; - #endif - }; - - CBUFFER_START(c_per_object) - float4x4 world_view_proj; - float4x4 world; - float4x4 inv_world; - float4x4 bounding_volume; - float4 dev_wireframe_color; - #if defined(FADE_OVER_TIME) - float start_time; - float life_time; - #endif - #if defined(COLOR_ALPHA_FADE) - float alpha; - #endif - GRAPH_MATERIAL_EXPORTS - CBUFFER_END - - #if defined(HAS_INSTANCING) - Buffer idata; - float ioffset; - #endif - - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - PS_INPUT vs_main(VS_INPUT input - #if defined(HAS_INSTANCING) - , uint instance_id : SV_InstanceId - #endif - ) - { - PS_INPUT o; - - - #if defined(HAS_INSTANCING) - uint offset = (uint)ioffset + instance_id * IDATA_STRIDE; - world[0] = idata.Load(offset + IDATA_world + 0); - world[1] = idata.Load(offset + IDATA_world + 1); - world[2] = idata.Load(offset + IDATA_world + 2); - world[3] = idata.Load(offset + IDATA_world + 3); - - #if defined(WIREFRAME_PASS) - o.instance_wireframe_color = idata.Load(offset + IDATA_dev_wireframe_color); - #endif - #endif - - #if defined(WIREFRAME_PASS) - o.position = mul(input.position, world_view_proj); - return o; - #else - #if defined(NEEDS_TANGENT_SPACE) && !defined(TANGENT_BASIS_FROM_SURFACE) - //tspace_transpose( - // o.tsm0, o.tsm1, o.tsm2, - // normalize(world._m00_m01_m02), - // normalize(world._m20_m21_m22), - // -normalize(world._m10_m11_m12) - // ); - tspace_transpose( - o.tsm0, o.tsm1, - normalize(world._m00_m01_m02), - normalize(world._m20_m21_m22), - -normalize(world._m10_m11_m12) - ); - #endif - - #if defined(HAS_NORMAL_THRESHOLD) - DECAL_BOX_Y(o) = -normalize(world._m10_m11_m12); - //o.decal_box_y = -normalize(world._m10_m11_m12); - #endif - - #if defined(FADE_OVER_TIME) - float fade_alpha = saturate(((start_time + life_time) - time) / 2.0); - //o.fade_alpha = fade_alpha * fade_alpha; - FADE_ALPHA(o) = fade_alpha * fade_alpha; - #endif - - - float4 p = mul(input.position, world_view_proj); - float4 view_space = p / p.w; - view_space.xy += get_vs_halton_offset(frame_number); - o.position = view_space * p.w; - o.w = encode_world_pos(o.position); - - return o; - #endif - } - - #if defined(GBUFFER_PASS) - #define BASE_COLOR_OPACITY(gbuffer) gbuffer.buffer0.a - #define NORMAL_OPACITY(gbuffer) gbuffer.buffer1.a - - struct PS_OUTPUT { - half4 buffer0 : SV_TARGET0; - half4 buffer1 : SV_TARGET1; - }; - - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - PS_OUTPUT ps_main(PS_INPUT input) - { - PS_OUTPUT o; - - half2 uv = input.position.xy/back_buffer_size; - float depth = gbuffer_decode_depth(TEX2D(linear_depth, uv)); - float3 wp = decode_world_pos(input.w, depth); - float3 op = mul(float4(wp, 1.0f), inv_world).xyz; - - // Discard pixel out of decal volume - bool3 inside = ((op > bounding_volume._m00_m01_m02) && (op < bounding_volume._m10_m11_m12)); - if(!all(inside)) - discard; - - GraphPixelParams params; - GraphPixelResults graph; - - // Compute graph input data - float2 decal_uv = compute_decal_uv(op, bounding_volume); - GRAPH_PIXEL_PARAM(params, decal_uv) = decal_uv; - - // Compute eye vector - float3 eye_vector = camera_pos - wp; - #if defined(NEEDS_EYE_VECTOR) - GRAPH_PIXEL_PARAM(params, eye_vector) = eye_vector; - #endif - - #if defined(NEEDS_GBUFFER_NORMAL) - float4 normals = TEX2D(normals_copy, uv); - float3 wn = gbuffer_decode_normal(normals); - float old_roughness = normals.a; - #endif - - #if defined(NEEDS_TANGENT_SPACE) - #if defined(TANGENT_BASIS_FROM_SURFACE) - float3x3 surface_tbn = tangent_frame(wn, eye_vector, decal_uv); - tspace_transpose( - GRAPH_PIXEL_PARAM(params, tsm0), - GRAPH_PIXEL_PARAM(params, tsm1), - GRAPH_PIXEL_PARAM(params, tsm2), - surface_tbn._m00_m01_m02, - -surface_tbn._m10_m11_m12, - surface_tbn._m20_m21_m22 - ); - #else - GRAPH_PIXEL_PARAM(params, tsm0) = input.tsm0; - GRAPH_PIXEL_PARAM(params, tsm1) = input.tsm1; - //GRAPH_PIXEL_PARAM(params, tsm2) = input.tsm2; - GRAPH_PIXEL_PARAM(params, tsm2) = cross(input.tsm0, input.tsm1); - - #endif - #endif - - #if defined(NEEDS_OBJECT_POSITION) - GRAPH_PIXEL_PARAM(params, object_position) = op; - #endif - - #if defined(NEEDS_WORLD_SPACE_POSITION) - GRAPH_PIXEL_PARAM(params, world_position) = wp; - #endif - - GRAPH_EVALUATE_PIXEL(graph, params); - - #if defined(HAS_MASK) - #if defined(HAS_MASK_THRESHOLD) - float mask_threshold = graph.mask_threshold; - #else - float mask_threshold = 0.5f; - #endif - if (graph.mask <= mask_threshold) - discard; - #endif - - float threshold_fade = 1.0; - #if defined(HAS_NORMAL_THRESHOLD) - #if defined(SOFT_NORMAL_THRESHOLD) - //threshold_fade = saturate((dot(input.decal_box_y, wn) - graph.normal_threshold) / (1.0 - graph.normal_threshold)); - threshold_fade = saturate((dot(DECAL_BOX_Y(input), wn) - graph.normal_threshold) / (1.0 - graph.normal_threshold)); - #else - //if (dot(input.decal_box_y, wn) < graph.normal_threshold) - if (dot(DECAL_BOX_Y(input), wn) < graph.normal_threshold) - discard; - #endif - #endif - #if defined(COLOR_ALPHA_FADE) - threshold_fade *= alpha; - #endif - - #if defined(FADE_OVER_TIME) - //threshold_fade *= input.fade_alpha; - threshold_fade *= FADE_ALPHA(input); - #endif - - // Base color - #if defined(BASE_COLOR_NORMAL_PASS) - #if defined(HAS_BASE_COLOR) - BASE_COLOR(o) = gbuffer_encode_base_color(graph.base_color); - #if defined(HAS_BASE_COLOR_OPACITY) - BASE_COLOR_OPACITY(o) = graph.base_color_opacity * threshold_fade; - #else - BASE_COLOR_OPACITY(o) = threshold_fade; - #endif - #endif - - // Normal - #if defined(HAS_NORMAL) - float3 graph_normal = graph.normal; - #if !defined(WORLD_SPACE_NORMAL) - graph_normal = rotate_vector3( - graph_normal, - GRAPH_PIXEL_PARAM(params, tsm0), - GRAPH_PIXEL_PARAM(params, tsm1), - GRAPH_PIXEL_PARAM(params, tsm2) - ); - #endif - - NORMAL(o) = gbuffer_encode_normal(float3(graph_normal)); - #if defined(HAS_NORMAL_OPACITY) - NORMAL_OPACITY(o) = graph.normal_opacity * threshold_fade; - #else - NORMAL_OPACITY(o) = threshold_fade; - #endif - #endif - #elif defined(METALLIC_ROUGHNESS_PASS) - #if defined(HAS_METALLIC_ROUGHNESS_MASK) - #if defined(HAS_METALLIC_ROUGHNESS_THRESHOLD) - float metallic_roughness_threshold = graph.metallic_roughness_threshold; - #else - float metallic_roughness_threshold = 0.5f; - #endif - if (graph.metallic_roughness_mask * threshold_fade <= metallic_roughness_threshold) - discard; - #endif - - #if defined(HAS_METALLIC) - METALLIC(o) = gbuffer_encode_metallic_mask(graph.metallic); - #endif - - #if defined(HAS_ROUGHNESS) - #if defined(FADE_OVER_TIME) - //ROUGHNESS(o) = gbuffer_encode_roughness(lerp(old_roughness, graph.roughness, input.fade_alpha)); - ROUGHNESS(o) = gbuffer_encode_roughness(lerp(old_roughness, graph.roughness, FADE_ALPHA(input))); - #else - ROUGHNESS(o) = gbuffer_encode_roughness(graph.roughness); - #endif - #endif - #endif - - return o; - } - #elif defined(EMISSIVE_PASS) - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - float4 ps_main(PS_INPUT input) : SV_TARGET0 - { - half2 uv = input.position.xy/back_buffer_size; - float depth = gbuffer_decode_depth(TEX2D(linear_depth, uv)); - float3 wp = decode_world_pos(input.w, depth); - float3 op = mul(float4(wp, 1.0f), inv_world).xyz; - - // Discard pixel out of decal volume - bool3 inside = ((op > bounding_volume._m00_m01_m02) && (op < bounding_volume._m10_m11_m12)); - if(!all(inside)) - discard; - - GraphPixelParams params; - GraphPixelResults graph; - - // Compute graph input data - float2 decal_uv = compute_decal_uv(op, bounding_volume); - GRAPH_PIXEL_PARAM(params, decal_uv) = decal_uv; - - #if defined(NEEDS_OBJECT_POSITION) - GRAPH_PIXEL_PARAM(params, object_position) = op; - #endif - - #if defined(NEEDS_WORLD_SPACE_POSITION) - GRAPH_PIXEL_PARAM(params, world_position) = wp; - #endif - - GRAPH_EVALUATE_PIXEL(graph, params); - - #if defined(HAS_MASK) - #if defined(HAS_MASK_THRESHOLD) - float mask_threshold = graph.mask_threshold; - #else - float mask_threshold = 0.5f; - #endif - if (graph.mask <= mask_threshold) - discard; - #endif - - float threshold_fade = 1.0; - #if defined(HAS_NORMAL_THRESHOLD) - float3 wn = gbuffer_decode_normal(TEX2D(gbuffer1, uv)); - #if defined(SOFT_NORMAL_THRESHOLD) - threshold_fade = saturate((dot(input.decal_box_y, wn) - graph.normal_threshold) / (1.0 - graph.normal_threshold)); - #else - if (dot(input.decal_box_y, wn) < graph.normal_threshold) - discard; - #endif - #endif - #if defined(COLOR_ALPHA_FADE) - threshold_fade *= alpha; - #endif - - return float4(graph.emissive * threshold_fade, 0.f); - } - #elif defined(WIREFRAME_PASS) - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - float4 ps_main(PS_INPUT input) : SV_TARGET0 - { - #if defined(HAS_INSTANCING) - return input.instance_wireframe_color; - #else - return dev_wireframe_color; - #endif - } - #endif - """ - } - } -} diff --git a/vmf/core/stingray_renderer/output_nodes/light_base.shader_node b/vmf/core/stingray_renderer/output_nodes/light_base.shader_node deleted file mode 100644 index f2cf195..0000000 --- a/vmf/core/stingray_renderer/output_nodes/light_base.shader_node +++ /dev/null @@ -1,434 +0,0 @@ -group = "Output" -display_name = "Light Base" -output_node = true -render_configs = ["core/stingray_renderer/renderer"] - -inputs = { - "c09a9bb3-95e4-41b6-92af-33c5865fc691" = { - name = "light_color" - is_required = false - display_name = "Light Color" - type = { vector3: ["HAS_LIGHT_COLOR"] } - domain = "pixel" - } -} - -options = { -} - -ui = [ -] - -render_state = { - light_source = { - inherit: ["core/stingray_renderer/shader_libraries/common#default"] - state: { - z_enable = "true" - z_write_enable = "false" - z_func = "greater_equal" - - cull_mode = "cull_ccw" - - blend_enable = "true" - blend_op = "blend_op_add" - dest_blend = "blend_one" - src_blend = "blend_one" - } - } - - light_shadow_mask_write = { - inherit: ["core/stingray_renderer/shader_libraries/common#default"] - state: { - z_enable = "true" - z_write_enable = "false" - z_func = "greater_equal" - cull_mode = "cull_ccw" - - blend_enable = "false" - - "defined(WRITE_R)" = { - write_mask0 = "red" - } - "defined(WRITE_G)" = { - write_mask0 = "green" - } - "defined(WRITE_B)" = { - write_mask0 = "blue" - } - "defined(WRITE_A)" = { - write_mask0 = "alpha" - } - } - } - - light_stencil = { - inherit: ["core/stingray_renderer/shader_libraries/common#default"] - state: { - z_enable = "true" - z_write_enable = "false" - z_func = "less_equal" - - cull_mode = "cull_none" - - write_mask0 = "0x0" - write_mask1 = "0x0" - write_mask2 = "0x0" - write_mask3 = "0x0" - - stencil_enable = "true" - stencil_func = "always" - stencil_fail = "stencil_op_keep" - stencil_pass = "stencil_op_keep" - stencil_ref = "0x0" - stencil_func_back_side = "always" - stencil_fail_back_side = "stencil_op_keep" - stencil_pass_back_side = "stencil_op_keep" - stencil_z_fail = "stencil_op_incr" - stencil_z_fail_back_side = "stencil_op_decr" - } - } -} - -channels = { - vertex_position = { type = "float4" domain = "vertex" } - light_vector = { type="float3" domain="pixel" } -} - -permutation_sets = { - shadow_modifiers = [ - { if: "light_cast_shadows() == true" define: ["SHADOW_MAPPING"] } - { default = true } - ] - - default = [ - { if: "light_type() == omni" define: ["OMNI"] permute_with: "shadow_modifiers" } - { if: "light_type() == spot" define: ["SPOT"] permute_with: "shadow_modifiers" } - { if: "light_type() == box" define: ["BOX"] permute_with: "shadow_modifiers" } - ] -} - -shader_contexts = { - default = { - passes_sort_mode = "immediate" - compile_with = [ - { if: "on_renderer(D3D11, D3D12, GNM)" permute_with: "default" } - ] - - passes = [ - // TODO: skin shading - { code_block="light_source" render_state="light_source" } - ] - } -} - -code_blocks = { - light_source = { - include:[ - "core/stingray_renderer/shader_libraries/common#common", - "core/stingray_renderer/shader_libraries/common#gbuffer_access", - "core/stingray_renderer/shader_libraries/lighting_common#brdf", - "core/stingray_renderer/shader_libraries/shadow_map_common#shadow_bias", - "core/stingray_renderer/shader_libraries/shadow_map_common#shadow_map_filtering", - "core/stingray_renderer/shader_libraries/common#taa_offsets" - ] - - samplers = { - gbuffer0 = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_point" - source = "resource_set" - slot_name = "gbuffer0" - type = "2d" - } - - gbuffer1 = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_point" - source = "resource_set" - slot_name = "gbuffer1" - type = "2d" - } - - linear_depth = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_point" - source = "resource_set" - slot_name = "linear_depth" - type = "2d" - } - - local_lights_shadow_atlas = { - sampler_state = "core/stingray_renderer/shader_libraries/shadow_map_common#shadow_map" - slot_name = "shadow_map_sampler" - type = "2d" - } - - fullscreen_shadow_mask = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_point" - source = "resource_set" - slot_name = "fullscreen_shadow_mask" - type = "2d" - } - } - - code = { - hlsl = """ - DECLARE_SAMPLER_2D(gbuffer0); - DECLARE_SAMPLER_2D(gbuffer1); - DECLARE_SAMPLER_2D(linear_depth); - - #if defined(SHADOW_MASK) - DECLARE_SAMPLER_2D(fullscreen_shadow_mask); - #endif - - #if defined(SHADOW_MAPPING) && (defined(D3D11) || defined(D3D12) || defined(GNM)) - DECLARE_COMPARISON_SAMPLER_2D(local_lights_shadow_atlas); - #endif - - struct VS_INPUT { - float4 position : POSITION; - GRAPH_VERTEX_INPUT - }; - - struct PS_INPUT { - float4 position : SV_POSITION; - #if !defined(STENCIL_MARK) - float4 w : TEXCOORD1; - #endif - GRAPH_PIXEL_INPUT - }; - - CBUFFER_START(c0) - #if defined(SPOT) || defined(BOX) || defined(NEEDS_WORLD_POSE) - float4x4 world; - #endif - #if defined(SPOT) || defined(BOX) || defined(NEEDS_INVERSE_WORLD_POSE) - float4x4 inv_world; - #endif - float4x4 world_view_proj; - GRAPH_MATERIAL_EXPORTS - CBUFFER_END - - CBUFFER_START(light) - float3 light_position; - float3 light_color; - #if defined(OMNI) || defined(SPOT) || defined(PYRAMID) - // start, 1.f/(end-start), exp - float3 light_falloff; - #endif - - #if defined(SPOT) - // scale + bias - float2 light_spot_falloff; - #endif - - #if defined(SHADOW_MAPPING) - #if defined(OMNI) - float4x4 world_to_shadow_maps[6]; - #else - float4x4 world_to_shadow_map; - #endif - #endif - - #if defined(SHADOW_MASK) - float4 shadow_mask; - #endif - - #if defined(PYRAMID) - float3 face_normal_right; - float3 face_normal_left; - float3 face_normal_up; - float3 face_normal_down; - #endif - - #if defined(BOX) - float3 light_box_min; - float3 light_box_max; - #endif - - float3 light_proxy_scale; - CBUFFER_END - - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - PS_INPUT vs_main(VS_INPUT input) { - PS_INPUT o; - - GraphVertexParams params; - GraphVertexResults results; - - // Write automatic params - GRAPH_VERTEX_WRITE_PARAMS(params, input); - - float4 position; - #if defined(BOX) - float3 p = input.position.xyz * light_proxy_scale; - p += (light_box_max + light_box_min) * 0.5; - position = mul(float4(p, 1), world_view_proj); - #else - position = mul(float4(input.position.xyz * light_proxy_scale, 1), world_view_proj); - #endif - - GRAPH_VERTEX_PARAM(params, vertex_position) = position; - - o.position = position; - #if !defined(STENCIL_MARK) - #if defined(SHADOW_MAPPING) - // When using temporal antialiasing we try to cancel out the jitter - // that was introduced in the depth buffer. This is to minimize self occlusion - // that can arrise when performing a depth test beween the jittered depth buffer - // and a non jittered shadow map. - float4 tmp = o.position; - float4 view_space = tmp / tmp.w; - view_space.xy -= get_vs_halton_offset(frame_number); - tmp = view_space * tmp.w; - o.w = encode_world_pos(tmp); - #else - o.w = encode_world_pos(o.position); - #endif - #endif - - // Evaluate all pieces of the graph that should run per-vertex. - GRAPH_EVALUATE_VERTEX(results, params); - - // Write results - GRAPH_VERTEX_WRITE(o, results, params); - - return o; - } - - struct PS_OUTPUT { - half4 base : SV_TARGET0; - }; - - #if defined(STENCIL_MARK) - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - half4 ps_main(PS_INPUT input) : SV_TARGET0 { - return half4(0,0,0,0); - } - #else - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - PS_OUTPUT ps_main(PS_INPUT input - #if defined(GL2) - , float2 wpos : VPOS - #endif - ) - { - PS_OUTPUT o; - o.base = half4(0,0,0,0); - - half2 uv = input.position.xy / back_buffer_size; - float d = gbuffer_decode_depth(TEX2D(linear_depth, uv)); - - float3 wp = decode_world_pos(input.w, d); - float3 V = normalize(camera_world._m30_m31_m32 - wp); - float3 L = float3(0,0,1); - float attn = 1.f; - - #if defined(OMNI) || defined(SPOT) - L = light_position - wp; - float len_L = length(L) + 0.00001f; - attn = light_attenuation(len_L, light_falloff.x, light_falloff.y); - L *= 1.0/len_L; - - float normalized_distance = (len_L - light_falloff.x) * light_falloff.y; - [branch] - if (normalized_distance > 1.0f) discard; - - #if defined(OMNI) && defined(SHADOW_MAPPING) - // The shadows from the faces of an onmni light are populated in the following order and directions. - // float3(-1.0f, 0.0f, 0.0f), - // float3( 1.0f, 0.0f, 0.0f), - // float3( 0.0f, -1.0f, 0.0f), - // float3( 0.0f, 1.0f, 0.0f), - // float3( 0.0f, 0.0f, -1.0f) - // float3( 0.0f, 0.0f, 1.0f), - - // Based on the biggest component of the vector from the shaded position to the light source and its sign, chose the correct - // shadow map index to get the correct world position to shadow map matrix. - const float3 shadow_L = -L; - const int3 is_positive = shadow_L > 0; - const float3 abs_shadow_L = abs(shadow_L); - int test_index = (abs_shadow_L.x > abs_shadow_L.y && abs_shadow_L.x > abs_shadow_L.z) ? 0 + is_positive[0]: (abs_shadow_L.y > abs_shadow_L.z) ? 2 + is_positive[1] : 4 + is_positive[2]; - - // On the cpu side, the whole matrix will be full of zeroes if the face is not casting any shadows. Just test the first element. - const float shadow_active = world_to_shadow_maps[uint(test_index)]._m00 != 0.0f? 1.0f : 0.0f; - float4 ls = mul(float4(wp, 1), world_to_shadow_maps[uint(test_index)]); - #elif defined(SPOT) - float spot_attenuation = spot_angle_attenuation(dot(-L, world._m10_m11_m12), light_spot_falloff.x, light_spot_falloff.y); - if (spot_attenuation == 0.0f) discard; - attn *= spot_attenuation; - #endif - #elif defined(BOX) - L = -world._m10_m11_m12; - float3 op = mul(float4(wp, 1), inv_world).xyz; - float3 containment = (op > light_box_min) * (op < light_box_max); - float mask = dot(containment, containment) == 3; - attn = light_attenuation(op.y, light_box_min.y, 1.f / (light_box_max.y - light_box_min.x)) * mask; - #endif - - #if defined(SHADOW_MAPPING) - #if !defined(OMNI) - float4 ls = mul(float4(wp,1), world_to_shadow_map); - #endif - - #if defined(D3D11) || defined(D3D12) || defined(GNM) - ls.xyz /= ls.w; - ls.z = apply_shadow_depth_comparison_bias(d, ls.z, local_shadow_map_bias); - float2 sm_resolution; - local_lights_shadow_atlas.tex.GetDimensions(sm_resolution.x, sm_resolution.y); - float2 tscale = float2(1.f / sm_resolution.x, 1.f / sm_resolution.y); - half shadow = shadow_intensity_2d(local_lights_shadow_atlas, sm_resolution, ls.xy, ls.z); - #if defined(OMNI) - shadow = (1.0f - shadow_active) + (shadow * 0.25f * shadow_active); - #else - shadow = (shadow * 0.25); - #endif - #endif - #endif - #if defined(SHADOW_MASK) - attn *= dot(TEX2D(fullscreen_shadow_mask, uv), shadow_mask); - #elif defined(SHADOW_MAPPING) - attn *= shadow; - #endif - - #if defined(WRITE_R) || defined(WRITE_G)|| defined(WRITE_B)|| defined(WRITE_A) - o.base = shadow * 0.25; - #else - GraphPixelParams params; - GraphPixelResults graph; - - GRAPH_PIXEL_PARAM(params, light_vector) = L; - - #if defined(HAS_LIGHT_COLOR) - GRAPH_PIXEL_WRITE_PARAMS(params, input); - GRAPH_EVALUATE_PIXEL(graph, params); - - float3 light_col = graph.light_color; - #else - float3 light_col = light_color; - #endif - - half4 gbuffer_0 = TEX2D(gbuffer0, uv); - half4 gbuffer_1 = TEX2D(gbuffer1, uv); - - float3 N = normalize(gbuffer_decode_normal(gbuffer_1)); - half roughness = gbuffer_decode_roughness(gbuffer_1); - - float3 base_color = gbuffer_decode_base_color(gbuffer_0); - half metallic = gbuffer_decode_metallic_mask(gbuffer_0); - // 0.04 is taken as a common value for dielectrics. Source: Real-time rendering 3rd edition. - float3 specular_color = lerp(float3(0.04,0.04,0.04), base_color, metallic); - float3 diffuse_color = lerp(base_color, new_half3(0,0,0), metallic); - - float3 acc_diff = float3(0,0,0); - float3 acc_spec = float3(0,0,0); - - bsdf(L, V, N, light_col, diffuse_color, specular_color, roughness, attn, acc_diff, acc_spec); - - o.base = half4(acc_diff + acc_spec, 0); - #endif - - return o; - } - #endif - """ - } - } -} diff --git a/vmf/core/stingray_renderer/output_nodes/particle_base.shader_node b/vmf/core/stingray_renderer/output_nodes/particle_base.shader_node deleted file mode 100644 index c97551a..0000000 --- a/vmf/core/stingray_renderer/output_nodes/particle_base.shader_node +++ /dev/null @@ -1,1105 +0,0 @@ -group = "Output/Particles" -display_name = "Blend Base" -output_node = true -render_configs = ["core/stingray_renderer/renderer"] - -// TODO: disable sun if it's disabled in environment settings. -// TODO: options to disable shadows, local lights, sun_light. - -inputs = { - "e1d24468-d03e-4884-9b0d-dba23aaa94d6" = { - name = "base_color" - is_required = false - display_name = "Base Color" - type = { vector3: ["HAS_BASE_COLOR"] } - domain = "pixel" - } - - "0752e133-0c01-4fc4-b45a-a629cad4f850" = { - name = "opacity" - is_required = false - display_name = "Opacity" - type = { scalar: ["HAS_OPACITY"] } - domain = "pixel" - } - - "6fd5ebe2-4d15-4ecc-abad-ab9731ea861a" = { - name = "fade_range" - is_required = false - display_name = "Angle Fade Range" - type = { vector2: ["HAS_ANGLE_FADE" "NEEDS_EYE_VECTOR"] } - domain = "pixel" - } -} - -options = { - "e6347231-6647-4bc3-a1d0-f24e1b3e0562" = "EXTERNAL_ROTATION" - "914232a9-5352-43d7-a877-cedfe798541d" = "TANGENT_LOCKED" - "e8e86308-83cd-47a1-ab84-82776b3cf0ca" = "SCREEN_SPACE" - "9775d054-ef17-4ca4-b5a4-8751c6e1eec6" = "PIVOT" - "aaebf627-efab-4c86-8244-359d29d00f33" = "ROTATION" - "47a74b09-1932-40d4-ab90-0ec090fb9643" = "BLEND_ADDITIVE" - "e267562a-65dc-4547-a9fa-6a605b451cae" = "BLEND_PREMULTIPLIED_ALPHA" - "4a42f2e1-1069-4afe-a93f-c7558572780f" = "EMISSIVE_PARTICLES" - "5e380f16-5cc6-482b-9df6-af0d2b3bda3c" = "HAS_CUSTOM_FOV" - "fea9af88-d417-433a-b475-346b6b03e249" = "HIGH_QUALITY" -} - -ui = [ - { - type = "drop_down" - display_name = "Resolution" - options = { - "Low" = "00000000-0000-0000-0000-000000000000" - "Full" = "fea9af88-d417-433a-b475-346b6b03e249" - } - default = "00000000-0000-0000-0000-000000000000" - } - - { - type = "drop_down" - display_name = "Blend Mode" - options = { - "Alpha Blend" = "00000000-0000-0000-0000-000000000000" - "Additive Blend" = "47a74b09-1932-40d4-ab90-0ec090fb9643" - "Pre-Multiplied Alpha Blend" = "e267562a-65dc-4547-a9fa-6a605b451cae" - } - default = "00000000-0000-0000-0000-000000000000" - } - - { - type = "drop_down" - display_name = "Turn-up Algorithms" - options = { - "Disabled" = "00000000-0000-0000-0000-000000000000" - "Screen Space" = "e8e86308-83cd-47a1-ab84-82776b3cf0ca" - "Aligned" = "914232a9-5352-43d7-a877-cedfe798541d" - "Facing" = "e6347231-6647-4bc3-a1d0-f24e1b3e0562" - } - default = "00000000-0000-0000-0000-000000000000" - } - - { - type = "drop_down" - display_name = "Light Calculation Options" - options = { - "Per-Vertex Lighting" = "00000000-0000-0000-0000-000000000000" - "Per-Pixel Shadows" = "22f9eada-ca3f-4261-8ee1-530a7bd828ed" - "Per-Pixel Lighting" = "9514fa9b-ba05-4587-9cb1-663f750a3d5d" - } - default = "00000000-0000-0000-0000-000000000000" - } - - { type = "checkbox" display_name = "Pivot" option = "9775d054-ef17-4ca4-b5a4-8751c6e1eec6" } - { type = "checkbox" display_name = "Rotation" option = "aaebf627-efab-4c86-8244-359d29d00f33" } - { type = "checkbox" display_name = "Emissive particles" option = "4a42f2e1-1069-4afe-a93f-c7558572780f" } - { type = "checkbox" display_name = "Custom FOV" option = "5e380f16-5cc6-482b-9df6-af0d2b3bda3c" } -] - -render_state = { - // TODO: does not work. - shadow_caster = { - inherit: ["core/stingray_renderer/shader_libraries/common#shadow_caster"] - state: { - z_write_enable = "false" - - write_mask0 = "red" - cull_mode = "cull_none" - blend_enable = "true" - - blend_op = "blend_op_add" - src_blend = "blend_one" - dest_blend = "blend_inv_src_color" - } - } - - opacity = { - inherit: ["core/stingray_renderer/shader_libraries/common#opacity"] - state: { - blend_op = "blend_op_add" - src_blend = "blend_one" - dest_blend = "blend_inv_src_alpha" - - "defined(SCREEN_SPACE)": { - cull_mode = "cull_none" - z_enable = "false" - } - "!defined(SCREEN_SPACE)": { - z_enable = "true" - } - "defined(LOW_RES)": { - write_mask0 = "red|green|blue|alpha" - write_mask1 = "red|green" - } - "!defined(LOW_RES)": { - write_mask0 = "red|green|blue" - } - } - } -} - -sampler_state = { - // TODO: inherit from lighting - shadow_map = { - inherit: ["core/stingray_renderer/shader_libraries/common#clamp_point"] - state: { - "on_platform(D3D11, D3D12)": { - comparison_func = "less" - filter = "comparison_min_mag_linear_mip_point" - } - "on_platform(GNM)": { - comparison_func = "less" - filter = "min_mag_mip_linear" - } - "on_platform(GL)": { - comparison_func = "less" - filter = "min_mag_linear" - } - } - } -} - -channels = { - "defined(PARTICLE_LIGHTING)": { - basis0 = { type = "float4" domains = ["vertex", "pixel"] } - basis1 = { type = "float4" domains = ["vertex", "pixel"] } - basis2 = { type = "float4" domains = ["vertex", "pixel"] } - back_lighting = { type = "float3" domains = ["vertex", "pixel"] } - } - - "defined(HAS_ANGLE_FADE)": { - world_space_plane_normal = { type = "float3" domains = ["vertex", "pixel"] } - } - - "defined(NEEDS_EYE_VECTOR)": { - eye_vector = { type = "float3" domains = ["vertex", "pixel"] } - } - - "defined(NEEDS_WORLD_SPACE_NORMAL)": { - world_space_normal = { type = "float3" domains = ["vertex", "pixel"] } - } - - "defined(NEEDS_PIXEL_DEPTH)": { - pixel_depth = { type = "float" domain = "pixel" } - } - - "defined(NEEDS_SCREEN_POS)": { - screen_pos = { type = "float2" domain = "pixel" } - } - - "on_platform(GL)": { - vertex_corner_info = { type = "float2" semantic = "COLOR1" domain = "vertex" } - } - "!on_platform(GL)": { - vertex_corner_info = { type = "float2" semantic = "POSITION1" domain = "vertex" } - } - vertex_size = { type = "float2" semantic = "TEXCOORD7" domain = "vertex" } - "defined(ROTATION)": { - vertex_rotation = { type = "float" semantic = "TEXCOORD1" domains = ["vertex"] } - } - "defined(NEEDS_UV_SCALE)": { - "defined(NEEDS_UV_ANIMATION)": { - vertex_uv_data = { type = "float3" semantic = "TEXCOORD0" domains = ["vertex"] } - uv_frame = { type = "float" domains = ["vertex"] } - } - "!defined(NEEDS_UV_ANIMATION)": { - vertex_uv_data = { type = "float2" semantic = "TEXCOORD0" domains = ["vertex"] } - } - uv_scale = { type = "float2" domains = ["vertex"] } - } - "!defined(NEEDS_UV_SCALE)": { - "defined(NEEDS_UV_ANIMATION)": { - vertex_uv_frame = { type = "float" semantic = "TEXCOORD0" domains = ["vertex"] } - uv_frame = { type = "float" domains = ["vertex"] } - } - } - "defined(PIVOT)": { - vertex_pivot = { type = "float2" semantic = "TEXCOORD6" domains = ["vertex"] } - } - "defined(EXTERNAL_ROTATION) || defined(TANGENT_LOCKED)": { - vertex_tangent = { type = "float3" semantic = "TANGENT" domains = ["vertex"] } - "defined(EXTERNAL_ROTATION)": { - vertex_binormal = { type = "float3" semantic = "BINORMAL" domains = ["vertex"] } - } - } -} - -log_permutations = false -permutation_sets = { - vertex_modifiers = [ - ] - - default = [ - ] - - shadow_caster = [ - ] -} - -shader_contexts = { - default = { - passes_sort_mode = "deferred" - compile_with = [ - { if: "on_renderer(D3D11, D3D12, GNM, GL) && render_cap(development) && render_setting(particle_visualization)" defines=["PARTICLE_DEBUG"] } - { if: "on_renderer(D3D11, D3D12, GNM, GL) && render_setting(low_res_transparency)" defines=["LOW_RES_ENABLED" "LOCAL_LIGHTS"] } - { if: "on_renderer(D3D11, D3D12, GNM, GL)" defines=["LOCAL_LIGHTS"] } - ] - - passes = [ - { if: "defined(PARTICLE_DEBUG)" then: [ - { if: "defined(SCREEN_SPACE)" then: [ - { layer="hdr_transparent_screen_space" code_block="billboard" render_state="opacity" } - ] else: [ - { layer="hdr_transparent" code_block="billboard" render_state="opacity" } - ]} - ] else: [ - { if: "defined(LOW_RES_ENABLED) && !defined(HIGH_QUALITY)" then: [ - { if: "defined(SCREEN_SPACE)" then: [ - { if: "defined(EMISSIVE_PARTICLES)" then: [ - { layer="hdr_transparent_screen_space_low_res" code_block="billboard" render_state="opacity" defines=["LOW_RES"] } - ] else: [ - { layer="hdr_transparent_screen_space_low_res" code_block="billboard" render_state="opacity" defines=["PARTICLE_LIGHTING" "LOW_RES" "VS_FOG"] } - ]} - ] else: [ - { if: "defined(EMISSIVE_PARTICLES)" then: [ - { layer="hdr_transparent_low_res" code_block="billboard" render_state="opacity" defines=["LOW_RES"] } - ] else: [ - { layer="hdr_transparent_low_res" code_block="billboard" render_state="opacity" defines=["PARTICLE_LIGHTING" "LOW_RES" "VS_FOG"] } - ]} - ]} - ] else: [ - { if: "defined(SCREEN_SPACE)" then: [ - { if: "defined(EMISSIVE_PARTICLES)" then: [ - { layer="hdr_transparent_screen_space" code_block="billboard" render_state="opacity" } - ] else: [ - { layer="hdr_transparent_screen_space" code_block="billboard" render_state="opacity" defines=["PARTICLE_LIGHTING" "VS_FOG"] } - ]} - ] else: [ - { if: "defined(EMISSIVE_PARTICLES)" then: [ - { layer="hdr_transparent" code_block="billboard" render_state="opacity" } - ] else: [ - { layer="hdr_transparent" code_block="billboard" render_state="opacity" defines=["PARTICLE_LIGHTING" "VS_FOG"] } - ]} - ]} - ]} - ]} - ] - } -} - -code_blocks = { - particle_lighting = { - code=""" - #if defined(PARTICLE_LIGHTING) - #if defined(D3D11) || defined(GNM) - #define BACK_LIGHTING - #endif - - #if defined(SHADOW_RECEIVING) - #define CALCULATE_LIGHTING - #endif - #endif - """ - } - - billboard = { - language = "hlsl" - - include:[ - "particle_lighting" - "core/stingray_renderer/shader_libraries/common#common", - "core/stingray_renderer/shader_libraries/common#gbuffer_access", - "core/stingray_renderer/shader_libraries/common#fog", - "core/stingray_renderer/shader_libraries/lighting_common#brdf", - "core/stingray_renderer/shader_libraries/common#taa_offsets", - "core/stingray_renderer/shader_libraries/shadow_map_common#shadow_bias" - "core/stingray_renderer/shader_libraries/shadow_map_common#shadow_map_filtering" - "core/stingray_renderer/shader_libraries/lighting_common#clustered_shading" - "core/stingray_renderer/shader_libraries/particle_lighting_common#radiosity_normal_mapping" - "core/stingray_renderer/shader_libraries/particle_lighting_common#particle_debug" ] - - instance_data = { - } - - stage_conditions = { - } - - samplers = { - "defined(DISTORTION)": { - hdr0 = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "hdr0" - type = "2d" - } - } - "defined(PARTICLE_LIGHTING)": { - global_diffuse_map = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "global_diffuse_map" - type = "cube" - } - } - "defined(PARTICLE_LIGHTING) && defined(SHADOW_RECEIVING)": { - sun_shadow_map = { - sampler_state = "shadow_map" - source = "resource_set" - slot_name = "sun_shadow_map" - type = "2d" - } - } - "defined(NEEDS_LINEAR_DEPTH)": { - "defined(LOW_RES)": { - linear_depth = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "linear_depth_div4" - type = "2d" - } - } - "!defined(LOW_RES)": { - linear_depth = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_point" - source = "resource_set" - slot_name = "linear_depth" - type = "2d" - } - } - } - "!defined(LOW_RES)": { - "defined(LOW_RES_ENABLED)": { - hdr_transparent_div4 = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "hdr_transparent_div4" - type = "2d" - } - - hdr_linear_depth_div4 = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "hdr_linear_depth_div4" - type = "2d" - } - } - } - } - - code = """ - #if defined(HAS_NORMAL) && !defined(WORLD_SPACE_NORMAL) - #define NEEDS_TANGENT_SPACE - #endif - - #if defined(NEEDS_PIXEL_DEPTH) || defined(PARTICLE_LIGHTING) || (!defined(LOW_RES) && defined(LOW_RES_ENABLED)) || defined(LOW_RES) - #define PS_NEEDS_WP - #endif - - #if defined(NEEDS_LINEAR_DEPTH) - DECLARE_SAMPLER_2D(linear_depth); - #define HAS_LINEAR_DEPTH - #endif - - struct VS_INPUT { - float4 position : POSITION; - GRAPH_VERTEX_INPUT - }; - - struct PS_INPUT { - float4 position : SV_POSITION; - #if defined(PS_NEEDS_WP) - float3 world_pos : TEXCOORD15; - #endif - #if defined(VS_FOG) - float4 fog_params : TEXCOORD16; - #endif - GRAPH_PIXEL_INPUT - }; - - CBUFFER_START(c_billboard) - #if defined(SCREEN_SPACE) - float4x4 proj; - float4x4 view; - #else - float4x4 view; - float4x4 view_proj; - #endif - #if defined(EMISSIVE_PARTICLES) - float emissive_particle_intensity; - #endif - CBUFFER_END - - CBUFFER_START(c_material_exports) - GRAPH_MATERIAL_EXPORTS - CBUFFER_END - - - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - PS_INPUT vs_main(VS_INPUT input) - { - PS_INPUT o; - - GraphVertexParams params; - GraphVertexResults results; - - // Write automatic params - GRAPH_VERTEX_WRITE_PARAMS(params, input); - - #if defined(EXTERNAL_ROTATION) - float3 y = GRAPH_VERTEX_DATA(input, vertex_tangent); - float3 x = GRAPH_VERTEX_DATA(input, vertex_binormal); - #elif defined(TANGENT_LOCKED) - float3 y = GRAPH_VERTEX_DATA(input, vertex_tangent); - float3 x = normalize(cross(normalize(input.position.xyz - camera_pos), y)); - #elif defined(SCREEN_SPACE) - float3 x = float3(1,0,0); - float3 y = float3(0,1,0); //float3(0,0,1); - #else - float3 x = view._m00_m10_m20; - float3 y = view._m02_m12_m22; - #endif - - #if defined(ROTATION) - float rotation = GRAPH_VERTEX_DATA(input, vertex_rotation); - float c = cos(rotation); - float s = sin(rotation); - float3 x_axis = x * c + y * s; - float3 y_axis = y * c - x * s; - #else - float3 x_axis = x; - float3 y_axis = y; - #endif - - float2 corner_info = GRAPH_VERTEX_DATA(input, vertex_corner_info); - float2 size = GRAPH_VERTEX_DATA(input, vertex_size); - #if defined(PIVOT) - float2 pivot = GRAPH_VERTEX_DATA(input, vertex_pivot); - float2 corner = corner_info * ( (1-(corner_info*0.5+0.5)) * size + corner_info * (pivot * size) ); - #else - float2 corner = corner_info * (size * 0.5); - #endif - - #if defined(SCREEN_SPACE) - float3 wp = input.position.xzy + (x_axis * corner.x + y_axis * corner.y) / float3(normalize(camera_unprojection.xz), 1); - float4 p = float4(wp, 1); //mul(float4(wp, 1), proj); - #else - float3 wp = input.position.xyz + (x_axis * corner.x + y_axis * corner.y); - #if defined(HAS_CUSTOM_FOV) - float4 p = mul(float4(wp, 1),camera_custom_fov_view_projection); - #else - float4 p = mul(float4(wp, 1), view_proj); - #endif - - // TODO: Do we need this for screen space? - #if defined(GBUFFER_PARTICLES) - float4 proj_pos = p / p.w; - proj_pos.xy += get_vs_halton_offset(frame_number); - p = proj_pos * p.w; - #endif - #endif - - #if defined(NEEDS_WORLD_SPACE_NORMAL) || defined(NEEDS_TANGENT_SPACE) || defined(PARTICLE_LIGHTING) - #if defined(SCREEN_SPACE) - float3 normal = view._m01_m11_m21; - #else - float3 normal = normalize(lerp(wp - input.position.xyz, -view._m01_m11_m21, 0.2)); - #endif - normal = mul(normal, (float3x3)view); - #endif - - #if defined(PARTICLE_LIGHTING) - float4 basis0 = float4(0,0,0,1); - float4 basis1 = float4(0,0,0,1); - float4 basis2 = float4(0,0,0,1); - float3 back_lighting = float3(0,0,0); - calc_basis_lighting(basis0, basis1, basis2, back_lighting, wp, normal, view, p); - GRAPH_VERTEX_PARAM(params, basis0) = basis0; - GRAPH_VERTEX_PARAM(params, basis1) = basis1; - GRAPH_VERTEX_PARAM(params, basis2) = basis2; - #if defined(BACK_LIGHTING) - GRAPH_VERTEX_PARAM(params, back_lighting) = back_lighting; - #endif - #endif - - #if defined(NEEDS_TANGENT_SPACE) || defined(HAS_ANGLE_FADE) - float3 n = cross(x_axis, y_axis); - #endif - #if defined(NEEDS_TANGENT_SPACE) - float3 tangent = x_axis; - float3 binormal = y_axis; - GRAPH_VERTEX_PARAM(params, tsm0).rgb = float3(tangent.x, binormal.x, n.x); - GRAPH_VERTEX_PARAM(params, tsm1).rgb = float3(tangent.y, binormal.y, n.y); - GRAPH_VERTEX_PARAM(params, tsm2).rgb = float3(tangent.z, binormal.z, n.z); - #endif - - #if defined(NEEDS_WORLD_SPACE_NORMAL) - GRAPH_VERTEX_PARAM(params, world_space_normal).rgb = normal; - #endif - - #if defined(NEEDS_EYE_VECTOR) - GRAPH_VERTEX_PARAM(params, eye_vector).rgb = camera_pos - wp; - #endif - - // TOOD: Move this code to its own shader node! - #if defined(NEEDS_UV_SCALE) - #if defined(NEEDS_UV_ANIMATION) - GRAPH_VERTEX_PARAM(params, uv_frame) = GRAPH_VERTEX_DATA(input, vertex_uv_data).z; - #endif - GRAPH_VERTEX_PARAM(params, uv_scale) = GRAPH_VERTEX_DATA(input, vertex_uv_data).xy; - #elif defined(NEEDS_UV_ANIMATION) - GRAPH_VERTEX_PARAM(params, uv_frame) = GRAPH_VERTEX_DATA(input, vertex_uv_frame); - #endif - - #if defined(HAS_ANGLE_FADE) - GRAPH_VERTEX_PARAM(params, world_space_plane_normal) = n; - #endif - - // Evaluate all pieces of the graph that should run per-vertex. - GRAPH_EVALUATE_VERTEX(results, params); - - #if defined(PS_NEEDS_WP) - o.world_pos = wp; - #endif - - #if defined(VS_FOG) - const float3 view_dir = camera_world._m30_m31_m32 - wp.xyz; - const float3 camera_dir = camera_world._m10_m11_m12; - const float depth = dot(-view_dir, camera_dir); - o.fog_params = calc_fog_vs(wp, depth); - #endif - - o.position = p; - - // Write results - GRAPH_VERTEX_WRITE(o, results, params); - - return o; - } - - #if defined(GBUFFER_PARTICLES) - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - GBUFFER_OUT ps_main(PS_INPUT input) { - GBUFFER_OUT o; - - GraphPixelParams params; - GraphPixelResults graph; - - GRAPH_PIXEL_WRITE_PARAMS(params, input); - - #if defined(NEEDS_SCREEN_POS) - float2 screen_position = (input.position.xy / back_buffer_size); - GRAPH_PIXEL_PARAM(params, screen_pos) = screen_position; - #endif - - #if defined(PS_NEEDS_WP) - const float3 world_pos = input.world_pos; - const float3 view_dir = camera_world._m30_m31_m32 - world_pos; - const float3 camera_dir = camera_world._m10_m11_m12; - - const float depth = dot(-view_dir, camera_dir); - #endif - #if defined(NEEDS_PIXEL_DEPTH) - GRAPH_PIXEL_PARAM(params, pixel_depth) = depth; - #endif - - GRAPH_EVALUATE_PIXEL(graph, params); - - #if defined(HAS_OPACITY) - #if defined(HAS_OPACITY_THRESHOLD) - float threshold = graph.opacity_threshold; - #else - float threshold = 0.5f; - #endif - if (graph.opacity < threshold) - discard; - #endif - - // Base color - float3 base_color = float3(0,0,0); - #if defined(HAS_BASE_COLOR) - base_color = graph.base_color; - #else - base_color = float3(0.5, 0.5, 0.5); - #endif - BASE_COLOR(o) = gbuffer_encode_base_color(base_color); - - // World space normal - #if defined(HAS_NORMAL) - #if !defined(WORLD_SPACE_NORMAL) - float3 tsm0 = GRAPH_PIXEL_DATA(input, tsm0).xyz; - float3 tsm1 = GRAPH_PIXEL_DATA(input, tsm1).xyz; - float3 tsm2 = GRAPH_PIXEL_DATA(input, tsm2).xyz; - float3 wn = rotate_vector3(graph.normal, tsm0, tsm1, tsm2); - #else - float3 wn = graph.normal; - #endif - #else - float3 wn = normalize((float3)GRAPH_PIXEL_DATA(input, world_space_normal).rgb); - #endif - - NORMAL(o) = gbuffer_encode_normal(wn); - - // Metallic - half metallic_ = 0.f; - #if defined(HAS_METALLIC) - metallic_ = graph.metallic; - #else - metallic_ = 0.f; - #endif - METALLIC(o) = gbuffer_encode_metallic_mask(metallic_); - - // Roughness - half roughness_ = 0.f; - #if defined(HAS_ROUGHNESS) - roughness_ = graph.roughness; - #else - roughness_ = 0.5; - #endif - ROUGHNESS(o) = gbuffer_encode_roughness(roughness_); - - // TODO: Velocity vector - VELOCITY(o) = encode_velocity(0.0); - - // TODO: Expose density - DENSITY(o) = 1.0; - - // Since we don't have baked lighting, we don't use this - // // Ambient Diffuse - // float3 ambient = rgbm_decode(TEXCUBELOD(global_diffuse_map, wn, 0)); - // AMBIENT_DIFFUSE_LIGHT(o) = gbuffer_encode_ambient_diffuse_light(ambient); - - #if defined(HAS_AMBIENT_OCCLUSION) - AMBIENT_OCCLUSION(o) = gbuffer_encode_ambient_occlusion(graph.ambient_occlusion); - #else - AMBIENT_OCCLUSION(o) = gbuffer_encode_ambient_occlusion(1.f); - #endif - - return o; - } - #elif defined(DISTORTION) // TODO: avoid sample from objects infront of the "distortion" - DECLARE_SAMPLER_2D(hdr0); - #if !defined(LOW_RES) && defined(LOW_RES_ENABLED) - DECLARE_SAMPLER_2D(hdr_transparent_div4); - DECLARE_SAMPLER_2D(hdr_linear_depth_div4); - #endif - - #ifdef LOW_RES - struct PS_OUTPUT { - half4 color : SV_TARGET0; - half4 depth : SV_TARGET1; - }; - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - PS_OUTPUT ps_main(PS_INPUT input) - #else - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - half4 ps_main(PS_INPUT input) : SV_TARGET0 - #endif - { - GraphPixelParams params; - GraphPixelResults graph; - - GRAPH_PIXEL_WRITE_PARAMS(params, input); - - #if (!defined(LOW_RES) && defined(LOW_RES_ENABLED)) || defined(NEEDS_SCREEN_POS) - #if defined(LOW_RES) - float2 screen_position = input.position.xy / (back_buffer_size * 0.25); - #else - float2 screen_position = (input.position.xy / back_buffer_size); - #endif - #endif - - #if defined(NEEDS_SCREEN_POS) - GRAPH_PIXEL_PARAM(params, screen_pos) = screen_position; - #endif - - #if defined(PS_NEEDS_WP) - const float3 world_pos = input.world_pos; - const float3 view_dir = camera_world._m30_m31_m32 - world_pos; - const float3 camera_dir = camera_world._m10_m11_m12; - - const float depth = dot(-view_dir, camera_dir); - #endif - #if defined(NEEDS_PIXEL_DEPTH) - GRAPH_PIXEL_PARAM(params, pixel_depth) = depth; - #endif - - GRAPH_EVALUATE_PIXEL(graph, params); - - float3 normal = graph.distortion_normal; - normal.rg = normal.rg * 2 - 1; - half2 distortion = normal.xy / back_buffer_size; - - #if defined(HAS_OPACITY) - half opacity = saturate(graph.opacity); - #else - half opacity = 0.5; - #endif - - #if !defined(LOW_RES) && defined(LOW_RES_ENABLED) - // Fade out high resolution particle if the low resolution particles is infront of the high resolution particle - float2 particle_depth_values = TEX2D(hdr_linear_depth_div4, screen_position).rg; - float depth_mean = particle_depth_values.x; - float depth_variance = particle_depth_values.y - depth_mean*depth_mean; - float background_depth = depth; - - float diff = max(background_depth - depth_mean, 0.0); - float C = 1.38629436112; // 2 * ln(2) - float T = exp2(-diff*diff / (C * max(depth_variance, 0.001))); - float alpha_modifier = TEX2D(hdr_transparent_div4, screen_position).a * (1.0 - T); - opacity *= 1.0 - alpha_modifier; - #endif - - float3 color = TEX2D(hdr0, screen_position + (distortion * graph.distortion_strength)).rgb; - - #if defined(HAS_BASE_COLOR) - color *= graph.base_color; - #endif - - #ifdef LOW_RES - PS_OUTPUT o; - o.color = half4(color * opacity, opacity); - float alpha_depth = depth * opacity; - o.depth = half4(alpha_depth, alpha_depth * alpha_depth, 0.0, opacity); - return o; - #else - #if defined(PARTICLE_DEBUG) - return DISTORTION_PARTICLES_DEBUG_COLOR; - #else - return half4(color * opacity, opacity); - #endif - #endif - } - #else - #if !defined(LOW_RES) && defined(LOW_RES_ENABLED) - DECLARE_SAMPLER_2D(hdr_transparent_div4); - DECLARE_SAMPLER_2D(hdr_linear_depth_div4); - #endif - - #ifdef LOW_RES - struct PS_OUTPUT { - half4 color : SV_TARGET0; - half4 depth : SV_TARGET1; - }; - - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - PS_OUTPUT ps_main(PS_INPUT input) - #else - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - half4 ps_main(PS_INPUT input) : SV_TARGET0 - #endif - { - GraphPixelParams params; - GraphPixelResults graph; - - GRAPH_PIXEL_WRITE_PARAMS(params, input); - - #if (!defined(LOW_RES) && defined(LOW_RES_ENABLED)) || defined(NEEDS_SCREEN_POS) - #if defined(LOW_RES) - float2 screen_position = input.position.xy / (back_buffer_size * 0.25); - #else - float2 screen_position = (input.position.xy / back_buffer_size); - #endif - #endif - - #if defined(NEEDS_SCREEN_POS) - GRAPH_PIXEL_PARAM(params, screen_pos) = screen_position; - #endif - - #if defined(PS_NEEDS_WP) - const float3 world_pos = input.world_pos; - const float3 view_dir = camera_world._m30_m31_m32 - world_pos; - const float3 camera_dir = camera_world._m10_m11_m12; - - const float depth = dot(-view_dir, camera_dir); - #endif - #if defined(NEEDS_PIXEL_DEPTH) - GRAPH_PIXEL_PARAM(params, pixel_depth) = depth; - #endif - - GRAPH_EVALUATE_PIXEL(graph, params); - - #if defined(HAS_OPACITY) - half opacity = saturate(graph.opacity); - #else - half opacity = 0.5; - #endif - - #if defined(HAS_BASE_COLOR) - float4 color = float4(graph.base_color, opacity); - #else - float4 color = float4(1,1,1, opacity); - #endif - - #if defined(PARTICLE_LIGHTING) - float4 basis0 = GRAPH_PIXEL_DATA(input, basis0); - float4 basis1 = GRAPH_PIXEL_DATA(input, basis1); - float4 basis2 = GRAPH_PIXEL_DATA(input, basis2); - #if defined(BACK_LIGHTING) - float3 back_lighting = GRAPH_PIXEL_DATA(input, back_lighting); - #endif - float3 normal = normalize(float3(basis0.w, basis1.w, basis2.w)); - color.rgb = calc_lighting(color, normal, back_lighting, basis0.xyz, basis1.xyz, basis2.xyz); - #if defined(VS_FOG) - // apply vs calculated fog - color.rgb = lerp(color.rgb, input.fog_params.rgb, input.fog_params.a); - #else - color = apply_fog(color, world_pos, depth); - #endif - #elif defined(EMISSIVE_PARTICLES) - color.rgb *= emissive_particle_intensity; - #endif - - #if defined(HAS_ANGLE_FADE) - float3 plane_wn = normalize(GRAPH_PIXEL_DATA(input, world_space_plane_normal)); - float3 eye_dir = normalize(GRAPH_PIXEL_DATA(input, eye_vector)); - float fade = dot(plane_wn, eye_dir); - opacity *= saturate((fade - graph.fade_range.x) / (graph.fade_range.y - graph.fade_range.x)); - #endif - - #if !defined(LOW_RES) && defined(LOW_RES_ENABLED) && !defined(SCREEN_SPACE) - // Fade out high resolution particle if the low resolution particles is infront of the high resolution particle - float2 particle_depth_values = TEX2D(hdr_linear_depth_div4, screen_position).rg; - float depth_mean = particle_depth_values.x; - float depth_variance = particle_depth_values.y - depth_mean*depth_mean; - float background_depth = depth; - - float diff = max(background_depth - depth_mean, 0.0); - float C = 1.38629436112; // 2 * ln(2) - float T = exp2(-diff*diff / (C * max(depth_variance, 0.001))); - float alpha_modifier = TEX2D(hdr_transparent_div4, screen_position).a * (1.0 - T); - opacity *= 1.0 - alpha_modifier; - #endif - - half4 output_color; - #if defined(BLEND_ADDITIVE) - output_color = half4(color.rgb * opacity, 0.0); - #elif defined(BLEND_PREMULTIPLIED_ALPHA) - output_color = half4(color.rgb, opacity); - #else - output_color = half4(color.rgb * opacity, opacity); - #endif - - #ifdef LOW_RES - PS_OUTPUT o; - o.color = output_color; - float alpha_depth = depth * opacity; - o.depth = half4(alpha_depth, alpha_depth * alpha_depth, 0.0, opacity); - return o; - #else - #if defined(PARTICLE_DEBUG) - #if defined(EMISSIVE_PARTICLES) - return EMISSIVE_PARTICLES_DEBUG_COLOR; - #else - return LIT_PARTICLES_DEBUG_COLOR; - #endif - #else - return output_color; - #endif - #endif - } - #endif - """ - } - - depth_only = { - language = "hlsl" - - include:[ - "core/stingray_renderer/shader_libraries/common#common", - "core/stingray_renderer/shader_libraries/common#gbuffer_access" ] - - instance_data = { - } - - /*stage_conditions = { - tessellation_control = "defined(DX11_DISPLACEMENT_MAPPING)" - }*/ - - samplers = { - "defined(DISTORTION)": { - hdr0 = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "hdr0" - type = "2d" - } - } - } - - code = """ - #if defined(HAS_NORMAL) && !defined(WORLD_SPACE_NORMAL) - #define NEEDS_TANGENT_SPACE - #endif - - struct VS_INPUT { - float4 position : POSITION; - GRAPH_VERTEX_INPUT - }; - - struct PS_INPUT { - float4 position : SV_POSITION; - GRAPH_PIXEL_INPUT - }; - - CBUFFER_START(c_billboard) - #if defined(SCREEN_SPACE) - float4x4 proj; - float4x4 view; - #else - float4x4 view; - float4x4 view_proj; - #endif - GRAPH_MATERIAL_EXPORTS - CBUFFER_END - - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - PS_INPUT vs_main(VS_INPUT input) - { - PS_INPUT o; - - GraphVertexParams params; - GraphVertexResults results; - - // Write automatic params - GRAPH_VERTEX_WRITE_PARAMS(params, input); - - #if defined(EXTERNAL_ROTATION) - float3 y = GRAPH_VERTEX_DATA(input, vertex_tangent); - float3 x = GRAPH_VERTEX_DATA(input, vertex_binormal); - #elif defined(TANGENT_LOCKED) - float3 y = GRAPH_VERTEX_DATA(input, vertex_tangent); - float3 x = normalize(cross(normalize(input.position.xyz - camera_pos), y)); - #elif defined(SCREEN_SPACE) - float3 x = float3(1,0,0); - float3 y = float3(0,1,0); //float3(0,0,1); - #else - float3 x = view._m00_m10_m20; - float3 y = view._m02_m12_m22; - #endif - - #if defined(ROTATION) - float rotation = GRAPH_VERTEX_DATA(input, vertex_rotation); - float c = cos(rotation); - float s = sin(rotation); - float3 x_axis = x * c + y * s; - float3 y_axis = y * c - x * s; - #else - float3 x_axis = x; - float3 y_axis = y; - #endif - - float2 corner_info = GRAPH_VERTEX_DATA(input, vertex_corner_info); - float2 size = GRAPH_VERTEX_DATA(input, vertex_size); - #if defined(PIVOT) - float2 pivot = GRAPH_VERTEX_DATA(input, vertex_pivot); - float2 corner = corner_info * ( (1-(corner_info*0.5+0.5)) * size + corner_info * (pivot * size) ); - #else - float2 corner = corner_info * (size * 0.5); - #endif - - #if defined(SCREEN_SPACE) - float3 wp = input.position.xzy + (x_axis * corner.x + y_axis * corner.y) / float3(camera_unprojection.xz, 1); - float4 p = float4(wp, 1); //mul(float4(wp, 1), proj); - #else - float3 wp = input.position.xyz + (x_axis * corner.x + y_axis * corner.y); - #if defined(HAS_CUSTOM_FOV) - float4 p = mul(float4(wp, 1),camera_custom_fov_view_projection); - #else - float4 p = mul(float4(wp, 1), view_proj); - #endif - #endif - - #if defined(NEEDS_WORLD_SPACE_NORMAL) || defined(NEEDS_TANGENT_SPACE) - #if defined(SCREEN_SPACE) - float3 normal = view._m01_m11_m21; - #else - float3 normal = normalize(lerp(wp - input.position.xyz, -view._m01_m11_m21, 0.2)); - #endif - normal = mul(normal, (float3x3)view); - #endif - - #if defined(NEEDS_UV) - GRAPH_VERTEX_PARAM(params, uv) = (corner_info * float2(1,-1) * 0.5 + 0.5); - #endif - - #if defined(NEEDS_TANGENT_SPACE) - float3 n = cross(x_axis, y_axis); - float3 tangent = x_axis; - float3 binormal = y_axis; - GRAPH_VERTEX_PARAM(params, tsm0).rgb = float3(tangent.x, binormal.x, n.x); - GRAPH_VERTEX_PARAM(params, tsm1).rgb = float3(tangent.y, binormal.y, n.y); - GRAPH_VERTEX_PARAM(params, tsm2).rgb = float3(tangent.z, binormal.z, n.z); - #endif - - #if defined(NEEDS_WORLD_SPACE_NORMAL) - GRAPH_VERTEX_PARAM(params, world_space_normal).rgb = normal; - #endif - - #if defined(NEEDS_EYE_VECTOR) - GRAPH_VERTEX_PARAM(params, eye_vector).rgb = camera_pos - wp; - #endif - - #if defined(NEEDS_UV_SCALE) - #if defined(NEEDS_UV_ANIMATION) - GRAPH_VERTEX_PARAM(params, uv_frame) = GRAPH_VERTEX_DATA(input, vertex_uv_data).z; - #endif - GRAPH_VERTEX_PARAM(params, uv_scale) = GRAPH_VERTEX_DATA(input, vertex_uv_data).xy; - #elif defined(NEEDS_UV_ANIMATION) - GRAPH_VERTEX_PARAM(params, uv_frame) = GRAPH_VERTEX_DATA(input, vertex_uv_frame); - #endif - - // Evaluate all pieces of the graph that should run per-vertex. - GRAPH_EVALUATE_VERTEX(results, params); - - o.position = p; - - // Write results - GRAPH_VERTEX_WRITE(o, results, params); - - return o; - } - - #if defined(GBUFFER_PARTICLES) - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - float4 ps_main(PS_INPUT input) : SV_TARGET0 - { - #if defined(HAS_OPACITY) - GraphPixelParams params; - GraphPixelResults graph; - - GRAPH_PIXEL_WRITE_PARAMS(params, input); - GRAPH_EVALUATE_PIXEL(graph, params); - - #if defined(HAS_OPACITY_THRESHOLD) - float threshold = graph.opacity_threshold; - #else - float threshold = 0.5f; - #endif - if (graph.opacity < threshold) - discard; - #endif - - return float4(1,1,1,1); - } - #else - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - float4 ps_main(PS_INPUT input) : SV_TARGET0 - { - #if defined(HAS_OPACITY) - GraphPixelParams params; - GraphPixelResults graph; - - GRAPH_PIXEL_WRITE_PARAMS(params, input); - GRAPH_EVALUATE_PIXEL(graph, params); - - half opacity = saturate(graph.opacity); - #else - half opacity = 0.5; - #endif - - return opacity.xxxx; - } - #endif - """ - } -} \ No newline at end of file diff --git a/vmf/core/stingray_renderer/output_nodes/particle_distortion_base.shader_node b/vmf/core/stingray_renderer/output_nodes/particle_distortion_base.shader_node deleted file mode 100644 index d9eb164..0000000 --- a/vmf/core/stingray_renderer/output_nodes/particle_distortion_base.shader_node +++ /dev/null @@ -1,175 +0,0 @@ -group = "Output/Particles" -display_name = "Distortion Base" -output_node = true -render_configs = ["core/stingray_renderer/renderer"] - -inputs = { - "1570ceed-8c40-4b7d-ba45-1bfe7722fed2" = { - name = "base_color" - is_required = false - display_name = "Base Color" - type = { vector3: ["HAS_BASE_COLOR"] } - domain = "pixel" - } - - "cdc6c110-5859-461a-9934-17e54089c764" = { - name = "opacity" - is_required = false - display_name = "Opacity" - type = { scalar: ["HAS_OPACITY"] } - domain = "pixel" - } - - "c050103c-1b43-4fbc-9547-d0c0d3f40ba6" = { - is_required = true - name = "distortion_normal" - display_name = "Distortion Normal" - domain = "pixel" - type = "vector3" - } - - "402a4a8d-b721-4746-9a2d-90027c4aad68" = { - is_required = true - name = "distortion_strength" - display_name = "Distortion Strength" - domain = "pixel" - type = "vector2" - } -} - -options = { - "2b136447-676e-4943-997b-04a28ae68497" = "WORLD_SPACE_NORMAL" - "a5733c57-be1f-457f-a6fc-366d9c0e3c8c" = "EXTERNAL_ROTATION" - "d63603f1-8cc0-4b03-a9aa-b787902c6997" = "TANGENT_LOCKED" - "f38425db-9f78-4f2c-95ba-634a367b7aed" = "SCREEN_SPACE" - "cae9d51b-35c3-40f7-9805-119d7932cfcf" = "PIVOT" - "6ce8aa19-350e-49b8-bb39-444a60db482d" = "ROTATION" - "b770b6bb-1e81-4937-8032-fec369a05ea3" = "HAS_CUSTOM_FOV" - "fea9af88-d417-433a-b475-346b6b03e249" = "HIGH_QUALITY" -} - -ui = [ - { - type = "drop_down" - display_name = "Resolution" - options = { - "Low" = "00000000-0000-0000-0000-000000000000" - "Full" = "fea9af88-d417-433a-b475-346b6b03e249" - } - default = "00000000-0000-0000-0000-000000000000" - } - { - type = "drop_down" - display_name = "Turn-up Algorithms" - options = { - "Disabled" = "00000000-0000-0000-0000-000000000000" - "Screen Space" = "f38425db-9f78-4f2c-95ba-634a367b7aed" - "Aligned" = "d63603f1-8cc0-4b03-a9aa-b787902c6997" - "Facing" = "a5733c57-be1f-457f-a6fc-366d9c0e3c8c" - } - default = "00000000-0000-0000-0000-000000000000" - } - - { type = "checkbox" display_name = "Pivot" option = "cae9d51b-35c3-40f7-9805-119d7932cfcf" } - { type = "checkbox" display_name = "Rotation" option = "6ce8aa19-350e-49b8-bb39-444a60db482d" } - { type = "checkbox" display_name = "Custom FOV" option = "b770b6bb-1e81-4937-8032-fec369a05ea3" } -] - -render_state = { - shadow_caster = { - inherit: ["core/stingray_renderer/output_nodes/particle_base#shadow_caster"] - } - - opacity = { - inherit: ["core/stingray_renderer/output_nodes/particle_base#opacity"] - } -} - -channels = { - "defined(NEEDS_EYE_VECTOR)": { - eye_vector = { type = "float3" domain = "vertex" } - } - - "defined(NEEDS_WORLD_SPACE_NORMAL)": { - world_space_normal = { type = "float3" domains = ["vertex", "pixel"] } - } - - "defined(NEEDS_PIXEL_DEPTH)": { - pixel_depth = { type = "float" domain = "pixel" } - } - - "defined(NEEDS_SCREEN_POS)": { - screen_pos = { type = "float2" domain = "pixel" } - } - - "on_platform(GL)": { - vertex_corner_info = { type = "float2" semantic = "COLOR1" domain = "vertex" } - } - "!on_platform(GL)": { - vertex_corner_info = { type = "float2" semantic = "POSITION1" domain = "vertex" } - } - vertex_size = { type = "float2" semantic = "TEXCOORD7" domain = "vertex" } - "defined(ROTATION)": { - vertex_rotation = { type = "float" semantic = "TEXCOORD1" domains = ["vertex"] } - } - "defined(NEEDS_UV_SCALE)": { - "defined(NEEDS_UV_ANIMATION)": { - vertex_uv_data = { type = "float3" semantic = "TEXCOORD0" domains = ["vertex"] } - uv_frame = { type = "float" domains = ["vertex"] } - } - "!defined(NEEDS_UV_ANIMATION)": { - vertex_uv_data = { type = "float2" semantic = "TEXCOORD0" domains = ["vertex"] } - } - uv_scale = { type = "float2" domains = ["vertex"] } - } - "!defined(NEEDS_UV_SCALE)": { - "defined(NEEDS_UV_ANIMATION)": { - vertex_uv_frame = { type = "float" semantic = "TEXCOORD0" domains = ["vertex"] } - uv_frame = { type = "float" domains = ["vertex"] } - } - } - "defined(PIVOT)": { - vertex_pivot = { type = "float2" semantic = "TEXCOORD6" domains = ["vertex"] } - } - "defined(EXTERNAL_ROTATION) || defined(TANGENT_LOCKED)": { - vertex_tangent = { type = "float3" semantic = "TANGENT" domains = ["vertex"] } - "defined(EXTERNAL_ROTATION)": { - vertex_binormal = { type = "float3" semantic = "BINORMAL" domains = ["vertex"] } - } - } -} - -shader_contexts = { - default = { - passes_sort_mode = "deferred" - compile_with = [ - { if: "on_renderer(D3D11, D3D12, GNM, GL) && render_cap(development) && render_setting(particle_visualization)" defines=["PARTICLE_DEBUG"] } - //{ if: "on_renderer(D3D11, D3D12, GNM, GL) && render_setting(low_res_transparency)" defines=["LOW_RES_ENABLED"] } - { if: "on_renderer(D3D11, D3D12, GNM, GL)" } - ] - - passes = [ - { if: "defined(PARTICLE_DEBUG)" then: [ - { if: "defined(SCREEN_SPACE)" then: [ - { layer="hdr_transparent_screen_space_low_res" code_block="core/stingray_renderer/output_nodes/particle_base#billboard" defines=["DISTORTION"] render_state="opacity" } - ] else: [ - { layer="hdr_transparent_low_res" code_block="core/stingray_renderer/output_nodes/particle_base#billboard" defines=["DISTORTION"] render_state="opacity" } - ]} - ] else: [ - { if: "defined(LOW_RES_ENABLED) && !defined(HIGH_QUALITY)" then: [ - { if: "defined(SCREEN_SPACE)" then: [ - { layer="hdr_transparent_screen_space_low_res" code_block="core/stingray_renderer/output_nodes/particle_base#billboard" defines=["DISTORTION" "LOW_RES"] render_state="opacity" } - ] else: [ - { layer="hdr_transparent_low_res" code_block="core/stingray_renderer/output_nodes/particle_base#billboard" defines=["DISTORTION" "LOW_RES"] render_state="opacity" } - ]} - ] else: [ - { if: "defined(SCREEN_SPACE)" then: [ - { layer="hdr_transparent_screen_space" code_block="core/stingray_renderer/output_nodes/particle_base#billboard" defines=["DISTORTION"] render_state="opacity" } - ] else: [ - { layer="hdr_transparent" code_block="core/stingray_renderer/output_nodes/particle_base#billboard" defines=["DISTORTION"] render_state="opacity" } - ]} - ]} - ]} - ] - } -} \ No newline at end of file diff --git a/vmf/core/stingray_renderer/output_nodes/particle_gbuffer_base.shader_node b/vmf/core/stingray_renderer/output_nodes/particle_gbuffer_base.shader_node deleted file mode 100644 index 1c261ea..0000000 --- a/vmf/core/stingray_renderer/output_nodes/particle_gbuffer_base.shader_node +++ /dev/null @@ -1,198 +0,0 @@ -group = "Output/Particles" -display_name = "GBuffer Base" -output_node = true -render_configs = ["core/stingray_renderer/renderer"] - -inputs = { - "f47209cb-36b0-499c-8c37-857888098e1c" = { - name = "base_color" - is_required = false - display_name = "Base Color" - type = { vector3: ["HAS_BASE_COLOR"] } - domain = "pixel" - } - - "2edbfd6b-4985-4acd-ad0e-cbafb0272a27" = { - name = "opacity" - is_required = false - display_name = "Opacity" - type = { scalar: ["HAS_OPACITY"] } - domain = "pixel" - } - - "9b191b4d-05f1-4f21-b883-d34d9c440b99" = { - name = "opacity_threshold" - is_required = false - display_name = "Opacity Threshold" - type = { scalar: ["HAS_OPACITY_THRESHOLD"] } - domain = "pixel" - } - - "4d3bf516-a2b7-4709-b973-707ebf593845" = { - is_required = false - name = "normal" - display_name = "Normal" - type = { vector3: ["HAS_NORMAL"] } - domain = "pixel" - } - - "98d6ab4a-2569-415d-82c4-ab8115438a28" = { - is_required = false - name = "metallic" - display_name = "Metallic" - type = { scalar: ["HAS_METALLIC"] } - domain = "pixel" - } - - "2a34232c-88b9-485e-b009-9d3470d02943" = { - is_required = false - name = "roughness" - display_name = "Roughness" - type = { scalar: ["HAS_ROUGHNESS"] } - domain = "pixel" - } - - "cfd2c734-e369-47db-b315-41a9bcacc441" = { - is_required = false - name = "ambient_occlusion" - display_name = "Ambient Occlusion" - type = { scalar: ["HAS_AMBIENT_OCCLUSION"] } - domain = "pixel" - } -} - -options = { - "2b136447-676e-4943-997b-04a28ae68497" = "WORLD_SPACE_NORMAL" - "a5733c57-be1f-457f-a6fc-366d9c0e3c8c" = "EXTERNAL_ROTATION" - "d63603f1-8cc0-4b03-a9aa-b787902c6997" = "TANGENT_LOCKED" - "f38425db-9f78-4f2c-95ba-634a367b7aed" = "SCREEN_SPACE" - "cae9d51b-35c3-40f7-9805-119d7932cfcf" = "PIVOT" - "6ce8aa19-350e-49b8-bb39-444a60db482d" = "ROTATION" - "3eca2035-4349-4d1a-ae8b-6b1d8b91033f" = "HAS_CUSTOM_FOV" -} - -ui = [ - { - type = "drop_down" - display_name = "Normals In" - options = { - "Tangent Space" = "00000000-0000-0000-0000-000000000000" - "World Space" = "2b136447-676e-4943-997b-04a28ae68497" - } - default = "00000000-0000-0000-0000-000000000000" - } - - { - type = "drop_down" - display_name = "Turn-up Algorithms" - options = { - "Disabled" = "00000000-0000-0000-0000-000000000000" - "Screen Space" = "f38425db-9f78-4f2c-95ba-634a367b7aed" - "Aligned" = "d63603f1-8cc0-4b03-a9aa-b787902c6997" - "Facing" = "a5733c57-be1f-457f-a6fc-366d9c0e3c8c" - } - default = "00000000-0000-0000-0000-000000000000" - } - - { type = "checkbox" display_name = "Pivot" option = "cae9d51b-35c3-40f7-9805-119d7932cfcf" } - { type = "checkbox" display_name = "Rotation" option = "6ce8aa19-350e-49b8-bb39-444a60db482d" } - { type = "checkbox" display_name = "Custom FOV" option = "3eca2035-4349-4d1a-ae8b-6b1d8b91033f" } -] - -render_state = { - gbuffer_material = { - inherit: ["core/stingray_renderer/output_nodes/standard_base#gbuffer_material"] - } - - shadow_caster = { - inherit: ["core/stingray_renderer/output_nodes/standard_base#shadow_caster"] - } -} - -channels = { - "(defined(HAS_NORMAL) && !defined(WORLD_SPACE_NORMAL)) || defined(NEEDS_TANGENT_SPACE)": { - tsm0 = { type = "float3" domains = ["vertex", "pixel"] } - tsm1 = { type = "float3" domains = ["vertex", "pixel"] } - tsm2 = { type = "float3" domains = ["vertex", "pixel"] } - } - - "defined(NEEDS_EYE_VECTOR)": { - eye_vector = { type = "float3" domain = "vertex" } - } - - "!defined(HAS_NORMAL) || defined(NEEDS_WORLD_SPACE_NORMAL)": { - world_space_normal = { type = "float3" domains = ["vertex", "pixel"] } - } - - "defined(NEEDS_PIXEL_DEPTH)": { - pixel_depth = { type = "float" domain = "pixel" } - } - - "defined(NEEDS_SCREEN_POS)": { - screen_pos = { type = "float2" domain = "pixel" } - } - - "on_platform(GL)": { - vertex_corner_info = { type = "float2" semantic = "COLOR1" domain = "vertex" } - } - "!on_platform(GL)": { - vertex_corner_info = { type = "float2" semantic = "POSITION1" domain = "vertex" } - } - vertex_size = { type = "float2" semantic = "TEXCOORD7" domain = "vertex" } - "defined(ROTATION)": { - vertex_rotation = { type = "float" semantic = "TEXCOORD1" domains = ["vertex"] } - } - "defined(NEEDS_UV_SCALE)": { - "defined(NEEDS_UV_ANIMATION)": { - vertex_uv_data = { type = "float3" semantic = "TEXCOORD0" domains = ["vertex"] } - uv_frame = { type = "float" domains = ["vertex"] } - } - "!defined(NEEDS_UV_ANIMATION)": { - vertex_uv_data = { type = "float2" semantic = "TEXCOORD0" domains = ["vertex"] } - } - uv_scale = { type = "float2" domains = ["vertex"] } - } - "!defined(NEEDS_UV_SCALE)": { - "defined(NEEDS_UV_ANIMATION)": { - vertex_uv_frame = { type = "float" semantic = "TEXCOORD0" domains = ["vertex"] } - uv_frame = { type = "float" domains = ["vertex"] } - } - } - "defined(PIVOT)": { - vertex_pivot = { type = "float2" semantic = "TEXCOORD6" domains = ["vertex"] } - } - "defined(EXTERNAL_ROTATION) || defined(TANGENT_LOCKED)": { - vertex_tangent = { type = "float3" semantic = "TANGENT" domains = ["vertex"] } - "defined(EXTERNAL_ROTATION)": { - vertex_binormal = { type = "float3" semantic = "BINORMAL" domains = ["vertex"] } - } - } -} - -shader_contexts = { - shadow_caster = { - passes_sort_mode = "immediate" - compile_with = [ - { if: "on_renderer(D3D11, D3D12, GNM, GL)" } - ] - - passes = [ - { code_block="core/stingray_renderer/output_nodes/particle_base#depth_only" define="GBUFFER_PARTICLES" render_state="shadow_caster" } - ] - } - - default = { - passes_sort_mode = "deferred" - compile_with = [ - { if: "on_renderer(D3D11, D3D12, GNM, GL)" } - ] - - passes = [ - { if: "defined(HAS_OPACITY)" then: [ - { layer="gbuffer_alpha_masked" code_block="core/stingray_renderer/output_nodes/particle_base#billboard" define="GBUFFER_PARTICLES" render_state="gbuffer_material" } - ] else: [ - { layer="gbuffer" code_block="core/stingray_renderer/output_nodes/particle_base#billboard" define="GBUFFER_PARTICLES" render_state="gbuffer_material" } - ]} - ] - } -} \ No newline at end of file diff --git a/vmf/core/stingray_renderer/output_nodes/probe_base.shader_node b/vmf/core/stingray_renderer/output_nodes/probe_base.shader_node deleted file mode 100644 index 0db74e8..0000000 --- a/vmf/core/stingray_renderer/output_nodes/probe_base.shader_node +++ /dev/null @@ -1,321 +0,0 @@ -group = "Output" -display_name = "Reflection Probe Base" -output_node = true -render_configs = ["core/stingray_renderer/renderer"] - -inputs = { -} - -options = { -} - -ui = [ -] - -render_state = { - reflection_probe = { - inherit: ["core/stingray_renderer/shader_libraries/common#default"] - state: { - z_enable = "true" - z_write_enable = "false" - z_func = "greater_equal" - - cull_mode = "cull_ccw" - - blend_enable = "true" - blend_op = "blend_op_add" - dest_blend = "blend_one" - src_blend = "blend_inv_dest_alpha" - } - } - - debug_visualization = { - inherit: ["core/stingray_renderer/shader_libraries/common#opacity"] - state: { - "defined(FRONT_CULLING)" = { - cull_mode = "cull_ccw" - } - "defined(BACK_CULLING)" = { - cull_mode = "cull_cw" - } - "defined(WIREFRAME)" = { - cull_mode = "cull_none" - fill_mode = "fill_wireframe" - "on_renderer(D3D11, D3D12)" = { - depth_bias = "-1" - depth_bias_clamp = "-0.00015" - slope_scale_depth_bias = "-2.0" - } - } - "defined(DRAW_INFLUENCE)" = { - cull_mode = "cull_none" - z_func = "greater_equal" - } - } - } -} - -sampler_state = { - -} - -channels = { - vertex_position = { type = "float4" domain = "vertex" } -} - -permutation_sets = { -} - -shader_contexts = { - default = { - passes_sort_mode = "deferred" - compile_with = [ - { if: "on_renderer(D3D11, D3D12, GNM, GL)" } - ] - passes = [ - { if: "on_renderer(D3D11, D3D12, GNM)" then: [ - { layer="reflections" code_block="reflection_probe" render_state="reflection_probe" } - - // { layer="wireframe" code_block="reflection_probe" defines=["DRAW_INFLUENCE_VOLUME" "FRONT_CULLING"] render_state="dev_volume_visualization" } - - { layer="wireframe" code_block="reflection_probe" defines=["DRAW_INFLUENCE"] render_state="debug_visualization" branch_key="dev_volume_visualization" } - - { layer="wireframe" code_block="reflection_probe" defines=["DRAW_TRACE_VOLUME" "FRONT_CULLING"] render_state="debug_visualization" branch_key="dev_volume_visualization" } - { layer="wireframe" code_block="reflection_probe" defines=["DRAW_TRACE_VOLUME" "BACK_CULLING"] render_state="debug_visualization" branch_key="dev_volume_visualization" } - { layer="wireframe" code_block="reflection_probe" defines=["DRAW_TRACE_VOLUME" "WIREFRAME"] render_state="debug_visualization" branch_key="dev_volume_visualization" } - - { layer="wireframe" code_block="reflection_probe" defines=["DRAW_INFLUENCE_VOLUME" "BACK_CULLING"] render_state="debug_visualization" branch_key="dev_volume_visualization" } - { layer="wireframe" code_block="reflection_probe" defines=["DRAW_INFLUENCE_VOLUME" "WIREFRAME"] render_state="debug_visualization" branch_key="dev_volume_visualization" } - ] } - ] - } -} - -code_blocks = { - reflection_probe = { - include:[ - "core/stingray_renderer/shader_libraries/common#common", - "core/stingray_renderer/shader_libraries/common#gbuffer_access", - "core/stingray_renderer/shader_libraries/lighting_common#brdf", - "core/stingray_renderer/shader_libraries/shadow_map_common#shadow_bias" - ] - - samplers = { - gbuffer1 = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_point" - source = "resource_set" - slot_name = "gbuffer1" - type = "2d" - } - - linear_depth = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_point" - source = "resource_set" - slot_name = "linear_depth" - type = "2d" - } - - reflection_map = { - display_name = "Reflection Map" - type = "cube" - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "material" - slot_name = "reflection_map" - } - - radiation_map = { - display_name = "Reflection Map" - type = "cube" - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "material" - slot_name = "radiation_map" - } - } - - code = { - hlsl = """ - DECLARE_SAMPLER_2D(gbuffer1); - DECLARE_SAMPLER_2D(linear_depth); - DECLARE_SAMPLER_CUBE(reflection_map); - DECLARE_SAMPLER_CUBE(radiation_map); - - struct VS_INPUT { - float4 position : POSITION; - GRAPH_VERTEX_INPUT - }; - - struct PS_INPUT { - float4 position : SV_POSITION; - float4 w : TEXCOORD1; - GRAPH_PIXEL_INPUT - }; - - CBUFFER_START(c0) - float4x4 world; - float4x4 inv_world; - float4x4 world_view_proj; - GRAPH_MATERIAL_EXPORTS - CBUFFER_END - - CBUFFER_START(light) - float3 light_position; - float3 light_proxy_scale; - float3 light_box_min; - float3 light_box_max; - - // controlled from script data on probe unit propagated through the light material. - float3 trace_box_min; - float3 trace_box_max; - float3 falloff; - CBUFFER_END - - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - PS_INPUT vs_main(VS_INPUT input) { - PS_INPUT o; - - GraphVertexParams params; - GraphVertexResults results; - - // Write automatic params - GRAPH_VERTEX_WRITE_PARAMS(params, input); - - #if defined(DRAW_TRACE_VOLUME) - float3 scale = trace_box_max - trace_box_min; - float4 position = float4(input.position.xyz * scale, 1); - position.xyz += (trace_box_min + trace_box_max) * 0.5f; - #else - float4 position = float4(input.position.xyz * light_proxy_scale, 1); - position.xyz += (light_box_min + light_box_max) * 0.5f; - #endif - GRAPH_VERTEX_PARAM(params, vertex_position) = position; - - o.position = mul(position, world_view_proj); - #if !defined(STENCIL_MARK) - o.w = encode_world_pos(o.position); - #endif - - // Evaluate all pieces of the graph that should run per-vertex. - GRAPH_EVALUATE_VERTEX(results, params); - - // Write results - GRAPH_VERTEX_WRITE(o, results, params); - - return o; - } - - #if defined(DRAW_INFLUENCE_VOLUME) || defined(DRAW_TRACE_VOLUME) - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - float4 ps_main() : SV_TARGET0 - { - #if defined(WIREFRAME) - #if defined(DRAW_INFLUENCE_VOLUME) - return float4(1,0.8,0.8,0.5); - #else - return float4(0.8,1,0.8,0.5); - #endif - #elif defined(DRAW_INFLUENCE_VOLUME) - return float4(1,0,0,0.1); - #else - return float4(0,1,0,0.1); - #endif - } - #else - // TODO: does not support scaling atm. - - #if defined(DRAW_INFLUENCE) - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - float4 ps_main(PS_INPUT input - #if defined(GL2) - , float2 wpos : VPOS - #endif - ) : SV_TARGET0 - #else - struct PS_OUTPUT { - float4 reflection : SV_TARGET0; - float4 radiation : SV_TARGET1; - }; - - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - PS_OUTPUT ps_main(PS_INPUT input - #if defined(GL2) - , float2 wpos : VPOS - #endif - ) - #endif - { - #if defined(GL2) - half2 uv = wpos.xy / back_buffer_size; - #else - half2 uv = input.position.xy / back_buffer_size; - #endif - float d = gbuffer_decode_depth(TEX2D(linear_depth, uv)); - - float3 wp = decode_world_pos(input.w, d); - float3 op = mul(float4(wp, 1), inv_world).xyz; - float3 V = mul(normalize(camera_world._m30_m31_m32 - wp), (float3x3)inv_world); - - #if defined(HAS_LIGHT_COLOR) - GraphPixelParams params; - GraphPixelResults graph; - GRAPH_PIXEL_WRITE_PARAMS(params, input); - GRAPH_EVALUATE_PIXEL(graph, params); - #else - //float3 light_col = light_color; - #endif - - half4 gbuffer_1 = TEX2D(gbuffer1, uv); - - float3 gbuffer_normal = gbuffer_decode_normal(gbuffer_1); - float3 N = mul(gbuffer_normal, (float3x3)inv_world); - half roughness = gbuffer_decode_roughness(gbuffer_1); - float mipmap_index = roughness * 7; - - float3 reflection_dir; - { - reflection_dir = reflect(-V, N); - float3 r_max = (trace_box_max - op) / reflection_dir; - float3 r_min = (trace_box_min - op) / reflection_dir; - float3 r_min_max = max(r_max, r_min); - float intersect_dist = min(min(r_min_max.x, r_min_max.y), r_min_max.z); - reflection_dir = mul(op + reflection_dir * intersect_dist, (float3x3)world); - } - - float3 reflection = rgbm_decode(TEXCUBELOD(reflection_map, reflection_dir, mipmap_index)); - - float3 radiation_dir = gbuffer_normal; - /*{ - radiation_dir = N; - float3 r_max = (trace_box_max - op) / radiation_dir; - float3 r_min = (trace_box_min - op) / radiation_dir; - float3 r_min_max = max(r_max, r_min); - float intersect_dist = min(min(r_min_max.x, r_min_max.y), r_min_max.z); - radiation_dir = mul(op + radiation_dir * intersect_dist, (float3x3)world); - }*/ - - // TODO: this might be wanted, but requires more probes in order to get good result. - // float diff_attn = saturate(dot(gbuffer_normal, normalize(world._m30_m31_m32 - wp))); - float3 radiation = rgbm_decode(TEXCUBELOD(radiation_map, radiation_dir, 0)); - - // Attenuate - float3 distances = min(op - light_box_min, light_box_max - op) / falloff; - float attn = saturate(min(distances.x, min(distances.y, distances.z))); - - #if defined(DRAW_INFLUENCE) - bool3 inside = (distances > 0.0); - if(!all(inside)) - discard; - return float4(0, 0, 1, (1.0 - attn) * 0.5); - #else - PS_OUTPUT o; - o.reflection = float4(reflection * attn, attn); - o.radiation = float4(radiation * attn, attn); - return o; - #endif - } - #endif - - - """ - } - } -} diff --git a/vmf/core/stingray_renderer/output_nodes/ribbon_base.shader_node b/vmf/core/stingray_renderer/output_nodes/ribbon_base.shader_node deleted file mode 100644 index d8b8497..0000000 --- a/vmf/core/stingray_renderer/output_nodes/ribbon_base.shader_node +++ /dev/null @@ -1,532 +0,0 @@ -group = "Particle Ribbon/Output" -display_name = "Ribbon Base" -output_node = true -render_configs = ["core/stingray_renderer/renderer"] - -// TODO: disable sun if it's disabled in environment settings. -// TODO: options to disable shadows, local lights, sun_light. - -inputs = { - "e1d24468-d03e-4884-9b0d-dba23aaa94d6" = { - name = "base_color" - is_required = false - display_name = "Base Color" - type = { vector3: ["HAS_BASE_COLOR"] } - domain = "pixel" - } - - "0752e133-0c01-4fc4-b45a-a629cad4f850" = { - name = "opacity" - is_required = false - display_name = "Opacity" - type = { scalar: ["HAS_OPACITY"] } - domain = "pixel" - } -/* - "6fd5ebe2-4d15-4ecc-abad-ab9731ea861a" = { - name = "fade_range" - is_required = false - display_name = "Angle Fade Range" - type = { vector2: ["HAS_ANGLE_FADE" "NEEDS_EYE_VECTOR"] } - domain = "pixel" - } -*/ -} - -options = { - "e6347231-6647-4bc3-a1d0-f24e1b3e0562" = "EXTERNAL_ROTATION" - "914232a9-5352-43d7-a877-cedfe798541d" = "TANGENT_LOCKED" - "e8e86308-83cd-47a1-ab84-82776b3cf0ca" = "SCREEN_SPACE" - "9775d054-ef17-4ca4-b5a4-8751c6e1eec6" = "PIVOT" - "aaebf627-efab-4c86-8244-359d29d00f33" = "ROTATION" - "47a74b09-1932-40d4-ab90-0ec090fb9643" = "BLEND_ADDITIVE" - "e267562a-65dc-4547-a9fa-6a605b451cae" = "BLEND_PREMULTIPLIED_ALPHA" - "4a42f2e1-1069-4afe-a93f-c7558572780f" = "EMISSIVE_PARTICLES" - "5e380f16-5cc6-482b-9df6-af0d2b3bda3c" = "HAS_CUSTOM_FOV" - "fea9af88-d417-433a-b475-346b6b03e249" = "HIGH_QUALITY" -} - -ui = [ - - { - type = "drop_down" - display_name = "Blend Mode" - options = { - "Alpha Blend" = "00000000-0000-0000-0000-000000000000" - "Additive Blend" = "47a74b09-1932-40d4-ab90-0ec090fb9643" - } - default = "00000000-0000-0000-0000-000000000000" - } - - { type = "checkbox" display_name = "Emissive particles" option = "4a42f2e1-1069-4afe-a93f-c7558572780f" } - { type = "checkbox" display_name = "Custom FOV" option = "5e380f16-5cc6-482b-9df6-af0d2b3bda3c" } -] - -render_state = { - - ribbon_opacity = { - inherit: ["core/stingray_renderer/shader_libraries/common#opacity"] - state: { - blend_op = "blend_op_add" - src_blend = "blend_one" - dest_blend = "blend_inv_src_alpha" - write_mask0 = "red|green|blue" - z_enable = "true" - } - } -} - -sampler_state = { -} - -channels = { - - "defined(PARTICLE_LIGHTING)": { - basis0 = { type = "float4" domains = ["vertex", "pixel"] } - basis1 = { type = "float4" domains = ["vertex", "pixel"] } - basis2 = { type = "float4" domains = ["vertex", "pixel"] } - back_lighting = { type = "float3" domains = ["vertex", "pixel"] } - } -/* - "defined(HAS_ANGLE_FADE)": { - world_space_plane_normal = { type = "float3" domains = ["vertex", "pixel"] } - } - - "defined(NEEDS_EYE_VECTOR)": { - eye_vector = { type = "float3" domains = ["vertex", "pixel"] } - } - - "defined(NEEDS_WORLD_SPACE_NORMAL)": { - world_space_normal = { type = "float3" domains = ["vertex", "pixel"] } - } - - "defined(NEEDS_PIXEL_DEPTH)": { - pixel_depth = { type = "float" domain = "pixel" } - } - - "defined(NEEDS_SCREEN_POS)": { - screen_pos = { type = "float2" domain = "pixel" } - } -*/ - strip_info = { type = "float" semantic = "POSITION1" domain = "vertex" } - vertex_size = { type = "float2" semantic = "TEXCOORD7" domain = "vertex" } - - - "defined(NEEDS_UV_SCALE)": { - "defined(NEEDS_UV_ANIMATION)": { - vertex_uv_data = { type = "float3" semantic = "TEXCOORD0" domains = ["vertex"] } - uv_frame = { type = "float" domains = ["vertex"] } - } - "!defined(NEEDS_UV_ANIMATION)": { - vertex_uv_data = { type = "float2" semantic = "TEXCOORD0" domains = ["vertex"] } - } - uv_scale = { type = "float2" domains = ["vertex"] } - } - "!defined(NEEDS_UV_SCALE)": { - "defined(NEEDS_UV_ANIMATION)": { - vertex_uv_frame = { type = "float" semantic = "TEXCOORD0" domains = ["vertex"] } - uv_frame = { type = "float" domains = ["vertex"] } - } - } - vertex_tangent = { type = "float3" semantic = "TANGENT" domains = ["vertex"] } - ribbon_distance = { type = "float" semantic = "TEXCOORD6" domains = ["vertex"] } - -} - -log_permutations = false -permutation_sets = { - vertex_modifiers = [ - ] - - default = [ - ] -} - -shader_contexts = { - default = { - passes_sort_mode = "deferred" - compile_with = [ - { if: "on_renderer(D3D11, D3D12, GNM, GL)" defines=["LOCAL_LIGHTS"] } - ] - - passes = [ - { if: "defined(EMISSIVE_PARTICLES)" then: [ - { layer="hdr_transparent" code_block="ribbon" render_state="ribbon_opacity" } - ] else: [ - { layer="hdr_transparent" code_block="ribbon" render_state="ribbon_opacity" defines=["PARTICLE_LIGHTING" "VS_FOG"] } - ]} - ] - } -} - -code_blocks = { - particle_lighting = { - code=""" - #if defined(PARTICLE_LIGHTING) - #if defined(D3D11) || defined(GNM) - #define BACK_LIGHTING - #endif - - #if defined(SHADOW_RECEIVING) - #define CALCULATE_LIGHTING - #endif - #endif - """ - } - - ribbon = { - language = "hlsl" - - include:[ - "particle_lighting" - "core/stingray_renderer/shader_libraries/common#common", - "core/stingray_renderer/shader_libraries/common#gbuffer_access", - "core/stingray_renderer/shader_libraries/common#fog", - "core/stingray_renderer/shader_libraries/lighting_common#brdf", - "core/stingray_renderer/shader_libraries/common#taa_offsets", - "core/stingray_renderer/shader_libraries/shadow_map_common#shadow_bias" - "core/stingray_renderer/shader_libraries/shadow_map_common#shadow_map_filtering" - "core/stingray_renderer/shader_libraries/lighting_common#clustered_shading" - "core/stingray_renderer/shader_libraries/particle_lighting_common#radiosity_normal_mapping" - "core/stingray_renderer/shader_libraries/particle_lighting_common#particle_debug" ] - - instance_data = { - } - - stage_conditions = { - } - - samplers = { - "defined(DISTORTION)": { - hdr0 = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "hdr0" - type = "2d" - } - } - "defined(PARTICLE_LIGHTING)": { - global_diffuse_map = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "global_diffuse_map" - type = "cube" - } - } - "defined(NEEDS_LINEAR_DEPTH)": { - linear_depth = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_point" - source = "resource_set" - slot_name = "linear_depth" - type = "2d" - } - } - - } - - code = """ - #if defined(HAS_NORMAL) && !defined(WORLD_SPACE_NORMAL) - #define NEEDS_TANGENT_SPACE - #endif - - #if defined(NEEDS_PIXEL_DEPTH) || defined(PARTICLE_LIGHTING) - #define PS_NEEDS_WP - #endif - - #if defined(NEEDS_LINEAR_DEPTH) - DECLARE_SAMPLER_2D(linear_depth); - #define HAS_LINEAR_DEPTH - #endif - - struct VS_INPUT { - float4 position : POSITION; - GRAPH_VERTEX_INPUT - }; - - struct PS_INPUT { - float4 position : SV_POSITION; - #if defined(PS_NEEDS_WP) - float3 world_pos : TEXCOORD15; - #endif - #if defined(VS_FOG) - float4 fog_params : TEXCOORD16; - #endif - GRAPH_PIXEL_INPUT - }; - - CBUFFER_START(c_ribbon) - float4x4 view; - float4x4 view_proj; - #if defined(EMISSIVE_PARTICLES) - float emissive_particle_intensity; - #endif - CBUFFER_END - - CBUFFER_START(c_material_exports) - GRAPH_MATERIAL_EXPORTS - CBUFFER_END - - - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - PS_INPUT vs_main(VS_INPUT input) - { - PS_INPUT o; - - GraphVertexParams params; - GraphVertexResults results; - - // Write automatic params - GRAPH_VERTEX_WRITE_PARAMS(params, input); - - - float3 y = GRAPH_VERTEX_DATA(input, vertex_tangent); - float3 x = normalize(cross(normalize(input.position.xyz - camera_pos), y)); - - float3 x_axis = x; - float3 y_axis = y; - - float strip_info = GRAPH_VERTEX_DATA(input, strip_info); - float2 size = GRAPH_VERTEX_DATA(input, vertex_size); - float corner = strip_info * (size.x * 0.5); - - float3 wp = input.position.xyz + (x_axis * corner); - - #if defined(HAS_CUSTOM_FOV) - float4 p = mul(float4(wp, 1),camera_custom_fov_view_projection); - #else - float4 p = mul(float4(wp, 1), view_proj); - #endif - - - #if defined(NEEDS_EYE_VECTOR) - GRAPH_VERTEX_PARAM(params, eye_vector).rgb = camera_pos - wp; - #endif - - // TOOD: Move this code to its own shader node! - #if defined(NEEDS_UV_SCALE) - #if defined(NEEDS_UV_ANIMATION) - GRAPH_VERTEX_PARAM(params, uv_frame) = GRAPH_VERTEX_DATA(input, vertex_uv_data).z; - #endif - GRAPH_VERTEX_PARAM(params, uv_scale) = GRAPH_VERTEX_DATA(input, vertex_uv_data).xy; - #elif defined(NEEDS_UV_ANIMATION) - GRAPH_VERTEX_PARAM(params, uv_frame) = GRAPH_VERTEX_DATA(input, vertex_uv_frame); - #endif - - - #if defined(PARTICLE_LIGHTING) - float3 normal = normalize(lerp(wp - input.position.xyz, -view._m01_m11_m21, 0.2)); - normal = mul(normal, (float3x3)view); - #endif - - - #if defined(PARTICLE_LIGHTING) - float4 basis0 = float4(0,0,0,1); - float4 basis1 = float4(0,0,0,1); - float4 basis2 = float4(0,0,0,1); - float3 back_lighting = float3(0,0,0); - calc_basis_lighting(basis0, basis1, basis2, back_lighting, wp, normal, view, p); - GRAPH_VERTEX_PARAM(params, basis0) = basis0; - GRAPH_VERTEX_PARAM(params, basis1) = basis1; - GRAPH_VERTEX_PARAM(params, basis2) = basis2; - #if defined(BACK_LIGHTING) - GRAPH_VERTEX_PARAM(params, back_lighting) = back_lighting; - #endif - #endif - - - // Evaluate all pieces of the graph that should run per-vertex. - GRAPH_EVALUATE_VERTEX(results, params); - - - #if defined(PS_NEEDS_WP) - o.world_pos = wp; - #endif - - #if defined(VS_FOG) - const float3 view_dir = camera_world._m30_m31_m32 - wp.xyz; - const float3 camera_dir = camera_world._m10_m11_m12; - const float depth = dot(-view_dir, camera_dir); - o.fog_params = calc_fog_vs(wp, depth); - #endif - - o.position = p; - - // Write results - GRAPH_VERTEX_WRITE(o, results, params); - - return o; - } - - /* - #elif defined(DISTORTION) // TODO: avoid sample from objects infront of the "distortion" - DECLARE_SAMPLER_2D(hdr0); - #if !defined(LOW_RES) && defined(LOW_RES_ENABLED) - DECLARE_SAMPLER_2D(hdr_transparent_div4); - DECLARE_SAMPLER_2D(hdr_linear_depth_div4); - #endif - - #ifdef LOW_RES - struct PS_OUTPUT { - half4 color : SV_TARGET0; - half4 depth : SV_TARGET1; - }; - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - PS_OUTPUT ps_main(PS_INPUT input) - #else - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - half4 ps_main(PS_INPUT input) : SV_TARGET0 - #endif - { - GraphPixelParams params; - GraphPixelResults graph; - - GRAPH_PIXEL_WRITE_PARAMS(params, input); - - #if (!defined(LOW_RES) && defined(LOW_RES_ENABLED)) || defined(NEEDS_SCREEN_POS) - #if defined(LOW_RES) - float2 screen_position = input.position.xy / (back_buffer_size * 0.25); - #else - float2 screen_position = (input.position.xy / back_buffer_size); - #endif - #endif - - #if defined(NEEDS_SCREEN_POS) - GRAPH_PIXEL_PARAM(params, screen_pos) = screen_position; - #endif - - #if defined(PS_NEEDS_WP) - const float3 world_pos = input.world_pos; - const float3 view_dir = camera_world._m30_m31_m32 - world_pos; - const float3 camera_dir = camera_world._m10_m11_m12; - - const float depth = dot(-view_dir, camera_dir); - #endif - #if defined(NEEDS_PIXEL_DEPTH) - GRAPH_PIXEL_PARAM(params, pixel_depth) = depth; - #endif - - GRAPH_EVALUATE_PIXEL(graph, params); - - float3 normal = graph.distortion_normal; - normal.rg = normal.rg * 2 - 1; - half2 distortion = normal.xy / back_buffer_size; - - #if defined(HAS_OPACITY) - half opacity = saturate(graph.opacity); - #else - half opacity = 0.5; - #endif - - #if !defined(LOW_RES) && defined(LOW_RES_ENABLED) - // Fade out high resolution particle if the low resolution particles is infront of the high resolution particle - float2 particle_depth_values = TEX2D(hdr_linear_depth_div4, screen_position).rg; - float depth_mean = particle_depth_values.x; - float depth_variance = particle_depth_values.y - depth_mean*depth_mean; - float background_depth = depth; - - float diff = max(background_depth - depth_mean, 0.0); - float C = 1.38629436112; // 2 * ln(2) - float T = exp2(-diff*diff / (C * max(depth_variance, 0.001))); - float alpha_modifier = TEX2D(hdr_transparent_div4, screen_position).a * (1.0 - T); - opacity *= 1.0 - alpha_modifier; - #endif - - float3 color = TEX2D(hdr0, screen_position + (distortion * graph.distortion_strength)).rgb; - - #if defined(HAS_BASE_COLOR) - color *= graph.base_color; - #endif - - #ifdef LOW_RES - PS_OUTPUT o; - o.color = half4(color * opacity, opacity); - float alpha_depth = depth * opacity; - o.depth = half4(alpha_depth, alpha_depth * alpha_depth, 0.0, opacity); - return o; - #else - #if defined(PARTICLE_DEBUG) - return DISTORTION_PARTICLES_DEBUG_COLOR; - #else - return half4(color * opacity, opacity); - #endif - #endif - } - #else - */ - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - half4 ps_main(PS_INPUT input) : SV_TARGET0 - { - GraphPixelParams params; - GraphPixelResults graph; - - GRAPH_PIXEL_WRITE_PARAMS(params, input); - - #if defined(PS_NEEDS_WP) - const float3 world_pos = input.world_pos; - const float3 view_dir = camera_world._m30_m31_m32 - world_pos; - const float3 camera_dir = camera_world._m10_m11_m12; - - const float depth = dot(-view_dir, camera_dir); - #endif - - #if defined(NEEDS_PIXEL_DEPTH) - GRAPH_PIXEL_PARAM(params, pixel_depth) = depth; - #endif - - GRAPH_EVALUATE_PIXEL(graph, params); - - #if defined(HAS_OPACITY) - half opacity = saturate(graph.opacity); - #else - half opacity = 0.5; - #endif - - - - #if defined(HAS_BASE_COLOR) - float4 color = float4(graph.base_color, opacity); - #else - float4 color = float4(1,1,1, opacity); - #endif - - - #if defined(PARTICLE_LIGHTING) - float4 basis0 = GRAPH_PIXEL_DATA(input, basis0); - float4 basis1 = GRAPH_PIXEL_DATA(input, basis1); - float4 basis2 = GRAPH_PIXEL_DATA(input, basis2); - #if defined(BACK_LIGHTING) - float3 back_lighting = GRAPH_PIXEL_DATA(input, back_lighting); - #endif - float3 normal = normalize(float3(basis0.w, basis1.w, basis2.w)); - color.rgb = calc_lighting(color, normal, back_lighting, basis0.xyz, basis1.xyz, basis2.xyz); - #if defined(VS_FOG) - // apply vs calculated fog - color.rgb = lerp(color.rgb, input.fog_params.rgb, input.fog_params.a); - #else - color = apply_fog(color, world_pos, depth); - #endif - #elif defined(EMISSIVE_PARTICLES) - color.rgb *= emissive_particle_intensity; - #endif - - - /* - #if defined(HAS_ANGLE_FADE) - float3 plane_wn = normalize(GRAPH_PIXEL_DATA(input, world_space_plane_normal)); - float3 eye_dir = normalize(GRAPH_PIXEL_DATA(input, eye_vector)); - float fade = dot(plane_wn, eye_dir); - opacity *= saturate((fade - graph.fade_range.x) / (graph.fade_range.y - graph.fade_range.x)); - #endif - */ - - half4 output_color = half4(color.rgb * opacity, opacity); - #if defined(BLEND_ADDITIVE) - output_color.a = 0.0; - #endif - - return output_color; - } - //#endif - """ - } -} \ No newline at end of file diff --git a/vmf/core/stingray_renderer/output_nodes/skydome_base.shader_node b/vmf/core/stingray_renderer/output_nodes/skydome_base.shader_node deleted file mode 100644 index 9bacdc3..0000000 --- a/vmf/core/stingray_renderer/output_nodes/skydome_base.shader_node +++ /dev/null @@ -1,207 +0,0 @@ -group = "Output" -display_name = "Skydome Base" -output_node = true -render_configs = ["core/stingray_renderer/renderer"] - -inputs = { - "19499850-aa42-40f8-a51e-75abb592e92b" = { - name = "base_color" - is_required = true - display_name = "Base Color" - type = { vector3: ["HAS_BASE_COLOR"] } - domain = "pixel" - } -} - -options = { - "582dd9e3-a746-4913-8eae-d8569b6d7b39" = "CAMERA_LOCK_XY" - "1e637d96-cadf-4d3c-a1c6-fc31ce81adf8" = "CAMERA_LOCK_Z" - "efe865a9-2225-4b9b-92dd-6080d4bfa417" = "SKYDOME_RGBM" -} - -ui = [ - { type = "checkbox" display_name = "Lock Camera in XY-plane" option = "582dd9e3-a746-4913-8eae-d8569b6d7b39" } - { type = "checkbox" display_name = "Lock Camera in Z-plane" option = "1e637d96-cadf-4d3c-a1c6-fc31ce81adf8" } - { type = "checkbox" display_name = "Skydome Texture RGBM encoded" option = "efe865a9-2225-4b9b-92dd-6080d4bfa417" } -] - -render_state = { - ambient_no_depth_write = { - inherit: ["core/stingray_renderer/shader_libraries/common#ambient"] - states = { - z_write_enable = "false" - } - } - - filter = { - inherit: ["core/stingray_renderer/shader_libraries/common#default"] - states = { - cull_mode = "cull_none" - z_write_enable = "false" - z_enable = "false" - } - } -} - -sampler_state = { } - -channels = { - "defined(NEEDS_EYE_VECTOR)": { - eye_vector = { type = "float3" domain = "vertex" } - } - - vertex_position = { type = "float4" domain = "vertex" } -} - -log_permutations = false -permutation_sets = { -} - -shader_contexts = { - material_transfer = { - passes_sort_mode = "immediate" - compile_with = [ - { if: "on_renderer(D3D11, D3D12, GNM, GL)" } - ] - - passes = [ - { code_block="skydome" defines=["MATERIAL_TRANSFER"] render_state="filter" } - ] - } - - default = { - passes_sort_mode = "deferred" - compile_with = [ - { if: "on_renderer(D3D11, D3D12, GNM, GL)" } - ] - - passes = [ - { layer="skydome" code_block="skydome" defines=["PROJECT_TO_FAR_PLANE"] render_state="ambient_no_depth_write" } - ] - } -} - -code_blocks = { - skydome = { - include:[ - "core/stingray_renderer/shader_libraries/common#common", - "core/stingray_renderer/shader_libraries/common#gbuffer_access"] - - instance_data = { - } - - stage_conditions = { - } - - samplers = { - } - - code = { - hlsl = """ - #if defined(NEEDS_EYE_VECTOR) || defined(CAMERA_LOCK_XY) || defined(CAMERA_LOCK_Z) - #define NEEDS_WORLD_SPACE - #endif - - struct VS_INPUT { - float4 position : POSITION; - GRAPH_VERTEX_INPUT - }; - - struct PS_INPUT { - float4 position : SV_POSITION; - GRAPH_PIXEL_INPUT - }; - - CBUFFER_START(c0) - #if defined(CAMERA_LOCK_XY) || defined(NEEDS_WORLD_SPACE) - float4x4 world; - #endif - #if defined(CAMERA_LOCK_XY) - float4x4 view; - float4x4 proj; - #endif - float4x4 world_view_proj; - GRAPH_MATERIAL_EXPORTS - CBUFFER_END - - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - PS_INPUT vs_main(VS_INPUT input) - { - PS_INPUT o; - float4 p; - - GraphVertexParams params; - GraphVertexResults results; - - // Write automatic params - GRAPH_VERTEX_WRITE_PARAMS(params, input); - - // Write output channels - float4 position = input.position; - #if defined(NEEDS_WORLD_SPACE) - float4 wp = mul(position, world); - #endif - - GRAPH_VERTEX_PARAM(params, vertex_position) = position; - - #if defined(NEEDS_EYE_VECTOR) - // TODO: this eye_vector can't be used to calculate distance (length(eye_vector) in this case - GRAPH_VERTEX_PARAM(params, eye_vector).rgb = -wp.rgb; - #endif - - // Evaluate all pieces of the graph that should run per-vertex. - GRAPH_EVALUATE_VERTEX(results, params); - - #if defined(CAMERA_LOCK_XY) - #if defined(CAMERA_LOCK_Z) - view._m30_m31_m32 = float3(0,0,0); - #else - view._m30_m31 = float2(0,0); - #endif - p = mul(mul(wp, view), proj); - #else - p = mul(position, world_view_proj); - #endif - - #if defined(PROJECT_TO_FAR_PLANE) - p.z = p.w; - #endif - - o.position = p; - - /* - // TODO: try import uv again! - #if defined(MATERIAL_TRANSFER) - float2 tmp = GRAPH_VERTEX_DATA(input, uv); - tmp.y = 1 - tmp.y; - o.position = float4(tmp * 2 - 1, 0, 1); - #endif - */ - - // Write results - GRAPH_VERTEX_WRITE(o, results, params); - - return o; - } - - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - half4 ps_main(PS_INPUT input) : SV_TARGET0 - { - GraphPixelParams params; - GraphPixelResults graph; - - GRAPH_PIXEL_WRITE_PARAMS(params, input); - GRAPH_EVALUATE_PIXEL(graph, params); - - half4 c = half4(graph.base_color, 1.0); - - //#if defined(MATERIAL_TRANSFER) - // c.rgb = pow(c.rgb, 1.f / 2.2f); - //#endif - - return c; - } - """ - } - } -} diff --git a/vmf/core/stingray_renderer/output_nodes/standard_base.shader_node b/vmf/core/stingray_renderer/output_nodes/standard_base.shader_node deleted file mode 100644 index 2e134dc..0000000 --- a/vmf/core/stingray_renderer/output_nodes/standard_base.shader_node +++ /dev/null @@ -1,2340 +0,0 @@ -group = "Output" -display_name = "Standard Base" -output_node = true -render_configs = ["core/stingray_renderer/renderer"] - -inputs = { - "aee6e47b-be7b-4d67-a123-2ab5d660b94e" = { - name = "vertex_offset" - display_name = "Position offset" - is_required = false - type = { vector3: ["HAS_VERTEX_OFFSET"] } - domain = "vertex" - } - - "aca690cb-6305-4a2f-bf3d-69183a493db3" = { - name = "base_color" - is_required = false - display_name = "Base Color" - type = { vector3: ["HAS_BASE_COLOR"] } - domain = "pixel" - } - - "34259752-b962-4b65-92c3-903a57338519" = { - name = "opacity" - is_required = false - display_name = "Opacity" - type = { scalar: ["HAS_OPACITY"] } - domain = "pixel" - } - - "7a9306c6-95ae-4cdb-9fef-0eedacce4e83" = { - name = "opacity_threshold" - is_required = false - display_name = "Opacity Threshold" - type = { scalar: ["HAS_OPACITY_THRESHOLD"] } - domain = "pixel" - } - - "b1c86408-aacb-4466-b754-ddcf37a3a2c8" = { - is_required = false - name = "normal" - display_name = "Normal" - type = { vector3: ["HAS_NORMAL"] } - domain = "pixel" - } - - "ad5e052f-d316-4a0f-8b79-53c38204d61b" = { - is_required = false - name = "metallic" - display_name = "Metallic" - type = { scalar: ["HAS_METALLIC"] } - domain = "pixel" - } - - "36ba46d2-f6ea-4e60-a428-fdc17c75bc62" = { - is_required = false - name = "roughness" - display_name = "Roughness" - type = { scalar: ["HAS_ROUGHNESS"] } - domain = "pixel" - } - - "1164a5ef-4563-4795-b3b5-42825d6df037" = { - is_required = false - name = "emissive" - display_name = "Emissive" - type = { vector3: ["HAS_EMISSIVE"] } - domain = "pixel" - } - - "59fd1cf4-f736-470d-8510-1dd7c016639e" = { - is_required = false - name = "ambient_occlusion" - display_name = "Ambient Occlusion" - type = { scalar: ["HAS_AMBIENT_OCCLUSION"] } - domain = "pixel" - } - - "0544ddb6-e168-452d-86f2-42a79e8c98e3" = { - is_required = false - name = "sss_strength" - display_name = "Skin SSS" - type = { scalar: ["SKIN", "HAS_SKIN_SSS_STRENGTH"] } - domain = "pixel" - } - - "cc5a1773-27a2-430b-96d2-d81815d97feb" = { - is_required = false - name = "refraction" - display_name = "Refraction" - type = { scalar: ["HAS_REFRACTION"] } - domain = "pixel" - } - - "20346ea6-ecb0-41c1-bdcc-35bbe3ce1a5c" = { - is_required = false - name = "density" - display_name = "Density" - type = { scalar: ["HAS_DENSITY"] } - domain = "pixel" - } -} - -options = { - "b2c7c0d2-beff-4b1a-a9d4-068a507625a2" = "USE_FBX_PERMUTATIONS" - "d1a42a54-0794-4d57-9aa0-eb35acb6b35c" = "INSTANCED" - "8df1b8f7-17c2-4ae4-8c4e-25517ec1df46" = "CULL_NONE" - "c198c109-2cdf-49ee-af18-a982c23e2729" = "CULL_FRONT" - "2b136447-676e-4943-997b-04a28ae68497" = "WORLD_SPACE_NORMAL" - "dd7fcf97-0627-48ab-b29a-95b5685bb123" = "TRANSPARENT" - "3b55d6c6-4398-4dbc-b9ef-570aff8696ae" = "TRANSPARENT_FADE" - "b5bb2062-c8fa-43c5-8657-493a0be6860c" = "SKINNED_DISABLED" - "901b44ce-d128-498a-9912-32cd9635c556" = "HAS_FOV" - "da4e717b-5d0d-47fa-93b0-01c988f8f3ff" = "LOCK_NORMAL_ROTATION" - "979cb7cf-c255-42d0-a389-78fc0fb0539f" = "DEFERRED_DECALS_GROUP_1" - "d557b597-fa90-46b4-a751-eb51ae61ba5b" = "DEFERRED_DECALS_GROUP_2" - "fe20cc01-4cec-4217-98a0-07220ad3add9" = "DEFERRED_DECALS_GROUP_3" - "524a5842-23b7-46d1-ab22-cb3a14746ce0" = "USE_GLOBAL_ROUGHNESS_MULTIPLIER" - "11256995-4805-4018-bd6b-9214414fd363" = "NORMAL_FLIP_DISABLED" - "580cc6eb-3591-4c71-aa50-528af18ba160" = "JITTER_TRANSPARENCY" - "b649332d-7a8a-42b3-a809-6d0eb9c7c070" = "GBUFFER_POST_OUTLINE" - "08e965b9-90ed-4046-b314-c97ea7e7f30e" = "OPAQUE_FORWARD_DISABLED" -} - -ui = [ - { - type = "drop_down" - display_name = "Normals In" - options = { - "Tangent Space" = "00000000-0000-0000-0000-000000000000" - "World Space" = "2b136447-676e-4943-997b-04a28ae68497" - } - default = "00000000-0000-0000-0000-000000000000" - } - { - type = "drop_down" - display_name = "Blend Mode" - options = { - "Opaque" = "00000000-0000-0000-0000-000000000000" - "Transparent" = "dd7fcf97-0627-48ab-b29a-95b5685bb123" - "Transparent Fade" = "3b55d6c6-4398-4dbc-b9ef-570aff8696ae" - } - default = "00000000-0000-0000-0000-000000000000" - } - { - type = "drop_down" - display_name = "Face Culling" - options = { - "Back" = "00000000-0000-0000-0000-000000000000" - "Front" = "c198c109-2cdf-49ee-af18-a982c23e2729" - "None (double sided)" = "8df1b8f7-17c2-4ae4-8c4e-25517ec1df46" - } - default = "00000000-0000-0000-0000-000000000000" - } - - { - type = "drop_down" - display_name = "Decal Group" - options = { - "Group 0" = "00000000-0000-0000-0000-000000000000" - "Group 1" = "979cb7cf-c255-42d0-a389-78fc0fb0539f" - "Group 2" = "d557b597-fa90-46b4-a751-eb51ae61ba5b" - "Group 3" = "fe20cc01-4cec-4217-98a0-07220ad3add9" - } - default = "00000000-0000-0000-0000-000000000000" - } - - { type = "checkbox" display_name = "Disable Skinning" option = "b5bb2062-c8fa-43c5-8657-493a0be6860c" } - { type = "checkbox" display_name = "Instancing" option = "d1a42a54-0794-4d57-9aa0-eb35acb6b35c" } - { type = "checkbox" display_name = "Custom FOV" option = "901b44ce-d128-498a-9912-32cd9635c556" } - { type = "checkbox" display_name = "Avoid Tangent Space Transform" option = "da4e717b-5d0d-47fa-93b0-01c988f8f3ff" } - { type = "checkbox" display_name = "Use Global Roughness Multiplier" option = "524a5842-23b7-46d1-ab22-cb3a14746ce0" } - { type = "checkbox" display_name = "Normal Flip Disabled (double sided)" option = "11256995-4805-4018-bd6b-9214414fd363" } - { type = "checkbox" display_name = "Jitter Transparency" option = "580cc6eb-3591-4c71-aa50-528af18ba160" } - { type = "checkbox" display_name = "Gbuffer Post-Outline" option = "b649332d-7a8a-42b3-a809-6d0eb9c7c070" } - { type = "checkbox" display_name = "Disable Opaque Forward" option = "08e965b9-90ed-4046-b314-c97ea7e7f30e" } -] - - -render_state = { - culling_base_default = { - inherit: ["core/stingray_renderer/shader_libraries/common#default"] - state: { - "defined(CULL_NONE)" = { - cull_mode = "cull_none" - } - "defined(CULL_FRONT)" = { - cull_mode = "cull_ccw" - } - "!defined(CULL_NONE) && !defined(CULL_FRONT)" = { - cull_mode = "cull_cw" - } - } - } - - culling_base_gbuffer = { - inherit: ["core/stingray_renderer/shader_libraries/common#gbuffer_material"] - state: { - "defined(CULL_NONE)" = { - cull_mode = "cull_none" - } - "defined(CULL_FRONT)" = { - cull_mode = "cull_ccw" - } - "!defined(CULL_NONE) && !defined(CULL_FRONT)" = { - cull_mode = "cull_cw" - } - } - } - - gbuffer_material = { - inherit: ["culling_base_gbuffer"] - state: { - "defined(HAS_FOV)" = { - stencil_enable = "true" - stencil_func = "always" - stencil_fail = "stencil_op_keep" - stencil_mask = "0xf8" - stencil_pass = "stencil_op_replace" - stencil_write_mask = "0xf8" - stencil_z_fail = "stencil_op_keep" - - stencil_func_back_side = "always" - stencil_fail_back_side = "stencil_op_keep" - stencil_pass_back_side = "stencil_op_replace" - stencil_z_fail_back_side = "stencil_op_keep" - - defined_DEFERRED_DECALS_GROUP_1 = { - defined_SKIN = { - stencil_ref = "0xa8" - } - ndefined_SKIN = { - stencil_ref = "0xa0" - } - } - ndefined_DEFERRED_DECALS_GROUP_1 = { - defined_DEFERRED_DECALS_GROUP_2 = { - defined_SKIN = { - stencil_ref = "0xc8" - } - ndefined_SKIN = { - stencil_ref = "0xc0" - } - } - ndefined_DEFERRED_DECALS_GROUP_2 = { - defined_DEFERRED_DECALS_GROUP_3 = { - defined_SKIN = { - stencil_ref = "0xe8" - } - ndefined_SKIN = { - stencil_ref = "0xe0" - } - } - ndefined_DEFERRED_DECALS_GROUP_3 = { - defined_SKIN = { - stencil_ref = "0x88" - } - ndefined_SKIN = { - stencil_ref = "0x80" - } - } - } - } - } - } - } - - emissive = { - inherit: ["culling_base_default"] - state: { - z_write_enable = "false" - z_func = "less_equal" - blend_enable = "true" - blend_op = "blend_op_add" - dest_blend = "blend_one" - src_blend = "blend_one" - } - } - - transparent_base = { - state : { - z_write_enable = "false" - // with refraction we are essentially taking over the blending in our shader, so we disable alpha blending - "!defined(HAS_REFRACTION)" = { - blend_enable = "true" - blend_op = "blend_op_add" - dest_blend = "blend_inv_src_alpha" - src_blend = "blend_one" - } - - "defined(HAS_FOV)" = { - stencil_enable = "true" - stencil_func = "always" - stencil_fail = "stencil_op_keep" - stencil_mask = "0x80" - stencil_pass = "stencil_op_replace" - stencil_ref = "0x80" - stencil_write_mask = "0x80" - stencil_z_fail = "stencil_op_keep" - - stencil_func_back_side = "always" - stencil_fail_back_side = "stencil_op_keep" - stencil_pass_back_side = "stencil_op_replace" - stencil_z_fail_back_side = "stencil_op_keep" - } - } - } - - transparent = { - inherit: ["culling_base_default", "transparent_base"] - } - - transparent_double_sided_cw = { - inherit: ["core/stingray_renderer/shader_libraries/common#default", "transparent_base"] - state : { - cull_mode = "cull_cw" - } - } - - transparent_double_sided_ccw = { - inherit: ["core/stingray_renderer/shader_libraries/common#default", "transparent_base"] - state : { - cull_mode = "cull_ccw" - } - } - - wireframe = { - inherit: ["transparent"] - state: { - fill_mode = "fill_wireframe" - src_blend = "blend_src_alpha" - cull_mode = "cull_none" - "on_renderer(D3D11, D3D12)" = { - depth_bias = "-1" - depth_bias_clamp = "-0.00015" - slope_scale_depth_bias = "-2.0" - } - } - } - - depth_only = { - inherit: ["culling_base_default"] - state: { - write_mask0 = "0x0" - write_mask1 = "0x0" - write_mask2 = "0x0" - write_mask3 = "0x0" - } - } - - outline_stencil_write = { - inherit: ["culling_base_default"] - state: { - z_enable = "false" - z_write_enable = "false" - - stencil_enable = "true" - stencil_func = "always" - stencil_fail = "stencil_op_keep" - stencil_mask = "0x80" - stencil_pass = "stencil_op_replace" - stencil_ref = "0x80" - stencil_write_mask = "0x80" - stencil_z_fail = "stencil_op_replace" - - stencil_func_back_side = "always" - stencil_fail_back_side = "stencil_op_keep" - stencil_pass_back_side = "stencil_op_replace" - stencil_z_fail_back_side = "stencil_op_replace" - } - } - - outline_stencil_write_z = { - inherit: ["culling_base_default"] - state: { - z_enable = "true" - z_write_enable = "false" - - stencil_enable = "true" - stencil_func = "always" - stencil_fail = "stencil_op_keep" - stencil_mask = "0x80" - stencil_pass = "stencil_op_replace" - stencil_ref = "0x80" - stencil_write_mask = "0x80" - stencil_z_fail = "stencil_op_replace" - - stencil_func_back_side = "always" - stencil_fail_back_side = "stencil_op_keep" - stencil_pass_back_side = "stencil_op_replace" - stencil_z_fail_back_side = "stencil_op_replace" - } - } - - outline_mask_write = { - inherit: ["culling_base_default"] - state: { - z_enable = "true" - z_write_enable = "false" - stencil_enable = "false" - write_mask0 = "red" - } - } - - - shadow_caster = { - inherit: ["depth_only"] - state: { - "on_renderer(D3D11, D3D12)" = { - depth_bias = "0xff" - slope_scale_depth_bias = "2.5" - } - "on_renderer(GNM)" = { - offset_front = "0.0001" - offset_scale_front = "40.0" - offset_back = "0.0001" - offset_scale_back = "40.0" - } - "on_renderer(GL)" = { - offset_factor = "1.0" - offset_units = "1024.0" - depth_bias_enable = "true" - } - } - } - - material_transfer = { - inherit: ["core/stingray_renderer/shader_libraries/common#default"] - state: { - cull_mode = "cull_none" - z_write_enable = "false" - z_enable = "false" - } - } -} - -sampler_state = { - shadow_map = { - inherit: ["core/stingray_renderer/shader_libraries/common#clamp_point"] - states = { - "on_renderer(D3D11, D3D12)" = { - comparison_func = "less" - filter = "comparison_min_mag_linear_mip_point" - } - "on_renderer(GNM)" = { - comparison_func = "less" - filter = "min_mag_mip_linear" - - } - "on_renderer(GL)" = { - comparison_func = "less" - filter = "min_mag_linear" - } - } - } - - clamp_point_no_mip = { - inherits: ["core/stingray_renderer/shader_libraries/common#clamp"] - states = { - "on_renderer(GL)" = { - filter = "min_mag_point" - } - "on_renderer(D3D11, D3D12)" = { - filter = "min_mag_mip_point" - } - "on_renderer(GNM)" = { - filter = "min_mag_mip_point" - } - } - } -} - -channels = { - "(defined(HAS_NORMAL) && !defined(WORLD_SPACE_NORMAL)) || defined(NEEDS_TANGENT_SPACE)": { - vertex_tangent = { type = "float3" semantic = "TANGENT" domain = "vertex" } - vertex_binormal = { type = "float3" semantic = "BINORMAL" domain = "vertex" } - - tsm0 = { type = "float3" domains = ["vertex", "pixel"] } - tsm1 = { type = "float3" domains = ["vertex", "pixel"] } - tsm2 = { type = "float3" domains = ["vertex", "pixel"] } - } - - "defined(NEEDS_EYE_VECTOR)": { - eye_vector = { type = "float3" domain = "vertex" } - } - - "!defined(HAS_NORMAL) || defined(NEEDS_WORLD_SPACE_NORMAL)": { - world_space_normal = { type = "float3" domains = ["vertex", "pixel"] } - } - - "defined(MOTION_BLUR)": { - last_clip_position = { type = "float3" domains = ["vertex", "pixel"] } - } - - vertex_position = { type = "float4" domain = "vertex" } - vertex_normal = { type = "float3" semantic = "NORMAL" domain = "vertex" } - - "defined(HAS_VERTEX_BAKED_DIFFUSE_LIGHTING)": { - vertex_color1 = { type = "float4" semantic = "COLOR1" domains = ["vertex"] } - baked_light = { type = "float3" domains = ["vertex", "pixel"] } - } - - "defined(HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING)": { - lightmap_uv_input = { type = "float2" semantic="TEXCOORD1" domains = ["vertex"] } - lightmap_uv = { type = "float2" domains = ["vertex", "pixel"] } - } - - "defined(MATERIAL_TRANSFER)": { - lightmap_uv = { type = "float2" semantic="TEXCOORD1" domains = ["vertex"] } - } - - "defined(NEEDS_UNSKINNED_WORLD_POS)": { - unskinned_world_pos = { type = "float3" domains = ["vertex", "pixel"] } - unskinned_normal = { type = "float3" domains = ["vertex", "pixel"] } - } - - "defined(NEEDS_PIXEL_DEPTH)": { - pixel_depth = { type = "float" domain = "pixel" } - } - - "defined(NEEDS_SCREEN_POS)": { - screen_pos = { type = "float2" domain = "pixel" } - } - - "defined(NEEDS_SUN_SHADOW_MASK)": { - //"defined(NEEDS_SUN_SHADOW_MASK) && (defined(EMISSIVE_PASS) || defined(TRANSPARENT) || defined(TRANSPARENT_FADE))": { - sun_shadow_mask = { type = "float" domain = "pixel" } - } -} - -//log_permutations = true -permutation_sets = { - vertex_modifiers = [ - { if: "num_skin_weights() == 4" define: { "macros": ["SKINNED_4WEIGHTS"] stages: ["vertex"] } } - { if: "num_skin_weights() == 3" define: { "macros": ["SKINNED_3WEIGHTS"] stages: ["vertex"] } } - { if: "num_skin_weights() == 2" define: { "macros": ["SKINNED_2WEIGHTS"] stages: ["vertex"] } } - { if: "num_skin_weights() == 1" define: { "macros": ["SKINNED_1WEIGHT"] stages: ["vertex"] } } - { default = true } - ] - - instanced_modifiers = [ - // { if: "mesh_baked_lighting_type() == lightmap" define: ["HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING"] } - { default = true } - ] - - lightmap_modifiers = [ - // { if: "lightmap_format() == directional_irradiance" define: ["HAS_DIRECTIONAL_LIGHTMAPS"] } - { default = true } - ] - - non_instanced_modifiers = [ - // { if: "mesh_baked_lighting_type() == lightmap" define: ["HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING"] permute_with: "lightmap_modifiers" } - // { if: "mesh_baked_lighting_type() == vertex" define: ["HAS_VERTEX_BAKED_DIFFUSE_LIGHTING"] } - { permute_with: "vertex_modifiers" } - ] - - instanced_and_non_instanced = [ - { if: "defined(INSTANCED)" permute_with: "instanced_modifiers" } - { if: "!defined(INSTANCED)" permute_with: "non_instanced_modifiers" } - ] - - default = [ - // FBX Standard material exclusive permutations, these will only compile of the - // 'USE_FBX_PERMUTATIONS' option is set, which it is in the shader used for imported fbx files. - //{ if: "defined(USE_FBX_PERMUTATIONS) && is_any_material_variable_set(use_emissive_map, emissive)" define: ["FBX_EMISSIVE"] permute_with: "instanced_and_non_instanced" } - - // Normal default permutation set - { if: "on_renderer(D3D11, D3D12, GNM, GL) && render_cap(development) && render_setting(mipmap_visualization)" defines=["MIPMAP_LEVEL_VISUALIZATION"] permute_with: "instanced_and_non_instanced" } - { if: "on_renderer(D3D11, D3D12, GNM, GL) && (defined(TRANSPARENT) || defined(TRANSPARENT_FADE)) && render_setting(low_res_transparency)" defines=["LOW_RES_ENABLED"] permute_with: "instanced_and_non_instanced" } - { permute_with: "instanced_and_non_instanced" } - ] - - shadow_caster = [ - { if: "defined(INSTANCED)" } - { if: "!defined(INSTANCED)" permute_with: "vertex_modifiers" } - ] -} - -//log_permutations = true -//log_constant_buffers = true -shader_contexts = { - shadow_caster = { - passes_sort_mode = "immediate" - compile_with = [ - { if: "on_renderer(D3D11, D3D12, GNM, GL)" permute_with: "shadow_caster" } - ] - - passes = [ - { code_block="depth_only" render_state="shadow_caster" } - ] - } - - //material_transfer = { - // passes_sort_mode = "immediate" - // compile_with = [ - // { if: "on_renderer(D3D11, D3D12)" } - // ] - // - // passes = [ - // { code_block="gbuffer_base" defines=["MATERIAL_TRANSFER"] render_state="material_transfer" } - // ] - //} - - default = { - passes_sort_mode = "deferred" - compile_with = [ - { if: "on_renderer(D3D11, D3D12, GNM, GL)" permute_with: [ - // TODO: create permutation for when local lights is off. - { permute_with: "default" } - ] } - ] - - passes = [ - { if: "(defined(TRANSPARENT) || defined(TRANSPARENT_FADE))" then: [ - { if: "defined(CULL_NONE)" then: [ - // TODO: render transparency in two passes makes the last pass not being sorted correctly with particles - //{ layer="hdr_transparent" code_block="gbuffer_base" defines="CALCULATE_LIGHTING" render_state="transparent_double_sided_ccw" } - //{ layer="hdr_transparent" code_block="gbuffer_base" defines="CALCULATE_LIGHTING" render_state="transparent_double_sided_cw" } - { layer="hdr_transparent" code_block="gbuffer_base" defines="CALCULATE_LIGHTING" render_state="transparent" } - ] else: [ - { layer="hdr_transparent" code_block="gbuffer_base" defines="CALCULATE_LIGHTING" render_state="transparent" } - ]} - ] else: [ - { if: "defined(GBUFFER_POST_OUTLINE)" then: [ - { layer="gbuffer_post_outline" code_block="gbuffer_base" defines="MOTION_BLUR" render_state="gbuffer_material" } - ] else: [ - { if: "defined(HAS_FOV)" then: [ - { layer="gbuffer_fpr" code_block="gbuffer_base" defines="MOTION_BLUR" render_state="gbuffer_material" } - ] else: [ - { if: "defined(HAS_OPACITY) || defined(JITTER_TRANSPARENCY)" then: [ - { layer="gbuffer_alpha_masked" code_block="gbuffer_base" defines="MOTION_BLUR" render_state="gbuffer_material" } - ] else: [ - { layer="gbuffer" code_block="gbuffer_base" defines="MOTION_BLUR" render_state="gbuffer_material" } - ]} - ]} - ]} - - // This bit of logic is a bit complicated. The gist of it is that we want to disable this pass - // for materials that has a value connected on emissive for all permutations, but should have it - // discarded for all but the special permutations with the define FBX_EMISSIVE - { if: "defined(HAS_EMISSIVE) && (!defined(USE_FBX_PERMUTATIONS) || defined(FBX_EMISSIVE))" then: [ - { layer="emissive" code_block="gbuffer_base" defines={ macros: ["EMISSIVE_PASS"] stages: ["pixel"] } render_state="emissive" } - ]} - - { if: "!defined(OPAQUE_FORWARD_DISABLED)" then: [ - { layer="opaque_forward" code_block="gbuffer_base" defines=["OPAQUE_FORWARD" "CALCULATE_LIGHTING" "MOTION_BLUR"] render_state="culling_base_default" } - ]} - ]} - - // Note we define MOTION_VECTOR for these additional passes to ensure we share constant buffer for bone stransforms with the opaque gbuffer pass - // For transparent surfaces the MOTION_VECTOR define gets undefined in the SKINNED code block - { if: "!on_renderer(GL)" then: [ - { layer="wireframe" code_block="depth_only" defines=["DRAW_WIREFRAME" "MOTION_BLUR"] render_state="wireframe" branch_key="dev_wireframe" } - ]} - - { layer="outline" code_block="depth_only" define="DRAW_OUTLINE" render_state="outline_stencil_write" branch_key="outline_unit" } - { layer="outline" code_block="depth_only" define="DRAW_OUTLINE" render_state="outline_stencil_write_z" branch_key="outline_unit_z" } - - // not used - // { layer="outline_mask" code_block="depth_only" defines=["DRAW_OUTLINE" "OUTLINE_MASK_WRITE"] render_state="outline_mask_write" branch_key="outline_unit_z_fail" } - // { layer="outline" code_block="depth_only" defines=["DRAW_OUTLINE" "OUTLINE_MASK_READ"] render_state="outline_stencil_write" branch_key="outline_unit_z_fail" } - ] - } -} - -code_blocks = { - gbuffer_base = { - include:[ - "core/stingray_renderer/shader_libraries/common#common", - "core/stingray_renderer/shader_libraries/common#gbuffer_access", - "core/stingray_renderer/shader_libraries/common#skinning", - "core/stingray_renderer/shader_libraries/common#taa_offsets", - "core/stingray_renderer/shader_libraries/lighting_common#brdf", - "core/stingray_renderer/shader_libraries/common#fog", - "core/stingray_renderer/shader_libraries/shadow_map_common#shadow_bias", - "core/stingray_renderer/shader_libraries/shadow_map_common#shadow_map_filtering", - "core/stingray_renderer/shader_libraries/lighting_common#lighting", - "core/stingray_renderer/shader_libraries/lighting_common#clustered_shading", - "core/stingray_renderer/shader_libraries/common#billboard_transformation"] - - instance_data = { - "on_renderer(D3D11) && !defined(MATERIAL_TRANSFER) && defined(INSTANCED)": { - world = { type = "matrix4x4" } - "defined(MOTION_BLUR)": { - last_world = { type = "matrix4x4" } - } - } - } - - stage_conditions = { - tessellation_control = "defined(DX11_DISPLACEMENT_MAPPING)" - } - - samplers = { - "defined(HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING)": { - lightmap = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "lightmap" - type = "2d" - } - lightmap_ambient_term = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "lightmap_ambient_term" - type = "2d" - } - lightmap_directional_term = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "lightmap_directional_term" - type = "2d" - } - lightmap_dominant_direction = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "lightmap_dominant_direction" - type = "2d" - } - } - - "defined(HAS_REFRACTION)": { - hdr0 = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "hdr0" - type = "2d" - } - } - "defined(HAS_REFRACTION) || defined(NEEDS_LINEAR_DEPTH)": { - linear_depth = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_point" - source = "resource_set" - slot_name = "linear_depth" - type = "2d" - } - } - - "defined(CALCULATE_LIGHTING)": { - sun_shadow_map = { - sampler_state = "core/stingray_renderer/shader_libraries/shadow_map_common#shadow_map" - slot_name = "sun_shadow_map" - type = "2d" - } - local_lights_shadow_atlas = { - sampler_state = "core/stingray_renderer/shader_libraries/shadow_map_common#shadow_map" - slot_name = "local_lights_shadow_atlas" - type = "2d" - } - //cs_cluster_buffer = { - // sampler_state = "clamp_point_no_mip" - // slot_name = "cs_cluster_buffer" - // type = "2d" - //} - //cs_light_index_buffer = { - // sampler_state = "clamp_point_no_mip" - // slot_name = "cs_light_index_buffer" - // type = "2d" - //} - //cs_light_data_buffer = { - // sampler_state = "clamp_point_no_mip" - // slot_name = "cs_light_data_buffer" - // type = "2d" - //} - //cs_light_shadow_matrices_buffer = { - // sampler_state = "clamp_point_no_mip" - // slot_name = "cs_light_shadow_matrices_buffer" - // type = "2d" - //} - static_sun_shadow_map = { - sampler_state = "core/stingray_renderer/shader_libraries/shadow_map_common#shadow_map" - slot_name = "static_sun_shadow_map" - type = "2d" - } - global_diffuse_map = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "global_diffuse_map" - type = "cube" - } - global_specular_map = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "global_specular_map" - type = "cube" - } - brdf_lut = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "brdf_lut" - type = "2d" - } - } - - "!defined(LOW_RES)": { - "defined(LOW_RES_ENABLED)": { - hdr_transparent_div4 = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "hdr_transparent_div4" - type = "2d" - } - - hdr_linear_depth_div4 = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "hdr_linear_depth_div4" - type = "2d" - } - } - } - - // TODO: this is incorrect, we need to actually sample the shadow maps... - /* - "defined(NEEDS_SUN_SHADOW_MASK) && defined(EMISSIVE_PASS)": { - ldr0 = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_point" - source = "resource_set" - slot_name = "ldr0" - type = "2d" - } - } - */ - } - - code = { - glsl = """ - #if defined(NEEDS_WORLD_SPACE_POSITION) || defined(NEEDS_TANGENT_SPACE) || defined(NEEDS_WORLD_POSE) || defined(NEEDS_WORLD_SPACE_NORMAL) - #define NEEDS_WORLD - #endif - - #if defined(NEEDS_WORLD_SPACE_POSITION) - #define NEEDS_VIEW_PROJECTION - #endif - - CBUFFER_START(c_per_object) - UNIFORM mat4 world_view_proj; - - #if defined(NEEDS_WORLD) - UNIFORM mat4 world; - #endif - - #if defined(NEEDS_VIEW_PROJECTION) - UNIFORM mat4 view_proj; - #endif - - #if defined(NEEDS_INVERSE_WORLD_POSE) - UNIFORM mat4 inv_world; - #endif - - #if defined(HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING) - #if defined(HAS_DIRECTIONAL_LIGHTMAPS) - UNIFORM vec2 lightmap_ambient_term_uv_scale; - UNIFORM vec2 lightmap_ambient_term_uv_offset; - #else - UNIFORM vec2 lightmap_uv_scale; - UNIFORM vec2 lightmap_uv_offset; - #endif - #endif - CBUFFER_END - - #if defined(CALCULATE_LIGHTING) - DECLARE_CLUSTER_DATA(cs_cluster_buffer); - DECLARE_LIGHT_INDEX_DATA(cs_light_index_buffer); - DECLARE_LIGHT_DATA(cs_light_data_buffer); - DECLARE_LIGHT_SHADOW_MATRICES(cs_light_shadow_matrices_buffer); - - DECLARE_COMPARISON_SAMPLER_2D(sun_shadow_map); - DECLARE_COMPARISON_SAMPLER_2D(local_lights_shadow_atlas); - DECLARE_SAMPLER_CUBE(global_specular_map); - DECLARE_SAMPLER_2D(brdf_lut); - #endif - #if defined(TRANSPARENT) || defined(TRANSPARENT_FADE) - #if defined(HAS_REFRACTION) || defined(NEEDS_LINEAR_DEPTH) - DECLARE_SAMPLER_2D(hdr0); - uniform highp usampler2D linear_depth; - #define HAS_LINEAR_DEPTH - #endif - #endif - - #if defined(STAGE_VERTEX) - layout(location = POSITION0) in vec4 in_position; - - void main() { - GraphManualChannels params; - GraphResults graph; - - #if defined(SKINNED) - vec4 p = vec4(skin_point(in_position, blendindices, blendweights), 1); - mediump vec3 n = skin_vector(GRAPH_DATA(vertex_normal).xyz, blendindices, blendweights); - #if defined(NEEDS_TANGENT_SPACE) - mediump vec3 t = skin_vector(GRAPH_DATA(vertex_tangent).xyz, blendindices, blendweights); - mediump vec3 b = skin_vector(GRAPH_DATA(vertex_binormal).xyz, blendindices, blendweights); - #endif - #else - vec4 p = in_position; - mediump vec3 n = GRAPH_DATA(vertex_normal); - #if defined(NEEDS_TANGENT_SPACE) - mediump vec3 t = GRAPH_DATA(vertex_tangent); - mediump vec3 b = GRAPH_DATA(vertex_binormal); - #endif - #endif - - #if defined(NEEDS_WORLD_SPACE_NORMAL) - GRAPH_PARAM(params, world_space_normal) = n * mat3(world); - #endif - - GRAPH_PARAM(params, vertex_position) = p; - - #if defined(NEEDS_WORLD_SPACE_POSITION) - vec4 wp = p * world; - #if defined(NEEDS_WORLD_POS_CHANNEL) - GRAPH_PARAM(params, world_pos) = wp.xyz; - #endif - #endif - - #if defined(NEEDS_TANGENT_SPACE) - tspace_transform_transpose( - GRAPH_PARAM(params, tsm0), - GRAPH_PARAM(params, tsm1), - GRAPH_PARAM(params, tsm2), - t, b, n, - mat3(world)); - #endif - - #if defined(NEEDS_EYE_VECTOR) - GRAPH_PARAM(params, eye_vector) = camera_pos - wp.rgb; - #endif - - #if defined(HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING) - mediump vec2 light_uv_in = GRAPH_DATA(lightmap_uv); - - #if defined(HAS_DIRECTIONAL_LIGHTMAPS) - mediump vec2 luv = light_uv_in*lightmap_ambient_term_uv_scale + lightmap_ambient_term_uv_offset; - #else - mediump vec2 luv = light_uv_in*lightmap_uv_scale + lightmap_uv_offset; - #endif - - GRAPH_PARAM(params, lightmap_uv) = luv; - #endif - - #if defined(NEEDS_SCREEN_SPACE_NORMAL) - GRAPH_PARAM(params, screen_space_normal) = mul(n.xyz, mat3(world_view_proj)); - #endif - - graph_evaluate(graph, params); - - #if defined(NEEDS_WORLD_SPACE_POSITION) - #if defined(HAS_VERTEX_OFFSET) - wp.xyz += graph.vertex_offset; - #if defined(NEEDS_WORLD_POS_CHANNEL) - GRAPH_PARAM(params, world_pos) = wp.xyz; - #endif - #endif - gl_Position = wp * view_proj; - #else - gl_Position = p * world_view_proj; - #endif - } - #elif defined(STAGE_FRAGMENT) - #if defined(EMISSIVE_PASS) - layout(location = 0) out mediump vec4 out_color; - - void main() { - GraphManualChannels params; - GraphResults graph; - graph_evaluate(graph, params); - - #if defined(EMISSIVE_PASS) - #if defined(HAS_OPACITY) - #if defined(HAS_OPACITY_THRESHOLD) - float threshold = graph.opacity_threshold; - #else - float threshold = 0.5f; - #endif - if (graph.opacity < threshold) - discard; - #endif - out_color = vec4(graph.emissive, 0); - #endif - } - #else - #if defined(TRANSPARENT) || defined(TRANSPARENT_FADE) - layout(location = 0) out mediump vec4 out_color; - #else - GBUFFER_OUTPUT; - #endif - - #if defined(HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING) - #if defined(HAS_DIRECTIONAL_LIGHTMAPS) - DECLARE_SAMPLER_2D(lightmap_ambient_term); - DECLARE_SAMPLER_2D(lightmap_directional_term); - DECLARE_SAMPLER_2D(lightmap_dominant_direction); - #else - DECLARE_SAMPLER_2D(lightmap); - #endif - #endif - - DECLARE_SAMPLER_CUBE(global_diffuse_map); - - void main() { - GraphManualChannels params; - GraphResults graph; - - #if defined(TRANSPARENT) || defined(TRANSPARENT_FADE) - float3 world_pos = GRAPH_DATA(world_pos); - float3 view_dir = float3(camera_world[0].w, camera_world[1].w, camera_world[2].w) - world_pos; - float3 camera_dir = float3(camera_world[0].y, camera_world[1].y, camera_world[2].y); - - float depth = dot(-view_dir, camera_dir); - - #if defined(NEEDS_PIXEL_DEPTH) - GRAPH_PARAM(params, pixel_depth) = depth; - #define HAS_PIXEL_DEPTH - #endif - - #if defined(NEEDS_SCREEN_POS) || defined(HAS_REFRACTION) - float2 screen_pos = gl_FragCoord.xy/back_buffer_size; - - #if defined(NEEDS_SCREEN_POS) - GRAPH_PARAM(params, screen_pos) = screen_pos; - #endif - #endif - #endif - - graph_evaluate(graph, params); - - #if defined(HAS_OPACITY) && !defined(TRANSPARENT) && !defined(TRANSPARENT_FADE) - #if defined(HAS_OPACITY_THRESHOLD) - float threshold = graph.opacity_threshold; - #else - float threshold = 0.5; - #endif - if (graph.opacity < threshold) - discard; - #endif - - // Base color - lowp vec3 base_color = vec3(0); - #if defined(HAS_BASE_COLOR) - base_color = graph.base_color; - #else - base_color = vec3(0.5, 0.5, 0.5); - #endif - - // World space normal - #if defined(HAS_NORMAL) - #if defined(WORLD_SPACE_NORMAL) - mediump vec3 wn = normalize(graph.normal); - #if defined(CULL_NONE) || defined(CULL_FRONT) - wn = !gl_FrontFacing ? wn : -wn; - #endif - #else - float3 tsm0 = GRAPH_DATA(tsm0).xyz; - float3 tsm1 = GRAPH_DATA(tsm1).xyz; - float3 tsm2 = GRAPH_DATA(tsm2).xyz; - #if defined(CULL_NONE) || defined(CULL_FRONT) - if (gl_FrontFacing) { - tsm0.z = -tsm0.z; - tsm1.z = -tsm1.z; - tsm2.z = -tsm2.z; - } - #endif - mediump vec3 wn = rotate_vector3(graph.normal, tsm0, tsm1, tsm2); - #endif - #else - mediump vec3 wn = normalize(GRAPH_DATA(world_space_normal)); - #if defined(CULL_NONE) || defined(CULL_FRONT) - wn = !gl_FrontFacing ? wn : -wn; - #endif - #endif - - // Metallic - lowp float metallic = 0.0; - #if defined(HAS_METALLIC) - metallic = graph.metallic; - #else - metallic = 0.0; - #endif - - // Roughness - half roughness = 0.0; - #if defined(HAS_ROUGHNESS) - roughness = max(graph.roughness, 1.f / 255.f); - #else - roughness = 0.5; - #endif - - // Ambient Diffuse - mediump vec3 ambient = vec3(0.0, 0.0, 0.0); - #if defined(HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING) - #if defined(HAS_DIRECTIONAL_LIGHTMAPS) - ambient = TEX2D(lightmap_ambient_term, GRAPH_DATA(lightmap_uv)).rgb; - mediump vec3 dd = TEX2D(lightmap_dominant_direction, GRAPH_DATA(lightmap_uv)).rgb * 2.0 - vec3(1.0); - ambient += TEX2D(lightmap_directional_term, GRAPH_DATA(lightmap_uv)).rgb * max(0.0, dot(dd, wn)); - #else - ambient = TEX2D(lightmap, GRAPH_DATA(lightmap_uv)).rgb; - #endif - #else - ambient = gbuffer_decode_ambient_diffuse_light(TEXCUBELOD(global_diffuse_map, wn, 0.0)); - #endif - - lowp float ambient_occlusion = 1.0; - #if defined(HAS_AMBIENT_OCCLUSION) - ambient_occlusion = graph.ambient_occlusion; - #endif - - // Density - half density = 1.0; - #if defined(HAS_DENSITY) - density = graph.density; - #endif - #if !defined(TRANSPARENT) && !defined(TRANSPARENT_FADE) - out_base_color = gbuffer_encode_base_color(base_color); - out_normal = gbuffer_encode_normal(wn); - out_metallic = gbuffer_encode_metallic_mask(metallic); - out_roughness = gbuffer_encode_roughness(roughness); - out_ambient_occlusion = gbuffer_encode_ambient_occlusion(ambient_occlusion); - out_ambient_diffuse_light = gbuffer_encode_ambient_diffuse_light(ambient); - - out_density = gbuffer_encode_density(density); - #else - #if defined(HAS_OPACITY) - half opacity = graph.opacity; - #else - half opacity = 0.5; - #endif - - float3 V = normalize(view_dir); - float3 N = normalize(wn); - - // 0.04 is taken as a common value for dielectrics. Source: Real-time rendering 3rd edition. - float3 specular_color = lerp(new_half3(0.04, 0.04, 0.04), base_color, metallic); - float3 diffuse_color = lerp(base_color, new_half3(0.0, 0.0, 0.0), metallic); - - float3 acc_diff = new_half3(0.0, 0.0, 0.0); - float3 acc_spec = new_half3(0.0, 0.0, 0.0); - float3 translucency = new_half3(0.0, 0.0, 0.0); - #if defined(CALCULATE_LIGHTING) - calculate_lighting(world_pos, depth, sun_shadow_map, brdf_lut, global_specular_map, N, V, roughness, ambient, diffuse_color, specular_color, density, base_color, acc_diff, acc_spec, translucency); - clustered_shading(cs_cluster_buffer, cs_light_index_buffer, cs_light_data_buffer, cs_light_shadow_matrices_buffer,local_lights_shadow_atlas, world_pos, V, N, diffuse_color, specular_color, roughness, gl_FragCoord.xy, depth, density, base_color, acc_diff, acc_spec, translucency); - #endif - - float3 acc_refraction = new_half3(0,0,0); - #if defined(HAS_REFRACTION) - #if defined(HAS_NORMAL) - float3 distortion_normal = normalize( mul(N, mat3(view_proj)) ); - #else - float3 distortion_normal = GRAPH_DATA(screen_space_normal); - #endif - - // put refraction value more towards the range of real material IOR values (air=1.0 glass=1.5). - half ior_air = 1.0; - half ior_range_bias = 0.1; - half2 distorted_uv = screen_pos - distortion_normal.xy * (graph.refraction - ior_air) * ior_range_bias; - - // avoid including pixels from objects in front of the refractive object - highp float refraction_depth = uintBitsToFloat(texture(linear_depth, distorted_uv).r); - bool depth_ok = depth < refraction_depth; - distorted_uv = lerp(screen_pos, distorted_uv, vec2(depth_ok, depth_ok)); - - acc_refraction = TEX2D(hdr0, distorted_uv).rgb; - acc_refraction *= (1.0 - opacity); - - #if defined(TRANSPARENT_FADE) - acc_diff *= opacity_to_use; - acc_spec *= opacity_to_use; - #endif - #endif - - #if defined(TRANSPARENT) - float3 accumulated_color = acc_diff * opacity + acc_refraction + acc_spec; - #else - float3 accumulated_color = acc_diff + acc_refraction + acc_spec; - #endif - accumulated_color += translucency; - - #if defined(HAS_EMISSIVE) - accumulated_color += graph.emissive; - #endif - - out_color = apply_fog(new_half4_xyz(accumulated_color, opacity), world_pos, depth); - #endif - } - #endif - #endif - """ - - hlsl = """ - // We need to disable instancing for the material transfer context as it doesn't use the world transform. - #if defined(INSTANCED) && defined(MATERIAL_TRANSFER) - #undef INSTANCED - #endif - - #if defined(CALCULATE_LIGHTING) || defined(NEEDS_PIXEL_DEPTH) || (!defined(LOW_RES) && defined(LOW_RES_ENABLED)) - #define PS_NEEDS_WP - #endif - - #if defined(PS_NEEDS_WP) || defined(NEEDS_EYE_VECTOR) || defined(HAS_VERTEX_OFFSET) || ((defined(RENDERER_D3D11)) && defined(INSTANCED)) || defined(BILLBOARD) - #define NEEDS_WORLD_SPACE_POSITION - #endif - - #if (defined(HAS_NORMAL) && !defined(WORLD_SPACE_NORMAL)) || defined(HAS_ANISOTROPY) - #define NEEDS_TANGENT_SPACE - #endif - - #if defined(HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING) - #if defined(HAS_DIRECTIONAL_LIGHTMAPS) - DECLARE_SAMPLER_2D(lightmap_ambient_term); - DECLARE_SAMPLER_2D(lightmap_directional_term); - DECLARE_SAMPLER_2D(lightmap_dominant_direction); - #else - DECLARE_SAMPLER_2D(lightmap); - #endif - #endif - - #if defined(NEEDS_INVERSE_WORLD_POSE) - #define NEEDS_INV_WORLD; - #endif - - #if defined(NEEDS_SUN_SHADOW_MASK) && defined(EMISSIVE_PASS) - DECLARE_SAMPLER_2D(ldr0); - #endif - - struct VS_INPUT - { - float4 position : POSITION; - SKIN_INPUT - GRAPH_VERTEX_INPUT - }; - - struct PS_INPUT - { - float4 position : SV_POSITION; - #if defined(PS_NEEDS_WP) - float3 world_pos : TEXCOORD15; - #endif - GRAPH_PIXEL_INPUT - }; - - CBUFFER_START(c_per_object) - float4x4 view_proj; - float4x4 world_view_proj; - #if defined(NEEDS_INV_WORLD) - float4x4 inv_world; - #endif - float4x4 world; - float4x4 last_world; - - #if defined(JITTER_TRANSPARENCY) - float inv_jitter_alpha; - #endif - - #if defined(HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING) - #if defined(HAS_DIRECTIONAL_LIGHTMAPS) - float2 lightmap_ambient_term_uv_scale; - float2 lightmap_ambient_term_uv_offset; - #else - float2 lightmap_uv_scale; - float2 lightmap_uv_offset; - #endif - #endif - - #if defined(BILLBOARD) && defined(SKYDOME_BILLBOARD) - #if defined(SECONDARY_SUN_DIRECTION) - float3 secondary_sun_direction; - #define billboard_direction secondary_sun_direction - #else - float3 sun_direction; - #define billboard_direction sun_direction - #endif - #endif - - #if defined(USE_GLOBAL_ROUGHNESS_MULTIPLIER) - float global_roughness_multiplier; - #endif - - GRAPH_MATERIAL_EXPORTS - CBUFFER_END - - #if defined(CALCULATE_LIGHTING) - DECLARE_CLUSTER_DATA(cs_cluster_buffer); - DECLARE_LIGHT_INDEX_DATA(cs_light_index_buffer); - DECLARE_LIGHT_DATA(cs_light_data_buffer); - DECLARE_LIGHT_SHADOW_MATRICES(cs_light_shadow_matrices_buffer); - - DECLARE_COMPARISON_SAMPLER_2D(sun_shadow_map); - DECLARE_COMPARISON_SAMPLER_2D_SHARED(static_sun_shadow_map, sun_shadow_map); - DECLARE_COMPARISON_SAMPLER_2D_SHARED(local_lights_shadow_atlas, sun_shadow_map); - DECLARE_SAMPLER_CUBE(global_specular_map); - DECLARE_SAMPLER_CUBE_SHARED(global_diffuse_map, global_specular_map); - DECLARE_SAMPLER_2D_SHARED(brdf_lut, global_specular_map); - #endif - - #if defined(TRANSPARENT) || defined(TRANSPARENT_FADE) - #if defined(HAS_REFRACTION) - DECLARE_SAMPLER_2D_SHARED(hdr0, global_specular_map); - #endif - #if defined(HAS_REFRACTION) || defined(NEEDS_LINEAR_DEPTH) - DECLARE_SAMPLER_2D(linear_depth); - #define HAS_LINEAR_DEPTH - #endif - #endif - - #if !defined(LOW_RES) && defined(LOW_RES_ENABLED) - DECLARE_SAMPLER_2D_SHARED(hdr_transparent_div4, global_specular_map); - DECLARE_SAMPLER_2D_SHARED(hdr_linear_depth_div4, global_specular_map); - #endif - - #if defined(INSTANCED) && (defined(RENDERER_D3D11)) - Buffer idata; - float ioffset; - #endif - - inline float3 calc_clip_position_with_halton_offset(float3 wp, float4x4 view_proj) - { - float4 clip_pos = mul(float4(wp, 1), view_proj); - float4 view_space = clip_pos / clip_pos.w; - view_space.xy += get_vs_halton_offset(frame_number); - view_space.xy = view_space.xy * 0.5 + 0.5; - view_space.y = 1.0 - view_space.y; - clip_pos = view_space * clip_pos.w; - return clip_pos.xyw; - } - - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - PS_INPUT vs_main(VS_INPUT input - #if defined(INSTANCED) && (defined(RENDERER_D3D11)) - , uint instance_id : SV_InstanceId - #endif - ) - { - PS_INPUT o; - float4 p; - - GraphVertexParams params; - GraphVertexResults results; - - #if defined(INSTANCED) && (defined(RENDERER_D3D11)) - uint offset = (uint)ioffset + instance_id*IDATA_STRIDE; - world[0] = idata.Load(offset + IDATA_world + 0); - world[1] = idata.Load(offset + IDATA_world + 1); - world[2] = idata.Load(offset + IDATA_world + 2); - world[3] = idata.Load(offset + IDATA_world + 3); - - #if defined(MOTION_BLUR) - last_world[0] = idata.Load(offset + IDATA_last_world + 0); - last_world[1] = idata.Load(offset + IDATA_last_world + 1); - last_world[2] = idata.Load(offset + IDATA_last_world + 2); - last_world[3] = idata.Load(offset + IDATA_last_world + 3); - #endif - #endif - - // Write automatic params - GRAPH_VERTEX_WRITE_PARAMS(params, input); - - // Write output channels - #if defined(SKINNED) - float4 position = float4(skin_point(input.position, input.blendindices, input.blendweights), 1); - #if defined(MOTION_BLUR) - float4 last_position = float4(skin_point_last_frame(input.position, input.blendindices, input.blendweights), 1); - #endif - #if !defined(BILLBOARD) - float3 normal = skin_vector(GRAPH_VERTEX_DATA(input, vertex_normal).xyz, input.blendindices, input.blendweights); - #if defined(NEEDS_TANGENT_SPACE) - float3 tangent = skin_vector(GRAPH_VERTEX_DATA(input, vertex_tangent).xyz, input.blendindices, input.blendweights); - float3 binormal = skin_vector(GRAPH_VERTEX_DATA(input, vertex_binormal).xyz, input.blendindices, input.blendweights); - #endif - #endif - #else - float4 position = input.position; - #if defined(MOTION_BLUR) - float4 last_position = position; - #endif - #if !defined(BILLBOARD) - float3 normal = GRAPH_VERTEX_DATA(input, vertex_normal).xyz; - #if defined(NEEDS_TANGENT_SPACE) - float3 tangent = GRAPH_VERTEX_DATA(input, vertex_tangent).xyz; - float3 binormal = GRAPH_VERTEX_DATA(input, vertex_binormal).xyz; - #endif - #endif - #endif - - #if defined(BILLBOARD) - float4 wp; - float3 normal, tangent, binormal; - #if !defined(SKYDOME_BILLBOARD) - get_billboard_data_from_position(world._m30_m31_m32, camera_world._m30_m31_m32, camera_view, position, wp, normal, tangent, binormal); - #else - get_billboard_data_from_direction(billboard_direction, position, wp, normal, tangent, binormal); - #endif - #elif defined(NEEDS_WORLD_SPACE_POSITION) - float4 wp = mul(position, world); - #endif - - #if defined(NEEDS_UNSKINNED_WORLD_POS) - float4 unskinned_wp = mul(input.position, world); - GRAPH_VERTEX_PARAM(params, unskinned_world_pos) = unskinned_wp.xyz; - GRAPH_VERTEX_PARAM(params, unskinned_normal) = GRAPH_VERTEX_DATA(input, vertex_normal).xyz; - #endif - - GRAPH_VERTEX_PARAM(params, vertex_position) = position; - - #if !defined(HAS_NORMAL) || defined(NEEDS_WORLD_SPACE_NORMAL) - GRAPH_VERTEX_PARAM(params, world_space_normal).rgb = mul(normal, (float3x3)world); - #endif - - #if defined(NEEDS_EYE_VECTOR) - #if defined(BILLBOARD) && defined(SKYDOME_BILLBOARD) - // TODO: not correct length, we can't use length(eye_vector) to determine the distance - GRAPH_VERTEX_PARAM(params, eye_vector).rgb = billboard_direction; - #else - GRAPH_VERTEX_PARAM(params, eye_vector).rgb = camera_pos - wp.rgb; - #endif - #endif - - #if defined(NEEDS_TANGENT_SPACE) - #if defined(LOCK_NORMAL_ROTATION) - tspace_transpose( - GRAPH_VERTEX_PARAM(params, tsm0), - GRAPH_VERTEX_PARAM(params, tsm1), - GRAPH_VERTEX_PARAM(params, tsm2), - tangent, binormal, normal); - #else - tspace_transform_transpose( - GRAPH_VERTEX_PARAM(params, tsm0), - GRAPH_VERTEX_PARAM(params, tsm1), - GRAPH_VERTEX_PARAM(params, tsm2), - tangent, binormal, normal, - (float3x3)world); - #endif - #endif - - // Evaluate all pieces of the graph that should run per-vertex. - GRAPH_EVALUATE_VERTEX(results, params); - - #if defined(NEEDS_WORLD_SPACE_POSITION) - #if defined(HAS_VERTEX_OFFSET) - wp += float4(results.vertex_offset, 0); - #endif - - #if defined(HAS_FOV) - p = mul(wp, camera_custom_fov_view_projection); - #else - p = mul(wp, view_proj); - #endif - #else - #if defined(HAS_FOV) - // TODO: create camera_custom_fov_world_view_projection? - p = mul(mul(position, world), camera_custom_fov_view_projection); - #else - p = mul(position, world_view_proj); - #endif - #endif - - #if defined(MOTION_BLUR) - GRAPH_VERTEX_PARAM(params, last_clip_position) = float3(0.0, 0.0, 0.0); - #if defined(NEEDS_WORLD_SPACE_POSITION) - float4 last_wp = mul(last_position, last_world); - - #if defined(HAS_VERTEX_OFFSET) - // TODO: Add _last_ position offset here to support vertex animation. - // The way it works now will only yield correct results of the offset is constant - last_wp += float4(results.vertex_offset, 0); - #endif - #else - float4 last_wp = mul(last_position, last_world); - #endif - #if defined(HAS_FOV) - float4 last_clip_pos = mul(last_wp, camera_custom_fov_last_view_projection); - #else - float4 last_clip_pos = mul(last_wp, camera_last_view_projection); - #endif - float4 last_view_space = last_clip_pos / last_clip_pos.w; - last_view_space.xy += get_vs_halton_offset(frame_number); - last_view_space.xy = last_view_space.xy * 0.5 + 0.5; - last_view_space.y = 1.0 - last_view_space.y; - last_clip_pos = last_view_space * last_clip_pos.w; - GRAPH_VERTEX_PARAM(params, last_clip_position) = last_clip_pos.xyw; - #endif - - #if defined(MATERIAL_TRANSFER) - float2 unwrapped_uv = GRAPH_VERTEX_DATA(input, lightmap_uv); - float2 ndc = float2(unwrapped_uv.x, unwrapped_uv.y) * 2 - 1; - ndc.y *= -1; - p = float4(ndc, 0, 1); - #endif - - #if defined(HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING) - GRAPH_VERTEX_PARAM(params, lightmap_uv) = float2(0,0); - #if defined(HAS_DIRECTIONAL_LIGHTMAPS) - GRAPH_VERTEX_PARAM(params, lightmap_uv) = GRAPH_VERTEX_DATA(input, lightmap_uv_input)*lightmap_ambient_term_uv_scale + lightmap_ambient_term_uv_offset; - #else - GRAPH_VERTEX_PARAM(params, lightmap_uv) = GRAPH_VERTEX_DATA(input, lightmap_uv_input)*lightmap_uv_scale + lightmap_uv_offset; - #endif - #endif - - #if defined(PS_NEEDS_WP) - o.world_pos = wp.xyz; - #endif - - #if defined(MATERIAL_TRANSFER) - o.position = p; - #else - float4 view_space = p / p.w; - view_space.xy += get_vs_halton_offset(frame_number); - o.position = view_space * p.w; - #endif - - // Write results - GRAPH_VERTEX_WRITE(o, results, params); - - return o; - } - - #if defined(MATERIAL_TRANSFER) - struct MATERIAL_TRANSFER_OUT { - float4 albedo_op : SV_TARGET0; - float4 emissive : SV_TARGET1; - }; - - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - MATERIAL_TRANSFER_OUT ps_main(PS_INPUT input) : SV_TARGET0 - { - GraphPixelParams params; - GraphPixelResults graph; - - GRAPH_PIXEL_WRITE_PARAMS(params, input); - - #if defined(PS_NEEDS_WP) - const float3 world_pos = input.world_pos; - const float3 view_dir = camera_world._m30_m31_m32 - world_pos; - const float3 camera_dir = camera_world._m10_m11_m12; - const float depth = dot(-view_dir, camera_dir); - #endif - - #if defined(NEEDS_PIXEL_DEPTH) - GRAPH_PIXEL_PARAM(params, pixel_depth) = depth; - #endif - - #if defined(NEEDS_SCREEN_POS) - float2 screen_position = (input.position.xy / back_buffer_size); - GRAPH_PIXEL_PARAM(params, screen_pos) = screen_position; - #endif - - GRAPH_EVALUATE_PIXEL(graph, params); - - MATERIAL_TRANSFER_OUT o; - - float opacity = 1.0; - - #if defined(TRANSPARENT) || defined(TRANSPARENT_FADE) - #if defined(HAS_OPACITY) - opacity = graph.opacity; - #else - opacity = 0.5; - #endif - #elif defined(HAS_OPACITY) - #if defined(HAS_OPACITY_THRESHOLD) - float threshold = graph.opacity_threshold; - #else - float threshold = 0.5f; - #endif - if (graph.opacity < threshold) - opacity = 0; - else - opacity = 1.0; - #endif - - #if defined(HAS_BASE_COLOR) - o.albedo_op = float4(graph.base_color, opacity); - #else - o.albedo_op = float4(0.5, 0.5, 0.5, opacity); - #endif - - #if defined(HAS_EMISSIVE) - o.emissive = float4(graph.emissive, 1.0); - #else - o.emissive = float4(0.0, 0.0, 0.0, 0.0); - #endif - - return o; - } - #elif defined(EMISSIVE_PASS) - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - float4 ps_main(PS_INPUT input) : SV_TARGET0 - { - #if defined(JITTER_TRANSPARENCY) - uint2 pos = uint2(input.position.xy); - float alpha = (float)((pos.x%2u) + 2u*(pos.y%2u)) * 0.25; - if (alpha >= 1.0 - inv_jitter_alpha) - discard; - #endif - - GraphPixelParams params; - GraphPixelResults graph; - - GRAPH_PIXEL_WRITE_PARAMS(params, input); - - #if defined(PS_NEEDS_WP) - const float3 world_pos = input.world_pos; - const float3 view_dir = camera_world._m30_m31_m32 - world_pos; - const float3 camera_dir = camera_world._m10_m11_m12; - - const float depth = dot(-view_dir, camera_dir); - #endif - - #if defined(NEEDS_PIXEL_DEPTH) - GRAPH_PIXEL_PARAM(params, pixel_depth) = depth; - #endif - - #if defined(NEEDS_SCREEN_POS) - float2 screen_position = (input.position.xy / back_buffer_size); - GRAPH_PIXEL_PARAM(params, screen_pos) = screen_position; - #endif - - #if defined(NEEDS_SUN_SHADOW_MASK) - GRAPH_PIXEL_PARAM(params, sun_shadow_mask) = ldr0.tex.Load(int3(input.position.xy, 0)).r; - #define HAS_SUN_SHADOW_MASK - #endif - - GRAPH_EVALUATE_PIXEL(graph, params); - - #if defined(EMISSIVE_PASS) - #if defined(HAS_OPACITY) - #if defined(HAS_OPACITY_THRESHOLD) - float threshold = graph.opacity_threshold; - #else - float threshold = 0.5f; - #endif - if (graph.opacity < threshold) - discard; - #endif - return float4(graph.emissive, 0); - #endif - } - #else - #if defined(CALCULATE_LIGHTING) - float4 apply_fog_data(float4 color, float4 fog_data) { - return float4(color.rgb * (1.0 - fog_data.a) + fog_data.rgb * fog_data.a, color.a); - } - - struct PS_OUTPUT { - half4 color : SV_TARGET0; - #if defined(MOTION_BLUR) - half2 buffer4 : SV_TARGET1; - #endif - }; - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - PS_OUTPUT ps_main(PS_INPUT input - #else - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - GBUFFER_OUT ps_main(PS_INPUT input - #endif - #if defined(CULL_NONE) || defined(CULL_FRONT) - #if defined(GNM) - , bool vface : S_FRONT_FACE - #else - , float vface : VFACE - #endif - #endif - ) - { - #if defined(CALCULATE_LIGHTING) - PS_OUTPUT o; - #else - GBUFFER_OUT o; - #endif - - #if defined(JITTER_TRANSPARENCY) && !(defined(TRANSPARENT) || defined(TRANSPARENT_FADE)) - uint2 pos = uint2(input.position.xy); - float alpha = (float)((pos.x%2u) + 2u*(pos.y%2u)) * 0.25; - if (alpha >= 1.0 - inv_jitter_alpha) - discard; - #endif - - GraphPixelParams params; - GraphPixelResults graph; - - GRAPH_PIXEL_WRITE_PARAMS(params, input); - - #if defined(PS_NEEDS_WP) - const float3 world_pos = input.world_pos; - const float3 view_dir = camera_world._m30_m31_m32 - world_pos; - const float3 camera_dir = camera_world._m10_m11_m12; - - const float depth = dot(-view_dir, camera_dir); - #endif - - #if defined(NEEDS_PIXEL_DEPTH) - GRAPH_PIXEL_PARAM(params, pixel_depth) = depth; - #define HAS_PIXEL_DEPTH - #endif - - #if defined(NEEDS_SCREEN_POS) || defined(HAS_REFRACTION) || defined(CALCULATE_LIGHTING) - float2 screen_pos = (input.position.xy / back_buffer_size); - - #if defined(NEEDS_SCREEN_POS) - GRAPH_PIXEL_PARAM(params, screen_pos) = screen_pos; - #endif - #endif - - GRAPH_EVALUATE_PIXEL(graph, params); - - #if defined(HAS_OPACITY) && !defined(TRANSPARENT) && !defined(TRANSPARENT_FADE) - #if defined(HAS_OPACITY_THRESHOLD) - float threshold = graph.opacity_threshold; - #else - float threshold = 0.5f; - #endif - if (graph.opacity < threshold) - discard; - #endif - - - // Base color - float3 base_color_to_use = float3(0,0,0); - #if defined(HAS_BASE_COLOR) - base_color_to_use = graph.base_color; - #else - base_color_to_use = float3(0.5, 0.5, 0.5); - #endif - - // World space normal - #if defined(HAS_NORMAL) - #if !defined(WORLD_SPACE_NORMAL) - float3 tsm0 = GRAPH_PIXEL_DATA(input, tsm0).xyz; - float3 tsm1 = GRAPH_PIXEL_DATA(input, tsm1).xyz; - float3 tsm2 = GRAPH_PIXEL_DATA(input, tsm2).xyz; - #if (defined(CULL_NONE) || defined(CULL_FRONT)) && !defined(NORMAL_FLIP_DISABLED) - if (!front_facing(vface)) { - tsm0.z = -tsm0.z; - tsm1.z = -tsm1.z; - tsm2.z = -tsm2.z; - } - #endif - float3 wn = rotate_vector3(graph.normal, tsm0, tsm1, tsm2); - #if defined(LOCK_NORMAL_ROTATION) - wn = mul(wn, (float3x3)world); - #endif - #else - float3 wn = normalize(graph.normal); - #if (defined(CULL_NONE) || defined(CULL_FRONT)) && !defined(NORMAL_FLIP_DISABLED) - wn = !front_facing(vface) ? -wn : wn; - #endif - #endif - #else - float3 wn = normalize((float3)GRAPH_PIXEL_DATA(input, world_space_normal).rgb); - #if (defined(CULL_NONE) || defined(CULL_FRONT)) && !defined(NORMAL_FLIP_DISABLED) - wn = !front_facing(vface) ? -wn : wn; - #endif - #endif - - // Metallic - half metallic_ = 0.f; - #if defined(HAS_METALLIC) - metallic_ = graph.metallic; - #else - metallic_ = 0.f; - #endif - - // Roughness - half roughness_ = 0.f; - #if defined(HAS_ROUGHNESS) - roughness_ = graph.roughness; - #else - roughness_ = 0.5; - #endif - #if defined(USE_GLOBAL_ROUGHNESS_MULTIPLIER) - roughness_ *= global_roughness_multiplier; - #endif - - // Velocity vector - #if defined(MOTION_BLUR) - float3 last_clip_pos = GRAPH_PIXEL_DATA(input, last_clip_position); - float2 current_screen_pos = (input.position.xy / back_buffer_size - viewport.zw) / viewport.xy; - float2 last_screen_pos = last_clip_pos.xy / last_clip_pos.z; - VELOCITY(o) = encode_velocity(viewport.xy*(current_screen_pos - last_screen_pos)); - #endif - - #if defined(CALCULATE_LIGHTING) - // Ambient Diffuse - float3 ambient = float3(0, 0, 0); - #if defined(HAS_VERTEX_BAKED_DIFFUSE_LIGHTING) - ambient = GRAPH_PIXEL_DATA(input, baked_light).rgb; - #elif defined(HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING) - #if defined(HAS_DIRECTIONAL_LIGHTMAPS) - ambient = TEX2D(lightmap_ambient_term, GRAPH_PIXEL_DATA(input, lightmap_uv)).rgb; - float3 dd = TEX2D(lightmap_dominant_direction, GRAPH_PIXEL_DATA(input, lightmap_uv)).rgb * 2 - 1; - ambient += TEX2D(lightmap_directional_term, GRAPH_PIXEL_DATA(input, lightmap_uv)).rgb * max(0, dot(dd, wn)); - #else - ambient = TEX2D(lightmap, GRAPH_PIXEL_DATA(input, lightmap_uv)).rgb; - #endif - #else - ambient = rgbm_decode(TEXCUBELOD(global_diffuse_map, wn, 0)); - #endif - - // ensure that lightmap debug grid is visible in dark areas of a level - #if defined(DRAW_LIGHTMAP_TEXELS) && defined(HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING) - ambient += float3(0.1, 0.1, 0.1); - #endif - #endif - - // Density - half density_ = 1.0f; - #if defined(HAS_SKIN_SSS_STRENGTH) && (!defined(TRANSPARENT) && !defined(TRANSPARENT_FADE)) - density_ = lerp(1.0, graph.sss_strength, skin_material_enabled); - #elif defined(HAS_DENSITY) - density_ = graph.density; - #endif - #if !defined(CALCULATE_LIGHTING) - BASE_COLOR(o) = gbuffer_encode_base_color(base_color_to_use); - NORMAL(o) = gbuffer_encode_normal(wn); - METALLIC(o) = gbuffer_encode_metallic_mask(metallic_); - ROUGHNESS(o) = gbuffer_encode_roughness(roughness_); - // AMBIENT_DIFFUSE_LIGHT(o) = gbuffer_encode_ambient_diffuse_light(ambient); - - #if defined(HAS_AMBIENT_OCCLUSION) - AMBIENT_OCCLUSION(o) = gbuffer_encode_ambient_occlusion(graph.ambient_occlusion); - #else - AMBIENT_OCCLUSION(o) = gbuffer_encode_ambient_occlusion(1.f); - #endif - DENSITY(o) = gbuffer_encode_density(density_); - #else - #if defined(HAS_OPACITY) - half opacity_to_use = graph.opacity; - #else - half opacity_to_use = 0.5; - #endif - - - const float3 V = normalize(view_dir); - const float3 N = wn; - - #if defined(CALCULATE_LIGHTING) && defined(HAS_ANISOTROPY) - float anisotropy_ = graph.anisotropy; - - // TODO: Reuse and use the real tangent and binormal. Optional should be to input a tangent/binormal map. - float3 tsm00 = GRAPH_PIXEL_DATA(input, tsm0).xyz; - float3 tsm11 = GRAPH_PIXEL_DATA(input, tsm1).xyz; - float3 tsm22 = GRAPH_PIXEL_DATA(input, tsm2).xyz; - - // create tangentspace vectors - #ifdef HAS_NORMAL - float3 B = normalize(float3(tsm00.y, tsm11.y, tsm22.y)); - float3 T = cross(B, N); - B = cross(N, T); - #else - float3 T = normalize(float3(tsm00.x, tsm11.x, tsm22.x)); - float3 B = normalize(float3(tsm00.y, tsm11.y, tsm22.y)); - #endif - #endif - - // 0.04 is taken as a common value for dielectrics. Source: Real-time rendering 3rd edition. - const float3 specular_color = lerp(float3(0.04,0.04,0.04), base_color_to_use, metallic_); - float3 diffuse_color = lerp(base_color_to_use, new_half3(0,0,0), metallic_); - - float3 acc_diff = 0; - float3 acc_spec = 0; - float3 translucency = 0; - #if defined(CALCULATE_LIGHTING) - #if defined(D3D11) - // If we are currently capturing a reflection probe, use specular F0 as diffuse color for metallics - diffuse_color = (capture_cubemap == 1) ? lerp(diffuse_color, specular_color, metallic_) : diffuse_color; - #endif - - calculate_lighting(world_pos, depth, sun_shadow_map, static_sun_shadow_map, brdf_lut, global_specular_map, N, V, roughness_, ambient, diffuse_color, specular_color, density_, base_color_to_use, acc_diff, acc_spec, translucency); - clustered_shading(cs_cluster_buffer, cs_light_index_buffer, cs_light_data_buffer, cs_light_shadow_matrices_buffer, local_lights_shadow_atlas, world_pos, V, N, diffuse_color, specular_color, roughness_, input.position.xy, input.position.w, density_, base_color_to_use, acc_diff, acc_spec, translucency); - #endif - - float3 acc_refraction = float3(0,0,0); - #if defined(HAS_REFRACTION) - #if defined(HAS_NORMAL) - float3 distortion_normal = normalize( mul(N, (float3x3)view_proj) ); - #else - float3 distortion_normal = GRAPH_CHANNEL(input, screen_space_normal); - #endif - - // A negative screen-space normal (-y) means we want to sample more towards the bottom of the screen, so we need to flip this value, because our screen_pos uses 0,0 for top left corner - distortion_normal.y = 1-distortion_normal.y; - - // put refraction value more towards the range of real material IOR values (air=1.0 glass=1.5). - half ior_air = 1.0; - half ior_range_bias = 0.1; - half2 distorted_uv = screen_pos - distortion_normal.xy * (graph.refraction - ior_air) * ior_range_bias; - - // avoid including pixels from objects in front of the refractive object - float refraction_depth = TEX2D(linear_depth, distorted_uv).r; - bool depth_ok = depth < refraction_depth; - distorted_uv = lerp(screen_pos, distorted_uv, depth_ok); - - acc_refraction = TEX2D(hdr0, distorted_uv).rgb; - acc_refraction *= (1 - opacity_to_use); - #endif - - #if !defined(LOW_RES) && defined(LOW_RES_ENABLED) - float2 screen_uv = input.position.xy / back_buffer_size; - - // Fade out high resolution particle if the low resolution particles is infront of the high resolution particle - float2 particle_depth_values = TEX2D(hdr_linear_depth_div4, screen_uv).rg; - float depth_mean = particle_depth_values.x; - float depth_variance = particle_depth_values.y - depth_mean*depth_mean; - float background_depth = depth; - - float diff = max(background_depth - depth_mean, 0.0); - float C = 1.38629436112; // 2 * ln(2) - float T = exp2(-diff*diff / (C * max(depth_variance, 0.001))); - float alpha_modifier = TEX2D(hdr_transparent_div4, screen_uv).a * (1.0 - T); - opacity_to_use *= 1.0 - alpha_modifier; - #endif - - #if defined(JITTER_TRANSPARENCY) - opacity_to_use *= 1.0 - inv_jitter_alpha; - #endif - - float3 accumulated_color = acc_diff + translucency; - #if defined(HAS_EMISSIVE) - accumulated_color += graph.emissive; - #endif - #if defined(TRANSPARENT) - // Transparent don't apply opacity on specular reflection or refraction. - float4 fog_data = calc_fog_vs(world_pos, depth); - float4 color = apply_fog_data(half4(accumulated_color, opacity_to_use), fog_data); - color.rgb = color.rgb * color.a + acc_spec * (1.0 - fog_data.a); - #else - accumulated_color += acc_spec; - float4 color = apply_fog(half4(accumulated_color, opacity_to_use), world_pos, depth); - color.rgb = color.rgb * color.a; - #endif - color.rgb += acc_refraction; - o.color = color; - #if defined(OPAQUE_FORWARD) - o.color.a = 1.0; // make sure it is solid - #endif - #endif - - return o; - } - #endif - """ - } - } - - depth_only = { - include: [ - "core/stingray_renderer/shader_libraries/common#common", - "core/stingray_renderer/shader_libraries/common#skinning", - "core/stingray_renderer/shader_libraries/common#billboard_transformation", - "core/stingray_renderer/shader_libraries/common#taa_offsets"] - - instance_data = { - "on_renderer(D3D11) && defined(INSTANCED)": { - world = { type = "matrix4x4" } - - "defined(DRAW_WIREFRAME)": { - dev_wireframe_color = { type = "vector4" } - } - "defined(DRAW_OUTLINE)": { - outline_color = { type = "vector4" } - outline_time = { type = "scalar" } - "defined(JITTER_TRANSPARENCY)": { - inv_jitter_alpha = { type = "scalar" } - } - } - } - } - - samplers = { - "defined(OUTLINE_MASK_READ)": { - outline_mask = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_point" - source = "resource_set" - slot_name = "outline_mask" - type = "2d" - } - } - } - - code = { - glsl = """ - CBUFFER_START(c_per_object) - UNIFORM mat4 world_view_proj; - #if defined(NEEDS_WORLD_SPACE_POSITION) || defined(NEEDS_WORLD_SPACE_NORMAL) - UNIFORM mat4 world; - UNIFORM mat4 view_proj; - #endif - #if defined(NEEDS_INVERSE_WORLD_POSE) - UNIFORM mat4 inv_world; - #endif - CBUFFER_END - - #if defined(STAGE_VERTEX) - layout(location = POSITION0) in vec4 in_position; - - void main() { - GraphManualChannels params; - GraphResults graph; - - #if defined(NEEDS_WORLD_SPACE_NORMAL) - GRAPH_PARAM(params, world_space_normal) = GRAPH_DATA(vertex_normal) * mat3(world); - #endif - - #if defined(SKINNED) - vec4 op = vec4(skin_point(in_position, blendindices, blendweights), 1); - #else - vec4 op = in_position; - #endif - GRAPH_PARAM(params, vertex_position) = op; - - #if defined(NEEDS_WORLD_SPACE_POSITION) - vec4 wp = op * world; - #endif - - #if defined(NEEDS_EYE_VECTOR) - GRAPH_PARAM(params, eye_vector) = camera_pos - wp.rgb; - #endif - - graph_evaluate(graph, params); - - #if defined(HAS_VERTEX_OFFSET) - wp.xyz += graph.vertex_offset; - gl_Position = wp * view_proj; - #else - gl_Position = op * world_view_proj; - #endif - } - #elif defined(STAGE_FRAGMENT) - void main() { - #if defined(HAS_OPACITY) && !defined(TRANSPARENT) && !defined(TRANSPARENT_FADE) - GraphManualChannels params; - GraphResults graph; - graph_evaluate(graph, params); - - #if defined(HAS_OPACITY_THRESHOLD) - float threshold = graph.opacity_threshold; - #else - float threshold = 0.5f; - #endif - - if (graph.opacity < threshold) - discard; - #endif - } - #endif - """ - - hlsl = """ - - #if defined(PS_NEEDS_WP) || defined(NEEDS_EYE_VECTOR) || defined(HAS_VERTEX_OFFSET) || ((defined(RENDERER_D3D11)) && defined(INSTANCED)) || defined(BILLBOARD) - #define NEEDS_WORLD_SPACE_POSITION - #endif - - struct VS_INPUT { - float4 position : POSITION; - SKIN_INPUT - GRAPH_VERTEX_INPUT - }; - - struct PS_INPUT { - float4 position : SV_POSITION; - #if (defined(RENDERER_D3D11)) && defined(INSTANCED) - #if defined(DRAW_WIREFRAME) - float4 instance_wireframe_color : COLOR0; - #if defined(DRAW_OUTLINE) - float4 instance_outline_color : COLOR1; - float instance_outline_time : COLOR2; - #if defined(JITTER_TRANSPARENCY) - float instance_inv_jitter_alpha : COLOR3; - #endif - #endif - #elif defined(DRAW_OUTLINE) - float4 instance_outline_color : COLOR0; - float instance_outline_time : COLOR1; - #if defined(JITTER_TRANSPARENCY) - float instance_inv_jitter_alpha : COLOR2; - #endif - #endif - #endif - GRAPH_PIXEL_INPUT - }; - - CBUFFER_START(c_depth_only) - float4x4 world; - #if defined(NEEDS_WORLD_SPACE_POSITION) - float4x4 view_proj; - #else - float4x4 world_view_proj; - #endif - #if defined(NEEDS_INVERSE_WORLD_POSE) - float4x4 inv_world; - #endif - float4 dev_wireframe_color; - - #if defined(BILLBOARD) && defined(SKYDOME_BILLBOARD) - #if defined(SECONDARY_SUN_DIRECTION) - float3 secondary_sun_direction; - #define billboard_direction secondary_sun_direction - #else - float3 sun_direction; - #define billboard_direction sun_direction - #endif - #endif - - float4 outline_color; - float outline_time; - float inv_jitter_alpha; - GRAPH_MATERIAL_EXPORTS - CBUFFER_END - - #if defined(OUTLINE_MASK_READ) - DECLARE_SAMPLER_2D(outline_mask); - #endif - - #if defined(INSTANCED) && (defined(RENDERER_D3D11)) - Buffer idata; - float ioffset; - #endif - - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - PS_INPUT vs_main(VS_INPUT input - #if defined(INSTANCED) && (defined(RENDERER_D3D11)) - , uint instance_id : SV_InstanceId - #endif - ) - { - PS_INPUT o; - float4 p; - - GraphVertexParams params; - GraphVertexResults results; - - #if ((defined(HAS_NORMAL) && !defined(WORLD_SPACE_NORMAL)) || defined(NEEDS_TANGENT_SPACE)) - GRAPH_VERTEX_PARAM(params, tsm0) = float3(0, 0, 0); - GRAPH_VERTEX_PARAM(params, tsm1) = float3(0, 0, 0); - GRAPH_VERTEX_PARAM(params, tsm2) = float3(0, 0, 0); - #endif - - #if defined(HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING) - GRAPH_VERTEX_PARAM(params, lightmap_uv) = float2(0, 0); - #endif - - #if defined(INSTANCED) && (defined(RENDERER_D3D11)) - uint offset = (uint)ioffset; - world[0] = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_world + 0)); - world[1] = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_world + 1)); - world[2] = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_world + 2)); - world[3] = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_world + 3)); - - #if defined(DRAW_WIREFRAME) - o.instance_wireframe_color = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_dev_wireframe_color)); - #endif - #if defined(DRAW_OUTLINE) - o.instance_outline_color = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_outline_color)); - o.instance_outline_time = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_outline_time)); - #if defined(JITTER_TRANSPARENCY) - o.instance_inv_jitter_alpha = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_inv_jitter_alpha)); - #endif - #endif - #endif - - // Write automatic params - GRAPH_VERTEX_WRITE_PARAMS(params, input); - - // Write output channels - #if defined(SKINNED) - float4 position = float4(skin_point(input.position, input.blendindices, input.blendweights), 1); - #if !defined(BILLBOARD) && (!defined(HAS_NORMAL) || defined(NEEDS_WORLD_SPACE_NORMAL)) - float3 normal = skin_vector(GRAPH_VERTEX_DATA(input, vertex_normal).xyz, input.blendindices, input.blendweights); - #endif - #else - float4 position = input.position; - #if !defined(BILLBOARD) && (!defined(HAS_NORMAL) || defined(NEEDS_WORLD_SPACE_NORMAL)) - float3 normal = GRAPH_VERTEX_DATA(input, vertex_normal).xyz; - #endif - #endif - - #if defined(BILLBOARD) - #if !defined(HAS_NORMAL) || defined(NEEDS_WORLD_SPACE_NORMAL) - float4 wp; - float3 normal, tangent, binormal; - #if !defined(SKYDOME_BILLBOARD) - get_billboard_data_from_position(world._m30_m31_m32, camera_world._m30_m31_m32, camera_view, position, wp, normal, tangent, binormal); - #else - get_billboard_data_from_direction(billboard_direction, position, wp, normal, tangent, binormal); - #endif - #else - float4 wp; - #if !defined(SKYDOME_BILLBOARD) - get_billboard_positions_from_position(world._m30_m31_m32, camera_world._m30_m31_m32, camera_view, position, wp); - #else - get_billboard_positions_from_direction(billboard_direction, position, wp); - #endif - #endif - #elif defined(NEEDS_WORLD_SPACE_POSITION) - float4 wp = mul(position, world); - // TODO: Expose output channel here - #endif - - // Write output channels - GRAPH_VERTEX_PARAM(params, vertex_position) = position; - - // All members of the params struct has to be initialized, so assign dummy normal here. - #if !defined(HAS_NORMAL) || defined(NEEDS_WORLD_SPACE_NORMAL) - GRAPH_VERTEX_PARAM(params, world_space_normal).rgb = mul(normal, (float3x3)world); - #endif - - #if defined(NEEDS_TANGENT_SPACE) - GRAPH_VERTEX_PARAM(params, tsm0) = - GRAPH_VERTEX_PARAM(params, tsm1) = - GRAPH_VERTEX_PARAM(params, tsm2) = - float3(0, 0, 0); - #endif - - #if defined(NEEDS_EYE_VECTOR) - #if defined(BILLBOARD) && defined(SKYDOME_BILLBOARD) - // TODO: not correct length, we can't use length(eye_vector) to determine the distance - GRAPH_VERTEX_PARAM(params, eye_vector).rgb = billboard_direction; - #else - GRAPH_VERTEX_PARAM(params, eye_vector).rgb = camera_pos - wp.rgb; - #endif - #endif - - // Evaluate all pieces of the graph that should run per-vertex. - GRAPH_EVALUATE_VERTEX(results, params); - - // Apply world pos offset - #if defined(NEEDS_WORLD_SPACE_POSITION) - #if defined(HAS_VERTEX_OFFSET) - wp += float4(results.vertex_offset, 0); - #endif - p = mul(wp, view_proj); - #else - p = mul(position, world_view_proj); - #endif - - #if defined(DRAW_OUTLINE) || defined(OUTLINE_MASK_READ) || defined(OUTLINE_MASK_WRITE) || defined(HAS_FOV) - float4 view_space = p / p.w; - view_space.xy += get_vs_halton_offset(frame_number); - o.position = view_space * p.w; - #else - o.position = p; - #endif - - // Write results - GRAPH_VERTEX_WRITE(o, results, params); - - return o; - } - - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - #if (((defined(RENDERER_D3D11)) && defined(INSTANCED)) || defined(HAS_OPACITY)) || defined(OUTLINE_MASK_READ) - float4 ps_main(PS_INPUT input) : SV_TARGET0 - #else - float4 ps_main() : SV_TARGET0 - #endif - - #if defined(DRAW_WIREFRAME) - { - #if (defined(RENDERER_D3D11)) && defined(INSTANCED) - return input.instance_wireframe_color; - #else - return dev_wireframe_color; - #endif - } - #elif defined(OUTLINE_MASK_WRITE) - { - return float4(1,1,1,1); - } - #elif defined(OUTLINE_MASK_READ) - { - float2 uv = input.position.xy / back_buffer_size; - float mask = 1.0 - TEX2D(outline_mask, uv).r; - if( mask < 1.0 ) - discard; - - #if (defined(RENDERER_D3D11)) && defined(INSTANCED) - return input.instance_outline_color; - #else - return outline_color; - #endif - } - #elif defined(DRAW_OUTLINE) - { - #if defined(HAS_OPACITY) - GraphPixelParams params; - GraphPixelResults graph; - GRAPH_PIXEL_WRITE_PARAMS(params, input); - GRAPH_EVALUATE_PIXEL(graph, params); - - #if defined(HAS_OPACITY_THRESHOLD) - float threshold = graph.opacity_threshold; - #else - float threshold = 0.5f; - #endif - - if (graph.opacity < threshold) - discard; - #endif - - #if (defined(RENDERER_D3D11)) && defined(INSTANCED) - float diff = time - input.instance_outline_time; - float multiplier = min(diff / 0.25, 1); - #if defined(JITTER_TRANSPARENCY) - multiplier *= 1.0 - input.instance_inv_jitter_alpha; - #endif - return input.instance_outline_color * multiplier; - #else - float diff = time - outline_time; - float multiplier = min(diff / 0.25, 1); - #if defined(JITTER_TRANSPARENCY) - multiplier *= 1.0 - inv_jitter_alpha; - #endif - return outline_color * multiplier; - #endif - } - #else - { - #if defined(HAS_OPACITY) && !defined(TRANSPARENT) && !defined(TRANSPARENT_FADE) - GraphPixelParams params; - GraphPixelResults graph; - GRAPH_PIXEL_WRITE_PARAMS(params, input); - GRAPH_EVALUATE_PIXEL(graph, params); - - #if defined(HAS_OPACITY_THRESHOLD) - float threshold = graph.opacity_threshold; - #else - float threshold = 0.5f; - #endif - - if (graph.opacity < threshold) - discard; - #endif - - return float4(1, 1, 1, 1); - } - #endif - """ - } - } -} diff --git a/vmf/core/stingray_renderer/output_nodes/standard_base_bitsquid.shader_node b/vmf/core/stingray_renderer/output_nodes/standard_base_bitsquid.shader_node deleted file mode 100644 index 82c4e45..0000000 --- a/vmf/core/stingray_renderer/output_nodes/standard_base_bitsquid.shader_node +++ /dev/null @@ -1,1740 +0,0 @@ -group = "Output/Bitsquid" -display_name = "Bitsquid - Standard Base" -output_node = true -render_configs = ["core/stingray_renderer/renderer"] - -inputs = { - "aee6e47b-be7b-4d67-a123-2ab5d660b94e" = { - name = "vertex_offset" - display_name = "Position offset" - is_required = false - type = { vector3: ["HAS_VERTEX_OFFSET"] } - domain = "vertex" - } - - "aca690cb-6305-4a2f-bf3d-69183a493db3" = { - name = "base_color" - is_required = false - display_name = "Base Color" - type = { vector3: ["HAS_BASE_COLOR"] } - domain = "pixel" - } - - "34259752-b962-4b65-92c3-903a57338519" = { - name = "opacity" - is_required = false - display_name = "Opacity" - type = { scalar: ["HAS_OPACITY"] } - domain = "pixel" - } - - "7a9306c6-95ae-4cdb-9fef-0eedacce4e83" = { - name = "opacity_threshold" - is_required = false - display_name = "Opacity Threshold" - type = { scalar: ["HAS_OPACITY_THRESHOLD"] } - domain = "pixel" - } - - "b1c86408-aacb-4466-b754-ddcf37a3a2c8" = { - is_required = false - name = "normal" - display_name = "Normal" - type = { vector3: ["HAS_NORMAL"] } - domain = "pixel" - } - - "ad5e052f-d316-4a0f-8b79-53c38204d61b" = { - is_required = false - name = "metallic" - display_name = "Metallic" - type = { scalar: ["HAS_METALLIC"] } - domain = "pixel" - } - - "36ba46d2-f6ea-4e60-a428-fdc17c75bc62" = { - is_required = false - name = "roughness" - display_name = "Roughness" - type = { scalar: ["HAS_ROUGHNESS"] } - domain = "pixel" - } - - "1164a5ef-4563-4795-b3b5-42825d6df037" = { - is_required = false - name = "emissive" - display_name = "Emissive" - type = { vector3: ["HAS_EMISSIVE" ] } - domain = "pixel" - } - - "59fd1cf4-f736-470d-8510-1dd7c016639e" = { - is_required = false - name = "ambient_occlusion" - display_name = "Ambient Occlusion" - type = { scalar: ["HAS_AMBIENT_OCCLUSION"] } - domain = "pixel" - } -} - -options = { - "b2c7c0d2-beff-4b1a-a9d4-068a507625a2" = "USE_FBX_PERMUTATIONS" - "d1a42a54-0794-4d57-9aa0-eb35acb6b35c" = "INSTANCED" - "8df1b8f7-17c2-4ae4-8c4e-25517ec1df46" = "CULL_NONE" - "c198c109-2cdf-49ee-af18-a982c23e2729" = "CULL_FRONT" - "34994d84-9d51-48ac-af85-bc053b2c65c3" = "SKIN" - "2b136447-676e-4943-997b-04a28ae68497" = "WORLD_SPACE_NORMAL" - "dd7fcf97-0627-48ab-b29a-95b5685bb123" = "TRANSPARENT" - "3b55d6c6-4398-4dbc-b9ef-570aff8696ae" = "TRANSPARENT_FADE" -} - -ui = [ - { - type = "drop_down" - display_name = "Normals In" - options = { - "Tangent Space" = "00000000-0000-0000-0000-000000000000" - "World Space" = "2b136447-676e-4943-997b-04a28ae68497" - } - default = "00000000-0000-0000-0000-000000000000" - } - { - type = "drop_down" - display_name = "Blend Mode" - options = { - "Opaque" = "00000000-0000-0000-0000-000000000000" - "Transparent" = "dd7fcf97-0627-48ab-b29a-95b5685bb123" - "Transparent Fade" = "3b55d6c6-4398-4dbc-b9ef-570aff8696ae" - } - default = "00000000-0000-0000-0000-000000000000" - } - { - type = "drop_down" - display_name = "Face Culling" - options = { - "Back" = "00000000-0000-0000-0000-000000000000" - "Front" = "c198c109-2cdf-49ee-af18-a982c23e2729" - "None" = "8df1b8f7-17c2-4ae4-8c4e-25517ec1df46" - } - default = "00000000-0000-0000-0000-000000000000" - } - { type = "checkbox" display_name = "Instancing" option = "d1a42a54-0794-4d57-9aa0-eb35acb6b35c" } -] - -render_state = { - culling_base = { - inherit: ["core/stingray_renderer/shader_libraries/common#default"] - state: { - "defined(CULL_NONE)" = { - cull_mode = "cull_none" - } - "defined(CULL_FRONT)" = { - cull_mode = "cull_ccw" - } - "!defined(CULL_NONE) && !defined(CULL_FRONT)" = { - cull_mode = "cull_cw" - } - } - } - - gbuffer_material = { - inherit: ["culling_base"] - state: { - } - } - - emissive = { - inherit: ["culling_base"] - state: { - z_func = "less_equal" - blend_enable = "true" - blend_op = "blend_op_add" - dest_blend = "blend_one" - src_blend = "blend_one" - } - } - - transparent = { - inherit: ["culling_base"] - state : { - z_write_enable = "false" - blend_enable = "true" - blend_op = "blend_op_add" - dest_blend = "blend_inv_src_alpha" - "defined(TRANSPARENT)" = { - src_blend = "blend_one" - } - "defined(TRANSPARENT_FADE)" = { - src_blend = "blend_src_alpha" - } - } - } - - wireframe = { - inherit: ["transparent"] - state: { - fill_mode = "fill_wireframe" - src_blend = "blend_src_alpha" - "on_renderer(D3D11, D3D12)" = { - depth_bias = "-1" - depth_bias_clamp = "-0.00015" - slope_scale_depth_bias = "-2.0" - } - } - } - - depth_only = { - inherit: ["culling_base"] - state: { - write_mask0 = "0x0" - write_mask1 = "0x0" - write_mask2 = "0x0" - write_mask3 = "0x0" - } - } - - shadow_caster = { - inherit: ["depth_only"] - state: { - "on_renderer(D3D11, D3D12)" = { - depth_bias = "0xff" - slope_scale_depth_bias = "1.0" - } - "on_renderer(GL)" = { - offset_factor = "1.0" - offset_units = "1024.0" - depth_bias_enable = "true" - } - } - } - - material_transfer = { - inherit: ["core/stingray_renderer/shader_libraries/common#default"] - state: { - cull_mode = "cull_none" - z_write_enable = "false" - z_enable = "false" - } - } -} - -sampler_state = { - shadow_map = { - inherit: ["core/stingray_renderer/shader_libraries/common#clamp_point"] - states = { - "on_renderer(D3D11, D3D12)" = { - comparison_func = "less" - filter = "comparison_min_mag_linear_mip_point" - } - "on_renderer(GNM)" = { - comparison_func = "less" - filter = "min_mag_mip_linear" - - } - "on_renderer(GL)" = { - comparison_func = "less" - filter = "min_mag_linear" - } - } - } -} - -channels = { - "(defined(HAS_NORMAL) && !defined(WORLD_SPACE_NORMAL)) || defined(NEEDS_TANGENT_SPACE)": { - vertex_tangent = { type = "float3" semantic = "TANGENT" domain = "vertex" } - vertex_binormal = { type = "float3" semantic = "BINORMAL" domain = "vertex" } - - tsm0 = { type = "float3" domains = ["vertex", "pixel"] } - tsm1 = { type = "float3" domains = ["vertex", "pixel"] } - tsm2 = { type = "float3" domains = ["vertex", "pixel"] } - } - - "defined(NEEDS_EYE_VECTOR)": { - eye_vector = { type = "float3" domain = "vertex" } - } - - "!defined(HAS_NORMAL) || defined(NEEDS_WORLD_SPACE_NORMAL)": { - world_space_normal = { type = "float3" domains = ["vertex", "pixel"] } - } - - "defined(MOTION_BLUR)": { - last_clip_position = { type = "float3" domains = ["vertex", "pixel"] } - } - - vertex_position = { type = "float4" domain = "vertex" } - vertex_normal = { type = "float3" semantic = "NORMAL" domain = "vertex" } - - "defined(HAS_VERTEX_BAKED_DIFFUSE_LIGHTING)": { - vertex_color1 = { type = "float4" semantic = "COLOR1" domains = ["vertex"] } - baked_light = { type = "float3" domains = ["vertex", "pixel"] } - } - - "defined(HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING)": { - lightmap_uv_input = { type = "float2" semantic="TEXCOORD1" domains = ["vertex"] } - lightmap_uv = { type = "float2" domains = ["vertex", "pixel"] } - } - - "defined(MATERIAL_TRANSFER)": { - lightmap_uv = { type = "float2" semantic="TEXCOORD1" domains = ["vertex"] } - } - - "defined(TRANSPARENT) || defined(TRANSPARENT_FADE)": { - world_pos = { type = "float3" domains = ["vertex", "pixel"] } - } -} - -//log_permutations = true -permutation_sets = { - vertex_modifiers = [ - { if: "num_skin_weights() == 4" define: { "macros": ["SKINNED_4WEIGHTS"] stages: ["vertex"] } } - { if: "num_skin_weights() == 3" define: { "macros": ["SKINNED_3WEIGHTS"] stages: ["vertex"] } } - { if: "num_skin_weights() == 2" define: { "macros": ["SKINNED_2WEIGHTS"] stages: ["vertex"] } } - { if: "num_skin_weights() == 1" define: { "macros": ["SKINNED_1WEIGHT"] stages: ["vertex"] } } - { default = true } - ] - - instanced_modifiers = [ - { if: "mesh_baked_lighting_type() == lightmap" define: ["HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING"] } - { default = true } - ] - - lightmap_modifiers = [ - { if: "lightmap_format() == directional_irradiance" define: ["HAS_DIRECTIONAL_LIGHTMAPS"] } - { default = true } - ] - - non_instanced_modifiers = [ - { if: "mesh_baked_lighting_type() == lightmap" define: ["HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING"] permute_with: "lightmap_modifiers" } - { if: "mesh_baked_lighting_type() == vertex" define: ["HAS_VERTEX_BAKED_DIFFUSE_LIGHTING"] } - { permute_with: "vertex_modifiers" } - ] - - instanced_and_non_instanced = [ - { if: "defined(INSTANCED)" permute_with: "instanced_modifiers" } - { if: "!defined(INSTANCED)" permute_with: "non_instanced_modifiers" } - ] - - default = [ - // FBX Standard material exclusive permutations, these will only compile of the - // 'USE_FBX_PERMUTATIONS' option is set, which it is in the shader used for imported fbx files. - { if: "defined(USE_FBX_PERMUTATIONS)" permute_with: [ - { if: "is_any_material_variable_set(use_emissive_map, emissive)" define: ["FBX_EMISSIVE"] permute_with: "instanced_and_non_instanced" } - ] } - - // Normal default permutation set - { permute_with: "instanced_and_non_instanced" } - ] - - shadow_caster = [ - { if: "defined(INSTANCED)" } - { if: "!defined(INSTANCED)" permute_with: "vertex_modifiers" } - ] -} - -shader_contexts = { - shadow_caster = { - passes_sort_mode = "immediate" - compile_with = [ - { if: "on_renderer(D3D11, D3D12, GNM, GL)" permute_with: "shadow_caster" } - ] - - passes = [ - { code_block="depth_only" render_state="shadow_caster" } - ] - } - - material_transfer = { - passes_sort_mode = "immediate" - compile_with = [ - { if: "on_renderer(D3D11, D3D12)" } - ] - - passes = [ - { code_block="gbuffer_base" defines=["MATERIAL_TRANSFER"] render_state="material_transfer" } - ] - } - - default = { - passes_sort_mode = "deferred" - compile_with = [ - { if: "on_renderer(D3D11, D3D12, GNM, GL)" permute_with: [ - { permute_with: "default" } - ] } - ] - - passes = [ - { if: "defined(TRANSPARENT) || defined(TRANSPARENT_FADE)" then: [ - { layer="hdr_transparent" code_block="gbuffer_base" render_state="transparent" } - ] else: [ - { layer="gbuffer" code_block="gbuffer_base" defines="MOTION_BLUR" render_state="gbuffer_material" } - - // This bit of logic is a bit complicated. The gist of it is that we want to disable this pass - // for materials that has a value connected on emissive for all permutations, but should have it - // discarded for all but the special permutations with the define FBX_EMISSIVE - { if: "defined(HAS_EMISSIVE) && (!defined(USE_FBX_PERMUTATIONS) || defined(FBX_EMISSIVE))" then: [ - { layer="emissive" code_block="gbuffer_base" defines={ macros: ["EMISSIVE_PASS"] stages: ["pixel"] } render_state="emissive" } - ]} - ]} - { if: "!on_renderer(GL)" then: [ - { layer="wireframe" code_block="depth_only" define="DRAW_WIREFRAME" render_state="wireframe" branch_key="dev_wireframe" } - ]} - ] - } -} - -code_blocks = { - gbuffer_base = { - include:[ - "core/stingray_renderer/shader_libraries/common#common", - "core/stingray_renderer/shader_libraries/common#gbuffer_access", - "core/stingray_renderer/shader_libraries/common#skinning", - "core/stingray_renderer/shader_libraries/common#taa_offsets", - "core/stingray_renderer/shader_libraries/lighting_common#brdf", - "core/stingray_renderer/shader_libraries/common#fog", - "core/stingray_renderer/shader_libraries/shadow_map_common#shadow_bias"] - - instance_data = { - "on_renderer(D3D11, D3D12) && !defined(MATERIAL_TRANSFER) && defined(INSTANCED)": { - world = { type = "matrix4x4" } - "defined(MOTION_BLUR)": { - last_world = { type = "matrix4x4" } - } - } - } - - stage_conditions = { - tessellation_control = "defined(DX11_DISPLACEMENT_MAPPING)" - } - - samplers = { - global_diffuse_map = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "global_diffuse_map" - type = "cube" - } - lightmap = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "lightmap" - type = "2d" - } - lightmap_ambient_term = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "lightmap_ambient_term" - type = "2d" - } - lightmap_directional_term = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "lightmap_directional_term" - type = "2d" - } - lightmap_dominant_direction = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "lightmap_dominant_direction" - type = "2d" - } - global_specular_map = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "global_specular_map" - type = "cube" - } - brdf_lut = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "brdf_lut" - type = "2d" - } - shadow_map_sampler = { - sampler_state = "core/stingray_renderer/shader_libraries/shadow_map_common#shadow_map" - slot_name = "shadow_map_sampler" - type = "2d" - } - - "!defined(DX10_STYLE_SAMPLERS)": { - sun_shadow_map = { - sampler_state = "shadow_map" - slot_name = "sun_shadow_map" - type = "2d" - } - } - } - - code = { - glsl = """ - #if (!defined(HAS_NORMAL) || defined(NEEDS_WORLD_SPACE_NORMAL)) || defined(NEEDS_EYE_VECTOR) || defined(HAS_VERTEX_OFFSET) - #define NEEDS_WORLD_SPACE_POSITION - #endif - - #if defined(HAS_NORMAL) && !defined(WORLD_SPACE_NORMAL) - #define NEEDS_TANGENT_SPACE - #endif - - CBUFFER_START(c_per_object) - UNIFORM mat4 world_view_proj; - #if defined(NEEDS_WORLD_SPACE_POSITION) || defined(NEEDS_TANGENT_SPACE) || defined(NEEDS_WORLD_POSE) - UNIFORM mat4 world; - #if defined(NEEDS_WORLD_SPACE_POSITION) - UNIFORM mat4 view_proj; - #endif - #endif - #if defined(NEEDS_INVERSE_WORLD_POSE) - UNIFORM mat4 inv_world; - #endif - #if defined(HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING) - #if defined(HAS_DIRECTIONAL_LIGHTMAPS) - UNIFORM vec2 lightmap_ambient_term_uv_scale; - UNIFORM vec2 lightmap_ambient_term_uv_offset; - #else - UNIFORM vec2 lightmap_uv_scale; - UNIFORM vec2 lightmap_uv_offset; - #endif - #endif - CBUFFER_END - - #if defined(TRANSPARENT) || defined(TRANSPARENT_FADE) - CBUFFER_START(clustered_shading_data) - UNIFORM vec3 baked_diffuse_tint; - UNIFORM vec3 reflections_tint; - UNIFORM mat4 sun_world_to_shadow_slice0; - UNIFORM mat4 sun_world_to_shadow_slice1; - UNIFORM mat4 sun_world_to_shadow_slice2; - UNIFORM mat4 sun_world_to_shadow_slice3; - UNIFORM vec4 sphere_slice0; - UNIFORM vec4 sphere_slice1; - UNIFORM vec4 sphere_slice2; - UNIFORM vec4 sphere_slice3; - CBUFFER_END - - DECLARE_SAMPLER_CUBE(global_specular_map); - DECLARE_SAMPLER_2D(brdf_lut); - - uniform highp sampler2DShadow sun_shadow_map; - - float sun_shadow_intensity(float3 world_pos, float3 shadow_biased_pos) { - float3 wp_to_sphere0 = world_pos - sphere_slice0.xyz; - float dist_to_sphere0 = dot(wp_to_sphere0, wp_to_sphere0); - - float3 wp_to_sphere1 = world_pos - sphere_slice1.xyz; - float dist_to_sphere1 = dot(wp_to_sphere1, wp_to_sphere1); - - float3 wp_to_sphere2 = world_pos - sphere_slice2.xyz; - float dist_to_sphere2 = dot(wp_to_sphere2, wp_to_sphere2); - - float3 wp_to_sphere3 = world_pos - sphere_slice3.xyz; - float dist_to_sphere3 = dot(wp_to_sphere3, wp_to_sphere3); - - float4x4 world_to_sm; - if (dist_to_sphere0 <= sphere_slice0.w) - world_to_sm = sun_world_to_shadow_slice0; - else if (dist_to_sphere1 <= sphere_slice1.w) - world_to_sm = sun_world_to_shadow_slice1; - else if (dist_to_sphere2 <= sphere_slice2.w) - world_to_sm = sun_world_to_shadow_slice2; - else if (dist_to_sphere3 <= sphere_slice3.w) - world_to_sm = sun_world_to_shadow_slice3; - else - return 1.0; - - float4 sm_pos = mul(float4(shadow_biased_pos, 1.0), world_to_sm); - vec2 inv_size = vec2(1.f) / vec2(textureSize(sun_shadow_map, 0)); - vec4 scale = vec4(inv_size, 0.f, 0.f); - - highp float shadow = - textureProj(sun_shadow_map, sm_pos + vec4(-0.5, 0.5, 0, 0) * scale) - + textureProj(sun_shadow_map, sm_pos + vec4(0.5, 0.5, 0, 0) * scale) - + textureProj(sun_shadow_map, sm_pos + vec4(0.5, -0.5, 0, 0) * scale) - + textureProj(sun_shadow_map, sm_pos + vec4(-0.5, -0.5, 0, 0) * scale); - - return shadow * 0.25; - } - - void sun_lighting(float3 world_pos, float3 shadow_biased_pos, float3 N, float3 V, float roughness, float3 ambient, float3 diffuse_color, float3 specular_color, inout float3 acc_diff, inout float3 acc_spec) { - float3 L = normalize(-sun_direction); - float2 scale_bias = TEX2D(brdf_lut, float2(saturate(dot(N, V)), 1.0 - roughness)).xy; - - float mipmap_index = roughness * 7.0; - acc_diff += ambient * baked_diffuse_tint * diffuse_color; - acc_spec += rgbm_decode(TEXCUBELOD(global_specular_map, reflect(-V, N), mipmap_index)) * (specular_color * scale_bias.x + scale_bias.y) * reflections_tint; - - float shadow_intensity = saturate(sun_shadow_intensity(world_pos, shadow_biased_pos)); - bsdf(L, V, N, sun_color, diffuse_color, specular_color, roughness, shadow_intensity, acc_diff, acc_spec); - } - #endif - - #if defined(STAGE_VERTEX) - layout(location = POSITION0) in vec4 in_position; - - void main() { - GraphManualChannels params; - GraphResults graph; - - #if defined(SKINNED) - vec4 p = vec4(skin_point(in_position, blendindices, blendweights), 1); - mediump vec3 n = skin_vector(GRAPH_DATA(vertex_normal).xyz, blendindices, blendweights); - #if defined(NEEDS_TANGENT_SPACE) - mediump vec3 t = skin_vector(GRAPH_DATA(vertex_tangent).xyz, blendindices, blendweights); - mediump vec3 b = skin_vector(GRAPH_DATA(vertex_binormal).xyz, blendindices, blendweights); - #endif - #else - vec4 p = in_position; - mediump vec3 n = GRAPH_DATA(vertex_normal); - #if defined(NEEDS_TANGENT_SPACE) - mediump vec3 t = GRAPH_DATA(vertex_tangent); - mediump vec3 b = GRAPH_DATA(vertex_binormal); - #endif - #endif - - #if !defined(HAS_NORMAL) || defined(NEEDS_WORLD_SPACE_NORMAL) - GRAPH_PARAM(params, world_space_normal) = n * mat3(world); - #endif - - GRAPH_PARAM(params, vertex_position) = p; - - #if defined(NEEDS_WORLD_SPACE_POSITION) || defined(TRANSPARENT) || defined(TRANSPARENT_FADE) - vec4 wp = p * world; - #if defined(TRANSPARENT) || defined(TRANSPARENT_FADE) - GRAPH_PARAM(params, world_pos) = wp.xyz; - #endif - #endif - - #if defined(NEEDS_TANGENT_SPACE) - tspace_transform_transpose( - GRAPH_PARAM(params, tsm0), - GRAPH_PARAM(params, tsm1), - GRAPH_PARAM(params, tsm2), - t, b, n, - mat3(world)); - #endif - - #if defined(NEEDS_EYE_VECTOR) - GRAPH_PARAM(params, eye_vector) = camera_pos - wp.rgb; - #endif - - #if defined(HAS_VERTEX_BAKED_DIFFUSE_LIGHTING) - GRAPH_PARAM(params, baked_light) = rgbm_decode(decode_vertex_color(GRAPH_DATA(vertex_color1))); - #elif defined(HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING) - mediump vec2 light_uv_in = GRAPH_DATA(lightmap_uv_input); - light_uv_in.y = 1.0 - light_uv_in.y; - - #if defined(HAS_DIRECTIONAL_LIGHTMAPS) - mediump vec2 luv = light_uv_in*lightmap_ambient_term_uv_scale + lightmap_ambient_term_uv_offset; - #else - mediump vec2 luv = light_uv_in*lightmap_uv_scale + lightmap_uv_offset; - #endif - - luv.y = 1.0 - luv.y; - GRAPH_PARAM(params, lightmap_uv) = luv; - #endif - - graph_evaluate(graph, params); - - #if defined(NEEDS_WORLD_SPACE_POSITION) - #if defined(HAS_VERTEX_OFFSET) - wp.xyz += graph.vertex_offset; - #endif - gl_Position = wp * view_proj; - #else - gl_Position = p * world_view_proj; - #endif - } - #elif defined(STAGE_FRAGMENT) - #if defined(EMISSIVE_PASS) - layout(location = 0) out mediump vec4 out_color; - - void main() { - GraphManualChannels params; - GraphResults graph; - graph_evaluate(graph, params); - - #if defined(EMISSIVE_PASS) - #if defined(HAS_OPACITY) - #if defined(HAS_OPACITY_THRESHOLD) - float threshold = graph.opacity_threshold; - #else - float threshold = 0.5f; - #endif - if (graph.opacity < threshold) - discard; - #endif - out_color = vec4(graph.emissive, 0); - #endif - } - #else - #if defined(TRANSPARENT) || defined(TRANSPARENT_FADE) - layout(location = 0) out mediump vec4 out_color; - #else - GBUFFER_OUTPUT; - #endif - - #if defined(HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING) - #if defined(HAS_DIRECTIONAL_LIGHTMAPS) - DECLARE_SAMPLER_2D(lightmap_ambient_term); - DECLARE_SAMPLER_2D(lightmap_directional_term); - DECLARE_SAMPLER_2D(lightmap_dominant_direction); - #else - DECLARE_SAMPLER_2D(lightmap); - #endif - #endif - - DECLARE_SAMPLER_CUBE(global_diffuse_map); - - void main() { - GraphManualChannels params; - GraphResults graph; - graph_evaluate(graph, params); - - #if defined(HAS_OPACITY) && !defined(TRANSPARENT) && !defined(TRANSPARENT_FADE) - #if defined(HAS_OPACITY_THRESHOLD) - float threshold = graph.opacity_threshold; - #else - float threshold = 0.5; - #endif - if (graph.opacity < threshold) - discard; - #endif - - // Base color - lowp vec3 base_color = vec3(0); - #if defined(HAS_BASE_COLOR) - base_color = graph.base_color; - #else - base_color = vec3(0.5, 0.5, 0.5); - #endif - - // World space normal - #if defined(HAS_NORMAL) - #if defined(WORLD_SPACE_NORMAL) - mediump vec3 wn = normalize(graph.normal); - #if defined(CULL_NONE) || defined(CULL_FRONT) - wn = gl_FrontFacing ? wn : -wn; - #endif - #else - float3 tsm0 = GRAPH_DATA(tsm0).xyz; - float3 tsm1 = GRAPH_DATA(tsm1).xyz; - float3 tsm2 = GRAPH_DATA(tsm2).xyz; - #if defined(CULL_NONE) || defined(CULL_FRONT) - if (!gl_FrontFacing) { - tsm0.z = -tsm0.z; - tsm1.z = -tsm1.z; - tsm2.z = -tsm2.z; - } - #endif - mediump vec3 wn = rotate_vector3(graph.normal, tsm0, tsm1, tsm2); - #endif - #else - mediump vec3 wn = normalize(GRAPH_DATA(world_space_normal)); - #if defined(CULL_NONE) || defined(CULL_FRONT) - wn = gl_FrontFacing ? wn : -wn; - #endif - #endif - - // Metallic - lowp float metallic = 0.0; - #if defined(HAS_METALLIC) - metallic = graph.metallic; - #else - metallic = 0.0; - #endif - - // Roughness - half roughness = 0.0; - #if defined(HAS_ROUGHNESS) - roughness = max(graph.roughness, 1.f / 255.f); - #else - roughness = 0.5; - #endif - - // Ambient Diffuse - mediump vec3 ambient = vec3(0.0, 0.0, 0.0); - #if defined(HAS_VERTEX_BAKED_DIFFUSE_LIGHTING) - ambient = GRAPH_DATA(baked_light); - #elif defined(HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING) - #if defined(HAS_DIRECTIONAL_LIGHTMAPS) - ambient = TEX2D(lightmap_ambient_term, GRAPH_DATA(lightmap_uv)).rgb; - mediump vec3 dd = TEX2D(lightmap_dominant_direction, GRAPH_DATA(lightmap_uv)).rgb * 2.0 - vec3(1.0); - ambient += TEX2D(lightmap_directional_term, GRAPH_DATA(lightmap_uv)).rgb * max(0.0, dot(dd, wn)); - #else - ambient = TEX2D(lightmap, GRAPH_DATA(lightmap_uv)).rgb; - #endif - #else - ambient = gbuffer_decode_ambient_diffuse_light(TEXCUBELOD(global_diffuse_map, wn, 0.0)); - #endif - - #if !defined(TRANSPARENT) && !defined(TRANSPARENT_FADE) - out_base_color = gbuffer_encode_base_color(base_color); - out_normal = gbuffer_encode_normal(wn); - out_metallic = gbuffer_encode_metallic_mask(metallic); - out_roughness = gbuffer_encode_roughness(roughness); - out_ambient_occlusion = gbuffer_encode_ambient_occlusion(1.0); - out_ambient_diffuse_light = gbuffer_encode_ambient_diffuse_light(ambient); - #else - #if defined(HAS_OPACITY) - half opacity = graph.opacity; - #else - half opacity = 0.5; - #endif - - float3 world_pos = GRAPH_DATA(world_pos); - float3 view_dir = float3(camera_world[0].w, camera_world[1].w, camera_world[2].w) - world_pos; - - float3 V = normalize(view_dir); - float3 N = normalize(wn); - - // 0.04 is taken as a common value for dielectrics. Source: Real-time rendering 3rd edition. - float3 specular_color = lerp(new_half3(0.04, 0.04, 0.04), base_color, metallic); - float3 diffuse_color = lerp(base_color, new_half3(0.0, 0.0, 0.0), metallic); - - float3 camera_dir = float3(camera_world[0].y, camera_world[1].y, camera_world[2].y); - float depth = dot(-view_dir, camera_dir); - float3 shadow_biased_pos = world_pos - (depth - apply_shadow_bias(depth)) * (-V); - - float3 acc_diff = new_half3(0.0, 0.0, 0.0); - float3 acc_spec = new_half3(0.0, 0.0, 0.0); - sun_lighting(world_pos, shadow_biased_pos, N, V, roughness, ambient, diffuse_color, specular_color, acc_diff, acc_spec); - - #if defined(TRANSPARENT) - float3 accumulated_color = acc_diff * opacity + acc_spec; - #else - float3 accumulated_color = acc_diff + acc_spec; - #endif - - out_color = apply_fog(new_half4_xyz(accumulated_color, opacity), world_pos, depth); - #endif - } - #endif - #endif - """ - - hlsl = """ - // We need to disable instancing for the material transfer context as it doesn't use the world transform. - #if defined(INSTANCED) && defined(MATERIAL_TRANSFER) - #undef INSTANCED - #endif - - #if defined(PS_NEEDS_WP) || defined(NEEDS_EYE_VECTOR) || defined(HAS_VERTEX_OFFSET) || ((defined(RENDERER_D3D11) || defined(RENDERER_D3D12)) && defined(INSTANCED)) - #define NEEDS_WORLD_SPACE_POSITION - #endif - - #if defined(HAS_NORMAL) && !defined(WORLD_SPACE_NORMAL) - #define NEEDS_TANGENT_SPACE - #endif - - #if defined(HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING) - #if defined(HAS_DIRECTIONAL_LIGHTMAPS) - DECLARE_SAMPLER_2D(lightmap_ambient_term); - DECLARE_SAMPLER_2D(lightmap_directional_term); - DECLARE_SAMPLER_2D(lightmap_dominant_direction); - #else - DECLARE_SAMPLER_2D(lightmap); - #endif - #endif - - DECLARE_SAMPLER_CUBE(global_diffuse_map); - - struct VS_INPUT { - float4 position : POSITION; - SKIN_INPUT - GRAPH_VERTEX_INPUT - }; - - struct PS_INPUT { - float4 position : SV_POSITION; - GRAPH_PIXEL_INPUT - }; - - CBUFFER_START(c_per_object) - #if defined(NEEDS_WORLD_SPACE_POSITION) - float4x4 view_proj; - #else - float4x4 world_view_proj; - #endif - float4x4 world; - #if defined(NEEDS_INVERSE_WORLD_POSE) - float4x4 inv_world; - #endif - float4x4 last_world; - - #if defined(HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING) - #if defined(HAS_DIRECTIONAL_LIGHTMAPS) - float2 lightmap_ambient_term_uv_scale; - float2 lightmap_ambient_term_uv_offset; - #else - float2 lightmap_uv_scale; - float2 lightmap_uv_offset; - #endif - #endif - - GRAPH_MATERIAL_EXPORTS - CBUFFER_END - - #if defined(TRANSPARENT) || defined(TRANSPARENT_FADE) - CBUFFER_START(clustered_shading_data) - float4x4 cs_world_to_shadow_maps[64]; - float3 baked_diffuse_tint; - float3 reflections_tint; - float4x4 sun_world_to_shadow_slice0; - float4x4 sun_world_to_shadow_slice1; - float4x4 sun_world_to_shadow_slice2; - float4x4 sun_world_to_shadow_slice3; - float4 sphere_slice0; - float4 sphere_slice1; - float4 sphere_slice2; - float4 sphere_slice3; - float4 cs_cluster_size_in_pixels; - float4 cs_lights_data[1024]; - CBUFFER_END - - #if defined(RENDERER_D3D11) || defined(RENDERER_D3D12) || defined(RENDERER_GNM) - Texture3D cluster_texture; - Texture2D light_index_texture; - - SamplerComparisonState shadow_map_sampler; - Texture2D sun_shadow_map; - Texture2D local_lights_shadow_atlas; - #endif - DECLARE_SAMPLER_CUBE(global_specular_map); - DECLARE_SAMPLER_2D(brdf_lut); - #endif - - #if defined(INSTANCED) && (defined(RENDERER_D3D11) || defined(RENDERER_D3D12)) - Buffer idata; - float ioffset; - #endif - - PS_INPUT vs_main(VS_INPUT input - #if defined(INSTANCED) && (defined(RENDERER_D3D11) || defined(RENDERER_D3D12)) - , uint instance_id : SV_InstanceId - #endif - ) - { - PS_INPUT o; - float4 p; - - GraphVertexParams params; - GraphVertexResults results; - - #if defined(INSTANCED) && (defined(RENDERER_D3D11) || defined(RENDERER_D3D12)) - uint offset = (uint)ioffset + instance_id*IDATA_STRIDE; - world[0] = idata.Load(offset + IDATA_world + 0); - world[1] = idata.Load(offset + IDATA_world + 1); - world[2] = idata.Load(offset + IDATA_world + 2); - world[3] = idata.Load(offset + IDATA_world + 3); - - #if defined(MOTION_BLUR) - last_world[0] = idata.Load(offset + IDATA_last_world + 0); - last_world[1] = idata.Load(offset + IDATA_last_world + 1); - last_world[2] = idata.Load(offset + IDATA_last_world + 2); - last_world[3] = idata.Load(offset + IDATA_last_world + 3); - #endif - #endif - - // Write automatic params - GRAPH_VERTEX_WRITE_PARAMS(params, input); - - // Write output channels - #if defined(SKINNED) - float4 position = float4(skin_point(input.position, input.blendindices, input.blendweights), 1); - #if defined(MOTION_BLUR) - float4 last_position = float4(skin_point_last_frame(input.position, input.blendindices, input.blendweights), 1); - #endif - float3 normal = skin_vector(GRAPH_VERTEX_DATA(input, vertex_normal).xyz, input.blendindices, input.blendweights); - #if defined(NEEDS_TANGENT_SPACE) - float3 tangent = skin_vector(GRAPH_VERTEX_DATA(input, vertex_tangent).xyz, input.blendindices, input.blendweights); - float3 binormal = skin_vector(GRAPH_VERTEX_DATA(input, vertex_binormal).xyz, input.blendindices, input.blendweights); - #endif - #else - float4 position = input.position; - #if defined(MOTION_BLUR) - float4 last_position = position; - #endif - float3 normal = GRAPH_VERTEX_DATA(input, vertex_normal).xyz; - #if defined(NEEDS_TANGENT_SPACE) - float3 tangent = GRAPH_VERTEX_DATA(input, vertex_tangent).xyz; - float3 binormal = GRAPH_VERTEX_DATA(input, vertex_binormal).xyz; - #endif - #endif - - #if defined(NEEDS_WORLD_SPACE_POSITION) || defined(TRANSPARENT) || defined(TRANSPARENT_FADE) - float4 wp = mul(position, world); - // TODO: Expose output channel here - #if defined(TRANSPARENT) || defined(TRANSPARENT_FADE) - GRAPH_VERTEX_PARAM(params, world_pos) = wp.xyz; - #endif - #endif - - GRAPH_VERTEX_PARAM(params, vertex_position) = position; - - #if !defined(HAS_NORMAL) || defined(NEEDS_WORLD_SPACE_NORMAL) - GRAPH_VERTEX_PARAM(params, world_space_normal).rgb = mul(normal, (float3x3)world); - #endif - - #if defined(NEEDS_EYE_VECTOR) - GRAPH_VERTEX_PARAM(params, eye_vector).rgb = camera_pos - wp.rgb; - #endif - - #if defined(NEEDS_TANGENT_SPACE) - tspace_transform_transpose( - GRAPH_VERTEX_PARAM(params, tsm0), - GRAPH_VERTEX_PARAM(params, tsm1), - GRAPH_VERTEX_PARAM(params, tsm2), - tangent, binormal, normal, - (float3x3)world); - #endif - - #if defined(HAS_VERTEX_BAKED_DIFFUSE_LIGHTING) - GRAPH_VERTEX_PARAM(params, baked_light) = rgbm_decode(decode_vertex_color(GRAPH_VERTEX_DATA(input, vertex_color1))); - #endif - - // Evaluate all pieces of the graph that should run per-vertex. - GRAPH_EVALUATE_VERTEX(results, params); - - #if defined(NEEDS_WORLD_SPACE_POSITION) - #if defined(HAS_VERTEX_OFFSET) - wp += float4(results.vertex_offset, 0); - #endif - p = mul(wp, view_proj); - #else - p = mul(position, world_view_proj); - #endif - - #if defined(MOTION_BLUR) - GRAPH_VERTEX_PARAM(params, last_clip_position) = float3(0.0, 0.0, 0.0); - #if defined(NEEDS_WORLD_SPACE_POSITION) - float4 cur_wp = wp; - float4 last_wp = mul(last_position, last_world); - - #if defined(HAS_VERTEX_OFFSET) - // TODO: Add _last_ position offset here to support vertex animation. - // The way it works now will only yield correct results of the offset is constant - last_wp += float4(results.vertex_offset, 0); - #endif - #else - float4 cur_wp = mul(position, last_world); - float4 last_wp = mul(last_position, last_world); - #endif - float4 last_clip_pos = mul(last_wp, camera_last_view_projection); - float4 last_view_space = last_clip_pos / last_clip_pos.w; - last_view_space.xy += get_vs_halton_offset(frame_number); - last_clip_pos = last_view_space * last_clip_pos.w; - GRAPH_VERTEX_PARAM(params, last_clip_position) = last_clip_pos.xyw; - #endif - - #if defined(MATERIAL_TRANSFER) - float2 unwrapped_uv = GRAPH_VERTEX_DATA(input, lightmap_uv); - float2 ndc = float2(unwrapped_uv.x, unwrapped_uv.y) * 2 - 1; - ndc.y *= -1; - p = float4(ndc, 0, 1); - #endif - - #if defined(HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING) - #if defined(HAS_DIRECTIONAL_LIGHTMAPS) - GRAPH_VERTEX_PARAM(params, lightmap_uv) = GRAPH_VERTEX_DATA(input, lightmap_uv_input)*lightmap_ambient_term_uv_scale + lightmap_ambient_term_uv_offset; - #else - GRAPH_VERTEX_PARAM(params, lightmap_uv) = GRAPH_VERTEX_DATA(input, lightmap_uv_input)*lightmap_uv_scale + lightmap_uv_offset; - #endif - #endif - - #if defined(MATERIAL_TRANSFER) - o.position = p; - #else - float4 view_space = p / p.w; - view_space.xy += get_vs_halton_offset(frame_number); - o.position = view_space * p.w; - #endif - - // Write results - GRAPH_VERTEX_WRITE(o, results, params); - - return o; - } - - #if defined(MATERIAL_TRANSFER) - struct MATERIAL_TRANSFER_OUT { - float4 albedo_op : SV_TARGET0; - float4 emissive : SV_TARGET1; - }; - - MATERIAL_TRANSFER_OUT ps_main(PS_INPUT input) : SV_TARGET0 - { - GraphPixelParams params; - GraphPixelResults graph; - - GRAPH_PIXEL_WRITE_PARAMS(params, input); - GRAPH_EVALUATE_PIXEL(graph, params); - - MATERIAL_TRANSFER_OUT o; - - #if defined(HAS_BASE_COLOR) - o.albedo_op = float4(graph.base_color, 0); - #else - o.albedo_op = float4(0.5, 0.5, 0.5, 0); - #endif - #if defined(HAS_EMISSIVE) - o.emissive = float4(graph.emissive, 1.0); - #else - o.emissive = float4(0.0, 0.0, 0.0, 0.0); - #endif - - return o; - } - #elif defined(EMISSIVE_PASS) - float4 ps_main(PS_INPUT input) : SV_TARGET0 - { - GraphPixelParams params; - GraphPixelResults graph; - - GRAPH_PIXEL_WRITE_PARAMS(params, input); - GRAPH_EVALUATE_PIXEL(graph, params); - - #if defined(EMISSIVE_PASS) - #if defined(HAS_OPACITY) - #if defined(HAS_OPACITY_THRESHOLD) - float threshold = graph.opacity_threshold; - #else - float threshold = 0.5f; - #endif - if (graph.opacity < threshold) - discard; - #endif - return float4(graph.emissive, 0); - #endif - } - #else - #if defined(TRANSPARENT) || defined(TRANSPARENT_FADE) - float sun_shadow_intensity(float3 world_pos, float3 shadow_biased_pos) { - float3 wp_to_sphere0 = world_pos - sphere_slice0.xyz; - float dist_to_sphere0 = dot(wp_to_sphere0, wp_to_sphere0); - - float3 wp_to_sphere1 = world_pos - sphere_slice1.xyz; - float dist_to_sphere1 = dot(wp_to_sphere1, wp_to_sphere1); - - float3 wp_to_sphere2 = world_pos - sphere_slice2.xyz; - float dist_to_sphere2 = dot(wp_to_sphere2, wp_to_sphere2); - - float3 wp_to_sphere3 = world_pos - sphere_slice3.xyz; - float dist_to_sphere3 = dot(wp_to_sphere3, wp_to_sphere3); - - float4x4 world_to_sm; - if (dist_to_sphere0 <= sphere_slice0.w) - world_to_sm = sun_world_to_shadow_slice0; - else if (dist_to_sphere1 <= sphere_slice1.w) - world_to_sm = sun_world_to_shadow_slice1; - else if (dist_to_sphere2 <= sphere_slice2.w) - world_to_sm = sun_world_to_shadow_slice2; - else if (dist_to_sphere3 <= sphere_slice3.w) - world_to_sm = sun_world_to_shadow_slice3; - else - return 1.0; - - float4 sm_pos = mul(float4(shadow_biased_pos, 1.0), world_to_sm); - float2 sm_resolution; - sun_shadow_map.GetDimensions(sm_resolution.x, sm_resolution.y); - float4 tscale = float4(1.f / sm_resolution.x, 1.f / sm_resolution.y, 0.f, 0.f); - - half shadow = 0.0; - for( float xx = -0.5; xx <= 0.5; xx += 1.0 ) { - for( float yy = -0.5; yy <= 0.5; yy += 1.0 ) { - #ifdef GNM - shadow += sun_shadow_map.SampleCmpLOD0(shadow_map_sampler, sm_pos.xy + (float2( xx, yy ) * tscale.xy), sm_pos.z); - #else - shadow += sun_shadow_map.SampleCmpLevelZero(shadow_map_sampler, sm_pos.xy + (float2( xx, yy ) * tscale.xy), sm_pos.z); - #endif - } - } - return shadow * 0.25; - } - - float local_light_shadow_intensity(float4 sm_pos) { - sm_pos.xyz /= sm_pos.w; - float2 sm_resolution; - local_lights_shadow_atlas.GetDimensions(sm_resolution.x, sm_resolution.y); - float2 tscale = float2(1.0f / sm_resolution.x, 1.0f / sm_resolution.y); - half shadow = 0; - [unroll] - for (float xx = -0.5; xx <= 0.5; xx += 1.0) { - [unroll] - for (float yy = -0.5; yy <= 0.5; yy += 1.0) - #if defined(RENDERER_GNM) - shadow += local_lights_shadow_atlas.SampleCmpLOD0(shadow_map_sampler, sm_pos.xy + (float2(xx, yy) * tscale), sm_pos.z); - #else - shadow += local_lights_shadow_atlas.SampleCmpLevelZero(shadow_map_sampler, sm_pos.xy + (float2(xx, yy) * tscale), sm_pos.z); - #endif - } - return shadow * 0.25; - } - - void sun_lighting(const float3 world_pos, const float3 shadow_biased_pos, const float3 N, const float3 V, const float roughness, const float3 ambient, const float3 diffuse_color, const float3 specular_color, inout float3 acc_diff, inout float3 acc_spec) { - const float3 L = normalize(-sun_direction); - const float2 scale_bias = TEX2D(brdf_lut, float2(saturate(dot(N, V)), roughness)).xy; - - const float mipmap_index = roughness * 7; - acc_diff += ambient * baked_diffuse_tint * diffuse_color; - acc_spec += rgbm_decode(TEXCUBELOD(global_specular_map, reflect(-V, N), mipmap_index)) * (specular_color * scale_bias.x + scale_bias.y) * reflections_tint; - - #if defined(RENDERER_D3D11) || defined(RENDERER_D3D12) || defined(RENDERER_GNM) - float shadow_intensity = saturate(sun_shadow_intensity(world_pos, shadow_biased_pos)); - #else - float shadow_intensity = 1.0f; - #endif - - bsdf(L, V, N, sun_color, diffuse_color, specular_color, roughness, shadow_intensity, acc_diff, acc_spec); - } - - struct PS_OUTPUT { - half4 color : SV_TARGET0; - }; - PS_OUTPUT ps_main(PS_INPUT input - #else - GBUFFER_OUT ps_main(PS_INPUT input - #endif - #if defined(CULL_NONE) || defined(CULL_FRONT) - #if defined(GNM) - , bool vface : S_FRONT_FACE - #else - , float vface : VFACE - #endif - #endif - ) - { - #if defined(TRANSPARENT) || defined(TRANSPARENT_FADE) - PS_OUTPUT o; - #else - GBUFFER_OUT o; - #endif - - GraphPixelParams params; - GraphPixelResults graph; - - GRAPH_PIXEL_WRITE_PARAMS(params, input); - GRAPH_EVALUATE_PIXEL(graph, params); - - #if defined(HAS_OPACITY) && !defined(TRANSPARENT) && !defined(TRANSPARENT_FADE) - #if defined(HAS_OPACITY_THRESHOLD) - float threshold = graph.opacity_threshold; - #else - float threshold = 0.5f; - #endif - if (graph.opacity < threshold) - discard; - #endif - - - // Base color - float3 base_color = float3(0,0,0); - #if defined(HAS_BASE_COLOR) - base_color = graph.base_color; - #else - base_color = float3(0.5, 0.5, 0.5); - #endif - - // World space normal - #if defined(HAS_NORMAL) - #if !defined(WORLD_SPACE_NORMAL) - float3 tsm0 = GRAPH_PIXEL_DATA(input, tsm0).xyz; - float3 tsm1 = GRAPH_PIXEL_DATA(input, tsm1).xyz; - float3 tsm2 = GRAPH_PIXEL_DATA(input, tsm2).xyz; - #if defined(CULL_NONE) || defined(CULL_FRONT) - if (!front_facing(vface)) { - tsm0.z = -tsm0.z; - tsm1.z = -tsm1.z; - tsm2.z = -tsm2.z; - } - #endif - float3 wn = rotate_vector3(graph.normal, tsm0, tsm1, tsm2); - #else - float3 wn = normalize(graph.normal); - #if defined(CULL_NONE) || defined(CULL_FRONT) - wn = !front_facing(vface) ? -wn : wn; - #endif - #endif - #else - float3 wn = normalize((float3)GRAPH_PIXEL_DATA(input, world_space_normal).rgb); - #if defined(CULL_NONE) || defined(CULL_FRONT) - wn = !front_facing(vface) ? -wn : wn; - #endif - #endif - - - // Metallic - half metallic_ = 0.f; - #if defined(HAS_METALLIC) - metallic_ = graph.metallic; - #else - metallic_ = 0.f; - #endif - - // Roughness - half roughness_ = 0.f; - #if defined(HAS_ROUGHNESS) - roughness_ = graph.roughness; - #else - roughness_ = 0.5; - #endif - - // Velocity vector - #if !defined(TRANSPARENT) && !defined(TRANSPARENT_FADE) - #if defined(MOTION_BLUR) - VELOCITY(o) = float2(0.0, 0.0); - float3 last_clip_pos = GRAPH_PIXEL_DATA(input, last_clip_position); - float2 screen_pos = (input.position.xy / back_buffer_size); - float2 last_screen_pos = last_clip_pos.xy / last_clip_pos.z; - last_screen_pos = last_screen_pos * 0.5 + 0.5; - last_screen_pos.y = 1.0 - last_screen_pos.y; - VELOCITY(o) = encode_velocity(screen_pos - last_screen_pos); - #else - VELOCITY(o) = encode_velocity(0.0); - #endif - #endif - - // Ambient Diffuse - float3 ambient = float3(0, 0, 0); - #if defined(HAS_VERTEX_BAKED_DIFFUSE_LIGHTING) - ambient = GRAPH_PIXEL_DATA(input, baked_light).rgb; - #elif defined(HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING) - #if defined(HAS_DIRECTIONAL_LIGHTMAPS) - ambient = TEX2D(lightmap_ambient_term, GRAPH_PIXEL_DATA(input, lightmap_uv)).rgb; - float3 dd = TEX2D(lightmap_dominant_direction, GRAPH_PIXEL_DATA(input, lightmap_uv)).rgb * 2 - 1; - ambient += TEX2D(lightmap_directional_term, GRAPH_PIXEL_DATA(input, lightmap_uv)).rgb * max(0, dot(dd, wn)); - #else - ambient = TEX2D(lightmap, GRAPH_PIXEL_DATA(input, lightmap_uv)).rgb; - #endif - #else - ambient = rgbm_decode(TEXCUBELOD(global_diffuse_map, wn, 0)); - #endif - - #if !defined(TRANSPARENT) && !defined(TRANSPARENT_FADE) - BASE_COLOR(o) = gbuffer_encode_base_color(base_color); - NORMAL(o) = gbuffer_encode_normal(wn); - METALLIC(o) = gbuffer_encode_metallic_mask(metallic_); - ROUGHNESS(o) = gbuffer_encode_roughness(roughness_); - DENSITY(o) = 1.0; - // AMBIENT_DIFFUSE_LIGHT(o) = gbuffer_encode_ambient_diffuse_light(ambient); - - #if defined(HAS_AMBIENT_OCCLUSION) - AMBIENT_OCCLUSION(o) = gbuffer_encode_ambient_occlusion(graph.ambient_occlusion); - #else - AMBIENT_OCCLUSION(o) = gbuffer_encode_ambient_occlusion(1.f); - #endif - #else - #if defined(HAS_OPACITY) - half opacity = graph.opacity; - #else - half opacity = 0.5; - #endif - const float3 world_pos = GRAPH_PIXEL_DATA(input, world_pos); - const float3 view_dir = camera_world._m30_m31_m32 - world_pos; - const float3 V = normalize(view_dir); - const float3 N = wn; - - // 0.04 is taken as a common value for dielectrics. Source: Real-time rendering 3rd edition. - const float3 specular_color = lerp(float3(0.04,0.04,0.04), base_color, metallic_); - const float3 diffuse_color = lerp(base_color, new_half3(0,0,0), metallic_); - - const float3 camera_dir = camera_world._m10_m11_m12; - const float depth = dot(-view_dir, camera_dir); - const float3 shadow_biased_pos = world_pos - (depth - apply_shadow_bias(depth)) * (-V); - - float3 acc_diff = 0; - float3 acc_spec = 0; - - sun_lighting(world_pos, shadow_biased_pos, N, V, roughness_, ambient, diffuse_color, specular_color, acc_diff, acc_spec); - - #if defined(RENDERER_D3D11) || defined(RENDERER_D3D12) || defined(RENDERER_GNM) - const float max_depth = cs_cluster_size_in_pixels.w; - const float depth_per_cluster = max_depth / cs_cluster_size_in_pixels.z; - const uint layer = input.position.w / depth_per_cluster; - - const uint2 light_data = cluster_texture.Load(int4(input.position.xy / cs_cluster_size_in_pixels.xy, layer, 0)); - uint light_index = light_data.x; - - float2 li_resolution; - light_index_texture.GetDimensions(li_resolution.x, li_resolution.y); - - const uint point_light_count = light_data.y & 0x00FF; - for (uint pl = 0; pl < point_light_count; ++pl) { - uint2 index_uv = uint2(fmod(light_index, li_resolution.x), light_index / li_resolution.x); - const uint index = light_index_texture.Load(int3(index_uv.xy, 0)).r; - const float3 light_position = cs_lights_data[index].xyz; - const float3 light_color = cs_lights_data[index + 1].rgb; - const float3 light_falloff = cs_lights_data[index + 2].xyz; - - float3 L = light_position - world_pos; - const float len_L = length(L) + 0.00001f; - L /= len_L; - - const float attn = light_attenuation(len_L, light_falloff.x, light_falloff.y); - bsdf(L, V, N, light_color, diffuse_color, specular_color, roughness_, attn, acc_diff, acc_spec); - - ++light_index; - } - - const uint shadow_casting_point_light_count = (light_data.y >> 8) & 0x00FF; - for (uint scpl = 0; scpl < shadow_casting_point_light_count; ++scpl) { - uint2 index_uv = uint2(fmod(light_index, li_resolution.x), light_index / li_resolution.x); - const uint index = light_index_texture.Load(int3(index_uv.xy, 0)).r; - const float3 light_position = cs_lights_data[index].xyz; - const float3 light_color = cs_lights_data[index + 1].rgb; - const float3 light_falloff = cs_lights_data[index + 2].xyz; - - float3 L = light_position - world_pos; - const float len_L = length(L) + 0.00001f; - L /= len_L; - - const float attn = light_attenuation(len_L, light_falloff.x, light_falloff.y); - - // The indices to select the correct world to shadow map matrix are stored in the following components. - const float sm_indices[6] = { - float(cs_lights_data[index + 0].w), - float(cs_lights_data[index + 1].w), - float(cs_lights_data[index + 3].x), - float(cs_lights_data[index + 3].y), - float(cs_lights_data[index + 3].z), - float(cs_lights_data[index + 3].w) - }; - - // The shadows from the faces of an onmni light are populated in the following order and directions. - // float3(-1.0f, 0.0f, 0.0f), - // float3( 1.0f, 0.0f, 0.0f), - // float3( 0.0f, -1.0f, 0.0f), - // float3( 0.0f, 1.0f, 0.0f), - // float3( 0.0f, 0.0f, -1.0f) - // float3( 0.0f, 0.0f, 1.0f), - - // Based on the biggest component of the vector from the shaded position to the light source and its sign, chose the correct - // shadow map index to get the correct world position to shadow map matrix. - const float3 shadow_L = -L; - const int3 is_positive = shadow_L > 0; - const float3 abs_shadow_L = abs(shadow_L); - int test_index = (abs_shadow_L.x > abs_shadow_L.y && abs_shadow_L.x > abs_shadow_L.z) ? 0 + is_positive[0]: (abs_shadow_L.y > abs_shadow_L.z) ? 2 + is_positive[1] : 4 + is_positive[2]; - const float sm_index = sm_indices[test_index]; - - float shadow_intensity = 1.0f; - if (sm_index != -1.0f) { - float4x4 world_to_sm = cs_world_to_shadow_maps[uint(sm_index)]; - float4 sm_pos = mul(float4(shadow_biased_pos, 1.0), world_to_sm); - shadow_intensity = saturate(local_light_shadow_intensity(sm_pos)); - } - - bsdf(L, V, N, light_color, diffuse_color, specular_color, roughness_, attn * shadow_intensity, acc_diff, acc_spec); - - ++light_index; - } - - const uint spot_light_count = (light_data.y >> 16) & 0x00FF; - for (uint sl = 0; sl < spot_light_count; ++sl) { - uint2 index_uv = uint2(fmod(light_index, li_resolution.x), light_index / li_resolution.x); - const uint index = light_index_texture.Load(int3(index_uv.xy, 0)).r; - const float3 light_position = cs_lights_data[index].xyz; - const float3 light_color = cs_lights_data[index + 1].rgb; - const float3 light_falloff = cs_lights_data[index + 2].xyz; - const float3 spot_light_falloff = cs_lights_data[index + 3].xyz; - const float3 spot_dir = normalize(float3(cs_lights_data[index].w, cs_lights_data[index + 1].w, cs_lights_data[index + 2].w)); - - float3 L = light_position - world_pos; - const float len_L = length(L) + 0.00001f; - L /= len_L; - - float attn = light_attenuation(len_L, light_falloff.x, light_falloff.y); - - const float spot_angle = 1.0 - dot(L, -spot_dir); - const float spot_attenuation = (spot_angle > spot_light_falloff.x ? 1.0 - saturate((spot_angle - spot_light_falloff.x) * spot_light_falloff.y) : 1); - attn *= spot_attenuation; - - bsdf(L, V, N, light_color, diffuse_color, specular_color, roughness_, attn, acc_diff, acc_spec); - - ++light_index; - } - - const uint shadow_casting_spot_light_count = (light_data.y >> 24) & 0x00FF; - for (uint scsl = 0; scsl < shadow_casting_spot_light_count; ++scsl) { - uint2 index_uv = uint2(fmod(light_index, li_resolution.x), light_index / li_resolution.x); - const uint index = light_index_texture.Load(int3(index_uv.xy, 0)).r; - const float3 light_position = cs_lights_data[index].xyz; - const float3 light_color = cs_lights_data[index + 1].rgb; - const float3 light_falloff = cs_lights_data[index + 2].xyz; - const float3 spot_light_falloff = cs_lights_data[index + 3].xyz; - const uint sm_index = uint(cs_lights_data[index + 3].w); - const float3 spot_dir = normalize(float3(cs_lights_data[index].w, cs_lights_data[index + 1].w, cs_lights_data[index + 2].w)); - - float3 L = light_position - world_pos; - const float len_L = length(L) + 0.00001f; - L /= len_L; - - float attn = light_attenuation(len_L, light_falloff.x, light_falloff.y); - - const float spot_angle = 1.0 - dot(L, -spot_dir); - const float spot_attenuation = (spot_angle > spot_light_falloff.x ? 1.0 - saturate((spot_angle - spot_light_falloff.x) * spot_light_falloff.y) : 1); - attn *= spot_attenuation; - - float4x4 world_to_sm = cs_world_to_shadow_maps[sm_index]; - float4 sm_pos = mul(float4(shadow_biased_pos, 1.0), world_to_sm); - const float shadow_intensity = saturate(local_light_shadow_intensity(sm_pos)); - - bsdf(L, V, N, light_color, diffuse_color, specular_color, roughness_, attn * shadow_intensity, acc_diff, acc_spec); - - ++light_index; - } - #endif - - #if defined(TRANSPARENT) - float3 accumulated_color = acc_diff * opacity + acc_spec; - #else - float3 accumulated_color = acc_diff + acc_spec; - #endif - - o.color = apply_fog(half4(accumulated_color, opacity), world_pos, depth); - #endif - - return o; - } - #endif - """ - } - } - - depth_only = { - include: [ - "core/stingray_renderer/shader_libraries/common#common", - "core/stingray_renderer/shader_libraries/common#skinning"] - - instance_data = { - "on_renderer(D3D11, D3D12) && defined(INSTANCED)": { - world = { type = "matrix4x4" } - - "defined(DRAW_WIREFRAME)": { - dev_wireframe_color = { type = "vector4" } - } - } - - } - - code = { - glsl = """ - #if (!defined(HAS_NORMAL) || defined(NEEDS_WORLD_SPACE_NORMAL)) || defined(NEEDS_EYE_VECTOR) || defined(HAS_VERTEX_OFFSET) - #define NEEDS_WORLD_SPACE_POSITION - #endif - - CBUFFER_START(c_per_object) - UNIFORM mat4 world_view_proj; - #if defined(NEEDS_WORLD_SPACE_POSITION) - UNIFORM mat4 world; - UNIFORM mat4 view_proj; - #endif - #if defined(NEEDS_INVERSE_WORLD_POSE) - UNIFORM mat4 inv_world; - #endif - CBUFFER_END - - #if defined(STAGE_VERTEX) - layout(location = POSITION0) in vec4 in_position; - - void main() { - GraphManualChannels params; - GraphResults graph; - - #if !defined(HAS_NORMAL) || defined(NEEDS_WORLD_SPACE_NORMAL) - GRAPH_PARAM(params, world_space_normal) = GRAPH_DATA(vertex_normal) * mat3(world); - #endif - - #if defined(SKINNED) - vec4 op = vec4(skin_point(in_position, blendindices, blendweights), 1); - #else - vec4 op = in_position; - #endif - GRAPH_PARAM(params, vertex_position) = op; - - #if defined(NEEDS_WORLD_SPACE_POSITION) - vec4 wp = op * world; - #endif - - #if defined(NEEDS_EYE_VECTOR) - GRAPH_PARAM(params, eye_vector) = camera_pos - wp.rgb; - #endif - - graph_evaluate(graph, params); - - #if defined(HAS_VERTEX_OFFSET) - wp.xyz += graph.vertex_offset; - gl_Position = wp * view_proj; - #else - gl_Position = op * world_view_proj; - #endif - } - #elif defined(STAGE_FRAGMENT) - void main() { - #if defined(HAS_OPACITY) && !defined(TRANSPARENT) && !defined(TRANSPARENT_FADE) - GraphManualChannels params; - GraphResults graph; - graph_evaluate(graph, params); - - #if defined(HAS_OPACITY_THRESHOLD) - float threshold = graph.opacity_threshold; - #else - float threshold = 0.5f; - #endif - - if (graph.opacity < threshold) - discard; - #endif - } - #endif - """ - - hlsl = """ - #if defined(PS_NEEDS_WP) || defined(NEEDS_EYE_VECTOR) || defined(HAS_VERTEX_OFFSET) || ((defined(RENDERER_D3D11) || defined(RENDERER_D3D12)) && defined(INSTANCED)) - #define NEEDS_WORLD_SPACE_POSITION - #endif - - struct VS_INPUT { - float4 position : POSITION; - SKIN_INPUT - GRAPH_VERTEX_INPUT - }; - - struct PS_INPUT { - float4 position : SV_POSITION; - #if (defined(RENDERER_D3D11) || defined(RENDERER_D3D12)) && defined(INSTANCED) && defined(DRAW_WIREFRAME) - float4 instance_wireframe_color : COLOR0; - #endif - GRAPH_PIXEL_INPUT - }; - - CBUFFER_START(c_depth_only) - #if defined(NEEDS_WORLD_SPACE_POSITION) || defined(NEEDS_WORLD_POSE) - float4x4 world; - #endif - #if defined(NEEDS_WORLD_SPACE_POSITION) - float4x4 view_proj; - #else - float4x4 world_view_proj; - #endif - #if defined(NEEDS_INVERSE_WORLD_POSE) - float4x4 inv_world; - #endif - - float4 dev_wireframe_color; - - GRAPH_MATERIAL_EXPORTS - CBUFFER_END - - #if defined(INSTANCED) && (defined(RENDERER_D3D11) || defined(RENDERER_D3D12)) - Buffer idata; - float ioffset; - #endif - - PS_INPUT vs_main(VS_INPUT input - #if defined(INSTANCED) && (defined(RENDERER_D3D11) || defined(RENDERER_D3D12)) - , uint instance_id : SV_InstanceId - #endif - ) - { - PS_INPUT o; - float4 p; - - GraphVertexParams params; - GraphVertexResults results; - - #if defined(INSTANCED) && (defined(RENDERER_D3D11) || defined(RENDERER_D3D12)) - uint offset = (uint)ioffset; - world[0] = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_world + 0)); - world[1] = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_world + 1)); - world[2] = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_world + 2)); - world[3] = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_world + 3)); - - #if defined(DRAW_WIREFRAME) - o.instance_wireframe_color = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_dev_wireframe_color)); - #endif - #endif - - #if defined(SKINNED) - float4 position = float4(skin_point(input.position, input.blendindices, input.blendweights), 1); - #else - float4 position = input.position; - #endif - - // Write automatic params - GRAPH_VERTEX_WRITE_PARAMS(params, input); - - // Write output channels - GRAPH_VERTEX_PARAM(params, vertex_position) = position; - - #if defined(NEEDS_WORLD_SPACE_POSITION) - float4 wp = mul(position, world); - // TODO: Expose output channel here - #endif - - // All members of the params struct has to be initialized, so assign dummy normal here. - #if !defined(HAS_NORMAL) || defined(NEEDS_WORLD_SPACE_NORMAL) - GRAPH_VERTEX_PARAM(params, world_space_normal) = float4(0, 0, 0, 0); - #endif - - #if defined(NEEDS_TANGENT_SPACE) - GRAPH_VERTEX_PARAM(params, tsm0) = - GRAPH_VERTEX_PARAM(params, tsm1) = - GRAPH_VERTEX_PARAM(params, tsm2) = - float4(0, 0, 0, 0); - #endif - - #if defined(NEEDS_EYE_VECTOR) - GRAPH_VERTEX_PARAM(params, eye_vector).rgb = normalize(camera_pos - wp.rgb); - #endif - - // Evaluate all pieces of the graph that should run per-vertex. - GRAPH_EVALUATE_VERTEX(results, params); - - #if defined(NEEDS_WORLD_SPACE_POSITION) - #if defined(HAS_VERTEX_OFFSET) - wp += float4(results.vertex_offset, 0); - #endif - p = mul(wp, view_proj); - #else - p = mul(position, world_view_proj); - #endif - - o.position = p; - - // Write results - GRAPH_VERTEX_WRITE(o, results, params); - - return o; - } - - #if defined(DRAW_WIREFRAME) - float4 ps_main(PS_INPUT input) : SV_TARGET0 - { - #if (defined(RENDERER_D3D11) || defined(RENDERER_D3D12)) && defined(INSTANCED) - return input.instance_wireframe_color; - #else - return dev_wireframe_color; - #endif - } - #else - float4 ps_main(PS_INPUT input) : SV_TARGET0 { - #if defined(HAS_OPACITY) && !defined(TRANSPARENT) && !defined(TRANSPARENT_FADE) - GraphPixelParams params; - GraphPixelResults graph; - GRAPH_PIXEL_WRITE_PARAMS(params, input); - GRAPH_EVALUATE_PIXEL(graph, params); - - #if defined(HAS_OPACITY_THRESHOLD) - float threshold = graph.opacity_threshold; - #else - float threshold = 0.5f; - #endif - - if (graph.opacity < threshold) - discard; - #endif - - return float4(1, 1, 1, 1); - } - #endif - """ - } - } -} diff --git a/vmf/core/stingray_renderer/output_nodes/terrain_base.shader_node b/vmf/core/stingray_renderer/output_nodes/terrain_base.shader_node deleted file mode 100644 index d681b8a..0000000 --- a/vmf/core/stingray_renderer/output_nodes/terrain_base.shader_node +++ /dev/null @@ -1,764 +0,0 @@ -group = "Output" -display_name = "Terrain Base" -output_node = true -render_configs = ["core/stingray_renderer/renderer"] - -inputs = { - "aca690cb-6305-4a2f-bf3d-69183a493db3" = { - name = "base_color" - is_required = false - display_name = "Base Color" - type = { vector3: ["HAS_BASE_COLOR"] } - domain = "pixel" - } - - "34259752-b962-4b65-92c3-903a57338519" = { - name = "opacity" - is_required = false - display_name = "Opacity" - type = { scalar: ["HAS_OPACITY"] } - domain = "pixel" - } - - "7a9306c6-95ae-4cdb-9fef-0eedacce4e83" = { - name = "opacity_threshold" - is_required = false - display_name = "Opacity Threshold" - type = { scalar: ["HAS_OPACITY_THRESHOLD"] } - domain = "pixel" - } - - "b1c86408-aacb-4466-b754-ddcf37a3a2c8" = { - is_required = false - name = "normal" - display_name = "Normal" - type = { vector3: ["HAS_NORMAL"] } - domain = "pixel" - } - - "ad5e052f-d316-4a0f-8b79-53c38204d61b" = { - is_required = false - name = "metallic" - display_name = "Metallic" - type = { scalar: ["HAS_METALLIC"] } - domain = "pixel" - } - - "36ba46d2-f6ea-4e60-a428-fdc17c75bc62" = { - is_required = false - name = "roughness" - display_name = "Roughness" - type = { scalar: ["HAS_ROUGHNESS"] } - domain = "pixel" - } - - "59fd1cf4-f736-470d-8510-1dd7c016639e" = { - is_required = false - name = "ambient_occlusion" - display_name = "Ambient Occlusion" - type = { scalar: ["HAS_AMBIENT_OCCLUSION"] } - domain = "pixel" - } - - "6ae3afc3-7a2d-4572-a376-f2649241c71d" = { - is_required = false - name = "density" - display_name = "Density" - type = { scalar: ["HAS_DENSITY"] } - domain = "pixel" - } -} - -options = { - "a84e242a-2ee2-4542-846a-3691a583e62c" = "USE_GLOBAL_ROUGHNESS_MULTIPLIER" -} - -ui = [ - { type = "checkbox" display_name = "Use Global Roughness Multiplier" option = "a84e242a-2ee2-4542-846a-3691a583e62c" } -] - -render_state = { - terrain = { - inherit: ["core/stingray_renderer/shader_libraries/common#gbuffer_material"] - state: { - fill_mode = "fill_solid" - cull_mode = "cull_ccw" - } - } - - - terrain_alpha_masked_with_prez = { - inherit: ["core/stingray_renderer/shader_libraries/common#gbuffer_material"] - state: { - - fill_mode = "fill_solid" - cull_mode = "cull_ccw" - z_func = "equal" - z_write_enable = "false" - z_enable = "true" - } - } - - depth_only = { - inherit: ["core/stingray_renderer/shader_libraries/common#default"] - state: { - write_mask0 = "0x0" - write_mask1 = "0x0" - write_mask2 = "0x0" - write_mask3 = "0x0" - } - } - - terrain_depth_prepass = { - inherit: ["depth_only"] - state: { - fill_mode = "fill_solid" - cull_mode = "cull_ccw" - } - } - - wireframe = { - inherit: ["core/stingray_renderer/shader_libraries/common#opacity"] - state: { - fill_mode = "fill_wireframe" - "on_renderer(D3D11, D3D12)" = { - depth_bias = "-1" - depth_bias_clamp = "-0.00015" - slope_scale_depth_bias = "-2.0" - } - } - } - - shadow_caster = { - inherit: ["depth_only"] - state: { - "on_renderer(D3D11, D3D12)" = { - depth_bias = "0xff" - slope_scale_depth_bias = "1.0" - } - "on_renderer(GNM)" = { - offset_front = "0.0001" - offset_scale_front = "40.0" - offset_back = "0.0001" - offset_scale_back = "40.0" - } - "on_renderer(GL)" = { - offset_factor = "1.0" - offset_units = "1024.0" - depth_bias_enable = "true" - } - } - } -} - -sampler_state = { } - -channels = { - "defined(NEEDS_TANGENT_SPACE)": { - tsm0 = { type = "float3" domain = "vertex" } - tsm1 = { type = "float3" domain = "vertex" } - tsm2 = { type = "float3" domain = "vertex" } - } - - "defined(NEEDS_EYE_VECTOR)": { - eye_vector = { type = "float3" domain = "vertex" } - } - - "defined(MOTION_BLUR)": { - last_clip_position = { type = "float3" domains = ["vertex", "pixel"] } - } - - vertex_position = { type = "float4" domain = "vertex" } - terrain_uv = { type = "float2" domains=["vertex" "pixel"] } -} - -permutation_sets = { -} - -shader_contexts = { - shadow_caster = { - passes_sort_mode = "immediate" - compile_with = [ - { if: "on_renderer(D3D11, D3D12, GNM)" } - ] - - passes = [ - { code_block="terrain_depth_only" render_state="shadow_caster" } - ] - } - - default = { - passes_sort_mode = "deferred" - compile_with = [ - { if: "on_renderer(D3D11, D3D12, GNM)" permute_with: "default" } - ] - - passes = [ - { if: "defined(HAS_OPACITY)" then: [ - { layer="depth_prepass" code_block="terrain_depth_only" defines=["DEPTH_PREPASS"] render_state="terrain_depth_prepass" } // TODO: Make a depth shader - { layer="gbuffer_terrain" code_block="terrain" defines="MOTION_BLUR" render_state="terrain_alpha_masked_with_prez" } - //{ layer="gbuffer_terrain" code_block="terrain" defines=["MOTION_BLUR" "SINGLE_PASS"] render_state="terrain" } - ] else: [ - { layer="gbuffer_terrain" code_block="terrain" defines="MOTION_BLUR" render_state="terrain" } - ]} - { if: "!on_renderer(GL)" then: [ - { layer="wireframe" code_block="terrain_depth_only" defines=["DRAW_WIREFRAME"] render_state="wireframe" branch_key="dev_wireframe" } - ]} - ] - } -} - -code_blocks = { - terrain_shared = { - code = { - hlsl = """ - float2 morph(float2 uv, float2 wp, float t, float gsize, float psize) { - float3 grid_size = { gsize, gsize*0.5, 2.f/gsize }; - float2 frac_part = (frac(uv*grid_size.yy) * grid_size.zz) * psize.xx; - return wp - frac_part * t; - } - - float3 normal_from_hmap(Sampler2D height_map, float2 uv, float2 texel_size, float texel_aspect) { - #if defined(RENDERER_D3D11) || defined(RENDERER_D3D12) || defined(RENDERER_GNM) - float4 h = { - TEX2D(height_map, uv + texel_size * float2(-1, 0)).r, - TEX2D(height_map, uv + texel_size * float2(1, 0)).r, - TEX2D(height_map, uv + texel_size * float2(0, -1)).r, - TEX2D(height_map, uv + texel_size * float2(0, 1)).r - }; - #endif - - h *= texel_aspect; - - float3 n = { - h[0] - h[1], - h[3] - h[2], - 2 - }; - - return normalize(n); - } - - float3 normal_from_hmap(Sampler2D height_map, float4 uv_lod, float2 texel_size, float texel_aspect) { - #if defined(RENDERER_D3D11) || defined(RENDERER_D3D12) || defined(RENDERER_GNM) - float4 h = { - TEX2DLOD(height_map, uv_lod.xy + texel_size * float2(-1, 0), uv_lod.zw).r, - TEX2DLOD(height_map, uv_lod.xy + texel_size * float2(1, 0), uv_lod.zw).r, - TEX2DLOD(height_map, uv_lod.xy + texel_size * float2(0, -1), uv_lod.zw).r, - TEX2DLOD(height_map, uv_lod.xy + texel_size * float2(0, 1), uv_lod.zw).r - }; - #endif - - h *= texel_aspect; - - float3 n = { - h[0] - h[1], - h[3] - h[2], - 2 - }; - - return normalize(n); - } - """ - } - } - - terrain = { - include:[ - "core/stingray_renderer/shader_libraries/common#common", - "core/stingray_renderer/shader_libraries/common#gbuffer_access", - "core/stingray_renderer/shader_libraries/common#taa_offsets", - "terrain_shared" ] - - samplers = { - //global_diffuse_map = { - // sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - // source = "resource_set" - // slot_name = "global_diffuse_map" - // type = "cube" - //} - hmap = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "hmap" - type = "2d" - } - } - - code = { - hlsl = """ - #if defined(PS_NEEDS_WP) || defined(NEEDS_EYE_VECTOR) - #define NEEDS_WORLD_SPACE_POSITION - #endif - - DECLARE_SAMPLER_2D(hmap); - - struct VS_INPUT { - float4 position : POSITION; - GRAPH_VERTEX_INPUT - }; - - struct PS_INPUT { - float4 position : SV_POSITION; - float4 color : COLOR; - GRAPH_PIXEL_INPUT - }; - - CBUFFER_START(c_per_object) - float4x4 world; - float4x4 world_view_proj; - float3 terrain_size; - float3 lod_camera_pos; - float4x4 last_world; - - #if defined(USE_GLOBAL_ROUGHNESS_MULTIPLIER) - float global_roughness_multiplier; - #endif - - float4 dev_wireframe_color; - GRAPH_MATERIAL_EXPORTS - CBUFFER_END - - #if defined(RENDERER_D3D11) || defined(RENDERER_D3D12) || defined(RENDERER_GNM) - Buffer idata; - #endif - - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - PS_INPUT vs_main(VS_INPUT input, uint instance_id : SV_InstanceId) - { - PS_INPUT o; - float4 p; - - GraphVertexParams params; - GraphVertexResults results; - - #if defined(RENDERER_D3D11) || defined(RENDERER_D3D12) || defined(RENDERER_GNM) - float4 pos_scale = idata.Load(instance_id * 2 + 0); - float4 tile_info = idata.Load(instance_id * 2 + 1); - #endif - float2 half_size = terrain_size.xy * 0.5; - float2 mip = input.position.xy; - float2 pos = (mip.xy - 0.5) * pos_scale.zw + pos_scale.xy; - - float3 temp_wp = mul(float4(pos, 0, 1), world); - float t = 1-saturate((distance(temp_wp, camera_pos) - (tile_info.x - pos_scale.z*0.5)) / tile_info.y); - - float2 huv = ((pos.xy / half_size) * 0.5 + 0.5); - #if defined(RENDERER_D3D11) || defined(RENDERER_D3D12) || defined(RENDERER_GNM) - huv.y = 1-huv.y; - #endif - float h = TEX2DLOD(hmap, huv, 0).r * terrain_size.z; - - // Write automatic params - GRAPH_VERTEX_WRITE_PARAMS(params, input); - - // Write output channels - float4 position = float4(pos.xy, h, 1); - #if defined(NEEDS_WORLD_SPACE_POSITION) - float4 wp = mul(position, world); - // TODO: Expose output channel here - #endif - GRAPH_VERTEX_PARAM(params, vertex_position) = position; - - #if defined(NEEDS_EYE_VECTOR) - GRAPH_VERTEX_PARAM(params, eye_vector).rgb = camera_pos - wp.rgb; - #endif - - GRAPH_VERTEX_PARAM(params, terrain_uv) = huv; - - #if defined(NEEDS_TANGENT_SPACE) - #if defined(RENDERER_D3D11) || defined(RENDERER_D3D12) || defined(RENDERER_GNM) - float2 res; - TEXTURE_NAME(hmap).GetDimensions(res.x, res.y); - float2 inv_hmap_size = 1.0/res; - #endif - float3 normal = normal_from_hmap(hmap, float4(huv, 0, 0), inv_hmap_size, terrain_size.z); - - // create tangentspace vectors - normal = mul(normal, (float3x3)world); - float3 tangent = normalize(cross(world._m10_m11_m12, normal)); // TODO: redundant normalize? - float3 binormal = normalize(cross(normal, tangent)); // TODO: redundant normalize? - - tspace_transpose( - GRAPH_VERTEX_PARAM(params, tsm0), - GRAPH_VERTEX_PARAM(params, tsm1), - GRAPH_VERTEX_PARAM(params, tsm2), - tangent, binormal, normal); - #endif - - // Evaluate all pieces of the graph that should run per-vertex. - GRAPH_EVALUATE_VERTEX(results, params); - - p = mul(position, world_view_proj); - - #if defined(MOTION_BLUR) - float4 last_wp = mul(position, last_world); - float4 last_clip_pos = mul(last_wp, camera_last_view_projection); - float4 last_view_space = last_clip_pos / last_clip_pos.w; - last_view_space.xy += get_vs_halton_offset(frame_number); - last_view_space.xy = last_view_space.xy * 0.5 + 0.5; - last_view_space.y = 1.0 - last_view_space.y; - last_clip_pos = last_view_space * last_clip_pos.w; - GRAPH_VERTEX_PARAM(params, last_clip_position) = last_clip_pos.xyw; - #endif - - #if defined(DRAW_WIREFRAME) - o.position = p; - #else - float4 view_space = p / p.w; - view_space.xy += get_vs_halton_offset(frame_number); - o.position = view_space * p.w; - #endif - - const float3 lod_cols[8] = { - float3(1,0,0), - float3(0,1,0), - float3(0,0,1), - float3(1,1,0), - float3(0,1,1), - float3(1,1,0.5), - float3(1,0,0.5), - float3(0,1,0.5) - }; - - o.color = float4(lod_cols[(uint)tile_info.w], t); - - // Write results - GRAPH_VERTEX_WRITE(o, results, params); - - return o; - } - - #if defined(DRAW_WIREFRAME) - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - float4 ps_main(PS_INPUT input) : SV_TARGET0 - { - return dev_wireframe_color; - } - #elif defined(DEPTH_ONLY) - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - float4 ps_main(PS_INPUT input) : SV_TARGET0 - { - #if defined(HAS_OPACITY) - GraphPixelParams params; - GraphPixelResults graph; - GRAPH_PIXEL_WRITE_PARAMS(params, input); - GRAPH_EVALUATE_PIXEL(graph, params); - - #if defined(HAS_OPACITY_THRESHOLD) - float threshold = graph.opacity_threshold; - #else - float threshold = 0.5f; - #endif - - if (graph.opacity < threshold) - discard; - #endif - - return float4(1,1,1,1); - } - #else - //DECLARE_SAMPLER_CUBE(global_diffuse_map); - - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - GBUFFER_OUT ps_main(PS_INPUT input) - { - GBUFFER_OUT o; - - GraphPixelParams params; - GraphPixelResults graph; - - GRAPH_PIXEL_WRITE_PARAMS(params, input); - GRAPH_EVALUATE_PIXEL(graph, params); - - #if defined(HAS_OPACITY) && defined(SINGLE_PASS) - #if defined(HAS_OPACITY_THRESHOLD) - float threshold = graph.opacity_threshold; - #else - float threshold = 0.5f; - #endif - - if (graph.opacity < threshold) - discard; - #endif - - #if !defined(HAS_NORMAL) - #if defined(RENDERER_D3D11) || defined(RENDERER_D3D12) || defined(RENDERER_GNM) - float2 res; - TEXTURE_NAME(hmap).GetDimensions(res.x, res.y); - float2 inv_hmap_size = 1.0/res; - #endif - float3 tnormal = normal_from_hmap(hmap, GRAPH_PIXEL_DATA(input, terrain_uv), inv_hmap_size, terrain_size.z); - #endif - - // Base color - float3 base_color = float3(0,0,0); - #if defined(HAS_BASE_COLOR) - base_color = graph.base_color; - #else - base_color = float3(0.5, 0.5, 0.5); - #endif - BASE_COLOR(o) = gbuffer_encode_base_color(base_color); - - // World space normal - #if defined(HAS_NORMAL) - float3 wn = graph.normal; - #else - float3 wn = tnormal; - #endif - wn = mul(wn, (float3x3)world); - - NORMAL(o) = gbuffer_encode_normal(wn); - - // Metallic - half metallic_ = 0.f; - #if defined(HAS_METALLIC) - metallic_ = graph.metallic; - #else - metallic_ = 0.f; - #endif - METALLIC(o) = gbuffer_encode_metallic_mask(metallic_); - - // Roughness - half roughness_ = 0.f; - #if defined(HAS_ROUGHNESS) - roughness_ = graph.roughness; - #else - roughness_ = 0.5; - #endif - #if defined(USE_GLOBAL_ROUGHNESS_MULTIPLIER) - roughness_ = saturate(roughness_ * global_roughness_multiplier); - #endif - ROUGHNESS(o) = gbuffer_encode_roughness(roughness_); - - #if defined(MOTION_BLUR) - float3 last_clip_pos = GRAPH_PIXEL_DATA(input, last_clip_position); - float2 screen_pos = (input.position.xy / back_buffer_size - viewport.zw) / viewport.xy; - float2 last_screen_pos = last_clip_pos.xy / last_clip_pos.z; - VELOCITY(o) = encode_velocity(viewport.xy*(screen_pos - last_screen_pos)); - #else - VELOCITY(o) = encode_velocity(float2(0.0, 0.0)); - #endif - - // Density - half density = 1.0; - #if defined(HAS_DENSITY) - density = graph.density; - #endif - DENSITY(o) = density; - - // Since we don't have baked lighting, we don't use this - // // Ambient Diffuse - // float3 ambient = float3(0, 0, 0); - // #if defined(HAS_VERTEX_BAKED_DIFFUSE_LIGHTING) - // ambient = GRAPH_PIXEL_DATA(input, baked_light).rgb; - // #elif defined(HAS_LIGHTMAP_BAKED_DIFFUSE_LIGHTING) && defined(HAS_UV_UNWRAP) - // ambient = TEX2D(lightmap, GRAPH_PIXEL_DATA(input, lightmap_uv)).rgb; - // #else - // ambient = rgbm_decode(TEXCUBELOD(global_diffuse_map, wn, 0)); - // #endif - - // AMBIENT_DIFFUSE_LIGHT(o) = gbuffer_encode_ambient_diffuse_light(ambient); - - #if defined(HAS_AMBIENT_OCCLUSION) - AMBIENT_OCCLUSION(o) = gbuffer_encode_ambient_occlusion(graph.ambient_occlusion); - #else - AMBIENT_OCCLUSION(o) = gbuffer_encode_ambient_occlusion(1.f); - #endif - - return o; - } - #endif - """ - } - } - - terrain_depth_only = { - include:[ - "core/stingray_renderer/shader_libraries/common#common", - "core/stingray_renderer/shader_libraries/common#gbuffer_access", - "core/stingray_renderer/shader_libraries/common#taa_offsets", - "terrain_shared" ] - - samplers = { - hmap = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "hmap" - type = "2d" - } - } - - code = { - hlsl = """ - #if defined(PS_NEEDS_WP) || defined(NEEDS_EYE_VECTOR) - #define NEEDS_WORLD_SPACE_POSITION - #endif - - DECLARE_SAMPLER_2D(hmap); - - struct VS_INPUT { - float4 position : POSITION; - #if defined(HAS_OPACITY) - GRAPH_VERTEX_INPUT - #endif - }; - - struct PS_INPUT { - float4 position : SV_POSITION; - #if defined(HAS_OPACITY) - GRAPH_PIXEL_INPUT - #endif - }; - - // TODO: why does not this tinner buffer work? - /*CBUFFER_START(c_per_object_depth_only) - float4x4 world; - float4x4 world_view_proj; - float3 terrain_size; - - float4 dev_wireframe_color; - #if defined(HAS_OPACITY) - GRAPH_MATERIAL_EXPORTS - #endif - CBUFFER_END*/ - - CBUFFER_START(c_per_object) - float4x4 world; - float4x4 world_view_proj; - float3 terrain_size; - float3 lod_camera_pos; - float4x4 last_world; - - #if defined(USE_GLOBAL_ROUGHNESS_MULTIPLIER) - float global_roughness_multiplier; - #endif - - float4 dev_wireframe_color; - GRAPH_MATERIAL_EXPORTS - CBUFFER_END - - #if defined(RENDERER_D3D11) || defined(RENDERER_D3D12) || defined(RENDERER_GNM) - Buffer idata; - #endif - - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - PS_INPUT vs_main(VS_INPUT input, uint instance_id : SV_InstanceId) - { - PS_INPUT o; - float4 p; - - #if defined(HAS_OPACITY) - GraphVertexParams params; - GraphVertexResults results; - #endif - - #if defined(RENDERER_D3D11) || defined(RENDERER_D3D12) || defined(RENDERER_GNM) - float4 pos_scale = idata.Load(instance_id * 2 + 0); - float4 tile_info = idata.Load(instance_id * 2 + 1); - #endif - float2 half_size = terrain_size.xy * 0.5; - float2 mip = input.position.xy; - float2 pos = (mip.xy - 0.5) * pos_scale.zw + pos_scale.xy; - - float2 huv = ((pos.xy / half_size) * 0.5 + 0.5); - #if defined(RENDERER_D3D11) || defined(RENDERER_D3D12) || defined(RENDERER_GNM) - huv.y = 1-huv.y; - #endif - float h = TEX2DLOD(hmap, huv, 0).r * terrain_size.z; - - float4 position = float4(pos.xy, h, 1); - - #if defined(HAS_OPACITY) - #if defined(NEEDS_WORLD_SPACE_POSITION) - float4 wp = mul(position, world); - // TODO: Expose output channel here - #endif - - // Write automatic params - GRAPH_VERTEX_WRITE_PARAMS(params, input); - - // Write output channels - GRAPH_VERTEX_PARAM(params, vertex_position) = position; - - GRAPH_VERTEX_PARAM(params, terrain_uv) = huv; - - #if defined(NEEDS_EYE_VECTOR) - GRAPH_VERTEX_PARAM(params, eye_vector).rgb = camera_pos - wp.rgb; - #endif - - #if defined(NEEDS_TANGENT_SPACE) - #if defined(RENDERER_D3D11) || defined(RENDERER_D3D12) || defined(RENDERER_GNM) - float2 res; - TEXTURE_NAME(hmap).GetDimensions(res.x, res.y); - float2 inv_hmap_size = 1.0/res; - #endif - float3 normal = normal_from_hmap(hmap, float4(huv, 0, 0), inv_hmap_size, terrain_size.z); - - // create tangentspace vectors - normal = mul(normal, (float3x3)world); - float3 tangent = normalize(cross(world._m10_m11_m12, normal)); // TODO: redundant normalize? - float3 binormal = normalize(cross(normal, tangent)); // TODO: redundant normalize? - - tspace_transpose( - GRAPH_VERTEX_PARAM(params, tsm0), - GRAPH_VERTEX_PARAM(params, tsm1), - GRAPH_VERTEX_PARAM(params, tsm2), - tangent, binormal, normal); - #endif - - // Evaluate all pieces of the graph that should run per-vertex. - GRAPH_EVALUATE_VERTEX(results, params); - #endif - - p = mul(position, world_view_proj); - - #if defined(DEPTH_PREPASS) - float4 view_space = p / p.w; - view_space.xy += get_vs_halton_offset(frame_number); - o.position = view_space * p.w; - #else - o.position = p; - #endif - - #if defined(HAS_OPACITY) - // Write results - GRAPH_VERTEX_WRITE(o, results, params); - #endif - - return o; - } - - #if defined(DRAW_WIREFRAME) - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - float4 ps_main(PS_INPUT input) : SV_TARGET0 - { - return dev_wireframe_color; - } - #else - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - float4 ps_main(PS_INPUT input) : SV_TARGET0 - { - #if defined(HAS_OPACITY) - GraphPixelParams params; - GraphPixelResults graph; - GRAPH_PIXEL_WRITE_PARAMS(params, input); - GRAPH_EVALUATE_PIXEL(graph, params); - - #if defined(HAS_OPACITY_THRESHOLD) - float threshold = graph.opacity_threshold; - #else - float threshold = 0.5f; - #endif - - if (graph.opacity < threshold) - discard; - #endif - - return float4(1,1,1,1); - } - #endif - """ - } - } -} diff --git a/vmf/core/stingray_renderer/output_nodes/unlit_base.shader_node b/vmf/core/stingray_renderer/output_nodes/unlit_base.shader_node deleted file mode 100644 index 3acdf67..0000000 --- a/vmf/core/stingray_renderer/output_nodes/unlit_base.shader_node +++ /dev/null @@ -1,746 +0,0 @@ -group = "Output" -display_name = "Unlit Base" -output_node = true -render_configs = ["core/stingray_renderer/renderer"] - -inputs = { - "aee6e47b-be7b-4d67-a123-2ab5d660b94e" = { - name = "vertex_offset" - display_name = "Position offset" - is_required = false - type = { vector3: ["HAS_VERTEX_OFFSET"] } - domain = "vertex" - } - - "aca690cb-6305-4a2f-bf3d-69183a493db3" = { - name = "base_color" - is_required = false - display_name = "Base Color" - type = { vector3: ["HAS_BASE_COLOR"] } - domain = "pixel" - } - - "34259752-b962-4b65-92c3-903a57338519" = { - name = "opacity" - is_required = false - display_name = "Opacity" - type = { scalar: ["HAS_OPACITY"] } - domain = "pixel" - } - - "c9a30d71-a8ad-4b9e-aedf-d785ae7e301f" = { - name = "additive" - is_required = false - display_name = "Additive" - type = { scalar: ["HAS_ADDITIVE"] } - domain = "pixel" - } -} - -options = { - "d1a42a54-0794-4d57-9aa0-eb35acb6b35c" = "INSTANCED" - "8df1b8f7-17c2-4ae4-8c4e-25517ec1df46" = "DOUBLE_SIDED" - "34994d84-9d51-48ac-af85-bc053b2c65c3" = "SKIN" - "e1bfa889-2503-4ac3-9134-c08a7fa04568" = "PROJECT_TO_FAR_PLANE" - "6a6241cc-7d21-4e2e-87c8-8d9c7bdcd322" = "CAMERA_TRANSLATION_LOCK" - "435e14e4-556d-4ac1-af14-8dafe63aff8f" = "BLEND_TRANSPARENT" - "52c7ce01-ee57-4770-914e-727fc1966962" = "LAYER_EMISSIVE" - "182fabd6-9a4d-4cfc-8c8f-0c45ef09a138" = "LAYER_SKYDOME" - "4c3163d4-c086-4645-ba1c-0d68a98022a1" = "LAYER_HDR_TRANSPARENT" - "c8d8b754-c567-4c7b-9cbd-8acab22beff5" = "LAYER_TRANSPARENT" - "afe47c59-33c4-43b2-af4a-817085b1113c" = "DEPTH_TEST_INVERTED" - "774556cd-2d1e-4df8-8ae2-5e84800f0c04" = "DEPTH_TEST_DISABLED" - "7b8bc0bf-c453-49d2-9415-0e80fec1039f" = "DISABLE_DEPTH_WRITE" - "b2556764-e8e9-47cf-9ecc-f53b5d5d73c7" = "HAS_CUSTOM_FOV" -} - -ui = [ - { - type = "drop_down" - display_name = "Layer" - options = { - "Emissive" = "52c7ce01-ee57-4770-914e-727fc1966962" - "Skydome" = "182fabd6-9a4d-4cfc-8c8f-0c45ef09a138" - "HDR Transparent" = "4c3163d4-c086-4645-ba1c-0d68a98022a1" - "LDR Transparent" = "c8d8b754-c567-4c7b-9cbd-8acab22beff5" - } - default = "4c3163d4-c086-4645-ba1c-0d68a98022a1" - } - - { - type = "drop_down" - display_name = "Depth Testing" - options = { - "Normal" = "00000000-0000-0000-0000-000000000000" - "Inverted" = "afe47c59-33c4-43b2-af4a-817085b1113c" - "Disabled" = "774556cd-2d1e-4df8-8ae2-5e84800f0c04" - } - default = "00000000-0000-0000-0000-000000000000" - } - - { - type = "drop_down" - display_name = "Blend Mode" - options = { - "Opaque" = "00000000-0000-0000-0000-000000000000" - "Transparent" = "435e14e4-556d-4ac1-af14-8dafe63aff8f" - } - default = "00000000-0000-0000-0000-000000000000" - } - - { type = "checkbox" display_name = "Disable Depth Writes" option = "7b8bc0bf-c453-49d2-9415-0e80fec1039f" } - { type = "checkbox" display_name = "Double Sided" option = "8df1b8f7-17c2-4ae4-8c4e-25517ec1df46" } - { type = "checkbox" display_name = "Instancing" option = "d1a42a54-0794-4d57-9aa0-eb35acb6b35c" } - { type = "checkbox" display_name = "Project to Far Plane" option = "e1bfa889-2503-4ac3-9134-c08a7fa04568" } - { type = "checkbox" display_name = "Camera Translation Lock" option = "6a6241cc-7d21-4e2e-87c8-8d9c7bdcd322" } - { type = "checkbox" display_name = "Custom FOV" option = "b2556764-e8e9-47cf-9ecc-f53b5d5d73c7" } -] - -render_state = { - unlit = { - inherit: ["core/stingray_renderer/shader_libraries/common#default"] - state: { - "defined(BLEND_TRANSPARENT)" = { - blend_enable = "true" - blend_op = "blend_op_add" - dest_blend = "blend_inv_src_alpha" - src_blend = "blend_one" - } - - "defined(DEPTH_TEST_DISABLED)" = { - z_enable = "false" - } - - "defined(DISABLE_DEPTH_WRITE)" = { - z_write_enable = "false" - } - - "defined(DEPTH_TEST_INVERTED)" = { - z_func = "greater_equal" - } - } - } - - material_transfer = { - inherit: ["core/stingray_renderer/shader_libraries/common#default"] - state: { - cull_mode = "cull_none" - z_write_enable = "false" - z_enable = "false" - } - } - - wireframe = { - inherit: ["core/stingray_renderer/shader_libraries/common#opacity"] - state: { - fill_mode = "fill_wireframe" - "on_renderer(D3D11, D3D12)" = { - depth_bias = "-1" - depth_bias_clamp = "-0.00015" - slope_scale_depth_bias = "-2.0" - } - } - } -} - -sampler_state = { } - -channels = { - "defined(NEEDS_EYE_VECTOR)": { - eye_vector = { type = "float3" domain = "vertex" } - } - - "defined(NEEDS_WORLD_SPACE_NORMAL)": { - world_space_normal = { type = "float3" domains = ["vertex", "pixel"] } - } - - "defined(MOTION_BLUR)": { - last_clip_position = { type = "float3" domains = ["vertex", "pixel"] } - } - - "defined(MATERIAL_TRANSFER)": { - lightmap_uv = { type = "float2" semantic="TEXCOORD1" domains = ["vertex"] } - } - - "defined(NEEDS_SCREEN_POS)": { - screen_pos = { type = "float2" domain = "pixel" } - } - - "defined(NEEDS_PIXEL_DEPTH)": { - pixel_depth = { type = "float" domain = "pixel" } - } - - vertex_position = { type = "float4" domain = "vertex" } - vertex_normal = { type = "float3" semantic = "NORMAL" domain = "vertex" } -} - -//log_permutations = true -permutation_sets = { - vertex_modifiers = [ - { if: "num_skin_weights() == 4" define: { "macros": ["SKINNED_4WEIGHTS"] stages: ["vertex"] } } - { if: "num_skin_weights() == 3" define: { "macros": ["SKINNED_3WEIGHTS"] stages: ["vertex"] } } - { if: "num_skin_weights() == 2" define: { "macros": ["SKINNED_2WEIGHTS"] stages: ["vertex"] } } - { if: "num_skin_weights() == 1" define: { "macros": ["SKINNED_1WEIGHT"] stages: ["vertex"] } } - { default = true } - ] - - instanced_modifiers = [ - { default = true } - ] - - non_instanced_modifiers = [ - { permute_with: "vertex_modifiers" } - ] - - default = [ - { if: "defined(INSTANCED)" permute_with: "instanced_modifiers" } - { if: "!defined(INSTANCED)" permute_with: "non_instanced_modifiers" } - ] -} - -shader_contexts = { - default = { - passes_sort_mode = "deferred" - compile_with = [ - { if: "on_renderer(D3D11, D3D12, GNM, GL) && defined(LAYER_HDR_TRANSPARENT) && render_setting(low_res_transparency)" defines=["LOW_RES_ENABLED"] permute_with: "default" } - { if: "on_renderer(D3D11, D3D12, GNM, GL)" permute_with: "default" } - ] - - passes = [ - { if: "defined(LAYER_EMISSIVE)" then: [ - { layer="emissive" code_block="unlit" defines="MOTION_BLUR" render_state="unlit" } - ]} - { if: "defined(LAYER_SKYDOME)" then: [ - { layer="skydome" code_block="unlit" render_state="unlit" } - ]} - { if: "defined(LAYER_HDR_TRANSPARENT)" then: [ - { layer="hdr_transparent" code_block="unlit" render_state="unlit" } - ]} - - { if: "defined(LAYER_TRANSPARENT)" then: [ - { layer="transparent" code_block="unlit" render_state="unlit" } - ] else: [ - { if: "!on_renderer(GL)" then: [ - { layer="wireframe" code_block="unlit" define="DRAW_WIREFRAME" render_state="wireframe" branch_key="dev_wireframe" } - ]} - ]} - ] - } -} - -code_blocks = { - macros = { - code = { - shared = """ - #define TAA_GUI_DEPTH_BIAS_RANGE 50.0 // The [0, TAA_GUI_DEPTH_BIAS_RANGE] depth range for which we lerp the min-max depth biases for line drawing - #define TAA_GUI_MIN_DEPTH_BIAS 0.001 // The depth offset to add for lines drawn at z = 0 - #define TAA_GUI_MAX_DEPTH_BIAS 0.05 // The depth offset to add for lines drawn at z >= GUI_DEPTH_BIAS_RANGE - - // We need to disable instancing for the material transfer context as it doesn't use the world transform. - #if defined(INSTANCED) && defined(MATERIAL_TRANSFER) - #undef INSTANCED - #endif - - #if defined(PS_NEEDS_WP) || defined(NEEDS_EYE_VECTOR) || defined(HAS_VERTEX_OFFSET) || ((defined(RENDERER_D3D11) || defined(RENDERER_D3D12)) && defined(INSTANCED)) || defined(CAMERA_TRANSLATION_LOCK) || defined(BILLBOARD) - #define NEEDS_WORLD_SPACE_POSITION - #endif - """ - } - } - - unlit = { - include:[ - "core/stingray_renderer/shader_libraries/common#common", - "core/stingray_renderer/shader_libraries/common#gbuffer_access", - "core/stingray_renderer/shader_libraries/common#skinning", - "core/stingray_renderer/shader_libraries/common#taa_offsets", - "macros", - "core/stingray_renderer/shader_libraries/common#billboard_transformation"] - - instance_data = { - "on_renderer(D3D11, D3D12) && !defined(MATERIAL_TRANSFER) && defined(INSTANCED)": { - world = { type = "matrix4x4" } - "defined(MOTION_BLUR)": { - last_world = { type = "matrix4x4" } - } - "defined(DRAW_WIREFRAME)": { - dev_wireframe_color = { type = "vector4" } - } - } - } - - samplers = { - "defined(NEEDS_LINEAR_DEPTH)": { - linear_depth = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_point" - source = "resource_set" - slot_name = "linear_depth" - type = "2d" - } - } - "!defined(LOW_RES)": { - "defined(LOW_RES_ENABLED)": { - hdr_transparent_div4 = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "hdr_transparent_div4" - type = "2d" - } - - hdr_linear_depth_div4 = { - sampler_state = "core/stingray_renderer/shader_libraries/common#clamp_linear" - source = "resource_set" - slot_name = "hdr_linear_depth_div4" - type = "2d" - } - } - } - } - - code = { - glsl = """ - #if defined(STAGE_VERTEX) - layout(location = POSITION0) in highp vec4 in_pos; - - CBUFFER_START(c_per_object) - #if defined(NEEDS_WORLD_SPACE_POSITION) - #if defined(CAMERA_TRANSLATION_LOCK) - UNIFORM mat4 view; - UNIFORM mat4 proj; - #else - UNIFORM mat4 view_proj; - #endif - #else - UNIFORM mat4 world_view_proj; - #endif - UNIFORM mat4 world; - CBUFFER_END - - void main() - { - GraphManualChannels params; - GraphResults graph; - - // Write output channels - #if defined(SKINNED) - vec4 position = vec4(skin_point(in_pos, blendindices, blendweights), 1); - mediump vec3 normal = skin_vector(GRAPH_DATA(vertex_normal), blendindices, blendweights); - #if defined(NEEDS_TANGENT_SPACE) - mediump vec3 tangent = skin_vector(GRAPH_DATA(vertex_tangent), blendindices, blendweights); - mediump vec3 binormal = skin_vector(GRAPH_DATA(vertex_binormal), blendindices, blendweights); - #endif - #else - vec4 position = in_pos; - mediump vec3 normal = GRAPH_DATA(vertex_normal); - #if defined(NEEDS_TANGENT_SPACE) - mediump vec3 tangent = GRAPH_DATA(vertex_tangent); - mediump vec3 binormal = GRAPH_DATA(vertex_binormal); - #endif - #endif - - #if defined(NEEDS_WORLD_SPACE_POSITION) - vec4 wp = position * world; - #endif - - GRAPH_PARAM(params, vertex_position) = position; - - #if defined(NEEDS_WORLD_SPACE_NORMAL) - GRAPH_PARAM(params, world_space_normal) = normal * mat3(world); - #endif - - #if defined(NEEDS_EYE_VECTOR) - GRAPH_PARAM(params, eye_vector) = camera_pos - wp.rgb; - #endif - - #if defined(NEEDS_TANGENT_SPACE) - tspace_transform_transpose( - GRAPH_PARAM(params, tsm0), - GRAPH_PARAM(params, tsm1), - GRAPH_PARAM(params, tsm2), - tangent, binormal, normal, - mat3(world)); - #endif - - // Evaluate all pieces of the graph that should run per-vertex. - graph_evaluate(graph, params); - - vec4 p; - #if defined(NEEDS_WORLD_SPACE_POSITION) - #if defined(HAS_VERTEX_OFFSET) - wp += vec4(graph.vertex_offset, 0); - #endif - - #if defined(CAMERA_TRANSLATION_LOCK) - view[0][3] = 0.0; - view[1][3] = 0.0; - view[2][3] = 0.0; - p = (wp * view) * proj; - #else - p = wp * view_proj; - #endif - #else - p = position * world_view_proj; - #endif - - #if defined(PROJECT_TO_FAR_PLANE) - p.z = p.w; - #endif - - gl_Position = p; - } - #elif defined(STAGE_FRAGMENT) - layout(location = 0) out mediump vec4 out_color; - - void main() - { - #if defined(HAS_BASE_COLOR) || defined(HAS_OPACITY) - GraphManualChannels params; - GraphResults graph; - graph_evaluate(graph, params); - #endif - - vec3 color = vec3(0.5, 0.5, 0.5); - #if defined(HAS_BASE_COLOR) - color = graph.base_color; - #endif - - float op = 1.0; - #if defined(HAS_OPACITY) - op = graph.opacity; - #endif - - out_color = vec4(color.r, color.g, color.b, op); - } - #endif - """ - - hlsl = """ - #if defined(NEEDS_LINEAR_DEPTH) - DECLARE_SAMPLER_2D(linear_depth); - #define HAS_LINEAR_DEPTH - #endif - - #if !defined(LOW_RES) && defined(LOW_RES_ENABLED) - DECLARE_SAMPLER_2D(hdr_transparent_div4); - DECLARE_SAMPLER_2D(hdr_linear_depth_div4); - #endif - - #if defined(NEEDS_PIXEL_DEPTH) || (!defined(LOW_RES) && defined(LOW_RES_ENABLED)) - #define PS_NEEDS_WP - #endif - - #if defined(PS_NEEDS_WP) - #define NEEDS_WORLD_SPACE_POSITION - #endif - - struct VS_INPUT { - float4 position : POSITION; - SKIN_INPUT - GRAPH_VERTEX_INPUT - }; - - struct PS_INPUT { - #if (defined(RENDERER_D3D11) || defined(RENDERER_D3D12)) && defined(INSTANCED) && defined(DRAW_WIREFRAME) - float4 instance_wireframe_color : COLOR0; - #endif - float4 position : SV_POSITION; - #if defined(PS_NEEDS_WP) - float3 world_pos : TEXCOORD15; - #endif - GRAPH_PIXEL_INPUT - }; - - CBUFFER_START(c_per_object) - #if defined(NEEDS_WORLD_SPACE_POSITION) - #if defined(CAMERA_TRANSLATION_LOCK) - float4x4 view; - float4x4 proj; - #else - float4x4 view_proj; - #endif - #else - float4x4 world_view_proj; - #endif - #if defined(BILLBOARD) && defined(LAYER_SKYDOME_BILLBOARD) - #if defined(SECONDARY_SUN_DIRECTION) - float3 secondary_sun_direction; - #define billboard_direction secondary_sun_direction - #else - float3 sun_direction; - #define billboard_direction sun_direction - #endif - #endif - float4x4 world; - float4x4 last_world; - float4 dev_wireframe_color; - GRAPH_MATERIAL_EXPORTS - CBUFFER_END - - #if defined(INSTANCED) && (defined(RENDERER_D3D11) || defined(RENDERER_D3D12)) - Buffer idata; - float ioffset; - #endif - - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - PS_INPUT vs_main(VS_INPUT input - #if defined(INSTANCED) && (defined(RENDERER_D3D11) || defined(RENDERER_D3D12)) - , uint instance_id : SV_InstanceId - #endif - ) - { - PS_INPUT o; - float4 p; - - GraphVertexParams params; - GraphVertexResults results; - - #if defined(INSTANCED) && (defined(RENDERER_D3D11) || defined(RENDERER_D3D12)) - uint offset = (uint)ioffset + instance_id*IDATA_STRIDE; - world[0] = idata.Load(offset + IDATA_world + 0); - world[1] = idata.Load(offset + IDATA_world + 1); - world[2] = idata.Load(offset + IDATA_world + 2); - world[3] = idata.Load(offset + IDATA_world + 3); - - #if defined(MOTION_BLUR) - last_world[0] = idata.Load(offset + IDATA_last_world + 0); - last_world[1] = idata.Load(offset + IDATA_last_world + 1); - last_world[2] = idata.Load(offset + IDATA_last_world + 2); - last_world[3] = idata.Load(offset + IDATA_last_world + 3); - #endif - - #if defined(DRAW_WIREFRAME) - o.instance_wireframe_color = idata.Load(offset + (instance_id*IDATA_STRIDE + IDATA_dev_wireframe_color)); - #endif - #endif - - // Write automatic params - GRAPH_VERTEX_WRITE_PARAMS(params, input); - - // Write output channels - #if defined(SKINNED) - float4 position = float4(skin_point(input.position, input.blendindices, input.blendweights), 1); - #if defined(MOTION_BLUR) - float4 last_position = float4(skin_point_last_frame(input.position, input.blendindices, input.blendweights), 1); - #endif - #if !defined(BILLBOARD) - #if (defined(NEEDS_WORLD_SPACE_NORMAL) || defined(NEEDS_TANGENT_SPACE)) - float3 normal = skin_vector(GRAPH_VERTEX_DATA(input, vertex_normal).xyz, input.blendindices, input.blendweights); - #endif - #if defined(NEEDS_TANGENT_SPACE) - float3 tangent = skin_vector(GRAPH_VERTEX_DATA(input, vertex_tangent).xyz, input.blendindices, input.blendweights); - float3 binormal = skin_vector(GRAPH_VERTEX_DATA(input, vertex_binormal).xyz, input.blendindices, input.blendweights); - #endif - #endif - #else - float4 position = input.position; - #if defined(MOTION_BLUR) - float4 last_position = position; - #endif - #if !defined(BILLBOARD) - #if (defined(NEEDS_WORLD_SPACE_NORMAL) || defined(NEEDS_TANGENT_SPACE)) - float3 normal = GRAPH_VERTEX_DATA(input, vertex_normal).xyz; - #endif - #if defined(NEEDS_TANGENT_SPACE) - float3 tangent = GRAPH_VERTEX_DATA(input, vertex_tangent).xyz; - float3 binormal = GRAPH_VERTEX_DATA(input, vertex_binormal).xyz; - #endif - #endif - #endif - - #if defined(BILLBOARD) - float4 wp; - float3 normal, tangent, binormal; - #if !defined(LAYER_SKYDOME_BILLBOARD) - get_billboard_data_from_position(world._m30_m31_m32, camera_world._m30_m31_m32, camera_view, position, wp, normal, tangent, binormal); - #else - get_billboard_data_from_direction(billboard_direction, position, wp, normal, tangent, binormal); - #endif - #elif defined(NEEDS_WORLD_SPACE_POSITION) - float4 wp = mul(position, world); - #endif - - GRAPH_VERTEX_PARAM(params, vertex_position) = position; - - #if defined(NEEDS_WORLD_SPACE_NORMAL) - GRAPH_VERTEX_PARAM(params, world_space_normal).rgb = mul(normal, (float3x3)world); - #endif - - #if defined(NEEDS_EYE_VECTOR) - #if defined(BILLBOARD) && defined(LAYER_SKYDOME_BILLBOARD) - // TODO: not correct length, we can't use length(eye_vector) to determine the distance - GRAPH_VERTEX_PARAM(params, eye_vector).rgb = billboard_direction; - #else - GRAPH_VERTEX_PARAM(params, eye_vector).rgb = camera_pos - wp.rgb; - #endif - #endif - - #if defined(NEEDS_TANGENT_SPACE) - tspace_transform_transpose( - GRAPH_VERTEX_PARAM(params, tsm0), - GRAPH_VERTEX_PARAM(params, tsm1), - GRAPH_VERTEX_PARAM(params, tsm2), - tangent, binormal, normal, - (float3x3)world); - #endif - - #if defined(MOTION_BLUR) - GRAPH_VERTEX_PARAM(params, last_clip_position) = float3(0.0, 0.0, 0.0); - - #if defined(BILLBOARD) - float4 cur_wp = wp; - float4 last_wp; - #if !defined(LAYER_SKYDOME_BILLBOARD) - get_billboard_positions_from_position(last_world._m30_m31_m32, camera_last_world._m30_m31_m32, camera_last_view, last_position, last_wp); - #else - get_billboard_positions_from_direction(billboard_direction, last_position, last_wp); - #endif - #else - float4 cur_wp = mul(position, world); - float4 last_wp = mul(last_position, last_world); - #endif - if(length(cur_wp - last_wp) > 0.0) { - float4 last_clip_pos = mul(last_wp, camera_last_view_projection); - GRAPH_VERTEX_PARAM(params, last_clip_position) = last_clip_pos.xyw; - } - #endif - - // Evaluate all pieces of the graph that should run per-vertex. - GRAPH_EVALUATE_VERTEX(results, params); - - #if defined(NEEDS_WORLD_SPACE_POSITION) - #if defined(HAS_VERTEX_OFFSET) - wp += float4(results.vertex_offset, 0); - #endif - - #if defined(CAMERA_TRANSLATION_LOCK) - view._m30_m31_m32 = float3(0,0,0); - p = mul(mul(wp, view), proj); - #else - #if defined(HAS_CUSTOM_FOV) - p = mul(wp, camera_custom_fov_view_projection); - #else - p = mul(wp, view_proj); - #endif - #endif - #else - #if defined(HAS_CUSTOM_FOV) - // TODO: create camera_custom_fov_world_view_projection? - p = mul(mul(position, world), camera_custom_fov_view_projection); - #else - p = mul(position, world_view_proj); - #endif - #endif - - #if defined(MATERIAL_TRANSFER) - float2 unwrapped_uv = GRAPH_VERTEX_DATA(input, lightmap_uv); - float2 ndc = float2(unwrapped_uv.x, unwrapped_uv.y) * 2 - 1; - ndc.y *= -1; - p = float4(ndc, 0, 1); - #endif - - #if defined(PROJECT_TO_FAR_PLANE) - p.z = p.w; - #endif - - #if defined(LAYER_TRANSPARENT) && !defined(DEPTH_TEST_DISABLED) - p.z -= lerp(TAA_GUI_MIN_DEPTH_BIAS, TAA_GUI_MAX_DEPTH_BIAS, saturate((o.position.z / o.position.w) / TAA_GUI_DEPTH_BIAS_RANGE)) * taa_enabled; - #endif - - #if defined(PS_NEEDS_WP) - o.world_pos = wp.xyz; - #endif - - #if defined(DRAW_WIREFRAME) || defined(MATERIAL_TRANSFER) || defined(LAYER_TRANSPARENT) - o.position = p; - #else - float4 view_space = p / p.w; - view_space.xy += get_vs_halton_offset(frame_number); - o.position = view_space * p.w; - #endif - - // Write results - GRAPH_VERTEX_WRITE(o, results, params); - - return o; - } - - #if defined(DRAW_WIREFRAME) - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - float4 ps_main(PS_INPUT input) : SV_TARGET0 - { - #if (defined(RENDERER_D3D11) || defined(RENDERER_D3D12)) && defined(INSTANCED) - return input.instance_wireframe_color; - #else - return dev_wireframe_color; - #endif - } - #else - DEFAULT_ROOT_SIGNATURE_ATTRIBUTE - float4 ps_main(PS_INPUT input) : SV_TARGET0 - { - #if defined(NEEDS_PIXEL_DEPTH) || (!defined(LOW_RES) && defined(LOW_RES_ENABLED)) - const float3 world_pos = input.world_pos; - const float3 view_dir = camera_world._m30_m31_m32 - world_pos; - const float3 camera_dir = camera_world._m10_m11_m12; - const float depth = dot(-view_dir, camera_dir); - #endif - - #if defined(HAS_BASE_COLOR) || defined(HAS_OPACITY) || defined(HAS_ADDITIVE) - GraphPixelParams params; - GraphPixelResults graph; - - GRAPH_PIXEL_WRITE_PARAMS(params, input); - - #if defined(NEEDS_PIXEL_DEPTH) - GRAPH_PIXEL_PARAM(params, pixel_depth) = depth; - #endif - - #if defined(NEEDS_SCREEN_POS) - float2 screen_pos = (input.position.xy / back_buffer_size); - GRAPH_PIXEL_PARAM(params, screen_pos) = screen_pos; - #endif - - GRAPH_EVALUATE_PIXEL(graph, params); - #endif - - float3 color = float3(0.5, 0.5, 0.5); - #if defined(HAS_BASE_COLOR) - color = graph.base_color; - #endif - - float op = 1.f; - #if defined(HAS_OPACITY) - op = graph.opacity; - #endif - - #if !defined(LOW_RES) && defined(LOW_RES_ENABLED) - float2 screen_uv = input.position.xy / back_buffer_size; - - // Fade out high resolution particle if the low resolution particles is infront of the high resolution particle - float2 particle_depth_values = TEX2D(hdr_linear_depth_div4, screen_uv).rg; - float depth_mean = particle_depth_values.x; - float depth_variance = particle_depth_values.y - depth_mean*depth_mean; - float background_depth = depth; - - float diff = max(background_depth - depth_mean, 0.0); - float C = 1.38629436112; // 2 * ln(2) - float T = exp2(-diff*diff / (C * max(depth_variance, 0.001))); - float alpha_modifier = TEX2D(hdr_transparent_div4, screen_uv).a * (1.0 - T); - op *= 1.0 - alpha_modifier; - #endif - - #ifdef LAYER_SKYDOME - return float4(color, 1.0); - #else - #if defined(HAS_ADDITIVE) - return float4(color * op, op * (1.0 - saturate(graph.additive))); - #else - return float4(color * op, op); - #endif - #endif - } - #endif - """ - } - } -}