Samplercube background

  • 7 Replies
  • 260 Views

0 Members and 1 Guest are viewing this topic.

Offline 3DickUlus

  • *
  • 3f
  • ******
  • Posts: 1710
    • Digilantism
« on: November 15, 2018, 05:55:14 AM »
Using sampler cube for skybox background and transparency effects

Add these...
#define providesBackground
#define providesColor
...before
#include "DE-Raytracer.frag"

after ^ add this...
Code: [Select]
#group Skybox
uniform samplerCube skybox; file[cubemap.png]
vec3  backgroundColor(vec3 dir) {
float t = length(from-dir);
    return mix(textureCube(skybox, dir.xzy).rgb, BackgroundColor, 1.0-exp(-pow(Fog,4.0)*t*t));
}

uniform float RefractiveIndex; slider[0,1,10]
vec3 baseColor(vec3 point, vec3 N){
    float ratio = 1.00 / RefractiveIndex;
    vec3 I = (point - from);
    vec3 R = refract(I, N, ratio);
    return textureCube(skybox, R.xzy).rgb;
}

the cubemap.png file goes in the Examples/Include folder

with that file in place and using the default mandelbulb.frag and raytracer.frag you should be able to drag and drop the small png screenshots onto Fragmentarium to apply the settings and reproduce the images

from there it will be easy to hack into other frags ;)

the EXR package includes exrEnvMap command, in the FragM/bin folder, converts OpenEXR latitude-longitude (FragM equirectangular) environment maps into cube-face environment maps or vice versa.


Linkback: https://fractalforums.org/code-snippets-fragments/74/samplercube-background/2300/
« Last Edit: November 15, 2018, 06:06:58 AM by 3DickUlus »

Offline claude

  • *
  • 3f
  • ******
  • Posts: 1535
    • mathr.co.uk
« Reply #1 on: November 18, 2018, 02:04:32 AM »
I couldn't get this to work at all (using Raymond).  Texture just gives black 0.0s as if no texture was not loaded.  Do I need to set some texture parameters?  Like to disable mipmapping or similar?

Loading the same cubemap texture into a sampler2D gives me non-black output, but the mapping is wrong as to be expected.  I suppose I could try the equirectangular for now - how to set X repeat Y norepeat for the sampler?

Code: [Select]
#group Skybox
// cube map texture for background
uniform samplerCube CubeMap; file[../images/Paris.cube.png]
// distance from origin at which the cube map is drawn
uniform float Distance; slider[0,100,1000]

float Background_intensity(Ray V)
{
  vec3 tex = texture(CubeMap, normalize(V.origin.xzy)).rgb;
  return tex.g; // temp hack for testing, still black
  vec3 rgb = sRGB2linear(tex);
  vec3 img = rgb2xyz(rgb);
  vec3 ray = observer(V.wavelength);
  return max(0.0, dot(img, ray)); // FIXME
}

Offline claude

  • *
  • 3f
  • ******
  • Posts: 1535
    • mathr.co.uk
« Reply #2 on: November 18, 2018, 02:43:37 AM »
Even sample2D textures work only sometimes, but then sometimes gives a black image.  Not sure what is going on, very unpredictable, very frustrating...

Offline 3DickUlus

  • *
  • 3f
  • ******
  • Posts: 1710
    • Digilantism
« Reply #3 on: November 18, 2018, 03:59:59 AM »
you can add texture parameters like...
Code: [Select]
uniform sampler2D myTexture; file[test.png]
#TexParameter myTexture GL_TEXTURE_MAX_LEVEL 1000
#TexParameter myTexture GL_TEXTURE_WRAP_S GL_REPEAT
#TexParameter myTexture GL_TEXTURE_WRAP_T GL_REPEAT
#TexParameter myTexture GL_TEXTURE_MAG_FILTER GL_LINEAR
#TexParameter myTexture GL_TEXTURE_MIN_FILTER GL_LINEAR_MIPMAP_LINEAR
... when adding texture parameters the above set is the minimum (also the defaults when none are specified iirc).

I have no problems with textures here, seems to work perfectly using nVidia card and drivers ???

2 things, what's in the log window? and can you send me the Raymond files and frag you're working with?

Offline claude

  • *
  • 3f
  • ******
  • Posts: 1535
    • mathr.co.uk
« Reply #4 on: November 18, 2018, 04:51:48 AM »
never mind, I think I had crashed my GPU drivers into an inconsistent state (linux 4.18.18 amdgpu.dc=0) by running a superheavy frag that exceeded some hard kernel time limit earlier, after a reboot (and being careful to set buffer to 1/6 window size before building..) everything is working fine again.  there were lots of messages in dmesg but I forgot to save them before rebooting, one (after each timeout was reported) said something about "drm GPU recovery disabled".

edit here's some logs of the exact messages (the seq numbers change each time):
Code: [Select]
[42234.934432] [drm:amdgpu_job_timedout [amdgpu]] *ERROR* ring gfx timeout, last signaled seq=1789752, last emitted seq=1789754
[42234.934437] [drm] GPU recovery disabled.
[42294.838218] [drm:amdgpu_job_timedout [amdgpu]] *ERROR* ring gfx timeout, last signaled seq=1789860, last emitted seq=1789862
[42294.838223] [drm] GPU recovery disabled.


sorry for wasting our time!

Raymond is at http://code.mathr.co.uk/raymond (not pushed the latest changes just yet as I'm still fiddling with it) examples/Mandelbrot.frag
« Last Edit: November 20, 2018, 01:11:48 PM by claude, Reason: logs »

Offline 3DickUlus

  • *
  • 3f
  • ******
  • Posts: 1710
    • Digilantism
« Reply #5 on: November 18, 2018, 05:06:36 AM »
good to hear all is working  :thumbs:

see attached re:texture parameters...

Offline claude

  • *
  • 3f
  • ******
  • Posts: 1535
    • mathr.co.uk
« Reply #6 on: November 20, 2018, 01:06:50 PM »

Offline 3DickUlus

  • *
  • 3f
  • ******
  • Posts: 1710
    • Digilantism
« Reply #7 on: November 26, 2018, 03:24:36 AM »
an update for the BG code... scale, offset, rotation :D
Code: [Select]
#group Skybox
uniform samplerCube skybox; file[cubemap.png]
uniform vec3 bgOffset; slider[(-1,-1,-1),(0,0,0),(1,1,1)]
uniform vec3 bgScale; slider[(-1,-1,-1),(1,-1,1),(1,1,1)]
uniform vec3 bgRotVec; slider[(-1,-1,-1),(0,0,0),(1,1,1)]
uniform float bgRotAngle; slider[-180,0,180]

vec3  backgroundColor(vec3 dir) {
dir *= rotationMatrix3(bgRotVec,bgRotAngle);
if(bgFocus > 0.0)
    dir += vec3(rand2(dir.xy),rand(dir.z));
  float t = length(from-dir);
return mix(textureCube(skybox, bgScale*(dir+bgOffset)).rgb, BackgroundColor, 1.0-exp(-pow(Fog,4.0)*t*t));
}
« Last Edit: November 26, 2018, 03:48:18 AM by 3DickUlus »


clip
background pic

Started by JungleFunk13 on Noob's Corner

5 Replies
233 Views
Last post August 07, 2019, 02:41:43 PM
by Sabine62
clip
Background image

Started by cubsterky on Mandelbulb3d

5 Replies
440 Views
Last post April 18, 2018, 05:48:43 PM
by spain2points
clip
Texturize Foreground and Background of FragM

Started by kosalos on Code Snippets (fragments)

0 Replies
82 Views
Last post November 07, 2019, 12:57:00 AM
by kosalos
clip
OpenCL - pixels, textured background and crashes

Started by Micha1982 on Mandelbulber

8 Replies
517 Views
Last post April 16, 2018, 10:13:46 AM
by Micha1982