Announcement

Collapse
No announcement yet.

Complex fresnel using VRayOSLtex

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

  • Complex fresnel using VRayOSLtex

    Here's an osl texture based on the paper "Artist friendly metallic fresnel" by Ole Gulbrandsen
    http://jcgt.org/published/0003/04/03/

    Usage is: diffuse black, fresnel off, add VRayOSLTex to the reflection map.

    Click image for larger version

Name:	AFMFresnel_gold.jpg
Views:	1
Size:	192.8 KB
ID:	881329 Click image for larger version

Name:	ArtistFriendlyMetallicFresnel_goldPlot.jpg
Views:	1
Size:	34.3 KB
ID:	881330 Click image for larger version

Name:	ArtistFriendlyMetallicFresnel_orangeTintPlot.jpg
Views:	1
Size:	31.9 KB
ID:	881331
    Example scene from vray-materials.de


    OSL texture
    AFMFresnel.zip
    Last edited by R2J2; 13-03-2015, 05:12 PM. Reason: updated file

  • #2
    Looks cool. Looking forward to trying it out.

    And thanks!

    Comment


    • #3
      Wow thats amazing, thank you.
      CGI - Freelancer - Available for work

      www.dariuszmakowski.com - come and look

      Comment


      • #4
        Wow...that's great...is it possible to port this to maya to try it out?
        always curious...

        Comment


        • #5
          you know I thought it would work in maya just the same, I'll have a look on monday.

          Comment


          • #6
            OMG somebody's using OSL - that's supercool

            Thanks for sharing!

            Best regards,
            Vlado
            I only act like I know everything, Rogers.

            Comment


            • #7
              Seems nice,
              How do we use it ?
              I've got a black render and nothing appearing in the shader itself

              Click image for larger version

Name:	SNAG-0051.jpg
Views:	1
Size:	423.7 KB
ID:	855326

              Stan
              3LP Team

              Comment


              • #8
                Same here. And I could have sworn I had OSL working with the thin-film shader that Vlado posted in another thread. That's not working now either.
                Last edited by YoyoBoy; 15-02-2015, 08:54 AM.
                - Geoff

                Comment


                • #9
                  looks like you are using it as an OSL material, it's used with the OSL texture in reflection and regular VRay material.

                  @jasonhuang so the .oso file will load into maya but I had to change the Color Output from result to Col_Out (max did this for me by default)
                  rest is the same, diffuse black and fresnel off as the shader does that work now.

                  Comment


                  • #10
                    Originally posted by R2J2 View Post
                    looks like you are using it as an OSL material, it's used with the OSL texture in reflection and regular VRay material.

                    @jasonhuang so the .oso file will load into maya but I had to change the Color Output from result to Col_Out (max did this for me by default)
                    rest is the same, diffuse black and fresnel off as the shader does that work now.
                    Thanks Jay. Will give that a try!

                    cheers!
                    always curious...

                    Comment


                    • #11
                      Thanks for the OSL Texture. But I'm not really sure how to use it. On the refractiveindex.info site I can find the n and k values for a whole range of materials, but in the texture I can only put in colors, not the values for n and k. Is there a way to convert these numbers to rgb colors?
                      Last edited by kosso_olli; 18-02-2015, 06:57 AM.
                      https://www.behance.net/Oliver_Kossatz

                      Comment


                      • #12
                        Hey OK! Looks like you just put in the values for R,G and B wavelengths respectively, so if you find the data on red for a material you enter that as the R part of the N and K colours, same for G and B. If your scale is 0-255 then just multiply your N,K values by 255.

                        So you look up N,K values for the R,G,B wavelengths and multiply them by 255. Optionally you could rewrite it to accept textures and put a VRayColor map in so you can use the direct values.
                        Rens Heeren
                        Generalist
                        WEBSITE - IMDB - LINKEDIN - OSL SHADERS

                        Comment


                        • #13
                          Rensy-Baby, thanks for the answer. But somehow it doesn't work as expected. Let's take a copper material for example:
                          http://refractiveindex.info/?shelf=3...ls&page=copper

                          When I type in the average wavelength for the blue component (472nm), the n value is already 1.2335. Obviously I can not multiply that value with 255, because I can't put values greater that 255 into the color slots of the OSL. Same is for the k value.
                          https://www.behance.net/Oliver_Kossatz

                          Comment


                          • #14
                            Ah.. Duh, good point.

                            Here's a quick hack, see if that works:

                            Code:
                            	//--Artist Friendly Metallic Fresnel--
                            	// BY Ole Gulbrandsen - Framestore
                            	//olegul@hotmail.com
                            	//http://jcgt.org/published/0003/04/03/
                            	//OSL version by JayCMiller
                            	//jcmiller.web@gmail.com
                            	//AFfresnel V 0.1 - tested in VRay 3.05.07
                            	// added texture slots - rh
                            	
                            	
                            	float n_min( float r ){
                            		return (1-r )/(1+ r );
                            	}
                            	float n_max( float r ){
                            		return (1+ sqrt ( r ))/(1- sqrt ( r ));
                            	}
                            	float get_n ( float r , float g){
                            		return n_min( r )*g + (1-g)*n_max( r );
                            	}
                            	float get_k2 ( float r , float n){
                            	float nr = (n+1)*(n+1)*r-(n-1)*(n-1);
                            		return nr/(1-r );
                            	}
                            	float get_r ( float n, float k){
                            		return ((n-1)*(n-1)+k*k )/(( n+1)*(n+1)+k*k);
                            	}
                            	float get_g ( float n, float k){
                            	float r = get_r (n,k);
                            		return (n_max( r)-n )/( n_max( r)-n_min( r ));
                            	}
                            	float AFMF ( float r , float g, float theta ){
                            	//clamp parameters
                            	float _r = clamp(r ,0 ,0.99);
                            	//compute n and k
                            	float n = get_n (_r ,g);
                            	float k2 = get_k2 (_r ,n);
                            	
                            	float c = cos ( theta );
                            	float rs_num = n*n + k2 - 2*n*c + c*c;
                            	float rs_den = n*n + k2 + 2*n*c + c*c;
                            	float rs = rs_num/ rs_den ;
                            	
                            	float rp_num = (n*n + k2)*c*c - 2*n*c + 1;
                            	float rp_den = (n*n + k2)*c*c + 2*n*c + 1;
                            	float rp = rp_num/ rp_den ;
                            	
                            	return 0.5*( rs+rp );
                            	}
                            	
                            	
                            shader AFMFresnelTex (
                            
                            	string N__ReflectivityTex = "",
                            	string K__EdgetintTex = "",
                            	float Color_Gamma = 2.2,
                            	
                                output color Col_Out = color(0.5)
                            )
                            	
                            {
                            	color N__Reflectivity = texture(N__ReflectivityTex, u, v);
                            	color K__Edgetint = texture(K__EdgetintTex, u, v);
                            	float thetaB = acos(dot(-I,N));
                            	float RCH = AFMF(N__Reflectivity[0],K__Edgetint[0],thetaB);
                            	float GCH = AFMF(N__Reflectivity[1],K__Edgetint[1],thetaB);
                            	float BCH = AFMF(N__Reflectivity[2],K__Edgetint[2],thetaB);
                            
                            	Col_Out = pow(color(RCH,GCH,BCH), Color_Gamma);
                            
                            }
                            Rens Heeren
                            Generalist
                            WEBSITE - IMDB - LINKEDIN - OSL SHADERS

                            Comment


                            • #15
                              Isn't inputting rgb wavelength n and k values exactly what this shader tries to avoid?

                              I understand how to get the reflectivity value from the charts, but how exactly is the edgetint color determined (in layman terms)? Shouldn't it always be white?

                              Comment

                              Working...
                              X