Skip to content

Commit

Permalink
🪩 Kylie Minogue
Browse files Browse the repository at this point in the history
  • Loading branch information
wobbier committed Mar 3, 2024
1 parent 7252b3b commit 26cca99
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 6 deletions.
83 changes: 81 additions & 2 deletions Tools/ShaderEditor/Source/Nodes/BasicNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,92 @@ bool BasicShaderMasterNode::OnEvaluate()
return false;
}

void BasicShaderMasterNode::ExportShitty( const std::string& inShaderName )
{
{
File file( Path( inShaderName + ".var" ) );
file.Reset();
file.Append( "vec4 v_color0 : COLOR0 = vec4(1.0, 0.0, 0.0, 1.0);\n\
vec3 v_normal : NORMAL = vec3( 0.0, 0.0, 1.0 );\n\
vec2 v_texcoord0 : TEXCOORD0 = vec2( 0.0, 0.0 );\n\
\n\
vec3 a_position : POSITION;\n\
vec3 a_normal : NORMAL;\n\
vec2 a_texcoord0 : TEXCOORD0;\n\
vec3 a_tangent : TANGENT;\n\
vec3 a_bitangent : BITANGENT;\n\
" );
//OnExport( file );

file.Write();
}
{
File file( Path( inShaderName + ".vert" ) );
file.Reset();
file.Append( "$input a_position, a_normal, a_texcoord0, a_tangent, a_bitangent\n\
$output v_color0, v_normal, v_texcoord0\n\
\n\
#include \"Common.sh\"\n\
\n\
void main()\n\
{\n\
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) );\n\
v_color0 = vec4(a_normal.x,a_normal.y,a_normal.z,1.0);\n\
v_texcoord0 = a_texcoord0;\n\
\n\
vec3 normal = a_normal.xyz;\n\
v_normal = mul(u_model[0], vec4(normalize(normal), 0.0) ).xyz;\n\
}" );
//OnExport( file );

file.Write();
}
{
File file( Path( inShaderName + ".frag" ) );
file.Reset();
file.Append( "$input v_color0, v_normal, v_texcoord0\n\
#include \"Common.sh\"\n\
\n\
SAMPLER2D(s_texDiffuse, 0);\n\
SAMPLER2D(s_texNormal, 1);\n\
SAMPLER2D(s_texAlpha, 2);\n\
uniform vec4 s_diffuse;\n\
uniform vec4 s_ambient;\n\
uniform vec4 s_sunDirection;\n\
uniform vec4 s_sunDiffuse;\n\
uniform vec4 s_tiling;\n\
uniform vec4 u_skyLuminance;\n\
\n\
void main()\n\
{\n\
vec2 uvs = v_texcoord0 * s_tiling.xy;\n\
vec4 color = texture2D(s_texDiffuse, uvs) * s_diffuse;\n\
\n\
vec4 ambient = s_ambient * color;\n\
vec4 lightDir = normalize(s_sunDirection);\n\
vec3 skyDirection = vec3(0.0, 0.0, 1.0);\n\
\n\
float diff = max(dot(normalize(v_normal), lightDir), 0.0);\n\
float diffuseSky = 1.0 + 0.5 * dot(normalize(v_normal), skyDirection);\n\
diffuseSky *= 0.03;\n\
vec4 diffuse = diff * s_sunDiffuse;// * color;\n\
color += diffuse;\n\
color += diffuseSky * u_skyLuminance;\n\
color.a = toLinear(texture2D(s_texAlpha, uvs)).r;\n\
gl_FragColor = color;//texture2D(s_texNormal, uvs);//color;ambient + \n\
}" );
///OnExport( file );

file.Write();
}
}

void BasicShaderMasterNode::OnExport( File& inFile )
{
inFile.Append( "BasicShaderMasterNode" );
for( auto pin : Inputs )
{
auto actualPin = pin.LinkedInput ? pin.LinkedInput : &pin;

inFile.Append( std::to_string(std::get<int>( actualPin->Data )) );
inFile.Append( "float var" + std::to_string( m_variableId++ ) + " = " + std::to_string(std::get<int>(actualPin->Data)) + ";\n");
}
}
5 changes: 4 additions & 1 deletion Tools/ShaderEditor/Source/Nodes/BasicNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class LessThanNode
: public Node
{
public:
LessThanNode(int& inId);
LessThanNode( int& inId );

bool OnEvaluate() override;
};
Expand All @@ -32,5 +32,8 @@ class BasicShaderMasterNode
BasicShaderMasterNode( int& inId );

virtual bool OnEvaluate() final;
void ExportShitty( const std::string& inShaderName );
virtual void OnExport( File& inFile ) final;
// static? reset on export? move to base?
int m_variableId = 0;
};
Empty file.
Empty file.
4 changes: 1 addition & 3 deletions Tools/ShaderEditor/Source/ShaderEditorInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,10 +505,8 @@ void ShaderEditorInstance::HandleAddNodeConxtualMenu()

void ShaderEditorInstance::ExportShader()
{
File file( Path( "EXPORT.txt" ) );

m_masterNode->OnExport( file );
file.Write();
m_masterNode->ExportShitty(m_shaderFileName);
}

void ShaderEditorInstance::BlueprintStart()
Expand Down

0 comments on commit 26cca99

Please sign in to comment.