0
我一直在工作,涉及我的Shader編碼的東西我不熟悉的工作項目。我已經提供了來自其他團隊成員的一些HLSL代碼,並一直試圖實現統一。不能直接使用提供的代碼,我一直試圖將它轉換爲unity所希望的格式,如下所示。只是想看看是否有任何明顯的我錯了,它編譯得很好,我可以將它附加到一個對象,但它只是一個平坦的黑色。問題HLSL着色器轉換成shaderLab
Shader "Custom/test2" {
SubShader {
Pass{
CGPROGRAM
#pragma fragment frag
struct PixelInput {
float4 norm : TEXCOORD0;
float4 worldpos : TEXCOORD1;
float4 eyevector : TEXCOORD2;
float4 tangent : TEXCOORD3;
float4 binormal : TEXCOORD4;
float4 objpos : TEXCOORD5;
float4 tex0 : TEXCOORD6;
float4 tex1 : TEXCOORD7;
};
struct PixelOutput {
float4 c : COLOR;
};
uniform sampler2D BumpTex;
uniform sampler2D MarbleCol1;
float4 marblefunc(float4 p, float3 norm, float3 eye, float4 uv){
float3 var;
float3 pos = p.xyz * 0.019500 ;
float3 r = float3(pos.x, pos.y, pos.z);
var[0] = (pos.x +10000)* 0.045000 + 60 *noise (r);
var[2] = var[0]%17;
if (var[2]<4){
r.r = pos.x/70.0f; r.g = pos.y/50.0f; r.b = pos.z/50.0f;
var[1] = 0.7f+0.2f*noise(r);
}
else {
r.r = pos.x; r.g = pos.y; r.b = pos.z;
if (var[2] <9) {
if (var[2] >=12){
var[0] = abs(var[0]-(var[0]/17.0) *17.0 - 10.5)* 0.1538462;
var[1] = 0.3 + 0.3*var[0] + 0.8*noise(r);
}
} else {
var[1] = 0.3f*(1.0f + noise(r));
}
}
float4 c0 = tex2D(MarbleCol1,uv);
float4 c1 = float4(0.301961, 0.815686, 0.101961, 1.0);
return (1.0f-var[1])*c0 + var[1]*c1;
}
uniform float4 Specular = float4(0.900000,0.900000,0.900000,1.000000);
uniform float4 Emissive = float4(0.000000,0.000000,0.000000,1.0f);
uniform float SpecularLevel = 0.000000;
uniform float GlossLevel = 9.999999;
uniform float3 LightCol0;
uniform float3 LightDir0;
uniform float LightFallOff0;
uniform float LightHotSpot0;
uniform float Opacity = 1.000000;
PixelOutput fragmentEntry(PixelInput pi)
{
PixelOutput PO;
float3 N;
N = normalize(pi.norm.xyz);
float3 Eye;
Eye.xyz = normalize(pi.eyevector.xyz);
float4 nColor = float4(0.0,0.0,0.0,1.0);
float3 BumpN;
float3 BumpX, BumpY, BumpZ;
BumpN = tex2D(BumpTex, pi.tex0);
BumpN = (BumpN - 0.5);
BumpN = normalize(float3(BumpN.x *0.300000, BumpN.y *0.300000, BumpN.z));
BumpZ = N;
BumpX = pi.binormal.xyz;
BumpY = pi.tangent.xyz;
BumpX = normalize(BumpX);
BumpY = normalize(BumpY);
BumpZ = normalize(BumpZ);
N = BumpX *BumpN.x + BumpY* BumpN.y + BumpZ *BumpN.z;
float4 mDiffuse;
mDiffuse = marblefunc(pi.objpos, N, Eye, pi.tex0);
float4 mSpecular = Specular;
float4 SelfIllum = Emissive;
nColor = nColor + SelfIllum *mDiffuse;
float3 H;
float3 Light;
float f;
float fAtt;
float fDist;
fAtt = 1.0;
nColor = nColor + float4(LightCol0,1.0)* mDiffuse* clamp(dot(N,LightDir0),0,1)* fAtt;
H = normalize(Eye+Light);
f = clamp(dot(N,H),0,1);
f = pow(f, GlossLevel);
f = f *SpecularLevel;
nColor = nColor + float4(LightCol0,1.0)* mSpecular* f *fAtt;
nColor.a = Opacity;
PO.c = nColor;
return PO;
}
ENDCG
}
}
FallBack "Diffuse"
}
任何和所有的幫助,非常感謝。
好的謝謝你的提示。我原本在那裏有#pragma vertex vert,但把它拿出來,因爲它給出了一個錯誤,所以我可以把它變成它運行的狀態。當你提到使用target 3.0時,是在編譯指令或編譯指令的頂部,而不是編譯指令。其他時間讀取nvidia文件,以獲得更多的舒適與這一切:) – 2014-09-11 09:38:59
@David Parsonson:要更清楚。 target 3.0是一個特定於統一的指令:http://docs.unity3d.com/Manual/SL-ShaderPrograms.html – Heisenbug 2014-09-11 09:45:18