Posted By: Iglarion
Use pixellight in one material? - 03/29/15 10:57
I have a problem when i using this material, the model does not react on dynamic lights:
How i can merge this shader with pixellight shader, or in any other way to get my models recive dynamic light? Here is pixelight shader
Code:
float4x4 matWorldViewProj; float4x4 matWorld; float4 vecAmbient; float4 vecSunDir; float4x4 matView; texture entSkin1; texture bmp_hero_highlight_bmap; sampler ColorMapSampler = sampler_state { Texture = <entSkin1>; AddressU = Wrap; AddressV = Wrap; }; sampler HighlightMapSampler = sampler_state { Texture = <bmp_hero_highlight_bmap>; AddressU = Wrap; AddressV = Wrap; }; void DiffuseVS( in float4 InPos: POSITION, in float3 InNormal: NORMAL, in float2 InTex: TEXCOORD0, out float4 OutPos: POSITION, out float2 OutTex: TEXCOORD0, out float3 OutNormal: TEXCOORD1, out float3 OutHighlightTex: TEXCOORD2) { OutPos = mul(InPos, matWorldViewProj); OutNormal = normalize(mul(InNormal, matWorld)); OutTex = InTex; OutHighlightTex = mul(InNormal, matView)*0.3+0.5; } float4 DiffusePS( in float2 InTex: TEXCOORD0, in float3 InNormal: TEXCOORD1, in float3 InHighlightTex: TEXCOORD2): COLOR { InNormal = normalize(InNormal); float4 Highlight = tex2D(HighlightMapSampler, InHighlightTex); float4 Color = tex2D(ColorMapSampler, InTex); float Diffuse = 0.5+0.5*saturate(dot(-vecSunDir, InNormal)*3); float4 final = Color*Diffuse*Highlight*1.25; return final; } technique DiffuseTechnique { pass P0 { VertexShader = compile vs_2_0 DiffuseVS(); PixelShader = compile ps_2_0 DiffusePS(); } }
How i can merge this shader with pixellight shader, or in any other way to get my models recive dynamic light? Here is pixelight shader
Code:
const float4x4 matWorldViewProj; // World*view*projection matrix. const float4x4 matWorld; // World matrix. const float4 vecAmbient; // Ambient color. const float4 vecViewPos; // View position. float4 vecLightPos[8]; float4 vecLightColor[8]; float4 vecLightDir[8]; texture entSkin1; texture entSkin2; sampler ColorMapSampler = sampler_state { Texture = <entSkin1>; }; sampler ShadowMapSampler = sampler_state { Texture = <entSkin2>; }; void PixelVS_lm( in float4 InPos: POSITION, in float3 InNormal: NORMAL, in float2 InTex: TEXCOORD0, in float4 InShadow: TEXCOORD1, out float4 OutPos: POSITION, out float2 OutTex: TEXCOORD0, out float4 OutShadow: TEXCOORD1, out float3 OutNormal: TEXCOORD2, out float3 OutWorldPos: TEXCOORD3) { OutPos = mul(InPos, matWorldViewProj); OutTex = InTex; OutShadow = InShadow; OutNormal = InNormal; OutWorldPos = mul(InPos, matWorld).xyz; } float4 PixelPS_lm( in float2 InTex: TEXCOORD0, in float4 InShadow: TEXCOORD1, in float3 InNormal: TEXCOORD2, in float3 InWorldPos: TEXCOORD3): COLOR { int i; float3 dir; float fac,lfac; InNormal = normalize(InNormal); float4 Shadow = tex2D(ShadowMapSampler, InShadow); float4 Color = tex2D(ColorMapSampler, InTex); float4 Light = 0; for(i = 0; i < 8; i++) { dir = vecLightPos[i].xyz-InWorldPos; fac = 1-saturate(length(dir)/vecLightPos[i].w); Light += vecLightColor[i]*fac*saturate(vecLightPos[i].w); } return Color*(Shadow+Light*2); } technique ShadowTechnique_lm { pass P0 { VertexShader = compile vs_2_0 PixelVS_lm(); PixelShader = compile ps_2_0 PixelPS_lm(); } } /////////////////////////////////////////////////// void PixelVS( in float4 InPos: POSITION, in float3 InNormal: NORMAL, in float2 InTex: TEXCOORD0, out float4 OutPos: POSITION, out float2 OutTex: TEXCOORD0, out float3 OutNormal: TEXCOORD1, out float3 OutWorldPos: TEXCOORD2) { OutPos = mul(InPos, matWorldViewProj); OutTex = InTex; OutNormal = mul(InNormal, matWorld); OutWorldPos = mul(InPos, matWorld).xyz; } float4 PixelPS( in float2 InTex: TEXCOORD0, in float3 InNormal: TEXCOORD1, in float3 InWorldPos: TEXCOORD2): COLOR { int i; float3 dir; float fac,lfac; InNormal = normalize(InNormal); float4 Color = tex2D(ColorMapSampler, InTex); float4 Light = 0; for(i = 0; i < 8; i++) { dir = vecLightPos[i].xyz-InWorldPos; fac = 1-saturate(length(dir)/vecLightPos[i].w); fac *= saturate(dot(normalize(dir),InNormal)); Light += vecLightColor[i]*fac*saturate(vecLightPos[i].w); } return Color*(vecAmbient+Light*2); } technique ShadowTechnique { pass P0 { VertexShader = compile vs_2_0 PixelVS(); PixelShader = compile ps_2_0 PixelPS(); } }