Skip to content

Commit

Permalink
automated embedded LUTs in the DCTL versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Fry committed Jul 28, 2022
1 parent d4e8c53 commit 1a30aed
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
DEFINE_ACES_PARAM(IS_PARAMETRIC_ACES_TRANSFORM: 0)


__DEVICE__ float lin_to_ACEScct(float in) {
if (in <= 0.0078125f) {
return 10.5402377416545f * in + 0.0729055341958355f;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
DEFINE_ACES_PARAM(IS_PARAMETRIC_ACES_TRANSFORM: 0)


__DEVICE__ float lin_to_ACEScct(float in) {
if (in <= 0.0078125f) {
return 10.5402377416545f * in + 0.0729055341958355f;
Expand All @@ -25,7 +24,6 @@ __DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, float p
}



DEFINE_CUBE_LUT(DRTLUT)
{
TITLE "Generated by Foundry::LUT"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
DEFINE_ACES_PARAM(IS_PARAMETRIC_ACES_TRANSFORM: 0)


__DEVICE__ float lin_to_ACEScct(float in) {
if (in <= 0.0078125f) {
return 10.5402377416545f * in + 0.0729055341958355f;
Expand All @@ -25,7 +24,6 @@ __DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, float p
}



DEFINE_CUBE_LUT(DRTLUT)
{
TITLE "Generated by Foundry::LUT"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
DEFINE_ACES_PARAM(IS_PARAMETRIC_ACES_TRANSFORM: 0)


__DEVICE__ float lin_to_ACEScct(float in) {
if (in <= 0.0078125f) {
return 10.5402377416545f * in + 0.0729055341958355f;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
DEFINE_ACES_PARAM(IS_PARAMETRIC_ACES_TRANSFORM: 0)


__DEVICE__ float lin_to_ACEScct(float in) {
if (in <= 0.0078125f) {
return 10.5402377416545f * in + 0.0729055341958355f;
Expand All @@ -25,7 +24,6 @@ __DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, float p
}



DEFINE_CUBE_LUT(DRTLUT)
{
TITLE "Generated by Foundry::LUT"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
DEFINE_ACES_PARAM(IS_PARAMETRIC_ACES_TRANSFORM: 0)


__DEVICE__ float lin_to_ACEScct(float in) {
if (in <= 0.0078125f) {
return 10.5402377416545f * in + 0.0729055341958355f;
Expand Down Expand Up @@ -28,7 +27,6 @@ __DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, float p
}



DEFINE_CUBE_LUT(DRTLUT)
{
TITLE "Generated by Foundry::LUT"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
DEFINE_ACES_PARAM(IS_PARAMETRIC_ACES_TRANSFORM: 0)


__DEVICE__ float lin_to_ACEScct(float in) {
if (in <= 0.0078125f) {
return 10.5402377416545f * in + 0.0729055341958355f;
Expand Down Expand Up @@ -28,7 +27,6 @@ __DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, float p
}



DEFINE_CUBE_LUT(DRTLUT)
{
TITLE "Generated by Foundry::LUT"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
DEFINE_ACES_PARAM(IS_PARAMETRIC_ACES_TRANSFORM: 0)


__DEVICE__ float lin_to_ACEScct(float in) {
if (in <= 0.0078125f) {
return 10.5402377416545f * in + 0.0729055341958355f;
Expand Down Expand Up @@ -28,7 +27,6 @@ __DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, float p
}



DEFINE_CUBE_LUT(DRTLUT)
{
TITLE "Generated by Foundry::LUT"
Expand Down
53 changes: 13 additions & 40 deletions python/lutWriteNodeCode.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,25 @@ def cubeToCub(cubePath,cubPath):
inputCubePath = cubePath
ouputCubPath = cubPath





# read the cube
with open(inputCubePath) as f:
lines = f.readlines()





# header
tlHeader = '''# Truelight Cube v2.1
# iDims 3
# oDims 3
# width 65 65 65\n
# Cube'''





# footer
tlFooter = '''\n# end\n'''






LUTlines = lines[2:]
LUTlines = [x.replace('\n','').split(' ') for x in LUTlines]
LUTlines = [[float(i) for i in x] for x in LUTlines]
LUTlines = [[str(i) for i in x] for x in LUTlines]





## remove decimal from 0.0 and 1.0
for i, x in enumerate(LUTlines):
for j, a in enumerate(x):
Expand All @@ -66,35 +45,19 @@ def cubeToCub(cubePath,cubPath):
if '1.0' == a:
LUTlines[i][j] = '1'





# reconstruct the cube string
stringLUTlines = []
for line in LUTlines:
stringLUTlines.append(' '.join(line))
newLUTStringBlock = '\n'.join(stringLUTlines)





# join it all up
outputContents = tlHeader + '\n' + newLUTStringBlock + '\n' + tlFooter





# check directory for outputCubPath exists, if not, create it
if not os.path.exists(os.path.dirname(ouputCubPath)):
os.makedirs(os.path.dirname(ouputCubPath))





# write the file
with open(ouputCubPath, 'w') as f:
f.write(outputContents)
Expand Down Expand Up @@ -165,13 +128,19 @@ def bakeCandidateLUTfromNode(node):
shutil.copy(cubePath,cubePathClean)


# read contents of cube file
with open(cubePathClean) as f:
cubelines = f.readlines()



## write the dctl file
with open(dctltemplatePath) as f:
lines = f.readlines()
newLines = [x.replace('replace.cube',cubeNameClean) for x in lines]
# replace the string REPLACE_WITH_CUBE_DATA with the contents of cubelines
newLines = [x.replace('REPLACE_WITH_CUBE_DATA',''.join(cubelines)) for x in newLines]

with open(dctlPath, 'w') as f:
f.write(''.join(newLines))

Expand All @@ -186,10 +155,14 @@ def bakeCandidateLUTfromNode(node):
# copy cubePath to ocioCubePath
shutil.copy(cubePath,ocioCubePath)

# remove original cube if it isnt the same as the clean version
if cubePathClean != cubePath:
# delete cubeName
# # remove original cube if it isnt the same as the clean version
# if cubePathClean != cubePath:
# # delete cubeName
# os.remove(cubePath)
if os.path.exists(cubePath):
os.remove(cubePath)
if os.path.exists(cubePathClean):
os.remove(cubePathClean)



Expand Down
7 changes: 5 additions & 2 deletions resources/ACES_ApplyLUT_Template_AP0.dctl
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
DEFINE_ACES_PARAM(IS_PARAMETRIC_ACES_TRANSFORM: 0)
DEFINE_LUT(DRTLUT, replace.cube)


__DEVICE__ float lin_to_ACEScct(float in) {
if (in <= 0.0078125f) {
Expand All @@ -24,3 +22,8 @@ __DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, float p

return res;
}


DEFINE_CUBE_LUT(DRTLUT)
{
REPLACE_WITH_CUBE_DATA}
7 changes: 5 additions & 2 deletions resources/ACES_ApplyLUT_Template_APS4.dctl
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
DEFINE_ACES_PARAM(IS_PARAMETRIC_ACES_TRANSFORM: 0)
DEFINE_LUT(DRTLUT, replace.cube)


__DEVICE__ float lin_to_ACEScct(float in) {
if (in <= 0.0078125f) {
Expand All @@ -27,3 +25,8 @@ __DEVICE__ float3 transform(int p_Width, int p_Height, int p_X, int p_Y, float p

return res;
}


DEFINE_CUBE_LUT(DRTLUT)
{
REPLACE_WITH_CUBE_DATA}

0 comments on commit 1a30aed

Please sign in to comment.