lyzerk

Members
  • Content count

    35
  • Joined

  • Last visited

Community Reputation

120 Neutral

About lyzerk

  • Rank
    Member
  1. Hi, im working on lights but i have problem with it. http://prntscr.com/finfv as you see terrain model has light but that house model never effect with that light, i didn't understand why im doing same process to house model. here is my HLSL code : [source lang="java"]float4 PixScene( float4 ViewPos : TEXCOORD0, float3 ViewNormal : TEXCOORD1, float2 Tex0 : TEXCOORD2, float4 Diffuse : TEXCOORD3 ) : COLOR0 { float3 L = g_vLightView - ViewPos; float LenSq = dot( L, L ); L = normalize( L ); float4 I = saturate( dot( normalize( ViewNormal ), L ) ) * Diffuse * (LIGHT_FALLOFF * LIGHT_FALLOFF) / LenSq; return float4( tex2D( g_samScene, Tex0 ).xyz, 1.0f ) * I; //return float4(1.0f,1.0f,1.0f,1.0f); }[/source] cpp [source lang="cpp"] V ( g_Effect->Begin( &cPasses, 0 ) ); for( int p = 0; p < cPasses; p++) { V ( g_Effect->BeginPass ( p ) ); world = g_Map.GetWorldMatrix(); V( g_Effect->SetMatrix( g_Effect->GetParameterByName(NULL, "g_mWorldView"), &world ) ); V( g_Effect->CommitChanges() ); ID3DXMesh* mesh = g_Map.BaseModel.GetMesh(); for( UINT i = 0; i < g_Map.BaseModel.m_dwNumMaterials; ++i ) { V( g_Effect->SetTexture( g_Effect->GetParameterByName(NULL, "g_txScene") , g_Map.BaseModel.m_pTextures[i] ) ); V( g_Effect->CommitChanges() ); mesh->DrawSubset( i ) ; } V ( g_Effect->EndPass() ); } g_Effect->End(); cPasses = 0; V ( g_Effect->Begin( &cPasses, 0 ) ); for( int p = 0; p < cPasses; p++) { V ( g_Effect->BeginPass ( p ) ); world = g_Bar.GetWorldMatrix(); V( g_Effect->SetMatrix( g_Effect->GetParameterByName(NULL, "g_mWorldView"), &world ) ); V( g_Effect->CommitChanges() ); ID3DXMesh* mesh = g_Bar.BaseModel.GetMesh(); for( UINT i = 0; i < g_Bar.BaseModel.m_dwNumMaterials; ++i ) { if(g_Bar.BaseModel.m_pTextures[i]) { V( g_Effect->SetTexture( g_Effect->GetParameterByName(NULL, "g_txScene") , g_Bar.BaseModel.m_pTextures[i] ) ); } else { V( g_Effect->SetTexture( g_Effect->GetParameterByName(NULL, "g_txScene") , g_pDefaultTex ) ); } V( g_Effect->CommitChanges() ); mesh->DrawSubset( i ) ; } V ( g_Effect->EndPass() ); }[/source] -Thanks
  2. Hello, Thanks for answers. I solve it, its about release/debug. when with release result is http://prntscr.com/f7nkt and with debug http://prntscr.com/f7nie Sorry for delay
  3. [source lang="cpp"] D3DXMATRIXA16 matWorld; D3DXMatrixTranslation( &matWorld, -89.0f, 0.0f, -132.0f );[/source] Im calling that code with 2 project one result is : http://prntscr.com/f7nie and another project result is : http://prntscr.com/f7nkt how can its possible , first result wrong i think. anybody can explain it for me ? -Thanks
  4. Light position problem

    can anyone help ?
  5. Light position problem

    hmm i understand i did same as they did but everything is same, nothings working. im really tried about that HLSL light. if someone can fix this i uploaded my project and worked project EmptyProject.rar is my project, and ShadowVolume is from directxsampler i copy everything about HSLS light. if someone worked light on EmptyProject, i will so much grateful -Thanks for everthing.
  6. Light position problem

    Ok now i open PIX and trying to use. but i think problem isnt light color or something. i think problem is that lightView here; at HLSL lightView is float3 and he is using ->SetVector. SecVector is for float4, and vLight is vector4. its so weird :S and he is transform vLight with matrix. maybe i should do ? but my matrixes "matrix16" not "matrix" so i dont know how to do. Sorry for my english, i'm trying for best. -Thanks
  7. Light position problem

    yes its same i tried delete it and false,true it but still same result. what it should be ? but i think problem is light vector
  8. Light position problem

    [quote name='kauna' timestamp='1346953508' post='4977279'] Just one question more : why do you set StencilEnable to Enable for the second pass? Best regards! [/quote] I didn't, like i said its copy from one working project. Maybe i need to Transform vector ?
  9. Light position problem

    [quote name='kauna' timestamp='1346949792' post='4977263'] Well, have you tried to play with the light_falloff value? Have you tried to narrow down the problem, like simplifying your intensity formula. [quote] // Compute world space normal ViewNormal = normalize( mul( vNormal, (float3x3)g_mWorldView ) ); [/quote] The code above looks suspicious in the sense that you write "Compute world space normal" but actually you are calculating view space normals. Are you doing all your calculations in the same space? Cheers! [/quote] Yes i tried play with light_falloff value negative and positive, i dont think so functions is wrong because i copy it from working one project. but they doing it like this; [source lang="cpp"] D3DXVECTOR4 vLight( g_aLights[L].m_Position.x, g_aLights[L].m_Position.y, g_aLights[L].m_Position.z, 1.0f ); D3DXVec4Transform( &vLight, &vLight, g_LCamera.GetWorldMatrix() ); D3DXVec4Transform( &vLight, &vLight, g_Camera.GetViewMatrix() ); V( g_pEffect->SetVector( "g_vLightView", &vLight ) );[/source] problem is just GetWorldMatrix and GetViewMatrix their return is matrix not matrix16, my Matrixes is matrix16, i can't figure out. -Thanks
  10. Light position problem

    [quote name='kauna' timestamp='1346946498' post='4977242'] What is your LIGHT_FALLOFF value? Also, your light position is at -100,-100,-100. Isn't that underground? Best regards! [/quote] LIGHT_FALLOF is 1.4 its my camera position. its not wrong i think. -Thanks
  11. Light position problem

    [quote name='kauna' timestamp='1346936343' post='4977169'] Well you could output just float4(1.0f,1.0f,1.0f,1.0f) from your shader if nothing appears. Just to verify that your code works. Also, you could set the background clear color to something else than black to verify if something is being drawed. Cheers! [/quote] float4(1.0f,1.0f,1.0f,1.0f) its worked all screen gonna white. and i did clear screen before begin with that V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_STENCIL, D3DCOLOR_ARGB( 0, 170, 170, 170 ), 1.0f, 0 ) );
  12. Light position problem

    [quote name='Seabolt' timestamp='1346878885' post='4976978'] I would take it into pix and see what the value of g_vLightView, otherwise it would be hard to pin-point what exactly the issue is. [/quote] [source lang="java"]float3 g_vLightView;[/source] its float3 and here ps and vs functions [source lang="cpp"]void VertScene( float4 vPos : POSITION, float3 vNormal : NORMAL, float2 vTex0 : TEXCOORD0, out float4 oPos : POSITION, out float4 ViewPos : TEXCOORD0, out float3 ViewNormal : TEXCOORD1, out float2 oTex0 : TEXCOORD2, out float4 oDiffuse : TEXCOORD3 ) { // Transform the position from view space to homogeneous projection space oPos = mul( vPos, g_mWorldViewProjection ); // Compute view space position ViewPos = mul( vPos, g_mWorldView ); // Compute world space normal ViewNormal = normalize( mul( vNormal, (float3x3)g_mWorldView ) ); // Modulate material with light to obtain diffuse oDiffuse = g_vMatColor * g_vLightColor; // Just copy the texture coordinate through oTex0 = vTex0; } float4 PixScene( float4 ViewPos : TEXCOORD0, float3 ViewNormal : TEXCOORD1, float2 Tex0 : TEXCOORD2, float4 Diffuse : TEXCOORD3 ) : COLOR0 { // Pixel to light vector float3 L = g_vLightView - ViewPos; float LenSq = dot( L, L ); L = normalize( L ); // Compute lighting amount float4 I = saturate( dot( normalize( ViewNormal ), L ) ) * Diffuse * (LIGHT_FALLOFF * LIGHT_FALLOFF) / LenSq; // Lookup mesh texture and modulate it with diffuse return float4( tex2D( g_samScene, Tex0 ).xyz, 1.0f ) * I; }[/source]
  13. Hello, I have problem with light pos, I did one HLSL file here technique [source lang="cpp"]technique RenderDarkAtmospher { pass P0 { VertexShader = compile vs_2_0 VertSceneAmbient(); PixelShader = compile ps_2_0 PixSceneAmbient(); StencilEnable = false; ZFunc = LessEqual; } pass P1 { VertexShader = compile vs_2_0 VertScene(); PixelShader = compile ps_2_0 PixScene(); ZEnable = true; ZFunc = LessEqual; StencilEnable = true; AlphaBlendEnable = true; BlendOp = Add; SrcBlend = One; DestBlend = One; StencilRef = 1; StencilFunc = Greater; StencilPass = Keep; } }[/source] anyway my HLSL functions is correct, i copy it from working one project. pass p0 is working great all terrain going a black Atmospher, but i tryed a values for light pos but itsnt worked. I want camera with light. PixScene : [source lang="cpp"] float3 L = g_vLightView - ViewPos; float LenSq = dot( L, L ); L = normalize( L ); // Compute lighting amount float4 I = saturate( dot( normalize( ViewNormal ), L ) ) * Diffuse * (LIGHT_FALLOFF * LIGHT_FALLOFF) / LenSq; // Lookup mesh texture and modulate it with diffuse return float4( tex2D( g_samScene, Tex0 ).xyz, 1.0f ) * I;[/source] and my camera matrixes [source lang="cpp"] D3DXMATRIXA16 matWorld; D3DXMatrixTranslation( &matWorld, camera.camera.x, camera.camera.y, camera.camera.z); D3DXVECTOR3 vEyePt( 0, 100, 0 ); D3DXVECTOR3 vLookatPt( 0 , 0, camera.vec ); D3DXVECTOR3 vUpVec( 0, 1, 1 ); //up D3DXMATRIXA16 matView; D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec ); D3DXMATRIXA16 result = matWorld * matView; pd3dDevice->SetTransform( D3DTS_VIEW, &result ); D3DXMATRIXA16 matProj; D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI / 4, 1.0f, 1.0f, 1000.0f ); pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );[/source] [source lang="cpp"] D3DXVECTOR3 vLight( -100, -100, -100); id3dxEffect->SetValue( id3dxEffect->GetParameterByName(NULL, "g_vLightView"), &vLight, sizeof(vLight) );[/source] What i should do for light pos ? nothings apper Thanks.
  14. Terrain light problem

    hmm ok i did what i want now its a dark atmospher. but its directional light so i want do it like, strategy game, open lights with camera, like here http://prntscr.com/ewzcm so i need point light for map i can do it with this effect file ? (and this effect file from DirectxSampler) [source lang="cpp"]//----------------------------------------------------------------------------- // File: CompiledEffect.fx // // Desc: // // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // Global variables //----------------------------------------------------------------------------- float4 g_MaterialAmbientColor; // Material's ambient color float4 g_MaterialDiffuseColor; // Material's diffuse color // This effect file uses a single directional light float3 g_LightDir = normalize(float3(1.0f, 1.0f, -1.0f)); // Light's direction float4 g_LightAmbient = { 0.1f, 0.1f, 0.1f, 0.1f }; // Light's ambient color float4 g_LightDiffuse = { 1.0f, 1.0f, 1.0f, 1.0f }; // Light's diffuse color texture g_RenderTargetTexture; // Full screen render target texture texture g_MeshTexture; // Color texture for mesh float g_fTime; // App's time in seconds float4x4 g_mWorld; // World matrix for object float4x4 g_mWorldViewProjection; // World * View * Projection matrix //----------------------------------------------------------------------------- // Texture samplers //----------------------------------------------------------------------------- sampler RenderTargetSampler = sampler_state { Texture = <g_RenderTargetTexture>; MinFilter = POINT; MagFilter = POINT; MipFilter = NONE; AddressU = Clamp; AddressV = Clamp; }; sampler MeshTextureSampler = sampler_state { Texture = <g_MeshTexture>; MipFilter = LINEAR; MinFilter = LINEAR; MagFilter = LINEAR; }; //----------------------------------------------------------------------------- // Vertex shader output structure //----------------------------------------------------------------------------- struct VS_OUTPUT { float4 Position : POSITION; // vertex position float4 Diffuse : COLOR0; // vertex diffuse color float2 TextureUV : TEXCOORD0; // vertex texture coords }; //----------------------------------------------------------------------------- // Name: RenderSceneVS // Type: Vertex shader // Desc: This shader computes standard transform and lighting //----------------------------------------------------------------------------- VS_OUTPUT RenderSceneVS( float4 vPos : POSITION, float3 vNormal : NORMAL, float2 vTexCoord0 : TEXCOORD0 ) { VS_OUTPUT Output; float3 vNormalWorldSpace; // Animation the vertex based on time and the vertex's object space position float4 vAnimatedPos = vPos; /*vAnimatedPos.x *= (1.0 + cos(g_fTime)/10); vAnimatedPos.y *= (1.0 + sin(g_fTime)/10); vAnimatedPos.z *= (1.0 + cos(g_fTime)/10);*/ // Transform the position from object space to homogeneous projection space Output.Position = mul(vAnimatedPos, g_mWorldViewProjection); // Transform the normal from object space to world space vNormalWorldSpace = normalize(mul(vNormal, (float3x3)g_mWorld)); // normal (world space) // Compute simple directional lighting equation Output.Diffuse.rgb = g_MaterialDiffuseColor * g_LightDiffuse * max(0,dot(vNormalWorldSpace, g_LightDir)) + g_MaterialAmbientColor * g_LightAmbient; Output.Diffuse.a = 1.0f; // Just copy the texture coordinate through Output.TextureUV = vTexCoord0; return Output; } //----------------------------------------------------------------------------- // Pixel shader output structure //----------------------------------------------------------------------------- struct PS_OUTPUT { float4 RGBColor : COLOR0; // Pixel color }; //----------------------------------------------------------------------------- // Name: RenderScenePS // Type: Pixel shader // Desc: This shader outputs the pixel's color //----------------------------------------------------------------------------- PS_OUTPUT RenderScenePS( VS_OUTPUT In ) { PS_OUTPUT Output; // Lookup mesh texture and modulate it with diffuse Output.RGBColor = tex2D(MeshTextureSampler, In.TextureUV) * In.Diffuse; return Output; } //----------------------------------------------------------------------------- // Name: RenderScene // Type: Technique // Desc: Renders scene to render target //----------------------------------------------------------------------------- technique RenderScene { pass P0 { ZENABLE = true; VertexShader = compile vs_2_0 RenderSceneVS(); PixelShader = compile ps_2_0 RenderScenePS(); } } [/source] I know im asking too much question but i want to learn it :/ and sorry for my english. Thanks.
  15. Terrain light problem

    hmm i understand that i did it like this [source lang="cpp"] D3DXVECTOR2 v(camera.camera.x, camera.camera.z); id3dxEffect->SetValue(id3dxEffect->GetParameterByName(NULL, "textureT"), &v, sizeof(v) );[/source] [source lang="cpp"]float2 textureT; sampler Texture2 = sampler_state { magfilter = LINEAR; minfilter = LINEAR; mipfilter = LINEAR; AddressU = mirror; AddressV = mirror; }; float4 PS(float3 Light: TEXCOORD0, float3 Norm : TEXCOORD1 ) : COLOR { float4 diffuse = { 1.0f, 1.0f, 1.0f, 1.0f}; float4 ambient = {1.0f, 1.0f, 1.0f, 1.0f}; return tex2D(Texture2, textureT) * (ambient + diffuse * saturate(dot(Light, Norm))); }[/source] its just taking one color, am i doing it wrong ? (my texture is earth) result : http://prntscr.com/ez6x7