|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Object common:Generic common:Coloring common:DirectColoring reb:REB_LightingDirect
class
Direct Coloring Lighting with textures and images.
Code modified from Damien M. Jones. Includes options for iteration and height
trapping, and variable transparency as a function of the height value.
class REB_LightingDirect(common.ulb:DirectColoring) { ; Direct Coloring Lighting with textures and images. <br> ; <p> ; Code modified from Damien M. Jones. Includes options for iteration and height ; trapping, and variable transparency as a function of the height value. public: import "common.ulb" import "dmj5.ulb" ; constructor func REB_LightingDirect(Generic pparent) Coloring.Coloring(pparent) m_Texture = new @ftexture(this) m_TrapColor = new @f_trapcolor(this) m_MergeColor = new @f_colormerge(0) endfunc ; initialize the object func Init(complex pz, complex ppixel) Coloring.Init(pz,ppixel) m_Texture.Init(pz) m_TrapColor.Init(pz) m_empty = true endfunc ; call for each iterated point func Iterate(complex pz) Coloring.Iterate(pz) if ((@fiter && m_iterations == @iternum)&& @v_lightingwithtexturesdirect < 104) \ || ((@mtile == "Fixed Iteration" && m_iterations == @iternum2) || \ (@mtile == "Cabs(z)" && cabs(pz) < @tcabs)) ptexture = m_Texture.Iterate(pz) ctexture = m_texture.GetTransformedPoint() if @v_lightingwithtexturesdirect >= 103 && @f_trapcolor != ColorTrapNoColor m_empty = false m_color = m_TrapColor.Iterate(pz) endif endif endfunc ; call in final section of coloring formula/class color func Result(complex pz) color return_color = rgba(0,0,0,0) color temp = rgba(0,0,0,0) if (!@fiter && @v_lightingwithtexturesdirect < 104) || (@mtile == "none" \ && @v_lightingwithtexturesdirect >= 104) ptexture = m_texture.iterate(pz) ctexture = m_texture.GetTransformedPoint() if @f_trapcolor == ColorTrapNoColor m_empty = true else m_color = m_TrapColor.Iterate(pz) m_empty = false endif if @v_lightingwithtexturesdirect >= 102 && m_empty == false if @ahue m_color = hsla(hue(m_color), sat(m_color), lum(m_color), \ hue(m_color)/6*alpha(m_color)) endif if @alum m_color = hsla(hue(m_color), sat(m_color), lum(m_color), \ lum(m_color)*alpha(m_color)) endif if @asat m_color = hsla(hue(m_color), sat(m_color), lum(m_color), \ sat(m_color)*alpha(m_color)) endif endif endif float res=0 float lowtrap=abs(round(real(@itrap)*#maxiter)) float hightrap=abs(round(imag(@itrap)*#maxiter)) if lowtrap>hightrap res=lowtrap lowtrap=hightrap hightrap=res endif if @trapsum lowtrap=real(@itrap) hightrap=imag(@itrap) if lowtrap>hightrap res=lowtrap lowtrap=hightrap hightrap=res endif endif if @utx pz = pz*(1+ctexture*@txamt) endif float vz = -sqrt(1-|pz|) ; extract implied portion of normal float d2r = #pi/180 ; degrees to radians conversion factor ; light origin float lpointx = @lpointx float lpointy = @lpointy float lpointz = @lplane ; light point at float lightx = @lightx float lighty = @lighty float lightz = @lightz ; create vector for light direction float lx = 0 float ly = 0 float lz = 0 if @ltype == "Infinite light" lx = cos((270-@angle)*d2r) * cos(@elevation*d2r) ly = sin((270-@angle)*d2r) * cos(@elevation*d2r) lz = -sin(@elevation*d2r) else lx = lightx-lpointx ly = -lighty+lpointy lz = lightz-lpointz endif float vd = sqrt(lx^2+ly^2+lz^2) lx = lx/vd ly = ly/vd lz = lz/vd ; compute cosine of angle between these vectors ; (this is the amount of lighting on the surface) float l = lx*real(pz) + ly*imag(pz) + lz*vz if (l < @ambient) ; light is below the ambient level l = @ambient ; set it to the ambient level endif if (@ambient < 0) ; the ambient level is negative l = l + 1 ; offset to prevent clipping at 0 endif if !@utx return_color = gradient(l + ptexture*@txamt) else return_color = gradient(l) endif float ht = abs(vz) if @trap m_solid = true if (m_iterations>=lowtrap)&&(m_iterations<=hightrap) m_solid = false endif elseif @trapsum m_solid = true if (ht>=lowtrap)&&(ht<=hightrap) m_solid = false endif endif if @fuzz return_color = rgba(red(return_color),green(return_color),\ blue(return_color),1-ht^@fpwr) endif if !m_empty || @f_trapcolor != ColorTrapNoColor if @nmerge == 1 temp = m_color m_color = return_color return_color = temp endif return_color = m_MergeColor.FullMerge(return_color, m_color, @opacity) endif if @v_lightingwithtexturesdirect >= 105 float br = (0.5-@p_bright)*2 int sign = 0 if br < 0 sign = -1 else sign = 1 endif br = br^2*sign float cr = (@p_contrast-0.5)*2 if cr < 0 sign = -1 else sign = 1 endif cr = cr^2*sign+1 float st = (0.5-@p_sat)*2 if st < 0 sign = -1 else sign = 1 endif st = st^2*sign*2 float hu = @p_hue*6 float rd = red(return_color)-br float gr = green(return_color)-br float bl = blue(return_color)-br if rd > 1 rd = 1 endif if gr > 1 gr = 1 endif if bl > 1 bl = 1 endif if rd < 0 rd = 0 endif if gr < 0 gr = 0 endif if bl < 0 bl = 0 endif return_color = rgba(rd,gr,bl,alpha(return_color)) rd = red(return_color)^cr gr = green(return_color)^cr bl = blue(return_color)^cr return_color = rgba(rd,gr,bl,alpha(return_color)) float satval = sat(return_color)-st if satval > 1 satval = 1 endif if satval < 0 satval = 0 endif return_color = hsla(hue(return_color), satval, lum(return_color), alpha(return_color)) float hueval = (hue(return_color)+hu) % 6 return_color = hsla(hueval, sat(return_color), lum(return_color), alpha(return_color)) if @p_poster float rd = floor(red(return_color)*@p_chan)/@p_chan + 0.5/@p_chan float gr = floor(green(return_color)*@p_chan)/@p_chan + 0.5/@p_chan float bl = floor(blue(return_color)*@p_chan)/@p_chan + 0.5/@p_chan return_color = rgba(rd,gr,bl,alpha(return_color)) endif if @p_gray float gry = 0.3 * red(return_color)+ 0.59 * green(return_color) + 0.11 * blue(return_color) return_color = rgba(gry,gry,gry,alpha(return_color)) endif if @p_solar float rd = red(return_color) float gr = green(return_color) float bl = blue(return_color) if rd > @p_thresh rd = 1-rd endif if gr > @p_thresh gr = 1-gr endif if bl > @p_thresh bl = 1-bl endif return_color = rgba(rd,gr,bl,alpha(return_color)) endif if @p_bw float gry = 0.3 * red(return_color)+ 0.59 * green(return_color) + 0.11 * blue(return_color) if gry < @p_bwt return_color = rgba(0,0,0,alpha(return_color)) else return_color = rgba(1,1,1,alpha(return_color)) endif endif endif return return_color endfunc protected: TrapShape m_Texture ColorTrap m_TrapColor DefaultColorMerge m_MergeColor complex ctexture float ptexture color m_color bool m_empty default: title = "Lighting with Textures Direct" int param v_lightingwithtexturesdirect caption = "Version (Lighting With Textures Direct)" default = 105 hint = "This version parameter is used to detect when a change has been made to the formula that is incompatible with the previous version. When that happens, this field will reflect the old version number to alert you to the fact that an alternate rendering is being used." visible = @v_lightingwithtexturesdirect < 105 endparam heading text = "This is a lighting formula with an iteration trap, a height \ trap, textures and color trap/image import capabilites." endheading heading caption = "Slope Lighting" endheading param ltype caption = "Light type" enum = "Point source" "Infinite light" default = 1 endparam param angle caption = "Light Rotation" default = 90.0 hint = "Gives the rotation of the light source, in degrees." visible=@ltype == "Infinite light" endparam param elevation caption = "Light Elevation" default = 30.0 hint = "Gives the elevation of the light source, in degrees." visible=@ltype == "Infinite light" endparam heading text = "Light Origin" visible=@ltype == "Point source" endheading float param lpointx caption = " X" default = 1.5 visible=@ltype == "Point source" endparam float param lpointy caption = " Y" default = 2 visible=@ltype == "Point source" endparam float param lplane caption = " Z" default = 5 visible=@ltype == "Point source" endparam heading text = "Light Point At" visible=@ltype == "Point source" endheading float param lightx caption = " X" default = 0.0 visible=@ltype == "Point source" endparam float param lighty caption = " Y" default = 0.0 visible=@ltype == "Point source" endparam float param lightz caption = " Z" default = 0.0 visible=@ltype == "Point source" endparam param ambient caption = "Ambient Light" default = 0.0 min = -1.0 max = 1.0 hint = "Specifies the level of ambient light. Use -1.0 to \ color all surfaces." endparam param trap caption="Use Trap by Iteration" default = false endparam param trapsum caption="Use Trap by Height" default = false endparam param itrap caption="Trap Limits" default=(0.0,1.0) hint="Between 0.0 and 1.0" endparam float param txamt caption = "Texture amount" default = 0.0 visible = @fTexture != DMJ_TrapShapeFlat endparam bool param utx caption = "Use Transformed" default = false visible = @fTexture != DMJ_TrapShapeFlat endparam bool param fiter caption = "Use Fixed Iteration" default = false visible = (@fTexture != DMJ_TrapShapeFlat || @f_trapcolor != ColorTrapNoColor) \ && @v_lightingwithtexturesdirect < 104 hint = "Changes the texture and color mapping." endparam int param iternum caption = "Iter number" default = 1 visible = ((@fTexture != DMJ_TrapShapeFlat&& @fiter || @f_trapcolor != \ ColorTrapNoColor) && @fiter)&& @v_lightingwithtexturesdirect < 104 hint = "Changes the texture and color mapping." endparam param mtile caption = "Tile method" default = 0 enum = "None" "Fixed Iteration" "Cabs(z)" visible = (@fTexture != DMJ_TrapShapeFlat || @f_trapcolor != ColorTrapNoColor) \ && @v_lightingwithtexturesdirect >= 104 endparam int param iternum2 caption = "Iter number" default = 1 hint = "Changes the texture/image mapping." visible = ((@fTexture != DMJ_TrapShapeFlat || @f_trapcolor != ColorTrapNoColor) && \ @mtile == "Fixed iteration") && @v_lightingwithtexturesdirect >= 104 endparam float param tcabs caption = "Cabs limit" default = 1.0 hint = "Changes the texture/image mapping." visible = ((@fTexture != DMJ_TrapShapeFlat || @f_trapcolor != ColorTrapNoColor) && \ @mtile == "Cabs(z)") && @v_lightingwithtexturesdirect >= 104 endparam bool param fuzz caption = "Soften edges" default = false hint = "Adjust using 'Height transfer' in the slope formula." endparam float param fpwr caption = "Fuzz power" default = 100 visible = @fuzz endparam TrapShape param fTexture caption = "Texture" default = DMJ_TrapShapeFlat hint = "Use TrapShape plugins as textures." endparam heading caption = "Images and Colorings" endheading ColorTrap param f_trapcolor caption = "Colors" default = ColorTrapNoColor expanded = false hint = "A trap shape that is used as a color or pattern." endparam DefaultColorMerge param f_colormerge caption = "Color Merge" default = DefaultColorMerge visible = @f_trapcolor != ColorTrapNoColor endparam param nmerge caption = "Merge order" default = 0 enum = "Image on Top" "Image on Bottom" visible = @f_trapcolor != ColorTrapNoColor endparam float param opacity caption = "Merge Opacity" default = 0.2 visible = @f_trapcolor != ColorTrapNoColor endparam heading text = "Make image transparent by: " visible = @v_lightingwithtexturesdirect >= 102 \ && @f_trapcolor != ColorTrapNoColor endheading bool param ahue caption = "Hue value" default = false visible = @v_lightingwithtexturesdirect >= 102 \ && @f_trapcolor != ColorTrapNoColor endparam bool param alum caption = "Luminance value" default = false visible = @v_lightingwithtexturesdirect >= 102 \ && @f_trapcolor != ColorTrapNoColor endparam bool param asat caption = "Saturation value" default = false visible = @v_lightingwithtexturesdirect >= 102 \ && @f_trapcolor != ColorTrapNoColor endparam heading caption = "Special Effects" visible = @v_lightingwithtexturesdirect >= 105 endheading float param p_bright caption = "Brightness" default = 0.5 min = 0 max = 1 visible = @v_lightingwithtexturesdirect >= 105 endparam float param p_contrast caption = "Contrast" default = 0.5 min = 0 max = 1 visible = @v_lightingwithtexturesdirect >= 105 endparam float param p_sat caption = "Saturation" default = 0.5 min = 0 max = 1 visible = @v_lightingwithtexturesdirect >= 105 endparam float param p_hue caption = "Hue" default = 0.0 min = 0 max = 1 visible = @v_lightingwithtexturesdirect >= 105 endparam bool param p_gray caption = "Grayscale" default = false visible = @v_lightingwithtexturesdirect >= 105 endparam bool param p_solar caption = "Solarize" default = false visible = @v_lightingwithtexturesdirect >= 105 endparam float param p_thresh caption = "Threshold" default = 0.5 visible = @v_lightingwithtexturesdirect >= 105 && @p_solar endparam bool param p_poster caption = "Posterize" default = false visible = @v_lightingwithtexturesdirect >= 105 endparam int param p_chan caption = "Colors per channel" default = 4 min = 2 visible = @p_poster && @v_lightingwithtexturesdirect >= 105 endparam bool param p_bw caption = "Black and White" default = false visible = @v_lightingwithtexturesdirect >= 105 endparam float param p_bwt caption = "Threshold" default = 0.5 min = 0 max = 1 visible = @p_bw && @v_lightingwithtexturesdirect >= 105 endparam }
Constructor Summary | |
---|---|
REB_LightingDirect()
|
|
REB_LightingDirect(Generic pparent)
constructor |
Method Summary | |
---|---|
void |
Init(complex pz,
complex ppixel)
initialize the object |
void |
Iterate(complex pz)
call for each iterated point |
color |
Result(complex pz)
call in final section of coloring formula/class |
Methods inherited from class common:DirectColoring |
---|
IsSolid |
Methods inherited from class common:Coloring |
---|
GetPixel, IsGradient |
Methods inherited from class common:Generic |
---|
GetParent |
Methods inherited from class Object |
---|
|
Constructor Detail |
---|
public REB_LightingDirect(Generic pparent)
public REB_LightingDirect()
Method Detail |
---|
public void Init(complex pz, complex ppixel)
Init
in class DirectColoring
pz
- first value for the sequence; for a normal coloring formula, this will be #zppixel
- seed value for the sequence; for a normal coloring formula, this will be #pixelpublic void Iterate(complex pz)
Iterate
in class DirectColoring
pz
- next value in the sequence; corresponds to #z in a coloring formulapublic color Result(complex pz)
Result
in class DirectColoring
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |