2016-07-19 17:35:25 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2020-04-25 14:38:41 +00:00
|
|
|
* Copyright (C) 2015-2020 Mario Luzeiro <mrluzeiro@ua.pt>
|
2020-12-12 17:29:11 +00:00
|
|
|
* Copyright (C) 2015-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-07-19 17:35:25 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-01-03 22:23:00 +00:00
|
|
|
* @file material.cpp
|
2016-07-19 17:35:25 +00:00
|
|
|
*/
|
|
|
|
|
2021-01-03 22:23:00 +00:00
|
|
|
#include "material.h"
|
2016-09-30 23:59:51 +00:00
|
|
|
#include <3d_math.h>
|
2016-07-19 17:35:25 +00:00
|
|
|
#include <wx/debug.h>
|
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
int MATERIAL::m_defaultRefractionRayCount = 4;
|
|
|
|
int MATERIAL::m_defaultReflectionRayCount = 3;
|
|
|
|
int MATERIAL::m_defaultRefractionRecursionCount = 2;
|
|
|
|
int MATERIAL::m_defaultFeflectionRecursionCount = 3;
|
2020-09-04 15:12:01 +00:00
|
|
|
|
2016-11-26 14:38:51 +00:00
|
|
|
// 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)
|
|
|
|
#define SPECULAR_FACTOR 1.0f
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
MATERIAL::MATERIAL()
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
m_ambientColor = SFVEC3F( 0.2f, 0.2f, 0.2f );
|
|
|
|
m_emissiveColor = SFVEC3F( 0.0f, 0.0f, 0.0f );
|
|
|
|
m_specularColor = SFVEC3F( 1.0f, 1.0f, 1.0f );
|
2021-01-07 19:33:43 +00:00
|
|
|
m_reflectivity = 50.2f;
|
2016-07-19 17:35:25 +00:00
|
|
|
m_transparency = 0.0f; // completely opaque
|
2021-01-07 19:33:43 +00:00
|
|
|
m_castShadows = true;
|
2016-07-19 17:35:25 +00:00
|
|
|
m_reflection = 0.0f;
|
2017-01-21 12:30:05 +00:00
|
|
|
m_absorbance = 1.0f;
|
2021-01-07 19:33:43 +00:00
|
|
|
m_refractionRayCount = m_defaultRefractionRayCount;
|
|
|
|
m_reflectionRayCount = m_defaultReflectionRayCount;
|
|
|
|
m_refractionRecursionCount = m_defaultRefractionRecursionCount;
|
|
|
|
m_reflectionRecursionCount = m_defaultFeflectionRecursionCount;
|
2016-09-30 23:59:51 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
m_generator = nullptr;
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
MATERIAL::MATERIAL( const SFVEC3F& aAmbient, const SFVEC3F& aEmissive, const SFVEC3F& aSpecular,
|
2021-01-03 22:23:00 +00:00
|
|
|
float aShinness, float aTransparency, float aReflection )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
wxASSERT( aReflection >= 0.0f );
|
|
|
|
wxASSERT( aReflection <= 1.0f );
|
|
|
|
|
|
|
|
wxASSERT( aTransparency >= 0.0f );
|
|
|
|
wxASSERT( aTransparency <= 1.0f );
|
|
|
|
|
|
|
|
wxASSERT( aShinness >= 0.0f );
|
|
|
|
wxASSERT( aShinness <= 180.0f );
|
|
|
|
|
2016-11-26 14:38:51 +00:00
|
|
|
m_ambientColor = aAmbient * SFVEC3F(AMBIENT_FACTOR);
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
m_emissiveColor = aEmissive;
|
|
|
|
m_specularColor = aSpecular;
|
2021-01-07 19:33:43 +00:00
|
|
|
m_reflectivity = aShinness;
|
2020-04-25 14:38:41 +00:00
|
|
|
m_transparency = glm::clamp( aTransparency, 0.0f, 1.0f );
|
2017-01-21 12:30:05 +00:00
|
|
|
m_absorbance = 1.0f;
|
2016-07-19 17:35:25 +00:00
|
|
|
m_reflection = aReflection;
|
2021-01-07 19:33:43 +00:00
|
|
|
m_castShadows = true;
|
|
|
|
m_refractionRayCount = m_defaultRefractionRayCount;
|
|
|
|
m_reflectionRayCount = m_defaultReflectionRayCount;
|
|
|
|
m_refractionRecursionCount = m_defaultRefractionRecursionCount;
|
|
|
|
m_reflectionRecursionCount = m_defaultFeflectionRecursionCount;
|
2016-09-30 23:59:51 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
m_generator = nullptr;
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
void MATERIAL::Generate( SFVEC3F& aNormal, const RAY& aRay, const HITINFO& aHitInfo ) const
|
2016-10-02 08:11:00 +00:00
|
|
|
{
|
2021-01-07 19:33:43 +00:00
|
|
|
if( m_generator )
|
2016-10-02 08:11:00 +00:00
|
|
|
{
|
2021-01-07 19:33:43 +00:00
|
|
|
aNormal = aNormal + m_generator->Generate( aRay, aHitInfo );
|
2016-10-02 08:11:00 +00:00
|
|
|
aNormal = glm::normalize( aNormal );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_shading_model
|
2021-01-02 21:05:29 +00:00
|
|
|
SFVEC3F BLINN_PHONG_MATERIAL::Shade( const RAY& aRay, const HITINFO& aHitInfo, float NdotL,
|
|
|
|
const SFVEC3F& aDiffuseObjColor, const SFVEC3F& aDirToLight,
|
|
|
|
const SFVEC3F& aLightColor,
|
|
|
|
float aShadowAttenuationFactor ) const
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
wxASSERT( NdotL >= FLT_EPSILON );
|
|
|
|
|
|
|
|
// This is a hack to get some kind of fake ambient illumination
|
|
|
|
// There is no logic behind this, just pure artistic experimentation
|
|
|
|
if( aShadowAttenuationFactor > FLT_EPSILON )
|
|
|
|
{
|
|
|
|
// Calculate the diffuse light factoring in light color,
|
|
|
|
// power and the attenuation
|
|
|
|
const SFVEC3F diffuse = NdotL * aLightColor;
|
|
|
|
|
|
|
|
// Calculate the half vector between the light vector and the view vector.
|
|
|
|
const SFVEC3F H = glm::normalize( aDirToLight - aRay.m_Dir );
|
|
|
|
|
|
|
|
//Intensity of the specular light
|
|
|
|
const float NdotH = glm::dot( H, aHitInfo.m_HitNormal );
|
2021-01-07 19:33:43 +00:00
|
|
|
const float intensitySpecular = glm::pow( glm::max( NdotH, 0.0f ), m_reflectivity );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2016-11-26 14:38:51 +00:00
|
|
|
return m_ambientColor +
|
2021-01-02 21:05:29 +00:00
|
|
|
aShadowAttenuationFactor * ( diffuse * aDiffuseObjColor + SPECULAR_FACTOR *
|
|
|
|
aLightColor * intensitySpecular * m_specularColor );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
2016-11-26 14:38:51 +00:00
|
|
|
return m_ambientColor;
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2016-09-30 23:59:51 +00:00
|
|
|
|
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
MATERIAL_GENERATOR::MATERIAL_GENERATOR()
|
2016-09-30 23:59:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-08 00:32:00 +00:00
|
|
|
static PerlinNoise s_perlinNoise = PerlinNoise( 0 );
|
|
|
|
|
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
BOARD_NORMAL::BOARD_NORMAL( float aScale ) : MATERIAL_GENERATOR()
|
2016-09-30 23:59:51 +00:00
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
m_scale = ( 2.0f * glm::pi<float>() ) / aScale;
|
2016-09-30 23:59:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
SFVEC3F BOARD_NORMAL::Generate( const RAY& aRay, const HITINFO& aHitInfo ) const
|
2016-09-30 23:59:51 +00:00
|
|
|
{
|
2020-09-08 00:32:00 +00:00
|
|
|
const SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale;
|
2016-09-30 23:59:51 +00:00
|
|
|
|
2016-10-02 08:11:00 +00:00
|
|
|
// http://www.fooplot.com/#W3sidHlwZSI6MCwiZXEiOiJzaW4oc2luKHNpbih4KSoxLjkpKjEuNSkiLCJjb2xvciI6IiMwMDAwMDAifSx7InR5cGUiOjEwMDAsIndpbmRvdyI6WyItMC45NjIxMDU3MDgwNzg1MjYyIiwiNy45NzE0MjYyNjc2MDE0MyIsIi0yLjUxNzYyMDM1MTQ4MjQ0OSIsIjIuOTc5OTM3Nzg3Mzk3NTMwMyJdLCJzaXplIjpbNjQ2LDM5Nl19XQ--
|
2016-09-30 23:59:51 +00:00
|
|
|
|
2016-10-04 21:23:21 +00:00
|
|
|
// Implement a texture as the "measling crazing blistering" method of FR4
|
2020-09-08 00:32:00 +00:00
|
|
|
const float x = glm::sin( glm::sin( hitPos.x ) * 1.5f ) * 0.06f;
|
|
|
|
const float y = glm::sin( glm::sin( hitPos.y ) * 1.5f ) * 0.03f;
|
|
|
|
const float z = -(x + y) + glm::sin( hitPos.z ) * 0.06f;
|
2016-10-02 08:11:00 +00:00
|
|
|
|
2020-09-08 00:32:00 +00:00
|
|
|
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;
|
2020-11-06 17:36:04 +00:00
|
|
|
const float noise3 = s_perlinNoise.noise( hitPos.x * 0.3f, hitPos.z * 1.0f ) - 0.5f;
|
2020-09-08 00:32:00 +00:00
|
|
|
|
|
|
|
return ( SFVEC3F( noise1, noise2, -( noise3 ) ) * 0.3f + SFVEC3F( x, y, z ) );
|
2016-09-30 23:59:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
COPPER_NORMAL::COPPER_NORMAL( float aScale, const MATERIAL_GENERATOR* aBoardNormalGenerator )
|
2016-09-30 23:59:51 +00:00
|
|
|
{
|
|
|
|
m_board_normal_generator = aBoardNormalGenerator;
|
2016-10-02 08:11:00 +00:00
|
|
|
m_scale = 1.0f / aScale;
|
2016-09-30 23:59:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
SFVEC3F COPPER_NORMAL::Generate( const RAY& aRay, const HITINFO& aHitInfo ) const
|
2016-09-30 23:59:51 +00:00
|
|
|
{
|
|
|
|
if( m_board_normal_generator )
|
|
|
|
{
|
|
|
|
const SFVEC3F boardNormal = m_board_normal_generator->Generate( aRay, aHitInfo );
|
|
|
|
|
2016-10-02 08:11:00 +00:00
|
|
|
SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale;
|
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
const float noise =
|
|
|
|
( s_perlinNoise.noise( hitPos.x + boardNormal.y + aRay.m_Origin.x * 0.2f,
|
2021-01-02 21:05:29 +00:00
|
|
|
hitPos.y + boardNormal.x ) - 0.5f ) * 2.0f;
|
2016-10-02 08:11:00 +00:00
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
float scratchPattern =
|
|
|
|
( s_perlinNoise.noise( noise + hitPos.x / 100.0f, hitPos.y * 100.0f ) - 0.5f );
|
2016-10-02 08:11:00 +00:00
|
|
|
|
2020-09-08 00:32:00 +00:00
|
|
|
const float x = scratchPattern * 0.14f;
|
|
|
|
const float y = (noise + noise * scratchPattern) * 0.14f;
|
2016-10-02 08:11:00 +00:00
|
|
|
|
2020-09-08 00:32:00 +00:00
|
|
|
return SFVEC3F( x, y, - ( x + y ) ) + boardNormal * 0.25f;
|
2016-09-30 23:59:51 +00:00
|
|
|
}
|
|
|
|
else
|
2020-12-12 17:29:11 +00:00
|
|
|
{
|
|
|
|
return SFVEC3F( 0.0f );
|
|
|
|
}
|
2016-09-30 23:59:51 +00:00
|
|
|
}
|
|
|
|
|
2016-10-02 08:11:00 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
SOLDER_MASK_NORMAL::SOLDER_MASK_NORMAL( const MATERIAL_GENERATOR* aCopperNormalGenerator )
|
2016-09-30 23:59:51 +00:00
|
|
|
{
|
|
|
|
m_copper_normal_generator = aCopperNormalGenerator;
|
|
|
|
}
|
|
|
|
|
2016-10-02 08:11:00 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
SFVEC3F SOLDER_MASK_NORMAL::Generate( const RAY& aRay, const HITINFO& aHitInfo ) const
|
2016-09-30 23:59:51 +00:00
|
|
|
{
|
|
|
|
if( m_copper_normal_generator )
|
|
|
|
{
|
|
|
|
const SFVEC3F copperNormal = m_copper_normal_generator->Generate( aRay, aHitInfo );
|
|
|
|
|
2020-09-08 00:32:00 +00:00
|
|
|
return copperNormal * 0.05f;
|
2016-09-30 23:59:51 +00:00
|
|
|
}
|
|
|
|
else
|
2020-12-12 17:29:11 +00:00
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
return SFVEC3F( 0.0f );
|
2020-12-12 17:29:11 +00:00
|
|
|
}
|
2016-09-30 23:59:51 +00:00
|
|
|
}
|
2016-10-02 08:11:00 +00:00
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
SFVEC3F PLATED_COPPER_NORMAL::Generate( const RAY& aRay, const HITINFO& aHitInfo ) const
|
2020-09-08 00:32:00 +00:00
|
|
|
{
|
|
|
|
SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale;
|
|
|
|
|
|
|
|
const float noise1 = ( s_perlinNoise.noise( hitPos.x, hitPos.y ) - 0.5f );
|
|
|
|
const float noise2 = ( s_perlinNoise.noise( hitPos.y, hitPos.x ) - 0.5f );
|
|
|
|
|
|
|
|
return SFVEC3F( noise1, noise2, -( noise1 + noise2 ) ) * 0.02f;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
PLASTIC_NORMAL::PLASTIC_NORMAL( float aScale )
|
2016-10-02 08:11:00 +00:00
|
|
|
{
|
|
|
|
m_scale = 1.0f / aScale;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
SFVEC3F PLASTIC_NORMAL::Generate( const RAY& aRay, const HITINFO& aHitInfo ) const
|
2016-10-02 08:11:00 +00:00
|
|
|
{
|
2016-11-26 14:38:51 +00:00
|
|
|
const SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale;
|
2016-10-02 08:11:00 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
const float noise1 = s_perlinNoise.noise( hitPos.x * 1.0f, hitPos.y * 1.1f,
|
2020-11-06 17:36:04 +00:00
|
|
|
hitPos.z * 1.2f ) - 0.5f;
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
const float noise2 = s_perlinNoise.noise( hitPos.x * 1.3f, hitPos.y * 1.0f,
|
2020-11-06 17:36:04 +00:00
|
|
|
hitPos.z * 1.5f ) - 0.5f;
|
2016-10-02 08:11:00 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
const float noise3 = s_perlinNoise.noise( hitPos.x * 1.0f, hitPos.y * 1.0f,
|
2020-11-06 17:36:04 +00:00
|
|
|
hitPos.z * 1.8f ) - 0.5f;
|
2016-10-02 08:11:00 +00:00
|
|
|
|
2020-11-06 17:36:04 +00:00
|
|
|
const float distanceReduction = 1.0f / ( aHitInfo.m_tHit + 0.5f );
|
2016-10-02 08:11:00 +00:00
|
|
|
|
2020-11-06 17:36:04 +00:00
|
|
|
return SFVEC3F( noise1, noise2, noise3 ) * SFVEC3F( distanceReduction );
|
2016-10-02 08:11:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
PLASTIC_SHINE_NORMAL::PLASTIC_SHINE_NORMAL( float aScale )
|
2016-10-02 08:11:00 +00:00
|
|
|
{
|
|
|
|
m_scale = 1.0f / aScale;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
SFVEC3F PLASTIC_SHINE_NORMAL::Generate( const RAY& aRay, const HITINFO& aHitInfo ) const
|
2016-10-02 08:11:00 +00:00
|
|
|
{
|
2016-11-26 14:38:51 +00:00
|
|
|
const SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale;
|
2016-10-02 08:11:00 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
const float noise1 = s_perlinNoise.noise( hitPos.x * 0.01f, hitPos.y * 0.01f,
|
2020-11-06 17:36:04 +00:00
|
|
|
hitPos.z * 0.01f ) - 0.5f;
|
2016-10-02 12:16:40 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
const float noise2 = s_perlinNoise.noise( hitPos.x * 1.0f, hitPos.y * 1.0f,
|
2020-11-06 17:36:04 +00:00
|
|
|
hitPos.z * 1.6f ) - 0.5f;
|
2016-11-26 18:11:45 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
float noise3 = s_perlinNoise.noise( hitPos.x * 1.5f, hitPos.y * 1.5f,
|
2020-11-06 17:36:04 +00:00
|
|
|
hitPos.z * 1.0f ) - 0.5f;
|
|
|
|
noise3 = noise3 * noise3 * noise3;
|
2016-10-02 12:16:40 +00:00
|
|
|
|
2020-11-06 17:36:04 +00:00
|
|
|
return SFVEC3F( noise1, noise2, noise3 ) * SFVEC3F( 0.1f, 0.2f, 1.0f );
|
2016-10-02 12:16:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
BRUSHED_METAL_NORMAL::BRUSHED_METAL_NORMAL( float aScale )
|
2016-10-02 12:16:40 +00:00
|
|
|
{
|
|
|
|
m_scale = 1.0f / aScale;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
SFVEC3F BRUSHED_METAL_NORMAL::Generate( const RAY& aRay, const HITINFO& aHitInfo ) const
|
2016-10-02 12:16:40 +00:00
|
|
|
{
|
2017-01-21 22:17:12 +00:00
|
|
|
const SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale;
|
2016-10-02 12:16:40 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
const float noise1 = s_perlinNoise.noise( hitPos.x * 1.0f, hitPos.y * 1.1f,
|
2020-11-06 17:36:04 +00:00
|
|
|
hitPos.z * 1.2f ) - 0.5f;
|
2016-10-02 12:16:40 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
const float noise2 = s_perlinNoise.noise( hitPos.x * 1.3f, hitPos.y * 1.4f,
|
2020-11-06 17:36:04 +00:00
|
|
|
hitPos.z * 1.5f ) - 0.5f;
|
2016-10-02 12:16:40 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
const float noise3 = s_perlinNoise.noise( hitPos.x * 0.1f, hitPos.y * 0.1f,
|
2020-11-06 17:36:04 +00:00
|
|
|
hitPos.z * 1.0f ) - 0.5f;
|
2016-10-02 12:16:40 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
return SFVEC3F( noise1 * 0.15f + noise3 * 0.35f, noise2 * 0.25f, noise1 * noise2 * noise3 );
|
2020-11-06 17:36:04 +00:00
|
|
|
}
|
2016-10-02 12:16:40 +00:00
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
SILK_SCREEN_NORMAL::SILK_SCREEN_NORMAL( float aScale )
|
2020-11-06 17:36:04 +00:00
|
|
|
{
|
|
|
|
m_scale = 1.0f / aScale;
|
|
|
|
}
|
2016-10-02 12:16:40 +00:00
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
SFVEC3F SILK_SCREEN_NORMAL::Generate( const RAY& aRay, const HITINFO& aHitInfo ) const
|
2020-11-06 17:36:04 +00:00
|
|
|
{
|
|
|
|
const SFVEC3F hitPos = aHitInfo.m_HitPoint * m_scale;
|
2016-10-02 12:16:40 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
const float noise1 = s_perlinNoise.noise( hitPos.x * 2.7f, hitPos.y * 2.6f, hitPos.z );
|
2016-10-02 12:16:40 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
const float noise2 = s_perlinNoise.noise( hitPos.x * 1.1f, hitPos.y * 1.2f, hitPos.z );
|
2016-10-02 08:11:00 +00:00
|
|
|
|
2020-12-12 17:29:11 +00:00
|
|
|
SFVEC3F t =
|
|
|
|
glm::abs( ( 1.8f / ( SFVEC3F( noise1, noise2, hitPos.z ) + 0.4f ) ) - 1.5f ) - 0.25f;
|
2020-11-06 17:36:04 +00:00
|
|
|
t = t * t * t * 0.1f;
|
2016-10-02 08:11:00 +00:00
|
|
|
|
2020-11-06 17:36:04 +00:00
|
|
|
return t;
|
2020-12-12 17:29:11 +00:00
|
|
|
}
|