0 registered members (),
1,397
guests, and 7
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: texture lookups problem
[Re: zefor]
#62391
01/21/06 16:08
01/21/06 16:08
|
Joined: Mar 2002
Posts: 221 USA
zefor
OP
Member
|
OP
Member
Joined: Mar 2002
Posts: 221
USA
|
Tried to add sunlight, dynamic lights, and fog from wiki. Engine does not like this line " vecSkill41 " and I do not know what to do about it. I commented the line with ///Doesnt like this line?? Here is what I have now. Code:
float4x4 matWorldViewProj: register(c0); float4x4 matView: register(c4); float4x4 matWorld; /////////////////////////////////// float4 vecSunDir; float4 vecSunDiffuse = float4(200.f/255.f, 200.f/255.f, 200.f/255.f, 1.f); float4 vecLightPos[8]; float4 vecLightColor[8]; float3 vecFalloff = float3(0.f, 0.f, 2.f); float4 vecFog; /////////////////////////////////// texture entSkin1; texture entSkin2;
sampler ColorMapSampler = sampler_state { Texture = <entSkin1>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = wrap; AddressV = wrap; };
sampler BumpMapSampler = sampler_state { Texture = <entSkin2>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = wrap; AddressV = wrap; };
///////////////////////// float4 DoPointLight(float3 P, float3 N, int i) { // calculate the light ray pointing from the light to the surface float3 D = (float3)vecLightPos[i]-P; // calculate the angle between surface and light ray float NdotL = dot(N,normalize(D)); // modulate the light by the surface angle float4 Color = vecLightColor[i] * NdotL;
// calculate the light attenuation factor, DX uses a really strange formula here float fac = 0.f; if (NdotL >= 0.f && vecLightPos[i].w > 0.f) { // get the distance factor float LD = length(D)/vecLightPos[i].w; #ifdef DXLIGHTING if (LD < 1.3f) fac = 1.f/(vecFalloff.x + vecFalloff.y*LD + vecFalloff.z*LD*LD); #else // linear Lighting if (LD < 1.f) fac = 1.f - LD; #endif } return Color * fac; }
float4 DoSunLight(float3 N) { // modulate the sunlight by the surface angle return vecSunDiffuse * dot(N,-vecSunDir); } float DoFog(float3 Pos) { // convert the vector position to view space to get it's depth (.z) float3 P = mul(Pos,matWorldViewProj); // apply the linear fog formula return saturate((vecFog.y-P.z) * vecFog.z); } ///////////////////////////////////
struct VS_OUTPUT { float4 Pos: POSITION; float2 texCoord: TEXCOORD0; float3 lightvec: TEXCOORD1;
float4 Color: COLOR0; float Fog: FOG; };
//VS_OUTPUT VS1(float4 Pos: POSITION, float3 normal: NORMAL, float3 tangent: TANGENT, float3 binormal: BINORMAL) { VS_OUTPUT VS1(float4 inPos: POSITION, float3 inNormal: NORMAL, float3 tangent: TANGENT) { VS_OUTPUT Out;
//Out.Pos = mul(view_proj_matrix, Pos); Out.Pos = mul(inPos, matWorldViewProj);
// transform the normal and the position float3 N = normalize(mul(inNormal,matWorld)); float3 P = mul(inPos,matWorld); // Add ambient and sun light Out.Color = vecSkill41.w + DoSunLight(N); //////////////Doesnt like this line??? // Add 6 dynamic lights (maximum for vs 1.1) for (int i=0; i<6; i++) Out.Color += DoPointLight(P,N,i); // Add fog Out.Fog = DoFog(inPos);
// convert texture coordinates or do other stuff
// Some object-linear texgen, specific for this particular model Out.texCoord.x = Pos.x * 0.0065 + 0.46; Out.texCoord.y = Pos.z * 0.0065 + 0.46;
//float3 Pview = -mul(view_matrix, Pos); float3 Pview = -mul(matView, Pos);
// Move our tangent-space into eye-space float3 vtang = mul(matView, tangent); float3 vbinorm = mul(matView, cross(tangent, normal)); float3 vnorm = mul(matView, normal);
// We use lightVec = viewVec, that is, the camera is also the light. float3 lightvec = Pview;
// Transform light vector from eye-space to tangent-soace Out.lightvec.x = dot(lightvec, vtang); Out.lightvec.y = dot(lightvec, vbinorm); Out.lightvec.z = dot(lightvec, vnorm);
return Out; }
/////////////////////Pixel Shader
float4 Gold: register(c0); sampler ColorMap: register(s0); sampler BumpMap: register(s1);
float4 PS1(float2 texCoord: TEXCOORD0, float3 lightvec: TEXCOORD1) : COLOR { float4 base = tex2D(ColorMapSampler, texCoord); float3 bump = tex2D(BumpMapSampler, texCoord) * 2.0 - 1.0;
// shine = diffuse and specular float shine = saturate(dot(normalize(lightvec), normalize(bump))); return (shine * 0.2) * base + pow(shine, 64) * Gold;
}
technique Gold_shine { pass p0 { VertexShader = compile vs_1_1 VS1(); PixelShader = compile ps_2_0 PS1(); } }
Last edited by zefor; 01/21/06 16:09.
|
|
|
Re: texture lookups problem
[Re: zefor]
#62396
01/24/06 07:32
01/24/06 07:32
|
Joined: Oct 2002
Posts: 8,939 planet.earth
ello
Senior Expert
|
Senior Expert
Joined: Oct 2002
Posts: 8,939
planet.earth
|
from what i see you dont pass the uv-texture coordinates of the model to the pixelshader : Code:
VS_OUTPUT VS1(float4 inPos: POSITION, float3 inNormal: NORMAL, float3 tangent: TANGENT, float2 texCoord : TEXCOORD0) {
...
Out.texCoord = texCoord; ...
Last edited by ello; 01/24/06 07:33.
www.earthcontrol.dequoted: We want to maintain a clean, decent, American family suited forum look... which means you may post zombies or chainsaw massacres, but no erotic.
|
|
|
Re: texture lookups problem
[Re: ello]
#62397
01/24/06 13:36
01/24/06 13:36
|
Joined: Mar 2002
Posts: 221 USA
zefor
OP
Member
|
OP
Member
Joined: Mar 2002
Posts: 221
USA
|
Still a no-go. Here is the code with all of the corrections. Do I have the lighting code that I got from the wiki placed in the proper area? I am racking my brain, but i just dont seem to be getting anywhere. Code:
float4x4 matWorldViewProj: register(c0); float4x4 matView: register(c4); float4x4 matWorld;
float4 vecSkill41; float4 vecSunDir; float4 vecSunDiffuse = float4(200.f/255.f, 200.f/255.f, 200.f/255.f, 1.f); float4 vecLightPos[8]; float4 vecLightColor[8]; float3 vecFalloff = float3(0.f, 0.f, 2.f); float4 vecFog;
texture entSkin1; texture entSkin2;
sampler ColorMapSampler = sampler_state { Texture = <entSkin1>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = wrap; AddressV = wrap; };
sampler BumpMapSampler = sampler_state { Texture = <entSkin2>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = wrap; AddressV = wrap; };
/////////////////////////LIGHTING FROM WIKI//////////////
float4 DoPointLight(float3 P, float3 N, int i) { // calculate the light ray pointing from the light to the surface float3 D = (float3)vecLightPos[i]-P; // calculate the angle between surface and light ray float NdotL = dot(N,normalize(D)); // modulate the light by the surface angle float4 Color = vecLightColor[i] * NdotL;
// calculate the light attenuation factor, DX uses a really strange formula here float fac = 0.f; if (NdotL >= 0.f && vecLightPos[i].w > 0.f) { // get the distance factor float LD = length(D)/vecLightPos[i].w; #ifdef DXLIGHTING if (LD < 1.3f) fac = 1.f/(vecFalloff.x + vecFalloff.y*LD + vecFalloff.z*LD*LD); #else // linear Lighting if (LD < 1.f) fac = 1.f - LD; #endif } return Color * fac; }
float4 DoSunLight(float3 N) { // modulate the sunlight by the surface angle return vecSunDiffuse * dot(N,-vecSunDir); } float DoFog(float3 Pos) { // convert the vector position to view space to get it's depth (.z) float3 P = mul(Pos,matWorldViewProj); // apply the linear fog formula return saturate((vecFog.y-P.z) * vecFog.z); } ///////////////////////////////////
struct VS_OUTPUT { float4 Pos: POSITION; float2 texCoord: TEXCOORD0; float3 lightvec: TEXCOORD1;
float4 Color: COLOR0; float Fog: FOG; };
VS_OUTPUT VS1(float4 inPos: POSITION, float3 normal: normal, float3 tangent: TANGENT, float2 texCoord : TEXCOORD0) { VS_OUTPUT Out;
//Out.Pos = mul(view_proj_matrix, Pos); Out.Pos = mul(inPos, matWorldViewProj);
// transform the normal and the position float3 N = normalize(mul(normal,matWorld)); float3 P = mul(inPos,matWorld); // Add ambient and sun light Out.Color = vecSkill41.w + DoSunLight(N); // Add 6 dynamic lights (maximum for vs 1.1) for (int i=0; i<6; i++) Out.Color += DoPointLight(P,N,i); // Add fog Out.Fog = DoFog(inPos);
// convert texture coordinates or do other stuff
// Some object-linear texgen, specific for this particular model Out.texCoord.x = inPos.x * 0.0065 + 0.46; Out.texCoord.y = inPos.z * 0.0065 + 0.46; Out.texCoord = texCoord;
float3 Pview = -mul(matView, inPos);
// Move our tangent-space into eye-space float3 vtang = mul(matView, tangent); float3 vbinorm = mul(matView, cross(tangent, normal)); float3 vnorm = mul(matView, normal);
// We use lightVec = viewVec, that is, the camera is also the light. float3 lightvec = Pview;
// Transform light vector from eye-space to tangent-soace Out.lightvec.x = dot(lightvec, vtang); Out.lightvec.y = dot(lightvec, vbinorm); Out.lightvec.z = dot(lightvec, vnorm);
return Out; }
/////////////////////Pixel Shader
float4 Gold: register(c0); sampler ColorMap: register(s0); sampler BumpMap: register(s1);
float4 PS1(float2 texCoord: TEXCOORD0, float3 lightvec: TEXCOORD1) : COLOR { float4 base = tex2D(ColorMapSampler, texCoord); float3 bump = tex2D(BumpMapSampler, texCoord) * 2.0 - 1.0;
// shine = diffuse and specular float shine = saturate(dot(normalize(lightvec), normalize(bump))); return (shine * 0.2) * base + pow(shine, 64) * Gold;
}
technique Gold_shine { pass p0 { VertexShader = compile vs_2_0 VS1(); PixelShader = compile ps_2_0 PS1(); } }
|
|
|
Re: texture lookups problem
[Re: zefor]
#62398
01/24/06 18:33
01/24/06 18:33
|
Joined: Oct 2003
Posts: 4,131
Matt_Aufderheide
Expert
|
Expert
Joined: Oct 2003
Posts: 4,131
|
Well, first of all you dont apply the lighitng in the pixel shader.. you cant just calculate the color in the vertex shader and expect it to do anything if you havea pixel shader. You must multiply the pixel shader result by the lighitng. To do this you have to modify your pixel shader inputs to include the color0 data. Then you multiply the result by it.
However, this is only going to add vertex lighting, and doesnt have anything to do with why the gold shine effect doesnt work. The model ought not to be black in any case. The reason it is black is that you multiply the final result in the pixel shader by a constant called "Gold", when in fact you don't actually define this constant's value anywhere, so of course it has a default value of zero. And you know that you multiply anything by zero you get .. zero. Which is black.
delete this line: float4 Gold: register(c0); and replace it with something like this: float4 Gold = float4(220.f/255.f, 200.f/255.f, 0.f/255.f, 1.f); //this is a rgb color for you... change it to suit
|
|
|
Re: texture lookups problem
[Re: Matt_Aufderheide]
#62399
01/26/06 13:55
01/26/06 13:55
|
Joined: Mar 2002
Posts: 221 USA
zefor
OP
Member
|
OP
Member
Joined: Mar 2002
Posts: 221
USA
|
I gave up on the wiki code and tried the sun/fog code from a code you (mat) posted earlier. I can now see models and they react with fog, but no shine effect. I believe the problem is in the "return" line, but nothing I try works. Can anyone spot my mistake? Code:
float4x4 matWorldViewProj; float4x4 matView; float4x4 matWorld;
float4 vecSkill41;
float4 vecViewPos; float4 vecFog; float4 vecSkill1; float4 ambientcolor={0.3,0.3,0.3,0.0}; //can also use vecLight here for true ambient color float4 suncolor={0.8,0.8,0.7,0.0}; //define the suncolor here, could also pass it from the script in a mtl skill
texture entSkin1; texture entSkin2;
sampler ColorMapSampler = sampler_state { Texture = <entSkin1>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = wrap; AddressV = wrap; };
sampler BumpMapSampler = sampler_state { Texture = <entSkin2>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = wrap; AddressV = wrap; };
struct VS_OUTPUT { float4 Pos: POSITION; float2 texCoord: TEXCOORD0; // float3 Sun: TEXCOORD1;
float3 View4 : TEXCOORD3; float3 Sun : TEXCOORD1; float Fog : FOG; };
VS_OUTPUT VS1(float4 inPos: POSITION, float3 normal: normal, float3 tangent: TANGENT, float2 texCoord : TEXCOORD0) { VS_OUTPUT Out;
Out.Pos = mul(inPos, matWorldViewProj);
////////////////////
// Some object-linear texgen, specific for this particular model Out.texCoord.x = inPos.x * 0.0065 + 0.46; Out.texCoord.y = inPos.z * 0.0065 + 0.46; Out.texCoord = texCoord;
// float3 PosWorld = mul(inPos, matWorld); float ofog = 1 - (distance(PosWorld, vecViewPos) - vecFog.x) * (vecFog.z); Out.Fog = ofog; // Out.Fog = 10000; float3 Pview = -mul(matView, inPos);
// Move our tangent-space into eye-space float3 vtang = mul(matView, tangent); float3 vbinorm = mul(matView, cross(tangent, normal)); float3 vnorm = mul(matView, normal);
// We use lightVec = viewVec, that is, the camera is also the light. float3 Sun = Pview;
// Transform light vector from eye-space to tangent-soace Out.Sun.x = dot(Sun, vtang); Out.Sun.y = dot(Sun, vbinorm); Out.Sun.z = dot(Sun, vnorm);
// float3 Viewer4 = PosWorld - vecViewPos; Out.View4 = mul(Pview, -Viewer4); // V
//sunlight Out.Sun.xyz = mul(Pview, vecSkill1); // L //
return Out; }
/////////////////////Pixel Shader
float4 Gold = float4(0.3,0.3,0.3,0.0); //float4 Gold: register(c1);
sampler ColorMap: register(s0); sampler BumpMap: register(s1);
float4 PS1(float2 texCoord: TEXCOORD0, float3 Sun: TEXCOORD1, float3 View4: TEXCOORD3, float Fog: FOG) : COLOR { float4 color = tex2D(ColorMapSampler, texCoord); float3 bump = tex2D(BumpMapSampler, texCoord) * 2.0 - 1.0; //bump=normalize(bump);
float3 ViewDir4 = normalize(View4); //sunlight float3 ViewSun = normalize(Sun); float4 diff7 = saturate(dot(bump, ViewSun)); // diffuse component float3 Reflect7 = normalize(2 * diff7 * bump - Sun); // R float4 spec7 = pow(saturate(dot(Reflect7, ViewDir4)), 64); float shadow7 = saturate(4 * diff7);
// shine = diffuse and specular // float shine = saturate(dot(normalize(Sun), normalize(bump))); // return (shine * 0.2) * color + pow(shine, 64) * Gold; return ( (ambientcolor * 2.0) * color + ((shadow7* (color * diff7 + (spec7*color.w))) * Gold) );
/* return ( (ambientcolor * color) + //ambient ambientcolor = Sun
((shadow7* (color * diff7 + (spec7*color.w))) * suncolor) ); */
}
technique Gold_shine { pass p0 {
VertexShader = compile vs_2_0 VS1(); PixelShader = compile ps_2_0 PS1(); } }
|
|
|
|