Jump to content
  • Advertisement

RenderPixel

Member
  • Content Count

    13
  • Joined

  • Last visited

Community Reputation

2 Neutral

About RenderPixel

  • Rank
    Member

Personal Information

  • Interests
    Art
    Programming

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. RenderPixel

    3D HLSL Minimap!

    I am working on making a shader driven minimap for a game. I have almost completed this task but I am stuck on one part. I need to make sure that when I track something (on the minimap) and it goes beyond the extent of my viewport (perimeter of minimap) it sticks to the edge of the viewport and does not continue past it. This is relatively straight forward for a circle minimap, however, mine is a rectangle. Not sure how to work out the math on this one. Any ideas??
  2. Another example of a var that doesnt need to be passed into a function is texture2d. I can just sample it in the pixel shader without having it as an input. Why is that?
  3. Hello. I have already posted a thread about myself and what I am trying to accomplish here. TLDR: I am a 12 year, game industry, artist moving into graphics programming, starting with hlsl shader development. I started with a basic phong shader and received a ton of help on these forums here. Now I continue my journey and am starting a new thread with general questions. I am using several books and online resources in my process but sometimes community is a great way to learn as well. Here we go! Question #1: I understand that there are global variables and local variables. If you want to use a declared, global. variable in a function (like a vertex shader) you need to pass it in. I usually create a struct that I want to use in the vertex shader for this reason. However, I have noticed that some variables (like, worldViewProjection : WORLDVIEWPROJECTION) can be declared and used in a function without being passed into it. Why is that? What am I missing here?
  4. RenderPixel

    Phong Specular Reflection Problems in HLSL!

    @matt77hias Yes. That was one of the issues with the code. I have moved forward with some more shader dev. and I have some more questions. It might be best to start a new thread since they do not petain specifically to the phong shader. Hopefully I will see you there! Thanks again for everything so far!
  5. RenderPixel

    Phong Specular Reflection Problems in HLSL!

    @matt77hias Thanks again for all of the info. I was able to get it to work and develop a better understanding with the information you have provided me. On to the next endeavor, where I am sure more questions will come.
  6. RenderPixel

    Phong Specular Reflection Problems in HLSL!

    @matt77hias The code you posted really helps a lot! I like the way you structured it. I have replicated this in my own code and have learned a lot from it already though I get a black material with no brdf influence when I compile. It is likely a syntax and/or math issue on my part. I will be pressing on with this more tomorrow to try to resolve the issue. I posted what I have at the moment. I am also not sure what the 'g_inv_pi' was in your code so I removed it. That, itself, could be the issue. Regardless, I am happy that, at this point, I am able to code at least this much with no reference. Obviously, once the brdf is implemented properly I will feel much more satisfied. Thanks again for you posts. I cannot express how much it helps. I feel that I am close to putting this all together. ///// RasterizerState ////////////////////////////////////////////// RasterizerState disableCulling { CullMode = NONE; }; ///// Vars ///////////////////////////////////////////////////////// float4x4 wvp : WORLDVIEWPROJECTION; float3 cameraPosition : CAMERAPOSITION; float4x4 world : WORLD; float light; float3 Ks; float3 Kd; float Ns; float3 E_directional; float3 lightDirection : DIRECTION < string Object = "DirectionalLight0";>; struct vsIn { float3 normal : NORMAL; float2 texCoord : TEXCOORD; float4 position : POSITION; }; struct vsOut { float4 position : SV_POSITION; float2 texCoord : TEXCOORD; float3 normal : NORMAL; float3 view :TEXCOORD2; }; ///// Phong Lighting /////////////////////////////////////////////// float3 phongLighting(float3 n, // The normalized surface normal vector. float3 l, // The normalized direction from the surface point to the light source (i.e. constant for directional lights) float3 v, // The normalized direction from the surface point to the eye. float3 Kd, // The diffuse reflection coefficient of the surface material. float3 Ks, // The specular reflection coefficient of the surface material. float Ns, // The specular exponent of the surface material. float3 E_directional // The irradiance of the directional light source. ) { const float3 r = reflect(-l, n); // Calculate the reflection vector using HLSL intrinsics. const float n_dot_l = saturate(dot(n, l)); // Note the saturate! const float v_dot_r = saturate(dot(v, r)); // Note the saturate again! const float3 diffuse = Kd; // Evaluate the diffuse part of the Phong BRDF. const float3 specular = Ks * pow(v_dot_r, Ns); // Evaluate the specular part of the Phong BRDF. const float3 brdf = diffuse + specular; // Evaluate the complete Phong BRDF. const float3 radiance = brdf * E_directional * n_dot_l; // Combine the BRDF and the irradiance. return radiance; } ///// Vertex Shader //////////////////////////////////////////////// vsOut vs (vsIn IN) { vsOut OUT = (vsOut)0; float3 worldPosition = mul(IN.position, world).xyz; OUT.position = mul(IN.position, wvp); OUT.view = normalize(cameraPosition - worldPosition); return OUT; } ///// Pixel Shader ///////////////////////////////////////////////// float4 ps (vsOut IN) : SV_TARGET { float4 OUT; OUT.rgb = phongLighting(normalize(IN.normal), normalize(lightDirection), normalize(IN.view), Kd, Ks, Ns, E_directional); OUT.a = 1; return OUT; } ///// Technique //////////////////////////////////////////////////// technique10 main10 { pass p0 { SetVertexShader (CompileShader(vs_4_0,vs())); SetPixelShader (CompileShader( ps_4_0,ps())); SetRasterizerState (disableCulling); } }
  7. RenderPixel

    Phong Specular Reflection Problems in HLSL!

    @matt77hias Thank you for taking the time to point all of this out. I have been in the game industry for a long time now and I udnerstand what its like to be asked to explain things that are seemingly obvious. Now, starting from the bottom again, I am glad to know that there are folks out there to help along the way. I will review this tonight and work my way through your notes. Thanks again!
  8. RenderPixel

    Phong Specular Reflection Problems in HLSL!

    I have tried the recommendations. I am still seeing the same results. Granted, I have not completed a full implementation of a point light using the formula provided above. I want to understand the problem I am facing before adding more complexity to the shader. The goal is a basic phong specular reflection using a directional light. I have been stopped here for a couple of days now. Perhaps someone would be kind enough to take a look at the code I attached on the original post and tell me what I am missing? I do not usually ask for hand-outs but I understand the math and the concept, yet I cannot get the proper result to appear. Any help is much appreciated!
  9. RenderPixel

    Phong Specular Reflection Problems in HLSL!

    @MJP So you are saying that I need to (specular reflection * saturate(diffuse reflection)) correct? (dot(R,V)^S) * (saturate(dot(N,L))
  10. I have just started writing shaders recently (a couple of weeks ago.) (Background info in another post here.) I decided to start with a basic phong shader. I understand (I think) the implementation of the diffuse and specular refleections. Diffuse reflection = (N.L) Specular reflection = (R.V)^S where s = specular power. Reflection vector = 2* (N.L)*N-L I have a shader put together for fx composer 2.5 that is an attempt at the phong lighting model. (Shader code linked.) I have not added in the texture sample to the pixel shader output yet since I am trying to debug lighting model issues. The diffuse reflection works fine, however, the specular reflection is giving me some trouble. The problem I am experience is that the specular reflection (shown here) seems to affect the back of the sphere. When I saturate the specular reflection value I get this: (If saturate clamps input to min=0 and max=1, I do not know where these values on the back are coming from since negative values should just get clamped to 0.) If I remove the saturate from the specular reflection and add the difuse reflection to the specular reflection I get this. (I will post an image of my diffuse reflection below to show how it looks on its own. ) Diffuse reflection by itself. What am I missing here? Also, I am completely open to feedback on my shader. I am looking to learn anything I can here. Thank you in advance for your time. phongUpload
  11. RenderPixel

    Artist To Programmer

    @CortexDragon Thanks again. I am looking into all of this already! Great info!
  12. RenderPixel

    Artist To Programmer

    @CortexDragon @alexokita Wow! I really appreciate from both of you. This is a lot of information to digest. I will start looking into all of the sources this evening. So far, the syntax has been the slowest part to pick up. The ideas and application have been simple to grasp since I have a solid background in 3d already. I like the idea of creating my own render engine and then using my own shaders in it as a learning process. I am curious how long it will take me to develop a wholistic understanding of all of this. My assumption is that it will likely take years. My goal is to see what I can learn by the end of this year with as much night and weekend time dedicated to this as possible. This feedback will serve as a great starting point for me. Thank you.
  13. Hello all. This is my first post in the forums here. I am currently an artist in the game industry. I have been working as an artist and/or art director for the past 12 years. I have been working in ue4 for the past several years and have become reasonably practiced at developing custom materials. My focus has shifted, quite a bit, from making art content to understanding the render pipe better. I recently purchased some books on directx and learned to develop basic shaders in hlsl. I am learning the math and physics as I go. As I learn, I am realizing that I have a real passion for this. My goal, initially, was to learn to be a shader programmer. However, as I learn more, I grow curious about what it would take to make a full transition into becoming a render engineer. I am curious where to start. I am piecing this all together as I learn at the moment. I.e render pipe, math, syntax, etc. Should I instead learn this in some particular order or fashion? Is schooling necessary to be successful in this endeavor? This is is basically a general inquisition. This could be a major career change for me and I am looking to get started the right way. Any help is greatly appreciated.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!