Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TODO] Add shader compilation on cmake #126

Open
edunad opened this issue Feb 28, 2024 · 0 comments
Open

[TODO] Add shader compilation on cmake #126

edunad opened this issue Feb 28, 2024 · 0 comments
Labels

Comments

@edunad
Copy link
Owner

edunad commented Feb 28, 2024

Taken from https://github.com/DiligentGraphics/DiligentSamples/blob/master/Samples/Asteroids/CMakeLists.txt

set_source_files_properties(${SHADERS} PROPERTIES VS_TOOL_OVERRIDE "None")

set(COMPILED_SHADERS_DIR ${CMAKE_CURRENT_BINARY_DIR}/CompiledShaders)
file(MAKE_DIRECTORY "${COMPILED_SHADERS_DIR}")

foreach(SRC_SHADER ${SHADERS})
    get_filename_component(SHADER_NAME ${SRC_SHADER} NAME_WE)
    get_filename_component(SHADER_EXT ${SRC_SHADER} EXT)
    set(COMPILED_SHADER ${COMPILED_SHADERS_DIR}/${SHADER_NAME}.h)
    list(APPEND COMPILED_SHADERS ${COMPILED_SHADER})

    set(PROFILE vs_5_0)
    if(${SHADER_NAME} STREQUAL "asteroid_ps")
        set(PROFILE ps_5_1)
    elseif(${SHADER_EXT} STREQUAL ".psh")
        set(PROFILE ps_5_0)
    endif()

    add_custom_command(OUTPUT ${COMPILED_SHADER} # We must use full path here!
                       COMMAND fxc /T ${PROFILE} /E ${SHADER_NAME} /Vn g_${SHADER_NAME} /Fh "${COMPILED_SHADER}" "${SRC_SHADER}"
                       WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
                       COMMENT "Compiling ${SRC_SHADER}"
                       VERBATIM
    )
endforeach(SRC_SHADER)

# NB: we must use the full path, otherwise the build system will not be able to properly detect
#     changes and shader compilation custom command will run every time
set_source_files_properties(${COMPILED_SHADERS} PROPERTIES GENERATED TRUE)
@edunad edunad added FEATURE Feature request TODO and removed FEATURE Feature request labels Feb 28, 2024
@edunad edunad added this to Rawrbox Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

No branches or pull requests

1 participant