Announcement

Collapse
No announcement yet.

Determining correct falloff

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #46
    Here's a "Material Library" for the lazy people out there who does not want to use OSL.

    LinearFalloff_vray.zip

    Click image for larger version

Name:	fqxugXh.jpg
Views:	1
Size:	287.2 KB
ID:	855907 Look into his eyes !
    Last edited by dubcat; 23-04-2015, 09:56 AM.

    Comment


    • #47
      Originally posted by jackieteh View Post
      Hi Rens, i go to the cgtalk post but cannot find the script you have mention here?
      Hi Jackie, maybe I just mentioned it. The full script is in backup somewhere but I've rewritten most of it yesterday evening, I'll post it later today.
      Rens Heeren
      Generalist
      WEBSITE - IMDB - LINKEDIN - OSL SHADERS

      Comment


      • #48
        Originally posted by dubcat View Post
        Here's a "Material Library" for the lazy people out there who does not want to use OSL.

        [ATTACH]23913[/ATTACH]

        [ATTACH=CONFIG]23914[/ATTACH] Look into his eyes !
        Doesn't appear to be anything in the material Library....
        Maxscript made easy....
        davewortley.wordpress.com
        Follow me here:
        facebook.com/MaxMadeEasy

        If you don't MaxScript, then have a look at my blog and learn how easy and powerful it can be.

        Comment


        • #49
          Ok here we go, I've modified the OSL texture posted earlier so it accepts a bitmap to drive the reflection colour.
          I've attached the OSL, my script to generate reflection gradient bitmaps, and two gradient examples.

          Usage:
          1. create a reflection gradient bitmap using rh_fresnelGradient_v001.ms
          2. load in the bitmap with gamma 1.0 as the gradientBitmap in the OSL tex.
          3. Place this OSL texture as your reflection map in your (V-Ray) material.
          4. Switch off Fresnel in the material as the bitmap already has the Fresnel information.


          Also, the fresnel script comes with working polarisation and an adjustable outside medium IOR value (for underwater!!). Suitable for metals and non-metals.
          Attached Files
          Rens Heeren
          Generalist
          WEBSITE - IMDB - LINKEDIN - OSL SHADERS

          Comment


          • #50
            And the scripts as text.

            OSL gradient driver:
            Code:
            /* 
            bitmapFalloff_v001
            created 2015-04-23 by Rens Heeren
            mail@rensheeren.com
            
            Linear falloff code by Wobi/Vlado:
            http://forums.chaosgroup.com/showthread.php?82438-Determining-correct-falloff/page2
            
            This is a simple OSL tex that will allow you to use a linear bitmap gradient as the texture to drive a reflection.
            Usage (V-Ray):
            1. create a reflection gradient bitmap using rh_fresnelGradient_v001.ms
            2. load in the bitmap with gamma 1.0 as the gradientBitmap.
            3. Place this OSL texture as your reflection map in your (V-Ray) material.
            4. Switch off Fresnel in the material as the bitmap already has the Fresnel information.
            
            */
            
            
            
            shader bitmapFalloff_v001
            (
                   string gradientBitmap = "",
                   output color Col_Out = color(0.5)
            )
            {
                   float fPos = acos (1.0 - (1 - (dot(normalize(N), normalize(I))* -1)))/(M_PI * 0.5);
                   color cColor = texture(gradientBitmap, fPos, 0);
                   Col_Out = cColor;
            }
            Maxscript reflection bitmap creator:
            Code:
            /*
            Complex Fresnel Gradient v001
            Created 2015-04-23 - Rens Heeren
            mail@rensheeren.com
            
            History:
            2015-04-23 - first version (rh)
            
            Creates a gradient bitmap for use in the reflection slot of a material. 
            Left = 0 degrees, right = 90 degrees from normal incidence, linear
            
            It allows for a different IOR for the first medium, usually this would be air with IOR 1.0. With a 
            different IOR you could for example simulate materials under water.
            Polarisation is also supported, 0 = parallel, 1 = perpendicular, 0.5 unpolarised, maybe of interest if you'd like to simulate 
            polarisation filters.
            
            Fresnel function based in part on David Bergström's mathlab code, link unknown.
            
            http://refractiveindex.info/ example Gold:
            Red / 650nm / #FF0000
            Green / 532nm / #00FF00
            Blue / 473nm / #0000FF
            NR = 0.18309
            KR = 3.4241
            NG = 0.54410
            KG = 2.1404
            NB = 1.1715
            KB = 1.7544
             */
            
            -- DIALOG CLOSE
            
            try (destroyDialog rltCxFrGrad)
            catch()
            
            
            -- DEF
            
            iBHeight = 30
            iBWidth = 800
            
            aCols = #()
            
            fn fnCxFresnel fNA fNB fKB fInDeg fPol =
            (
            
            	/* testing
            	fInDeg = 45.
            	fNA = 1.0
            	fNB = .27
            	fKB = 2.77 
            	fPol = 0.5
            	*/
            
            	fSinDeg = sin fInDeg
            	fCosDeg = cos fInDeg
            	fTanDeg = tan fInDeg
            
            	fSinDeg2 = fSinDeg * fSinDeg
            	fCosDeg2 = fCosDeg * fCosDeg
            	fTanDeg2 = fTanDeg * fTanDeg
            
            	fNA2 = fNA * fNA
            	fNB2 = fNB * fNB
            	fKB2 = fKB * fKB
            
            	f1 = (fNB2 - fKB2 - fNA2 * fSinDeg2)
            	fP = sqrt (.5 * (sqrt ((pow f1 2) + 4 * fNB2 * fKB2) + f1))
            	fQ = sqrt (.5* (sqrt ((pow f1 2) + 4 * fNB2 * fKB2) - f1))
            	fS = ((pow (fNA * fCosDeg - fP) 2.0) + fQ * fQ) / ((pow (fNA * fCosDeg + fP) 2) + fQ * fQ)
            	fR = ((pow (fP - fNA * fSinDeg * fTanDeg) 2) + fQ * fQ) / ((pow (fP + fNA * fSinDeg * fTanDeg) 2.0) + fQ * fQ) * fS
            	fOut = (fS * fPol) + (fR * (1-fPol))
            	fOut
            )
            
            
            /* fn fnSetPixels oBitmap p2Pos aCols =
            (
            	setPixels oBitmap p2Pos aCols
            ) */
            
            
            -- ROLLOUT
            
            rollout rltCxFrGrad "RH Fresnel Gradient v001"
            (
            	label lblRed "Red" align:#left
            	spinner spnNAR "N Outside:" range:[-50.0,50.0,1.0] type:#float across:3
            	spinner spnNBR "N:" range:[-50.0,50.0,1.331] type:#float 
            	spinner spnKBR "K:" range:[-50.0,50.0,0.0] type:#float
            	
            	label lbGreen "Green" align:#left
            	spinner spnNAG "N Outside:" range:[-50.0,50.0,1.0] type:#float across:3
            	spinner spnNBG "N:" range:[-50.0,50.0,1.334] type:#float 
            	spinner spnKBG "K:" range:[-50.0,50.0,0.0] type:#float
            	
            	label lblBlue "Blue" align:#left
            	spinner spnNAB "N Outside:" range:[-50.0,50.0,1.0] type:#float across:3
            	spinner spnNBB "N:" range:[-50.0,50.0,1.336] type:#float 
            	spinner spnKBB "K:" range:[-50.0,50.0,0.0] type:#float
            	
            	label lblEmpty1 ""
            	
            	spinner spnPol "Polarization:" range:[0.0,1.0,.5] type:#float align:#left
            	
            	label lblEmpty2 ""
            	
            	spinner spnWidth "Width:" range:[0,5000,800] type:#integer across:2 align:#left
            	spinner spnHeight "Height:" range:[0,5000,30] type:#integer align:#left
            	
            	label lblEmpty3 ""
            	
            	button btnCreate "Create Bitmap"
            	
            	on btnCreate pressed do
            	(
            		
            		
            		/* 		
            		n = 0
            		fNAR = 1.0
            		fNBR = 1.333
            		fKBR = 0.0
            		*/
            		
            		fNAR = spnNAR.value
            		fNBR = spnNBR.value
            		fKBR = spnKBR.value
            		
            		fNAG = spnNAG.value
            		fNBG = spnNBG.value
            		fKBG = spnKBG.value
            		
            		fNAB = spnNAB.value
            		fNBB = spnNBB.value
            		fKBB = spnKBB.value
            		
            		fPol = spnPol.value
            		
            		iBWidth = spnWidth.value
            		iBHeight = spnHeight.value
            		
            		oBitmap = bitmap iBWidth iBHeight gamma:1.0 hdr:true --color:cCol 
            		
            		aCols = #()
            		
            		for n = 0 to (iBWidth-1) do 
            		(
            			fColR = (fnCxFresnel fNAR fNBR fKBR (n*(1./(iBWidth-1))*90) fPol)*255
            			fColG = (fnCxFresnel fNAG fNBG fKBG (n*(1./(iBWidth-1))*90) fPol)*255
            			fColB = (fnCxFresnel fNAB fNBB fKBB (n*(1./(iBWidth-1))*90) fPol)*255
            			--fCol = n*(1./(iBWidth-1))*255
            			cCol = color fColR fColG fColB
            			append aCols cCol
            		)
            
            		for i = 0 to (iBHeight-1) do
            		(
            			p2Pos = [0,i]
            			setPixels oBitmap p2Pos aCols
            		)
            
            		display oBitmap
            	)
            	)
            
            	
            -- DIALOG OPEN
            	
            createDialog rltCxFrGrad 350 300
            Rens Heeren
            Generalist
            WEBSITE - IMDB - LINKEDIN - OSL SHADERS

            Comment


            • #51
              In Max:

              Click image for larger version

Name:	fresnelgradient_screen1.JPG
Views:	2
Size:	78.6 KB
ID:	855911Click image for larger version

Name:	fresnelgradient_screen2.JPG
Views:	1
Size:	20.9 KB
ID:	855912
              Rens Heeren
              Generalist
              WEBSITE - IMDB - LINKEDIN - OSL SHADERS

              Comment


              • #52
                It'd be great if they just wrote in maxscript access to create flags on the gradient ramp or access to the vertices in the output map wouldn't it

                Comment


                • #53
                  I have literally never felt more stupid than I have reading this thread

                  *sits in corner & faces wall*
                  MDI Digital
                  moonjam

                  Comment


                  • #54
                    Originally posted by AJ Jefferies View Post
                    I have literally never felt more stupid than I have reading this thread

                    *sits in corner & faces wall*
                    The more you know, the more you know you don't know :/

                    Comment


                    • #55
                      Originally posted by joconnell View Post
                      It'd be great if they just wrote in maxscript access to create flags on the gradient ramp or access to the vertices in the output map wouldn't it
                      Oh yeah I wanted to link to your script as well:
                      http://forums.chaosgroup.com/showthr...pany-ref/page2

                      And yes that would be really great.
                      Rens Heeren
                      Generalist
                      WEBSITE - IMDB - LINKEDIN - OSL SHADERS

                      Comment


                      • #56
                        Noooo, don't link to mine - it's inflexible nonsense compared to the osl or your script

                        Comment


                        • #57
                          Originally posted by joconnell View Post
                          Noooo, don't link to mine - it's inflexible nonsense compared to the osl or your script
                          Oh, well, too late now.
                          Rens Heeren
                          Generalist
                          WEBSITE - IMDB - LINKEDIN - OSL SHADERS

                          Comment


                          • #58
                            Hey there,

                            Are you aware of the fact, that there is a complex fresnel shader written by Vlado, which you can find here:

                            http://docs.chaosgroup.com/display/O...resnel+shader#

                            You just type in the n and k values and there you go. Rendering a gradient with maxscript, saving, loading, putting it into the OSL seems a bit overcomplicated to me...

                            The intention of the original OSL-Shader by me was that you can just put that map into a falloff/output texture and use your reflection curves from refractive-index, as Grant Warwick and many others do for long time. The only difference is, that the OSL corrects the curve to be what it should have been since using this technique...

                            cheers Ben

                            Comment


                            • #59
                              Hi Ben,

                              Yes, I have another OSL shader like that. The gradient is more visual and quicker to render, but yes more complicated to set up initially. The gradient replaces the curves, and yes I've been using the same technique for many years.

                              Sorry if I hijacked the thread!
                              Last edited by Rens; 23-04-2015, 08:47 AM.
                              Rens Heeren
                              Generalist
                              WEBSITE - IMDB - LINKEDIN - OSL SHADERS

                              Comment


                              • #60
                                Hey Rens,

                                I didn't mean to offend you. So no need to feel sorry. Anyway, what I think would be nice to have would be something like this:
                                Click image for larger version

Name:	Refl_Curve_UI.jpg
Views:	1
Size:	39.2 KB
ID:	855915

                                It's a mix of setting artist-friendly 0-Degree-Color and the UI of the Arch&Design-Material. So you can visualize the curve right away, while still not having to work with these unfriendly output-curve of max.
                                Of course, this is just a 5-Minute PhotoShop-UI and lacks many other aspects, e.g. setting n+k values. But this woud speed up working with these curves and color values for me.
                                Maybe something like this could be implemented with a mix of scripted texturemap, OSL-Shader and Dotnet-UI... but well... I'm drifting away...

                                PS: the values in there don't make sense... just a photoshop-quickie as I said...

                                Comment

                                Working...
                                X