Навигация по форуму
|
|
4 |
Quest3D / Визуализация, Шейдеры / Re: [G] Проблема с отображением HLSL объектов (есть ответ) : 03 Августа 2011, 14:05:44
| /*** Generated through Lumonix shaderFX by: Vladimir in 3dsmax at: 03.08.2011 1:04:38 ***/
// This FX shader was built to support the Quest3D engine. // Tell the app that we want tangets int UseTangent : UseTangent; int UseBiNormal : UseBiNormal;
texture TextureMap_3177 : TEXTURE0 < string ResourceType = "2D"; >; sampler2D TextureMap_3177Sampler = sampler_state { Texture = <TextureMap_3177>; MinFilter = LINEAR; MagFilter = LINEAR; MipFilter = LINEAR; AddressU = WRAP; AddressV = WRAP; }; float spec :CHANNELVALUE0 < string UIWidget = "Slider"; float UIMin = 0.0; float UIMax = 255.0; float UIStep = 0.1; string UIName = "spec"; > = 0.2; float gloss :CHANNELVALUE1 < string UIWidget = "Slider"; float UIMin = 0.0; float UIMax = 255.0; float UIStep = 0.1; string UIName = "gloss"; > = 10.0; texture BumpMap_4244 : TEXTURE1 < string ResourceType = "2D"; >; sampler2D BumpMap_4244Sampler = sampler_state { Texture = <BumpMap_4244>; MinFilter = LINEAR; MagFilter = LINEAR; MipFilter = LINEAR; AddressU = WRAP; AddressV = WRAP; };
// this function does the different types of light attenuation float attenuation_func(int lightattenType, float4 lightAttenuation, float3 lightVec) { float att = 1.0; return att; } // this function does the different types of cone angle float coneangle_func(int lightconeType, float lightHotspot, float lightFalloff, float3 lightVec, float3 lightDir) { float cone = 1.0; return cone; }
/************** light info **************/
#define MAX_LIGHTCOUNT 8 float NLIGHTS = 1; #define LIGHT_TYPE_NONE 0 #define LIGHT_TYPE_POINT 1 #define LIGHT_TYPE_SPOT 2 #define LIGHT_TYPE_DIRECTIONAL 3 float3 light_dir[MAX_LIGHTCOUNT] : LIGHTDIR; float3 light_pos[MAX_LIGHTCOUNT] : LIGHTPOS; float4 light_color[MAX_LIGHTCOUNT] : LIGHTCOLOR; float light_atten1[MAX_LIGHTCOUNT] : LIGHTATT1; float light_atten2[MAX_LIGHTCOUNT] : LIGHTATT2; float light_atten3[MAX_LIGHTCOUNT] : LIGHTATT3; float light_hotspot[MAX_LIGHTCOUNT] : LIGHTPHI; float light_falloff[MAX_LIGHTCOUNT] : LIGHTTHETA; float light_type[MAX_LIGHTCOUNT] : LIGHTTYPE; #define light1attenType 0 #define light1coneType 0 #define light1CastShadows false
//----------------------------------
float4x4 wvp : WorldViewProjection < string UIWidget = "None"; >; float4x4 worldI : WorldInverse < string UIWidget = "None"; >; float4x4 worldIT : WorldInverseTranspose < string UIWidget = "None"; >; float4x4 viewInv : ViewInverse < string UIWidget = "None"; >; float4x4 world : World < string UIWidget = "None"; >; // create the light vector float3 lightVec_func(float3 worldSpacePos, float3 lightVector, float3x3 objTangentXf, int lightType) { float3 lightVec = mul(objTangentXf, (mul((lightVector - worldSpacePos), worldI).xyz)); return lightVec; }
// input from application struct a2v { float4 position : POSITION; float4 tangent : TANGENT; float4 binormal : BINORMAL; float4 normal : NORMAL;
float2 texCoord : TEXCOORD0;
};
// output to fragment program struct v2f { float4 position : POSITION; float3 lightVec : TEXCOORD0; float3 eyeVec : TEXCOORD1;
float2 texCoord : TEXCOORD2;
};
//Diffuse and Specular Pass Vertex Shader v2f v(a2v In, uniform float3 lightPos, uniform int lightType, uniform float3 lightDir) { v2f Out = (v2f)0; float3x3 objTangentXf; //build object to tangent space transform matrix objTangentXf[0] = In.tangent.xyz; objTangentXf[1] = -In.binormal.xyz; objTangentXf[2] = In.normal.xyz; float3 worldSpacePos = mul(In.position, world).xyz; //world space position Out.lightVec = lightVec_func(worldSpacePos, lightPos, objTangentXf, lightType); float4 osIPos = mul(viewInv[3], worldI); //put world space eye position in object space float3 osIVec = osIPos.xyz - In.position.xyz; //object space eye vector Out.eyeVec = mul(objTangentXf, osIVec); //tangent space eye vector passed out Out.position = mul(In.position, wvp); //transform vert position to homogeneous clip space
Out.texCoord = In.texCoord; //pass through texture coordinates from channel 1
return Out; }
//Diffuse and Specular Pass Pixel Shader float4 f(v2f In, uniform float3 lightDir, uniform float4 lightColor, uniform float4 lightAttenuation, uniform float lightHotspot, uniform float lightFalloff, uniform int lightType, uniform int lightattenType, uniform int lightconeType, uniform bool lightCastShadows, uniform int shadowPassCount) : COLOR { float3 ret = float3(0,0,0); float3 V = normalize(In.eyeVec); //creating the eye vector float3 L = normalize(In.lightVec); //creating the light vector
float4 TextureMap_3177 = tex2D(TextureMap_3177Sampler, In.texCoord.xy); float3 input2 = TextureMap_3177.rgb;
float input4 = spec;
float input5 = gloss;
float BumpMap_4244_center = tex2D(BumpMap_4244Sampler, In.texCoord.xy).r; //center bump map sample float BumpMap_4244_U = tex2D(BumpMap_4244Sampler, In.texCoord.xy + float2( 0.005, 0)).r; //U bump map sample float BumpMap_4244_V = tex2D(BumpMap_4244Sampler, In.texCoord.xy + float2(0, 0.005)).r; //V bump map sample float BumpMap_4244_dHdU = BumpMap_4244_U - BumpMap_4244_center; //create bump map U offset float BumpMap_4244_dHdV = BumpMap_4244_V - BumpMap_4244_center; //create bump map V offset float3 BumpMap_4244 = float3( -BumpMap_4244_dHdU, BumpMap_4244_dHdV, 0.05 ); //create the tangent space normal BumpMap_4244 = normalize(BumpMap_4244); //normalize the result float3 input8 = BumpMap_4244;
float3 N = input8; //using the Normal socket float3 diffuseColor = input2; //using the Diffuse Color socket float NdotL = dot(N, L); //calculate the diffuse float diffuse = saturate(NdotL); //clamp to zero diffuseColor *= diffuse; //the resulting diffuse color float specularColor = input4; //the Specular Color socket was empty - using Specular Level instead float glossiness = input5; //using the Glossiness socket float3 R = -reflect(L, N); //Compute the reflection vector float RdotV = saturate(dot(R,V)); //Compute RdotV specularColor *= pow(RdotV, glossiness);//Raise to glossiness power and compute final specular color ret += specularColor + diffuseColor; //add specular and diffuse color together ret *= lightColor; //multiply by the color of the light float attenuation = attenuation_func(lightattenType, lightAttenuation, In.lightVec); //calculate the light attenuation float coneangle = coneangle_func(lightconeType, lightHotspot, lightFalloff, In.lightVec, lightDir); //calculate the light's cone angle ret *= attenuation * coneangle; //multiply by the light decay float4 done = float4(ret, 1); //create the final ouput value return done; }
technique Complete { pass light1 { VertexShader = compile vs_2_0 v(light_pos[0], light_type[0], light_dir[0]); ZEnable = true; CullMode = ccw; ShadeMode = Gouraud; ZWriteEnable = true; AlphaBlendEnable = false; SrcBlend = SrcAlpha; DestBlend = One; AlphaTestEnable = FALSE; PixelShader = compile ps_2_0 f(light_dir[0], light_color[0], float4(light_atten1[0], light_atten2[0], light_atten3[0], 1.0), light_hotspot[0], light_falloff[0], light_type[0], light1attenType, light1coneType, light1CastShadows, 1); } } |
7 |
Quest3D / Логика / Walkthrough Camera : 25 Июля 2011, 13:43:35
| Подскажите как поднять Walkthrough Camera.
Значение Value для высоты в Movement Position связано со значением Value в Collision Spheroid Radius.
Соответственно когда значения небольшие камера низко, когда увеличиваю начинает застревать в проходах.
Можно ли как-нибудь настроить эти значения отдельно? |
|