Skip to main content
added 143 characters in body
Source Link
Sidar
  • 3.6k
  • 2
  • 17
  • 28

You can do this but it just makes your nodes messy! It's a bit of a messy approach but I'm not aware of any nodes that gives us quick access to surrounding pixels:

  1. Create const floats ( name them wRatio and hRatio ) and set their values to:
    wRatio : 1.0/texture width
    hRatio: 1.0/texture height

If you want to hit pixel center offset the texture ( or add it to w/hRatio ) by half of wRatio and hRatio.

  1. Create a TexCoord node

  2. Create a BreakOutFloatComponent and attach the TexCoord output to it.

  3. With our new data we now need to Create 9 new (3x3, you can do 16 but do you really want to?) 2d Vectors. The ouput is set by their offset based on the wRatio and hRation. for example {-wRatio,-hRatio} is the top left pixel of the 3x3 setup. Combine the BreakOutFloatComponent with your ratios using add math nodes. Make sure to negate any ratio first by multiplying by -1 using a math multiply node to get the correct coordinate. R output with wRatio and G with hRatio.

  4. Use the append node to combine the new u and v coordinates into a new vector 2d. Repeat this for every offset.

  5. Use each result to sample from the texture as uv input. For this create 9 Texture Sample nodes and connect each offset respectively.

  6. Add all of the color outputs together with the math add node and then divide them by 9 with the math divide node. This is your average color.

Here is the setup for average of 2 lookups average of 2

You can see that this will be a nightmare if you go up in sample count.

Alternatively you can also use a custom expression : https://docs.unrealengine.com/en-us/Engine/Rendering/Materials/ExpressionReference/Custom

Requires you to write some hlsl but the syntax for such function is actually very easy. The blur example points you in the right direction.

You can do this but it just makes your nodes messy! It's a bit of a messy approach but I'm not aware of any nodes that gives us quick access to surrounding pixels:

  1. Create const floats ( name them wRatio and hRatio ) and set their values to:
    wRatio : 1.0/texture width
    hRatio: 1.0/texture height

If you want to hit pixel center offset the texture ( or add it to w/hRatio ) by half of wRatio and hRatio.

  1. Create a TexCoord node

  2. Create a BreakOutFloatComponent and attach the TexCoord output to it.

  3. With our new data we now need to Create 9 new (3x3, you can do 16 but do you really want to?) 2d Vectors. The ouput is set by their offset based on the wRatio and hRation. for example {-wRatio,-hRatio} is the top left pixel of the 3x3 setup. Combine the BreakOutFloatComponent with your ratios using add math nodes. Make sure to negate any ratio first by multiplying by -1 using a math multiply node to get the correct coordinate. R output with wRatio and G with hRatio.

  4. Use the append node to combine the new u and v coordinates into a new vector 2d. Repeat this for every offset.

  5. Use each result to sample from the texture as uv input. For this create 9 Texture Sample nodes and connect each offset respectively.

  6. Add all of the color outputs together with the math add node and then divide them by 9 with the math divide node. This is your average color.

Here is the setup for average of 2 lookups average of 2

You can see that this will be a nightmare if you go up in sample count.

Alternatively you can also use a custom expression : https://docs.unrealengine.com/en-us/Engine/Rendering/Materials/ExpressionReference/Custom

You can do this but it just makes your nodes messy! It's a bit of a messy approach but I'm not aware of any nodes that gives us quick access to surrounding pixels:

  1. Create const floats ( name them wRatio and hRatio ) and set their values to:
    wRatio : 1.0/texture width
    hRatio: 1.0/texture height

If you want to hit pixel center offset the texture ( or add it to w/hRatio ) by half of wRatio and hRatio.

  1. Create a TexCoord node

  2. Create a BreakOutFloatComponent and attach the TexCoord output to it.

  3. With our new data we now need to Create 9 new (3x3, you can do 16 but do you really want to?) 2d Vectors. The ouput is set by their offset based on the wRatio and hRation. for example {-wRatio,-hRatio} is the top left pixel of the 3x3 setup. Combine the BreakOutFloatComponent with your ratios using add math nodes. Make sure to negate any ratio first by multiplying by -1 using a math multiply node to get the correct coordinate. R output with wRatio and G with hRatio.

  4. Use the append node to combine the new u and v coordinates into a new vector 2d. Repeat this for every offset.

  5. Use each result to sample from the texture as uv input. For this create 9 Texture Sample nodes and connect each offset respectively.

  6. Add all of the color outputs together with the math add node and then divide them by 9 with the math divide node. This is your average color.

Here is the setup for average of 2 lookups average of 2

You can see that this will be a nightmare if you go up in sample count.

Alternatively you can also use a custom expression : https://docs.unrealengine.com/en-us/Engine/Rendering/Materials/ExpressionReference/Custom

Requires you to write some hlsl but the syntax for such function is actually very easy. The blur example points you in the right direction.

Source Link
Sidar
  • 3.6k
  • 2
  • 17
  • 28

You can do this but it just makes your nodes messy! It's a bit of a messy approach but I'm not aware of any nodes that gives us quick access to surrounding pixels:

  1. Create const floats ( name them wRatio and hRatio ) and set their values to:
    wRatio : 1.0/texture width
    hRatio: 1.0/texture height

If you want to hit pixel center offset the texture ( or add it to w/hRatio ) by half of wRatio and hRatio.

  1. Create a TexCoord node

  2. Create a BreakOutFloatComponent and attach the TexCoord output to it.

  3. With our new data we now need to Create 9 new (3x3, you can do 16 but do you really want to?) 2d Vectors. The ouput is set by their offset based on the wRatio and hRation. for example {-wRatio,-hRatio} is the top left pixel of the 3x3 setup. Combine the BreakOutFloatComponent with your ratios using add math nodes. Make sure to negate any ratio first by multiplying by -1 using a math multiply node to get the correct coordinate. R output with wRatio and G with hRatio.

  4. Use the append node to combine the new u and v coordinates into a new vector 2d. Repeat this for every offset.

  5. Use each result to sample from the texture as uv input. For this create 9 Texture Sample nodes and connect each offset respectively.

  6. Add all of the color outputs together with the math add node and then divide them by 9 with the math divide node. This is your average color.

Here is the setup for average of 2 lookups average of 2

You can see that this will be a nightmare if you go up in sample count.

Alternatively you can also use a custom expression : https://docs.unrealengine.com/en-us/Engine/Rendering/Materials/ExpressionReference/Custom