LDraw.org Discussion Forums

Full Version: LDCad POVray export
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
A couple of observations.

1. slope bricks are not bumpy/grainy like they should be

2. at the POV-Ray newsgroups we came up with some code to add blurred reflections to models:

Code:
// this methoid is slower
#macro BlurredReflectionMicroNormals(InPigment, InFinish, InNormal, BlurAmount, BlurSamples)
//    texture
//    {
        average
        texture_map
        {
            #declare iCount = 0;
            #declare S = seed(0);
            #while (iCount < BlurSamples)
                [
                    1 // The pigment of the object:
                    pigment { InPigment }
                    // The surface finish:
                    finish { InFinish }
                    // This is the actual trick:
                    normal
                    {
                        average
                        normal_map
                        {
                            [1 bumps BlurAmount translate <rand(S),rand(S),rand(S)>*100 scale 0.001]
                            [1 InNormal]
                        }
                    }
                ]
                #declare iCount = iCount + 1;
            #end
        }
//    }
#end



// this method is faster, but requires a focal blur and/or extra antialiasing to smooth out the pixelation
#macro BlurredReflectionSingleNormals(InPigment, InFinish, InNormal, BlurAmount)
//    texture
//    {
        pigment { InPigment }
        finish { InFinish }
        normal { InNormal }
        normal {bumps BlurAmount scale 0.001}
//    }
#end



#if (Use_BlurRef = true)
    #ifndef (Use_BlurAmt) #declare Use_BlurAmt = 0.05; #end                // amount of surface reflection blurring
    #macro ldrawBuildTex(basePigment, baseNormal, baseFinish, pngIdx)
        #if (pngIdx<0)
            BlurredReflectionSingleNormals(basePigment, baseFinish, baseNormal, Use_BlurAmt)
        #else
            texture
            {
                pigment
                {
                    uv_mapping
                    image_map
                    {
                        png getPngName(pngIdx)
                        getPngMapType(pngIdx)
                        interpolate 2
                    }
                    getPngWarp(pngIdx)
                }
            }
            texture
            {
                BlurredReflectionSingleNormals(basePigment, baseFinish, baseNormal, Use_BlurAmt)
            }
        #end
    #end
#else
    #macro ldrawBuildTex(basePigment, baseNormal, baseFinish, pngIdx)
        #if (pngIdx<0)
            pigment { basePigment }
            normal { baseNormal }
            finish { baseFinish }
        #else
            #local texPigment= pigment
            {
                uv_mapping
                image_map
                {
                    png getPngName(pngIdx)
                    getPngMapType(pngIdx)
                    interpolate 2
                }
                getPngWarp(pngIdx)
            }
            #local result = texture
            {
                pigment { basePigment }
                normal { baseNormal }
                finish { baseFinish }
            }
            texture
            {
                pigment { texPigment }
            }
            result
        #end
    #end
#end

Unfortunately, there's no way to differentiate between ABS (solid) and Polycarbonate (clear) plastics. Could you add another column to the `ldColor` array for the `BlurAmount` value, in addition to `ior`? It would be great.

See also:

https://www.eurobricks.com/forum/index.p...e-realism/
http://news.povray.org/povray.binaries.i...ay.org%3E/


Thanks!
(2018-02-17, 21:47)Michael Horvath Wrote: [ -> ]A couple of observations.

1. slope bricks are not bumpy/grainy like they should be

2. at the POV-Ray newsgroups we came up with some code to add blurred reflections to models:

Unfortunately, there's no way to differentiate between ABS (solid) and Polycarbonate (clear) plastics. Could you add another column to the `ldColor` array for the `BlurAmount` value, in addition to `ior`? It would be great.

1:
Those would require .dat changes and an extension to the texture map spec to allow for bump maps or something like that.

2:
You could check on alpha being <1.0  ( ldColor[getColorIndex(ldCode)][4]<1.0 ) for transparent ones.

If you need an extra parameter you could declare an array for mapping the odd ones, e.g.
Code:
#declare ldColorBlurCount=3;        
#declare ldColorBlur=array[ldColorBlurCount][2] {
{2, 0.25},
{7, 0.4},
{256, 0.7}
}      

#macro getColorBlur(ldCode)
#local result=-1
#local i=0;
#while (result=-1 & i<ldColorBlurCount)
 #if (ldColorBlur[i][0]=ldCode)
   #local result=i
 #else
   #local i=i+1;
 #end
#end

#if (result>=0)
  ldColorBlur[i][1];
else //def
  1.0
#end
#end

FYI: did you notice you can apply your modifications to material definitions in the %appdata%/LDCad/povray/default/colors.pov  file to avoid to have to post process each export. Or copy the default map so you can choose which set of scripts to use during export.
(2018-02-18, 21:01)Roland Melkert Wrote: [ -> ]1:
Those would require .dat changes and an extension to the texture map spec to allow for bump maps or something like that.

For some reason I recalled L3P supporting parts with bumps, but this apparently is only true for LGEO parts. My mistake.

(2018-02-18, 21:01)Roland Melkert Wrote: [ -> ]2:
You could check on alpha being <1.0  ( ldColor[getColorIndex(ldCode)][4]<1.0 ) for transparent ones.

If you need an extra parameter you could declare an array for mapping the odd ones, e.g.
Code:
#declare ldColorBlurCount=3;        
#declare ldColorBlur=array[ldColorBlurCount][2] {
{2, 0.25},
{7, 0.4},
{256, 0.7}
}      

#macro getColorBlur(ldCode)
#local result=-1
#local i=0;
#while (result=-1 & i<ldColorBlurCount)
 #if (ldColorBlur[i][0]=ldCode)
   #local result=i
 #else
   #local i=i+1;
 #end
#end

#if (result>=0)
  ldColorBlur[i][1];
else //def
  1.0
#end
#end

Yes, I can make my own array. But I was hoping for official support within LDCad.

(2018-02-18, 21:01)Roland Melkert Wrote: [ -> ]FYI: did you notice you can apply your modifications to material definitions in the %appdata%/LDCad/povray/default/colors.pov  file to avoid to have to post process each export. Or copy the default map so you can choose which set of scripts to use during export.

I already delete all colors from each POV file and simply link to an external INC file with colors in it. I do this for L3P and LDView, as well, so now I can swap between all three whenever I want to in any model.
(2018-02-18, 21:28)Michael Horvath Wrote: [ -> ]Yes, I can make my own array. But I was hoping for official support within LDCad.

I wouldn't know where to get the values from unless they are added to !COLOUR meta's or something.
(2018-02-18, 21:48)Roland Melkert Wrote: [ -> ]
(2018-02-18, 21:28)Michael Horvath Wrote: [ -> ]Yes, I can make my own array. But I was hoping for official support within LDCad.

I wouldn't know where to get the values from unless they are added to !COLOUR meta's or something.

"LDConfig.ldr" does not specify anything other than color, so you must have come up with your own values for `ior`, `reflection`, `diffuse`, `specular`, etc. etc. `BlurAmount` is just one added value. Maybe instead of storing `ior` in the array, you should instead store the material type? E.g. ABS = 1, polycarbonate = 2, rubber = 3, chrome = 4, pearl = 6, metal = 7, etc. etc.

Regardless, you use the `ldrawTexPlastic` macro for both regular plastic bricks and transparent plastic bricks. Since they are two different types of plastics (ABS versus polycarbonate) they should probably use different textures/materials. The POV-Ray newsgroup may be able to offer tips on what values you should use for materials.
(2018-02-18, 23:03)Michael Horvath Wrote: [ -> ]
(2018-02-18, 21:48)Roland Melkert Wrote: [ -> ]I wouldn't know where to get the values from unless they are added to !COLOUR meta's or something.

"LDConfig.ldr" does not specify anything other than color, so you must have come up with your own values for `ior`, `reflection`, `diffuse`, `specular`, etc. etc. `BlurAmount` is just one added value. Maybe instead of storing `ior` in the array, you should instead store the material type? E.g. ABS = 1, polycarbonate = 2, rubber = 3, chrome = 4, pearl = 6, metal = 7, etc. etc.

Regardless, you use the `ldrawTexPlastic` macro for both regular plastic bricks and transparent plastic bricks. Since they are two different types of plastics (ABS versus polycarbonate) they should probably use different textures/materials. The POV-Ray newsgroup may be able to offer tips on what values you should use for materials.

Even if you differentiate between plastics, the refraction still won’t be quite right since the converter makes meshes and not solid geometry.
(2018-02-18, 23:31)Orion Pobursky Wrote: [ -> ]
(2018-02-18, 23:03)Michael Horvath Wrote: [ -> ]"LDConfig.ldr" does not specify anything other than color, so you must have come up with your own values for `ior`, `reflection`, `diffuse`, `specular`, etc. etc. `BlurAmount` is just one added value. Maybe instead of storing `ior` in the array, you should instead store the material type? E.g. ABS = 1, polycarbonate = 2, rubber = 3, chrome = 4, pearl = 6, metal = 7, etc. etc.

Regardless, you use the `ldrawTexPlastic` macro for both regular plastic bricks and transparent plastic bricks. Since they are two different types of plastics (ABS versus polycarbonate) they should probably use different textures/materials. The POV-Ray newsgroup may be able to offer tips on what values you should use for materials.

Even if you differentiate between plastics, the refraction still won’t be quite right since the converter makes meshes and not solid geometry.

I'm talking about blurred reflections, not blurred refractions.

Also, why do you store `ior` info if your geometry is not solid?
(2018-02-18, 23:43)Michael Horvath Wrote: [ -> ]
(2018-02-18, 23:31)Orion Pobursky Wrote: [ -> ]Even if you differentiate between plastics, the refraction still won’t be quite right since the converter makes meshes and not solid geometry.

I'm talking about blurred reflections, not blurred refractions.

Light transmittal through the material affects the reflection. Also, reflection should be more of a function of material smoothness and not plastic type.
(2018-02-18, 23:50)Orion Pobursky Wrote: [ -> ]
(2018-02-18, 23:43)Michael Horvath Wrote: [ -> ]I'm talking about blurred reflections, not blurred refractions.

Light transmittal through the material affects the reflection. Also, reflection should be more of a function of material smoothness and not plastic type.

Sorry, I got you and Roland mixed up earlier. I think LDCad output meshes *are* solid, which is why `ior` (index of refraction) is specified for transparent parts. (Otherwise there would generally not be a point in specifying `ior`.) Also, Roland *already* does differentiate between types of plastic by specifying different `ior` values for transparent and non-transparent parts. He just doesn't do this for finishes as well.

[ed. correction: there is no `ior` specified for non-transparent parts.]

Anyway, blurred reflections don't look realistic on transparent parts. Something has to be done about this.
(2018-02-19, 1:50)Michael Horvath Wrote: [ -> ]Sorry, I got you and Roland mixed up earlier. I think LDCad output meshes *are* solid, which is why `ior` (index of refraction) is specified for transparent parts.

No they aren’t. Nothing that is a mesh is. This is why I started the LDraw POV project. Admittedly, I have no idea if it makes a huge difference and, if there is a noticeable difference, if it is worth the trouble for non-high res renders.
Pages: 1 2