Last active
October 2, 2018 10:34
-
-
Save FredrikNoren/e60797f55b6e69d771757e965030cab0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function mutateAbilitySlots(abilitySlotsSize: number, maxColorAttachements: number) { | |
return multilayerShaderSource(maxColorAttachements, | |
` | |
uniform sampler2DArray cellProperties; | |
uniform sampler2D cleanCopyMove; | |
uniform float noiseSeedModify; | |
uniform float noiseSeedAmount; | |
uniform float mutateChance; | |
${RandomGLSL} | |
`, | |
` | |
int copyMove = int(texture(cleanCopyMove, texcoord).r); | |
`, | |
i => ` | |
float ability = texture(cellProperties, vec3(texcoord, inputLayer)).r; | |
if (copyMove == ${CopyMoveStates.Copy}) { | |
float modify = rands(texcoord, noiseSeedModify + float(inputLayer) / ${shaderFloatConstant(abilitySlotsSize)}); | |
float amount = rands(texcoord, noiseSeedAmount - float(inputLayer) / ${shaderFloatConstant(abilitySlotsSize)}); | |
// "&& amount > -1.0" is just there because for some reason this part gets optimized away on linux. See https://sentry.io/share/issue/638a1607fb3b46c2abd74ff44f32659b/ | |
if (modify < mutateChance && amount > -1.0) { | |
out_values[${i}] = vec4(int(amount * ${shaderFloatConstant(abilitySlotsSize)}), 0, 0, 1); | |
} else { | |
out_values[${i}] = vec4(ability, 0, 0, 1); | |
} | |
} else { | |
out_values[${i}] = vec4(ability, 0, 0, 1); | |
} | |
`); | |
} | |
export function multilayerShaderSource(maxColorAttachements: number, uniforms: string, initMain: string, layerUpdate: (i: number) => string): string { | |
return shaderHeader + ` | |
in vec2 texcoord; | |
out vec4 out_values[${maxColorAttachements}]; | |
${uniforms} | |
uniform int inputLayers[${maxColorAttachements}]; | |
void main() { | |
${initMain} | |
${ | |
new Array(maxColorAttachements).fill(0).map((_, i) => ` | |
{ | |
int inputLayer = inputLayers[${i}]; | |
${layerUpdate(i)} | |
} | |
`).join('\n') | |
} | |
} | |
`; | |
}; | |
// Generated GLSL | |
#version 300 es | |
precision highp float; | |
precision highp int; | |
precision highp sampler2DArray; | |
#define PI 3.1415926535897932384626433832795 | |
in vec2 texcoord; | |
out vec4 out_values[8]; | |
uniform sampler2DArray cellProperties; | |
uniform sampler2D cleanCopyMove; | |
uniform float noiseSeedModify; | |
uniform float noiseSeedAmount; | |
uniform float mutateChance; | |
float rand(vec2 co){ | |
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); | |
} | |
float rands(vec2 co, float seed){ | |
return rand(mod(co.xy + seed, 1.0)); | |
} | |
uniform int inputLayers[8]; | |
void main() { | |
int copyMove = int(texture(cleanCopyMove, texcoord).r); | |
{ | |
int inputLayer = inputLayers[0]; | |
float ability = texture(cellProperties, vec3(texcoord, inputLayer)).r; | |
if (copyMove == 2) { | |
float modify = rands(texcoord, noiseSeedModify + float(inputLayer) / 0.0); | |
float amount = rands(texcoord, noiseSeedAmount - float(inputLayer) / 0.0); | |
// "&& amount > -1.0" is just there because for some reason this part gets optimized away on linux. See https://sentry.io/share/issue/638a1607fb3b46c2abd74ff44f32659b/ | |
if (modify < mutateChance && amount > -1.0) { | |
out_values[0] = vec4(int(amount * 0.0), 0, 0, 1); | |
} else { | |
out_values[0] = vec4(ability, 0, 0, 1); | |
} | |
} else { | |
out_values[0] = vec4(ability, 0, 0, 1); | |
} | |
} | |
{ | |
int inputLayer = inputLayers[1]; | |
float ability = texture(cellProperties, vec3(texcoord, inputLayer)).r; | |
if (copyMove == 2) { | |
float modify = rands(texcoord, noiseSeedModify + float(inputLayer) / 0.0); | |
float amount = rands(texcoord, noiseSeedAmount - float(inputLayer) / 0.0); | |
// "&& amount > -1.0" is just there because for some reason this part gets optimized away on linux. See https://sentry.io/share/issue/638a1607fb3b46c2abd74ff44f32659b/ | |
if (modify < mutateChance && amount > -1.0) { | |
out_values[1] = vec4(int(amount * 0.0), 0, 0, 1); | |
} else { | |
out_values[1] = vec4(ability, 0, 0, 1); | |
} | |
} else { | |
out_values[1] = vec4(ability, 0, 0, 1); | |
} | |
} | |
{ | |
int inputLayer = inputLayers[2]; | |
float ability = texture(cellProperties, vec3(texcoord, inputLayer)).r; | |
if (copyMove == 2) { | |
float modify = rands(texcoord, noiseSeedModify + float(inputLayer) / 0.0); | |
float amount = rands(texcoord, noiseSeedAmount - float(inputLayer) / 0.0); | |
// "&& amount > -1.0" is just there because for some reason this part gets optimized away on linux. See https://sentry.io/share/issue/638a1607fb3b46c2abd74ff44f32659b/ | |
if (modify < mutateChance && amount > -1.0) { | |
out_values[2] = vec4(int(amount * 0.0), 0, 0, 1); | |
} else { | |
out_values[2] = vec4(ability, 0, 0, 1); | |
} | |
} else { | |
out_values[2] = vec4(ability, 0, 0, 1); | |
} | |
} | |
{ | |
int inputLayer = inputLayers[3]; | |
float ability = texture(cellProperties, vec3(texcoord, inputLayer)).r; | |
if (copyMove == 2) { | |
float modify = rands(texcoord, noiseSeedModify + float(inputLayer) / 0.0); | |
float amount = rands(texcoord, noiseSeedAmount - float(inputLayer) / 0.0); | |
// "&& amount > -1.0" is just there because for some reason this part gets optimized away on linux. See https://sentry.io/share/issue/638a1607fb3b46c2abd74ff44f32659b/ | |
if (modify < mutateChance && amount > -1.0) { | |
out_values[3] = vec4(int(amount * 0.0), 0, 0, 1); | |
} else { | |
out_values[3] = vec4(ability, 0, 0, 1); | |
} | |
} else { | |
out_values[3] = vec4(ability, 0, 0, 1); | |
} | |
} | |
{ | |
int inputLayer = inputLayers[4]; | |
float ability = texture(cellProperties, vec3(texcoord, inputLayer)).r; | |
if (copyMove == 2) { | |
float modify = rands(texcoord, noiseSeedModify + float(inputLayer) / 0.0); | |
float amount = rands(texcoord, noiseSeedAmount - float(inputLayer) / 0.0); | |
// "&& amount > -1.0" is just there because for some reason this part gets optimized away on linux. See https://sentry.io/share/issue/638a1607fb3b46c2abd74ff44f32659b/ | |
if (modify < mutateChance && amount > -1.0) { | |
out_values[4] = vec4(int(amount * 0.0), 0, 0, 1); | |
} else { | |
out_values[4] = vec4(ability, 0, 0, 1); | |
} | |
} else { | |
out_values[4] = vec4(ability, 0, 0, 1); | |
} | |
} | |
{ | |
int inputLayer = inputLayers[5]; | |
float ability = texture(cellProperties, vec3(texcoord, inputLayer)).r; | |
if (copyMove == 2) { | |
float modify = rands(texcoord, noiseSeedModify + float(inputLayer) / 0.0); | |
float amount = rands(texcoord, noiseSeedAmount - float(inputLayer) / 0.0); | |
// "&& amount > -1.0" is just there because for some reason this part gets optimized away on linux. See https://sentry.io/share/issue/638a1607fb3b46c2abd74ff44f32659b/ | |
if (modify < mutateChance && amount > -1.0) { | |
out_values[5] = vec4(int(amount * 0.0), 0, 0, 1); | |
} else { | |
out_values[5] = vec4(ability, 0, 0, 1); | |
} | |
} else { | |
out_values[5] = vec4(ability, 0, 0, 1); | |
} | |
} | |
{ | |
int inputLayer = inputLayers[6]; | |
float ability = texture(cellProperties, vec3(texcoord, inputLayer)).r; | |
if (copyMove == 2) { | |
float modify = rands(texcoord, noiseSeedModify + float(inputLayer) / 0.0); | |
float amount = rands(texcoord, noiseSeedAmount - float(inputLayer) / 0.0); | |
// "&& amount > -1.0" is just there because for some reason this part gets optimized away on linux. See https://sentry.io/share/issue/638a1607fb3b46c2abd74ff44f32659b/ | |
if (modify < mutateChance && amount > -1.0) { | |
out_values[6] = vec4(int(amount * 0.0), 0, 0, 1); | |
} else { | |
out_values[6] = vec4(ability, 0, 0, 1); | |
} | |
} else { | |
out_values[6] = vec4(ability, 0, 0, 1); | |
} | |
} | |
{ | |
int inputLayer = inputLayers[7]; | |
float ability = texture(cellProperties, vec3(texcoord, inputLayer)).r; | |
if (copyMove == 2) { | |
float modify = rands(texcoord, noiseSeedModify + float(inputLayer) / 0.0); | |
float amount = rands(texcoord, noiseSeedAmount - float(inputLayer) / 0.0); | |
// "&& amount > -1.0" is just there because for some reason this part gets optimized away on linux. See https://sentry.io/share/issue/638a1607fb3b46c2abd74ff44f32659b/ | |
if (modify < mutateChance && amount > -1.0) { | |
out_values[7] = vec4(int(amount * 0.0), 0, 0, 1); | |
} else { | |
out_values[7] = vec4(ability, 0, 0, 1); | |
} | |
} else { | |
out_values[7] = vec4(ability, 0, 0, 1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment