JohnK Posted November 13, 2015 Share Posted November 13, 2015 Sometimes the shader I am creating will be given an image file to use as a texture sampler and sometimes it will not. In the shader when the image file is given I need the lineuniform sampler2D refTexture;and in the main function a line along the lines offloat x = 0.5 * texture2D(refSampler, uv).rgb.x;and when no image file is given thenfloat x = 0.5 * position.xFrom looking at the code in the samplers in the materialsLibrary I see there are some conditions on the uniforms such as#if defined(SPOTLIGHT0) || defined(DIRLIGHT0)varying vec4 vPositionFromLight0;uniform sampler2D shadowSampler0;#elseuniform samplerCube shadowSampler0;#endif1. Is there a condition I can use for#if ..................uniform sampler2D refTexture;#endif2. Is there a conditional statement within the main function I can use forIF texture loaded float x = 0.5 * texture2D(refSampler, uv).rgb.x;ELSE float x = 0.5 * position.xENDIF Quote Link to comment Share on other sites More sharing options...
jerome Posted November 13, 2015 Share Posted November 13, 2015 maybe this will help : http://www.shaderific.com/glsl-statements/ I don't know GLSL Quote Link to comment Share on other sites More sharing options...
MarianG Posted November 13, 2015 Share Posted November 13, 2015 I think you can define a variable in your material.js file like : Material.prototype.isReady = function (mesh, useInstances) { if (texture loaded) { defines.push("#define variable_name"); }}and in you shader check #ifdef variable_name float x = 0.5 * texture2D(refSampler, uv).rgb.x;#else float x = 0.5 * position.x;#endif Quote Link to comment Share on other sites More sharing options...
JohnK Posted November 13, 2015 Author Share Posted November 13, 2015 @jerome & @bulisor thanks for suggestions, after reading these and looking further at the sample files in the materialsLibrary I can see that I can define a public variable in the class defines in the typescript file which can be set as true if there is a texture file given - just got to work out how I actually do this and then use #ifdef in the shader file. More thinking to do yet. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.