blubee

08-12-2015, 10:46 PM

I wrote a simple program to draw a mandelbrot set in the fragment shader, it's currently using a uniform float as it's scale factor which allows a certain degree of zoom ability but then the image quality deteriorates really badly and I can't get to some of the more interesting places in the set.

I was wondering is it possible to use large fixed point values and send them into the fragment shader?

I would need a really large factional part and only 1 or 2 bits for decimal since it'll be around 1 to -1.[0000000000...]

I might be approaching the problem wrong I am unsure that's why I am asking here. How can I send such large numbers to the fragment shader? I noticed that I am able to do logical shifts in the fragment shader so 1<<30 or 1>>30 both work.

I am just unsure how to put it together. Here's the fragment shader btw.

#version 330 core

in vec4 fcolor;

in vec2 fTexCoord;

in vec2 fCoord;

uniform int maxIterations;

uniform sampler1D mandiTexture;

uniform vec2 center;

uniform float scale;

out vec4 color;

void main()

{

float ONE_OVER_LOG_TWO = 1.0f/0.69314718055f;

vec2 c, z;

vec4 colora, colorb;

c.x = (fCoord.x * scale) + center.x;

c.y = (fCoord.y * scale) + center.y;

int i;

z = vec2(0.0f, 0.0f);

float size, smoothed, colorI;

for(i=0; i< maxIterations; i++) {

float x = (z.x * z.x - z.y * z.y) + c.x;

float y = (z.y * z.x + z.x * z.y) + c.y;

if((x * x + y * y) > (1 << 30))

{

break;

}

z.x = x;

z.y = y;

}

vec4 tcolor;

if (i == maxIterations)

{

tcolor = vec4(0.0f, 0.0f, 0.0f, 1.0f);

}

else

{

float tr, tg, tb;

float t = float(i)/float(maxIterations);

tr = (9*(1-t)*t*t*t);

tg = (15*(1-t)*(1-t)*t*t);

tb = (8.5*(1-t)*(1-t)*(1-t)*t);

tcolor = vec4(tr, tg, tb, 1.0f);

}

color = tcolor;

}

I was wondering is it possible to use large fixed point values and send them into the fragment shader?

I would need a really large factional part and only 1 or 2 bits for decimal since it'll be around 1 to -1.[0000000000...]

I might be approaching the problem wrong I am unsure that's why I am asking here. How can I send such large numbers to the fragment shader? I noticed that I am able to do logical shifts in the fragment shader so 1<<30 or 1>>30 both work.

I am just unsure how to put it together. Here's the fragment shader btw.

#version 330 core

in vec4 fcolor;

in vec2 fTexCoord;

in vec2 fCoord;

uniform int maxIterations;

uniform sampler1D mandiTexture;

uniform vec2 center;

uniform float scale;

out vec4 color;

void main()

{

float ONE_OVER_LOG_TWO = 1.0f/0.69314718055f;

vec2 c, z;

vec4 colora, colorb;

c.x = (fCoord.x * scale) + center.x;

c.y = (fCoord.y * scale) + center.y;

int i;

z = vec2(0.0f, 0.0f);

float size, smoothed, colorI;

for(i=0; i< maxIterations; i++) {

float x = (z.x * z.x - z.y * z.y) + c.x;

float y = (z.y * z.x + z.x * z.y) + c.y;

if((x * x + y * y) > (1 << 30))

{

break;

}

z.x = x;

z.y = y;

}

vec4 tcolor;

if (i == maxIterations)

{

tcolor = vec4(0.0f, 0.0f, 0.0f, 1.0f);

}

else

{

float tr, tg, tb;

float t = float(i)/float(maxIterations);

tr = (9*(1-t)*t*t*t);

tg = (15*(1-t)*(1-t)*t*t);

tb = (8.5*(1-t)*(1-t)*(1-t)*t);

tcolor = vec4(tr, tg, tb, 1.0f);

}

color = tcolor;

}