Click here to Skip to main content
15,886,873 members
Articles / Desktop Programming / WPF

Mandelbrot Set with PixelShader in WPF

Rate me:
Please Sign up or sign in to vote.
4.90/5 (42 votes)
23 Jul 2011CPOL7 min read 47.7K   2.9K   38  
This article explains how to use pixel shaders for fast generation of Mandelbrot Sets.
<Window x:Class="ShaderMandelbrot.JuliiWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:my="clr-namespace:ShaderMandelbrot"
        Title="ShaderJulii" Height="350" Width="350"
        WindowStartupLocation="Manual">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <Grid Grid.Row="0" Grid.ColumnSpan="2" x:Name="MandelRoot" SizeChanged="MandelRoot_SizeChanged" Background="White" MouseMove="Grid_MouseMove" MouseDown="MandelRoot_MouseDown" MouseUp="MandelRoot_MouseUp">
            <Grid.Effect>
                <my:JuliiEffect x:Name="m" />
            </Grid.Effect>
        </Grid>
        
        <Grid x:Name="darker" HorizontalAlignment="Left" VerticalAlignment="Top" Background="#55000000" Visibility="Collapsed"
              MouseMove="Grid_MouseMove" MouseUp="MandelRoot_MouseUp"></Grid>

        <Grid x:Name="options" Grid.Row="1" Visibility="Collapsed">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <TextBlock Grid.Row="0" Grid.ColumnSpan="2" Margin="2" Text="MiddleButton translate, LeftButton zoom in, RightButton zoom out." />

            <TextBlock Grid.Row="1" Grid.Column="0" Text="Seed (Real)" Margin="2" TextAlignment="Right" />
            <Slider x:Name="seedR" Grid.Row="1" Grid.Column="1" Minimum="-3" Maximum="3" Value="-1.25" ValueChanged="seedR_ValueChanged" />

            <TextBlock Grid.Row="2" Grid.Column="0" Text="Seed (Imaginary)" Margin="2" TextAlignment="Right" />
            <Slider x:Name="seedI" Grid.Row="2" Grid.Column="1" Minimum="-3" Maximum="3" Value="0" ValueChanged="seedI_ValueChanged" />

            <TextBlock Grid.Row="3" Grid.Column="0" Text="Maximal iteration" Margin="2" TextAlignment="Right" />
            <Slider x:Name="maxIter" Grid.Row="3" Grid.Column="1" Minimum="0" Maximum="100" Value="32" ValueChanged="maxIter_ValueChanged" />

            <TextBlock Grid.Row="4" Grid.Column="0" Text="Power (Real)" Margin="2" TextAlignment="Right" />
            <Slider x:Name="powerR" Grid.Row="4" Grid.Column="1" Minimum="0" Maximum="10" Value="2" ValueChanged="powerR_ValueChanged" />

            <TextBlock Grid.Row="5" Grid.Column="0" Text="Power (Imaginary)" Margin="2" TextAlignment="Right" />
            <Slider x:Name="powerI" Grid.Row="5" Grid.Column="1" Minimum="0" Maximum="10" Value="0" ValueChanged="powerI_ValueChanged" />

            <TextBlock Grid.Row="6" Grid.Column="0" Text="Bailout" Margin="2" TextAlignment="Right" />
            <Slider x:Name="bailout" Grid.Row="6" Grid.Column="1" Minimum="0" Maximum="100" Value="4" ValueChanged="bailout_ValueChanged" />

            <TextBlock Grid.Row="7" Grid.Column="0" Text="Other" Margin="2" TextAlignment="Right" />
            <StackPanel Grid.Row="7" Grid.Column="1" Orientation="Horizontal">
                <Button Click="Button_Click">Reset</Button>
            </StackPanel>
        </Grid>
    </Grid>
</Window>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Poland Poland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions