Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public enum BLEND_MODES
- {
- NORMAL,
- MULTIPLY,
- ADDITIVE,
- DIFFERENCE,
- OVERLAY,
- SCREEN
- }
- static float[,] Blend_Normal(float[,] mapA, float[,] mapB, int width, int height, WorldMinMax blendMinMax)
- {
- for (int i = 0; i < width; i++)
- {
- for (int j = 0; j < height; j++)
- {
- float v = mapB[i, j];
- blendMinMax.AddValue(v);
- }
- }
- return mapB;
- }
- static float[,] Blend_Multiply(float[,] mapA, float[,] mapB, int width, int height, WorldMinMax blendMinMax)
- {
- float[,] blendedMap = new float[width, height];
- for (int i = 0; i < width; i++)
- {
- for (int j = 0; j < height; j++)
- {
- float v = mapA[i, j] * mapB[i, j];
- blendedMap[i, j] = v;
- blendMinMax.AddValue(v);
- }
- }
- return blendedMap;
- }
- // Given layer a and a layer b where b is the top layer and a is the underlying layer.
- public static float[,] Blend(BLEND_MODES blend_mode, float[,] mapA, float[,] mapB, int width, int height,
- WorldMinMax blendMinMax)
- {
- switch (blend_mode)
- {
- case BLEND_MODES.NORMAL:
- return Blend_Normal(mapA, mapB, width, height, blendMinMax);
- case BLEND_MODES.MULTIPLY:
- return Blend_Multiply(mapA, mapB, width, height, blendMinMax);
- //case BLEND_MODES.DIVIDE:
- // return Blend_Divide(mapA, mapB, width, height, blendMinMax);
- case BLEND_MODES.ADDITIVE:
- return Blend_Add(mapA, mapB, width, height, blendMinMax);
- case BLEND_MODES.DIFFERENCE:
- return Blend_Diff(mapA, mapB, width, height, blendMinMax);
- case BLEND_MODES.OVERLAY:
- return Blend_Overlay(mapA, mapB, width, height, blendMinMax);
- case BLEND_MODES.SCREEN:
- return Blend_Screen(mapA, mapB, width, height, blendMinMax);
- }
- return new float[width, height];
- }
- static float[,] Blend_Add(float[,] mapA, float[,] mapB, int width, int height, WorldMinMax blendMinMax)
- {
- float[,] blendedMap = new float[width, height];
- for (int i = 0; i < width; i++)
- {
- for (int j = 0; j < height; j++)
- {
- float v = mapA[i, j] + mapB[i, j];
- blendedMap[i, j] = v;
- blendMinMax.AddValue(v);
- }
- }
- return blendedMap;
- }
- static float[,] Blend_Diff(float[,] mapA, float[,] mapB, int width, int height, WorldMinMax blendMinMax)
- {
- float[,] blendedMap = new float[width, height];
- for (int i = 0; i < width; i++)
- {
- for (int j = 0; j < height; j++)
- {
- float v = mapA[i, j] - mapB[i, j];
- blendedMap[i, j] = v;
- blendMinMax.AddValue(v);
- }
- }
- return blendedMap;
- }
- static float[,] Blend_Screen(float[,] mapA, float[,] mapB, int width, int height, WorldMinMax blendMinMax)
- {
- float[,] blendedMap = new float[width, height];
- for (int i = 0; i < width; i++)
- {
- for (int j = 0; j < height; j++)
- {
- float v = (1 - mapA[i, j]) * (1 - mapB[i, j]);
- blendedMap[i, j] = v;
- blendMinMax.AddValue(v);
- }
- }
- return blendedMap;
- }
- static float[,] Blend_Overlay(float[,] mapA, float[,] mapB, int width, int height, WorldMinMax blendMinMax)
- {
- float[,] blendedMap = new float[width, height];
- for (int i = 0; i < width; i++)
- {
- for (int j = 0; j < height; j++)
- {
- float v_a = mapA[i, j];
- float v_b = mapB[i, j];
- float v = 0;
- if (v_a < 0.5f)
- {
- v = 2 * v_a * v_b;
- }
- else
- {
- v = 1 - (2 * (1 - v_a) * (1 - v_b));
- }
- blendedMap[i, j] = v;
- blendMinMax.AddValue(v);
- }
- }
- return blendedMap;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement