3D-Viewer: Raytracing, add silkscreen texture
improves other textures
This commit is contained in:
parent
87da9271a4
commit
5841ea3cd2
|
@ -93,11 +93,13 @@ void C3D_RENDER_RAYTRACING::setupMaterials()
|
||||||
|
|
||||||
m_solder_mask_normal_perturbator = CSOLDERMASKNORMAL( &m_board_normal_perturbator );
|
m_solder_mask_normal_perturbator = CSOLDERMASKNORMAL( &m_board_normal_perturbator );
|
||||||
|
|
||||||
m_plastic_normal_perturbator = CPLASTICNORMAL( 0.15f * mmTo3Dunits );
|
m_plastic_normal_perturbator = CPLASTICNORMAL( 0.05f * mmTo3Dunits );
|
||||||
|
|
||||||
m_plastic_shine_normal_perturbator = CPLASTICSHINENORMAL( 1.0f * mmTo3Dunits );
|
m_plastic_shine_normal_perturbator = CPLASTICSHINENORMAL( 0.1f * mmTo3Dunits );
|
||||||
|
|
||||||
m_brushed_metal_normal_perturbator = CMETALBRUSHEDNORMAL( 1.0f * mmTo3Dunits );
|
m_brushed_metal_normal_perturbator = CMETALBRUSHEDNORMAL( 0.05f * mmTo3Dunits );
|
||||||
|
|
||||||
|
m_silkscreen_normal_perturbator = CSILKSCREENNORMAL( 0.25f * mmTo3Dunits );
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://devernay.free.fr/cours/opengl/materials.html
|
// http://devernay.free.fr/cours/opengl/materials.html
|
||||||
|
@ -150,6 +152,9 @@ void C3D_RENDER_RAYTRACING::setupMaterials()
|
||||||
0.0f, // transparency
|
0.0f, // transparency
|
||||||
0.0f );
|
0.0f );
|
||||||
|
|
||||||
|
if( m_boardAdapter.GetFlag( FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES ) )
|
||||||
|
m_materials.m_SilkS.SetNormalPerturbator( &m_silkscreen_normal_perturbator );
|
||||||
|
|
||||||
// Assume that SolderMaskTop == SolderMaskBot
|
// Assume that SolderMaskTop == SolderMaskBot
|
||||||
const float solderMask_gray =
|
const float solderMask_gray =
|
||||||
( m_boardAdapter.m_SolderMaskColorTop.r + m_boardAdapter.m_SolderMaskColorTop.g
|
( m_boardAdapter.m_SolderMaskColorTop.r + m_boardAdapter.m_SolderMaskColorTop.g
|
||||||
|
@ -1562,11 +1567,7 @@ MODEL_MATERIALS *C3D_RENDER_RAYTRACING::get_3D_model_material( const S3DMODEL *a
|
||||||
( glm::abs( material.m_Diffuse.r - material.m_Diffuse.b ) < 0.15f ) ) )
|
( glm::abs( material.m_Diffuse.r - material.m_Diffuse.b ) < 0.15f ) ) )
|
||||||
{
|
{
|
||||||
// This may be a black plastic..
|
// This may be a black plastic..
|
||||||
|
blinnMaterial.SetNormalPerturbator( &m_plastic_normal_perturbator );
|
||||||
if( material.m_Shininess < 0.26f )
|
|
||||||
blinnMaterial.SetNormalPerturbator( &m_plastic_normal_perturbator );
|
|
||||||
else
|
|
||||||
blinnMaterial.SetNormalPerturbator( &m_plastic_shine_normal_perturbator );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -124,6 +124,7 @@ private:
|
||||||
CPLASTICNORMAL m_plastic_normal_perturbator;
|
CPLASTICNORMAL m_plastic_normal_perturbator;
|
||||||
CPLASTICSHINENORMAL m_plastic_shine_normal_perturbator;
|
CPLASTICSHINENORMAL m_plastic_shine_normal_perturbator;
|
||||||
CMETALBRUSHEDNORMAL m_brushed_metal_normal_perturbator;
|
CMETALBRUSHEDNORMAL m_brushed_metal_normal_perturbator;
|
||||||
|
CSILKSCREENNORMAL m_silkscreen_normal_perturbator;
|
||||||
|
|
||||||
bool m_isPreview;
|
bool m_isPreview;
|
||||||
|
|
||||||
|
|
|
@ -177,7 +177,7 @@ SFVEC3F CBOARDNORMAL::Generate( const RAY &aRay, const HITINFO &aHitInfo ) const
|
||||||
|
|
||||||
const float noise1 = s_perlinNoise.noise( hitPos.x * 1.0f, hitPos.y * 0.7f ) - 0.5f;
|
const float noise1 = s_perlinNoise.noise( hitPos.x * 1.0f, hitPos.y * 0.7f ) - 0.5f;
|
||||||
const float noise2 = s_perlinNoise.noise( hitPos.x * 0.7f, hitPos.y * 1.0f ) - 0.5f;
|
const float noise2 = s_perlinNoise.noise( hitPos.x * 0.7f, hitPos.y * 1.0f ) - 0.5f;
|
||||||
const float noise3 = s_perlinNoise.noise( hitPos.x * 0.3f, hitPos.y * 0.3f ) - 0.5f;
|
const float noise3 = s_perlinNoise.noise( hitPos.x * 0.3f, hitPos.z * 1.0f ) - 0.5f;
|
||||||
|
|
||||||
return ( SFVEC3F( noise1, noise2, -( noise3 ) ) * 0.3f + SFVEC3F( x, y, z ) );
|
return ( SFVEC3F( noise1, noise2, -( noise3 ) ) * 0.3f + SFVEC3F( x, y, z ) );
|
||||||
}
|
}
|
||||||
|
@ -254,20 +254,20 @@ SFVEC3F CPLASTICNORMAL::Generate( const RAY &aRay, const HITINFO &aHitInfo ) con
|
||||||
const SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale;
|
const SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale;
|
||||||
|
|
||||||
const float noise1 = s_perlinNoise.noise( hitPos.x * 1.0f,
|
const float noise1 = s_perlinNoise.noise( hitPos.x * 1.0f,
|
||||||
|
hitPos.y * 1.1f,
|
||||||
|
hitPos.z * 1.2f ) - 0.5f;
|
||||||
|
|
||||||
|
const float noise2 = s_perlinNoise.noise( hitPos.x * 1.3f,
|
||||||
hitPos.y * 1.0f,
|
hitPos.y * 1.0f,
|
||||||
hitPos.z * 1.0f ) - 0.5f;
|
hitPos.z * 1.5f ) - 0.5f;
|
||||||
|
|
||||||
const float noise2 = s_perlinNoise.noise( hitPos.x * 1.5f,
|
const float noise3 = s_perlinNoise.noise( hitPos.x * 1.0f,
|
||||||
hitPos.y * 1.5f,
|
hitPos.y * 1.0f,
|
||||||
hitPos.z * 2.0f ) - 0.5f;
|
hitPos.z * 1.8f ) - 0.5f;
|
||||||
|
|
||||||
const float noise3 = s_perlinNoise.noise( hitPos.x * 2.0f,
|
const float distanceReduction = 1.0f / ( aHitInfo.m_tHit + 0.5f );
|
||||||
hitPos.y * 2.0f,
|
|
||||||
hitPos.z * 2.0f ) - 0.5f;
|
|
||||||
|
|
||||||
return SFVEC3F( noise1 * noise2 * noise3 * 4.00f,
|
return SFVEC3F( noise1, noise2, noise3 ) * SFVEC3F( distanceReduction );
|
||||||
noise1 * expf(noise2) * noise3 * 4.00f,
|
|
||||||
noise3 * noise3 * 1.00f );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -281,19 +281,20 @@ SFVEC3F CPLASTICSHINENORMAL::Generate( const RAY &aRay, const HITINFO &aHitInfo
|
||||||
{
|
{
|
||||||
const SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale;
|
const SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale;
|
||||||
|
|
||||||
const float noise1 = s_perlinNoise.noise( hitPos.x * 0.05f,
|
const float noise1 = s_perlinNoise.noise( hitPos.x * 0.01f,
|
||||||
hitPos.y * 0.05f,
|
hitPos.y * 0.01f,
|
||||||
hitPos.z * 0.05f ) - 0.5f;
|
hitPos.z * 0.01f ) - 0.5f;
|
||||||
|
|
||||||
const float noise2 = s_perlinNoise.noise( hitPos.x * 0.2f,
|
const float noise2 = s_perlinNoise.noise( hitPos.x * 1.0f,
|
||||||
hitPos.y * 0.2f,
|
hitPos.y * 1.0f,
|
||||||
hitPos.z * 0.2f ) - 0.5f;
|
hitPos.z * 1.6f ) - 0.5f;
|
||||||
|
|
||||||
const float noise3 = s_perlinNoise.noise( hitPos.x * 0.5f,
|
float noise3 = s_perlinNoise.noise( hitPos.x * 1.5f,
|
||||||
hitPos.y * 0.5f,
|
hitPos.y * 1.5f,
|
||||||
hitPos.z * 0.5f ) - 0.5f;
|
hitPos.z * 1.0f ) - 0.5f;
|
||||||
|
noise3 = noise3 * noise3 * noise3;
|
||||||
|
|
||||||
return SFVEC3F( noise1 * 0.5f, noise2 * 0.5f, noise3 * 0.5f );
|
return SFVEC3F( noise1, noise2, noise3 ) * SFVEC3F( 0.1f, 0.2f, 1.0f );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -307,43 +308,44 @@ SFVEC3F CMETALBRUSHEDNORMAL::Generate( const RAY &aRay, const HITINFO &aHitInfo
|
||||||
{
|
{
|
||||||
const SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale;
|
const SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale;
|
||||||
|
|
||||||
const SFVEC3F hitPosRelative = hitPos - glm::floor( hitPos );
|
const float noise1 = s_perlinNoise.noise( hitPos.x * 1.0f,
|
||||||
|
hitPos.y * 1.1f,
|
||||||
|
hitPos.z * 1.2f ) - 0.5f;
|
||||||
|
|
||||||
const float noiseX = (s_perlinNoise.noise( hitPos.x * (60.0f),
|
const float noise2 = s_perlinNoise.noise( hitPos.x * 1.3f,
|
||||||
hitPos.y * 1.0f,
|
hitPos.y * 1.4f,
|
||||||
hitPos.z * 1.0f ) - 0.5f);
|
hitPos.z * 1.5f ) - 0.5f;
|
||||||
|
|
||||||
const float noiseY = (s_perlinNoise.noise( hitPos.x * 1.0f,
|
const float noise3 = s_perlinNoise.noise( hitPos.x * 0.1f,
|
||||||
hitPos.y * (60.0f),
|
hitPos.y * 0.1f,
|
||||||
hitPos.z * 1.0f ) - 0.5f);
|
hitPos.z * 1.0f ) - 0.5f;
|
||||||
|
|
||||||
const float noise2 = (s_perlinNoise.noise( hitPos.x * 1.0f,
|
return SFVEC3F( noise1 * 0.15f + noise3 * 0.35f,
|
||||||
hitPos.y * 1.0f,
|
noise2 * 0.25f,
|
||||||
hitPos.z * 1.0f ) - 0.5f);
|
noise1 * noise2 * noise3 );
|
||||||
|
|
||||||
const float noise3X = (s_perlinNoise.noise( hitPos.x * (80.0f + noise2 * 0.5f),
|
|
||||||
hitPos.y * 0.5f,
|
|
||||||
hitPos.z * 0.5f ) - 0.5f );
|
|
||||||
|
|
||||||
const float noise3Y = (s_perlinNoise.noise( hitPos.x * 0.5f,
|
|
||||||
hitPos.y * (80.0f + noise2 * 0.5f),
|
|
||||||
hitPos.z * 0.5f ) - 0.5f );
|
|
||||||
|
|
||||||
// http://www.fooplot.com/#W3sidHlwZSI6MCwiZXEiOiIoKHgtZmxvb3IoeCkpK3Npbih4KSleMyIsImNvbG9yIjoiIzAwMDAwMCJ9LHsidHlwZSI6MTAwMCwid2luZG93IjpbIi02LjcxNDAwMDAxOTAzMDA3NyIsIjcuMjQ0NjQzNjkyOTY5NzM5IiwiLTMuMTU1NTUyNjAxNDUyNTg4IiwiNS40MzQzODE5OTA1NDczMDY1Il0sInNpemUiOls2NDQsMzk0XX1d
|
|
||||||
// ((x - floor(x))+sin(x))^3
|
|
||||||
|
|
||||||
float sawX = (hitPosRelative.x + glm::sin( 10.0f * hitPos.x + 5.0f * noise2 + Fast_RandFloat() ) );
|
|
||||||
sawX = sawX * sawX * sawX;
|
|
||||||
|
|
||||||
float sawY = (hitPosRelative.y + glm::sin( 10.0f * hitPos.y + 5.0f * noise2 + Fast_RandFloat() ) );
|
|
||||||
sawY = sawY * sawY * sawY;
|
|
||||||
|
|
||||||
float xOut = sawX * noise3X * 0.17f + noiseX * 0.25f + noise3X * 0.57f;
|
|
||||||
float yOut = sawY * noise3Y * 0.17f + noiseY * 0.25f + noise3Y * 0.57f;
|
|
||||||
|
|
||||||
const float outLowFreqNoise = noise2 * 0.05f;
|
|
||||||
|
|
||||||
return SFVEC3F( xOut + outLowFreqNoise,
|
|
||||||
yOut + outLowFreqNoise,
|
|
||||||
0.0f + outLowFreqNoise );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CSILKSCREENNORMAL::CSILKSCREENNORMAL( float aScale )
|
||||||
|
{
|
||||||
|
m_scale = 1.0f / aScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SFVEC3F CSILKSCREENNORMAL::Generate( const RAY &aRay, const HITINFO &aHitInfo ) const
|
||||||
|
{
|
||||||
|
const SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale;
|
||||||
|
|
||||||
|
const float noise1 = s_perlinNoise.noise( hitPos.x * 2.7f,
|
||||||
|
hitPos.y * 2.6f,
|
||||||
|
hitPos.z );
|
||||||
|
|
||||||
|
const float noise2 = s_perlinNoise.noise( hitPos.x * 1.1f,
|
||||||
|
hitPos.y * 1.2f,
|
||||||
|
hitPos.z );
|
||||||
|
|
||||||
|
SFVEC3F t = glm::abs( ( 1.8f / ( SFVEC3F( noise1, noise2, hitPos.z ) + 0.4f ) ) - 1.5f ) - 0.25f;
|
||||||
|
t = t * t * t * 0.1f;
|
||||||
|
|
||||||
|
return t;
|
||||||
|
}
|
|
@ -211,6 +211,26 @@ private:
|
||||||
float m_scale;
|
float m_scale;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CSILKSCREENNORMAL : public CPROCEDURALGENERATOR
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CSILKSCREENNORMAL() : CPROCEDURALGENERATOR()
|
||||||
|
{
|
||||||
|
m_scale = 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
CSILKSCREENNORMAL( float aScale );
|
||||||
|
|
||||||
|
virtual ~CSILKSCREENNORMAL()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Imported from CPROCEDURALGENERATOR
|
||||||
|
SFVEC3F Generate( const RAY &aRay,
|
||||||
|
const HITINFO &aHitInfo ) const override;
|
||||||
|
private:
|
||||||
|
float m_scale;
|
||||||
|
};
|
||||||
|
|
||||||
/// A base material class that can be used to derive a material implementation
|
/// A base material class that can be used to derive a material implementation
|
||||||
class CMATERIAL
|
class CMATERIAL
|
||||||
|
|
Loading…
Reference in New Issue