Jump to content

Ray marching Volume


Lutojar

Recommended Posts

I trying make ray-marching volume shader in VEX. I want use it to create Volume Light Effect as i use in RenderMan in Maya.

I take simple example of RSL code without any patterns

volume smoke (

float density = 60;

float integstart = 0, integend = 1000;

float stepsize = 0.1;

float debug = 0;

color scatter = 1;   /* for sky, try (1, 2.25, 21) */

float lightscale = 15;

)

{
point Worigin = P - I;
vector incident = vtransform ("shader", I);
point origin = transform ("shader", Worigin);
vector IN, WIN;
float tau;
color Cv = 0, Ov = 0;		   /* net color & opacity of volume */
color dC, dO;				   /* differential color & opacity */
float ss, dtau, last_dtau;
color li, last_li, lighttau;
color scat;
point PP, PW;
float f, i;

  float end = min (length (incident), integend) - 0.0001;

  /* Integrate forwards from the start point */
float d = integstart + random()*stepsize;
 if (d < end) {
	IN = normalize (incident);
	WIN = vtransform ("shader", "current", IN);
	dtau = 0;
	li = 0;
	ss = min (stepsize, end-d);
	d += ss;

	  while (d <= end) {
		 PP = origin + d*IN; 
		 PW = Worigin + d*WIN;
		 last_dtau = dtau;
		 last_li = li;

		 li = 0;
		 illuminance (PW, vector(0,0,1), PI) { li += Cl; }

		 dtau = density;

		  /* Our goal now is to find dC and dO, the color and opacity
		  * of the portion of the volume covered by this step.
		 */

		 tau = .5 * ss * (dtau + last_dtau);
		 lighttau = .5 * ss * (li*dtau + last_li*last_dtau);

		 scat = -tau * scatter;
		 dO = 1 - color (exp(comp(scat,0)), exp(comp(scat,1)), exp(comp(scat,2)));
		 dC = lighttau * dO;

		  /* Now we adjust Cv/Ov to account for dC and dO */
		  Cv += (1-Ov)*dC;
		  Ov += (1-Ov)*dO;

		  ss = max (min (ss, end-d), 0.005);
		  d += ss;
	 }
 }

  Ci = lightscale*Cv + (1-Ov)*Ci;
  Oi = Ov + (1-Ov)*Oi;

}

I make It in VEX builder and assign to Fog Object (as usual for volume shaders)

but it is no effect there

Does anybody can show me example of Ray Marchin Volume shader for Mantra?

my scene:

Volume_RayMarching.zip

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...