AnKor
Topic Author
Posts: 21
Joined: 22 Jul 2022, 16:14

BrushShader and CroppedBitmap tiling

10 Sep 2022, 10:52

Looks like I managed to stumble upon a case that isn't supported (yet?).

I wanted to use an image from an atlas, tile it, and also change its color with a BrushShader.
And I found out that BrushShader works fine with either CroppedBitmap or tiling, but not both at the same time.

I'll probably just avoid CroppedBitmap for such scenarios, but is there anything I can do to make it work or the solution is simply "don't do this"? :)

(uses Nature.png from here https://www.noesisengine.com/xamltoy/71 ... a731aa1861 )
<Grid
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:noesis="clr-namespace:NoesisGUIExtensions;assembly=Noesis.GUI.Extensions">
  <Grid.Resources>
    <BitmapImage x:Key="src" UriSource="Nature.png" />
    <CroppedBitmap x:Key="Cropped" Source="{StaticResource src}" SourceRect="240,100,200,150"  />
  </Grid.Resources>
  <StackPanel Orientation="Vertical" HorizontalAlignment="Center">
    <Label>Shader and Tile</Label>
            <Rectangle Width="360" Height="240">
              <Rectangle.Fill>
                <ImageBrush ImageSource="{StaticResource Cropped}" TileMode="Tile" Viewport="0,0,0.5,0.5" >
                  <noesis:Brush.Shader>
                    <noesis:MonochromeBrushShader Color="White"/>
                  </noesis:Brush.Shader>
                </ImageBrush>
              </Rectangle.Fill>
            </Rectangle>
    <Decorator Height="30" />
    <Label>No Shader</Label>
            <Rectangle Width="360" Height="240">
              <Rectangle.Fill>
                <ImageBrush ImageSource="{StaticResource Cropped}" TileMode="Tile" Viewport="0,0,0.5,0.5" />
              </Rectangle.Fill>
            </Rectangle>
    <Decorator Height="30" />
    <Label>No Tile</Label>
            <Rectangle Width="360" Height="240">
              <Rectangle.Fill>
                <ImageBrush ImageSource="{StaticResource Cropped}" >
                  <noesis:Brush.Shader>
                    <noesis:MonochromeBrushShader Color="White"/>
                  </noesis:Brush.Shader>
                </ImageBrush>
              </Rectangle.Fill>
            </Rectangle>
    </StackPanel>
</Grid>
 
User avatar
jsantos
Site Admin
Posts: 3925
Joined: 20 Jan 2012, 17:18
Contact:

Re: BrushShader and CroppedBitmap tiling

12 Sep 2022, 18:26

This is a limitation of the current architecture to avoid increasing the numbers of shaders needed per custom brush. When you implement a custom brush, as you discover, you don't receive the clamping/tiling rectangle. You are suppose to implement this with extra parameters in your shader. Note that CroppedBitmap will always work and send the correct UV to the shader.

We don't have immediate plans to change this, as there isn't a obvious solution but if you want to open a ticket about this we will be more than happy to review the current state at some point.
 
AnKor
Topic Author
Posts: 21
Joined: 22 Jul 2022, 16:14

Re: BrushShader and CroppedBitmap tiling

12 Sep 2022, 19:54

Thanks!
Indeed I can store the coordinates in the constant buffer. Somehow it didn't occur to me :)

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 7 guests