(forget to staged modified files)
This commit is contained in:
parent
8493a2f6d5
commit
995fde8d9c
|
@ -56,6 +56,7 @@ enum DISPLAY3D_FLG {
|
|||
FL_RENDER_RAYTRACING_REFLECTIONS,
|
||||
FL_RENDER_RAYTRACING_POST_PROCESSING,
|
||||
FL_RENDER_RAYTRACING_ANTI_ALIASING,
|
||||
FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES,
|
||||
FL_LAST
|
||||
};
|
||||
|
||||
|
|
|
@ -144,14 +144,18 @@ inline float mapf( float x,
|
|||
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||
}
|
||||
|
||||
inline float RGBtoGray( const SFVEC3F &aColor )
|
||||
{
|
||||
return (aColor.r * 0.2126f +
|
||||
aColor.g * 0.7152f +
|
||||
aColor.b * 0.0722f);
|
||||
}
|
||||
|
||||
inline SFVEC3F MaterialDiffuseToColorCAD( const SFVEC3F &aDiffuseColor )
|
||||
{
|
||||
// convert to a discret scale of grays
|
||||
const float luminance = glm::min( (((float)((unsigned int) ( 4.0f *
|
||||
(aDiffuseColor.r * 0.2126f +
|
||||
aDiffuseColor.g * 0.7152f +
|
||||
aDiffuseColor.b * 0.0722f))) + 0.5f) /
|
||||
RGBtoGray( aDiffuseColor ) ) ) + 0.5f) /
|
||||
4.0f) * 1.0f,
|
||||
1.0f );
|
||||
|
||||
|
|
|
@ -49,95 +49,162 @@
|
|||
// JAVA IMPLEMENTATION OF THE IMPROVED PERLIN FUNCTION (see http://mrl.nyu.edu/~perlin/noise/)
|
||||
// THE ORIGINAL JAVA IMPLEMENTATION IS COPYRIGHT 2002 KEN PERLIN
|
||||
|
||||
// I ADDED AN EXTRA METHOD THAT GENERATES A NEW PERMUTATION VECTOR (THIS IS NOT PRESENT IN THE ORIGINAL IMPLEMENTATION)
|
||||
// I ADDED AN EXTRA METHOD THAT GENERATES A NEW PERMUTATION VECTOR
|
||||
// (THIS IS NOT PRESENT IN THE ORIGINAL IMPLEMENTATION)
|
||||
|
||||
// Initialize with the reference values for the permutation vector
|
||||
PerlinNoise::PerlinNoise()
|
||||
{
|
||||
|
||||
// Initialize the permutation vector with the reference values
|
||||
p = {
|
||||
151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,
|
||||
8,99,37,240,21,10,23,190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,
|
||||
35,11,32,57,177,33,88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,
|
||||
134,139,48,27,166,77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,
|
||||
55,46,245,40,244,102,143,54, 65,25,63,161,1,216,80,73,209,76,132,187,208, 89,
|
||||
18,169,200,196,135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,
|
||||
250,124,123,5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,
|
||||
189,28,42,223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167,
|
||||
43,172,9,129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,
|
||||
97,228,251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,
|
||||
107,49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254,
|
||||
138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180 };
|
||||
// Duplicate the permutation vector
|
||||
p.insert(p.end(), p.begin(), p.end());
|
||||
|
||||
// Initialize the permutation vector with the reference values
|
||||
p = {
|
||||
151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,
|
||||
8,99,37,240,21,10,23,190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,
|
||||
35,11,32,57,177,33,88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,
|
||||
134,139,48,27,166,77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,
|
||||
55,46,245,40,244,102,143,54, 65,25,63,161,1,216,80,73,209,76,132,187,208, 89,
|
||||
18,169,200,196,135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,
|
||||
250,124,123,5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,
|
||||
189,28,42,223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167,
|
||||
43,172,9,129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,
|
||||
97,228,251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,
|
||||
107,49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254,
|
||||
138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180 };
|
||||
|
||||
// Duplicate the permutation vector
|
||||
p.insert(p.end(), p.begin(), p.end());
|
||||
}
|
||||
|
||||
// Generate a new permutation vector based on the value of seed
|
||||
PerlinNoise::PerlinNoise( unsigned int seed )
|
||||
{
|
||||
p.resize( 256 );
|
||||
p.resize( 256 );
|
||||
|
||||
// Fill p with values from 0 to 255
|
||||
std::iota( p.begin(), p.end(), 0 );
|
||||
// Fill p with values from 0 to 255
|
||||
std::iota( p.begin(), p.end(), 0 );
|
||||
|
||||
// Initialize a random engine with seed
|
||||
std::default_random_engine engine( seed );
|
||||
// Initialize a random engine with seed
|
||||
std::default_random_engine engine( seed );
|
||||
|
||||
// Suffle using the above random engine
|
||||
std::shuffle( p.begin(), p.end(), engine );
|
||||
// Suffle using the above random engine
|
||||
std::shuffle( p.begin(), p.end(), engine );
|
||||
|
||||
// Duplicate the permutation vector
|
||||
p.insert(p.end(), p.begin(), p.end());
|
||||
// Duplicate the permutation vector
|
||||
p.insert( p.end(), p.begin(), p.end() );
|
||||
}
|
||||
|
||||
float PerlinNoise::noise(float x, float y, float z)
|
||||
float PerlinNoise::noise( float x, float y, float z ) const
|
||||
{
|
||||
// Find the unit cube that contains the point
|
||||
int X = (int) floor(x) & 255;
|
||||
int Y = (int) floor(y) & 255;
|
||||
int Z = (int) floor(z) & 255;
|
||||
// Find the unit cube that contains the point
|
||||
int X = (int) ((float)floor( x )) & 255;
|
||||
int Y = (int) ((float)floor( y )) & 255;
|
||||
int Z = (int) ((float)floor( z )) & 255;
|
||||
|
||||
// Find relative x, y,z of point in cube
|
||||
x -= floor( x );
|
||||
y -= floor( y );
|
||||
z -= floor( z );
|
||||
// Find relative x, y,z of point in cube
|
||||
x -= (float)floor( x );
|
||||
y -= (float)floor( y );
|
||||
z -= (float)floor( z );
|
||||
|
||||
// Compute fade curves for each of x, y, z
|
||||
float u = fade( x );
|
||||
float v = fade( y );
|
||||
float w = fade( z );
|
||||
// Compute fade curves for each of x, y, z
|
||||
const float u = fade( x );
|
||||
const float v = fade( y );
|
||||
const float w = fade( z );
|
||||
|
||||
// Hash coordinates of the 8 cube corners
|
||||
int A = p[X] + Y;
|
||||
int AA = p[A] + Z;
|
||||
int AB = p[A + 1] + Z;
|
||||
int B = p[X + 1] + Y;
|
||||
int BA = p[B] + Z;
|
||||
int BB = p[B + 1] + Z;
|
||||
// Hash coordinates of the 8 cube corners
|
||||
const int A = p[X] + Y;
|
||||
const int AA = p[A] + Z;
|
||||
const int AB = p[A + 1] + Z;
|
||||
const int B = p[X + 1] + Y;
|
||||
const int BA = p[B] + Z;
|
||||
const int BB = p[B + 1] + Z;
|
||||
|
||||
// Add blended results from 8 corners of cube
|
||||
float res = lerp( w, lerp( v, lerp( u, grad( p[AA], x, y, z), grad(p[BA], x-1, y, z)), lerp(u, grad(p[AB], x, y-1, z), grad(p[BB], x-1, y-1, z))), lerp(v, lerp(u, grad(p[AA+1], x, y, z-1), grad(p[BA+1], x-1, y, z-1)), lerp(u, grad(p[AB+1], x, y-1, z-1), grad(p[BB+1], x-1, y-1, z-1))));
|
||||
return (res + 1.0)/2.0;
|
||||
// Add blended results from 8 corners of cube
|
||||
const float res = lerp( w,
|
||||
lerp( v,
|
||||
lerp( u,
|
||||
grad( p[AA], x , y, z),
|
||||
grad( p[BA], x - 1, y, z) ),
|
||||
lerp( u,
|
||||
grad( p[AB], x , y - 1, z ),
|
||||
grad( p[BB], x - 1, y - 1, z) ) ),
|
||||
lerp( v,
|
||||
lerp( u,
|
||||
grad( p[AA + 1], x , y, z - 1 ),
|
||||
grad( p[BA + 1], x - 1, y, z - 1) ),
|
||||
lerp( u,
|
||||
grad( p[AB + 1], x , y - 1, z - 1 ),
|
||||
grad( p[BB + 1], x - 1, y - 1, z - 1 ) ) ) );
|
||||
|
||||
return (res + 1.0f) / 2.0f;
|
||||
}
|
||||
|
||||
float PerlinNoise::fade( float t )
|
||||
{
|
||||
return t * t * t * (t * (t * 6 - 15) + 10);
|
||||
}
|
||||
|
||||
float PerlinNoise::lerp( float t, float a, float b )
|
||||
{
|
||||
return a + t * (b - a);
|
||||
}
|
||||
|
||||
float PerlinNoise::grad( int hash, float x, float y, float z )
|
||||
float PerlinNoise::noise( float x, float y ) const
|
||||
{
|
||||
int h = hash & 15;
|
||||
// Find the unit cube that contains the point
|
||||
int X = (int) ((float)floor( x )) & 255;
|
||||
int Y = (int) ((float)floor( y )) & 255;
|
||||
|
||||
// Convert lower 4 bits of hash inot 12 gradient directions
|
||||
float u = h < 8 ? x : y,
|
||||
v = h < 4 ? y : h == 12 || h == 14 ? x : z;
|
||||
|
||||
return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v);
|
||||
// Find relative x, y,z of point in cube
|
||||
x -= (float)floor( x );
|
||||
y -= (float)floor( y );
|
||||
|
||||
// Compute fade curves for each of x, y
|
||||
const float u = fade( x );
|
||||
const float v = fade( y );
|
||||
|
||||
// Hash coordinates of the 8 cube corners
|
||||
const int A = p[X] + Y;
|
||||
const int AA = p[A] + 0;
|
||||
const int AB = p[A + 1] + 0;
|
||||
const int B = p[X + 1] + Y;
|
||||
const int BA = p[B] + 0;
|
||||
const int BB = p[B + 1] + 0;
|
||||
|
||||
// Add blended results from 8 corners of cube
|
||||
const float res = lerp( v,
|
||||
lerp( u,
|
||||
grad( p[AA], x , y ),
|
||||
grad( p[BA], x - 1, y ) ),
|
||||
lerp( u,
|
||||
grad( p[AB], x , y - 1 ),
|
||||
grad( p[BB], x - 1, y - 1 ) ) );
|
||||
|
||||
return (res + 1.0f) / 2.0f;
|
||||
}
|
||||
|
||||
|
||||
float PerlinNoise::fade( float t ) const
|
||||
{
|
||||
return t * t * t * (t * (t * 6.0f - 15.0f) + 10.0f);
|
||||
}
|
||||
|
||||
|
||||
float PerlinNoise::lerp( float t, float a, float b ) const
|
||||
{
|
||||
return a + t * (b - a);
|
||||
}
|
||||
|
||||
|
||||
float PerlinNoise::grad( int hash, float x, float y, float z ) const
|
||||
{
|
||||
const int h = hash & 15;
|
||||
|
||||
// Convert lower 4 bits of hash inot 12 gradient directions
|
||||
const float u = h < 8 ? x : y;
|
||||
const float v = h < 4 ? y : h == 12 || h == 14 ? x : z;
|
||||
|
||||
return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v);
|
||||
}
|
||||
|
||||
|
||||
float PerlinNoise::grad( int hash, float x, float y ) const
|
||||
{
|
||||
const int h = hash & 15;
|
||||
|
||||
// Convert lower 4 bits of hash inot 12 gradient directions
|
||||
const float u = h < 8 ? x : y;
|
||||
const float v = h < 4 ? y : h == 12 || h == 14 ? x : 0.0f;
|
||||
|
||||
return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v);
|
||||
}
|
||||
|
|
|
@ -32,11 +32,12 @@
|
|||
* Original copyright notice:
|
||||
*
|
||||
* Perlin_Noise
|
||||
* Here you could find the code for "Perlin noise in C++11", for more informations visit the project webpage:
|
||||
* "Here you could find the code for "Perlin noise in C++11",
|
||||
* for more informations visit the project webpage:
|
||||
* http://solarianprogrammer.com/2012/07/18/perlin-noise-cpp-11/
|
||||
* You could use this program under the terms of GPL v3, for more details see:
|
||||
* http://www.gnu.org/copyleft/gpl.html
|
||||
* Copyright 2012 Sol from www.solarianprogrammer.com
|
||||
* Copyright 2012 Sol from www.solarianprogrammer.com"
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
|
@ -45,28 +46,33 @@
|
|||
// JAVA IMPLEMENTATION OF THE IMPROVED PERLIN FUNCTION (see http://mrl.nyu.edu/~perlin/noise/)
|
||||
// THE ORIGINAL JAVA IMPLEMENTATION IS COPYRIGHT 2002 KEN PERLIN
|
||||
|
||||
// I ADDED AN EXTRA METHOD THAT GENERATES A NEW PERMUTATION VECTOR (THIS IS NOT PRESENT IN THE ORIGINAL IMPLEMENTATION)
|
||||
// I ADDED AN EXTRA METHOD THAT GENERATES A NEW PERMUTATION VECTOR
|
||||
// (THIS IS NOT PRESENT IN THE ORIGINAL IMPLEMENTATION)
|
||||
|
||||
#ifndef PERLINNOISE_H
|
||||
#define PERLINNOISE_H
|
||||
|
||||
class PerlinNoise {
|
||||
// The permutation vector
|
||||
std::vector<int> p;
|
||||
class PerlinNoise
|
||||
{
|
||||
// The permutation vector
|
||||
std::vector<int> p;
|
||||
|
||||
public:
|
||||
// Initialize with the reference values for the permutation vector
|
||||
PerlinNoise();
|
||||
// Initialize with the reference values for the permutation vector
|
||||
PerlinNoise();
|
||||
|
||||
// Generate a new permutation vector based on the value of seed
|
||||
PerlinNoise( unsigned int seed );
|
||||
// Generate a new permutation vector based on the value of seed
|
||||
PerlinNoise( unsigned int seed );
|
||||
|
||||
// Get a noise value, for 2D images z can have any value
|
||||
float noise( float x, float y, float z );
|
||||
// Returns between 0.0f and 1.0f
|
||||
float noise( float x, float y, float z ) const;
|
||||
float noise( float x, float y ) const;
|
||||
|
||||
private:
|
||||
float fade( float t );
|
||||
float lerp( float t, float a, float b );
|
||||
float grad( int hash, float x, float y, float z );
|
||||
float fade( float t ) const;
|
||||
float lerp( float t, float a, float b ) const;
|
||||
float grad( int hash, float x, float y, float z ) const;
|
||||
float grad( int hash, float x, float y ) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -54,33 +54,37 @@
|
|||
|
||||
void C3D_RENDER_RAYTRACING::setupMaterials()
|
||||
{
|
||||
m_board_normal_perturbator = CBOARDNORMAL( 1.25f * IU_PER_MM * m_settings.BiuTo3Dunits() );
|
||||
m_copper_normal_perturbator = CCOPPERNORMAL( &m_board_normal_perturbator );
|
||||
m_solder_mask_normal_perturbator = CSOLDERMASKNORMAL( &m_copper_normal_perturbator );
|
||||
|
||||
if( m_settings.GetFlag( FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES ) )
|
||||
{
|
||||
m_board_normal_perturbator = CBOARDNORMAL( 0.5f * IU_PER_MM * m_settings.BiuTo3Dunits() );
|
||||
|
||||
m_copper_normal_perturbator = CCOPPERNORMAL( 4.0f * IU_PER_MM * m_settings.BiuTo3Dunits(),
|
||||
&m_board_normal_perturbator );
|
||||
|
||||
m_solder_mask_normal_perturbator = CSOLDERMASKNORMAL( &m_board_normal_perturbator );
|
||||
|
||||
m_plastic_normal_perturbator = CPLASTICNORMAL( 0.15f * IU_PER_MM * m_settings.BiuTo3Dunits() );
|
||||
|
||||
m_plastic_shine_normal_perturbator = CPLASTICSHINENORMAL( 1.0f * IU_PER_MM * m_settings.BiuTo3Dunits() );
|
||||
}
|
||||
|
||||
// http://devernay.free.fr/cours/opengl/materials.html
|
||||
|
||||
// Copper
|
||||
|
||||
// This guess the material type(ex: copper vs gold) to determine the
|
||||
// shininess factor between 0.1 and 0.4
|
||||
float shininessfactor = 0.40f - mapf( fabs( m_settings.m_CopperColor.r -
|
||||
m_settings.m_CopperColor.g ),
|
||||
0.15f, 1.00f,
|
||||
0.00f, 0.30f );
|
||||
|
||||
m_materials.m_Copper = CBLINN_PHONG_MATERIAL(
|
||||
(SFVEC3F)m_settings.m_CopperColor * (SFVEC3F)(0.28f), // ambient
|
||||
(SFVEC3F)m_settings.m_CopperColor * (SFVEC3F)(0.18f), // ambient
|
||||
SFVEC3F( 0.0f, 0.0f, 0.0f ), // emissive
|
||||
glm::clamp( ((SFVEC3F)(1.0f) -
|
||||
(SFVEC3F)m_settings.m_CopperColor),
|
||||
SFVEC3F( 0.0f ),
|
||||
SFVEC3F( 0.45f ) ), // specular
|
||||
shininessfactor * 128.0f, // shiness
|
||||
SFVEC3F( 0.35f ) ), // specular
|
||||
0.4f * 128.0f, // shiness
|
||||
0.0f, // transparency
|
||||
0.0f );
|
||||
|
||||
m_materials.m_Copper.SetNormalPerturbator( &m_copper_normal_perturbator );
|
||||
if( m_settings.GetFlag( FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES ) )
|
||||
m_materials.m_Copper.SetNormalPerturbator( &m_copper_normal_perturbator );
|
||||
|
||||
m_materials.m_Paste = CBLINN_PHONG_MATERIAL(
|
||||
(SFVEC3F)m_settings.m_SolderPasteColor *
|
||||
|
@ -117,7 +121,8 @@ void C3D_RENDER_RAYTRACING::setupMaterials()
|
|||
|
||||
m_materials.m_SolderMask.SetCastShadows( true );
|
||||
|
||||
m_materials.m_SolderMask.SetNormalPerturbator( &m_solder_mask_normal_perturbator );
|
||||
if( m_settings.GetFlag( FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES ) )
|
||||
m_materials.m_SolderMask.SetNormalPerturbator( &m_solder_mask_normal_perturbator );
|
||||
|
||||
m_materials.m_EpoxyBoard = CBLINN_PHONG_MATERIAL(
|
||||
SFVEC3F( 16.0f / 255.0f,
|
||||
|
@ -131,7 +136,8 @@ void C3D_RENDER_RAYTRACING::setupMaterials()
|
|||
0.10f, // transparency
|
||||
0.0f ); // reflection
|
||||
|
||||
m_materials.m_EpoxyBoard.SetNormalPerturbator( &m_board_normal_perturbator );
|
||||
if( m_settings.GetFlag( FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES ) )
|
||||
m_materials.m_EpoxyBoard.SetNormalPerturbator( &m_board_normal_perturbator );
|
||||
|
||||
SFVEC3F bgTop = (SFVEC3F)m_settings.m_BgColorTop;
|
||||
//SFVEC3F bgBot = (SFVEC3F)m_settings.m_BgColorBot;
|
||||
|
@ -255,9 +261,9 @@ void C3D_RENDER_RAYTRACING::reload( REPORTER *aStatusTextReporter )
|
|||
|
||||
// This will work as the front camera light.
|
||||
const float light_camera_intensity = 0.15;
|
||||
const float light_directional_intensity_top = 0.2;
|
||||
const float light_directional_intensity_top = 0.30;
|
||||
const float light_directional_intensity = ( 1.0f - ( light_camera_intensity +
|
||||
light_directional_intensity_top ) ) / 2.0f;
|
||||
light_directional_intensity_top ) ) / 4.0f;
|
||||
|
||||
m_camera_light = new CDIRECTIONALLIGHT( SFVEC3F( 0.0f, 0.0f, 0.0f ),
|
||||
SFVEC3F( light_camera_intensity ) );
|
||||
|
@ -1306,18 +1312,52 @@ void C3D_RENDER_RAYTRACING::add_3D_models( const S3DMODEL *a3DModel,
|
|||
{
|
||||
const SMATERIAL &material = a3DModel->m_Materials[imat];
|
||||
|
||||
float reflectionFactor = glm::clamp( material.m_Shininess *
|
||||
0.75f - 0.125f,
|
||||
0.0f,
|
||||
1.0f );
|
||||
const float reflectionFactor = glm::clamp( material.m_Shininess *
|
||||
0.75f - 0.125f,
|
||||
0.0f,
|
||||
1.0f );
|
||||
|
||||
(*materialVector)[imat] = CBLINN_PHONG_MATERIAL(
|
||||
CBLINN_PHONG_MATERIAL &blinnMaterial = (*materialVector)[imat];
|
||||
|
||||
blinnMaterial = CBLINN_PHONG_MATERIAL(
|
||||
material.m_Ambient,
|
||||
material.m_Emissive,
|
||||
material.m_Specular,
|
||||
material.m_Shininess * 180.0f,
|
||||
material.m_Transparency,
|
||||
reflectionFactor );
|
||||
|
||||
if( m_settings.GetFlag( FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES ) )
|
||||
{
|
||||
// Guess material type and apply a normal perturbator
|
||||
|
||||
if( ( RGBtoGray(material.m_Diffuse) < 0.3f ) &&
|
||||
( material.m_Shininess < 0.36f ) &&
|
||||
( material.m_Transparency == 0.0f ) &&
|
||||
( (glm::abs( material.m_Diffuse.r - material.m_Diffuse.g ) < 0.15f) &&
|
||||
(glm::abs( material.m_Diffuse.b - material.m_Diffuse.g ) < 0.15f) &&
|
||||
(glm::abs( material.m_Diffuse.r - material.m_Diffuse.b ) < 0.15f) ) )
|
||||
{
|
||||
// This may be a black plastic..
|
||||
|
||||
if( material.m_Shininess < 0.26f )
|
||||
blinnMaterial.SetNormalPerturbator( &m_plastic_normal_perturbator );
|
||||
else
|
||||
blinnMaterial.SetNormalPerturbator( &m_plastic_shine_normal_perturbator );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( ( RGBtoGray(material.m_Diffuse) > 0.3f ) &&
|
||||
( material.m_Shininess < 0.30f ) &&
|
||||
( material.m_Transparency == 0.0f ) &&
|
||||
( (glm::abs( material.m_Diffuse.r - material.m_Diffuse.g ) > 0.25f) ||
|
||||
(glm::abs( material.m_Diffuse.b - material.m_Diffuse.g ) > 0.25f) ||
|
||||
(glm::abs( material.m_Diffuse.r - material.m_Diffuse.b ) > 0.25f) ) )
|
||||
{
|
||||
blinnMaterial.SetNormalPerturbator( &m_plastic_shine_normal_perturbator );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -1988,13 +1988,10 @@ SFVEC3F C3D_RENDER_RAYTRACING::shadeHit( const SFVEC3F &aBgColor,
|
|||
if( aRecursiveLevel > 2 )
|
||||
return SFVEC3F( 0.0f );
|
||||
|
||||
SFVEC3F hitPoint;
|
||||
SFVEC3F hitPoint = aHitInfo.m_HitPoint;
|
||||
|
||||
if( m_isPreview )
|
||||
hitPoint = aRay.at( aHitInfo.m_tHit );
|
||||
else
|
||||
hitPoint = aRay.at( aHitInfo.m_tHit ) +
|
||||
aHitInfo.m_HitNormal * ( 0.5f * m_settings.GetNonCopperLayerThickness3DU() *
|
||||
if( !m_isPreview )
|
||||
hitPoint += aHitInfo.m_HitNormal * ( 0.5f * m_settings.GetNonCopperLayerThickness3DU() *
|
||||
glm::abs(Fast_RandFloat()) +
|
||||
0.5f * m_settings.GetNonCopperLayerThickness3DU() );
|
||||
|
||||
|
|
|
@ -99,6 +99,8 @@ private:
|
|||
CBOARDNORMAL m_board_normal_perturbator;
|
||||
CCOPPERNORMAL m_copper_normal_perturbator;
|
||||
CSOLDERMASKNORMAL m_solder_mask_normal_perturbator;
|
||||
CPLASTICNORMAL m_plastic_normal_perturbator;
|
||||
CPLASTICSHINENORMAL m_plastic_shine_normal_perturbator;
|
||||
|
||||
bool m_isPreview;
|
||||
|
||||
|
|
|
@ -74,6 +74,17 @@ CMATERIAL::CMATERIAL( const SFVEC3F &aAmbient,
|
|||
}
|
||||
|
||||
|
||||
void CMATERIAL::PerturbeNormal( SFVEC3F &aNormal,
|
||||
const RAY &aRay,
|
||||
const HITINFO &aHitInfo ) const
|
||||
{
|
||||
if( m_normal_perturbator )
|
||||
{
|
||||
aNormal = aNormal + m_normal_perturbator->Generate( aRay, aHitInfo );
|
||||
aNormal = glm::normalize( aNormal );
|
||||
}
|
||||
}
|
||||
|
||||
// This may be a good value if based on nr of lights
|
||||
// that contribute to the illumination of that point
|
||||
#define AMBIENT_FACTOR (1.0f / 6.0f)
|
||||
|
@ -137,19 +148,22 @@ CBOARDNORMAL::CBOARDNORMAL( float aScale ) : CPROCEDURALGENERATOR()
|
|||
|
||||
SFVEC3F CBOARDNORMAL::Generate( const RAY &aRay, const HITINFO &aHitInfo ) const
|
||||
{
|
||||
const SFVEC3F hitPos = aRay.at( aHitInfo.m_tHit );
|
||||
const SFVEC3F &hitPos = aHitInfo.m_HitPoint;
|
||||
|
||||
// http://www.fooplot.com/#W3sidHlwZSI6MCwiZXEiOiJzaW4oc2luKHgpKjEuNykrMSIsImNvbG9yIjoiIzAwMDAwMCJ9LHsidHlwZSI6MTAwMCwid2luZG93IjpbIi0wLjk2MjEwNTcwODA3ODUyNjIiLCI3Ljk3MTQyNjI2NzYwMTQzIiwiLTIuNTE3NjIwMzUxNDgyNDQ5IiwiMi45Nzk5Mzc3ODczOTc1MzAzIl0sInNpemUiOls2NDgsMzk4XX1d
|
||||
// http://www.fooplot.com/#W3sidHlwZSI6MCwiZXEiOiJzaW4oc2luKHNpbih4KSoxLjkpKjEuNSkiLCJjb2xvciI6IiMwMDAwMDAifSx7InR5cGUiOjEwMDAsIndpbmRvdyI6WyItMC45NjIxMDU3MDgwNzg1MjYyIiwiNy45NzE0MjYyNjc2MDE0MyIsIi0yLjUxNzYyMDM1MTQ4MjQ0OSIsIjIuOTc5OTM3Nzg3Mzk3NTMwMyJdLCJzaXplIjpbNjQ2LDM5Nl19XQ--
|
||||
|
||||
return SFVEC3F( ((float)glm::sin( glm::sin(hitPos.x * m_scale ) ) + 1.0f) * 0.15f,
|
||||
((float)glm::sin( glm::sin(hitPos.y * m_scale ) ) + 1.0f) * 0.07f,
|
||||
0.0f );
|
||||
const float x = (glm::sin(glm::sin( glm::sin( hitPos.x * m_scale ) * 1.9f ) * 1.5f ) + 0.0f) * 0.10f;
|
||||
const float y = (glm::sin(glm::sin( glm::sin( hitPos.y * m_scale ) * 1.9f ) * 1.5f ) + 0.0f) * 0.04f;
|
||||
|
||||
return SFVEC3F( x, y, 0.0f );
|
||||
}
|
||||
|
||||
|
||||
CCOPPERNORMAL::CCOPPERNORMAL( const CBOARDNORMAL *aBoardNormalGenerator )
|
||||
CCOPPERNORMAL::CCOPPERNORMAL( float aScale, const CPROCEDURALGENERATOR *aBoardNormalGenerator )
|
||||
{
|
||||
m_board_normal_generator = aBoardNormalGenerator;
|
||||
m_copper_perlin = PerlinNoise( 0 );
|
||||
m_scale = 1.0f / aScale;
|
||||
}
|
||||
|
||||
|
||||
|
@ -159,25 +173,87 @@ SFVEC3F CCOPPERNORMAL::Generate( const RAY &aRay, const HITINFO &aHitInfo ) cons
|
|||
{
|
||||
const SFVEC3F boardNormal = m_board_normal_generator->Generate( aRay, aHitInfo );
|
||||
|
||||
return boardNormal * SFVEC3F(0.75f);
|
||||
SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale;
|
||||
|
||||
const float noise = (m_copper_perlin.noise( hitPos.x + Fast_RandFloat() * 0.1f,
|
||||
hitPos.y ) - 0.5f) * 2.0f;
|
||||
|
||||
float scratchPattern = (m_copper_perlin.noise( hitPos.x / 100.0f, hitPos.y * 20.0f ) - 0.5f);
|
||||
|
||||
scratchPattern = glm::clamp( scratchPattern * 5.0f, -1.0f, 1.0f );
|
||||
|
||||
const float x = glm::clamp( (noise + scratchPattern) * 0.04f, -0.10f, 0.10f );
|
||||
const float y = glm::clamp( (noise + (noise * scratchPattern)) * 0.04f, -0.10f, 0.10f );
|
||||
|
||||
return SFVEC3F( x, y, 0.0f ) + boardNormal * 0.85f;
|
||||
}
|
||||
else
|
||||
return SFVEC3F(0.0f);
|
||||
}
|
||||
|
||||
CSOLDERMASKNORMAL::CSOLDERMASKNORMAL( const CCOPPERNORMAL *aCopperNormalGenerator )
|
||||
|
||||
CSOLDERMASKNORMAL::CSOLDERMASKNORMAL( const CPROCEDURALGENERATOR *aCopperNormalGenerator )
|
||||
{
|
||||
m_copper_normal_generator = aCopperNormalGenerator;
|
||||
}
|
||||
|
||||
|
||||
SFVEC3F CSOLDERMASKNORMAL::Generate( const RAY &aRay, const HITINFO &aHitInfo ) const
|
||||
{
|
||||
if( m_copper_normal_generator )
|
||||
{
|
||||
const SFVEC3F copperNormal = m_copper_normal_generator->Generate( aRay, aHitInfo );
|
||||
|
||||
return copperNormal * SFVEC3F(0.40f);
|
||||
return copperNormal * SFVEC3F(0.20f);
|
||||
}
|
||||
else
|
||||
return SFVEC3F(0.0f);
|
||||
}
|
||||
|
||||
|
||||
CPLASTICNORMAL::CPLASTICNORMAL( float aScale )
|
||||
{
|
||||
m_scale = 1.0f / aScale;
|
||||
}
|
||||
|
||||
|
||||
SFVEC3F CPLASTICNORMAL::Generate( const RAY &aRay, const HITINFO &aHitInfo ) const
|
||||
{
|
||||
SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale;
|
||||
|
||||
const float noise1 = (m_perlin.noise( hitPos.x,
|
||||
hitPos.y,
|
||||
hitPos.z ) - 0.5f);
|
||||
|
||||
const float noise2 = (m_perlin.noise( hitPos.x * 5.0f,
|
||||
hitPos.y * 5.0f,
|
||||
hitPos.z * 5.0f ) - 0.5f);
|
||||
|
||||
const float noise3 = (m_perlin.noise( hitPos.x * 10.0f + Fast_RandFloat() * 0.10f,
|
||||
hitPos.y * 10.0f + Fast_RandFloat() * 0.10f,
|
||||
hitPos.z * 10.0f + Fast_RandFloat() * 0.10f ) - 0.5f);
|
||||
|
||||
return SFVEC3F( noise1 * 0.08f + noise2 * 0.10f + noise3 * 0.20f );
|
||||
}
|
||||
|
||||
|
||||
CPLASTICSHINENORMAL::CPLASTICSHINENORMAL( float aScale )
|
||||
{
|
||||
m_scale = 1.0f / aScale;
|
||||
}
|
||||
|
||||
|
||||
SFVEC3F CPLASTICSHINENORMAL::Generate( const RAY &aRay, const HITINFO &aHitInfo ) const
|
||||
{
|
||||
SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale;
|
||||
|
||||
const float noise1 = (m_perlin.noise( hitPos.x,
|
||||
hitPos.y,
|
||||
hitPos.z ) - 0.5f);
|
||||
|
||||
const float noise2 = (m_perlin.noise( hitPos.x * 3.0f,
|
||||
hitPos.y * 3.0f,
|
||||
hitPos.z * 3.0f ) - 0.5f);
|
||||
|
||||
return SFVEC3F( noise1 * 0.09f + noise2 * 0.05f );
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include "ray.h"
|
||||
#include "hitinfo.h"
|
||||
#include "PerlinNoise.h"
|
||||
|
||||
/// A base class that can be used to derive a procedural generator implementation
|
||||
class CPROCEDURALGENERATOR
|
||||
|
@ -72,14 +73,21 @@ private:
|
|||
class CCOPPERNORMAL : public CPROCEDURALGENERATOR
|
||||
{
|
||||
public:
|
||||
CCOPPERNORMAL() : CPROCEDURALGENERATOR() { m_board_normal_generator = NULL; }
|
||||
CCOPPERNORMAL( const CBOARDNORMAL *aBoardNormalGenerator );
|
||||
CCOPPERNORMAL() : CPROCEDURALGENERATOR()
|
||||
{
|
||||
m_board_normal_generator = NULL;
|
||||
m_scale = 1.0f;
|
||||
}
|
||||
|
||||
CCOPPERNORMAL( float aScale, const CPROCEDURALGENERATOR *aBoardNormalGenerator );
|
||||
|
||||
// Imported from CPROCEDURALGENERATOR
|
||||
SFVEC3F Generate( const RAY &aRay,
|
||||
const HITINFO &aHitInfo ) const override;
|
||||
private:
|
||||
const CBOARDNORMAL *m_board_normal_generator;
|
||||
const CPROCEDURALGENERATOR *m_board_normal_generator;
|
||||
PerlinNoise m_copper_perlin;
|
||||
float m_scale;
|
||||
};
|
||||
|
||||
// Procedural generation of the solder mask
|
||||
|
@ -87,15 +95,56 @@ class CSOLDERMASKNORMAL : public CPROCEDURALGENERATOR
|
|||
{
|
||||
public:
|
||||
CSOLDERMASKNORMAL() : CPROCEDURALGENERATOR() { m_copper_normal_generator = NULL; }
|
||||
CSOLDERMASKNORMAL( const CCOPPERNORMAL *aCopperNormalGenerator );
|
||||
CSOLDERMASKNORMAL( const CPROCEDURALGENERATOR *aCopperNormalGenerator );
|
||||
|
||||
// Imported from CPROCEDURALGENERATOR
|
||||
SFVEC3F Generate( const RAY &aRay,
|
||||
const HITINFO &aHitInfo ) const override;
|
||||
private:
|
||||
const CCOPPERNORMAL *m_copper_normal_generator;
|
||||
const CPROCEDURALGENERATOR *m_copper_normal_generator;
|
||||
};
|
||||
|
||||
|
||||
// Procedural generation of the plastic normals
|
||||
class CPLASTICNORMAL : public CPROCEDURALGENERATOR
|
||||
{
|
||||
public:
|
||||
CPLASTICNORMAL() : CPROCEDURALGENERATOR()
|
||||
{
|
||||
m_scale = 1.0f;
|
||||
}
|
||||
|
||||
CPLASTICNORMAL( float aScale );
|
||||
|
||||
// Imported from CPROCEDURALGENERATOR
|
||||
SFVEC3F Generate( const RAY &aRay,
|
||||
const HITINFO &aHitInfo ) const override;
|
||||
private:
|
||||
PerlinNoise m_perlin;
|
||||
float m_scale;
|
||||
};
|
||||
|
||||
|
||||
// Procedural generation of the shining plastic normals
|
||||
class CPLASTICSHINENORMAL : public CPROCEDURALGENERATOR
|
||||
{
|
||||
public:
|
||||
CPLASTICSHINENORMAL() : CPROCEDURALGENERATOR()
|
||||
{
|
||||
m_scale = 1.0f;
|
||||
}
|
||||
|
||||
CPLASTICSHINENORMAL( float aScale );
|
||||
|
||||
// Imported from CPROCEDURALGENERATOR
|
||||
SFVEC3F Generate( const RAY &aRay,
|
||||
const HITINFO &aHitInfo ) const override;
|
||||
private:
|
||||
PerlinNoise m_perlin;
|
||||
float m_scale;
|
||||
};
|
||||
|
||||
|
||||
/// A base material class that can be used to derive a material implementation
|
||||
class CMATERIAL
|
||||
{
|
||||
|
@ -146,6 +195,8 @@ public:
|
|||
void SetNormalPerturbator( const CPROCEDURALGENERATOR *aPerturbator ) { m_normal_perturbator = aPerturbator; }
|
||||
const CPROCEDURALGENERATOR *GetNormalPerturbator() const { return m_normal_perturbator; }
|
||||
|
||||
void PerturbeNormal( SFVEC3F &aNormal, const RAY &aRay, const HITINFO &aHitInfo ) const;
|
||||
|
||||
protected:
|
||||
SFVEC3F m_ambientColor;
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ struct HITINFO
|
|||
SFVEC2F m_UV; ///< ( 8) 2-D texture coordinates
|
||||
unsigned int m_acc_node_info; ///< ( 4) The acc stores here the node that it hits
|
||||
|
||||
SFVEC3F m_HitPoint; ///< (12) hit position
|
||||
float m_ShadowFactor; ///< ( 4) Shadow attenuation (1.0 no shadow, 0.0f darkness)
|
||||
|
||||
#ifdef RAYTRACING_RAY_STATISTICS
|
||||
|
|
|
@ -145,7 +145,6 @@ bool CITEMLAYERCSG2D::Intersect( const RAYSEG2D &aSegRay,
|
|||
currentRayPos = aSegRay.atNormalized( currentRayDist );
|
||||
|
||||
if( m_objectA->IsPointInside( currentRayPos ) )
|
||||
//if(1)
|
||||
{
|
||||
wasInsideSubVol = true;
|
||||
|
||||
|
|
|
@ -109,18 +109,16 @@ bool CVCYLINDER::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
|
|||
|
||||
if( hitResult )
|
||||
{
|
||||
const SFVEC2F hitPoint2D = aRay.at2D( aHitInfo.m_tHit );
|
||||
//aHitInfo.m_HitPoint =
|
||||
aHitInfo.m_HitPoint = aRay.at( aHitInfo.m_tHit );
|
||||
|
||||
const SFVEC2F hitPoint2D = SFVEC2F( aHitInfo.m_HitPoint.x,
|
||||
aHitInfo.m_HitPoint.y );
|
||||
|
||||
aHitInfo.m_HitNormal = SFVEC3F( -(hitPoint2D.x - m_center.x) * m_inv_radius,
|
||||
-(hitPoint2D.y - m_center.y) * m_inv_radius,
|
||||
0.0f );
|
||||
|
||||
if (m_material->GetNormalPerturbator())
|
||||
{
|
||||
aHitInfo.m_HitNormal = aHitInfo.m_HitNormal +
|
||||
m_material->GetNormalPerturbator()->Generate( aRay, aHitInfo );
|
||||
aHitInfo.m_HitNormal = glm::normalize( aHitInfo.m_HitNormal );
|
||||
}
|
||||
m_material->PerturbeNormal( aHitInfo.m_HitNormal, aRay, aHitInfo );
|
||||
|
||||
aHitInfo.pHitObject = this;
|
||||
}
|
||||
|
|
|
@ -48,18 +48,14 @@ bool CDUMMYBLOCK::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
|
|||
if( t < aHitInfo.m_tHit )
|
||||
{
|
||||
aHitInfo.m_tHit = t;
|
||||
//aHitInfo.m_HitPoint = aRay.at( t );
|
||||
aHitInfo.m_HitPoint = aRay.at( t );
|
||||
|
||||
if( aRay.m_dirIsNeg[2] )
|
||||
aHitInfo.m_HitNormal = SFVEC3F( 0.0f, 0.0f, 1.0f );
|
||||
else
|
||||
aHitInfo.m_HitNormal = SFVEC3F( 0.0f, 0.0f,-1.0f );
|
||||
|
||||
if (m_material->GetNormalPerturbator())
|
||||
{
|
||||
aHitInfo.m_HitNormal = aHitInfo.m_HitNormal +
|
||||
m_material->GetNormalPerturbator()->Generate( aRay, aHitInfo );
|
||||
aHitInfo.m_HitNormal = glm::normalize( aHitInfo.m_HitNormal );
|
||||
}
|
||||
m_material->PerturbeNormal( aHitInfo.m_HitNormal, aRay, aHitInfo );
|
||||
|
||||
aHitInfo.pHitObject = this;
|
||||
|
||||
|
|
|
@ -118,16 +118,11 @@ bool CLAYERITEM::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
|
|||
if( tBot < aHitInfo.m_tHit )
|
||||
{
|
||||
aHitInfo.m_tHit = tBot;
|
||||
//aHitInfo.m_HitPoint = aRay.at( tBot );
|
||||
aHitInfo.m_HitPoint = aRay.at( tBot );
|
||||
aHitInfo.m_HitNormal = SFVEC3F( 0.0f, 0.0f, -1.0f );
|
||||
aHitInfo.pHitObject = this;
|
||||
|
||||
if (m_material->GetNormalPerturbator())
|
||||
{
|
||||
aHitInfo.m_HitNormal = aHitInfo.m_HitNormal +
|
||||
m_material->GetNormalPerturbator()->Generate( aRay, aHitInfo );
|
||||
aHitInfo.m_HitNormal = glm::normalize( aHitInfo.m_HitNormal );
|
||||
}
|
||||
m_material->PerturbeNormal( aHitInfo.m_HitNormal, aRay, aHitInfo );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -142,16 +137,11 @@ bool CLAYERITEM::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
|
|||
if( tTop < aHitInfo.m_tHit )
|
||||
{
|
||||
aHitInfo.m_tHit = tTop;
|
||||
//aHitInfo.m_HitPoint = aRay.at( tTop );
|
||||
aHitInfo.m_HitPoint = aRay.at( tTop );
|
||||
aHitInfo.m_HitNormal = SFVEC3F( 0.0f, 0.0f, 1.0f );
|
||||
aHitInfo.pHitObject = this;
|
||||
|
||||
if (m_material->GetNormalPerturbator())
|
||||
{
|
||||
aHitInfo.m_HitNormal = aHitInfo.m_HitNormal +
|
||||
m_material->GetNormalPerturbator()->Generate( aRay, aHitInfo );
|
||||
aHitInfo.m_HitNormal = glm::normalize( aHitInfo.m_HitNormal );
|
||||
}
|
||||
m_material->PerturbeNormal( aHitInfo.m_HitNormal, aRay, aHitInfo );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -171,16 +161,11 @@ bool CLAYERITEM::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
|
|||
if( tTop < aHitInfo.m_tHit )
|
||||
{
|
||||
aHitInfo.m_tHit = tTop;
|
||||
//aHitInfo.m_HitPoint = aRay.at( tTop );
|
||||
aHitInfo.m_HitPoint = aRay.at( tTop );
|
||||
aHitInfo.m_HitNormal = SFVEC3F( 0.0f, 0.0f, 1.0f );
|
||||
aHitInfo.pHitObject = this;
|
||||
|
||||
if (m_material->GetNormalPerturbator())
|
||||
{
|
||||
aHitInfo.m_HitNormal = aHitInfo.m_HitNormal +
|
||||
m_material->GetNormalPerturbator()->Generate( aRay, aHitInfo );
|
||||
aHitInfo.m_HitNormal = glm::normalize( aHitInfo.m_HitNormal );
|
||||
}
|
||||
m_material->PerturbeNormal( aHitInfo.m_HitNormal, aRay, aHitInfo );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -200,16 +185,11 @@ bool CLAYERITEM::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
|
|||
if( tBot < aHitInfo.m_tHit )
|
||||
{
|
||||
aHitInfo.m_tHit = tBot;
|
||||
//aHitInfo.m_HitPoint = aRay.at( tBot );
|
||||
aHitInfo.m_HitPoint = aRay.at( tBot );
|
||||
aHitInfo.m_HitNormal = SFVEC3F( 0.0f, 0.0f, -1.0f );
|
||||
aHitInfo.pHitObject = this;
|
||||
|
||||
if (m_material->GetNormalPerturbator())
|
||||
{
|
||||
aHitInfo.m_HitNormal = aHitInfo.m_HitNormal +
|
||||
m_material->GetNormalPerturbator()->Generate( aRay, aHitInfo );
|
||||
aHitInfo.m_HitNormal = glm::normalize( aHitInfo.m_HitNormal );
|
||||
}
|
||||
m_material->PerturbeNormal( aHitInfo.m_HitNormal, aRay, aHitInfo );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -247,21 +227,27 @@ bool CLAYERITEM::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
|
|||
// and calculate the real hitT of the ray.
|
||||
SFVEC3F hitPoint = boxHitPointStart +
|
||||
(boxHitPointEnd - boxHitPointStart) * tOut;
|
||||
|
||||
const float t = glm::length( hitPoint - aRay.m_Origin );
|
||||
|
||||
if( t < aHitInfo.m_tHit )
|
||||
{
|
||||
aHitInfo.m_tHit = t;
|
||||
//aHitInfo.m_HitPoint = hitPoint;
|
||||
aHitInfo.m_HitNormal = SFVEC3F( outNormal.x, outNormal.y, 0.0f );
|
||||
aHitInfo.m_HitPoint = hitPoint;
|
||||
|
||||
if( (outNormal.x == 0.0f) &&
|
||||
(outNormal.y == 0.0f) )
|
||||
{
|
||||
aHitInfo.m_HitNormal = SFVEC3F( 0.0f, 0.0f, 1.0f );
|
||||
}
|
||||
else
|
||||
{
|
||||
aHitInfo.m_HitNormal = SFVEC3F( outNormal.x, outNormal.y, 0.0f );
|
||||
}
|
||||
|
||||
aHitInfo.pHitObject = this;
|
||||
|
||||
if (m_material->GetNormalPerturbator())
|
||||
{
|
||||
aHitInfo.m_HitNormal = aHitInfo.m_HitNormal +
|
||||
m_material->GetNormalPerturbator()->Generate( aRay, aHitInfo );
|
||||
aHitInfo.m_HitNormal = glm::normalize( aHitInfo.m_HitNormal );
|
||||
}
|
||||
m_material->PerturbeNormal( aHitInfo.m_HitNormal, aRay, aHitInfo );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -294,6 +280,7 @@ bool CLAYERITEM::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
|
|||
if( tBBoxEnd < aHitInfo.m_tHit )
|
||||
{
|
||||
aHitInfo.m_tHit = tBBoxEnd;
|
||||
aHitInfo.m_HitPoint = aRay.at( tBBoxEnd );
|
||||
aHitInfo.pHitObject = this;
|
||||
|
||||
if( aRay.m_Dir.z > 0.0f )
|
||||
|
@ -301,12 +288,7 @@ bool CLAYERITEM::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
|
|||
else
|
||||
aHitInfo.m_HitNormal = SFVEC3F( 0.0f, 0.0f, 1.0f );
|
||||
|
||||
if (m_material->GetNormalPerturbator())
|
||||
{
|
||||
aHitInfo.m_HitNormal = aHitInfo.m_HitNormal +
|
||||
m_material->GetNormalPerturbator()->Generate( aRay, aHitInfo );
|
||||
aHitInfo.m_HitNormal = glm::normalize( aHitInfo.m_HitNormal );
|
||||
}
|
||||
m_material->PerturbeNormal( aHitInfo.m_HitNormal, aRay, aHitInfo );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -326,16 +308,11 @@ bool CLAYERITEM::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
|
|||
if( t < aHitInfo.m_tHit )
|
||||
{
|
||||
aHitInfo.m_tHit = t;
|
||||
//aHitInfo.m_HitPoint = hitPoint;
|
||||
aHitInfo.m_HitPoint = hitPoint;
|
||||
aHitInfo.m_HitNormal = SFVEC3F( outNormal.x, outNormal.y, 0.0f );
|
||||
aHitInfo.pHitObject = this;
|
||||
|
||||
if (m_material->GetNormalPerturbator())
|
||||
{
|
||||
aHitInfo.m_HitNormal = aHitInfo.m_HitNormal +
|
||||
m_material->GetNormalPerturbator()->Generate( aRay, aHitInfo );
|
||||
aHitInfo.m_HitNormal = glm::normalize( aHitInfo.m_HitNormal );
|
||||
}
|
||||
m_material->PerturbeNormal( aHitInfo.m_HitNormal, aRay, aHitInfo );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ bool CXYPLANE::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
|
|||
return false;
|
||||
|
||||
aHitInfo.m_tHit = t;
|
||||
//aHitInfo.m_HitPoint = aRay.at( t );
|
||||
aHitInfo.m_HitPoint = aRay.at( t );
|
||||
aHitInfo.pHitObject = this;
|
||||
|
||||
if( aRay.m_dirIsNeg[2] )
|
||||
|
@ -90,12 +90,7 @@ bool CXYPLANE::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
|
|||
else
|
||||
aHitInfo.m_HitNormal = SFVEC3F( 0.0f, 0.0f,-1.0f );
|
||||
|
||||
if (m_material->GetNormalPerturbator())
|
||||
{
|
||||
aHitInfo.m_HitNormal = aHitInfo.m_HitNormal +
|
||||
m_material->GetNormalPerturbator()->Generate( aRay, aHitInfo );
|
||||
aHitInfo.m_HitNormal = glm::normalize( aHitInfo.m_HitNormal );
|
||||
}
|
||||
m_material->PerturbeNormal( aHitInfo.m_HitNormal, aRay, aHitInfo );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -81,20 +81,15 @@ bool CROUNDSEG::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
|
|||
if( tPlane < aHitInfo.m_tHit )
|
||||
{
|
||||
aHitInfo.m_tHit = tPlane;
|
||||
//aHitInfo.m_HitPoint = SFVEC3F( planeHitPoint2d.x,
|
||||
// planeHitPoint2d.y,
|
||||
// aRay.m_Origin.z + aRay.m_Dir.z * tPlane );
|
||||
aHitInfo.m_HitPoint = SFVEC3F( planeHitPoint2d.x,
|
||||
planeHitPoint2d.y,
|
||||
aRay.m_Origin.z + aRay.m_Dir.z * tPlane );
|
||||
aHitInfo.m_HitNormal = SFVEC3F( 0.0f,
|
||||
0.0f,
|
||||
aRay.m_dirIsNeg[2]? 1.0f: -1.0f );
|
||||
aHitInfo.pHitObject = this;
|
||||
|
||||
if (m_material->GetNormalPerturbator())
|
||||
{
|
||||
aHitInfo.m_HitNormal = aHitInfo.m_HitNormal +
|
||||
m_material->GetNormalPerturbator()->Generate( aRay, aHitInfo );
|
||||
aHitInfo.m_HitNormal = glm::normalize( aHitInfo.m_HitNormal );
|
||||
}
|
||||
m_material->PerturbeNormal( aHitInfo.m_HitNormal, aRay, aHitInfo );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -126,18 +121,13 @@ bool CROUNDSEG::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
|
|||
if( t < aHitInfo.m_tHit )
|
||||
{
|
||||
aHitInfo.m_tHit = t;
|
||||
//aHitInfo.m_HitPoint = hitP;
|
||||
aHitInfo.m_HitPoint = hitP;
|
||||
aHitInfo.m_HitNormal = SFVEC3F( m_plane_dir_right.x,
|
||||
m_plane_dir_right.y,
|
||||
0.0f );
|
||||
aHitInfo.pHitObject = this;
|
||||
|
||||
if (m_material->GetNormalPerturbator())
|
||||
{
|
||||
aHitInfo.m_HitNormal = aHitInfo.m_HitNormal +
|
||||
m_material->GetNormalPerturbator()->Generate( aRay, aHitInfo );
|
||||
aHitInfo.m_HitNormal = glm::normalize( aHitInfo.m_HitNormal );
|
||||
}
|
||||
m_material->PerturbeNormal( aHitInfo.m_HitNormal, aRay, aHitInfo );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -170,18 +160,13 @@ bool CROUNDSEG::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
|
|||
if( t < aHitInfo.m_tHit )
|
||||
{
|
||||
aHitInfo.m_tHit = t;
|
||||
//aHitInfo.m_HitPoint = hitP;
|
||||
aHitInfo.m_HitPoint = hitP;
|
||||
aHitInfo.m_HitNormal = SFVEC3F( m_plane_dir_left.x,
|
||||
m_plane_dir_left.y,
|
||||
0.0f );
|
||||
aHitInfo.pHitObject = this;
|
||||
|
||||
if (m_material->GetNormalPerturbator())
|
||||
{
|
||||
aHitInfo.m_HitNormal = aHitInfo.m_HitNormal +
|
||||
m_material->GetNormalPerturbator()->Generate( aRay, aHitInfo );
|
||||
aHitInfo.m_HitNormal = glm::normalize( aHitInfo.m_HitNormal );
|
||||
}
|
||||
m_material->PerturbeNormal( aHitInfo.m_HitNormal, aRay, aHitInfo );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -225,20 +210,19 @@ bool CROUNDSEG::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
|
|||
if( t < aHitInfo.m_tHit )
|
||||
{
|
||||
aHitInfo.m_tHit = t;
|
||||
SFVEC2F hitPoint2D = aRay.at2D( t );
|
||||
//aHitInfo.m_HitPoint = aRay.at( t );
|
||||
aHitInfo.m_HitPoint = aRay.at( t );
|
||||
|
||||
const SFVEC2F hitPoint2D = SFVEC2F( aHitInfo.m_HitPoint.x,
|
||||
aHitInfo.m_HitPoint.y );
|
||||
|
||||
aHitInfo.m_HitNormal = SFVEC3F(
|
||||
(hitPoint2D.x - m_segment.m_Start.x) * m_inv_radius,
|
||||
(hitPoint2D.y - m_segment.m_Start.y) * m_inv_radius,
|
||||
0.0f );
|
||||
|
||||
aHitInfo.pHitObject = this;
|
||||
|
||||
if (m_material->GetNormalPerturbator())
|
||||
{
|
||||
aHitInfo.m_HitNormal = aHitInfo.m_HitNormal +
|
||||
m_material->GetNormalPerturbator()->Generate( aRay, aHitInfo );
|
||||
aHitInfo.m_HitNormal = glm::normalize( aHitInfo.m_HitNormal );
|
||||
}
|
||||
m_material->PerturbeNormal( aHitInfo.m_HitNormal, aRay, aHitInfo );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -271,8 +255,10 @@ bool CROUNDSEG::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
|
|||
if( t < aHitInfo.m_tHit )
|
||||
{
|
||||
aHitInfo.m_tHit = t;
|
||||
//aHitInfo.m_HitPoint = aRay.at( t );
|
||||
const SFVEC2F hitPoint2D = aRay.at2D( t );
|
||||
aHitInfo.m_HitPoint = aRay.at( t );
|
||||
|
||||
const SFVEC2F hitPoint2D = SFVEC2F( aHitInfo.m_HitPoint.x,
|
||||
aHitInfo.m_HitPoint.y );
|
||||
|
||||
aHitInfo.m_HitNormal = SFVEC3F(
|
||||
(hitPoint2D.x - m_segment.m_End.x) * m_inv_radius,
|
||||
|
@ -280,12 +266,7 @@ bool CROUNDSEG::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
|
|||
0.0f );
|
||||
aHitInfo.pHitObject = this;
|
||||
|
||||
if (m_material->GetNormalPerturbator())
|
||||
{
|
||||
aHitInfo.m_HitNormal = aHitInfo.m_HitNormal +
|
||||
m_material->GetNormalPerturbator()->Generate( aRay, aHitInfo );
|
||||
aHitInfo.m_HitNormal = glm::normalize( aHitInfo.m_HitNormal );
|
||||
}
|
||||
m_material->PerturbeNormal( aHitInfo.m_HitNormal, aRay, aHitInfo );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -252,19 +252,14 @@ bool CTRIANGLE::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
|
|||
return false;
|
||||
|
||||
aHitInfo.m_tHit = t;
|
||||
//aHitInfo.m_UV
|
||||
aHitInfo.m_HitPoint = aRay.at( t );
|
||||
|
||||
// interpolate vertex normals with UVW using Gouraud's shading
|
||||
aHitInfo.m_HitNormal = glm::normalize( (1.0f - u - v) * m_normal[0] +
|
||||
u * m_normal[1] +
|
||||
v * m_normal[2] );
|
||||
|
||||
if (m_material->GetNormalPerturbator())
|
||||
{
|
||||
aHitInfo.m_HitNormal = aHitInfo.m_HitNormal +
|
||||
m_material->GetNormalPerturbator()->Generate( aRay, aHitInfo );
|
||||
aHitInfo.m_HitNormal = glm::normalize( aHitInfo.m_HitNormal );
|
||||
}
|
||||
m_material->PerturbeNormal( aHitInfo.m_HitNormal, aRay, aHitInfo );
|
||||
|
||||
aHitInfo.pHitObject = this;
|
||||
|
||||
|
|
|
@ -242,6 +242,11 @@ void EDA_3D_VIEWER::CreateMenuBar()
|
|||
_( "Render Shadows" ),
|
||||
KiBitmap( green_xpm ), wxITEM_CHECK );
|
||||
|
||||
AddMenuItem( renderOptionsMenu_RAYTRACING, ID_MENU3D_FL_RAYTRACING_PROCEDURAL_TEXTURES,
|
||||
_( "Procedural Textures" ),
|
||||
_( "Apply procedural textures to materials (slow)"),
|
||||
KiBitmap( green_xpm ), wxITEM_CHECK );
|
||||
|
||||
AddMenuItem( renderOptionsMenu_RAYTRACING, ID_MENU3D_FL_RAYTRACING_BACKFLOOR,
|
||||
_( "Add floor" ),
|
||||
_( "Adds a floor plane below the board (slow)"),
|
||||
|
@ -424,6 +429,13 @@ void EDA_3D_VIEWER::SetMenuBarOptionsState()
|
|||
item = menuBar->FindItem( ID_MENU3D_MOUSEWHEEL_PANNING );
|
||||
item->Check( m_settings.GetFlag( FL_MOUSEWHEEL_PANNING ) );
|
||||
|
||||
|
||||
item = menuBar->FindItem( ID_MENU3D_ENGINE_OPENGL_LEGACY );
|
||||
item->Check( m_settings.RenderEngineGet() == RENDER_ENGINE_OPENGL_LEGACY );
|
||||
|
||||
item = menuBar->FindItem( ID_MENU3D_ENGINE_RAYTRACING );
|
||||
item->Check( m_settings.RenderEngineGet() == RENDER_ENGINE_RAYTRACING );
|
||||
|
||||
item = menuBar->FindItem( ID_MENU3D_REALISTIC_MODE );
|
||||
item->Check( m_settings.GetFlag( FL_USE_REALISTIC_MODE ) );
|
||||
item = menuBar->FindItem( ID_MENU3D_COMMENTS_ONOFF );
|
||||
|
@ -469,6 +481,9 @@ void EDA_3D_VIEWER::SetMenuBarOptionsState()
|
|||
item = menuBar->FindItem( ID_MENU3D_FL_RAYTRACING_ANTI_ALIASING );
|
||||
item->Check( m_settings.GetFlag( FL_RENDER_RAYTRACING_ANTI_ALIASING ) );
|
||||
|
||||
item = menuBar->FindItem( ID_MENU3D_FL_RAYTRACING_PROCEDURAL_TEXTURES );
|
||||
item->Check( m_settings.GetFlag( FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES ) );
|
||||
|
||||
|
||||
item = menuBar->FindItem( ID_MENU3D_SHOW_BOARD_BODY );
|
||||
item->Check( m_settings.GetFlag( FL_SHOW_BOARD_BODY ) );
|
||||
|
|
|
@ -94,6 +94,7 @@ static const wxChar keyRenderRAY_Refractions[] = wxT( "Render_RAY_Refractions"
|
|||
static const wxChar keyRenderRAY_Reflections[] = wxT( "Render_RAY_Reflections" );
|
||||
static const wxChar keyRenderRAY_PostProcess[] = wxT( "Render_RAY_PostProcess" );
|
||||
static const wxChar keyRenderRAY_AAliasing[] = wxT( "Render_RAY_AntiAliasing" );
|
||||
static const wxChar keyRenderRAY_ProceduralT[] = wxT( "Render_RAY_ProceduralTextures" );
|
||||
|
||||
static const wxChar keyShowAxis[] = wxT( "ShowAxis" );
|
||||
static const wxChar keyShowGrid[] = wxT( "ShowGrid3D" );
|
||||
|
@ -341,12 +342,22 @@ void EDA_3D_VIEWER::Process_Special_Functions( wxCommandEvent &event )
|
|||
|
||||
case ID_MENU3D_BGCOLOR_BOTTOM_SELECTION:
|
||||
if( Set3DColorFromUser( m_settings.m_BgColorBot, _( "Background Color, Bottom" ) ) )
|
||||
m_canvas->Request_refresh();
|
||||
{
|
||||
if( m_settings.RenderEngineGet() == RENDER_ENGINE_OPENGL_LEGACY )
|
||||
m_canvas->Request_refresh();
|
||||
else
|
||||
ReloadRequest();
|
||||
}
|
||||
return;
|
||||
|
||||
case ID_MENU3D_BGCOLOR_TOP_SELECTION:
|
||||
if( Set3DColorFromUser( m_settings.m_BgColorTop, _( "Background Color, Top" ) ) )
|
||||
m_canvas->Request_refresh();
|
||||
{
|
||||
if( m_settings.RenderEngineGet() == RENDER_ENGINE_OPENGL_LEGACY )
|
||||
m_canvas->Request_refresh();
|
||||
else
|
||||
ReloadRequest();
|
||||
}
|
||||
return;
|
||||
|
||||
case ID_MENU3D_SILKSCREEN_COLOR_SELECTION:
|
||||
|
@ -414,6 +425,11 @@ void EDA_3D_VIEWER::Process_Special_Functions( wxCommandEvent &event )
|
|||
m_canvas->Request_refresh();
|
||||
return;
|
||||
|
||||
case ID_MENU3D_FL_RAYTRACING_PROCEDURAL_TEXTURES:
|
||||
m_settings.SetFlag( FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES, isChecked );
|
||||
ReloadRequest( );
|
||||
return;
|
||||
|
||||
case ID_MENU3D_FL_RAYTRACING_BACKFLOOR:
|
||||
m_settings.SetFlag( FL_RENDER_RAYTRACING_BACKFLOOR, isChecked );
|
||||
ReloadRequest( );
|
||||
|
@ -754,6 +770,8 @@ void EDA_3D_VIEWER::LoadSettings( wxConfigBase *aCfg )
|
|||
aCfg->Read( keyRenderRAY_AAliasing, &tmp, true );
|
||||
m_settings.SetFlag( FL_RENDER_RAYTRACING_ANTI_ALIASING, tmp );
|
||||
|
||||
aCfg->Read( keyRenderRAY_ProceduralT, &tmp, true );
|
||||
m_settings.SetFlag( FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES, tmp );
|
||||
|
||||
aCfg->Read( keyShowAxis, &tmp, true );
|
||||
m_settings.SetFlag( FL_AXIS, tmp );
|
||||
|
@ -858,12 +876,13 @@ void EDA_3D_VIEWER::SaveSettings( wxConfigBase *aCfg )
|
|||
aCfg->Write( keyRenderRAY_Reflections, m_settings.GetFlag( FL_RENDER_RAYTRACING_REFLECTIONS ) );
|
||||
aCfg->Write( keyRenderRAY_PostProcess, m_settings.GetFlag( FL_RENDER_RAYTRACING_POST_PROCESSING ) );
|
||||
aCfg->Write( keyRenderRAY_AAliasing, m_settings.GetFlag( FL_RENDER_RAYTRACING_ANTI_ALIASING ) );
|
||||
aCfg->Write( keyRenderRAY_ProceduralT, m_settings.GetFlag( FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES ) );
|
||||
|
||||
aCfg->Write( keyShowAxis, m_settings.GetFlag( FL_AXIS ) );
|
||||
aCfg->Write( keyShowGrid, (int)m_settings.GridGet() );
|
||||
|
||||
aCfg->Write( keyShowFootprints_Normal, m_settings.GetFlag( FL_MODULE_ATTRIBUTES_NORMAL ) );
|
||||
aCfg->Write( keyShowFootprints_Virtual, m_settings.GetFlag( FL_MODULE_ATTRIBUTES_NORMAL_INSERT ) );
|
||||
aCfg->Write( keyShowFootprints_Insert, m_settings.GetFlag( FL_MODULE_ATTRIBUTES_NORMAL_INSERT ) );
|
||||
aCfg->Write( keyShowFootprints_Virtual, m_settings.GetFlag( FL_MODULE_ATTRIBUTES_VIRTUAL ) );
|
||||
|
||||
aCfg->Write( keyShowZones, m_settings.GetFlag( FL_ZONE ) );
|
||||
|
|
|
@ -78,6 +78,7 @@ enum id_3dview_frm
|
|||
ID_MENU3D_FL_RAYTRACING_REFLECTIONS,
|
||||
ID_MENU3D_FL_RAYTRACING_POST_PROCESSING,
|
||||
ID_MENU3D_FL_RAYTRACING_ANTI_ALIASING,
|
||||
ID_MENU3D_FL_RAYTRACING_PROCEDURAL_TEXTURES,
|
||||
|
||||
ID_RENDER_CURRENT_VIEW,
|
||||
|
||||
|
|
|
@ -60,6 +60,7 @@ set(3D-VIEWER_SRCS
|
|||
${DIR_RAY_ACC}/cbvh_pbrt.cpp
|
||||
${DIR_RAY_ACC}/ccontainer.cpp
|
||||
${DIR_RAY_ACC}/ccontainer2d.cpp
|
||||
${DIR_RAY}/PerlinNoise.cpp
|
||||
${DIR_RAY}/c3d_render_createscene.cpp
|
||||
${DIR_RAY}/c3d_render_raytracing.cpp
|
||||
${DIR_RAY}/cfrustum.cpp
|
||||
|
|
Loading…
Reference in New Issue