A Singleplayer & Multiplayer Mod for Mount & Blade II Bannerlord, which brings the world of the Three Kingdoms Period in Ancient China.

RSS Development Tech Update #1

We build 2 Shader for Defensive wall in ThreeKingdoms Mod.

Posted by on - Intermediate Textures

We made 2 shaders for making the defensive walls in ThreeKingdoms Mod.


ezgif 4 ef272c323db8

ezgif 4 2af25603861a

ezgif 4 74125414c088


We used the `Flood Fill` Algorithm to fill the shader.

In OpenCV, Flood Fill is the most common way in fill algorithms. There are 2 functions for `Flood Fill`, One with mask while the other without mask. This mask is used to control which area will be filled (For example when we want to fill the image multiple times).For both functions, we need first select a seed point in image, then fill the same color to the surrounding similar regions.

The floodFill from opencv asks for the image, a mask (not used = None), the seed pixel and the color to color the seed and the similar neighbors. With that in hands we only need to go pixel by pixel checking its color, if it is white we change to some gray color, and then increment the gray color so the next object will have a different gray ton. As this process goes we can count how many times the floodFill was applied and assume that’s the number of objects we have in the scene. (Source: Medium.com)

  • The first parameter, inputOutputArray type image, input/output 1 channel or 3 channels, 8-bit or floating-point image, the specific parameters are specified by the following parameters.
  • The second parameter, the mask of the InputOutputArray type, is the only parameter of the second version of FloodFill, which represents the operation mask. It should be a single-channel, 8-bit, long and wide image that is two pixels larger than the input image. The second version of FloodFill needs to use and update the mask, so we must prepare and fill in this mask parameter here. It should be noted that the flood fill will not fill the non-zero pixel area of ​​the mask. E.g,The output of an edge detection operator can be used as a mask to prevent filling to the edge. Similarly, the same mask can be used in multiple function calls to ensure that the filled areas will not overlap. In addition, it should be noted that the mask of the mask will be larger than the image to be filled, so the coordinates of the points in the mask corresponding to the pixels of the input image (x, y) are (x+1, y+1).
  • The third parameter, seedPoint of type Point, is the starting point of the flood filling algorithm.
  • The fourth parameter, the newVal of the Scalar type, the pixel's color value, that is, the new value of the pixel in the redraw area.
  • The fifth parameter, Rect* type rect, has a default value of 0. An optional parameter is used to set the minimum bounding rectangular area of ​​the area that the FloodFill function will redraw.
  • The sixth parameter, the Scalar type of loDiff, has a default value of Scalar( ), which represents the negative difference in brightness or color between the currently observed pixel value and its component neighborhood pixel value or the seed pixel to be added to the component (lower brightness/color difference).
  • The seventh parameter, the ScalD type of upDiff, has a default value of Scalar( ), which represents the positive difference in brightness or color between the currently observed pixel value and the pixel value of its component neighborhood or the seed pixel to be added to the component (lower brightness/color difference).
  • The eighth parameter, flags of int type, operation identifier, this parameter contains three parts, which is more complicated, let's take a closer look.

very hot. I like these tech blogs!

Reply Good karma Bad karma+2 votes
Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.

Follow Profile
Mount & Blade II: Bannerlord
YiGu Studio
Send Message
Release date
Mod watch
Related Games
Related Groups
YiGu Studio
YiGu Studio Developer & Publisher