Can someone please show the equavalents of the following standart matrices.
float4x4 WorldITXf : WorldInverseTranspose = ???
float4x4 WvpXf : WorldViewProjection = ???
float4x4 WorldXf : World = ???
float4x4 ViewIXf : ViewInverse = ???
float4x4 WorldIXf: WorldInverse = ???
float4x4 CamPos: EyePosition = ???
.
.
etc.
Even better, can someone show how to convert a standart shaderfx phong effect into unity?
I believe so many people want to know this.
thanks
I know that help page, but the problem is it doesnt say which one is WorldInverseTranspose forexample, so i need someone to translate.
Neither is it, that matrix isn’t present unless you calculate it yourself from World
Unity uses OpenGL nomenclature. WorldInverseTranspose would be UNITY_MATRIX_IT_MV.
Well, for learning purposes, can anyone teach me and everybody else here how to convert a HLSL shader into unity shader thing?
I dont know much of HLSL either but i do understand most of the maths and code written there.
Here is a basic relief mapping shader, if anyone can show how to make it work in unity, ill appreciate.
//====================================================
// Relief Mapping
//====================================================
// By EVOLVED
// [url]www.evolved-software.com[/url]
//====================================================
//--------------
// un-tweaks
//--------------
matrix WorldVP:WorldViewProjection;
matrix World:World;
matrix ViewInv:ViewInverse;
//--------------
// tweaks
//--------------
float3 Ambient={0.3f,0.3f,0.3f};
float3 LightPosition={150.0f,150.0f,0.0f};
float3 LightColor={1.0f,1.0f,1.0f};
float LightRange=200.0f;
float SpecularPow=32.0f;
float depth=0.03;
float4 FogColor={0.8f,0.8f,0.8f,1.0f};
float FogRange=2500.0f;
float Alpha=1.0f;
//--------------
// Textures
//--------------
texture BaseTX <string Name="";>;
sampler2D Base = sampler_state
{
texture = <BaseTX>;
};
texture NormalTX <string Name="";>;
sampler2D Normal = sampler_state
{
texture = <NormalTX>;
};
//--------------
// structs
//--------------
struct input
{
float4 Pos:POSITION;
float2 UV:TEXCOORD;
float3 Normal:NORMAL;
float3 Tangent:TANGENT;
float3 Binormal:BINORMAL;
};
struct output
{
float4 OPos:POSITION;
float2 Tex:TEXCOORD0;
float3 LightVec:TEXCOORD1;
float3 Attenuation:TEXCOORD2;
float3 ViewVec:TEXCOORD3;
float3 ViewPos:TEXCOORD4;
float3 VNormal:TEXCOORD5;
float Fog:FOG;
};
//--------------
// vertex shader
//--------------
output VS(input IN)
{
output OUT;
OUT.OPos=mul(IN.Pos,WorldVP);
OUT.Tex=IN.UV;
float3x3 TBN={IN.Tangent,IN.Binormal,IN.Normal};
TBN=transpose(mul(TBN,World));
float3 WPos=mul(IN.Pos,World);
float3 LightPos=LightPosition-WPos;
float3 ViewPos=ViewInv[3].xyz-WPos;
OUT.LightVec=mul(LightPos,TBN);
OUT.Attenuation=-LightPos/LightRange;
OUT.ViewVec=mul(ViewPos,TBN);
OUT.ViewPos=-ViewPos;
OUT.VNormal=mul(IN.Normal,World);
OUT.Fog=1-saturate(dot(ViewPos/FogRange,ViewPos/FogRange));
return OUT;
}
//--------------
// pixel shader
//--------------
float GetDepth(in float2 Uv,in float2 Displace)
{
float Height=0.0;
float depth=1.0;
float Inc=0.125f;
for( int i=0;i<8;i++ )
{
Height+=Inc;
float HeightTex=tex2D(Normal,Uv+Displace*Height).w;
if (depth>0.995)
if (Height>=HeightTex) depth=Height;
}
Height=depth;
for( int i=0;i<4;i++ )
{
Inc*=0.5;
float HeightTex=tex2D(Normal,Uv+Displace*Height).w;
if (Height>=HeightTex)
{
depth=Height;
Height-=2*Inc;
}
Height=Height+Inc;
}
return depth;
}
float4 PS(output IN) : COLOR
{
float2 Uv=IN.Tex;
float3 View=normalize(IN.ViewVec);
float ViewN=dot(IN.VNormal,normalize(IN.ViewPos));
float2 Displace=((View*depth)/ViewN).xy;
float Ray=GetDepth(Uv,Displace);
float2 NewUv=(Uv+Displace*Ray);
float4 Texture=tex2D(Base,NewUv);
float3 NormalMap=tex2D(Normal,NewUv)*2-1; NormalMap.y=-NormalMap.y;
NormalMap=normalize(NormalMap);
float3 LightV=normalize(IN.LightVec);
float Normal=saturate(dot(reflect(-View,NormalMap),LightV));
Normal=pow(Normal,SpecularPow)+saturate(dot(NormalMap,LightV));
float PixelLight=1-saturate(dot(IN.Attenuation,IN.Attenuation));
float3 Light=PixelLight*LightColor;
return float4(Texture*((Normal*Light)+Ambient),Texture.w*Alpha);
}
//--------------
// techniques
//--------------
technique Relief
{
pass p1
{
vertexShader = compile vs_2_0 VS();
pixelShader = compile ps_2_a PS();
FOGCOLOR=(FogColor);
FOGENABLE=TRUE;
}
}
I think a more basic example will ensure that someone helps you out ).
Honestly, I don’t think I’ve ever seen someone get “help converting a shader from X” in this forum. What people asking this question don’t realize is that it’s a slightly different version of “teach me how to write this shader”. That’s not going to happen on a web forum.
To do this yourself, you need to know what the shader does (pretty much what the math on every line means), and you need to know how to write Shaderlab and Cg fluently. If you don’t know these things, you’ll have to learn them, which will take a lot of effort, or get someone who already knows them to do the translation. Getting someone else to do it usually costs money, but it’s probably the cheaper option if your time is worth anything.
wait for more surfaceshader reference and example come,then you could do it.
but now i think few people could do it in unity3.0,maybe some could do it in unity2.6.
ivkoni
November 8, 2010, 10:59pm
11
you can check this thread:
standard untweakables
Thank you kind sir, that was what i needed indeed.